UNPKG

skynovel

Version:
215 lines 8.51 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); const CmnLib_1 = require("./CmnLib"); const Config_1 = require("./Config"); const Grammar_1 = require("./Grammar"); const AnalyzeTagArg_1 = require("./AnalyzeTagArg"); const PropParser_1 = require("./PropParser"); const DebugMng_1 = require("./DebugMng"); const Variable_1 = require("./Variable"); const SoundMng_1 = require("./SoundMng"); const LayerMng_1 = require("./LayerMng"); const EventMng_1 = require("./EventMng"); const ScriptIterator_1 = require("./ScriptIterator"); const pixi_js_1 = require("pixi.js"); class Main { constructor(sys) { this.sys = sys; this.hTag = Object.create(null); this.fncNext = () => { }; this.alzTagArg = new AnalyzeTagArg_1.AnalyzeTagArg; this.inited = false; this.fncTicker = () => { this.fncNext(); this.dbgMng.update(); }; this.fncresume = (fnc = this.runAnalyze) => { if (this.destroyed) return; this.layMng.clearBreak(); this.fncNext = fnc; this.resume = (fnc = this.runAnalyze) => { this.fncNext = fnc; }; this.scrItr.noticeBreak(false); }; this.resume = this.fncresume; this.stop = () => { this.fncNext = () => { }; this.resume = this.fncresume; this.scrItr.noticeBreak(true); }; this.pauseDev = () => this.appPixi.stop(); this.resumeDev = () => this.appPixi.start(); this.destroyed = false; this.isDestroyed = () => this.destroyed; pixi_js_1.utils.skipHello(); this.cfg = new Config_1.Config(sys, () => { var _a; const hApp = { width: this.cfg.oCfg.window.width, height: this.cfg.oCfg.window.height, backgroundColor: this.cfg.oCfg.init.bg_color, resolution: (_a = window.devicePixelRatio) !== null && _a !== void 0 ? _a : 1, autoResize: true, }; const cvs = document.getElementById(CmnLib_1.CmnLib.SN_ID); if (cvs) { this.clone_cvs = cvs.cloneNode(true); this.clone_cvs.id = CmnLib_1.CmnLib.SN_ID; hApp.view = cvs; } this.appPixi = new pixi_js_1.Application(hApp); if (!cvs) { document.body.appendChild(this.appPixi.view); this.appPixi.view.id = CmnLib_1.CmnLib.SN_ID; } this.val = new Variable_1.Variable(this.cfg, this.hTag); this.prpPrs = new PropParser_1.PropParser(this.val); this.sys.init(this.cfg, this.hTag, this.appPixi, this.val, this); this.hTag['title']({ text: this.cfg.oCfg.book.title || 'SKYNovel' }); this.sndMng = new SoundMng_1.SoundMng(this.cfg, this.hTag, this.val, this, this.sys); this.scrItr = new ScriptIterator_1.ScriptIterator(this.cfg, this.hTag, this, this.val, this.alzTagArg, () => this.runAnalyze(), this.prpPrs, this.sndMng, this.sys); this.dbgMng = new DebugMng_1.DebugMng(this.sys, this.hTag, this.scrItr); this.layMng = new LayerMng_1.LayerMng(this.cfg, this.hTag, this.appPixi, this.val, this, this.scrItr, this.sys); this.evtMng = new EventMng_1.EventMng(this.cfg, this.hTag, this.appPixi, this, this.layMng, this.val, this.sndMng, this.scrItr); this.appPixi.ticker.add(this.fncTicker); this.resumeByJumpOrCall({ fn: 'main' }); this.inited = true; }); } errScript(mes, isThrow = true) { this.stop(); DebugMng_1.DebugMng.myTrace(mes); if (CmnLib_1.CmnLib.debugLog) console.log('🍜 SKYNovel err!'); if (isThrow) throw mes; } resumeByJumpOrCall(hArg) { var _a, _b; if (hArg.url) { window.open(hArg.url); return; } this.val.setVal_Nochk('tmp', 'sn.eventArg', (_a = hArg.arg) !== null && _a !== void 0 ? _a : ''); this.val.setVal_Nochk('tmp', 'sn.eventLabel', (_b = hArg.label) !== null && _b !== void 0 ? _b : ''); if (CmnLib_1.CmnLib.argChk_Boolean(hArg, 'call', false)) { this.scrItr.subIdxToken(); this.resume(() => this.hTag.call(hArg)); } else { this.hTag.clear_event({}); this.resume(() => this.hTag.jump(hArg)); } } runAnalyze() { while (true) { let token = this.scrItr.nextToken(); if (!token) break; const uc = token.charCodeAt(0); if (this.cfg.oCfg.debug.token) console.log(`🌱 トークン fn:${this.scrItr.scriptFn} lnum:${this.scrItr.lineNum} uc:${uc} token<${token}>`); if (uc == 9) continue; if (uc == 10) { this.evtMng.cr(token.length); continue; } if (uc == 91) { try { if (this.scrItr.タグ解析(token)) { this.stop(); break; } continue; } catch (err) { let mes = ''; if (err instanceof Error) { const e = err; mes = 'タグ解析中例外 mes=' + e.message + '(' + e.name + ')'; const a_tag = Grammar_1.Grammar.REG_TAG.exec(token); if (a_tag != null) mes = '[' + a_tag.name + ']' + mes; } else { mes = err; } this.errScript(mes, false); return; } } if (uc == 38) { try { if (token.substr(-1) != '&') { const o = Grammar_1.Grammar.splitAmpersand(token.slice(1)); o.name = this.prpPrs.getValAmpersand(o.name); o.text = String(this.prpPrs.parse(o.text)); this.hTag.let(o); continue; } if (token.charAt(1) == '&') throw new Error('「&表示&」書式では「&」指定が不要です'); token = String(this.prpPrs.parse(token.slice(1, -1))); } catch (err) { let mes = ''; if (err instanceof Error) { const e = err; mes = '& 変数操作・変数表示 mes=' + e.message + '(' + e.name + ')'; } else { mes = err; } this.errScript(mes, false); return; } } else if (uc == 59) continue; else if ((uc == 42) && (token.length > 1)) continue; try { const tl = this.layMng.getCurrentTxtlayForeNeedErr(); tl.tagCh(token); } catch (err) { let mes = ''; if (err instanceof Error) { const e = err; mes = '文字表示 mes=' + e.message + '(' + e.name + ')'; } else { mes = err; } this.errScript(mes, false); return; } } } async destroy(ms_late = 0) { if (this.destroyed) return; this.destroyed = true; if (!this.inited) return; await this.layMng.before_destroy(); if (ms_late > 0) await new Promise(r => setTimeout(r, ms_late)); this.stop(); this.hTag = {}; this.evtMng.destroy(); this.layMng.destroy(); this.dbgMng.destroy(); this.appPixi.ticker.remove(this.fncTicker); if (this.clone_cvs && this.appPixi) { this.appPixi.view.parentElement.insertBefore(this.clone_cvs, this.appPixi.view); } pixi_js_1.utils.clearTextureCache(); this.appPixi.destroy(true); } } exports.Main = Main; //# sourceMappingURL=Main.js.map