Files
ai_game/client/js/scenes/SceneManager.js

59 lines
1.3 KiB
JavaScript

/**
* 场景管理器
*/
import HomeScene from './HomeScene';
import StoryScene from './StoryScene';
import EndingScene from './EndingScene';
import ProfileScene from './ProfileScene';
import ChapterScene from './ChapterScene';
import AICreateScene from './AICreateScene';
export default class SceneManager {
constructor(main) {
this.main = main;
this.currentScene = null;
this.scenes = {
home: HomeScene,
story: StoryScene,
ending: EndingScene,
profile: ProfileScene,
chapter: ChapterScene,
aiCreate: AICreateScene
};
}
/**
* 切换场景
*/
switchScene(sceneName, params = {}) {
const SceneClass = this.scenes[sceneName];
if (!SceneClass) {
console.error('场景不存在:', sceneName);
return;
}
// 销毁当前场景
if (this.currentScene && this.currentScene.destroy) {
this.currentScene.destroy();
}
// 创建新场景
this.currentScene = new SceneClass(this.main, params);
// 初始化场景
if (this.currentScene.init) {
this.currentScene.init();
}
console.log('切换到场景:', sceneName);
}
/**
* 获取当前场景名称
*/
getCurrentSceneName() {
if (!this.currentScene) return null;
return this.currentScene.constructor.name;
}
}