|
|
@@ -841,6 +841,76 @@ export class InGameManager extends Component {
|
|
|
this.updateEnergyBar();
|
|
|
console.log('[InGameManager] 能量系统重置完成');
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 清理游戏数据,为返回主页面做准备
|
|
|
+ * 当游戏胜利或失败返回主页面时调用
|
|
|
+ */
|
|
|
+ private cleanupGameDataForMainMenu() {
|
|
|
+ console.log('[InGameManager] 开始清理游戏数据,准备返回主页面');
|
|
|
+
|
|
|
+ const eventBus = EventBus.getInstance();
|
|
|
+
|
|
|
+ // 1. 清空场上的所有游戏对象
|
|
|
+ console.log('[InGameManager] 清空场上敌人、方块、球');
|
|
|
+ eventBus.emit(GameEvents.CLEAR_ALL_ENEMIES); // 清空所有敌人
|
|
|
+ eventBus.emit(GameEvents.CLEAR_ALL_BULLETS); // 清空所有子弹
|
|
|
+ eventBus.emit(GameEvents.CLEAR_ALL_GAME_OBJECTS); // 清空其他游戏对象
|
|
|
+
|
|
|
+ // 2. 重置能量系统
|
|
|
+ console.log('[InGameManager] 重置能量系统');
|
|
|
+ this.energyPoints = 0;
|
|
|
+ this.updateEnergyBar();
|
|
|
+
|
|
|
+ // 3. 清空技能选择数据(重置临时技能状态)
|
|
|
+ console.log('[InGameManager] 清空技能选择数据');
|
|
|
+ if (SkillManager.getInstance()) {
|
|
|
+ // 重置技能管理器中的临时技能状态
|
|
|
+ const skillManager = SkillManager.getInstance();
|
|
|
+ const allSkills = skillManager.getAllSkillsData();
|
|
|
+ allSkills.forEach(skill => {
|
|
|
+ skillManager.setSkillLevel(skill.id, 0); // 重置所有技能等级为0
|
|
|
+ });
|
|
|
+ }
|
|
|
+
|
|
|
+ // 4. 重置关卡数据和游戏状态
|
|
|
+ console.log('[InGameManager] 重置关卡数据和游戏状态');
|
|
|
+ this.currentWave = 1;
|
|
|
+ this.currentWaveEnemyCount = 0;
|
|
|
+ this.currentWaveTotalEnemies = 0;
|
|
|
+ this.enemiesKilled = 0;
|
|
|
+ this.totalEnemiesSpawned = 0;
|
|
|
+ this.levelTotalEnemies = 0;
|
|
|
+ this.levelWaves = [];
|
|
|
+ this.gameStarted = false;
|
|
|
+ this.enemySpawningStarted = false;
|
|
|
+ this.preparingNextWave = false;
|
|
|
+ this.pendingSkillSelection = false;
|
|
|
+ this.pendingBlockSelection = false;
|
|
|
+ this.shouldShowNextWavePrompt = false;
|
|
|
+
|
|
|
+ // 5. 重置UI状态
|
|
|
+ console.log('[InGameManager] 重置UI状态');
|
|
|
+ if (this.selectSkillUI) {
|
|
|
+ this.selectSkillUI.active = false;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 6. 清理会话数据(金币等临时数据)
|
|
|
+ console.log('[InGameManager] 清理会话数据');
|
|
|
+ if (LevelSessionManager.inst) {
|
|
|
+ LevelSessionManager.inst.clear(); // 清空局内金币等临时数据
|
|
|
+ }
|
|
|
+
|
|
|
+ // 7. 通过事件系统通知其他组件进行清理
|
|
|
+ eventBus.emit(GameEvents.RESET_BALL_CONTROLLER); // 重置球控制器
|
|
|
+ eventBus.emit(GameEvents.RESET_BLOCK_MANAGER); // 重置方块管理器
|
|
|
+ eventBus.emit(GameEvents.RESET_BLOCK_SELECTION); // 重置方块选择
|
|
|
+ eventBus.emit(GameEvents.RESET_ENEMY_CONTROLLER); // 重置敌人控制器
|
|
|
+ eventBus.emit(GameEvents.RESET_WALL_HEALTH); // 重置墙体血量
|
|
|
+ eventBus.emit(GameEvents.RESET_UI_STATES); // 重置UI状态
|
|
|
+
|
|
|
+ console.log('[InGameManager] 游戏数据清理完成,可以安全返回主页面');
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 重置游戏状态(供ReStartGame调用)
|
|
|
@@ -858,6 +928,14 @@ export class InGameManager extends Component {
|
|
|
this.checkTimer = 0;
|
|
|
console.log('[InGameManager] 游戏状态重置完成');
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 手动触发游戏数据清理(供外部调用)
|
|
|
+ * 可以在返回主菜单按钮点击时调用
|
|
|
+ */
|
|
|
+ public triggerGameDataCleanup() {
|
|
|
+ this.cleanupGameDataForMainMenu();
|
|
|
+ }
|
|
|
|
|
|
/**
|
|
|
* 应用关卡配置
|