forked from OpenWebGAL/WebGAL
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
0a8fc81
commit e5abab0
Showing
9 changed files
with
152 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -38,7 +38,7 @@ export const nextSentence = () => { | |
} | ||
} | ||
|
||
scriptExecutor(); | ||
scriptExecutor(-1); | ||
return; | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,64 +1,24 @@ | ||
import { runtime_currentBacklog } from '../../runtime/backlog'; | ||
import { initSceneData, runtime_currentSceneData } from '../../runtime/sceneData'; | ||
import { runtime_gamePlay } from '../../runtime/gamePlay'; | ||
import { getRef } from '../../store/storeRef'; | ||
import { assetSetter, fileType } from '../../util/assetSetter'; | ||
import { sceneFetcher } from '../../util/sceneFetcher'; | ||
import { sceneParser } from '../../parser/sceneParser'; | ||
import { nextSentence } from './nextSentence'; | ||
import * as _ from 'lodash'; | ||
import { initState } from '../../store/stage'; | ||
import { IStageState } from '../../interface/stateInterface/stageInterface'; | ||
import {runtime_currentSceneData} from '../../runtime/sceneData'; | ||
import {getRef} from '../../store/storeRef'; | ||
import {assetSetter, fileType} from '../../util/assetSetter'; | ||
import {sceneFetcher} from '../../util/sceneFetcher'; | ||
import {sceneParser} from '../../parser/sceneParser'; | ||
import {eventSender} from "@/Core/controller/eventBus/eventSender"; | ||
import {resetStage} from "@/Core/util/resetStage"; | ||
|
||
/** | ||
* 从头开始游戏 | ||
*/ | ||
export const startGame = () => { | ||
/* | ||
清空运行时 | ||
*/ | ||
runtime_currentBacklog.splice(0, runtime_currentBacklog.length); // 清空backlog | ||
// 清空sceneData,并重新获取 | ||
runtime_currentSceneData.currentSentenceId = 0; | ||
runtime_currentSceneData.sceneStack = []; | ||
runtime_currentSceneData.currentScene = initSceneData.currentScene; | ||
|
||
// 清空所有演出和timeOut | ||
for (const e of runtime_gamePlay.performList) { | ||
e.stopFunction(); | ||
} | ||
runtime_gamePlay.performList = []; | ||
for (const e of runtime_gamePlay.timeoutList) { | ||
clearTimeout(e); | ||
} | ||
runtime_gamePlay.timeoutList = []; | ||
runtime_gamePlay.isAuto = false; | ||
runtime_gamePlay.isFast = false; | ||
const autoInterval = runtime_gamePlay.autoInterval; | ||
if (autoInterval !== null) clearInterval(autoInterval); | ||
runtime_gamePlay.autoInterval = null; | ||
const fastInterval = runtime_gamePlay.fastInterval; | ||
if (fastInterval !== null) clearInterval(fastInterval); | ||
runtime_gamePlay.fastInterval = null; | ||
const autoTimeout = runtime_gamePlay.autoTimeout; | ||
if (autoTimeout !== null) clearInterval(autoTimeout); | ||
runtime_gamePlay.autoTimeout = null; | ||
|
||
// 清空舞台状态表 | ||
const initSceneDataCopy = _.cloneDeep(initState); | ||
for (const k in initSceneDataCopy) { | ||
if (initSceneDataCopy.hasOwnProperty(k)) { | ||
getRef('stageRef').setStage(k as keyof IStageState, initSceneDataCopy[k as keyof IStageState]); | ||
} | ||
} | ||
resetStage(true); | ||
|
||
// 重新获取初始场景 | ||
const sceneUrl: string = assetSetter('start.txt', fileType.scene); | ||
// 场景写入到运行时 | ||
sceneFetcher(sceneUrl).then((rawScene) => { | ||
runtime_currentSceneData.currentScene = sceneParser(rawScene, 'start.txt', sceneUrl); | ||
// 开始第一条语句 | ||
eventSender('nextSentence_target', 0, 0); | ||
}); | ||
getRef('GuiRef').setVisibility('showTitle', false); | ||
// 开始第一条语句 | ||
nextSentence(); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
import {scriptExecutor} from "@/Core/controller/gamePlay/scriptExecutor"; | ||
|
||
export const bindExtraFunc = () => { | ||
(window as any).jmpToSentence = scriptExecutor; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import {runtime_currentBacklog} from "@/Core/runtime/backlog"; | ||
import {initSceneData, runtime_currentSceneData} from "@/Core/runtime/sceneData"; | ||
import {runtime_gamePlay} from "@/Core/runtime/gamePlay"; | ||
import * as _ from "lodash"; | ||
import {initState} from "@/Core/store/stage"; | ||
import {getRef} from "@/Core/store/storeRef"; | ||
import {IStageState} from "@/Core/interface/stateInterface/stageInterface"; | ||
|
||
export const resetStage = (resetBacklog: boolean) => { | ||
/** | ||
* 清空运行时 | ||
*/ | ||
if (resetBacklog) { | ||
runtime_currentBacklog.splice(0, runtime_currentBacklog.length); // 清空backlog | ||
} | ||
// 清空sceneData,并重新获取 | ||
runtime_currentSceneData.currentSentenceId = 0; | ||
runtime_currentSceneData.sceneStack = []; | ||
runtime_currentSceneData.currentScene = initSceneData.currentScene; | ||
|
||
// 清空所有演出和timeOut | ||
for (const e of runtime_gamePlay.performList) { | ||
e.stopFunction(); | ||
} | ||
runtime_gamePlay.performList = []; | ||
for (const e of runtime_gamePlay.timeoutList) { | ||
clearTimeout(e); | ||
} | ||
runtime_gamePlay.timeoutList = []; | ||
runtime_gamePlay.isAuto = false; | ||
runtime_gamePlay.isFast = false; | ||
const autoInterval = runtime_gamePlay.autoInterval; | ||
if (autoInterval !== null) clearInterval(autoInterval); | ||
runtime_gamePlay.autoInterval = null; | ||
const fastInterval = runtime_gamePlay.fastInterval; | ||
if (fastInterval !== null) clearInterval(fastInterval); | ||
runtime_gamePlay.fastInterval = null; | ||
const autoTimeout = runtime_gamePlay.autoTimeout; | ||
if (autoTimeout !== null) clearInterval(autoTimeout); | ||
runtime_gamePlay.autoTimeout = null; | ||
|
||
// 清空舞台状态表 | ||
const initSceneDataCopy = _.cloneDeep(initState); | ||
for (const k in initSceneDataCopy) { | ||
if (initSceneDataCopy.hasOwnProperty(k)) { | ||
getRef('stageRef').setStage(k as keyof IStageState, initSceneDataCopy[k as keyof IStageState]); | ||
} | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
import {getRef} from "@/Core/store/storeRef"; | ||
import {resetStage} from "@/Core/util/resetStage"; | ||
import {assetSetter, fileType} from "@/Core/util/assetSetter"; | ||
import {sceneFetcher} from "@/Core/util/sceneFetcher"; | ||
import {runtime_currentSceneData} from "@/Core/runtime/sceneData"; | ||
import {sceneParser} from "@/Core/parser/sceneParser"; | ||
import {scriptExecutor} from "@/Core/controller/gamePlay/scriptExecutor"; | ||
import {logger} from "./logger"; | ||
|
||
export const syncWithOrigine = (str: string) => { | ||
const strLst = str.split(' '); | ||
const scene = strLst[1].replace(/json/g, 'txt'); | ||
const sentenceID = parseInt(strLst[2], 10); | ||
logger.warn('正在跳转到' + scene + ':' + sentenceID); | ||
const guiRef = getRef('GuiRef'); | ||
guiRef.setVisibility('showTitle', false); | ||
guiRef.setVisibility('showMenuPanel', false); | ||
resetStage(true); | ||
// 重新获取初始场景 | ||
const sceneUrl: string = assetSetter(scene, fileType.scene); | ||
// 场景写入到运行时 | ||
sceneFetcher(sceneUrl).then((rawScene) => { | ||
runtime_currentSceneData.currentScene = sceneParser(rawScene, 'start.txt', sceneUrl); | ||
// 开始快进到指定语句 | ||
scriptExecutor(sentenceID); | ||
}); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import {logger} from "./logger"; | ||
import {syncWithOrigine} from "@/Core/util/syncWithOrigine"; | ||
|
||
export const webSocketFunc = () => { | ||
try { | ||
const loc: string = window.location.hostname; | ||
const wsUrl = `ws://${loc}:9999`; | ||
logger.info('正在启动socket连接位于:' + wsUrl); | ||
const socket = new WebSocket(wsUrl); | ||
socket.onopen = () => { | ||
logger.info('socket已连接'); | ||
socket.send(' WebGAL 已和 Terre 建立连接。'); | ||
}; | ||
socket.onmessage = e => { | ||
logger.info('收到信息', e.data); | ||
const str: string = e.data; | ||
if (str.match('jmp')) { | ||
syncWithOrigine(str); | ||
} | ||
}; | ||
} catch (e) { | ||
logger.warn('ws连接失败'); | ||
} | ||
}; |