import { LQCollide } from "./Collide/lq_collide_system/lq_collide"; import { ConfigConst } from "./game/cfg/ConfigDef"; import { ConfigMgr } from "./game/cfg/configMgr"; import { SmallLevelItem } from "./game/cfg/smallLevelItem"; import { Utils } from "./game/common/utils"; import levelempty from "./game/level/levelempty"; import { NestPlay } from "./game/nest/nestPlay"; import { ResMgr } from "./game/res/resMgr"; import { GameSysLogic } from "./game/update/gameSysLogic"; /** * 1 关卡有多个 飞机巢穴 * 2 一个飞机巢穴属性:动画,位置,怪物 * 类型1 数量,时间间隔,延时 */ let pass = 5; enum LevelState { none, loading, playing, } /** * 1 切换关卡 */ export class LevelMgr extends GameSysLogic { parent: cc.Node; title: cc.Label; passCnt: number = 0; state = LevelState.none; private static _inst: LevelMgr; public static get inst(): LevelMgr { if (this._inst == null) { this._inst = new LevelMgr(); this._inst.init(); } return this._inst; } init(){ } updateSec(dt){ if(this.state != LevelState.playing) return; if(this.parent.getComponentsInChildren(LQCollide).length > 0) return; this.next(); } async begin(){ this.passCnt = 0; pass = ConfigMgr.inst.getCfgKeys(ConfigConst.smallLevel).length; this.load(); } load(){ this.title.string = `level${this.passCnt + 1}`; this.loadSmallLevel(); } async loadSmallLevel(){ this.parent.destroyAllChildren(); this.state = LevelState.loading let node = await ResMgr.inst.loadPrefab(`level/levelEmpty`, this.parent); let levelView = node.getComponent(levelempty); let levelData = ConfigMgr.inst.getCfgClassById(ConfigConst.smallLevel, this.passCnt+1, SmallLevelItem); let nestPos = levelData.getNestId(); let task = []; nestPos.forEach(v=>{ let nestNode = Utils.createNode(levelView.$top_node, 'nest'); let p = this.fillNest(nestNode, v); task.push(p); }); await Promise.all(task); this.state = LevelState.playing; } async fillNest(nestNode: cc.Node, id: string){ let nestPlay = nestNode.addComponent(NestPlay); await nestPlay.init(id); await nestPlay.waitDone(); } skip(num: number){ cc.log('skip-', num); if(num > pass) return; if(num < 1) return; this.passCnt = num-1; this.load(); } next(){ if(this.passCnt + 1 >= pass) return; this.passCnt ++; this.load(); } pre(){ if(this.passCnt <= 0) return; this.passCnt--; this.load(); } getMax(){ return pass; } private loadPrefabLevel() { this.state = LevelState.loading this.title.string = `level${this.passCnt + 1}`; this.parent.destroyAllChildren(); ResMgr.inst.loadPrefab(`level/level${this.passCnt + 1}`, this.parent).then(()=>{ this.state = LevelState.playing; }); } }