diff --git a/libs/events.js b/libs/events.js index 030abdf..c1f0a45 100644 --- a/libs/events.js +++ b/libs/events.js @@ -305,6 +305,7 @@ events.prototype._gameOver_askRate = function (ending) { events.prototype.restart = function () { core.showStartAnimate(); core.playBgm(main.startBgm); + core.resumeBgm(); }; ////// 询问是否需要重新开始 ////// diff --git a/libs/loader.js b/libs/loader.js index 27a5ec4..5b1c885 100644 --- a/libs/loader.js +++ b/libs/loader.js @@ -630,6 +630,7 @@ loader.prototype._loadMusics = function () { }); // 直接开始播放 core.playBgm(main.startBgm); + core.resumeBgm(); }; loader.prototype._loadSounds_sync = function () { diff --git a/libs/utils.js b/libs/utils.js index cd5e576..40fe703 100644 --- a/libs/utils.js +++ b/libs/utils.js @@ -1,4 +1,3 @@ - /* utils.js 工具类 @@ -6,1335 +5,1488 @@ utils.js 工具类 "use strict"; -function utils () { - this._init(); - this.scan = { - 'up': { 'x': 0, 'y': -1 }, - 'left': { 'x': -1, 'y': 0 }, - 'down': { 'x': 0, 'y': 1 }, - 'right': { 'x': 1, 'y': 0 } - }; - this.scan2 = { - 'up': { 'x': 0, 'y': -1 }, - 'left': { 'x': -1, 'y': 0 }, - 'down': { 'x': 0, 'y': 1 }, - 'right': { 'x': 1, 'y': 0 }, - 'leftup': { 'x': -1, 'y': -1 }, - 'leftdown': { 'x': -1, 'y': 1 }, - 'rightup': { 'x': 1, 'y': -1 }, - 'rightdown': { 'x': 1, 'y': 1 } - }; +function utils() { + this._init(); + this.scan = { + up: { x: 0, y: -1 }, + left: { x: -1, y: 0 }, + down: { x: 0, y: 1 }, + right: { x: 1, y: 0 }, + }; + this.scan2 = { + up: { x: 0, y: -1 }, + left: { x: -1, y: 0 }, + down: { x: 0, y: 1 }, + right: { x: 1, y: 0 }, + leftup: { x: -1, y: -1 }, + leftdown: { x: -1, y: 1 }, + rightup: { x: 1, y: -1 }, + rightdown: { x: 1, y: 1 }, + }; } utils.prototype._init = function () { - // -} + // +}; ////// 将文字中的${和}(表达式)进行替换 ////// utils.prototype.replaceText = function (text, prefix) { - if (typeof text != 'string') return text; - var index = text.indexOf("${"); - if (index < 0) return text; - var cnt = 0, curr = index; - while (++curr < text.length) { - if (text.charAt(curr) == '{') cnt++; - if (text.charAt(curr) == '}') cnt--; - if (cnt == 0) break; - } - if (cnt != 0) return text; - var value = core.calValue(text.substring(index + 2, curr), prefix); - if (value == null) value = ""; - return text.substring(0, index) + value + core.replaceText(text.substring(curr + 1), prefix); -} + if (typeof text != "string") return text; + var index = text.indexOf("${"); + if (index < 0) return text; + var cnt = 0, + curr = index; + while (++curr < text.length) { + if (text.charAt(curr) == "{") cnt++; + if (text.charAt(curr) == "}") cnt--; + if (cnt == 0) break; + } + if (cnt != 0) return text; + var value = core.calValue(text.substring(index + 2, curr), prefix); + if (value == null) value = ""; + return ( + text.substring(0, index) + + value + + core.replaceText(text.substring(curr + 1), prefix) + ); +}; utils.prototype.replaceValue = function (value) { - if (typeof value == "string" && (value.indexOf(":") >= 0 || value.indexOf("flag:") >= 0 || value.indexOf('global:') >= 0)) { - if (value.indexOf('status:') >= 0) - value = value.replace(/status:([a-zA-Z0-9_]+)/g, "core.getStatus('$1')"); - if (value.indexOf('buff:') >= 0) - value = value.replace(/buff:([a-zA-Z0-9_]+)/g, "core.getBuff('$1')"); - if (value.indexOf('item:') >= 0) - value = value.replace(/item:([a-zA-Z0-9_]+)/g, "core.itemCount('$1')"); - if (value.indexOf('flag:') >= 0 || value.indexOf('flag:') >= 0) - value = value.replace(/flag[::]([a-zA-Z0-9_\u4E00-\u9FCC\u3040-\u30FF\u2160-\u216B\u0391-\u03C9]+)/g, "core.getFlag('$1', 0)"); - //if (value.indexOf('switch:' >= 0)) - // value = value.replace(/switch:([a-zA-Z0-9_]+)/g, "core.getFlag('" + (prefix || ":f@x@y") + "@$1', 0)"); - if (value.indexOf('global:') >= 0 || value.indexOf('global:') >= 0) - value = value.replace(/global[::]([a-zA-Z0-9_\u4E00-\u9FCC\u3040-\u30FF\u2160-\u216B\u0391-\u03C9]+)/g, "core.getGlobal('$1', 0)"); - if (value.indexOf('enemy:') >= 0) - value = value.replace(/enemy:([a-zA-Z0-9_]+)[\.:]([a-zA-Z0-9_]+)/g, "core.material.enemys['$1'].$2"); - if (value.indexOf('blockId:') >= 0) - value = value.replace(/blockId:(\d+),(\d+)/g, "core.getBlockId($1, $2)"); - if (value.indexOf('blockNumber:') >= 0) - value = value.replace(/blockNumber:(\d+),(\d+)/g, "core.getBlockNumber($1, $2)"); - if (value.indexOf('blockCls:') >= 0) - value = value.replace(/blockCls:(\d+),(\d+)/g, "core.getBlockCls($1, $2)"); - if (value.indexOf('equip:') >= 0) - value = value.replace(/equip:(\d)/g, "core.getEquip($1)"); - if (value.indexOf('temp:') >= 0) - value = value.replace(/temp:([a-zA-Z0-9_]+)/g, "core.getFlag('@temp@$1', 0)"); - } - return value; -} + if ( + typeof value == "string" && + (value.indexOf(":") >= 0 || + value.indexOf("flag:") >= 0 || + value.indexOf("global:") >= 0) + ) { + if (value.indexOf("status:") >= 0) + value = value.replace(/status:([a-zA-Z0-9_]+)/g, "core.getStatus('$1')"); + if (value.indexOf("buff:") >= 0) + value = value.replace(/buff:([a-zA-Z0-9_]+)/g, "core.getBuff('$1')"); + if (value.indexOf("item:") >= 0) + value = value.replace(/item:([a-zA-Z0-9_]+)/g, "core.itemCount('$1')"); + if (value.indexOf("flag:") >= 0 || value.indexOf("flag:") >= 0) + value = value.replace( + /flag[::]([a-zA-Z0-9_\u4E00-\u9FCC\u3040-\u30FF\u2160-\u216B\u0391-\u03C9]+)/g, + "core.getFlag('$1', 0)" + ); + //if (value.indexOf('switch:' >= 0)) + // value = value.replace(/switch:([a-zA-Z0-9_]+)/g, "core.getFlag('" + (prefix || ":f@x@y") + "@$1', 0)"); + if (value.indexOf("global:") >= 0 || value.indexOf("global:") >= 0) + value = value.replace( + /global[::]([a-zA-Z0-9_\u4E00-\u9FCC\u3040-\u30FF\u2160-\u216B\u0391-\u03C9]+)/g, + "core.getGlobal('$1', 0)" + ); + if (value.indexOf("enemy:") >= 0) + value = value.replace( + /enemy:([a-zA-Z0-9_]+)[\.:]([a-zA-Z0-9_]+)/g, + "core.material.enemys['$1'].$2" + ); + if (value.indexOf("blockId:") >= 0) + value = value.replace(/blockId:(\d+),(\d+)/g, "core.getBlockId($1, $2)"); + if (value.indexOf("blockNumber:") >= 0) + value = value.replace( + /blockNumber:(\d+),(\d+)/g, + "core.getBlockNumber($1, $2)" + ); + if (value.indexOf("blockCls:") >= 0) + value = value.replace( + /blockCls:(\d+),(\d+)/g, + "core.getBlockCls($1, $2)" + ); + if (value.indexOf("equip:") >= 0) + value = value.replace(/equip:(\d)/g, "core.getEquip($1)"); + if (value.indexOf("temp:") >= 0) + value = value.replace( + /temp:([a-zA-Z0-9_]+)/g, + "core.getFlag('@temp@$1', 0)" + ); + } + return value; +}; ////// 计算表达式的值 ////// utils.prototype.calValue = function (value, prefix) { - if (!core.isset(value)) return null; - if (typeof value === 'string') { - if (value.indexOf(':') >= 0 || value.indexOf("flag:") >= 0 || value.indexOf('global:') >= 0) { - if (value.indexOf('switch:') >= 0) - value = value.replace(/switch:([a-zA-Z0-9_]+)/g, "core.getFlag('" + (prefix || ":f@x@y") + "@$1', 0)"); - value = this.replaceValue(value); - } - return eval(value); + if (!core.isset(value)) return null; + if (typeof value === "string") { + if ( + value.indexOf(":") >= 0 || + value.indexOf("flag:") >= 0 || + value.indexOf("global:") >= 0 + ) { + if (value.indexOf("switch:") >= 0) + value = value.replace( + /switch:([a-zA-Z0-9_]+)/g, + "core.getFlag('" + (prefix || ":f@x@y") + "@$1', 0)" + ); + value = this.replaceValue(value); } - if (value instanceof Function) { - return value(); - } - return value; -} + return eval(value); + } + if (value instanceof Function) { + return value(); + } + return value; +}; ////// 向某个数组前插入另一个数组或元素 ////// utils.prototype.unshift = function (a, b) { - if (!(a instanceof Array) || b == null) return; - if (b instanceof Array) { - core.clone(b).reverse().forEach(function (e) { - a.unshift(e); - }); - } - else a.unshift(b); - return a; -} + if (!(a instanceof Array) || b == null) return; + if (b instanceof Array) { + core + .clone(b) + .reverse() + .forEach(function (e) { + a.unshift(e); + }); + } else a.unshift(b); + return a; +}; ////// 向某个数组后插入另一个数组或元素 ////// utils.prototype.push = function (a, b) { - if (!(a instanceof Array) || b == null) return; - if (b instanceof Array) { - core.clone(b).forEach(function (e) { - a.push(e); - }); - } - else a.push(b); - return a; -} + if (!(a instanceof Array) || b == null) return; + if (b instanceof Array) { + core.clone(b).forEach(function (e) { + a.push(e); + }); + } else a.push(b); + return a; +}; utils.prototype.decompress = function (value) { - try { - var output = lzw_decode(value); - if (output) return JSON.parse(output); - } - catch (e) { - } - try { - var output = LZString.decompress(value); - if (output) return JSON.parse(output); - } - catch (e) { - } - try { - return JSON.parse(value); - } - catch (e) { - console.error(e); - } - return null; -} + try { + var output = lzw_decode(value); + if (output) return JSON.parse(output); + } catch (e) {} + try { + var output = LZString.decompress(value); + if (output) return JSON.parse(output); + } catch (e) {} + try { + return JSON.parse(value); + } catch (e) { + console.error(e); + } + return null; +}; ////// 设置本地存储 ////// utils.prototype.setLocalStorage = function (key, value) { - try { - if (value == null) { - this.removeLocalStorage(key); - return; - } - - var str = JSON.stringify(value).replace(/[\u007F-\uFFFF]/g, function (chr) { - return "\\u" + ("0000" + chr.charCodeAt(0).toString(16)).substr(-4) - }); - localStorage.setItem(core.firstData.name + "_" + key, str); - - if (key == 'autoSave') core.saves.ids[0] = true; - else if (/^save\d+$/.test(key)) core.saves.ids[parseInt(key.substring(4))] = true; - - return true; + try { + if (value == null) { + this.removeLocalStorage(key); + return; } - catch (e) { - console.error(e); - return false; - } -} + + var str = JSON.stringify(value).replace(/[\u007F-\uFFFF]/g, function (chr) { + return "\\u" + ("0000" + chr.charCodeAt(0).toString(16)).substr(-4); + }); + localStorage.setItem(core.firstData.name + "_" + key, str); + + if (key == "autoSave") core.saves.ids[0] = true; + else if (/^save\d+$/.test(key)) + core.saves.ids[parseInt(key.substring(4))] = true; + + return true; + } catch (e) { + console.error(e); + return false; + } +}; ////// 获得本地存储 ////// utils.prototype.getLocalStorage = function (key, defaultValue) { - try { - var value = JSON.parse(localStorage.getItem(core.firstData.name + "_" + key)); - if (value == null) return defaultValue; - return value; - } catch (e) { - return defaultValue; - } -} + try { + var value = JSON.parse( + localStorage.getItem(core.firstData.name + "_" + key) + ); + if (value == null) return defaultValue; + return value; + } catch (e) { + return defaultValue; + } +}; ////// 移除本地存储 ////// utils.prototype.removeLocalStorage = function (key) { - localStorage.removeItem(core.firstData.name + "_" + key); - if (key == 'autoSave') delete core.saves.ids[0]; - else if (/^save\d+$/.test(key)) delete core.saves.ids[parseInt(key.substring(4))]; -} + localStorage.removeItem(core.firstData.name + "_" + key); + if (key == "autoSave") delete core.saves.ids[0]; + else if (/^save\d+$/.test(key)) + delete core.saves.ids[parseInt(key.substring(4))]; +}; -utils.prototype.setLocalForage = function (key, value, successCallback, errorCallback) { - if (value == null) { - this.removeLocalForage(key); - return; - } +utils.prototype.setLocalForage = function ( + key, + value, + successCallback, + errorCallback +) { + if (value == null) { + this.removeLocalForage(key); + return; + } - var name = core.firstData.name + "_" + key; - var str = JSON.stringify(value).replace(/[\u007F-\uFFFF]/g, function (chr) { - return "\\u" + ("0000" + chr.charCodeAt(0).toString(16)).substr(-4) - }); - var callback = function (err) { - if (err) { - if (errorCallback) errorCallback(err); - } - else { - if (key == 'autoSave') core.saves.ids[0] = true; - else if (/^save\d+$/.test(key)) core.saves.ids[parseInt(key.substring(4))] = true; - if (successCallback) successCallback(); - } + var name = core.firstData.name + "_" + key; + var str = JSON.stringify(value).replace(/[\u007F-\uFFFF]/g, function (chr) { + return "\\u" + ("0000" + chr.charCodeAt(0).toString(16)).substr(-4); + }); + var callback = function (err) { + if (err) { + if (errorCallback) errorCallback(err); + } else { + if (key == "autoSave") core.saves.ids[0] = true; + else if (/^save\d+$/.test(key)) + core.saves.ids[parseInt(key.substring(4))] = true; + if (successCallback) successCallback(); } - this._setLocalForage_set(name, str, callback); -} + }; + this._setLocalForage_set(name, str, callback); +}; utils.prototype._setLocalForage_set = function (name, str, callback) { - if (window.jsinterface && window.jsinterface.setLocalForage) { - var id = setTimeout(null); - core['__callback' + id] = callback; - core.saves.cache[name] = str; - window.jsinterface.setLocalForage(id, name, str); - } else { - var compressed = str.length > 100000 ? LZString.compress(str) : lzw_encode(str); - core.saves.cache[name] = compressed; - localforage.setItem(name, compressed, callback); - } -} + if (window.jsinterface && window.jsinterface.setLocalForage) { + var id = setTimeout(null); + core["__callback" + id] = callback; + core.saves.cache[name] = str; + window.jsinterface.setLocalForage(id, name, str); + } else { + var compressed = + str.length > 100000 ? LZString.compress(str) : lzw_encode(str); + core.saves.cache[name] = compressed; + localforage.setItem(name, compressed, callback); + } +}; -utils.prototype.getLocalForage = function (key, defaultValue, successCallback, errorCallback) { - var name = core.firstData.name + "_" + key; - var callback = function (err, value) { - if (err) { - if (errorCallback) errorCallback(err); - } - else { - core.saves.cache[name] = value; - if (!successCallback) return; - if (value != null) { - var res = core.utils.decompress(value); - successCallback(res == null ? defaultValue : res); - return; - } - successCallback(defaultValue); - } - }; - if (core.saves.cache[name] != null) { - return callback(null, core.saves.cache[name]); +utils.prototype.getLocalForage = function ( + key, + defaultValue, + successCallback, + errorCallback +) { + var name = core.firstData.name + "_" + key; + var callback = function (err, value) { + if (err) { + if (errorCallback) errorCallback(err); + } else { + core.saves.cache[name] = value; + if (!successCallback) return; + if (value != null) { + var res = core.utils.decompress(value); + successCallback(res == null ? defaultValue : res); + return; + } + successCallback(defaultValue); } - this._getLocalForage_get(name, callback); -} + }; + if (core.saves.cache[name] != null) { + return callback(null, core.saves.cache[name]); + } + this._getLocalForage_get(name, callback); +}; utils.prototype._getLocalForage_get = function (name, callback) { - if (window.jsinterface && window.jsinterface.getLocalForage) { - var id = setTimeout(null); - core['__callback' + id] = callback; - window.jsinterface.getLocalForage(id, name); - } else { - localforage.getItem(name, callback); - } -} + if (window.jsinterface && window.jsinterface.getLocalForage) { + var id = setTimeout(null); + core["__callback" + id] = callback; + window.jsinterface.getLocalForage(id, name); + } else { + localforage.getItem(name, callback); + } +}; -utils.prototype.removeLocalForage = function (key, successCallback, errorCallback) { - var name = core.firstData.name + "_" + key; - var callback = function (err) { - if (err) { - if (errorCallback) errorCallback(err); - } - else { - if (key == 'autoSave') delete core.saves.ids[0]; - else if (/^save\d+$/.test(key)) delete core.saves.ids[parseInt(key.substring(4))]; - if (successCallback) successCallback(); - } +utils.prototype.removeLocalForage = function ( + key, + successCallback, + errorCallback +) { + var name = core.firstData.name + "_" + key; + var callback = function (err) { + if (err) { + if (errorCallback) errorCallback(err); + } else { + if (key == "autoSave") delete core.saves.ids[0]; + else if (/^save\d+$/.test(key)) + delete core.saves.ids[parseInt(key.substring(4))]; + if (successCallback) successCallback(); } - delete core.saves.cache[name]; - this._removeLocalForage_remove(name, callback); -} + }; + delete core.saves.cache[name]; + this._removeLocalForage_remove(name, callback); +}; utils.prototype._removeLocalForage_remove = function (name, callback) { - if (window.jsinterface && window.jsinterface.removeLocalForage) { - var id = setTimeout(null); - core['__callback' + id] = callback; - window.jsinterface.removeLocalForage(id, name); - } else { - localforage.removeItem(name, callback); - } -} + if (window.jsinterface && window.jsinterface.removeLocalForage) { + var id = setTimeout(null); + core["__callback" + id] = callback; + window.jsinterface.removeLocalForage(id, name); + } else { + localforage.removeItem(name, callback); + } +}; utils.prototype.clearLocalForage = function (callback) { - core.saves.cache = {}; - if (window.jsinterface && window.jsinterface.clearLocalForage) { - var id = setTimeout(null); - core['__callback' + id] = callback; - window.jsinterface.clearLocalForage(id); - } else { - localforage.clear(callback); - } -} + core.saves.cache = {}; + if (window.jsinterface && window.jsinterface.clearLocalForage) { + var id = setTimeout(null); + core["__callback" + id] = callback; + window.jsinterface.clearLocalForage(id); + } else { + localforage.clear(callback); + } +}; utils.prototype.iterateLocalForage = function (iter, callback) { - if (window.jsinterface && window.jsinterface.iterateLocalForage) { - var id = setTimeout(null); - core['__iter' + id] = iter; - core['__callback' + id] = callback; - window.jsinterface.iterateLocalForage(id); - } else { - localforage.iterate(iter, callback); - } -} + if (window.jsinterface && window.jsinterface.iterateLocalForage) { + var id = setTimeout(null); + core["__iter" + id] = iter; + core["__callback" + id] = callback; + window.jsinterface.iterateLocalForage(id); + } else { + localforage.iterate(iter, callback); + } +}; utils.prototype.keysLocalForage = function (callback) { - if (window.jsinterface && window.jsinterface.keysLocalForage) { - var id = setTimeout(null); - core['__callback' + id] = callback; - window.jsinterface.keysLocalForage(id); - } else { - localforage.keys(callback); - } -} + if (window.jsinterface && window.jsinterface.keysLocalForage) { + var id = setTimeout(null); + core["__callback" + id] = callback; + window.jsinterface.keysLocalForage(id); + } else { + localforage.keys(callback); + } +}; utils.prototype.lengthLocalForage = function (callback) { - if (window.jsinterface && window.jsinterface.lengthLocalForage) { - var id = setTimeout(null); - core['__callback' + id] = callback; - window.jsinterface.lengthLocalForage(id); - } else { - localforage.length(callback); - } -} + if (window.jsinterface && window.jsinterface.lengthLocalForage) { + var id = setTimeout(null); + core["__callback" + id] = callback; + window.jsinterface.lengthLocalForage(id); + } else { + localforage.length(callback); + } +}; utils.prototype.setGlobal = function (key, value) { - if (core.isReplaying()) return; - core.setLocalStorage(key, value); -} + if (core.isReplaying()) return; + core.setLocalStorage(key, value); +}; utils.prototype.getGlobal = function (key, defaultValue) { - var value; - if (core.isReplaying()) { - // 不考虑key不一致的情况 - var action = core.status.replay.toReplay.shift(); - if (action.indexOf("input2:") == 0) { - value = JSON.parse(core.decodeBase64(action.substring(7))); - core.setFlag('__global__' + key, value); - core.status.route.push("input2:" + core.encodeBase64(JSON.stringify(value))); - } - else { - // 录像兼容性:尝试从flag和localStorage获得 - // 注意这里不再二次记录 input2: 到录像 - core.status.replay.toReplay.unshift(action); - value = core.getFlag('__global__' + key, core.getLocalStorage(key, defaultValue)); - } + var value; + if (core.isReplaying()) { + // 不考虑key不一致的情况 + var action = core.status.replay.toReplay.shift(); + if (action.indexOf("input2:") == 0) { + value = JSON.parse(core.decodeBase64(action.substring(7))); + core.setFlag("__global__" + key, value); + core.status.route.push( + "input2:" + core.encodeBase64(JSON.stringify(value)) + ); + } else { + // 录像兼容性:尝试从flag和localStorage获得 + // 注意这里不再二次记录 input2: 到录像 + core.status.replay.toReplay.unshift(action); + value = core.getFlag( + "__global__" + key, + core.getLocalStorage(key, defaultValue) + ); } - else { - value = core.getLocalStorage(key, defaultValue); - core.setFlag('__global__' + key, value); - core.status.route.push("input2:" + core.encodeBase64(JSON.stringify(value))); - } - return value; -} + } else { + value = core.getLocalStorage(key, defaultValue); + core.setFlag("__global__" + key, value); + core.status.route.push( + "input2:" + core.encodeBase64(JSON.stringify(value)) + ); + } + return value; +}; ////// 深拷贝一个对象 ////// utils.prototype.clone = function (data, filter, recursion) { - if (!core.isset(data)) return null; - // date - if (data instanceof Date) { - var copy = new Date(); - copy.setTime(data.getTime()); - return copy; - } - // array - if (data instanceof Array) { - var copy = []; - for (var i in data) { - if (!filter || filter(i, data[i])) - copy[i] = core.clone(data[i], recursion ? filter : null, recursion); - } - return copy; - } - // 函数 - if (data instanceof Function) { - return data; - } - // object - if (data instanceof Object) { - var copy = {}; - for (var i in data) { - if (data.hasOwnProperty(i) && (!filter || filter(i, data[i]))) - copy[i] = core.clone(data[i], recursion ? filter : null, recursion); - } - return copy; + if (!core.isset(data)) return null; + // date + if (data instanceof Date) { + var copy = new Date(); + copy.setTime(data.getTime()); + return copy; + } + // array + if (data instanceof Array) { + var copy = []; + for (var i in data) { + if (!filter || filter(i, data[i])) + copy[i] = core.clone(data[i], recursion ? filter : null, recursion); } + return copy; + } + // 函数 + if (data instanceof Function) { return data; -} + } + // object + if (data instanceof Object) { + var copy = {}; + for (var i in data) { + if (data.hasOwnProperty(i) && (!filter || filter(i, data[i]))) + copy[i] = core.clone(data[i], recursion ? filter : null, recursion); + } + return copy; + } + return data; +}; ////// 深拷贝1D/2D数组优化 ////// utils.prototype.cloneArray = function (data) { - if (!(data instanceof Array)) return this.clone(data); - if (data[0] instanceof Array) { - return data.map(function (one) { return one.slice(); }); - } else { - return data.slice(); - } -} + if (!(data instanceof Array)) return this.clone(data); + if (data[0] instanceof Array) { + return data.map(function (one) { + return one.slice(); + }); + } else { + return data.slice(); + } +}; ////// 裁剪图片 ////// utils.prototype.splitImage = function (image, width, height) { - if (typeof image == "string") { - image = core.getMappedName(image); - image = core.material.images.images[image]; + if (typeof image == "string") { + image = core.getMappedName(image); + image = core.material.images.images[image]; + } + if (!image) return []; + width = width || 32; + height = height || width; + var canvas = document.createElement("canvas"); + var ctx = canvas.getContext("2d"); + var ans = []; + for (var j = 0; j < image.height; j += height) { + for (var i = 0; i < image.width; i += width) { + var w = Math.min(width, image.width - i), + h = Math.min(height, image.height - j); + canvas.width = w; + canvas.height = h; + core.drawImage(ctx, image, i, j, w, h, 0, 0, w, h); + var img = new Image(); + img.src = canvas.toDataURL("image/png"); + ans.push(img); } - if (!image) return []; - width = width || 32; - height = height || width; - var canvas = document.createElement("canvas"); - var ctx = canvas.getContext("2d"); - var ans = []; - for (var j = 0; j < image.height; j += height) { - for (var i = 0; i < image.width; i += width) { - var w = Math.min(width, image.width - i), h = Math.min(height, image.height - j); - canvas.width = w; canvas.height = h; - core.drawImage(ctx, image, i, j, w, h, 0, 0, w, h); - var img = new Image(); - img.src = canvas.toDataURL("image/png"); - ans.push(img); - } - } - return ans; -} + } + return ans; +}; ////// 格式化时间为字符串 ////// utils.prototype.formatDate = function (date) { - if (!date) date = new Date(); - return "" + date.getFullYear() + "-" + core.setTwoDigits(date.getMonth() + 1) + "-" + core.setTwoDigits(date.getDate()) + " " - + core.setTwoDigits(date.getHours()) + ":" + core.setTwoDigits(date.getMinutes()) + ":" + core.setTwoDigits(date.getSeconds()); -} + if (!date) date = new Date(); + return ( + "" + + date.getFullYear() + + "-" + + core.setTwoDigits(date.getMonth() + 1) + + "-" + + core.setTwoDigits(date.getDate()) + + " " + + core.setTwoDigits(date.getHours()) + + ":" + + core.setTwoDigits(date.getMinutes()) + + ":" + + core.setTwoDigits(date.getSeconds()) + ); +}; ////// 格式化时间为最简字符串 ////// utils.prototype.formatDate2 = function (date) { - if (!date) date = new Date(); - return "" + date.getFullYear() + core.setTwoDigits(date.getMonth() + 1) + core.setTwoDigits(date.getDate()) - + core.setTwoDigits(date.getHours()) + core.setTwoDigits(date.getMinutes()) + core.setTwoDigits(date.getSeconds()); -} + if (!date) date = new Date(); + return ( + "" + + date.getFullYear() + + core.setTwoDigits(date.getMonth() + 1) + + core.setTwoDigits(date.getDate()) + + core.setTwoDigits(date.getHours()) + + core.setTwoDigits(date.getMinutes()) + + core.setTwoDigits(date.getSeconds()) + ); +}; utils.prototype.formatTime = function (time) { - return core.setTwoDigits(parseInt(time / 3600000)) - + ":" + core.setTwoDigits(parseInt(time / 60000) % 60) - + ":" + core.setTwoDigits(parseInt(time / 1000) % 60); -} + return ( + core.setTwoDigits(parseInt(time / 3600000)) + + ":" + + core.setTwoDigits(parseInt(time / 60000) % 60) + + ":" + + core.setTwoDigits(parseInt(time / 1000) % 60) + ); +}; ////// 两位数显示 ////// utils.prototype.setTwoDigits = function (x) { - return (parseInt(x) < 10 && parseInt(x) >= 0) ? "0" + x : x; -} + return parseInt(x) < 10 && parseInt(x) >= 0 ? "0" + x : x; +}; utils.prototype.formatSize = function (size) { - if (size < 1024) return size + 'B'; - else if (size < 1024 * 1024) return (size / 1024).toFixed(2) + "KB"; - else return (size / 1024 / 1024).toFixed(2) + "MB"; -} + if (size < 1024) return size + "B"; + else if (size < 1024 * 1024) return (size / 1024).toFixed(2) + "KB"; + else return (size / 1024 / 1024).toFixed(2) + "MB"; +}; utils.prototype.formatBigNumber = function (x, digits) { - if (digits === true) digits = 5; // 兼容旧版onMap参数 - if (!digits || digits < 5) digits = 6; // 连同负号、小数点和后缀字母在内的总位数,至少需为5,默认为6 - x = Math.trunc(parseFloat(x)); // 尝试识别为小数,然后向0取整 - if (x == null || !Number.isFinite(x)) return '???'; // 无法识别的数或正负无穷大,显示'???' - var units = [ // 单位及其后缀字母,可自定义,如改成千进制下的K、M、G、T、P - { "val": 1e4, "suffix": "w" }, - { "val": 1e8, "suffix": "e" }, - { "val": 1e12, "suffix": "z" }, - { "val": 1e16, "suffix": "j" }, - { "val": 1e20, "suffix": "g" }, - ]; - if (Math.abs(x) > 1e20 * Math.pow(10, digits - 2)) - return x.toExponential(0); // 绝对值过大以致于失去精度的数,直接使用科学记数法,系数只保留整数 - var sign = x < 0 ? '-' : ''; - if (sign) --digits; // 符号位单独处理,负号要占一位 - x = Math.abs(x); + if (digits === true) digits = 5; // 兼容旧版onMap参数 + if (!digits || digits < 5) digits = 6; // 连同负号、小数点和后缀字母在内的总位数,至少需为5,默认为6 + x = Math.trunc(parseFloat(x)); // 尝试识别为小数,然后向0取整 + if (x == null || !Number.isFinite(x)) return "???"; // 无法识别的数或正负无穷大,显示'???' + var units = [ + // 单位及其后缀字母,可自定义,如改成千进制下的K、M、G、T、P + { val: 1e4, suffix: "w" }, + { val: 1e8, suffix: "e" }, + { val: 1e12, suffix: "z" }, + { val: 1e16, suffix: "j" }, + { val: 1e20, suffix: "g" }, + ]; + if (Math.abs(x) > 1e20 * Math.pow(10, digits - 2)) return x.toExponential(0); // 绝对值过大以致于失去精度的数,直接使用科学记数法,系数只保留整数 + var sign = x < 0 ? "-" : ""; + if (sign) --digits; // 符号位单独处理,负号要占一位 + x = Math.abs(x); - if (x < Math.pow(10, digits)) return sign + x; + if (x < Math.pow(10, digits)) return sign + x; - for (var i = 0; i < units.length; ++i) { - var each = units[i]; - var u = (x / each.val).toFixed(digits).substring(0, digits); - if (u.indexOf('.') < 0) continue; - u = u.substring(0, u[u.length - 2] == '.' ? u.length - 2 : u.length - 1); - return sign + u + each.suffix; - } - return sign + x.toExponential(0); -} + for (var i = 0; i < units.length; ++i) { + var each = units[i]; + var u = (x / each.val).toFixed(digits).substring(0, digits); + if (u.indexOf(".") < 0) continue; + u = u.substring(0, u[u.length - 2] == "." ? u.length - 2 : u.length - 1); + return sign + u + each.suffix; + } + return sign + x.toExponential(0); +}; ////// 变速移动 ////// utils.prototype.applyEasing = function (name) { - var list = { - "easeIn": function (t) { - return Math.pow(t, 3); - }, - "easeOut": function (t) { - return 1 - Math.pow(1 - t, 3); - }, - "easeInOut": function (t) { - // easeInOut试了一下感觉二次方效果明显点 - if (t < 0.5) return Math.pow(t, 2) * 2; - else return 1 - Math.pow(1 - t, 2) * 2; - }, - "linear": function (t) { - return t - } - } - if (name == 'random') { - var keys = Object.keys(list); - name = keys[Math.floor(Math.random() * keys.length)]; - } - return list[name] || list.linear; -} + var list = { + easeIn: function (t) { + return Math.pow(t, 3); + }, + easeOut: function (t) { + return 1 - Math.pow(1 - t, 3); + }, + easeInOut: function (t) { + // easeInOut试了一下感觉二次方效果明显点 + if (t < 0.5) return Math.pow(t, 2) * 2; + else return 1 - Math.pow(1 - t, 2) * 2; + }, + linear: function (t) { + return t; + }, + }; + if (name == "random") { + var keys = Object.keys(list); + name = keys[Math.floor(Math.random() * keys.length)]; + } + return list[name] || list.linear; +}; ////// 数组转RGB ////// utils.prototype.arrayToRGB = function (color) { - if (!(color instanceof Array)) return color; - var nowR = this.clamp(parseInt(color[0]), 0, 255), nowG = this.clamp(parseInt(color[1]), 0, 255), - nowB = this.clamp(parseInt(color[2]), 0, 255); - return "#" + ((1 << 24) + (nowR << 16) + (nowG << 8) + nowB).toString(16).slice(1); -} + if (!(color instanceof Array)) return color; + var nowR = this.clamp(parseInt(color[0]), 0, 255), + nowG = this.clamp(parseInt(color[1]), 0, 255), + nowB = this.clamp(parseInt(color[2]), 0, 255); + return ( + "#" + ((1 << 24) + (nowR << 16) + (nowG << 8) + nowB).toString(16).slice(1) + ); +}; utils.prototype.arrayToRGBA = function (color) { - if (!(color instanceof Array)) return color; - if (color[3] == null) color[3] = 1; - var nowR = this.clamp(parseInt(color[0]), 0, 255), nowG = this.clamp(parseInt(color[1]), 0, 255), - nowB = this.clamp(parseInt(color[2]), 0, 255), nowA = this.clamp(parseFloat(color[3]), 0, 1); - return "rgba(" + nowR + "," + nowG + "," + nowB + "," + nowA + ")"; -} + if (!(color instanceof Array)) return color; + if (color[3] == null) color[3] = 1; + var nowR = this.clamp(parseInt(color[0]), 0, 255), + nowG = this.clamp(parseInt(color[1]), 0, 255), + nowB = this.clamp(parseInt(color[2]), 0, 255), + nowA = this.clamp(parseFloat(color[3]), 0, 1); + return "rgba(" + nowR + "," + nowG + "," + nowB + "," + nowA + ")"; +}; ////// 加密路线 ////// utils.prototype.encodeRoute = function (route) { - var ans = "", lastMove = "", cnt = 0; + var ans = "", + lastMove = "", + cnt = 0; - route.forEach(function (t) { - if (t == 'up' || t == 'down' || t == 'left' || t == 'right') { - if (t != lastMove && cnt > 0) { - ans += lastMove.substring(0, 1).toUpperCase(); - if (cnt > 1) ans += cnt; - cnt = 0; - } - lastMove = t; - cnt++; - } - else { - if (cnt > 0) { - ans += lastMove.substring(0, 1).toUpperCase(); - if (cnt > 1) ans += cnt; - cnt = 0; - } - ans += core.utils._encodeRoute_encodeOne(t); - } - }); - if (cnt > 0) { + route.forEach(function (t) { + if (t == "up" || t == "down" || t == "left" || t == "right") { + if (t != lastMove && cnt > 0) { ans += lastMove.substring(0, 1).toUpperCase(); if (cnt > 1) ans += cnt; + cnt = 0; + } + lastMove = t; + cnt++; + } else { + if (cnt > 0) { + ans += lastMove.substring(0, 1).toUpperCase(); + if (cnt > 1) ans += cnt; + cnt = 0; + } + ans += core.utils._encodeRoute_encodeOne(t); } - return LZString.compressToBase64(ans); -} + }); + if (cnt > 0) { + ans += lastMove.substring(0, 1).toUpperCase(); + if (cnt > 1) ans += cnt; + } + return LZString.compressToBase64(ans); +}; utils.prototype._encodeRoute_id2number = function (id) { - var number = core.maps.getNumberById(id); - return number == 0 ? id : number; -} + var number = core.maps.getNumberById(id); + return number == 0 ? id : number; +}; utils.prototype._encodeRoute_encodeOne = function (t) { - if (t.indexOf('item:') == 0) - return "I" + this._encodeRoute_id2number(t.substring(5)) + ":"; - else if (t.indexOf('unEquip:') == 0) - return "u" + t.substring(8); - else if (t.indexOf('equip:') == 0) - return "e" + this._encodeRoute_id2number(t.substring(6)) + ":"; - else if (t.indexOf('saveEquip:') == 0) - return "s" + t.substring(10); - else if (t.indexOf('loadEquip:') == 0) - return "l" + t.substring(10); - else if (t.indexOf('fly:') == 0) - return "F" + t.substring(4) + ":"; - else if (t == 'choices:none') - return "c"; - else if (t.indexOf('choices:') == 0) - return "C" + t.substring(8); - else if (t.indexOf('shop:') == 0) - return "S" + t.substring(5) + ":"; - else if (t == 'turn') - return 'T'; - else if (t.indexOf('turn:') == 0) - return "t" + t.substring(5).substring(0, 1).toUpperCase() + ":"; - else if (t == 'getNext') - return 'G'; - else if (t == 'input:none') - return 'p'; - else if (t.indexOf('input:') == 0) - return "P" + t.substring(6); - else if (t.indexOf('input2:') == 0) - return "Q" + t.substring(7) + ":"; - else if (t == 'no') - return 'N'; - else if (t.indexOf('move:') == 0) - return "M" + t.substring(5); - else if (t.indexOf('key:') == 0) - return 'K' + t.substring(4); - else if (t.indexOf('click:') == 0) - return 'k' + t.substring(6); - else if (t.indexOf('random:') == 0) - return 'X' + t.substring(7); - return '(' + t + ')'; -} + if (t.indexOf("item:") == 0) + return "I" + this._encodeRoute_id2number(t.substring(5)) + ":"; + else if (t.indexOf("unEquip:") == 0) return "u" + t.substring(8); + else if (t.indexOf("equip:") == 0) + return "e" + this._encodeRoute_id2number(t.substring(6)) + ":"; + else if (t.indexOf("saveEquip:") == 0) return "s" + t.substring(10); + else if (t.indexOf("loadEquip:") == 0) return "l" + t.substring(10); + else if (t.indexOf("fly:") == 0) return "F" + t.substring(4) + ":"; + else if (t == "choices:none") return "c"; + else if (t.indexOf("choices:") == 0) return "C" + t.substring(8); + else if (t.indexOf("shop:") == 0) return "S" + t.substring(5) + ":"; + else if (t == "turn") return "T"; + else if (t.indexOf("turn:") == 0) + return "t" + t.substring(5).substring(0, 1).toUpperCase() + ":"; + else if (t == "getNext") return "G"; + else if (t == "input:none") return "p"; + else if (t.indexOf("input:") == 0) return "P" + t.substring(6); + else if (t.indexOf("input2:") == 0) return "Q" + t.substring(7) + ":"; + else if (t == "no") return "N"; + else if (t.indexOf("move:") == 0) return "M" + t.substring(5); + else if (t.indexOf("key:") == 0) return "K" + t.substring(4); + else if (t.indexOf("click:") == 0) return "k" + t.substring(6); + else if (t.indexOf("random:") == 0) return "X" + t.substring(7); + return "(" + t + ")"; +}; ////// 解密路线 ////// utils.prototype.decodeRoute = function (route) { - if (!route) return route; + if (!route) return route; - // 解压缩 - try { - var v = LZString.decompressFromBase64(route); - if (v != null && /^[-_a-zA-Z0-9+\/=:()]*$/.test(v)) { - if (v != "" || route.length < 8) - route = v; - } - } catch (e) { + // 解压缩 + try { + var v = LZString.decompressFromBase64(route); + if (v != null && /^[-_a-zA-Z0-9+\/=:()]*$/.test(v)) { + if (v != "" || route.length < 8) route = v; } + } catch (e) {} - var decodeObj = { route: route, index: 0, ans: [] }; - while (decodeObj.index < decodeObj.route.length) { - this._decodeRoute_decodeOne(decodeObj, decodeObj.route.charAt(decodeObj.index++)); - } - return decodeObj.ans; -} + var decodeObj = { route: route, index: 0, ans: [] }; + while (decodeObj.index < decodeObj.route.length) { + this._decodeRoute_decodeOne( + decodeObj, + decodeObj.route.charAt(decodeObj.index++) + ); + } + return decodeObj.ans; +}; utils.prototype._decodeRoute_getNumber = function (decodeObj, noparse) { - var num = ""; - var first = true; - while (true) { - var ch = decodeObj.route.charAt(decodeObj.index); - if (ch >= '0' && ch <= '9') num += ch; - else if (ch == '-' && first) num += ch; - else break; - first = false; - decodeObj.index++; - } - if (num.length == 0) num = "1"; - return noparse ? num : parseInt(num); -} + var num = ""; + var first = true; + while (true) { + var ch = decodeObj.route.charAt(decodeObj.index); + if (ch >= "0" && ch <= "9") num += ch; + else if (ch == "-" && first) num += ch; + else break; + first = false; + decodeObj.index++; + } + if (num.length == 0) num = "1"; + return noparse ? num : parseInt(num); +}; utils.prototype._decodeRoute_getString = function (decodeObj) { - var str = ""; - while (decodeObj.index < decodeObj.route.length && decodeObj.route.charAt(decodeObj.index) != ':') { - str += decodeObj.route.charAt(decodeObj.index++); - } - decodeObj.index++; - return str; -} + var str = ""; + while ( + decodeObj.index < decodeObj.route.length && + decodeObj.route.charAt(decodeObj.index) != ":" + ) { + str += decodeObj.route.charAt(decodeObj.index++); + } + decodeObj.index++; + return str; +}; utils.prototype._decodeRoute_number2id = function (number) { - if (/^\d+$/.test(number)) { - var info = core.maps.blocksInfo[number]; - if (info) return info.id; - } - return number; -} + if (/^\d+$/.test(number)) { + var info = core.maps.blocksInfo[number]; + if (info) return info.id; + } + return number; +}; utils.prototype._decodeRoute_decodeOne = function (decodeObj, c) { - // --- 特殊处理自定义项 - if (c == '(') { - var idx = decodeObj.route.indexOf(')', decodeObj.index); - if (idx >= 0) { - decodeObj.ans.push(decodeObj.route.substring(decodeObj.index, idx)); - decodeObj.index = idx + 1; - return; - } + // --- 特殊处理自定义项 + if (c == "(") { + var idx = decodeObj.route.indexOf(")", decodeObj.index); + if (idx >= 0) { + decodeObj.ans.push(decodeObj.route.substring(decodeObj.index, idx)); + decodeObj.index = idx + 1; + return; } - var nxt = (c == 'I' || c == 'e' || c == 'F' || c == 'S' || c == 'Q' || c == 't') ? - this._decodeRoute_getString(decodeObj) : this._decodeRoute_getNumber(decodeObj); + } + var nxt = + c == "I" || c == "e" || c == "F" || c == "S" || c == "Q" || c == "t" + ? this._decodeRoute_getString(decodeObj) + : this._decodeRoute_getNumber(decodeObj); - var mp = { "U": "up", "D": "down", "L": "left", "R": "right" }; + var mp = { U: "up", D: "down", L: "left", R: "right" }; - switch (c) { - case "U": - case "D": - case "L": - case "R": - for (var i = 0; i < nxt; i++) decodeObj.ans.push(mp[c]); - break; - case "I": - decodeObj.ans.push("item:" + this._decodeRoute_number2id(nxt)); - break; - case "u": - decodeObj.ans.push("unEquip:" + nxt); - break; - case "e": - decodeObj.ans.push("equip:" + this._decodeRoute_number2id(nxt)); - break; - case "s": - decodeObj.ans.push("saveEquip:" + nxt); - break; - case "l": - decodeObj.ans.push("loadEquip:" + nxt); - break; - case "F": - decodeObj.ans.push("fly:" + nxt); - break; - case 'c': - decodeObj.ans.push('choices:none'); - break; - case "C": - decodeObj.ans.push("choices:" + nxt); - break; - case "S": - decodeObj.ans.push("shop:" + nxt); - break; - case "T": - decodeObj.ans.push("turn"); - break; - case "t": - decodeObj.ans.push("turn:" + mp[nxt]); - break; - case "G": - decodeObj.ans.push("getNext"); - break; - case "p": - decodeObj.ans.push("input:none"); - break; - case "P": - decodeObj.ans.push("input:" + nxt); - break; - case "Q": - decodeObj.ans.push("input2:" + nxt); - break; - case "N": - decodeObj.ans.push("no"); - break; - case "M": - ++decodeObj.index; - decodeObj.ans.push("move:" + nxt + ":" + this._decodeRoute_getNumber(decodeObj)); - break; - case "K": - decodeObj.ans.push("key:" + nxt); - break; - case "k": - ++decodeObj.index; - var px = this._decodeRoute_getNumber(decodeObj); - ++decodeObj.index; - var py = this._decodeRoute_getNumber(decodeObj); - decodeObj.ans.push("click:" + nxt + ":" + px + ":" + py); - break; - case "X": - decodeObj.ans.push("random:" + nxt); - break; - } -} + switch (c) { + case "U": + case "D": + case "L": + case "R": + for (var i = 0; i < nxt; i++) decodeObj.ans.push(mp[c]); + break; + case "I": + decodeObj.ans.push("item:" + this._decodeRoute_number2id(nxt)); + break; + case "u": + decodeObj.ans.push("unEquip:" + nxt); + break; + case "e": + decodeObj.ans.push("equip:" + this._decodeRoute_number2id(nxt)); + break; + case "s": + decodeObj.ans.push("saveEquip:" + nxt); + break; + case "l": + decodeObj.ans.push("loadEquip:" + nxt); + break; + case "F": + decodeObj.ans.push("fly:" + nxt); + break; + case "c": + decodeObj.ans.push("choices:none"); + break; + case "C": + decodeObj.ans.push("choices:" + nxt); + break; + case "S": + decodeObj.ans.push("shop:" + nxt); + break; + case "T": + decodeObj.ans.push("turn"); + break; + case "t": + decodeObj.ans.push("turn:" + mp[nxt]); + break; + case "G": + decodeObj.ans.push("getNext"); + break; + case "p": + decodeObj.ans.push("input:none"); + break; + case "P": + decodeObj.ans.push("input:" + nxt); + break; + case "Q": + decodeObj.ans.push("input2:" + nxt); + break; + case "N": + decodeObj.ans.push("no"); + break; + case "M": + ++decodeObj.index; + decodeObj.ans.push( + "move:" + nxt + ":" + this._decodeRoute_getNumber(decodeObj) + ); + break; + case "K": + decodeObj.ans.push("key:" + nxt); + break; + case "k": + ++decodeObj.index; + var px = this._decodeRoute_getNumber(decodeObj); + ++decodeObj.index; + var py = this._decodeRoute_getNumber(decodeObj); + decodeObj.ans.push("click:" + nxt + ":" + px + ":" + py); + break; + case "X": + decodeObj.ans.push("random:" + nxt); + break; + } +}; ////// 判断某对象是否不为null也不为NaN ////// utils.prototype.isset = function (val) { - return val != null && !(typeof val == 'number' && isNaN(val)); -} + return val != null && !(typeof val == "number" && isNaN(val)); +}; ////// 获得子数组 ////// utils.prototype.subarray = function (a, b) { - if (!(a instanceof Array) || !(b instanceof Array) || a.length < b.length) - return null; - for (var i = 0; i < b.length; ++i) { - if (a[i] != b[i]) return null; - } - return a.slice(b.length); -} + if (!(a instanceof Array) || !(b instanceof Array) || a.length < b.length) + return null; + for (var i = 0; i < b.length; ++i) { + if (a[i] != b[i]) return null; + } + return a.slice(b.length); +}; utils.prototype.inArray = function (array, element) { - return (array instanceof Array) && array.indexOf(element) >= 0; -} + return array instanceof Array && array.indexOf(element) >= 0; +}; utils.prototype.clamp = function (x, a, b) { - var min = Math.min(a, b), max = Math.max(a, b); - return Math.min(Math.max(x || 0, min), max); -} + var min = Math.min(a, b), + max = Math.max(a, b); + return Math.min(Math.max(x || 0, min), max); +}; utils.prototype.getCookie = function (name) { - var match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)')); - return match ? match[2] : null; -} + var match = document.cookie.match(new RegExp("(^| )" + name + "=([^;]+)")); + return match ? match[2] : null; +}; ////// 设置statusBar的innerHTML,会自动斜体和放缩,也可以增加自定义css ////// utils.prototype.setStatusBarInnerHTML = function (name, value, css) { - if (!core.statusBar[name]) return; - if (typeof value == 'number') value = this.formatBigNumber(value); - var italic = /^[-a-zA-Z0-9`~!@#$%^&*()_=+\[{\]}\\|;:'",<.>\/?]*$/.test(value); - var style = 'font-style: ' + (italic ? 'italic' : 'normal') + '; '; - style += 'text-shadow: #000 1px 0 0, #000 0 1px 0, #000 -1px 0 0, #000 0 -1px 0; '; - // 判定是否需要缩放 - var length = this.strlen(value) || 1; - style += 'font-size: ' + Math.min(1, 7 / length) + 'em; '; - if (css) style += css; - var _style = core.statusBar[name].getAttribute('_style'); - var _value = core.statusBar[name].getAttribute('_value'); - if (_style == style) { - if (value == _value) return; - core.statusBar[name].children[0].innerText = value; - } else { - core.statusBar[name].innerHTML = ""; - core.statusBar[name].children[0].innerText = value; - core.statusBar[name].setAttribute('_style', style); - } - core.statusBar[name].setAttribute('_value', value);; -} + if (!core.statusBar[name]) return; + if (typeof value == "number") value = this.formatBigNumber(value); + var italic = /^[-a-zA-Z0-9`~!@#$%^&*()_=+\[{\]}\\|;:'",<.>\/?]*$/.test(value); + var style = "font-style: " + (italic ? "italic" : "normal") + "; "; + style += + "text-shadow: #000 1px 0 0, #000 0 1px 0, #000 -1px 0 0, #000 0 -1px 0; "; + // 判定是否需要缩放 + var length = this.strlen(value) || 1; + style += "font-size: " + Math.min(1, 7 / length) + "em; "; + if (css) style += css; + var _style = core.statusBar[name].getAttribute("_style"); + var _value = core.statusBar[name].getAttribute("_value"); + if (_style == style) { + if (value == _value) return; + core.statusBar[name].children[0].innerText = value; + } else { + core.statusBar[name].innerHTML = + ""; + core.statusBar[name].children[0].innerText = value; + core.statusBar[name].setAttribute("_style", style); + } + core.statusBar[name].setAttribute("_value", value); +}; utils.prototype.strlen = function (str) { - var count = 0; - for (var i = 0, len = str.length; i < len; i++) { - count += str.charCodeAt(i) < 256 ? 1 : 2; - } - return count; + var count = 0; + for (var i = 0, len = str.length; i < len; i++) { + count += str.charCodeAt(i) < 256 ? 1 : 2; + } + return count; }; utils.prototype.turnDirection = function (turn, direction) { - direction = direction || core.getHeroLoc('direction'); - var directionList = ["left", "leftup", "up", "rightup", "right", "rightdown", "down", "leftdown"]; - if (directionList.indexOf(turn) >= 0) return turn; - if (turn == ':hero') return core.getHeroLoc('direction'); - if (turn == ':backhero') return this.turnDirection(':back', core.getHeroLoc('direction')); - if (typeof turn === 'number' && turn % 45 == 0) turn /= 45; - else { - switch (turn) { - case ':left': turn = 6; break; // turn left - case ':right': turn = 2; break; // turn right - case ':back': turn = 4; break; // turn back - default: turn = 0; break; - } + direction = direction || core.getHeroLoc("direction"); + var directionList = [ + "left", + "leftup", + "up", + "rightup", + "right", + "rightdown", + "down", + "leftdown", + ]; + if (directionList.indexOf(turn) >= 0) return turn; + if (turn == ":hero") return core.getHeroLoc("direction"); + if (turn == ":backhero") + return this.turnDirection(":back", core.getHeroLoc("direction")); + if (typeof turn === "number" && turn % 45 == 0) turn /= 45; + else { + switch (turn) { + case ":left": + turn = 6; + break; // turn left + case ":right": + turn = 2; + break; // turn right + case ":back": + turn = 4; + break; // turn back + default: + turn = 0; + break; } - var index = directionList.indexOf(direction); - if (index < 0) return direction; - return directionList[(index + (turn || 0)) % directionList.length]; -} + } + var index = directionList.indexOf(direction); + if (index < 0) return direction; + return directionList[(index + (turn || 0)) % directionList.length]; +}; utils.prototype.matchWildcard = function (pattern, string) { - try { - return new RegExp('^' + pattern.split(/\*+/).map(function (s) { - return s.replace(/[|\\{}()[\]^$+*?.]/g, '\\$&'); - }).join('.*') + '$').test(string); - } catch (e) { - return false; - } -} + try { + return new RegExp( + "^" + + pattern + .split(/\*+/) + .map(function (s) { + return s.replace(/[|\\{}()[\]^$+*?.]/g, "\\$&"); + }) + .join(".*") + + "$" + ).test(string); + } catch (e) { + return false; + } +}; utils.prototype.matchRegex = function (pattern, string) { - try { - if (pattern.startsWith("^")) pattern = pattern.substring(1); - if (pattern.endsWith("$")) pattern = pattern.substring(0, pattern.length - 1); - return new RegExp("^" + pattern + "$").test(string); - } catch (e) { - return false; - } -} + try { + if (pattern.startsWith("^")) pattern = pattern.substring(1); + if (pattern.endsWith("$")) + pattern = pattern.substring(0, pattern.length - 1); + return new RegExp("^" + pattern + "$").test(string); + } catch (e) { + return false; + } +}; ////// Base64加密 ////// utils.prototype.encodeBase64 = function (str) { - return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function (match, p1) { - return String.fromCharCode(parseInt(p1, 16)) - })) -} + return btoa( + encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function (match, p1) { + return String.fromCharCode(parseInt(p1, 16)); + }) + ); +}; ////// Base64解密 ////// utils.prototype.decodeBase64 = function (str) { - return decodeURIComponent(atob(str).split('').map(function (c) { - return '%' + ('00' + c.charCodeAt(0).toString(16)).slice(-2); - }).join('')); -} + return decodeURIComponent( + atob(str) + .split("") + .map(function (c) { + return "%" + ("00" + c.charCodeAt(0).toString(16)).slice(-2); + }) + .join("") + ); +}; utils.prototype.rand = function (num) { - var rand = core.getFlag('__rand__'); - rand = this.__next_rand(rand); - core.setFlag('__rand__', rand); - var ans = rand / 2147483647; - if (num && num > 0) - return Math.floor(ans * num); - return ans; -} + var rand = core.getFlag("__rand__"); + rand = this.__next_rand(rand); + core.setFlag("__rand__", rand); + var ans = rand / 2147483647; + if (num && num > 0) return Math.floor(ans * num); + return ans; +}; ////// 生成随机数(录像方法) ////// utils.prototype.rand2 = function (num) { - num = num || 2147483648; - num = Math.abs(num); + num = num || 2147483648; + num = Math.abs(num); - var value; - if (core.isReplaying()) { - var action = core.status.replay.toReplay.shift(); - if (action.indexOf("random:") == 0) { - value = parseInt(action.substring(7)); - if (isNaN(value) || value >= num || value < 0) { - console.warn('错误!当前random:项超过范围。将重新随机生成!'); - value = Math.floor(Math.random() * num); - } - } - else { - console.warn('错误!当前需要一个random:项。将重新随机生成!'); - value = Math.floor(Math.random() * num); - } - } - else { + var value; + if (core.isReplaying()) { + var action = core.status.replay.toReplay.shift(); + if (action.indexOf("random:") == 0) { + value = parseInt(action.substring(7)); + if (isNaN(value) || value >= num || value < 0) { + console.warn("错误!当前random:项超过范围。将重新随机生成!"); value = Math.floor(Math.random() * num); + } + } else { + console.warn("错误!当前需要一个random:项。将重新随机生成!"); + value = Math.floor(Math.random() * num); } - core.status.route.push("random:" + value); - return value; -} + } else { + value = Math.floor(Math.random() * num); + } + core.status.route.push("random:" + value); + return value; +}; utils.prototype.__init_seed = function () { - var rand = new Date().getTime() % 34834795 + 3534; - rand = this.__next_rand(rand); - rand = this.__next_rand(rand); - rand = this.__next_rand(rand); - core.setFlag('__seed__', rand); - core.setFlag('__rand__', rand); -} + var rand = (new Date().getTime() % 34834795) + 3534; + rand = this.__next_rand(rand); + rand = this.__next_rand(rand); + rand = this.__next_rand(rand); + core.setFlag("__seed__", rand); + core.setFlag("__rand__", rand); +}; utils.prototype.__next_rand = function (_rand) { - _rand = (_rand % 127773) * 16807 - ~~(_rand / 127773) * 2836; - _rand += _rand < 0 ? 2147483647 : 0; - return _rand; -} + _rand = (_rand % 127773) * 16807 - ~~(_rand / 127773) * 2836; + _rand += _rand < 0 ? 2147483647 : 0; + return _rand; +}; ////// 读取一个本地文件内容 ////// utils.prototype.readFile = function (success, error, accept, readType) { + core.platform.successCallback = success; + core.platform.errorCallback = error; - core.platform.successCallback = success; - core.platform.errorCallback = error; + if (window.jsinterface) { + window.jsinterface.readFile(); + return; + } - if (window.jsinterface) { - window.jsinterface.readFile(); + // step 0: 不为http/https,直接不支持 + if (!core.platform.isOnline) { + alert("离线状态下不支持文件读取!"); + if (error) error(); + return; + } + + // Step 1: 如果不支持FileReader,直接不支持 + if (core.platform.fileReader == null) { + alert("当前浏览器不支持FileReader!"); + if (error) error(); + return; + } + + if (core.platform.fileInput == null) { + core.platform.fileInput = document.createElement("input"); + core.platform.fileInput.style.opacity = 0; + core.platform.fileInput.type = "file"; + core.platform.fileInput.onchange = function () { + var files = core.platform.fileInput.files; + if (files.length == 0) { + if (core.platform.errorCallback) core.platform.errorCallback(); return; - } + } + if (!readType) + core.platform.fileReader.readAsText(core.platform.fileInput.files[0]); + else + core.platform.fileReader.readAsDataURL( + core.platform.fileInput.files[0] + ); + core.platform.fileInput.value = ""; + }; + } + core.platform.fileInput.value = ""; + if (accept) core.platform.fileInput.accept = accept; - // step 0: 不为http/https,直接不支持 - if (!core.platform.isOnline) { - alert("离线状态下不支持文件读取!"); - if (error) error(); - return; - } - - // Step 1: 如果不支持FileReader,直接不支持 - if (core.platform.fileReader == null) { - alert("当前浏览器不支持FileReader!"); - if (error) error(); - return; - } - - if (core.platform.fileInput == null) { - core.platform.fileInput = document.createElement("input"); - core.platform.fileInput.style.opacity = 0; - core.platform.fileInput.type = 'file'; - core.platform.fileInput.onchange = function () { - var files = core.platform.fileInput.files; - if (files.length == 0) { - if (core.platform.errorCallback) - core.platform.errorCallback(); - return; - } - if (!readType) core.platform.fileReader.readAsText(core.platform.fileInput.files[0]); - else core.platform.fileReader.readAsDataURL(core.platform.fileInput.files[0]); - core.platform.fileInput.value = ''; - } - } - core.platform.fileInput.value = ''; - if (accept) core.platform.fileInput.accept = accept; - - core.platform.fileInput.click(); -} + core.platform.fileInput.click(); +}; ////// 读取文件完毕 ////// utils.prototype.readFileContent = function (content) { - var obj = null; - if (content.slice(0, 4) === 'data') { - if (core.platform.successCallback) - core.platform.successCallback(content); - return; - } - // 检查base64 + var obj = null; + if (content.slice(0, 4) === "data") { + if (core.platform.successCallback) core.platform.successCallback(content); + return; + } + // 检查base64 + try { + obj = JSON.parse(LZString.decompressFromBase64(content)); + } catch (e) {} + if (!obj) { try { - obj = JSON.parse(LZString.decompressFromBase64(content)); - } catch (e) { } - if (!obj) { - try { - obj = JSON.parse(content); - } catch (e) { - console.error(e) - } + obj = JSON.parse(content); + } catch (e) { + console.error(e); } + } - if (obj) { - if (core.platform.successCallback) - core.platform.successCallback(obj); - return; - } + if (obj) { + if (core.platform.successCallback) core.platform.successCallback(obj); + return; + } - if (core.platform.errorCallback) - core.platform.errorCallback(); -} + if (core.platform.errorCallback) core.platform.errorCallback(); +}; ////// 下载文件到本地 ////// utils.prototype.download = function (filename, content) { + if (window.jsinterface) { + window.jsinterface.download(filename, content); + return; + } - if (window.jsinterface) { - window.jsinterface.download(filename, content); - return; - } + // Step 0: 不为http/https,直接不支持 + if (!core.platform.isOnline) { + alert("离线状态下不支持下载操作!"); + return; + } - // Step 0: 不为http/https,直接不支持 - if (!core.platform.isOnline) { - alert("离线状态下不支持下载操作!"); - return; + // Step 1: 如果是iOS平台,直接不支持 + if (core.platform.isIOS) { + if (core.copy(content)) { + alert( + "iOS平台下不支持直接下载文件!\n所有应下载内容已经复制到您的剪切板,请自行创建空白文件并粘贴。" + ); + } else { + alert("iOS平台下不支持下载操作!"); } + return; + } - // Step 1: 如果是iOS平台,直接不支持 - if (core.platform.isIOS) { - if (core.copy(content)) { - alert("iOS平台下不支持直接下载文件!\n所有应下载内容已经复制到您的剪切板,请自行创建空白文件并粘贴。"); - } - else { - alert("iOS平台下不支持下载操作!"); - } - return; + // Step 2: 如果不是PC平台(Android),则只支持chrome + if (!core.platform.isPC) { + if ( + !core.platform.isChrome || + core.platform.isQQ || + core.platform.isWeChat + ) { + // 检测chrome + if (core.copy(content)) { + alert( + "移动端只有Chrome浏览器支持直接下载文件!\n所有应下载内容已经复制到您的剪切板,请自行创建空白文件并粘贴。" + ); + } else { + alert("该平台或浏览器暂不支持下载操作!"); + } + return; } + } - // Step 2: 如果不是PC平台(Android),则只支持chrome - if (!core.platform.isPC) { - if (!core.platform.isChrome || core.platform.isQQ || core.platform.isWeChat) { // 检测chrome - if (core.copy(content)) { - alert("移动端只有Chrome浏览器支持直接下载文件!\n所有应下载内容已经复制到您的剪切板,请自行创建空白文件并粘贴。"); - } - else { - alert("该平台或浏览器暂不支持下载操作!"); - } - return; - } - } + // Step 3: 如果是Safari浏览器,则提示并打开新窗口 + if (core.platform.isSafari) { + alert( + "你当前使用的是Safari浏览器,不支持直接下载文件。\n即将打开一个新窗口为应下载内容,请自行全选复制然后创建空白文件并粘贴。" + ); + var blob = new Blob([content], { type: "text/plain;charset=utf-8" }); + var href = window.URL.createObjectURL(blob); + var opened = window.open(href, "_blank"); + window.URL.revokeObjectURL(href); + return; + } - // Step 3: 如果是Safari浏览器,则提示并打开新窗口 - if (core.platform.isSafari) { - alert("你当前使用的是Safari浏览器,不支持直接下载文件。\n即将打开一个新窗口为应下载内容,请自行全选复制然后创建空白文件并粘贴。"); - var blob = new Blob([content], { type: 'text/plain;charset=utf-8' }); - var href = window.URL.createObjectURL(blob); - var opened = window.open(href, "_blank"); - window.URL.revokeObjectURL(href); - return; - } - - // Step 4: 下载 - var blob = new Blob([content], { type: 'text/plain;charset=utf-8' }); - if (window.navigator.msSaveOrOpenBlob) { - window.navigator.msSaveBlob(blob, filename); - } - else { - var href = window.URL.createObjectURL(blob); - var elem = window.document.createElement('a'); - elem.href = href; - elem.download = filename; - document.body.appendChild(elem); - elem.click(); - document.body.removeChild(elem); - window.URL.revokeObjectURL(href); - } -} + // Step 4: 下载 + var blob = new Blob([content], { type: "text/plain;charset=utf-8" }); + if (window.navigator.msSaveOrOpenBlob) { + window.navigator.msSaveBlob(blob, filename); + } else { + var href = window.URL.createObjectURL(blob); + var elem = window.document.createElement("a"); + elem.href = href; + elem.download = filename; + document.body.appendChild(elem); + elem.click(); + document.body.removeChild(elem); + window.URL.revokeObjectURL(href); + } +}; ////// 复制一段内容到剪切板 ////// utils.prototype.copy = function (data) { + if (window.jsinterface) { + window.jsinterface.copy(data); + return true; + } - if (window.jsinterface) { - window.jsinterface.copy(data); - return true; - } + if (!core.platform.supportCopy) return false; - if (!core.platform.supportCopy) return false; + var textArea = document.createElement("textarea"); + textArea.style.position = "fixed"; + textArea.style.top = 0; + textArea.style.left = 0; + textArea.style.width = "2em"; + textArea.style.height = "2em"; + textArea.style.padding = 0; + textArea.style.border = "none"; + textArea.style.outline = "none"; + textArea.style.boxShadow = "none"; + textArea.style.background = "transparent"; + textArea.value = data; + document.body.appendChild(textArea); + textArea.focus(); + textArea.setSelectionRange(0, textArea.value.length); + var successful = false; + try { + successful = document.execCommand("copy"); + } catch (err) { + successful = false; + } - var textArea = document.createElement("textarea"); - textArea.style.position = 'fixed'; - textArea.style.top = 0; - textArea.style.left = 0; - textArea.style.width = '2em'; - textArea.style.height = '2em'; - textArea.style.padding = 0; - textArea.style.border = 'none'; - textArea.style.outline = 'none'; - textArea.style.boxShadow = 'none'; - textArea.style.background = 'transparent'; - textArea.value = data; - document.body.appendChild(textArea); - textArea.focus(); - textArea.setSelectionRange(0, textArea.value.length); - var successful = false; - try { - successful = document.execCommand('copy'); - } catch (err) { - successful = false; - } - - document.body.removeChild(textArea); - return successful; -} + document.body.removeChild(textArea); + return successful; +}; ////// 显示一段confirm ////// utils.prototype.myconfirm = function (hint, yesCallback, noCallback) { - main.dom.inputDiv.style.display = 'block'; - main.dom.inputMessage.innerHTML = hint.replace(/\n/g, '
'); - main.dom.inputBox.style.display = 'none'; - main.dom.inputYes.blur(); - main.dom.inputNo.blur(); - core.status.holdingKeys = []; + main.dom.inputDiv.style.display = "block"; + main.dom.inputMessage.innerHTML = hint.replace(/\n/g, "
"); + main.dom.inputBox.style.display = "none"; + main.dom.inputYes.blur(); + main.dom.inputNo.blur(); + core.status.holdingKeys = []; - core.platform.successCallback = yesCallback; - core.platform.errorCallback = noCallback; -} + core.platform.successCallback = yesCallback; + core.platform.errorCallback = noCallback; +}; ////// 让用户输入一段文字 ////// utils.prototype.myprompt = function (hint, value, callback) { - main.dom.inputDiv.style.display = 'block'; - main.dom.inputMessage.innerHTML = hint.replace(/\n/g, '
'); - main.dom.inputBox.style.display = 'block'; - main.dom.inputBox.value = value == null ? "" : value; - main.dom.inputYes.blur(); - main.dom.inputNo.blur(); - setTimeout(function () { - main.dom.inputBox.focus(); - }); - core.status.holdingKeys = []; + main.dom.inputDiv.style.display = "block"; + main.dom.inputMessage.innerHTML = hint.replace(/\n/g, "
"); + main.dom.inputBox.style.display = "block"; + main.dom.inputBox.value = value == null ? "" : value; + main.dom.inputYes.blur(); + main.dom.inputNo.blur(); + setTimeout(function () { + main.dom.inputBox.focus(); + }); + core.status.holdingKeys = []; - core.platform.successCallback = core.platform.errorCallback = callback; -} + core.platform.successCallback = core.platform.errorCallback = callback; +}; ////// 动画显示某对象 ////// utils.prototype.showWithAnimate = function (obj, speed, callback) { - obj.style.display = 'block'; - if (!speed || main.mode != 'play') { - obj.style.opacity = 1; - if (callback) callback(); - return; + obj.style.display = "block"; + if (!speed || main.mode != "play") { + obj.style.opacity = 1; + if (callback) callback(); + return; + } + obj.style.opacity = 0; + var opacityVal = 0; + var showAnimate = window.setInterval(function () { + opacityVal += 0.03; + obj.style.opacity = opacityVal; + if (opacityVal > 1) { + clearInterval(showAnimate); + if (callback) callback(); } - obj.style.opacity = 0; - var opacityVal = 0; - var showAnimate = window.setInterval(function () { - opacityVal += 0.03; - obj.style.opacity = opacityVal; - if (opacityVal > 1) { - clearInterval(showAnimate); - if (callback) callback(); - } - }, speed); -} + }, speed); +}; ////// 动画使某对象消失 ////// utils.prototype.hideWithAnimate = function (obj, speed, callback) { - if (!speed || main.mode != 'play') { - obj.style.display = 'none'; - if (callback) callback(); - return; + if (!speed || main.mode != "play") { + obj.style.display = "none"; + if (callback) callback(); + return; + } + obj.style.opacity = 1; + var opacityVal = 1; + var hideAnimate = window.setInterval(function () { + opacityVal -= 0.03; + obj.style.opacity = opacityVal; + if (opacityVal < 0) { + obj.style.display = "none"; + clearInterval(hideAnimate); + if (callback) callback(); } - obj.style.opacity = 1; - var opacityVal = 1; - var hideAnimate = window.setInterval(function () { - opacityVal -= 0.03; - obj.style.opacity = opacityVal; - if (opacityVal < 0) { - obj.style.display = 'none'; - clearInterval(hideAnimate); - if (callback) callback(); - } - }, speed); -} + }, speed); +}; ////// 生成浏览器唯一的 guid ////// utils.prototype.getGuid = function () { - var guid = localStorage.getItem('guid'); - if (guid != null) return guid; - guid = 'xxxxxxxx_xxxx_4xxx_yxxx_xxxxxxxxxxxx'.replace(/[xy]/g, function (c) { - var r = Math.random() * 16 | 0, v = c == 'x' ? r : (r & 0x3 | 0x8); - return v.toString(16); - }); - localStorage.setItem('guid', guid); - return guid; -} + var guid = localStorage.getItem("guid"); + if (guid != null) return guid; + guid = "xxxxxxxx_xxxx_4xxx_yxxx_xxxxxxxxxxxx".replace(/[xy]/g, function (c) { + var r = (Math.random() * 16) | 0, + v = c == "x" ? r : (r & 0x3) | 0x8; + return v.toString(16); + }); + localStorage.setItem("guid", guid); + return guid; +}; utils.prototype.hashCode = function (obj) { - if (typeof obj == 'string') { - var hash = 0, i, chr; - if (obj.length === 0) return hash; - for (i = 0; i < obj.length; i++) { - chr = obj.charCodeAt(i); - hash = ((hash << 5) - hash) + chr; - hash |= 0; - } - return hash; + if (typeof obj == "string") { + var hash = 0, + i, + chr; + if (obj.length === 0) return hash; + for (i = 0; i < obj.length; i++) { + chr = obj.charCodeAt(i); + hash = (hash << 5) - hash + chr; + hash |= 0; } - return this.hashCode(JSON.stringify(obj).split("").sort().join("")); -} + return hash; + } + return this.hashCode(JSON.stringify(obj).split("").sort().join("")); +}; utils.prototype.same = function (a, b) { - if (a == null && b == null) return true; - if (a == null || b == null) return false; - if (a === b) return true; - if (a instanceof Array && b instanceof Array) { - if (a.length != b.length) return false; - for (var i = 0; i < a.length; i++) { - if (!this.same(a[i], b[i])) return false; + if (a == null && b == null) return true; + if (a == null || b == null) return false; + if (a === b) return true; + if (a instanceof Array && b instanceof Array) { + if (a.length != b.length) return false; + for (var i = 0; i < a.length; i++) { + if (!this.same(a[i], b[i])) return false; + } + return true; + } + if (a instanceof Object && b instanceof Object) { + var obj = {}; + for (var i in a) obj[i] = true; + for (var i in b) obj[i] = true; + for (var i in obj) { + if (!this.same(a[i], b[i])) return false; + } + return true; + } + return false; +}; + +utils.prototype.unzip = function ( + blobOrUrl, + success, + error, + convertToText, + onprogress +) { + var _error = function (msg) { + console.error(msg); + if (error) error(msg); + }; + + if (!window.zip) { + return _error("zip.js not exists!"); + } + + if (typeof blobOrUrl == "string") { + return core.http( + "GET", + blobOrUrl, + null, + function (data) { + core.unzip(data, success, error, convertToText); + }, + _error, + null, + "blob", + onprogress + ); + } + + if (!(blobOrUrl instanceof Blob)) { + return _error("Should use Blob or URL as input"); + } + + zip.createReader( + new zip.BlobReader(blobOrUrl), + function (reader) { + reader.getEntries(function (entries) { + core.utils._unzip_readEntries( + entries, + function (data) { + reader.close(function () { + if (success) success(data); + }); + }, + convertToText + ); + }); + }, + _error + ); +}; + +utils.prototype._unzip_readEntries = function ( + entries, + success, + convertToText +) { + var results = {}; + if (entries == null || entries.length == 0) { + return success(results); + } + var length = entries.length; + entries.forEach(function (entry) { + entry.getData( + convertToText ? new zip.TextWriter("utf8") : new zip.BlobWriter(), + function (data) { + results[entry.filename] = data; + length--; + if (length == 0) { + success(results); } - return true; - } - if (a instanceof Object && b instanceof Object) { - var obj = {}; - for (var i in a) obj[i] = true; - for (var i in b) obj[i] = true; - for (var i in obj) { - if (!this.same(a[i], b[i])) return false; - } - return true; - } - return false; -} + } + ); + }); +}; -utils.prototype.unzip = function (blobOrUrl, success, error, convertToText, onprogress) { - var _error = function (msg) { - console.error(msg); - if (error) error(msg); +utils.prototype.http = function ( + type, + url, + formData, + success, + error, + mimeType, + responseType, + onprogress +) { + var xhr = new XMLHttpRequest(); + xhr.open(type, url, true); + if (mimeType) xhr.overrideMimeType(mimeType); + if (responseType) xhr.responseType = responseType; + xhr.onload = function (e) { + if (xhr.status == 200) { + if (success) success(xhr.response); + } else { + if (error) error("HTTP " + xhr.status); } - - if (!window.zip) { - return _error("zip.js not exists!"); + }; + xhr.onprogress = function (e) { + if (e.lengthComputable) { + if (onprogress) onprogress(e.loaded, e.total); } - - if (typeof blobOrUrl == 'string') { - return core.http('GET', blobOrUrl, null, function (data) { - core.unzip(data, success, error, convertToText); - }, _error, null, 'blob', onprogress); - } - - if (!(blobOrUrl instanceof Blob)) { - return _error("Should use Blob or URL as input"); - } - - zip.createReader(new zip.BlobReader(blobOrUrl), function (reader) { - reader.getEntries(function (entries) { - core.utils._unzip_readEntries(entries, function (data) { - reader.close(function () { - if (success) success(data); - }); - }, convertToText); - }); - }, _error); -} - -utils.prototype._unzip_readEntries = function (entries, success, convertToText) { - var results = {}; - if (entries == null || entries.length == 0) { - return success(results); - } - var length = entries.length; - entries.forEach(function (entry) { - entry.getData(convertToText ? new zip.TextWriter('utf8') : new zip.BlobWriter(), function (data) { - results[entry.filename] = data; - length--; - if (length == 0) { - success(results); - } - }); - }); -} - -utils.prototype.http = function (type, url, formData, success, error, mimeType, responseType, onprogress) { - var xhr = new XMLHttpRequest(); - xhr.open(type, url, true); - if (mimeType) xhr.overrideMimeType(mimeType); - if (responseType) xhr.responseType = responseType; - xhr.onload = function (e) { - if (xhr.status == 200) { - if (success) success(xhr.response); - } - else { - if (error) error("HTTP " + xhr.status); - } - }; - xhr.onprogress = function (e) { - if (e.lengthComputable) { - if (onprogress) onprogress(e.loaded, e.total); - } - } - xhr.onabort = function () { - if (error) error("Abort"); - } - xhr.ontimeout = function () { - if (error) error("Timeout"); - } - xhr.onerror = function () { - if (error) error("Error on Connection"); - } - if (formData) - xhr.send(formData); - else xhr.send(); -} + }; + xhr.onabort = function () { + if (error) error("Abort"); + }; + xhr.ontimeout = function () { + if (error) error("Timeout"); + }; + xhr.onerror = function () { + if (error) error("Error on Connection"); + }; + if (formData) xhr.send(formData); + else xhr.send(); +}; // LZW-compress // https://gist.github.com/revolunet/843889 -function lzw_encode (s) { - var dict = {}; - var data = (s + "").split(""); - var out = []; - var currChar; - var phrase = data[0]; - var code = 256; - for (var i = 1; i < data.length; i++) { - currChar = data[i]; - if (dict[phrase + currChar] != null) { - phrase += currChar; - } - else { - out.push(phrase.length > 1 ? dict[phrase] : phrase.charCodeAt(0)); - dict[phrase + currChar] = code; - code++; - phrase = currChar; - } +function lzw_encode(s) { + var dict = {}; + var data = (s + "").split(""); + var out = []; + var currChar; + var phrase = data[0]; + var code = 256; + for (var i = 1; i < data.length; i++) { + currChar = data[i]; + if (dict[phrase + currChar] != null) { + phrase += currChar; + } else { + out.push(phrase.length > 1 ? dict[phrase] : phrase.charCodeAt(0)); + dict[phrase + currChar] = code; + code++; + phrase = currChar; } - out.push(phrase.length > 1 ? dict[phrase] : phrase.charCodeAt(0)); - for (var i = 0; i < out.length; i++) { - out[i] = String.fromCharCode(out[i]); - } - return out.join(""); + } + out.push(phrase.length > 1 ? dict[phrase] : phrase.charCodeAt(0)); + for (var i = 0; i < out.length; i++) { + out[i] = String.fromCharCode(out[i]); + } + return out.join(""); } // Decompress an LZW-encoded string -function lzw_decode (s) { - var dict = {}; - var data = (s + "").split(""); - var currChar = data[0]; - var oldPhrase = currChar; - var out = [currChar]; - var code = 256; - var phrase; - for (var i = 1; i < data.length; i++) { - var currCode = data[i].charCodeAt(0); - if (currCode < 256) { - phrase = data[i]; - } - else { - phrase = dict[currCode] ? dict[currCode] : (oldPhrase + currChar); - } - out.push(phrase); - currChar = phrase.charAt(0); - dict[code] = oldPhrase + currChar; - code++; - oldPhrase = phrase; +function lzw_decode(s) { + var dict = {}; + var data = (s + "").split(""); + var currChar = data[0]; + var oldPhrase = currChar; + var out = [currChar]; + var code = 256; + var phrase; + for (var i = 1; i < data.length; i++) { + var currCode = data[i].charCodeAt(0); + if (currCode < 256) { + phrase = data[i]; + } else { + phrase = dict[currCode] ? dict[currCode] : oldPhrase + currChar; } - return out.join(""); + out.push(phrase); + currChar = phrase.charAt(0); + dict[code] = oldPhrase + currChar; + code++; + oldPhrase = phrase; + } + return out.join(""); } diff --git a/project/plugins.js b/project/plugins.js index e8418e9..f33de61 100644 --- a/project/plugins.js +++ b/project/plugins.js @@ -3738,569 +3738,567 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = // init() called in `afterLoadResources`. }, "override": function () { - core.statusBar.icons = { - floor: 0, - name: null, - lv: 1, - hpmax: 2, - hp: 3, - atk: 4, - def: 5, - mdef: 6, - money: 7, - exp: 8, - up: 9, - book: 10, - fly: 11, - toolbox: 12, - keyboard: 13, - shop: 14, - save: 15, - load: 16, - settings: 17, - play: 18, - pause: 19, - stop: 20, - speedDown: 21, - speedUp: 22, - rewind: 23, - equipbox: 24, - mana: 25, - skill: 26, - exit: 27, - btn1: 28, - btn2: 29, - btn3: 30, - btn4: 31, - btn5: 32, - btn6: 33, - btn7: 34, - alt: 35, - keys: 36, - help: 37, - battle: 38, - }; - core.actions._getClickLoc = function (x, y) { - var size = 32 * core.domStyle.scale; - var left = main.dom.gameDraw.offsetLeft + main.dom.gameGroup.offsetLeft; - var top = main.dom.gameDraw.offsetTop + main.dom.gameGroup.offsetTop; - var loc = { - x: Math.max(x - left, 0), - y: Math.max(y - top, 0), - size: size, - }; - return loc; - }; - core.ui._drawWindowSelector = function (background, x, y, w, h) { - w = Math.round(w) + 48; - h = Math.round(h); - var ctx = core.ui.createCanvas("_selector", x - 24, y, w, h, 165); - ctx.canvas.id = ""; - this._drawSelector(ctx, background, w, h); - }; + core.statusBar.icons = { + floor: 0, + name: null, + lv: 1, + hpmax: 2, + hp: 3, + atk: 4, + def: 5, + mdef: 6, + money: 7, + exp: 8, + up: 9, + book: 10, + fly: 11, + toolbox: 12, + keyboard: 13, + shop: 14, + save: 15, + load: 16, + settings: 17, + play: 18, + pause: 19, + stop: 20, + speedDown: 21, + speedUp: 22, + rewind: 23, + equipbox: 24, + mana: 25, + skill: 26, + exit: 27, + btn1: 28, + btn2: 29, + btn3: 30, + btn4: 31, + btn5: 32, + btn6: 33, + btn7: 34, + alt: 35, + keys: 36, + help: 37, + battle: 38, + }; + core.actions._getClickLoc = function (x, y) { + var size = 32 * core.domStyle.scale; + var left = main.dom.gameDraw.offsetLeft + main.dom.gameGroup.offsetLeft; + var top = main.dom.gameDraw.offsetTop + main.dom.gameGroup.offsetTop; + var loc = { + x: Math.max(x - left, 0), + y: Math.max(y - top, 0), + size: size, + }; + return loc; + }; + core.ui._drawWindowSelector = function (background, x, y, w, h) { + w = Math.round(w) + 48; + h = Math.round(h); + var ctx = core.ui.createCanvas("_selector", x - 24, y, w, h, 165); + ctx.canvas.id = ""; + this._drawSelector(ctx, background, w, h); + }; - core.ui._drawSelector = function (ctx, background, w, h, left, top) { - left = left || 0; - top = top || 0; - ctx = this.getContextByName(ctx); - if (!ctx) return; - if (typeof background == "string") - background = core.material.images.images[background]; - if (!(background instanceof Image)) return; - // badge - ctx.drawImage(background, 132, 68, 24, 24, left + 4, top + 4, 24, 24); - ctx.drawImage( - background, - 132, - 68, - 24, - 24, - w - left - 28, - top + 4, - 24, - 24 - ); - }; + core.ui._drawSelector = function (ctx, background, w, h, left, top) { + left = left || 0; + top = top || 0; + ctx = this.getContextByName(ctx); + if (!ctx) return; + if (typeof background == "string") + background = core.material.images.images[background]; + if (!(background instanceof Image)) return; + // badge + ctx.drawImage(background, 132, 68, 24, 24, left + 4, top + 4, 24, 24); + ctx.drawImage( + background, + 132, + 68, + 24, + 24, + w - left - 28, + top + 4, + 24, + 24 + ); + }; - enemys.prototype._nextCriticals_useBinarySearch = function ( - enemy, - info, - number, - x, - y, - floorId - ) { - var mon_hp = info.mon_hp, - hero_atk = core.status.hero.atk, - mon_def = info.mon_def, - pre = info.damage; - var list = []; - var start_atk = hero_atk; - if (info.__over__) { - start_atk += info.__overAtk__; - list.push([info.__overAtk__, -info.damage]); - } - var calNext = function (currAtk, maxAtk) { - var start = Math.floor(currAtk), - end = Math.floor(maxAtk); - if (start > end) return null; + enemys.prototype._nextCriticals_useBinarySearch = function ( + enemy, + info, + number, + x, + y, + floorId + ) { + var mon_hp = info.mon_hp, + hero_atk = core.status.hero.atk, + mon_def = info.mon_def, + pre = info.damage; + var list = []; + var start_atk = hero_atk; + if (info.__over__) { + start_atk += info.__overAtk__; + list.push([info.__overAtk__, -info.damage]); + } + var calNext = function (currAtk, maxAtk) { + var start = Math.floor(currAtk), + end = Math.floor(maxAtk); + if (start > end) return null; - while (start < end) { - var mid = Math.floor((start + end) / 2); - if (mid - start > end - mid) mid--; - var nextInfo = core.enemys.getDamageInfo( - enemy, - { atk: mid }, - x, - y, - floorId - ); - if (nextInfo == null || typeof nextInfo == "number") return null; - if (pre > nextInfo.damage) end = mid; - else start = mid + 1; - } - var nextInfo = core.enemys.getDamageInfo( - enemy, - { atk: start }, - x, - y, - floorId - ); - return nextInfo == null || - typeof nextInfo == "number" || - nextInfo.damage >= pre - ? null - : [start, nextInfo.damage]; - }; - var currAtk = start_atk; - while (true) { - var next = calNext(currAtk + 1, Number.MAX_SAFE_INTEGER, pre); - if (next == null) break; - currAtk = next[0]; - pre = next[1]; - list.push([currAtk - hero_atk, info.damage - pre]); - if (pre <= 0 && !core.flags.enableNegativeDamage) break; - if (list.length >= number) break; - } - if (list.length == 0) list.push([0, 0]); - return list; - }; - core.ui.clearMap = function (name, x, y, width, height) { - if (name == "all") { - for (var m in core.canvas) { - core.canvas[m].clearRect( - -32, - -32, - core.canvas[m].canvas.width + 32, - core.canvas[m].canvas.height + 32 - ); - } - core.clearMap("outerUI"); - core.dom.gif.innerHTML = ""; - core.removeGlobalAnimate(); - core.deleteCanvas(function (one) { - return one.startsWith("_bigImage_"); - }); - core.setWeather(null); - } else { - var ctx = this.getContextByName(name); - if (ctx) - ctx.clearRect( - x || 0, - y || 0, - width || ctx.canvas.width, - height || ctx.canvas.height - ); - } - }; - events.prototype.openBook = function (fromUserAction) { - if (core.isReplaying()) return; - // 如果能恢复事件(从callBook事件触发) - if ( - core.status.event.id == "book" && - core.events.recoverEvents(core.status.event.interval) - ) - return; - // 当前是book,且从“浏览地图”打开 - if (core.status.event.id == "book" && core.status.event.ui) { - core.status.boxAnimateObjs = []; - core.ui._drawViewMaps(core.status.event.ui); - return; - } - // 从“浏览地图”页面打开 - if (core.status.event.id == "viewMaps" || core.status.event.id == "fly") { - fromUserAction = false; - core.status.event.ui = core.status.event.data; - } - if (!this._checkStatus("book", fromUserAction, true)) return; - core.playSound("打开界面"); - core.useItem("book", true); - }; - ////// 怪物手册界面时,放开某个键的操作 ////// - core.actions._keyUpBook = function (keycode) { - if (keycode == 27 || keycode == 88) { - core.playSound("取消"); - if (core.events.recoverEvents(core.status.event.interval)) { - return; - } else if (core.status.event.ui != null) { - core.status.boxAnimateObjs = []; - if (typeof core.status.event.ui === "number") { - core.status.event.id = "fly"; - core.ui.drawFly(core.status.event.ui); - } else { - core.ui._drawViewMaps(core.status.event.ui); - } - } else core.ui.closePanel(); - return; - } - if (keycode == 13 || keycode == 32 || keycode == 67) { - var data = core.status.event.data; - if (data != null) { - core.ui._drawBookDetail(data); - } - return; - } - }; - ////// 怪物手册界面的点击操作 ////// - actions.prototype._clickBook = function (x, y) { - var pageinfo = core.ui._drawBook_pageinfo(); - // 上一页 - if ( - (x == this._HX_ - 2 || x == this._HX_ - 3) && - y === core._HEIGHT_ - 1 - ) { - core.playSound("光标移动"); - core.ui.drawBook(core.status.event.data - pageinfo.per_page); - return; - } - // 下一页 - if ( - (x == this._HX_ + 2 || x == this._HX_ + 3) && - y === core._HEIGHT_ - 1 - ) { - core.playSound("光标移动"); - core.ui.drawBook(core.status.event.data + pageinfo.per_page); - return; - } - // 返回 - if (x >= this.LAST - 2 && y === core._HEIGHT_ - 1) { - core.playSound("取消"); - if (core.events.recoverEvents(core.status.event.interval)) { - return; - } else if (core.status.event.ui != null) { - core.status.boxAnimateObjs = []; - if (typeof core.status.event.ui === "number") { - core.status.event.id = "fly"; - core.ui.drawFly(core.status.event.ui); - } else { - core.ui._drawViewMaps(core.status.event.ui); - } - } else core.ui.closePanel(); - return; - } - // 怪物信息 - var data = core.status.event.data; - if (data != null && y < core._HEIGHT_ - 1) { - var per_page = pageinfo.per_page, - page = parseInt(data / per_page); - var u = (core._HEIGHT_ - 1) / per_page; - for (var i = 0; i < per_page; ++i) { - if (y >= u * i && y < u * (i + 1)) { - var index = per_page * page + i; - core.ui.drawBook(index); - core.ui._drawBookDetail(index); - break; - } - } - return; - } - return; - }; + while (start < end) { + var mid = Math.floor((start + end) / 2); + if (mid - start > end - mid) mid--; + var nextInfo = core.enemys.getDamageInfo( + enemy, { atk: mid }, + x, + y, + floorId + ); + if (nextInfo == null || typeof nextInfo == "number") return null; + if (pre > nextInfo.damage) end = mid; + else start = mid + 1; + } + var nextInfo = core.enemys.getDamageInfo( + enemy, { atk: start }, + x, + y, + floorId + ); + return nextInfo == null || + typeof nextInfo == "number" || + nextInfo.damage >= pre ? + null : + [start, nextInfo.damage]; + }; + var currAtk = start_atk; + while (true) { + var next = calNext(currAtk + 1, Number.MAX_SAFE_INTEGER, pre); + if (next == null) break; + currAtk = next[0]; + pre = next[1]; + list.push([currAtk - hero_atk, info.damage - pre]); + if (pre <= 0 && !core.flags.enableNegativeDamage) break; + if (list.length >= number) break; + } + if (list.length == 0) list.push([0, 0]); + return list; + }; + core.ui.clearMap = function (name, x, y, width, height) { + if (name == "all") { + for (var m in core.canvas) { + core.canvas[m].clearRect( + -32, + -32, + core.canvas[m].canvas.width + 32, + core.canvas[m].canvas.height + 32 + ); + } + core.clearMap("outerUI"); + core.dom.gif.innerHTML = ""; + core.removeGlobalAnimate(); + core.deleteCanvas(function (one) { + return one.startsWith("_bigImage_"); + }); + core.setWeather(null); + } else { + var ctx = this.getContextByName(name); + if (ctx) + ctx.clearRect( + x || 0, + y || 0, + width || ctx.canvas.width, + height || ctx.canvas.height + ); + } + }; + events.prototype.openBook = function (fromUserAction) { + if (core.isReplaying()) return; + // 如果能恢复事件(从callBook事件触发) + if ( + core.status.event.id == "book" && + core.events.recoverEvents(core.status.event.interval) + ) + return; + // 当前是book,且从“浏览地图”打开 + if (core.status.event.id == "book" && core.status.event.ui) { + core.status.boxAnimateObjs = []; + core.ui._drawViewMaps(core.status.event.ui); + return; + } + // 从“浏览地图”页面打开 + if (core.status.event.id == "viewMaps" || core.status.event.id == "fly") { + fromUserAction = false; + core.status.event.ui = core.status.event.data; + } + if (!this._checkStatus("book", fromUserAction, true)) return; + core.playSound("打开界面"); + core.useItem("book", true); + }; + ////// 怪物手册界面时,放开某个键的操作 ////// + core.actions._keyUpBook = function (keycode) { + if (keycode == 27 || keycode == 88) { + core.playSound("取消"); + if (core.events.recoverEvents(core.status.event.interval)) { + return; + } else if (core.status.event.ui != null) { + core.status.boxAnimateObjs = []; + if (typeof core.status.event.ui === "number") { + core.status.event.id = "fly"; + core.ui.drawFly(core.status.event.ui); + } else { + core.ui._drawViewMaps(core.status.event.ui); + } + } else core.ui.closePanel(); + return; + } + if (keycode == 13 || keycode == 32 || keycode == 67) { + var data = core.status.event.data; + if (data != null) { + core.ui._drawBookDetail(data); + } + return; + } + }; + ////// 怪物手册界面的点击操作 ////// + actions.prototype._clickBook = function (x, y) { + var pageinfo = core.ui._drawBook_pageinfo(); + // 上一页 + if ( + (x == this._HX_ - 2 || x == this._HX_ - 3) && + y === core._HEIGHT_ - 1 + ) { + core.playSound("光标移动"); + core.ui.drawBook(core.status.event.data - pageinfo.per_page); + return; + } + // 下一页 + if ( + (x == this._HX_ + 2 || x == this._HX_ + 3) && + y === core._HEIGHT_ - 1 + ) { + core.playSound("光标移动"); + core.ui.drawBook(core.status.event.data + pageinfo.per_page); + return; + } + // 返回 + if (x >= this.LAST - 2 && y === core._HEIGHT_ - 1) { + core.playSound("取消"); + if (core.events.recoverEvents(core.status.event.interval)) { + return; + } else if (core.status.event.ui != null) { + core.status.boxAnimateObjs = []; + if (typeof core.status.event.ui === "number") { + core.status.event.id = "fly"; + core.ui.drawFly(core.status.event.ui); + } else { + core.ui._drawViewMaps(core.status.event.ui); + } + } else core.ui.closePanel(); + return; + } + // 怪物信息 + var data = core.status.event.data; + if (data != null && y < core._HEIGHT_ - 1) { + var per_page = pageinfo.per_page, + page = parseInt(data / per_page); + var u = (core._HEIGHT_ - 1) / per_page; + for (var i = 0; i < per_page; ++i) { + if (y >= u * i && y < u * (i + 1)) { + var index = per_page * page + i; + core.ui.drawBook(index); + core.ui._drawBookDetail(index); + break; + } + } + return; + } + return; + }; - ////// 执行当前自定义事件列表中的下一个事件 ////// - events.prototype.doAction = function () { - // 清空boxAnimate和UI层 - clearInterval(core.status.event.interval); - clearTimeout(core.status.event.interval); - clearInterval(core.status.event.animateUI); - core.status.event.interval = null; - delete core.status.event.aniamteUI; - if (core.status.gameOver || core.status.replay.failed) return; - // 判定是否执行完毕 - if (this._doAction_finishEvents()) return; - core.clearUI(); - var floorId = core.status.event.data.floorId || core.status.floorId; - // 当前点坐标和前缀 - var x = core.status.event.data.x, - y = core.status.event.data.y; - var prefix = [ - floorId || ":f", - x != null ? x : "x", - y != null ? y : "y", - ].join("@"); - var current = core.status.event.data.list[0]; - if (this._popEvents(current, prefix)) return; - // 当前要执行的事件 - var data = current.todo.shift(); - core.status.event.data.current = data; - if (typeof data == "string") data = { type: "text", text: data }; - // 该事件块已经被禁用 - if (data._disabled) return core.doAction(); - if (data.type !== "cgtext") { - core.unregisterAnimationFrame("skip"); - core.setFlag("skip", false); - } - data.floorId = data.floorId || floorId; - core.status.event.data.type = data.type; - this.doEvent(data, x, y, prefix); - return; - }; + ////// 执行当前自定义事件列表中的下一个事件 ////// + events.prototype.doAction = function () { + // 清空boxAnimate和UI层 + clearInterval(core.status.event.interval); + clearTimeout(core.status.event.interval); + clearInterval(core.status.event.animateUI); + core.status.event.interval = null; + delete core.status.event.aniamteUI; + if (core.status.gameOver || core.status.replay.failed) return; + // 判定是否执行完毕 + if (this._doAction_finishEvents()) return; + core.clearUI(); + var floorId = core.status.event.data.floorId || core.status.floorId; + // 当前点坐标和前缀 + var x = core.status.event.data.x, + y = core.status.event.data.y; + var prefix = [ + floorId || ":f", + x != null ? x : "x", + y != null ? y : "y", + ].join("@"); + var current = core.status.event.data.list[0]; + if (this._popEvents(current, prefix)) return; + // 当前要执行的事件 + var data = current.todo.shift(); + core.status.event.data.current = data; + if (typeof data == "string") data = { type: "text", text: data }; + // 该事件块已经被禁用 + if (data._disabled) return core.doAction(); + if (data.type !== "cgtext") { + core.unregisterAnimationFrame("skip"); + core.setFlag("skip", false); + } + data.floorId = data.floorId || floorId; + core.status.event.data.type = data.type; + this.doEvent(data, x, y, prefix); + return; + }; - ////// 在某个canvas上绘制粗体 ////// - core.fillBoldText1 = function ( - name, - text, - x, - y, - style, - strokeStyle, - lineWidth, - font, - maxWidth - ) { - var ctx = this.getContextByName(name); - if (!ctx) return; - if (font) ctx.font = font; - if (!style) style = ctx.fillStyle; - style = core.arrayToRGBA(style); - if (!strokeStyle) strokeStyle = "#000000"; - strokeStyle = core.arrayToRGBA(strokeStyle); - if (maxWidth != null) { - this.setFontForMaxWidth(ctx, text, maxWidth); - } - ctx.strokeStyle = strokeStyle; + ////// 在某个canvas上绘制粗体 ////// + core.fillBoldText1 = function ( + name, + text, + x, + y, + style, + strokeStyle, + lineWidth, + font, + maxWidth + ) { + var ctx = this.getContextByName(name); + if (!ctx) return; + if (font) ctx.font = font; + if (!style) style = ctx.fillStyle; + style = core.arrayToRGBA(style); + if (!strokeStyle) strokeStyle = "#000000"; + strokeStyle = core.arrayToRGBA(strokeStyle); + if (maxWidth != null) { + this.setFontForMaxWidth(ctx, text, maxWidth); + } + ctx.strokeStyle = strokeStyle; - if (!lineWidth) lineWidth = 2; - ctx.lineWidth = lineWidth; - ctx.strokeText(text, x, y); - ctx.fillStyle = style; - ctx.fillText(text, x, y); - }; - ////// 绘制 WindowSkin - ui.prototype.drawWindowSkin = function ( - background, - ctx, - x, - y, - w, - h, - direction, - px, - py, - size = 1 - ) { - background = background || core.status.textAttribute.background; + if (!lineWidth) lineWidth = 2; + ctx.lineWidth = lineWidth; + ctx.strokeText(text, x, y); + ctx.fillStyle = style; + ctx.fillText(text, x, y); + }; + ////// 绘制 WindowSkin + ui.prototype.drawWindowSkin = function ( + background, + ctx, + x, + y, + w, + h, + direction, + px, + py, + size = 1 + ) { + background = background || core.status.textAttribute.background; - // 仿RM窗口皮肤 ↓ - // 绘制背景 - core.drawImage( - ctx, - background, - 0, - 0, - 128, - 128, - x + 2 * size, - y + 2 * size, - w - 4 * size, - h - 4 * size - ); - // 绘制边框 - // 上方 - core.drawImage( - ctx, - background, - 128, - 0, - 16, - 16, - x, - y, - 16 * size, - 16 * size - ); - for (var dx = 0; dx < w - 64 * size; dx += 32 * size) { - core.drawImage( - ctx, - background, - 144, - 0, - 32, - 16, - x + dx + 16 * size, - y, - 32 * size, - 16 * size - ); - core.drawImage( - ctx, - background, - 144, - 48, - 32, - 16, - x + dx + 16 * size, - y + h - 16 * size, - 32 * size, - 16 * size - ); - } - core.drawImage( - ctx, - background, - 144, - 0, - (w - dx - 32 * size) / size, - 16, - x + dx + 16 * size, - y, - w - dx - 32 * size, - 16 * size - ); - core.drawImage( - ctx, - background, - 144, - 48, - (w - dx - 32 * size) / size, - 16, - x + dx + 16 * size, - y + h - 16 * size, - w - dx - 32 * size, - 16 * size - ); - core.drawImage( - ctx, - background, - 176, - 0, - 16, - 16, - x + w - 16 * size, - y, - 16 * size, - 16 * size - ); - // 左右 - for (var dy = 0; dy < h - 64 * size; dy += 32 * size) { - core.drawImage( - ctx, - background, - 128, - 16, - 16, - 32, - x, - y + dy + 16 * size, - 16 * size, - 32 * size - ); - core.drawImage( - ctx, - background, - 176, - 16, - 16, - 32, - x + w - 16 * size, - y + dy + 16 * size, - 16 * size, - 32 * size - ); - } - core.drawImage( - ctx, - background, - 128, - 16, - 16, - (h - dy - 32 * size) / size, - x, - y + dy + 16 * size, - 16 * size, - h - dy - 32 * size - ); - core.drawImage( - ctx, - background, - 176, - 16, - 16, - (h - dy - 32 * size) / size, - x + w - 16 * size, - y + dy + 16 * size, - 16 * size, - h - dy - 32 * size - ); - //下方 - core.drawImage( - ctx, - background, - 128, - 48, - 16, - 16, - x, - y + h - 16 * size, - 16 * size, - 16 * size - ); - core.drawImage( - ctx, - background, - 176, - 48, - 16, - 16, - x + w - 16 * size, - y + h - 16 * size, - 16 * size, - 16 * size - ); + // 仿RM窗口皮肤 ↓ + // 绘制背景 + core.drawImage( + ctx, + background, + 0, + 0, + 128, + 128, + x + 2 * size, + y + 2 * size, + w - 4 * size, + h - 4 * size + ); + // 绘制边框 + // 上方 + core.drawImage( + ctx, + background, + 128, + 0, + 16, + 16, + x, + y, + 16 * size, + 16 * size + ); + for (var dx = 0; dx < w - 64 * size; dx += 32 * size) { + core.drawImage( + ctx, + background, + 144, + 0, + 32, + 16, + x + dx + 16 * size, + y, + 32 * size, + 16 * size + ); + core.drawImage( + ctx, + background, + 144, + 48, + 32, + 16, + x + dx + 16 * size, + y + h - 16 * size, + 32 * size, + 16 * size + ); + } + core.drawImage( + ctx, + background, + 144, + 0, + (w - dx - 32 * size) / size, + 16, + x + dx + 16 * size, + y, + w - dx - 32 * size, + 16 * size + ); + core.drawImage( + ctx, + background, + 144, + 48, + (w - dx - 32 * size) / size, + 16, + x + dx + 16 * size, + y + h - 16 * size, + w - dx - 32 * size, + 16 * size + ); + core.drawImage( + ctx, + background, + 176, + 0, + 16, + 16, + x + w - 16 * size, + y, + 16 * size, + 16 * size + ); + // 左右 + for (var dy = 0; dy < h - 64 * size; dy += 32 * size) { + core.drawImage( + ctx, + background, + 128, + 16, + 16, + 32, + x, + y + dy + 16 * size, + 16 * size, + 32 * size + ); + core.drawImage( + ctx, + background, + 176, + 16, + 16, + 32, + x + w - 16 * size, + y + dy + 16 * size, + 16 * size, + 32 * size + ); + } + core.drawImage( + ctx, + background, + 128, + 16, + 16, + (h - dy - 32 * size) / size, + x, + y + dy + 16 * size, + 16 * size, + h - dy - 32 * size + ); + core.drawImage( + ctx, + background, + 176, + 16, + 16, + (h - dy - 32 * size) / size, + x + w - 16 * size, + y + dy + 16 * size, + 16 * size, + h - dy - 32 * size + ); + //下方 + core.drawImage( + ctx, + background, + 128, + 48, + 16, + 16, + x, + y + h - 16 * size, + 16 * size, + 16 * size + ); + core.drawImage( + ctx, + background, + 176, + 48, + 16, + 16, + x + w - 16 * size, + y + h - 16 * size, + 16 * size, + 16 * size + ); - // arrow - if (px != null && py != null) { - if (direction == "up") { - core.drawImage( - ctx, - background, - 128, - 96, - 32, - 32, - px, - y + h - 3 * size, - 32 * size, - 32 * size - ); - } else if (direction == "down") { - core.drawImage( - ctx, - background, - 160, - 96, - 32, - 32, - px, - y - 29 * size, - 32 * size, - 32 * size - ); - } - } - // 仿RM窗口皮肤 ↑ - }; - }, + // arrow + if (px != null && py != null) { + if (direction == "up") { + core.drawImage( + ctx, + background, + 128, + 96, + 32, + 32, + px, + y + h - 3 * size, + 32 * size, + 32 * size + ); + } else if (direction == "down") { + core.drawImage( + ctx, + background, + 160, + 96, + 32, + 32, + px, + y - 29 * size, + 32 * size, + 32 * size + ); + } + } + // 仿RM窗口皮肤 ↑ + }; +}, "额外信息": function () { /* 宝石血瓶左下角显示数值 * 注意!!!不要在道具属性中直接操作flags,使用core.status.hero.flags或core.setFlag系列函数代替! @@ -10713,8 +10711,24 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = }; //bgm相关复写 control.prototype.playBgm = (bgm, when) => { - if (!bgm || core.bgms.includes(bgm)) - bgmController.play(bgm, when); + bgm = core.getMappedName(bgm) + if (main.mode != "play" || !bgm || !core.bgms.includes(bgm)) return + if (!core.musicStatus.bgmStatus) { + try { + core.musicStatus.playingBgm = bgm; + core.musicStatus.lastBgm = bgm; + bgmController.pause(); + } catch (e) { + console.error(e); + } + return; + } + if ( + bgmController.playingBgm == bgm && isNil(when) + ) { + return; + } + bgmController.play(bgm, when); core.setMusicBtn(); }; control.prototype.pauseBgm = () => { @@ -15246,900 +15260,901 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = }; }, "剧情cg": function () { - // 在此增加新插件 - const cg = document.createElement("canvas"); //cg画布设置 - cg.style.position = "absolute"; - cg.style.zIndex = 300; - cg.style.display = "none"; - cg.id = "cgText"; - main.dom.gameGroup.insertAdjacentElement("afterend", cg); - cg.style.top = "50%"; - cg.style.left = "50%"; - cg.style.transform = "translate(-50%,-50%)"; - const ctx = cg.getContext("2d"); - main.dom.cgText = cg; - const logcanvas = document.createElement("canvas"); //cg画布设置 - logcanvas.style.position = "absolute"; - logcanvas.style.zIndex = 301; - logcanvas.style.display = "none"; - logcanvas.id = "cgText"; - main.dom.gameGroup.insertAdjacentElement("afterend", logcanvas); - logcanvas.style.top = "50%"; - logcanvas.style.left = "50%"; - logcanvas.style.transform = "translate(-50%,-50%)"; - const logctx = logcanvas.getContext("2d"); - main.dom.logcanvas = logcanvas; - logcanvas.onmouseup = function (e) { - //鼠标抬起 + // 在此增加新插件 + const cg = document.createElement("canvas"); //cg画布设置 + cg.style.position = "absolute"; + cg.style.zIndex = 300; + cg.style.display = "none"; + cg.id = "cgText"; + main.dom.gameGroup.insertAdjacentElement("afterend", cg); + cg.style.top = "50%"; + cg.style.left = "50%"; + cg.style.transform = "translate(-50%,-50%)"; + const ctx = cg.getContext("2d"); + main.dom.cgText = cg; + const logcanvas = document.createElement("canvas"); //cg画布设置 + logcanvas.style.position = "absolute"; + logcanvas.style.zIndex = 301; + logcanvas.style.display = "none"; + logcanvas.id = "cgText"; + main.dom.gameGroup.insertAdjacentElement("afterend", logcanvas); + logcanvas.style.top = "50%"; + logcanvas.style.left = "50%"; + logcanvas.style.transform = "translate(-50%,-50%)"; + const logctx = logcanvas.getContext("2d"); + main.dom.logcanvas = logcanvas; + logcanvas.onmouseup = function (e) { + //鼠标抬起 - try { - if (!core.isPlaying()) return false; - core.unregisterAnimationFrame("skip"); - let a = core.getFlag("skip", false); - core.setFlag("skip", false); - if (a) { - const data = core.clone(core.status.event.data.current); + try { + if (!core.isPlaying()) return false; + core.unregisterAnimationFrame("skip"); + let a = core.getFlag("skip", false); + core.setFlag("skip", false); + if (a) { + const data = core.clone(core.status.event.data.current); - core.insertAction(data); - core.doAction(); - } - } catch (ee) { - console.error(ee); - } - }; - logcanvas.onmousedown = function (e) { - //鼠标按下 - try { - if (!core.isPlaying()) return false; - const left = core.dom.gameGroup.offsetLeft; - const top = core.dom.gameGroup.offsetTop; - const px = Math.floor((e.clientX - left) / core.domStyle.scale), - py = Math.floor((e.clientY - top) / core.domStyle.scale); - core.ui.cgText.click(px * 3, py * 3); - } catch (ee) { - main.log(ee); - } - }; - logcanvas.ontouchend = function (e) { - //触摸抬起 + core.insertAction(data); + core.doAction(); + } + } catch (ee) { + console.error(ee); + } + }; + logcanvas.onmousedown = function (e) { + //鼠标按下 + try { + if (!core.isPlaying()) return false; + const left = core.dom.gameGroup.offsetLeft; + const top = core.dom.gameGroup.offsetTop; + const px = Math.floor((e.clientX - left) / core.domStyle.scale), + py = Math.floor((e.clientY - top) / core.domStyle.scale); + core.ui.cgText.click(px * 3, py * 3); + } catch (ee) { + main.log(ee); + } + }; + logcanvas.ontouchend = function (e) { + //触摸抬起 - try { - if (!core.isPlaying()) return false; - core.unregisterAnimationFrame("skip"); - core.setFlag("skip", false); - let a = core.getFlag("skip", false); - core.setFlag("skip", false); - if (a) { - const data = core.clone(core.status.event.data.current); + try { + if (!core.isPlaying()) return false; + core.unregisterAnimationFrame("skip"); + core.setFlag("skip", false); + let a = core.getFlag("skip", false); + core.setFlag("skip", false); + if (a) { + const data = core.clone(core.status.event.data.current); - core.insertAction(data); - core.doAction(); - } - } catch (ee) {} - }; - logcanvas.ontouchstart = function (e) { - //触摸按下 - try { - if (!core.isPlaying()) return false; - const left = core.dom.gameGroup.offsetLeft; - const top = core.dom.gameGroup.offsetTop; - const px = Math.floor( - (e.targetTouches[0].clientX - left) / core.domStyle.scale - ), - py = Math.floor( - (e.targetTouches[0].clientY - top) / core.domStyle.scale - ); - core.ui.cgText.click(px * 3, py * 3); - } catch (ee) { - main.log(ee); - } - }; - cg.onmouseup = function (e) { - //鼠标抬起 + core.insertAction(data); + core.doAction(); + } + } catch (ee) {} + }; + logcanvas.ontouchstart = function (e) { + //触摸按下 + try { + if (!core.isPlaying()) return false; + const left = core.dom.gameGroup.offsetLeft; + const top = core.dom.gameGroup.offsetTop; + const px = Math.floor( + (e.targetTouches[0].clientX - left) / core.domStyle.scale + ), + py = Math.floor( + (e.targetTouches[0].clientY - top) / core.domStyle.scale + ); + core.ui.cgText.click(px * 3, py * 3); + } catch (ee) { + main.log(ee); + } + }; + cg.onmouseup = function (e) { + //鼠标抬起 - try { - if (!core.isPlaying()) return false; - core.unregisterAnimationFrame("skip"); - let a = core.getFlag("skip", false); - core.setFlag("skip", false); - if (a) { - const data = core.clone(core.status.event.data.current); + try { + if (!core.isPlaying()) return false; + core.unregisterAnimationFrame("skip"); + let a = core.getFlag("skip", false); + core.setFlag("skip", false); + if (a) { + const data = core.clone(core.status.event.data.current); - core.insertAction(data); - core.doAction(); - } - } catch (ee) { - console.error(ee); - } - }; - cg.onmousedown = function (e) { - //鼠标按下 - try { - if (!core.isPlaying()) return false; - const left = core.dom.gameGroup.offsetLeft; - const top = core.dom.gameGroup.offsetTop; - const px = Math.floor((e.clientX - left) / core.domStyle.scale), - py = Math.floor((e.clientY - top) / core.domStyle.scale); - core.ui.cgText.click(px * 3, py * 3); - } catch (ee) { - main.log(ee); - } - }; - cg.ontouchend = function (e) { - //触摸抬起 + core.insertAction(data); + core.doAction(); + } + } catch (ee) { + console.error(ee); + } + }; + cg.onmousedown = function (e) { + //鼠标按下 + try { + if (!core.isPlaying()) return false; + const left = core.dom.gameGroup.offsetLeft; + const top = core.dom.gameGroup.offsetTop; + const px = Math.floor((e.clientX - left) / core.domStyle.scale), + py = Math.floor((e.clientY - top) / core.domStyle.scale); + core.ui.cgText.click(px * 3, py * 3); + } catch (ee) { + main.log(ee); + } + }; + cg.ontouchend = function (e) { + //触摸抬起 - try { - if (!core.isPlaying()) return false; - core.unregisterAnimationFrame("skip"); - core.setFlag("skip", false); - let a = core.getFlag("skip", false); - core.setFlag("skip", false); - if (a) { - const data = core.clone(core.status.event.data.current); + try { + if (!core.isPlaying()) return false; + core.unregisterAnimationFrame("skip"); + core.setFlag("skip", false); + let a = core.getFlag("skip", false); + core.setFlag("skip", false); + if (a) { + const data = core.clone(core.status.event.data.current); - core.insertAction(data); - core.doAction(); - } - } catch (ee) { - console.error(ee); - } - }; - cg.ontouchstart = function (e) { - //触摸按下 - try { - if (!core.isPlaying()) return false; - const left = core.dom.gameGroup.offsetLeft; - const top = core.dom.gameGroup.offsetTop; - const px = Math.floor( - (e.targetTouches[0].clientX - left) / core.domStyle.scale - ), - py = Math.floor( - (e.targetTouches[0].clientY - top) / core.domStyle.scale - ); - core.ui.cgText.click(px * 3, py * 3); - } catch (ee) { - main.log(ee); - } - }; - let auto = false; + core.insertAction(data); + core.doAction(); + } + } catch (ee) { + console.error(ee); + } + }; + cg.ontouchstart = function (e) { + //触摸按下 + try { + if (!core.isPlaying()) return false; + const left = core.dom.gameGroup.offsetLeft; + const top = core.dom.gameGroup.offsetTop; + const px = Math.floor( + (e.targetTouches[0].clientX - left) / core.domStyle.scale + ), + py = Math.floor( + (e.targetTouches[0].clientY - top) / core.domStyle.scale + ); + core.ui.cgText.click(px * 3, py * 3); + } catch (ee) { + main.log(ee); + } + }; + let auto = false; - class cgText { - constructor() { - //绘制需要的变量 - this.image = ""; - this.head = { name: "face_050445.webp", px: -300 }; - this.bodyList = [ - { name: "tati_050145a.webp", px: 100, filter: false }, - { name: "tati_120124.webp", px: 1100, filter: true }, - ]; - this.name = ""; - this.text = ""; - this.time = 0; - this.WindowSkin = false; - this.sound = ""; - this.beforeSound = 0; - this.wait = 1000; - this.memory = false; - this.textList = []; - this.page = 1; - this.overpage = 1; - this.log = false; - this.index = 0; - } - click(px, py) { - //点击效果 + class cgText { + constructor() { + //绘制需要的变量 + this.image = ""; + this.head = { name: "face_050445.webp", px: -300 }; + this.bodyList = [ + { name: "tati_050145a.webp", px: 100, filter: false }, + { name: "tati_120124.webp", px: 1100, filter: true }, + ]; + this.name = ""; + this.text = ""; + this.time = 0; + this.WindowSkin = false; + this.sound = ""; + this.beforeSound = 0; + this.wait = 1000; + this.memory = false; + this.textList = []; + this.page = 1; + this.overpage = 1; + this.log = false; + this.index = 0; + } + click(px, py) { + //点击效果 - const makeBox = ([x, y], [w, h]) => { - return [ - [x, y], - [x + w, y + h], - ]; - }; - const inRect = ([x, y], [[sx, sy], [dx, dy]]) => { - return sx <= x && x <= dx && sy <= y && y <= dy; - }; - const pos = [px, py]; - const savebox = makeBox([1700, 1100], [192, 96]); - const saveboxVertical = makeBox([52, 1700], [96, 192]); - const skipbox = makeBox([1700, 1000], [192, 96]); - const skipboxVertical = makeBox([152, 1700], [96, 192]); - const autobox = makeBox([1700, 900], [192, 96]); - const autoboxVertical = makeBox([252, 1700], [96, 192]); - const textbox = makeBox([1700, 800], [192, 96]); - const textboxVertical = makeBox([352, 1700], [96, 192]); - const backbox = makeBox([15, 35], [210, 90]); - const backboxVertical = makeBox([1123, 15], [90, 210]); - const pageupbox = makeBox([300, 1130], [200, 100]); - const pageupboxVertical = makeBox([18, 300], [100, 200]); - const pagedownbox = makeBox([1500, 1130], [200, 100]); - const pagedownboxVertical = makeBox([18, 1500], [100, 200]); - if (this.log) { - if ( - (core.domStyle.isVertical && inRect(pos, backboxVertical)) || - (!core.domStyle.isVertical && inRect(pos, backbox)) - ) { - core.clearMap(logctx); - main.dom.logcanvas.style.display = "none"; - this.log = false; - } else if ( - (core.domStyle.isVertical && inRect(pos, pageupboxVertical)) || - (!core.domStyle.isVertical && inRect(pos, pageupbox)) - ) { - core.clearMap(logctx); - if (this.page > 1) this.page--; - this.logdraw(this.page); - } else if ( - (core.domStyle.isVertical && inRect(pos, pagedownboxVertical)) || - (!core.domStyle.isVertical && inRect(pos, pagedownbox)) - ) { - core.clearMap(logctx); - if (this.page < this.overpage) this.page++; - this.logdraw(this.page); - } - } else { - if ( - (core.domStyle.isVertical && - inRect(pos, skipboxVertical) && - !this.WindowSkin) || - (!core.domStyle.isVertical && - !this.WindowSkin && - inRect(pos, skipbox)) - ) { - auto = false; - let time = 0; - core.stopSound(this.beforeSound); - core.registerAnimationFrame("skip", true, (timestamp) => { - if (timestamp > time + 50) { - time = timestamp; - if ( - core.status.event.id == "action" && - core.status.event.data.type == "cgtext" - ) { - core.setFlag("skip", true); - main.dom.cgText.style.display = "none"; - core.doAction(); - } - } - }); - } else if ( - (core.domStyle.isVertical && - inRect(pos, textboxVertical) && - !this.WindowSkin) || - (!core.domStyle.isVertical && - !this.WindowSkin && - inRect(pos, textbox)) - ) { - auto = false; - this.log = true; - this.overpage = Math.floor(this.index / 6) + 1; - this.page = this.overpage; - logcanvas.style.display = "block"; - const data = core.clone(core.status.event.data.current); - data.showAll = true; - data.time = 0; - data.text = this.text.replaceAll(/(\\(z))(\[.*?\])?/g, ""); //去除打字机暂停效果 - data.sound = ""; - core.insertAction(data); - core.doAction(); - this.logdraw(this.page); - } else if ( - (core.domStyle.isVertical && - inRect(pos, autoboxVertical) && - !this.WindowSkin) || - (!core.domStyle.isVertical && - !this.WindowSkin && - inRect(pos, autobox)) - ) { - auto = !auto; + const makeBox = ([x, y], [w, h]) => { + return [ + [x, y], + [x + w, y + h], + ]; + }; + const inRect = ([x, y], [ + [sx, sy], + [dx, dy] + ]) => { + return sx <= x && x <= dx && sy <= y && y <= dy; + }; + const pos = [px, py]; + const savebox = makeBox([1700, 1100], [192, 96]); + const saveboxVertical = makeBox([52, 1700], [96, 192]); + const skipbox = makeBox([1700, 1000], [192, 96]); + const skipboxVertical = makeBox([152, 1700], [96, 192]); + const autobox = makeBox([1700, 900], [192, 96]); + const autoboxVertical = makeBox([252, 1700], [96, 192]); + const textbox = makeBox([1700, 800], [192, 96]); + const textboxVertical = makeBox([352, 1700], [96, 192]); + const backbox = makeBox([15, 35], [210, 90]); + const backboxVertical = makeBox([1123, 15], [90, 210]); + const pageupbox = makeBox([300, 1130], [200, 100]); + const pageupboxVertical = makeBox([18, 300], [100, 200]); + const pagedownbox = makeBox([1500, 1130], [200, 100]); + const pagedownboxVertical = makeBox([18, 1500], [100, 200]); + if (this.log) { + if ( + (core.domStyle.isVertical && inRect(pos, backboxVertical)) || + (!core.domStyle.isVertical && inRect(pos, backbox)) + ) { + core.clearMap(logctx); + main.dom.logcanvas.style.display = "none"; + this.log = false; + } else if ( + (core.domStyle.isVertical && inRect(pos, pageupboxVertical)) || + (!core.domStyle.isVertical && inRect(pos, pageupbox)) + ) { + core.clearMap(logctx); + if (this.page > 1) this.page--; + this.logdraw(this.page); + } else if ( + (core.domStyle.isVertical && inRect(pos, pagedownboxVertical)) || + (!core.domStyle.isVertical && inRect(pos, pagedownbox)) + ) { + core.clearMap(logctx); + if (this.page < this.overpage) this.page++; + this.logdraw(this.page); + } + } else { + if ( + (core.domStyle.isVertical && + inRect(pos, skipboxVertical) && + !this.WindowSkin) || + (!core.domStyle.isVertical && + !this.WindowSkin && + inRect(pos, skipbox)) + ) { + auto = false; + let time = 0; + core.stopSound(this.beforeSound); + core.registerAnimationFrame("skip", true, (timestamp) => { + if (timestamp > time + 50) { + time = timestamp; + if ( + core.status.event.id == "action" && + core.status.event.data.type == "cgtext" + ) { + core.setFlag("skip", true); + main.dom.cgText.style.display = "none"; + core.doAction(); + } + } + }); + } else if ( + (core.domStyle.isVertical && + inRect(pos, textboxVertical) && + !this.WindowSkin) || + (!core.domStyle.isVertical && + !this.WindowSkin && + inRect(pos, textbox)) + ) { + auto = false; + this.log = true; + this.overpage = Math.floor(this.index / 6) + 1; + this.page = this.overpage; + logcanvas.style.display = "block"; + const data = core.clone(core.status.event.data.current); + data.showAll = true; + data.time = 0; + data.text = this.text.replaceAll(/(\\(z))(\[.*?\])?/g, ""); //去除打字机暂停效果 + data.sound = ""; + core.insertAction(data); + core.doAction(); + this.logdraw(this.page); + } else if ( + (core.domStyle.isVertical && + inRect(pos, autoboxVertical) && + !this.WindowSkin) || + (!core.domStyle.isVertical && + !this.WindowSkin && + inRect(pos, autobox)) + ) { + auto = !auto; - const data = core.clone(core.status.event.data.current); - data.showAll = true; - data.time = 0; - data.text = this.text.replaceAll(/(\\(z))(\[.*?\])?/g, ""); //去除打字机暂停效果 - data.sound = ""; - core.insertAction(data); - core.doAction(); - } else if ( - (core.domStyle.isVertical && - inRect(pos, saveboxVertical) && - !this.WindowSkin) || - (!core.domStyle.isVertical && - !this.WindowSkin && - inRect(pos, savebox)) - ) { - //存档 - auto = false; - if (core.status.event.animateUI) return; - if (core.status.event.interval != null) return; - const current = core.clone(core.status.event.data.current); - current.showAll = true; - current.time = 0; - current.sound = ""; - current.text = this.text.replaceAll(/(\\(z))(\[.*?\])?/g, ""); //去除当前事件所有打字机效果 - cg.style.display = "none"; - const data = [{ type: "callSave" }, current]; //插入存档事件 - core.insertAction(data); + const data = core.clone(core.status.event.data.current); + data.showAll = true; + data.time = 0; + data.text = this.text.replaceAll(/(\\(z))(\[.*?\])?/g, ""); //去除打字机暂停效果 + data.sound = ""; + core.insertAction(data); + core.doAction(); + } else if ( + (core.domStyle.isVertical && + inRect(pos, saveboxVertical) && + !this.WindowSkin) || + (!core.domStyle.isVertical && + !this.WindowSkin && + inRect(pos, savebox)) + ) { + //存档 + auto = false; + if (core.status.event.animateUI) return; + if (core.status.event.interval != null) return; + const current = core.clone(core.status.event.data.current); + current.showAll = true; + current.time = 0; + current.sound = ""; + current.text = this.text.replaceAll(/(\\(z))(\[.*?\])?/g, ""); //去除当前事件所有打字机效果 + cg.style.display = "none"; + const data = [{ type: "callSave" }, current]; //插入存档事件 + core.insertAction(data); - core.doAction(); - } else if (!core.status.event.data) { - cg.style.display = "none"; - core.ui._animateUI("hide", null, () => { - core.doAction(); - }); - } else { - // 正在淡入淡出的话不执行 - if (core.status.event.animateUI) return; - auto = false; + core.doAction(); + } else if (!core.status.event.data) { + cg.style.display = "none"; + core.ui._animateUI("hide", null, () => { + core.doAction(); + }); + } else { + // 正在淡入淡出的话不执行 + if (core.status.event.animateUI) return; + auto = false; - // 打字机效果显示全部文字 - if (core.status.event.interval != null) { - const data = core.clone(core.status.event.data?.current); - data.showAll = true; - data.time = 0; - data.text = this.text.replaceAll(/(\\(z))(\[.*?\])?/g, ""); //去除打字机暂停效果 - data.sound = ""; - core.insertAction(data); - core.doAction(); - return; - } else { - core.stopSound(this.beforeSound); - } + // 打字机效果显示全部文字 + if (core.status.event.interval != null) { + const data = core.clone(core.status.event.data?.current); + data.showAll = true; + data.time = 0; + data.text = this.text.replaceAll(/(\\(z))(\[.*?\])?/g, ""); //去除打字机暂停效果 + data.sound = ""; + core.insertAction(data); + core.doAction(); + return; + } else { + core.stopSound(this.beforeSound); + } - cg.style.display = "none"; - core.ui._animateUI("hide", null, () => { - core.doAction(); - }); - } - } - } + cg.style.display = "none"; + core.ui._animateUI("hide", null, () => { + core.doAction(); + }); + } + } + } - drawTextContent(ctx, content, config) { - //绘制多行文字并执行打字机效果 + drawTextContent(ctx, content, config) { + //绘制多行文字并执行打字机效果 - ctx = core.getContextByName(ctx); - // 设置默认配置项 - var textAttribute = - core.status.textAttribute || core.initStatus.textAttribute; - var globalAttribute = - core.status.globalAttribute || core.initStatus.globalAttribute; - config = core.clone(config || {}); - config.left = config.left || 0; - config.right = - config.left + (config.maxWidth == null ? core._PX_ : config.maxWidth); - config.top = config.top || 0; - config.color = core.arrayToRGBA(config.color || textAttribute.text); - if (config.bold == null) config.bold = textAttribute.bold; - config.italic = config.italic || false; - config.align = config.align || textAttribute.align || "left"; - config.fontSize = config.fontSize || textAttribute.textfont; - config.lineHeight = config.lineHeight || config.fontSize * 1.3; - config.defaultFont = config.font = config.font || globalAttribute.font; - config.time = config.time || 0; - config.letterSpacing = - config.letterSpacing == null - ? textAttribute.letterSpacing || 0 - : config.letterSpacing; + ctx = core.getContextByName(ctx); + // 设置默认配置项 + var textAttribute = + core.status.textAttribute || core.initStatus.textAttribute; + var globalAttribute = + core.status.globalAttribute || core.initStatus.globalAttribute; + config = core.clone(config || {}); + config.left = config.left || 0; + config.right = + config.left + (config.maxWidth == null ? core._PX_ : config.maxWidth); + config.top = config.top || 0; + config.color = core.arrayToRGBA(config.color || textAttribute.text); + if (config.bold == null) config.bold = textAttribute.bold; + config.italic = config.italic || false; + config.align = config.align || textAttribute.align || "left"; + config.fontSize = config.fontSize || textAttribute.textfont; + config.lineHeight = config.lineHeight || config.fontSize * 1.3; + config.defaultFont = config.font = config.font || globalAttribute.font; + config.time = config.time || 0; + config.letterSpacing = + config.letterSpacing == null ? + textAttribute.letterSpacing || 0 : + config.letterSpacing; - config.index = 0; - config.currcolor = config.color; - config.currfont = config.fontSize; - config.lineMargin = Math.max( - Math.round(config.fontSize / 4), - config.lineHeight - config.fontSize - ); - config.topMargin = parseInt(config.lineMargin / 2); - config.lineMaxHeight = config.lineMargin + config.fontSize; - config.offsetX = 0; - config.offsetY = 0; - config.line = 0; - config.blocks = []; - config.isHD = ctx == null || ctx.canvas.hasAttribute("isHD"); + config.index = 0; + config.currcolor = config.color; + config.currfont = config.fontSize; + config.lineMargin = Math.max( + Math.round(config.fontSize / 4), + config.lineHeight - config.fontSize + ); + config.topMargin = parseInt(config.lineMargin / 2); + config.lineMaxHeight = config.lineMargin + config.fontSize; + config.offsetX = 0; + config.offsetY = 0; + config.line = 0; + config.blocks = []; + config.isHD = ctx == null || ctx.canvas.hasAttribute("isHD"); - // 创建一个新的临时画布 - var tempCtx = document.createElement("canvas").getContext("2d"); - if (config.isHD && ctx) { - core.maps._setHDCanvasSize( - tempCtx, - ctx.canvas.width, - ctx.canvas.height - ); - } else { - tempCtx.canvas.width = ctx == null ? 1 : ctx.canvas.width; - tempCtx.canvas.height = ctx == null ? 1 : ctx.canvas.height; - } + // 创建一个新的临时画布 + var tempCtx = document.createElement("canvas").getContext("2d"); + if (config.isHD && ctx) { + core.maps._setHDCanvasSize( + tempCtx, + ctx.canvas.width, + ctx.canvas.height + ); + } else { + tempCtx.canvas.width = ctx == null ? 1 : ctx.canvas.width; + tempCtx.canvas.height = ctx == null ? 1 : ctx.canvas.height; + } - tempCtx.textBaseline = "top"; - tempCtx.font = core.ui._buildFont( - config.fontSize, - config.bold, - config.italic, - config.font - ); - tempCtx.fillStyle = config.color; - config = this._drawTextContent_draw(ctx, tempCtx, content, config); - return config; - } - _drawTextContent_draw(ctx, tempCtx, content, config) { - // Step 1: 绘制到tempCtx上,并记录下图块信息 - while (core.ui._drawTextContent_next(tempCtx, content, config)); + tempCtx.textBaseline = "top"; + tempCtx.font = core.ui._buildFont( + config.fontSize, + config.bold, + config.italic, + config.font + ); + tempCtx.fillStyle = config.color; + config = this._drawTextContent_draw(ctx, tempCtx, content, config); + return config; + } + _drawTextContent_draw(ctx, tempCtx, content, config) { + // Step 1: 绘制到tempCtx上,并记录下图块信息 + while (core.ui._drawTextContent_next(tempCtx, content, config)); - if (ctx == null) return config; + if (ctx == null) return config; - // Step 2: 从tempCtx绘制到画布上 - config.index = 0; - var _drawNext = function () { - if (config.index >= config.blocks.length) return false; - var block = config.blocks[config.index++]; - if (block != null) { - // It works, why? - const scale = config.isHD - ? devicePixelRatio * core.domStyle.scale - : 1; - ctx.restore(); - ctx.save(); //保存设置 - if (core.domStyle.isVertical) { - ctx.translate(1248, 0); //重新定位右上角为基准 - ctx.rotate(Math.PI / 2); //旋转90度 - } - ctx.drawImage( - tempCtx.canvas, - block.left * scale, - block.top * scale, - block.width * scale, - block.height * scale, - config.left + block.left + block.marginLeft, - config.top + block.top + block.marginTop, - block.width, - block.height - ); - ctx.restore(); - } - return true; - }; + // Step 2: 从tempCtx绘制到画布上 + config.index = 0; + var _drawNext = function () { + if (config.index >= config.blocks.length) return false; + var block = config.blocks[config.index++]; + if (block != null) { + // It works, why? + const scale = config.isHD ? + devicePixelRatio * core.domStyle.scale : + 1; + ctx.restore(); + ctx.save(); //保存设置 + if (core.domStyle.isVertical) { + ctx.translate(1248, 0); //重新定位右上角为基准 + ctx.rotate(Math.PI / 2); //旋转90度 + } + ctx.drawImage( + tempCtx.canvas, + block.left * scale, + block.top * scale, + block.width * scale, + block.height * scale, + config.left + block.left + block.marginLeft, + config.top + block.top + block.marginTop, + block.width, + block.height + ); + ctx.restore(); + } + return true; + }; - if (config.time == 0) { - while (_drawNext()); + if (config.time == 0) { + while (_drawNext()); - if ( - (auto && !core.ui.cgText.WindowSkin && !core.ui.cgText.sound) || - (core.ui.cgText.sound && !core.musicStatus.soundStatus) - ) { - setTimeout(() => { - if (auto) { - cg.style.display = "none"; - core.ui._animateUI("hide", null, () => { - core.doAction(); - }); - } - }, core.ui.cgText.wait); - } - } else { - clearInterval(core.status.event.interval); - core.status.event.interval = setInterval(function () { - if (!_drawNext()) { - clearInterval(core.status.event.interval); - core.status.event.interval = null; + if ( + (auto && !core.ui.cgText.WindowSkin && !core.ui.cgText.sound) || + (core.ui.cgText.sound && !core.musicStatus.soundStatus) + ) { + setTimeout(() => { + if (auto) { + cg.style.display = "none"; + core.ui._animateUI("hide", null, () => { + core.doAction(); + }); + } + }, core.ui.cgText.wait); + } + } else { + clearInterval(core.status.event.interval); + core.status.event.interval = setInterval(function () { + if (!_drawNext()) { + clearInterval(core.status.event.interval); + core.status.event.interval = null; - if ( - (auto && !core.ui.cgText.WindowSkin && !core.ui.cgText.sound) || - (core.ui.cgText.sound && !core.musicStatus.soundStatus) - ) - setTimeout(() => { - if (auto) { - cg.style.display = "none"; - core.ui._animateUI("hide", null, () => { - core.doAction(); - }); - } - }, core.ui.cgText.wait); - } - }, config.time); - } + if ( + (auto && !core.ui.cgText.WindowSkin && !core.ui.cgText.sound) || + (core.ui.cgText.sound && !core.musicStatus.soundStatus) + ) + setTimeout(() => { + if (auto) { + cg.style.display = "none"; + core.ui._animateUI("hide", null, () => { + core.doAction(); + }); + } + }, core.ui.cgText.wait); + } + }, config.time); + } - return config; - } + return config; + } - update() { - this.background(); - if (this.log) this.logdraw(this.page); - } - logdraw(page) { - if (core.domStyle.isVertical) { - logctx.canvas.width = 1248; - logctx.canvas.height = 2028; - logctx.save(); //保存设置 - logctx.translate(1248, 0); //重新定位右上角为基准 - logctx.rotate(Math.PI / 2); //旋转90度 - } else { - logctx.canvas.width = 2028; - logctx.canvas.height = 1248; - } - core.fillRect(logctx, 0, 0, 2028, 1248, "rgba(0,0,0,0.5)"); - core.setTextAlign(logctx, "center"); - core.fillBoldText1( - logctx, - "◀离开", - 110, - 100, - "#FFFFFF", - "#000000", - 6, - core.ui._buildFont(66, true) - ); - logctx.strokeStyle = "#FFFFFF"; - logctx.lineWidth = 3; - logctx.beginPath(); - logctx.moveTo(100, 150); - logctx.lineTo(1928, 150); + update() { + this.background(); + if (this.log) this.logdraw(this.page); + } + logdraw(page) { + if (core.domStyle.isVertical) { + logctx.canvas.width = 1248; + logctx.canvas.height = 2028; + logctx.save(); //保存设置 + logctx.translate(1248, 0); //重新定位右上角为基准 + logctx.rotate(Math.PI / 2); //旋转90度 + } else { + logctx.canvas.width = 2028; + logctx.canvas.height = 1248; + } + core.fillRect(logctx, 0, 0, 2028, 1248, "rgba(0,0,0,0.5)"); + core.setTextAlign(logctx, "center"); + core.fillBoldText1( + logctx, + "◀离开", + 110, + 100, + "#FFFFFF", + "#000000", + 6, + core.ui._buildFont(66, true) + ); + logctx.strokeStyle = "#FFFFFF"; + logctx.lineWidth = 3; + logctx.beginPath(); + logctx.moveTo(100, 150); + logctx.lineTo(1928, 150); - logctx.stroke(); - let posy = 150; - const indexList = this.textList; - core.setTextAlign(logctx, "left"); - for ( - let i = (page - 1) * 6; - i <= Math.min(this.index, page * 6 - 1); - i++ - ) { - const text = this.textList[i][1].replaceAll( - /(\\(d|e|f|g|i|n|r|b|c|t|z))(\[.*?\])?/g, - "" - ); //取消打字机 - const name = this.textList[i][0] - ? "【" + this.textList[i][0] + "】" - : ""; - if (name) { - core.fillBoldText1( - logctx, - name, - 150, - posy + 50, - "#FFFFFF", - "#000000", - 6, - core.ui._buildFont(42, true) - ); - } - if (text.length < 30) { - core.fillBoldText1( - logctx, - text, - 650, - posy + 50, - "#FFFFFF", - "#000000", - 6, - core.ui._buildFont(42, true) - ); - } else { - let text1 = text.slice(0, 30); - core.fillBoldText1( - logctx, - text1, - 650, - posy + 50, - "#FFFFFF", - "#000000", - 6, - core.ui._buildFont(42, true) - ); - if (text.length > 60) { - let text2 = text.slice(30, 60); - let text3 = text.slice(60); - core.fillBoldText1( - logctx, - text2, - 650, - posy + 100, - "#FFFFFF", - "#000000", - 6, - core.ui._buildFont(42, true) - ); - core.fillBoldText1( - logctx, - text3, - 650, - posy + 150, - "#FFFFFF", - "#000000", - 6, - core.ui._buildFont(42, true) - ); - } else { - let text2 = text.slice(30); - core.fillBoldText1( - logctx, - text2, - 650, - posy + 100, - "#FFFFFF", - "#000000", - 6, - core.ui._buildFont(42, true) - ); - } - } + logctx.stroke(); + let posy = 150; + const indexList = this.textList; + core.setTextAlign(logctx, "left"); + for ( + let i = (page - 1) * 6; i <= Math.min(this.index, page * 6 - 1); i++ + ) { + const text = this.textList[i][1].replaceAll( + /(\\(d|e|f|g|i|n|r|b|c|t|z))(\[.*?\])?/g, + "" + ); //取消打字机 + const name = this.textList[i][0] ? + "【" + this.textList[i][0] + "】" : + ""; + if (name) { + core.fillBoldText1( + logctx, + name, + 150, + posy + 50, + "#FFFFFF", + "#000000", + 6, + core.ui._buildFont(42, true) + ); + } + if (text.length < 30) { + core.fillBoldText1( + logctx, + text, + 650, + posy + 50, + "#FFFFFF", + "#000000", + 6, + core.ui._buildFont(42, true) + ); + } else { + let text1 = text.slice(0, 30); + core.fillBoldText1( + logctx, + text1, + 650, + posy + 50, + "#FFFFFF", + "#000000", + 6, + core.ui._buildFont(42, true) + ); + if (text.length > 60) { + let text2 = text.slice(30, 60); + let text3 = text.slice(60); + core.fillBoldText1( + logctx, + text2, + 650, + posy + 100, + "#FFFFFF", + "#000000", + 6, + core.ui._buildFont(42, true) + ); + core.fillBoldText1( + logctx, + text3, + 650, + posy + 150, + "#FFFFFF", + "#000000", + 6, + core.ui._buildFont(42, true) + ); + } else { + let text2 = text.slice(30); + core.fillBoldText1( + logctx, + text2, + 650, + posy + 100, + "#FFFFFF", + "#000000", + 6, + core.ui._buildFont(42, true) + ); + } + } - logctx.strokeStyle = "#FFFFFF"; - logctx.lineWidth = 3; - logctx.beginPath(); - logctx.moveTo(100, posy); - logctx.lineTo(1928, posy); - logctx.stroke(); + logctx.strokeStyle = "#FFFFFF"; + logctx.lineWidth = 3; + logctx.beginPath(); + logctx.moveTo(100, posy); + logctx.lineTo(1928, posy); + logctx.stroke(); - posy += 160; - } - logctx.beginPath(); - logctx.moveTo(100, 1120); - logctx.lineTo(1928, 1120); - logctx.moveTo(100, 1110); - logctx.lineTo(1928, 1110); - logctx.stroke(); - core.fillBoldText1( - logctx, - "上一页", - 300, - 1200, - page === 1 ? "#444444" : "#FFFFFF", - "#000000", - 6, - core.ui._buildFont(66, true) - ); + posy += 160; + } + logctx.beginPath(); + logctx.moveTo(100, 1120); + logctx.lineTo(1928, 1120); + logctx.moveTo(100, 1110); + logctx.lineTo(1928, 1110); + logctx.stroke(); + core.fillBoldText1( + logctx, + "上一页", + 300, + 1200, + page === 1 ? "#444444" : "#FFFFFF", + "#000000", + 6, + core.ui._buildFont(66, true) + ); - core.fillBoldText1( - logctx, - page + "/" + this.overpage, - 1000, - 1200, - "#FFFFFF", - "#000000", - 6, - core.ui._buildFont(66, true) - ); - core.fillBoldText1( - logctx, - "下一页", - 1500, - 1200, - page === this.overpage ? "#444444" : "#FFFFFF", - "#000000", - 6, - core.ui._buildFont(66, true) - ); - } - background() { - const img = core.material.images.images?.[this.image]; + core.fillBoldText1( + logctx, + page + "/" + this.overpage, + 1000, + 1200, + "#FFFFFF", + "#000000", + 6, + core.ui._buildFont(66, true) + ); + core.fillBoldText1( + logctx, + "下一页", + 1500, + 1200, + page === this.overpage ? "#444444" : "#FFFFFF", + "#000000", + 6, + core.ui._buildFont(66, true) + ); + } + background() { + const img = core.material.images.images?.[this.image]; - if (core.domStyle.isVertical) { - ctx.canvas.width = 1248; - ctx.canvas.height = 2028; - ctx.save(); //保存设置 - ctx.translate(1248, 0); //重新定位右上角为基准 - ctx.rotate(Math.PI / 2); //旋转90度 - } else { - ctx.canvas.width = 2028; - ctx.canvas.height = 1248; - } + if (core.domStyle.isVertical) { + ctx.canvas.width = 1248; + ctx.canvas.height = 2028; + ctx.save(); //保存设置 + ctx.translate(1248, 0); //重新定位右上角为基准 + ctx.rotate(Math.PI / 2); //旋转90度 + } else { + ctx.canvas.width = 2028; + ctx.canvas.height = 1248; + } - if (img) { - //绘制背景 - if (this.memory) ctx.filter = "sepia(50%)"; - ctx.drawImage(img, 0, 0, 2028, 1248); - ctx.filter = "none"; - } else { - core.fillRect(ctx, 0, 0, 2028, 1248); - } - this.bodyList.forEach((v) => { - //绘制立绘 - const body = core.material.images.images?.[v.name]; - if (v.filter) ctx.filter = "brightness(50%)"; - if (body) { - if (!v.w && !v.h && !v.scale) v.scale = 1.7; - if (!v.w && !v.h) { - ctx.drawImage( - body, - 0, - 0, - body.width, - body.height, - v.px, - 1248 - body.height * v.scale, - body.width * v.scale, - body.height * v.scale - ); - } else { - ctx.drawImage( - body, - 0, - 0, - body.width, - body.height, - v.px, - 1248 - (v.h ?? body.height), - v.w ?? body.width, - v.h ?? body.height - ); - } - } - ctx.filter = "none"; - }); - if (core.isPlaying() && !this.WindowSkin) - core.drawWindowSkin( - "winskin.webp", - ctx, - 30, - 780, - 1968, - 436, - null, - null, - null, - 3 - ); //绘制对话框 - const head = core.material.images.images?.[this.head.name]; - if (head) { - //绘制头像 - ctx.drawImage( - head, - 0, - 0, - head.width, - head.height, - this.head.px, - 1248 - head.height * 2.2, - head.width * 2.2, - head.height * 2.2 - ); - } - if (core.isPlaying() && !this.WindowSkin) { - core.drawWindowSkin( - "winskin.webp", - ctx, - 1700, - 800, - 192, - 96, - null, - null, - null, - 3 - ); - core.fillBoldText1( - ctx, - "记 录", - 1736, - 866, - "#FFFFFF", - "#000000", - 6, - "bold 48px Verdana" - ); - core.drawWindowSkin( - "winskin.webp", - ctx, - 1700, - 1100, - 192, - 96, - null, - null, - null, - 3 - ); - core.fillBoldText1( - ctx, - "存 档", - 1736, - 1166, - "#FFFFFF", - "#000000", - 6, - "bold 48px Verdana" - ); - core.drawWindowSkin( - "winskin.webp", - ctx, - 1700, - 1000, - 192, - 96, - null, - null, - null, - 3 - ); - core.fillBoldText1( - ctx, - "▶▶", - 1756, - 1066, - "#FFFFFF", - "#000000", - 6, - "bold 48px Verdana" - ); - core.drawWindowSkin( - "winskin.webp", - ctx, - 1700, - 900, - 192, - 96, - null, - null, - null, - 3 - ); - let autoText = "AUTO"; - if (auto) autoText = "STOP"; - core.fillBoldText1( - ctx, - autoText, - 1722, - 966, - "#FFFFFF", - "#000000", - 6, - "bold 48px Verdana" - ); - } - if (this.name) - core.fillBoldText1( - ctx, - `【${this.name}】`, - 550, - 880, - "#FFFFFF", - "#000000", - 6, - "bold 48px Verdana" - ); //绘制名字 + if (img) { + //绘制背景 + if (this.memory) ctx.filter = "sepia(50%)"; + ctx.drawImage(img, 0, 0, 2028, 1248); + ctx.filter = "none"; + } else { + core.fillRect(ctx, 0, 0, 2028, 1248); + } + this.bodyList.forEach((v) => { + //绘制立绘 + const body = core.material.images.images?.[v.name]; + if (v.filter) ctx.filter = "brightness(50%)"; + if (body) { + if (!v.w && !v.h && !v.scale) v.scale = 1.7; + if (!v.w && !v.h) { + ctx.drawImage( + body, + 0, + 0, + body.width, + body.height, + v.px, + 1248 - body.height * v.scale, + body.width * v.scale, + body.height * v.scale + ); + } else { + ctx.drawImage( + body, + 0, + 0, + body.width, + body.height, + v.px, + 1248 - (v.h ?? body.height), + v.w ?? body.width, + v.h ?? body.height + ); + } + } + ctx.filter = "none"; + }); + if (core.isPlaying() && !this.WindowSkin) + core.drawWindowSkin( + "winskin.webp", + ctx, + 30, + 780, + 1968, + 436, + null, + null, + null, + 3 + ); //绘制对话框 + const head = core.material.images.images?.[this.head.name]; + if (head) { + //绘制头像 + ctx.drawImage( + head, + 0, + 0, + head.width, + head.height, + this.head.px, + 1248 - head.height * 2.2, + head.width * 2.2, + head.height * 2.2 + ); + } + if (core.isPlaying() && !this.WindowSkin) { + core.drawWindowSkin( + "winskin.webp", + ctx, + 1700, + 800, + 192, + 96, + null, + null, + null, + 3 + ); + core.fillBoldText1( + ctx, + "记 录", + 1736, + 866, + "#FFFFFF", + "#000000", + 6, + "bold 48px Verdana" + ); + core.drawWindowSkin( + "winskin.webp", + ctx, + 1700, + 1100, + 192, + 96, + null, + null, + null, + 3 + ); + core.fillBoldText1( + ctx, + "存 档", + 1736, + 1166, + "#FFFFFF", + "#000000", + 6, + "bold 48px Verdana" + ); + core.drawWindowSkin( + "winskin.webp", + ctx, + 1700, + 1000, + 192, + 96, + null, + null, + null, + 3 + ); + core.fillBoldText1( + ctx, + "▶▶", + 1756, + 1066, + "#FFFFFF", + "#000000", + 6, + "bold 48px Verdana" + ); + core.drawWindowSkin( + "winskin.webp", + ctx, + 1700, + 900, + 192, + 96, + null, + null, + null, + 3 + ); + let autoText = "AUTO"; + if (auto) autoText = "STOP"; + core.fillBoldText1( + ctx, + autoText, + 1722, + 966, + "#FFFFFF", + "#000000", + 6, + "bold 48px Verdana" + ); + } + if (this.name) + core.fillBoldText1( + ctx, + `【${this.name}】`, + 550, + 880, + "#FFFFFF", + "#000000", + 6, + "bold 48px Verdana" + ); //绘制名字 - if ( - this.sound && - core.sounds && - !core.getFlag("skip", false) && - core.musicStatus.soundStatus - ) { - this.beforeSound = core.playSound(this.sound, null, () => { - if ( - this.sound && - auto && - !this.WindowSkin && - core.musicStatus.soundStatus - ) { - setTimeout(() => { - if (auto) { - cg.style.display = "none"; - core.ui._animateUI("hide", null, () => { - core.doAction(); - }); - } - }, this.wait); - } - }); - } - if (this.text && !core.getFlag("skip", false)) { - //绘制对话 - this.drawTextContent(ctx, this.text, { - left: 550, - top: 950, - bold: true, - color: "#FFFFFF", - align: "left", - fontSize: 48, - time: this.time || 0, - font: "Verdana", - maxWidth: 1000, - }); - } + if ( + this.sound && + core.sounds && + !core.getFlag("skip", false) && + core.musicStatus.soundStatus + ) { + this.beforeSound = core.playSound(this.sound, null, () => { + if ( + this.sound && + auto && + !this.WindowSkin && + core.musicStatus.soundStatus + ) { + setTimeout(() => { + if (auto) { + cg.style.display = "none"; + core.ui._animateUI("hide", null, () => { + core.doAction(); + }); + } + }, this.wait); + } + }); + } + if (this.text && !core.getFlag("skip", false)) { + //绘制对话 + this.drawTextContent(ctx, this.text, { + left: 550, + top: 950, + bold: true, + color: "#FFFFFF", + align: "left", + fontSize: 48, + time: this.time || 0, + font: "Verdana", + maxWidth: 1000, + }); + } - ctx.restore(); - } - } - core.ui.cgText = new cgText(); - }, + ctx.restore(); + } + } + core.ui.cgText = new cgText(); +}, "旁白": function () { // 在此增加新插件 const over = document.createElement("canvas"); //over画布设置 @@ -17113,6 +17128,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = music.height = 1248; } } + mousedown(px, py) { //鼠标按下时 @@ -17181,7 +17197,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = core.playBgm( main.core.ui.music.musicMx[main.core.ui.music.selection[0]][ main.core.ui.music.selection[1] - ] + ], 0 ); page = this.selection[0]; @@ -17217,7 +17233,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = core.playBgm( main.core.ui.music.musicMx[main.core.ui.music.selection[0]][ main.core.ui.music.selection[1] - ] + ], 0 ); break; @@ -17247,7 +17263,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = core.playBgm( main.core.ui.music.musicMx[main.core.ui.music.selection[0]][ main.core.ui.music.selection[1] - ] + ], 0 ); break; @@ -17261,7 +17277,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = core.playBgm( main.core.ui.music.musicMx[main.core.ui.music.selection[0]][ main.core.ui.music.selection[1] - ] + ], 0 ); page = this.selection[0]; @@ -17297,7 +17313,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = core.playBgm( main.core.ui.music.musicMx[main.core.ui.music.selection[0]][ main.core.ui.music.selection[1] - ] + ], 0 ); break; @@ -17327,7 +17343,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = core.playBgm( main.core.ui.music.musicMx[main.core.ui.music.selection[0]][ main.core.ui.music.selection[1] - ] + ], 0 ); break; @@ -17365,7 +17381,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = core.playBgm( main.core.ui.music.musicMx[main.core.ui.music.selection[0]][ main.core.ui.music.selection[1] - ] + ], 0 ); this.stop = false; @@ -17427,7 +17443,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = core.playBgm( main.core.ui.music.musicMx[main.core.ui.music.selection[0]][ main.core.ui.music.selection[1] - ] + ], 0 ); page = this.selection[0]; @@ -17464,7 +17480,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = core.playBgm( main.core.ui.music.musicMx[main.core.ui.music.selection[0]][ main.core.ui.music.selection[1] - ] + ], 0 ); break; @@ -17495,7 +17511,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = core.playBgm( main.core.ui.music.musicMx[main.core.ui.music.selection[0]][ main.core.ui.music.selection[1] - ] + ], 0 ); break; @@ -17509,7 +17525,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = core.playBgm( main.core.ui.music.musicMx[main.core.ui.music.selection[0]][ main.core.ui.music.selection[1] - ] + ], 0 ); page = this.selection[0]; @@ -17547,7 +17563,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = core.playBgm( main.core.ui.music.musicMx[main.core.ui.music.selection[0]][ main.core.ui.music.selection[1] - ] + ], 0 ); break; @@ -17577,7 +17593,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = core.playBgm( main.core.ui.music.musicMx[main.core.ui.music.selection[0]][ main.core.ui.music.selection[1] - ] + ], 0 ); break; @@ -17615,7 +17631,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = core.playBgm( main.core.ui.music.musicMx[main.core.ui.music.selection[0]][ main.core.ui.music.selection[1] - ] + ], 0 ); this.stop = false; } @@ -18060,7 +18076,7 @@ var plugins_bb40132b_638b_4a9f_b028_d3fe47acc8d1 = core.playBgm( main.core.ui.music.musicMx[main.core.ui.music.selection[0]][ main.core.ui.music.selection[1] - ] + ], 0 ); const arr = main.core.ui.music.musicMx.flat(Infinity);