Hall.ts 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. import { _decorator, Component, director, Node, profiler } from 'cc';
  2. import { ResUtil } from '../../core/util/ResUtil';
  3. import TableLoadUtil from '../../core/util/TableLoadUtil';
  4. import get_new_head_icon from '../../core/util_class/HeadIcon';
  5. import { TableUtil } from '../../module_extra/table_ts/TableUtil';
  6. import { ModuleDef } from '../../Scripts/ModuleDef';
  7. import { SceneDef } from '../../Scripts/SceneDef';
  8. import PlayerData from '../game/PlayerData';
  9. import { ch } from '../../ch/ch';
  10. import { gui } from '../../core/ui/ui';
  11. import { UI_Hall } from '../ui/UI_Hall/UI_Hall';
  12. const { ccclass, property } = _decorator;
  13. @ccclass('Hall')
  14. export class Hall extends Component {
  15. private static instance: Hall;
  16. public player: PlayerData;
  17. public head_icon = get_new_head_icon();
  18. firstEnter:boolean = false;
  19. public static getInstance(): Hall {
  20. return Hall.instance;
  21. }
  22. async start() {
  23. if (!Hall.instance) {
  24. Hall.instance = this;
  25. }
  26. this.init();
  27. director.addPersistRootNode(this.node);
  28. // if(chsdk.checkFromSidebar())
  29. // {
  30. // Hall.getInstance().player.add_item(2,2);
  31. // }
  32. }
  33. async init() {
  34. await this.loadTable();
  35. this.player = PlayerData.getInstance(ch.sdk.get_gid(), ch.sdk.get_uid().toString());
  36. await this.player.init_user_info();
  37. await this.player.load();
  38. this.player.set_login_num(1);
  39. console.log("登录次数:" + this.player.get_login_num());
  40. if (this.player.get_max_floor() == 0) {
  41. this.firstEnter=true;
  42. ResUtil.loadScene(SceneDef.GAME, ModuleDef.GAME, true);
  43. }else{
  44. gui.show(UI_Hall);
  45. }
  46. }
  47. private loadTable(): void {
  48. ch.log.log_start("加载配置初始化");
  49. TableLoadUtil.preloadAll(ModuleDef.EXTRA, "table_json", async () => {
  50. }, TableUtil.set);
  51. }
  52. }