-
-
Notifications
You must be signed in to change notification settings - Fork 339
Expand file tree
/
Copy pathchangeScene.ts
More file actions
49 lines (47 loc) · 1.83 KB
/
changeScene.ts
File metadata and controls
49 lines (47 loc) · 1.83 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import { sceneFetcher } from './sceneFetcher';
import { sceneParser } from '../../parser/sceneParser';
import { logger } from '../../util/logger';
import { nextSentence } from '@/Core/controller/gamePlay/nextSentence';
import uniqWith from 'lodash/uniqWith';
import { scenePrefetcher } from '@/Core/util/prefetcher/scenePrefetcher';
import { WebGAL } from '@/Core/WebGAL';
import { arg } from './sceneInterface';
import { stageActions } from '@/store/stageReducer';
import { webgalStore } from '@/store/store';
/**
* 切换场景
* @param sceneUrl 场景路径
* @param sceneName 场景名称
* @param args 场景参数
*/
export const changeScene = (sceneUrl: string, sceneName: string, args: Array<arg>) => {
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;
// 开始场景的预加载
const subSceneList = WebGAL.sceneManager.sceneData.currentScene.subSceneList;
WebGAL.sceneManager.settledScenes.push(sceneUrl); // 放入已加载场景列表,避免递归加载相同场景
const subSceneListUniq = uniqWith(subSceneList); // 去重
scenePrefetcher(subSceneListUniq);
logger.debug('现在切换场景,切换后的结果:', WebGAL.sceneManager.sceneData);
WebGAL.sceneManager.lockSceneWrite = false;
// 写入场景调用参数
webgalStore.dispatch(
stageActions.addSceneArgument({
url: sceneUrl,
value: args,
}),
);
nextSentence();
})
.catch((e) => {
logger.error('场景调用错误', e);
WebGAL.sceneManager.lockSceneWrite = false;
});
};