GameFlowTree.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. import BasicTreeBehaviorNode from "../../Engine/Basic/BasicTreeBehaviorNode";
  2. import BasicTreeControlNode from "../../Engine/Basic/BasicTreeControlNode";
  3. import EventManager from "../../Engine/Event/EventManager";
  4. import { ConstObject } from "../Data/GameDataType";
  5. import GameEventName from "../Event/GameEventName";
  6. import { _EGameFlow } from "./Data/GameFlowConfig";
  7. import Game_Gameing_Flow from "./Game_Gameing_Flow";
  8. import Game_Hall_Flow from "./Game_Hall_Flow";
  9. import { Game_Hall_Precondition } from "./Game_Hall_Precondition";
  10. import Game_InitLoad_Flow from "./Game_InitLoad_Flow";
  11. import Game_Login_Flow from "./Game_Login_Flow";
  12. import Game_Over_Flow from "./Game_Over_Flow";
  13. import { GameFlowTree_Precondition } from "./GameFlowTree_Precondition";
  14. import Game_WaitStart_Flow from "./Game_WaitStart_Flow";
  15. import { _IBehaviorTreeConfig } from "../../Engine/Data/CommonDataType";
  16. /**
  17. * 游戏流程树 - 逻辑层
  18. */
  19. export default class GameFlowTree extends BasicTreeControlNode {
  20. constructor (node: cc.Node, flowTreeConfig: _IBehaviorTreeConfig) {
  21. let GameFlowComponent = {
  22. "Login": Game_Login_Flow,
  23. "InitLoad": Game_InitLoad_Flow,
  24. "Hall": Game_Hall_Flow,
  25. "WaitStart": Game_WaitStart_Flow,
  26. "Gameing": Game_Gameing_Flow,
  27. "Over": Game_Over_Flow,
  28. };
  29. let data: Array<_EGameFlow> = Object.values(_EGameFlow);
  30. let controls = new Map<_EGameFlow, BasicTreeBehaviorNode>();
  31. for (let index in data) {
  32. let key = data[index];
  33. let control: any = GameFlowComponent[key];
  34. if (control != null) {
  35. let precondition: GameFlowTree_Precondition = new GameFlowTree_Precondition(flowTreeConfig.priority[key]);
  36. ConstObject.CreatePrecondition(precondition, data)
  37. controls.set(key, new control(node, _EGameFlow[key], precondition));
  38. }
  39. }
  40. super(node, "", ConstObject.GameFlowTreeID, flowTreeConfig, controls);
  41. EventManager.onEvent(GameEventName.Game_GetGameFlow, this, this.onGetGameFlow);
  42. }
  43. protected _enterFail (): void {
  44. }
  45. protected _enterAgain (): void {
  46. }
  47. /**获得当前游戏流程 */
  48. private onGetGameFlow (callback: Function): void {
  49. callback && callback(this.currentChilds.pop());
  50. }
  51. }