nestConditionMgr.ts 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. import { SmallLevelItem } from "../cfg/smallLevelItem";
  2. import { GameSysLogic } from "../update/gameSysLogic";
  3. import { NestCondition } from "./nestCondition";
  4. export class NestConditionMgr {
  5. conditionArr: NestCondition[] = [];
  6. cnt = 0;
  7. call: Function;
  8. init(levelData: SmallLevelItem){
  9. for (let index = 2; index <= 6; index++) {
  10. let nestKey = `nest${index}`;
  11. let intervalKey = `interval${index}`;
  12. if(levelData.data[nestKey] == '' || levelData.data[intervalKey] == '') break;
  13. let condition = new NestCondition();
  14. condition.name = `interval-${index}`;
  15. condition.fill(levelData.data[intervalKey]);
  16. this.conditionArr.push(condition);
  17. }
  18. }
  19. start(){
  20. this.cnt = 0;
  21. this.do();
  22. }
  23. destroy(){
  24. this.conditionArr.forEach(v=>{v.end()})
  25. this.conditionArr = [];
  26. }
  27. do(){
  28. if(this.cnt >= this.conditionArr.length) return;
  29. let condition = this.conditionArr[this.cnt];
  30. condition.call = ()=>{
  31. this.call && this.call(this.cnt);
  32. this.cnt ++;
  33. this.do();
  34. }
  35. condition.start();
  36. }
  37. isDone(){
  38. return this.cnt >= this.conditionArr.length;
  39. }
  40. }