-
-
Notifications
You must be signed in to change notification settings - Fork 339
Expand file tree
/
Copy pathchangeScene.ts
More file actions
34 lines (32 loc) · 1.26 KB
/
changeScene.ts
File metadata and controls
34 lines (32 loc) · 1.26 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
import { sceneFetcher } from './sceneFetcher';
import { sceneParser } from '../../parser/sceneParser';
import { logger } from '../../util/logger';
import { nextSentence } from '@/Core/controller/gamePlay/nextSentence';
import { clearPrefetchLinks } from '@/Core/util/prefetcher/assetsPrefetcher';
import { WebGAL } from '@/Core/WebGAL';
/**
* 切换场景
* @param sceneUrl 场景路径
* @param sceneName 场景名称
*/
export const changeScene = (sceneUrl: string, sceneName: string) => {
if (WebGAL.sceneManager.lockSceneWrite) {
return;
}
WebGAL.sceneManager.lockSceneWrite = true;
// 场景写入到运行时
sceneFetcher(sceneUrl)
.then((rawScene) => {
WebGAL.sceneManager.sceneData.currentScene = sceneParser(rawScene, sceneName, sceneUrl);
WebGAL.sceneManager.sceneData.currentSentenceId = 0;
clearPrefetchLinks();
WebGAL.sceneManager.settledScenes.add(sceneUrl); // 放入已加载场景列表,避免递归加载相同场景
logger.debug('现在切换场景,切换后的结果:', WebGAL.sceneManager.sceneData);
WebGAL.sceneManager.lockSceneWrite = false;
nextSentence();
})
.catch((e) => {
logger.error('场景调用错误', e);
WebGAL.sceneManager.lockSceneWrite = false;
});
};