Hall.ts 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. import { _decorator, Component, director, Node } from 'cc';
  2. import PlayerData from '../game/PlayerData';
  3. import { ch } from '../../ch/ch';
  4. import { FMSType } from '../process/FMS';
  5. import get_new_fms from '../../core/util_class/FMS';
  6. import get_new_head_icon from '../../core/util_class/HeadIcon';
  7. const { ccclass, property } = _decorator;
  8. export enum GameState {
  9. start,//开始
  10. win,//成功
  11. over,//失败
  12. wait//等待
  13. }
  14. @ccclass('Hall')
  15. export class Hall extends Component {
  16. public FMS = get_new_fms();
  17. private static instance: Hall;
  18. public player: PlayerData;
  19. public head_icon = get_new_head_icon();
  20. sceneChanging: boolean = false;//场景切换
  21. public static getInstance(): Hall {
  22. return Hall.instance;
  23. }
  24. async start() {
  25. if (!Hall.instance) {
  26. Hall.instance = this;
  27. }
  28. console.log("hall start")
  29. this.init();
  30. }
  31. async init() {
  32. this.player = PlayerData.getInstance(ch.sdk.get_gid(), ch.sdk.get_uid().toString());
  33. await this.player.init_user_info();
  34. await this.player.load();
  35. this.to_hall()
  36. console.log("12121212")
  37. }
  38. to_main() {
  39. debugger
  40. this.FMS.Change(FMSType.Main);
  41. }
  42. to_hall() {
  43. this.FMS.Change(FMSType.Hall);
  44. }
  45. async preloadUIMainResources() {
  46. try {
  47. await new Promise<void>((resolve, reject) => {
  48. director.preloadScene("game", (err) => {
  49. if (err) reject(err);
  50. else resolve();
  51. });
  52. });
  53. } catch (error) {
  54. console.error("Preload failed:", error);
  55. }
  56. }
  57. }