From 70967374d8e54fc92a7bfd47aa59ce11880632a6 Mon Sep 17 00:00:00 2001 From: Student Main Date: Sun, 25 Nov 2018 21:34:35 +0800 Subject: [PATCH] fix (?) vm logic --- src/index.js | 30 ++++++++++++++++++++++-------- src/ksvm.js | 34 +++++++++++++++------------------- src/runtime.js | 45 ++++++++++++++++++++++++--------------------- 3 files changed, 61 insertions(+), 48 deletions(-) diff --git a/src/index.js b/src/index.js index bd6a717..2aad858 100644 --- a/src/index.js +++ b/src/index.js @@ -1,17 +1,16 @@ +import AsyncTask from "./async/asynctask"; import Character from "./character"; import KSVM from "./ksvm"; import ObjectMapper from './objectmapper'; -import Runtime from "./runtime"; +import TJSVM from "./tjsvm"; import YZBgImg from "./ui/bgimg"; +import YZCG from "./ui/cg"; import YZSound from "./ui/sound"; import YZText from "./ui/text"; -import AsyncTask from "./async/asynctask"; +import YZVideo from "./ui/video"; import FilePath from './utils/filepath'; import KSParser from "./utils/ksparser"; import TJSON from "./utils/tjson"; -import Preloader from "./async/preload"; -import YZCG from "./ui/cg"; -import YZVideo from "./ui/video"; async function LoadVMData() { //Unicode 万国码 @@ -37,8 +36,22 @@ async function LoadVMData() { return; } -TJSVM.addObject('f'); -TJSVM.addObject('sf'); +TJSVM.addObject('f', { + sak_flag: 0, + rur_flag: 0, + san_flag: 0, + aoi_flag: 0, + mah_flag: 0, + yuk_flag: 0, +}); +TJSVM.addObject('sf', { + sakuya_clear: false, + ruri_clear: false, + sana_clear: false, + aoi_clear: false, + mahiro_clear: false, + yukari_clear: false, +}); TJSVM.addObject('kag'); $(document).ready(async () => { @@ -50,8 +63,9 @@ $(document).ready(async () => { YZVideo.Init(); AsyncTask.Init(); await LoadVMData(); - KSVM.RunFrom('start'); $(document).click(() => KSVM.Next()); + KSVM.RunFrom('start'); + KSVM.Next(); let preloadps = []; // TODO: let vm cache module load other script let scripts = Object.keys(FilePath.ls('scenario')); diff --git a/src/ksvm.js b/src/ksvm.js index 39ace1f..4f4b86a 100644 --- a/src/ksvm.js +++ b/src/ksvm.js @@ -1,17 +1,5 @@ -import Runtime from "./runtime"; import AsyncTask from "./async/asynctask"; -import TJSVM from './tjsvm'; - -// when to hang up vm -let VM_STEP = 0; -let VM_SCENE = 1; -let VM_SELECT = 2; -let VM_NEVER = 3; -// vm display mode -let VM_NORMAL = 0; // standard mode -let VM_AUTO = 1; // wait for voice end -let VM_QUICK = 2; // fixed interval -let VM_NONE = 3; // no output +import Runtime from "./runtime"; const VMMode = { Step: 0, // stop per step @@ -23,7 +11,7 @@ const VMMode = { export default class KSVM { static Init() { - this.mode = VMMode.Step; + this.mode = VMMode.Text; this.hang = false; // scripts = {name: script} this.scripts = {}; @@ -83,13 +71,13 @@ export default class KSVM { * @param {String} script script name */ static LocateTag(tag, script) { - script = script.match(/(.+?)\.([^.]*$|$)/i)[1]; + if (script) script = script.split('.')[0]; // No tag, return first line of script if (tag === undefined) { return { script: script, line: 0 }; } const tags = this.tags[tag.substr(1)]; - if (script === undefined) return tags[0]; + if (script === undefined) return (tags || [])[0]; else { for (const t of tags) { if (t.script == script) return t; @@ -120,7 +108,7 @@ export default class KSVM { if (this.runlock) return; this.runlock = true; while (!this.hang) { - if (this.HitBreakPoint(this.currentpos)) debugger; + if (this.CurrentCmd() === undefined) { // too far this.hang = true; @@ -137,8 +125,9 @@ export default class KSVM { // Okay, comand return a new position, lets use it if (next !== undefined) { if (this.mode == VMMode.Step) this.hang = true; + let nextpos = this.LocateTag(next[0], next[1]); + if (nextpos === undefined) debugger; this.currentpos = this.LocateTag(next[0], next[1]); - if (this.currentpos === undefined) debugger; } break; case "text": @@ -152,6 +141,13 @@ export default class KSVM { } break; } + if (this.HitBreakPoint(this.currentpos)) { + this.hang = true; + this.runlock = true; + debugger; + return; + } + if(VMMode.Step) this.hang = true; this.currentpos.line++; } this.runlock = false; @@ -161,13 +157,13 @@ export default class KSVM { static async RunFrom(tag) { this.currentpos = this.tags[tag][0]; this.runlock = false; - await this.Run(); } // VM Control Functions // . static async Next() { this.hang = false; + this.mode = VMMode.Text; AsyncTask.Cancel(); await this.Run(); } diff --git a/src/runtime.js b/src/runtime.js index f239448..1bdd004 100644 --- a/src/runtime.js +++ b/src/runtime.js @@ -1,11 +1,11 @@ // runtime libs import Character from './character'; import ObjectMapper from './objectmapper'; +import TJSVM from './tjsvm'; import YZBgImg from './ui/bgimg'; +import YZCG from './ui/cg'; import YZSound from './ui/sound'; import YZText from './ui/text'; -import TJSVM from './tjsvm'; -import YZCG from './ui/cg'; import YZVideo from './ui/video'; export default class Runtime { @@ -43,13 +43,14 @@ export default class Runtime { // TODO: mselect is Tenshin Ranman only command? // add map select option static MapSelectAdd(cmd) { - this.MapSelectData.push([ - cmd.param.name, - cmd.param.target, - cmd.param.cond, - cmd.param.storage, - cmd.param.place, - ]); + let p = cmd.param; + this.MapSelectData.push({ + name: p.name, + target: p.target, + cond: p.cond, + storage: p.storage, + place: p.place + }); } // raise a map select @@ -58,23 +59,25 @@ export default class Runtime { var n = 0; for (const d of this.MapSelectData) { s += n; - s += d[0]; + s += d.name; s += '\n'; n++; } var r = prompt(s, 0); var ro = this.MapSelectData[r]; this.MapSelectData = []; - return [ro[1], ro[3]]; + if (!ro.target && !ro.storage) return undefined; + return [ro.target, ro.storage]; } static SelectAdd(cmd) { - this.SelectData.push([ - cmd.param.text, - cmd.param.target, - cmd.param.exp, - cmd.param.storage, - ]); + let p = cmd.param; + this.SelectData.push({ + text: p.text, + target: p.target, + exp: p.exp, + storage: p.storage + }); } // raise a normal select @@ -83,16 +86,16 @@ export default class Runtime { var n = 0; for (const d of this.SelectData) { s += n; - s += d[0]; + s += d.text; s += '\n'; n++; } var r = prompt(s, 0); var ro = this.SelectData[r]; - if (ro[2] !== undefined) - TJSVM.eval(ro[2]); + if (ro.exp) TJSVM.eval(ro.exp); this.SelectData = []; - return [ro[1], ro[3]]; + if (!ro.target && !ro.storage) return undefined; + return [ro.target, ro.storage]; } static AddTrans(cmd) {