+
+
+
diff --git a/libs/control.js b/libs/control.js
index c6e4f30..93b4a0a 100644
--- a/libs/control.js
+++ b/libs/control.js
@@ -1,4 +1,3 @@
-
/*
control.js:游戏主要逻辑控制
主要负责status相关内容,以及各种变量获取/存储
@@ -7,57 +6,93 @@ control.js:游戏主要逻辑控制
"use strict";
-function control () {
- this._init();
+function control() {
+ this._init();
}
control.prototype._init = function () {
- this.controldata = functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a.control;
- this.renderFrameFuncs = [];
- this.replayActions = [];
- this.weathers = {};
- this.resizes = [];
- this.noAutoEvents = true;
- this.updateNextFrame = false;
- // --- 注册系统的animationFrame
- this.registerAnimationFrame("totalTime", false, this._animationFrame_totalTime);
- this.registerAnimationFrame("autoSave", true, this._animationFrame_autoSave);
- this.registerAnimationFrame("globalAnimate", true, this._animationFrame_globalAnimate);
- this.registerAnimationFrame("animate", true, this._animationFrame_animate);
- this.registerAnimationFrame("heroMoving", true, this._animationFrame_heroMoving);
- this.registerAnimationFrame("weather", true, this._animationFrame_weather);
- this.registerAnimationFrame("tip", true, this._animateFrame_tip);
- this.registerAnimationFrame("parallelDo", false, this._animationFrame_parallelDo);
- // --- 注册系统的天气
- this.registerWeather("rain", this._weather_rain, this._animationFrame_weather_rain);
- this.registerWeather("snow", this._weather_snow, this._animationFrame_weather_snow);
- this.registerWeather("fog", this._weather_fog, this.__animateFrame_weather_image);
- this.registerWeather("cloud", this._weather_cloud, this.__animateFrame_weather_image);
- this.registerWeather("sun", this._weather_sun, this._animationFrame_weather_sun);
- // --- 注册系统的replay
- this.registerReplayAction("move", this._replayAction_move);
- this.registerReplayAction("item", this._replayAction_item);
- this.registerReplayAction("equip", this._replayAction_equip);
- this.registerReplayAction("unEquip", this._replayAction_unEquip);
- this.registerReplayAction("saveEquip", this._replayAction_saveEquip);
- this.registerReplayAction("loadEquip", this._replayAction_loadEquip);
- this.registerReplayAction("fly", this._replayAction_fly);
- this.registerReplayAction("shop", this._replayAction_shop);
- this.registerReplayAction("turn", this._replayAction_turn);
- this.registerReplayAction("getNext", this._replayAction_getNext);
- this.registerReplayAction("moveDirectly", this._replayAction_moveDirectly);
- this.registerReplayAction("key", this._replayAction_key);
- this.registerReplayAction("click", this._replayAction_click);
- this.registerReplayAction("ignoreInput", this._replayAction_ignoreInput);
- this.registerReplayAction("no", this._replayAction_no);
- // --- 注册系统的resize
- this.registerResize("gameGroup", this._resize_gameGroup);
- this.registerResize("canvas", this._resize_canvas);
- this.registerResize("statusBar", this._resize_statusBar);
- this.registerResize("status", this._resize_status);
- this.registerResize("toolBar", this._resize_toolBar);
- this.registerResize("tools", this._resize_tools);
-}
+ this.controldata = functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a.control;
+ this.renderFrameFuncs = [];
+ this.replayActions = [];
+ this.weathers = {};
+ this.resizes = [];
+ this.noAutoEvents = true;
+ this.updateNextFrame = false;
+ // --- 注册系统的animationFrame
+ this.registerAnimationFrame(
+ "totalTime",
+ false,
+ this._animationFrame_totalTime
+ );
+ this.registerAnimationFrame("autoSave", true, this._animationFrame_autoSave);
+ this.registerAnimationFrame(
+ "globalAnimate",
+ true,
+ this._animationFrame_globalAnimate
+ );
+ this.registerAnimationFrame("animate", true, this._animationFrame_animate);
+ this.registerAnimationFrame(
+ "heroMoving",
+ true,
+ this._animationFrame_heroMoving
+ );
+ this.registerAnimationFrame("weather", true, this._animationFrame_weather);
+ this.registerAnimationFrame("tip", true, this._animateFrame_tip);
+ this.registerAnimationFrame(
+ "parallelDo",
+ false,
+ this._animationFrame_parallelDo
+ );
+ // --- 注册系统的天气
+ this.registerWeather(
+ "rain",
+ this._weather_rain,
+ this._animationFrame_weather_rain
+ );
+ this.registerWeather(
+ "snow",
+ this._weather_snow,
+ this._animationFrame_weather_snow
+ );
+ this.registerWeather(
+ "fog",
+ this._weather_fog,
+ this.__animateFrame_weather_image
+ );
+ this.registerWeather(
+ "cloud",
+ this._weather_cloud,
+ this.__animateFrame_weather_image
+ );
+ this.registerWeather(
+ "sun",
+ this._weather_sun,
+ this._animationFrame_weather_sun
+ );
+ // --- 注册系统的replay
+ this.registerReplayAction("move", this._replayAction_move);
+ this.registerReplayAction("item", this._replayAction_item);
+ this.registerReplayAction("equip", this._replayAction_equip);
+ this.registerReplayAction("unEquip", this._replayAction_unEquip);
+ this.registerReplayAction("saveEquip", this._replayAction_saveEquip);
+ this.registerReplayAction("loadEquip", this._replayAction_loadEquip);
+ this.registerReplayAction("fly", this._replayAction_fly);
+ this.registerReplayAction("shop", this._replayAction_shop);
+ this.registerReplayAction("turn", this._replayAction_turn);
+ this.registerReplayAction("getNext", this._replayAction_getNext);
+ this.registerReplayAction("moveDirectly", this._replayAction_moveDirectly);
+ this.registerReplayAction("key", this._replayAction_key);
+ this.registerReplayAction("click", this._replayAction_click);
+ this.registerReplayAction("ignoreInput", this._replayAction_ignoreInput);
+ this.registerReplayAction("no", this._replayAction_no);
+ // --- 注册系统的resize
+ this.registerResize("gameGroup", this._resize_gameGroup);
+ this.registerResize("canvas", this._resize_canvas);
+ this.registerResize("statusBar", this._resize_statusBar);
+ this.registerResize("status", this._resize_status);
+ this.registerResize("toolBar", this._resize_toolBar);
+ this.registerResize("tools", this._resize_tools);
+};
// ------ requestAnimationFrame 相关 ------ //
@@ -65,1542 +100,1938 @@ control.prototype._init = function () {
// name:名称,可用来作为注销使用;needPlaying:是否只在游戏运行时才执行(在标题界面不执行)
// func:要执行的函数,或插件中的函数名;可接受timestamp(从页面加载完毕到当前所经过的时间)作为参数
control.prototype.registerAnimationFrame = function (name, needPlaying, func) {
- this.unregisterAnimationFrame(name);
- this.renderFrameFuncs.push({ name: name, needPlaying: needPlaying, func: func });
-}
+ this.unregisterAnimationFrame(name);
+ this.renderFrameFuncs.push({
+ name: name,
+ needPlaying: needPlaying,
+ func: func,
+ });
+};
////// 注销一个 animationFrame //////
control.prototype.unregisterAnimationFrame = function (name) {
- this.renderFrameFuncs = this.renderFrameFuncs.filter(function (x) { return x.name != name; });
-}
+ this.renderFrameFuncs = this.renderFrameFuncs.filter(function (x) {
+ return x.name != name;
+ });
+};
////// 设置requestAnimationFrame //////
control.prototype._setRequestAnimationFrame = function () {
- this._checkRequestAnimationFrame();
- core.animateFrame.totalTime = Math.max(core.animateFrame.totalTime, core.getLocalStorage('totalTime', 0));
- var loop = function (timestamp) {
- core.control.renderFrameFuncs.forEach(function (b) {
- if (b.func) {
- try {
- if (core.isPlaying() || !b.needPlaying)
- core.doFunc(b.func, core.control, timestamp);
- }
- catch (e) {
- console.error(e);
- console.error("ERROR in requestAnimationFrame[" + b.name + "]:已自动注销该项。");
- core.unregisterAnimationFrame(b.name);
- }
- }
- })
- window.requestAnimationFrame(loop);
- }
+ this._checkRequestAnimationFrame();
+ core.animateFrame.totalTime = Math.max(
+ core.animateFrame.totalTime,
+ core.getLocalStorage("totalTime", 0)
+ );
+ var loop = function (timestamp) {
+ core.control.renderFrameFuncs.forEach(function (b) {
+ if (b.func) {
+ try {
+ if (core.isPlaying() || !b.needPlaying)
+ core.doFunc(b.func, core.control, timestamp);
+ } catch (e) {
+ console.error(e);
+ console.error(
+ "ERROR in requestAnimationFrame[" + b.name + "]:已自动注销该项。"
+ );
+ core.unregisterAnimationFrame(b.name);
+ }
+ }
+ });
window.requestAnimationFrame(loop);
-}
+ };
+ window.requestAnimationFrame(loop);
+};
control.prototype._checkRequestAnimationFrame = function () {
- (function () {
- var lastTime = 0;
- var vendors = ['webkit', 'moz'];
- for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
- window.requestAnimationFrame = window[vendors[x] + 'RequestAnimationFrame'];
- window.cancelAnimationFrame = window[vendors[x] + 'CancelAnimationFrame'] || // Webkit中此取消方法的名字变了
- window[vendors[x] + 'CancelRequestAnimationFrame'];
- }
+ (function () {
+ var lastTime = 0;
+ var vendors = ["webkit", "moz"];
+ for (var x = 0; x < vendors.length && !window.requestAnimationFrame; ++x) {
+ window.requestAnimationFrame =
+ window[vendors[x] + "RequestAnimationFrame"];
+ window.cancelAnimationFrame =
+ window[vendors[x] + "CancelAnimationFrame"] || // Webkit中此取消方法的名字变了
+ window[vendors[x] + "CancelRequestAnimationFrame"];
+ }
- if (!window.requestAnimationFrame) {
- window.requestAnimationFrame = function (callback, element) {
- var currTime = new Date().getTime();
- var timeToCall = Math.max(0, 16.7 - (currTime - lastTime));
- var id = window.setTimeout(function () {
- callback(currTime + timeToCall);
- }, timeToCall);
- lastTime = currTime + timeToCall;
- return id;
- };
- }
- if (!window.cancelAnimationFrame) {
- window.cancelAnimationFrame = function (id) {
- clearTimeout(id);
- };
- }
- }());
-}
+ if (!window.requestAnimationFrame) {
+ window.requestAnimationFrame = function (callback, element) {
+ var currTime = new Date().getTime();
+ var timeToCall = Math.max(0, 16.7 - (currTime - lastTime));
+ var id = window.setTimeout(function () {
+ callback(currTime + timeToCall);
+ }, timeToCall);
+ lastTime = currTime + timeToCall;
+ return id;
+ };
+ }
+ if (!window.cancelAnimationFrame) {
+ window.cancelAnimationFrame = function (id) {
+ clearTimeout(id);
+ };
+ }
+ })();
+};
control.prototype._animationFrame_totalTime = function (timestamp) {
- core.animateFrame.totalTime += timestamp - core.animateFrame.totalTimeStart;
- core.animateFrame.totalTimeStart = timestamp;
- if (core.isPlaying()) {
- core.status.hero.statistics.totalTime = core.animateFrame.totalTime;
- core.status.hero.statistics.currTime += timestamp - (core.status.hero.statistics.start || timestamp);
- core.status.hero.statistics.start = timestamp;
- }
-}
+ core.animateFrame.totalTime += timestamp - core.animateFrame.totalTimeStart;
+ core.animateFrame.totalTimeStart = timestamp;
+ if (core.isPlaying()) {
+ core.status.hero.statistics.totalTime = core.animateFrame.totalTime;
+ core.status.hero.statistics.currTime +=
+ timestamp - (core.status.hero.statistics.start || timestamp);
+ core.status.hero.statistics.start = timestamp;
+ }
+};
control.prototype._animationFrame_autoSave = function (timestamp) {
- if (timestamp - core.saves.autosave.time <= 5000) return;
- core.control.checkAutosave();
- core.saves.autosave.time = timestamp;
-}
+ if (timestamp - core.saves.autosave.time <= 5000) return;
+ core.control.checkAutosave();
+ core.saves.autosave.time = timestamp;
+};
control.prototype._animationFrame_globalAnimate = function (timestamp) {
- if (timestamp - core.animateFrame.globalTime <= core.values.animateSpeed) return;
- core.status.globalAnimateStatus++;
- if (core.status.floorId) {
- // Global Animate
- core.status.globalAnimateObjs.forEach(function (block) {
- core.drawBlock(block, core.status.globalAnimateStatus);
- });
+ if (timestamp - core.animateFrame.globalTime <= core.values.animateSpeed)
+ return;
+ core.status.globalAnimateStatus++;
+ if (core.status.floorId) {
+ // Global Animate
+ core.status.globalAnimateObjs.forEach(function (block) {
+ core.drawBlock(block, core.status.globalAnimateStatus);
+ });
- // Global floor images
- core.maps._drawFloorImages(core.status.floorId, core.canvas.bg, 'bg', core.status.floorAnimateObjs || [], core.status.globalAnimateStatus);
- core.maps._drawFloorImages(core.status.floorId, core.canvas.fg, 'fg', core.status.floorAnimateObjs || [], core.status.globalAnimateStatus);
+ // Global floor images
+ core.maps._drawFloorImages(
+ core.status.floorId,
+ core.canvas.bg,
+ "bg",
+ core.status.floorAnimateObjs || [],
+ core.status.globalAnimateStatus
+ );
+ core.maps._drawFloorImages(
+ core.status.floorId,
+ core.canvas.fg,
+ "fg",
+ core.status.floorAnimateObjs || [],
+ core.status.globalAnimateStatus
+ );
- // Global Autotile Animate
- core.status.autotileAnimateObjs.forEach(function (block) {
- core.maps._drawAutotileAnimate(block, core.status.globalAnimateStatus);
- });
+ // Global Autotile Animate
+ core.status.autotileAnimateObjs.forEach(function (block) {
+ core.maps._drawAutotileAnimate(block, core.status.globalAnimateStatus);
+ });
- // Global hero animate
- if ((core.status.hero || {}).animate && core.status.heroMoving == 0 && main.mode == 'play' && !core.status.preview.enabled) {
- core.drawHero('stop', null, core.status.globalAnimateStatus);
- }
+ // Global hero animate
+ if (
+ (core.status.hero || {}).animate &&
+ core.status.heroMoving == 0 &&
+ main.mode == "play" &&
+ !core.status.preview.enabled
+ ) {
+ core.drawHero("stop", null, core.status.globalAnimateStatus);
}
- // Box animate
- core.drawBoxAnimate();
- core.animateFrame.globalTime = timestamp;
-}
+ }
+ // Box animate
+ core.drawBoxAnimate();
+ core.animateFrame.globalTime = timestamp;
+};
control.prototype._animationFrame_animate = function (timestamp) {
- if (timestamp - core.animateFrame.animateTime < 50 || !core.status.animateObjs || core.status.animateObjs.length == 0) return;
- core.clearMap('animate');
- // 更新帧
- for (var i = 0; i < core.status.animateObjs.length; i++) {
- var obj = core.status.animateObjs[i];
- if (obj.index == obj.animate.frames.length) {
- (function (callback) {
- setTimeout(function () {
- if (callback) callback();
- });
- })(obj.callback);
- }
+ if (
+ timestamp - core.animateFrame.animateTime < 50 ||
+ !core.status.animateObjs ||
+ core.status.animateObjs.length == 0
+ )
+ return;
+ core.clearMap("animate");
+ // 更新帧
+ for (var i = 0; i < core.status.animateObjs.length; i++) {
+ var obj = core.status.animateObjs[i];
+ if (obj.index == obj.animate.frames.length) {
+ (function (callback) {
+ setTimeout(function () {
+ if (callback) callback();
+ });
+ })(obj.callback);
}
- core.status.animateObjs = core.status.animateObjs.filter(function (obj) {
- return obj.index < obj.animate.frames.length;
- });
- core.status.animateObjs.forEach(function (obj) {
- if (obj.hero) {
- core.maps._drawAnimateFrame('animate', obj.animate, core.status.heroCenter.px, core.status.heroCenter.py, obj.index++);
- } else {
- core.maps._drawAnimateFrame('animate', obj.animate, obj.centerX, obj.centerY, obj.index++);
- }
- });
- core.animateFrame.animateTime = timestamp;
-}
+ }
+ core.status.animateObjs = core.status.animateObjs.filter(function (obj) {
+ return obj.index < obj.animate.frames.length;
+ });
+ core.status.animateObjs.forEach(function (obj) {
+ if (obj.hero) {
+ core.maps._drawAnimateFrame(
+ "animate",
+ obj.animate,
+ core.status.heroCenter.px,
+ core.status.heroCenter.py,
+ obj.index++
+ );
+ } else {
+ core.maps._drawAnimateFrame(
+ "animate",
+ obj.animate,
+ obj.centerX,
+ obj.centerY,
+ obj.index++
+ );
+ }
+ });
+ core.animateFrame.animateTime = timestamp;
+};
control.prototype._animationFrame_heroMoving = function (timestamp) {
- if (core.status.heroMoving <= 0) return;
- // 换腿
- if (timestamp - core.animateFrame.moveTime > core.values.moveSpeed) {
- core.animateFrame.leftLeg = !core.animateFrame.leftLeg;
- core.animateFrame.moveTime = timestamp;
- }
- core.drawHero(core.animateFrame.leftLeg ? 'leftFoot' : 'rightFoot', 4 * core.status.heroMoving);
-}
+ if (core.status.heroMoving <= 0) return;
+ // 换腿
+ if (timestamp - core.animateFrame.moveTime > core.values.moveSpeed) {
+ core.animateFrame.leftLeg = !core.animateFrame.leftLeg;
+ core.animateFrame.moveTime = timestamp;
+ }
+ core.drawHero(
+ core.animateFrame.leftLeg ? "leftFoot" : "rightFoot",
+ 4 * core.status.heroMoving
+ );
+};
control.prototype._animationFrame_weather = function (timestamp) {
- var weather = core.animateFrame.weather, type = weather.type;
- if (!core.dymCanvas.weather || !core.control.weathers[type] || !core.control.weathers[type].frameFunc) return;
- try {
- core.doFunc(core.control.weathers[type].frameFunc, core.control, timestamp, core.animateFrame.weather.level);
- } catch (e) {
- console.error(e);
- console.error("ERROR in weather[" + type + "]:已自动注销该项。");
- core.unregisterWeather(type);
- }
-}
+ var weather = core.animateFrame.weather,
+ type = weather.type;
+ if (
+ !core.dymCanvas.weather ||
+ !core.control.weathers[type] ||
+ !core.control.weathers[type].frameFunc
+ )
+ return;
+ try {
+ core.doFunc(
+ core.control.weathers[type].frameFunc,
+ core.control,
+ timestamp,
+ core.animateFrame.weather.level
+ );
+ } catch (e) {
+ console.error(e);
+ console.error("ERROR in weather[" + type + "]:已自动注销该项。");
+ core.unregisterWeather(type);
+ }
+};
control.prototype._animationFrame_weather_rain = function (timestamp, level) {
- if (timestamp - core.animateFrame.weather.time < 30) return;
- var ctx = core.dymCanvas.weather, ox = core.bigmap.offsetX, oy = core.bigmap.offsetY;
- core.clearMap('weather');
- ctx.strokeStyle = 'rgba(174,194,224,0.8)';
- ctx.lineWidth = 1;
- ctx.lineCap = 'round';
+ if (timestamp - core.animateFrame.weather.time < 30) return;
+ var ctx = core.dymCanvas.weather,
+ ox = core.bigmap.offsetX,
+ oy = core.bigmap.offsetY;
+ core.clearMap("weather");
+ ctx.strokeStyle = "rgba(174,194,224,0.8)";
+ ctx.lineWidth = 1;
+ ctx.lineCap = "round";
- core.animateFrame.weather.nodes.forEach(function (p) {
- ctx.beginPath();
- ctx.moveTo(p.x - ox, p.y - oy);
- ctx.lineTo(p.x + p.l * p.xs - ox, p.y + p.l * p.ys - oy);
- ctx.stroke();
+ core.animateFrame.weather.nodes.forEach(function (p) {
+ ctx.beginPath();
+ ctx.moveTo(p.x - ox, p.y - oy);
+ ctx.lineTo(p.x + p.l * p.xs - ox, p.y + p.l * p.ys - oy);
+ ctx.stroke();
- p.x += p.xs;
- p.y += p.ys;
- if (p.x > core.bigmap.width * 32 || p.y > core.bigmap.height * 32) {
- p.x = Math.random() * core.bigmap.width * 32;
- p.y = -10;
- }
+ p.x += p.xs;
+ p.y += p.ys;
+ if (p.x > core.bigmap.width * 32 || p.y > core.bigmap.height * 32) {
+ p.x = Math.random() * core.bigmap.width * 32;
+ p.y = -10;
+ }
+ });
- });
-
- ctx.fill();
- core.animateFrame.weather.time = timestamp;
-}
+ ctx.fill();
+ core.animateFrame.weather.time = timestamp;
+};
control.prototype._animationFrame_weather_snow = function (timestamp, level) {
- if (timestamp - core.animateFrame.weather.time < 30) return;
- var ctx = core.dymCanvas.weather, ox = core.bigmap.offsetX, oy = core.bigmap.offsetY;
- core.clearMap('weather');
- ctx.fillStyle = "rgba(255, 255, 255, 0.8)";
- ctx.beginPath();
- core.animateFrame.weather.data = core.animateFrame.weather.data || 0;
- core.animateFrame.weather.data += 0.01;
+ if (timestamp - core.animateFrame.weather.time < 30) return;
+ var ctx = core.dymCanvas.weather,
+ ox = core.bigmap.offsetX,
+ oy = core.bigmap.offsetY;
+ core.clearMap("weather");
+ ctx.fillStyle = "rgba(255, 255, 255, 0.8)";
+ ctx.beginPath();
+ core.animateFrame.weather.data = core.animateFrame.weather.data || 0;
+ core.animateFrame.weather.data += 0.01;
- var angle = core.animateFrame.weather.data;
- core.animateFrame.weather.nodes.forEach(function (p) {
- ctx.moveTo(p.x - ox, p.y - oy);
- ctx.arc(p.x - ox, p.y - oy, p.r, 0, Math.PI * 2, true);
- // update
- p.x += Math.sin(angle) * core.animateFrame.weather.level;
- p.y += Math.cos(angle + p.d) + 1 + p.r / 2;
- if (p.x > core.bigmap.width * 32 + 5 || p.x < -5 || p.y > core.bigmap.height * 32) {
- if (Math.random() > 1 / 3) {
- p.x = Math.random() * core.bigmap.width * 32;
- p.y = -10;
- }
- else {
- if (Math.sin(angle) > 0)
- p.x = -5;
- else
- p.x = core.bigmap.width * 32 + 5;
- p.y = Math.random() * core.bigmap.height * 32;
- }
- }
- });
- ctx.fill();
- core.animateFrame.weather.time = timestamp;
-}
+ var angle = core.animateFrame.weather.data;
+ core.animateFrame.weather.nodes.forEach(function (p) {
+ ctx.moveTo(p.x - ox, p.y - oy);
+ ctx.arc(p.x - ox, p.y - oy, p.r, 0, Math.PI * 2, true);
+ // update
+ p.x += Math.sin(angle) * core.animateFrame.weather.level;
+ p.y += Math.cos(angle + p.d) + 1 + p.r / 2;
+ if (
+ p.x > core.bigmap.width * 32 + 5 ||
+ p.x < -5 ||
+ p.y > core.bigmap.height * 32
+ ) {
+ if (Math.random() > 1 / 3) {
+ p.x = Math.random() * core.bigmap.width * 32;
+ p.y = -10;
+ } else {
+ if (Math.sin(angle) > 0) p.x = -5;
+ else p.x = core.bigmap.width * 32 + 5;
+ p.y = Math.random() * core.bigmap.height * 32;
+ }
+ }
+ });
+ ctx.fill();
+ core.animateFrame.weather.time = timestamp;
+};
control.prototype.__animateFrame_weather_image = function (timestamp, level) {
- if (timestamp - core.animateFrame.weather.time < 30) return;
- var node = core.animateFrame.weather.nodes[0];
- var image = node.image;
- if (!image) return;
- core.clearMap('weather');
- core.setAlpha('weather', node.level / 500);
- var wind = 1.5;
- var width = image.width, height = image.height;
- node.x += node.dx * wind;
- node.y += (2 * node.dy - 1) * wind;
- if (node.x + 3 * width <= core._PX_) {
- node.x += 4 * width;
- while (node.x > 0) node.x -= width;
+ if (timestamp - core.animateFrame.weather.time < 30) return;
+ var node = core.animateFrame.weather.nodes[0];
+ var image = node.image;
+ if (!image) return;
+ core.clearMap("weather");
+ core.setAlpha("weather", node.level / 500);
+ var wind = 1.5;
+ var width = image.width,
+ height = image.height;
+ node.x += node.dx * wind;
+ node.y += (2 * node.dy - 1) * wind;
+ if (node.x + 3 * width <= core._PX_) {
+ node.x += 4 * width;
+ while (node.x > 0) node.x -= width;
+ }
+ node.dy += node.delta;
+ if (node.dy >= 1) {
+ node.delta = -0.001;
+ } else if (node.dy <= 0) {
+ node.delta = 0.001;
+ }
+ if (node.y + 3 * height <= core._PY_) {
+ node.y += 4 * height;
+ while (node.y > 0) node.y -= height;
+ } else if (node.y >= 0) {
+ node.y -= height;
+ }
+ for (var i = 0; i < 3; ++i) {
+ for (var j = 0; j < 3; ++j) {
+ if (
+ node.x + (i + 1) * width <= 0 ||
+ node.x + i * width >= core._PX_ ||
+ node.y + (j + 1) * height <= 0 ||
+ node.y + j * height >= core._PY_
+ )
+ continue;
+ core.drawImage("weather", image, node.x + i * width, node.y + j * height);
}
- node.dy += node.delta;
- if (node.dy >= 1) {
- node.delta = -0.001;
- } else if (node.dy <= 0) {
- node.delta = 0.001;
- }
- if (node.y + 3 * height <= core._PY_) {
- node.y += 4 * height;
- while (node.y > 0) node.y -= height;
- }
- else if (node.y >= 0) {
- node.y -= height;
- }
- for (var i = 0; i < 3; ++i) {
- for (var j = 0; j < 3; ++j) {
- if (node.x + (i + 1) * width <= 0 || node.x + i * width >= core._PX_
- || node.y + (j + 1) * height <= 0 || node.y + j * height >= core._PY_)
- continue;
- core.drawImage('weather', image, node.x + i * width, node.y + j * height);
- }
- }
- core.setAlpha('weather', 1);
- core.animateFrame.weather.time = timestamp;
-}
+ }
+ core.setAlpha("weather", 1);
+ core.animateFrame.weather.time = timestamp;
+};
control.prototype._animationFrame_weather_sun = function (timestamp, level) {
- if (timestamp - core.animateFrame.weather.time < 30) return;
- var node = core.animateFrame.weather.nodes[0];
- var opacity = node.opacity + node.delta;
- if (opacity > level / 10 + 0.3 || opacity < level / 10 - 0.3)
- node.delta = -node.delta;
- node.opacity = opacity;
- core.setOpacity('weather', core.clamp(opacity, 0, 1));
- core.animateFrame.weather.time = timestamp;
-}
+ if (timestamp - core.animateFrame.weather.time < 30) return;
+ var node = core.animateFrame.weather.nodes[0];
+ var opacity = node.opacity + node.delta;
+ if (opacity > level / 10 + 0.3 || opacity < level / 10 - 0.3)
+ node.delta = -node.delta;
+ node.opacity = opacity;
+ core.setOpacity("weather", core.clamp(opacity, 0, 1));
+ core.animateFrame.weather.time = timestamp;
+};
control.prototype._animateFrame_tip = function (timestamp) {
- if (core.animateFrame.tip == null) return;
- var tip = core.animateFrame.tip;
- if (timestamp - tip.time <= 30) return;
- var delta = timestamp - tip.time;
- tip.time = timestamp;
+ if (core.animateFrame.tip == null) return;
+ var tip = core.animateFrame.tip;
+ if (timestamp - tip.time <= 30) return;
+ var delta = timestamp - tip.time;
+ tip.time = timestamp;
- core.setFont('data', "16px Arial");
- core.setTextAlign('data', 'left');
- core.clearMap('data', 0, 0, core._PX_, 50);
- core.ui._drawTip_drawOne(tip);
- if (tip.stage == 1) {
- tip.opacity += 0.05;
- if (tip.opacity >= 0.6) {
- tip.stage = 2;
- tip.displayTime = 0;
- }
- } else if (tip.stage == 2) {
- tip.displayTime += delta;
- if (tip.displayTime >= 1000) tip.stage = 3;
- } else tip.opacity -= 0.05;
-
- if (tip.opacity <= 0) {
- core.animateFrame.tip = null;
+ core.setFont("data", "16px Arial");
+ core.setTextAlign("data", "left");
+ core.clearMap("data", 0, 0, core._PX_, 50);
+ core.ui._drawTip_drawOne(tip);
+ if (tip.stage == 1) {
+ tip.opacity += 0.05;
+ if (tip.opacity >= 0.6) {
+ tip.stage = 2;
+ tip.displayTime = 0;
}
-}
+ } else if (tip.stage == 2) {
+ tip.displayTime += delta;
+ if (tip.displayTime >= 1000) tip.stage = 3;
+ } else tip.opacity -= 0.05;
+
+ if (tip.opacity <= 0) {
+ core.animateFrame.tip = null;
+ }
+};
control.prototype._animationFrame_parallelDo = function (timestamp) {
- core.control.controldata.parallelDo(timestamp);
-}
+ core.control.controldata.parallelDo(timestamp);
+};
// ------ 标题界面的处理 ------ //
////// 显示游戏开始界面 //////
control.prototype.showStartAnimate = function (noAnimate, callback) {
- this._showStartAnimate_resetDom();
- if (core.flags.startUsingCanvas || noAnimate)
- return this._showStartAnimate_finished(core.flags.startUsingCanvas, callback);
- core.hideWithAnimate(core.dom.startTop, 20, function () {
- core.control._showStartAnimate_finished(false, callback);
- });
-}
+ this._showStartAnimate_resetDom();
+ if (core.flags.startUsingCanvas || noAnimate)
+ return this._showStartAnimate_finished(
+ core.flags.startUsingCanvas,
+ callback
+ );
+ core.hideWithAnimate(core.dom.startTop, 20, function () {
+ core.control._showStartAnimate_finished(false, callback);
+ });
+};
control.prototype._showStartAnimate_resetDom = function () {
- core.dom.startPanel.style.opacity = 1;
- core.dom.startPanel.style.display = "block";
- core.dom.startTop.style.opacity = 1;
- core.dom.startTop.style.display = "block";
- core.dom.startButtonGroup.style.display = 'none';
- core.dom.startButtons.style.display = 'block';
- core.dom.levelChooseButtons.style.display = 'none';
- core.status.played = false;
- core.clearStatus();
- core.clearMap('all');
- core.dom.musicBtn.style.display = 'block';
- core.setMusicBtn();
- // 重置音量
- core.events.setVolume(1, 0);
- core.updateStatusBar();
-}
+ core.dom.startPanel.style.opacity = 1;
+ core.dom.startPanel.style.display = "block";
+ core.dom.startTop.style.opacity = 1;
+ core.dom.startTop.style.display = "block";
+ core.dom.startButtonGroup.style.display = "none";
+ core.dom.startButtons.style.display = "block";
+ core.dom.levelChooseButtons.style.display = "none";
+ core.status.played = false;
+ core.clearStatus();
+ core.clearMap("all");
+ core.dom.musicBtn.style.display = "block";
+ core.setMusicBtn();
+ // 重置音量
+ core.events.setVolume(1, 0);
+ core.updateStatusBar();
+};
control.prototype._showStartAnimate_finished = function (start, callback) {
- core.dom.startTop.style.display = 'none';
- core.dom.startButtonGroup.style.display = 'block';
- main.selectedButton = null;
- main.selectButton(0);
- if (start) core.startGame();
- if (callback) callback();
-}
+ core.dom.startTop.style.display = "none";
+ core.dom.startButtonGroup.style.display = "block";
+ main.selectedButton = null;
+ main.selectButton(0);
+ if (start) core.startGame();
+ if (callback) callback();
+};
////// 隐藏游戏开始界面 //////
control.prototype.hideStartAnimate = function (callback) {
- core.hideWithAnimate(core.dom.startPanel, 20, callback);
-}
+ core.hideWithAnimate(core.dom.startPanel, 20, callback);
+};
////// 游戏是否已经开始 //////
control.prototype.isPlaying = function () {
- return core.status.played;
-}
+ return core.status.played;
+};
////// 清除游戏状态和数据 //////
control.prototype.clearStatus = function () {
- // 停止各个Timeout和Interval
- for (var i in core.timeout) {
- clearTimeout(core.timeout[i]);
- core.timeout[i] = null;
- }
- for (var i in core.interval) {
- clearInterval(core.interval[i]);
- core.interval[i] = null;
- }
- core.status = {};
- core.clearStatusBar();
- core.deleteAllCanvas();
- core.status.played = false;
-}
+ // 停止各个Timeout和Interval
+ for (var i in core.timeout) {
+ clearTimeout(core.timeout[i]);
+ core.timeout[i] = null;
+ }
+ for (var i in core.interval) {
+ clearInterval(core.interval[i]);
+ core.interval[i] = null;
+ }
+ core.status = {};
+ core.clearStatusBar();
+ core.deleteAllCanvas();
+ core.status.played = false;
+};
control.prototype._initStatistics = function (totalTime) {
- if (!core.isset(core.status.hero.statistics))
- core.status.hero.statistics = {
- 'totalTime': totalTime,
- 'currTime': 0,
- 'hp': 0,
- "battle": 0,
- 'money': 0,
- 'exp': 0,
- 'battleDamage': 0,
- 'poisonDamage': 0,
- 'extraDamage': 0,
- 'moveDirectly': 0,
- 'ignoreSteps': 0,
- }
-}
+ if (!core.isset(core.status.hero.statistics))
+ core.status.hero.statistics = {
+ totalTime: totalTime,
+ currTime: 0,
+ hp: 0,
+ battle: 0,
+ money: 0,
+ exp: 0,
+ battleDamage: 0,
+ poisonDamage: 0,
+ extraDamage: 0,
+ moveDirectly: 0,
+ ignoreSteps: 0,
+ };
+};
// ------ 自动寻路,人物行走 ------ //
////// 清除自动寻路路线 //////
control.prototype.clearAutomaticRouteNode = function (x, y) {
- core.clearMap('route', x * 32 + 5 - core.status.automaticRoute.offsetX, y * 32 + 5 - core.status.automaticRoute.offsetY, 27, 27);
-}
+ core.clearMap(
+ "route",
+ x * 32 + 5 - core.status.automaticRoute.offsetX,
+ y * 32 + 5 - core.status.automaticRoute.offsetY,
+ 27,
+ 27
+ );
+};
////// 停止自动寻路操作 //////
control.prototype.stopAutomaticRoute = function () {
- if (!core.status.played) return;
- core.status.automaticRoute.autoHeroMove = false;
- core.status.automaticRoute.autoStep = 0;
- core.status.automaticRoute.destStep = 0;
- core.status.automaticRoute.movedStep = 0;
- core.status.automaticRoute.autoStepRoutes = [];
- core.status.automaticRoute.destX = null;
- core.status.automaticRoute.destY = null;
- core.status.automaticRoute.lastDirection = null;
- core.status.heroStop = true;
- if (core.status.automaticRoute.moveStepBeforeStop.length == 0)
- core.deleteCanvas('route');
-}
+ if (!core.status.played) return;
+ core.status.automaticRoute.autoHeroMove = false;
+ core.status.automaticRoute.autoStep = 0;
+ core.status.automaticRoute.destStep = 0;
+ core.status.automaticRoute.movedStep = 0;
+ core.status.automaticRoute.autoStepRoutes = [];
+ core.status.automaticRoute.destX = null;
+ core.status.automaticRoute.destY = null;
+ core.status.automaticRoute.lastDirection = null;
+ core.status.heroStop = true;
+ if (core.status.automaticRoute.moveStepBeforeStop.length == 0)
+ core.deleteCanvas("route");
+};
////// 保存剩下的寻路,并停止 //////
control.prototype.saveAndStopAutomaticRoute = function () {
- var automaticRoute = core.status.automaticRoute;
- if (automaticRoute.moveStepBeforeStop.length == 0) {
- automaticRoute.moveStepBeforeStop = automaticRoute.autoStepRoutes.slice(automaticRoute.autoStep - 1);
- if (automaticRoute.moveStepBeforeStop.length >= 1)
- automaticRoute.moveStepBeforeStop[0].step -= automaticRoute.movedStep;
- }
- this.stopAutomaticRoute();
-}
+ var automaticRoute = core.status.automaticRoute;
+ if (automaticRoute.moveStepBeforeStop.length == 0) {
+ automaticRoute.moveStepBeforeStop = automaticRoute.autoStepRoutes.slice(
+ automaticRoute.autoStep - 1
+ );
+ if (automaticRoute.moveStepBeforeStop.length >= 1)
+ automaticRoute.moveStepBeforeStop[0].step -= automaticRoute.movedStep;
+ }
+ this.stopAutomaticRoute();
+};
////// 继续剩下的自动寻路操作 //////
control.prototype.continueAutomaticRoute = function () {
- // 此函数只应由events.afterOpenDoor和events.afterBattle调用
- var moveStep = core.status.automaticRoute.moveStepBeforeStop;
- //core.status.automaticRoute.moveStepBeforeStop = [];
- if (moveStep.length === 0 || (moveStep.length === 1 && moveStep[0].step === 1)) {
- core.status.automaticRoute.moveStepBeforeStop = [];
- }
- else {
- core.setAutoHeroMove(moveStep);
- }
-}
+ // 此函数只应由events.afterOpenDoor和events.afterBattle调用
+ var moveStep = core.status.automaticRoute.moveStepBeforeStop;
+ //core.status.automaticRoute.moveStepBeforeStop = [];
+ if (
+ moveStep.length === 0 ||
+ (moveStep.length === 1 && moveStep[0].step === 1)
+ ) {
+ core.status.automaticRoute.moveStepBeforeStop = [];
+ } else {
+ core.setAutoHeroMove(moveStep);
+ }
+};
////// 清空剩下的自动寻路列表 //////
control.prototype.clearContinueAutomaticRoute = function (callback) {
- core.deleteCanvas('route');
- core.status.automaticRoute.moveStepBeforeStop = [];
- if (callback) callback();
-}
+ core.deleteCanvas("route");
+ core.status.automaticRoute.moveStepBeforeStop = [];
+ if (callback) callback();
+};
////// 设置自动寻路路线 //////
control.prototype.setAutomaticRoute = function (destX, destY, stepPostfix) {
- if (!core.status.played || core.status.lockControl) return;
- if (this._setAutomaticRoute_isMoving(destX, destY)) return;
- if (this._setAutomaticRoute_isTurning(destX, destY, stepPostfix)) return;
- if (this._setAutomaticRoute_clickMoveDirectly(destX, destY, stepPostfix)) return;
- // 找寻自动寻路路线
- var moveStep = core.automaticRoute(destX, destY);
- if (moveStep.length == 0 && (destX != core.status.hero.loc.x || destY != core.status.hero.loc.y || stepPostfix.length == 0))
- return;
- moveStep = moveStep.concat(stepPostfix);
- core.status.automaticRoute.destX = destX;
- core.status.automaticRoute.destY = destY;
- this._setAutomaticRoute_drawRoute(moveStep);
- this._setAutomaticRoute_setAutoSteps(moveStep);
- // 立刻移动
- core.setAutoHeroMove();
-}
+ if (!core.status.played || core.status.lockControl) return;
+ if (this._setAutomaticRoute_isMoving(destX, destY)) return;
+ if (this._setAutomaticRoute_isTurning(destX, destY, stepPostfix)) return;
+ if (this._setAutomaticRoute_clickMoveDirectly(destX, destY, stepPostfix))
+ return;
+ // 找寻自动寻路路线
+ var moveStep = core.automaticRoute(destX, destY);
+ if (
+ moveStep.length == 0 &&
+ (destX != core.status.hero.loc.x ||
+ destY != core.status.hero.loc.y ||
+ stepPostfix.length == 0)
+ )
+ return;
+ moveStep = moveStep.concat(stepPostfix);
+ core.status.automaticRoute.destX = destX;
+ core.status.automaticRoute.destY = destY;
+ this._setAutomaticRoute_drawRoute(moveStep);
+ this._setAutomaticRoute_setAutoSteps(moveStep);
+ // 立刻移动
+ core.setAutoHeroMove();
+};
control.prototype._setAutomaticRoute_isMoving = function (destX, destY) {
- if (core.status.automaticRoute.autoHeroMove) {
- var lastX = core.status.automaticRoute.destX, lastY = core.status.automaticRoute.destY;
- core.stopAutomaticRoute();
- // 双击瞬移
- if (lastX == destX && lastY == destY) {
- core.status.automaticRoute.moveDirectly = true;
- setTimeout(function () {
- if (core.status.automaticRoute.moveDirectly && core.status.heroMoving == 0) {
- core.control.tryMoveDirectly(destX, destY);
- }
- core.status.automaticRoute.moveDirectly = false;
- }, core.values.moveSpeed);
+ if (core.status.automaticRoute.autoHeroMove) {
+ var lastX = core.status.automaticRoute.destX,
+ lastY = core.status.automaticRoute.destY;
+ core.stopAutomaticRoute();
+ // 双击瞬移
+ if (lastX == destX && lastY == destY) {
+ core.status.automaticRoute.moveDirectly = true;
+ setTimeout(function () {
+ if (
+ core.status.automaticRoute.moveDirectly &&
+ core.status.heroMoving == 0
+ ) {
+ core.control.tryMoveDirectly(destX, destY);
}
- return true;
+ core.status.automaticRoute.moveDirectly = false;
+ }, core.values.moveSpeed);
}
- return false;
-}
+ return true;
+ }
+ return false;
+};
-control.prototype._setAutomaticRoute_isTurning = function (destX, destY, stepPostfix) {
- if (destX == core.status.hero.loc.x && destY == core.status.hero.loc.y && stepPostfix.length == 0) {
- if (core.timeout.turnHeroTimeout == null) {
- var routeLength = core.status.route.length;
- core.timeout.turnHeroTimeout = setTimeout(function () {
- if (core.status.route.length == routeLength) core.turnHero();
- clearTimeout(core.timeout.turnHeroTimeout);
- core.timeout.turnHeroTimeout = null;
- }, 250);
- }
- else {
- clearTimeout(core.timeout.turnHeroTimeout);
- core.timeout.turnHeroTimeout = null;
- core.getNextItem();
- }
- return true;
+control.prototype._setAutomaticRoute_isTurning = function (
+ destX,
+ destY,
+ stepPostfix
+) {
+ if (
+ destX == core.status.hero.loc.x &&
+ destY == core.status.hero.loc.y &&
+ stepPostfix.length == 0
+ ) {
+ if (core.timeout.turnHeroTimeout == null) {
+ var routeLength = core.status.route.length;
+ core.timeout.turnHeroTimeout = setTimeout(function () {
+ if (core.status.route.length == routeLength) core.turnHero();
+ clearTimeout(core.timeout.turnHeroTimeout);
+ core.timeout.turnHeroTimeout = null;
+ }, 250);
+ } else {
+ clearTimeout(core.timeout.turnHeroTimeout);
+ core.timeout.turnHeroTimeout = null;
+ core.getNextItem();
}
- if (core.timeout.turnHeroTimeout != null) return true;
- return false;
-}
+ return true;
+ }
+ if (core.timeout.turnHeroTimeout != null) return true;
+ return false;
+};
-control.prototype._setAutomaticRoute_clickMoveDirectly = function (destX, destY, stepPostfix) {
- // 单击瞬间移动
- if (core.status.heroStop && core.status.heroMoving == 0) {
- if (stepPostfix.length <= 1 && !core.hasFlag('__noClickMove__') && core.control.tryMoveDirectly(destX, destY))
- return true;
- }
- return false;
-}
+control.prototype._setAutomaticRoute_clickMoveDirectly = function (
+ destX,
+ destY,
+ stepPostfix
+) {
+ // 单击瞬间移动
+ if (core.status.heroStop && core.status.heroMoving == 0) {
+ if (
+ stepPostfix.length <= 1 &&
+ !core.hasFlag("__noClickMove__") &&
+ core.control.tryMoveDirectly(destX, destY)
+ )
+ return true;
+ }
+ return false;
+};
control.prototype._setAutomaticRoute_drawRoute = function (moveStep) {
- // 计算绘制区域的宽高,并尽可能小的创建route层
- var sx = core.bigmap.width * 32, sy = core.bigmap.height * 32, dx = 0, dy = 0;
- moveStep.forEach(function (t) {
- sx = Math.min(sx, t.x * 32); dx = Math.max(dx, t.x * 32);
- sy = Math.min(sy, t.y * 32); dy = Math.max(dy, t.y * 32);
- });
- core.status.automaticRoute.offsetX = sx;
- core.status.automaticRoute.offsetY = sy;
- var ctx = core.createCanvas('route', sx - core.bigmap.offsetX, sy - core.bigmap.offsetY, dx - sx + 32, dy - sy + 32, 95);
- ctx.fillStyle = '#bfbfbf';
- ctx.strokeStyle = '#bfbfbf';
- ctx.lineWidth = 8;
- for (var m = 0; m < moveStep.length; m++) {
- if (m == moveStep.length - 1) {
- ctx.fillRect(moveStep[m].x * 32 + 10 - sx, moveStep[m].y * 32 + 10 - sy, 12, 12);
- }
- else {
- ctx.beginPath();
- var cx = moveStep[m].x * 32 + 16 - sx, cy = moveStep[m].y * 32 + 16 - sy;
- var currDir = moveStep[m].direction, nextDir = moveStep[m + 1].direction;
- ctx.moveTo(cx - core.utils.scan[currDir].x * 11, cy - core.utils.scan[currDir].y * 11);
- ctx.lineTo(cx, cy);
- ctx.lineTo(cx + core.utils.scan[nextDir].x * 11, cy + core.utils.scan[nextDir].y * 11);
- ctx.stroke();
- }
+ // 计算绘制区域的宽高,并尽可能小的创建route层
+ var sx = core.bigmap.width * 32,
+ sy = core.bigmap.height * 32,
+ dx = 0,
+ dy = 0;
+ moveStep.forEach(function (t) {
+ sx = Math.min(sx, t.x * 32);
+ dx = Math.max(dx, t.x * 32);
+ sy = Math.min(sy, t.y * 32);
+ dy = Math.max(dy, t.y * 32);
+ });
+ core.status.automaticRoute.offsetX = sx;
+ core.status.automaticRoute.offsetY = sy;
+ var ctx = core.createCanvas(
+ "route",
+ sx - core.bigmap.offsetX,
+ sy - core.bigmap.offsetY,
+ dx - sx + 32,
+ dy - sy + 32,
+ 95
+ );
+ ctx.fillStyle = "#bfbfbf";
+ ctx.strokeStyle = "#bfbfbf";
+ ctx.lineWidth = 8;
+ for (var m = 0; m < moveStep.length; m++) {
+ if (m == moveStep.length - 1) {
+ ctx.fillRect(
+ moveStep[m].x * 32 + 10 - sx,
+ moveStep[m].y * 32 + 10 - sy,
+ 12,
+ 12
+ );
+ } else {
+ ctx.beginPath();
+ var cx = moveStep[m].x * 32 + 16 - sx,
+ cy = moveStep[m].y * 32 + 16 - sy;
+ var currDir = moveStep[m].direction,
+ nextDir = moveStep[m + 1].direction;
+ ctx.moveTo(
+ cx - core.utils.scan[currDir].x * 11,
+ cy - core.utils.scan[currDir].y * 11
+ );
+ ctx.lineTo(cx, cy);
+ ctx.lineTo(
+ cx + core.utils.scan[nextDir].x * 11,
+ cy + core.utils.scan[nextDir].y * 11
+ );
+ ctx.stroke();
}
-}
+ }
+};
control.prototype._setAutomaticRoute_setAutoSteps = function (moveStep) {
- // 路线转autoStepRoutes
- var step = 0, currStep = null;
- moveStep.forEach(function (t) {
- var dir = t.direction;
- if (currStep == null || currStep == dir)
- step++;
- else {
- core.status.automaticRoute.autoStepRoutes.push({ 'direction': currStep, 'step': step });
- step = 1;
- }
- currStep = dir;
- });
- core.status.automaticRoute.autoStepRoutes.push({ 'direction': currStep, 'step': step });
-}
+ // 路线转autoStepRoutes
+ var step = 0,
+ currStep = null;
+ moveStep.forEach(function (t) {
+ var dir = t.direction;
+ if (currStep == null || currStep == dir) step++;
+ else {
+ core.status.automaticRoute.autoStepRoutes.push({
+ direction: currStep,
+ step: step,
+ });
+ step = 1;
+ }
+ currStep = dir;
+ });
+ core.status.automaticRoute.autoStepRoutes.push({
+ direction: currStep,
+ step: step,
+ });
+};
////// 设置勇士的自动行走路线 //////
control.prototype.setAutoHeroMove = function (steps) {
- steps = steps || core.status.automaticRoute.autoStepRoutes;
- if (steps.length == 0) return;
- core.status.automaticRoute.autoStepRoutes = steps;
- core.status.automaticRoute.autoHeroMove = true;
- core.status.automaticRoute.autoStep = 1;
- core.status.automaticRoute.destStep = steps[0].step;
- core.moveHero(steps[0].direction);
-}
+ steps = steps || core.status.automaticRoute.autoStepRoutes;
+ if (steps.length == 0) return;
+ core.status.automaticRoute.autoStepRoutes = steps;
+ core.status.automaticRoute.autoHeroMove = true;
+ core.status.automaticRoute.autoStep = 1;
+ core.status.automaticRoute.destStep = steps[0].step;
+ core.moveHero(steps[0].direction);
+};
////// 设置行走的效果动画 //////
control.prototype.setHeroMoveInterval = function (callback) {
- if (core.status.heroMoving > 0) return;
- if (core.status.replay.speed == 24) {
- if (callback) callback();
- return;
+ if (core.status.heroMoving > 0) return;
+ if (core.status.replay.speed == 24) {
+ if (callback) callback();
+ return;
+ }
+
+ core.status.heroMoving = 1;
+
+ var toAdd = 1;
+ if (core.status.replay.speed > 3) toAdd = 2;
+ if (core.status.replay.speed > 6) toAdd = 4;
+ if (core.status.replay.speed > 12) toAdd = 8;
+
+ core.interval.heroMoveInterval = window.setInterval(function () {
+ core.status.heroMoving += toAdd;
+ if (core.status.heroMoving >= 8) {
+ clearInterval(core.interval.heroMoveInterval);
+ core.status.heroMoving = 0;
+ if (callback) callback();
}
-
- core.status.heroMoving = 1;
-
- var toAdd = 1;
- if (core.status.replay.speed > 3) toAdd = 2;
- if (core.status.replay.speed > 6) toAdd = 4;
- if (core.status.replay.speed > 12) toAdd = 8;
-
- core.interval.heroMoveInterval = window.setInterval(function () {
- core.status.heroMoving += toAdd;
- if (core.status.heroMoving >= 8) {
- clearInterval(core.interval.heroMoveInterval);
- core.status.heroMoving = 0;
- if (callback) callback();
- }
- }, core.values.moveSpeed / 8 * toAdd / core.status.replay.speed);
-}
+ }, ((core.values.moveSpeed / 8) * toAdd) / core.status.replay.speed);
+};
////// 每移动一格后执行的事件 //////
control.prototype.moveOneStep = function (callback) {
- return this.controldata.moveOneStep(callback);
-}
+ return this.controldata.moveOneStep(callback);
+};
////// 实际每一步的行走过程 //////
control.prototype.moveAction = function (callback) {
- if (core.status.heroMoving > 0) return;
- var noPass = core.noPass(core.nextX(), core.nextY()), canMove = core.canMoveHero();
- // 下一个点如果不能走
- if (noPass || !canMove) return this._moveAction_noPass(canMove, callback);
- this._moveAction_moving(callback);
-}
+ if (core.status.heroMoving > 0) return;
+ var noPass = core.noPass(core.nextX(), core.nextY()),
+ canMove = core.canMoveHero();
+ // 下一个点如果不能走
+ if (noPass || !canMove) return this._moveAction_noPass(canMove, callback);
+ this._moveAction_moving(callback);
+};
control.prototype._moveAction_noPass = function (canMove, callback) {
- core.status.route.push(core.getHeroLoc('direction'));
- core.status.automaticRoute.moveStepBeforeStop = [];
- core.status.automaticRoute.lastDirection = core.getHeroLoc('direction');
- if (canMove) core.trigger(core.nextX(), core.nextY());
- core.drawHero();
+ core.status.route.push(core.getHeroLoc("direction"));
+ core.status.automaticRoute.moveStepBeforeStop = [];
+ core.status.automaticRoute.lastDirection = core.getHeroLoc("direction");
+ if (canMove) core.trigger(core.nextX(), core.nextY());
+ core.drawHero();
- if (core.status.automaticRoute.moveStepBeforeStop.length == 0) {
- core.clearContinueAutomaticRoute();
- core.stopAutomaticRoute();
- }
- if (callback) callback();
-}
+ if (core.status.automaticRoute.moveStepBeforeStop.length == 0) {
+ core.clearContinueAutomaticRoute();
+ core.stopAutomaticRoute();
+ }
+ if (callback) callback();
+};
control.prototype._moveAction_moving = function (callback) {
- core.setHeroMoveInterval(function () {
- core.setHeroLoc('x', core.nextX(), true);
- core.setHeroLoc('y', core.nextY(), true);
+ core.setHeroMoveInterval(function () {
+ core.setHeroLoc("x", core.nextX(), true);
+ core.setHeroLoc("y", core.nextY(), true);
- var direction = core.getHeroLoc('direction');
- core.control._moveAction_popAutomaticRoute();
- core.status.route.push(direction);
+ var direction = core.getHeroLoc("direction");
+ core.control._moveAction_popAutomaticRoute();
+ core.status.route.push(direction);
- core.moveOneStep();
- core.checkRouteFolding();
- if (callback) callback();
- });
-}
+ core.moveOneStep();
+ core.checkRouteFolding();
+ if (callback) callback();
+ });
+};
control.prototype._moveAction_popAutomaticRoute = function () {
- var automaticRoute = core.status.automaticRoute;
- // 检查自动寻路是否被弹出
- if (automaticRoute.autoHeroMove) {
- automaticRoute.movedStep++;
- automaticRoute.lastDirection = core.getHeroLoc('direction');
- if (automaticRoute.destStep == automaticRoute.movedStep) {
- if (automaticRoute.autoStep == automaticRoute.autoStepRoutes.length) {
- core.clearContinueAutomaticRoute();
- core.stopAutomaticRoute();
- }
- else {
- automaticRoute.movedStep = 0;
- automaticRoute.destStep = automaticRoute.autoStepRoutes[automaticRoute.autoStep].step;
- core.setHeroLoc('direction', automaticRoute.autoStepRoutes[automaticRoute.autoStep].direction);
- core.status.automaticRoute.autoStep++;
- }
- }
+ var automaticRoute = core.status.automaticRoute;
+ // 检查自动寻路是否被弹出
+ if (automaticRoute.autoHeroMove) {
+ automaticRoute.movedStep++;
+ automaticRoute.lastDirection = core.getHeroLoc("direction");
+ if (automaticRoute.destStep == automaticRoute.movedStep) {
+ if (automaticRoute.autoStep == automaticRoute.autoStepRoutes.length) {
+ core.clearContinueAutomaticRoute();
+ core.stopAutomaticRoute();
+ } else {
+ automaticRoute.movedStep = 0;
+ automaticRoute.destStep =
+ automaticRoute.autoStepRoutes[automaticRoute.autoStep].step;
+ core.setHeroLoc(
+ "direction",
+ automaticRoute.autoStepRoutes[automaticRoute.autoStep].direction
+ );
+ core.status.automaticRoute.autoStep++;
+ }
}
-}
+ }
+};
////// 让勇士开始移动 //////
control.prototype.moveHero = function (direction, callback) {
- // 如果正在移动,直接return
- if (core.status.heroMoving != 0) return;
- if (core.isset(direction))
- core.setHeroLoc('direction', direction);
+ // 如果正在移动,直接return
+ if (core.status.heroMoving != 0) return;
+ if (core.isset(direction)) core.setHeroLoc("direction", direction);
- if (callback) return this.moveAction(callback);
- this._moveHero_moving();
-}
+ if (callback) return this.moveAction(callback);
+ this._moveHero_moving();
+};
control.prototype._moveHero_moving = function () {
- // ------ 我已经看不懂这个函数了,反正好用就行23333333
- core.status.heroStop = false;
- core.status.automaticRoute.moveDirectly = false;
- var move = function () {
- if (!core.status.heroStop) {
- if (core.hasFlag('debug') && core.status.ctrlDown) {
- if (core.status.heroMoving != 0) return;
- // 检测是否穿出去
- var nx = core.nextX(), ny = core.nextY();
- if (nx < 0 || nx >= core.bigmap.width || ny < 0 || ny >= core.bigmap.height) return;
- core.eventMoveHero([core.getHeroLoc('direction')], core.values.moveSpeed, move);
- }
- else {
- core.moveAction();
- setTimeout(move, 50);
- }
- }
+ // ------ 我已经看不懂这个函数了,反正好用就行23333333
+ core.status.heroStop = false;
+ core.status.automaticRoute.moveDirectly = false;
+ var move = function () {
+ if (!core.status.heroStop) {
+ if (core.hasFlag("debug") && core.status.ctrlDown) {
+ if (core.status.heroMoving != 0) return;
+ // 检测是否穿出去
+ var nx = core.nextX(),
+ ny = core.nextY();
+ if (
+ nx < 0 ||
+ nx >= core.bigmap.width ||
+ ny < 0 ||
+ ny >= core.bigmap.height
+ )
+ return;
+ core.eventMoveHero(
+ [core.getHeroLoc("direction")],
+ core.values.moveSpeed,
+ move
+ );
+ } else {
+ core.moveAction();
+ setTimeout(move, 50);
+ }
}
- move();
-}
+ };
+ move();
+};
////// 当前是否正在移动 //////
control.prototype.isMoving = function () {
- return !core.status.heroStop || core.status.heroMoving > 0;
-}
+ return !core.status.heroStop || core.status.heroMoving > 0;
+};
////// 停止勇士的一切行动,等待勇士行动结束后,再执行callback //////
control.prototype.waitHeroToStop = function (callback) {
- var lastDirection = core.status.automaticRoute.lastDirection;
- core.stopAutomaticRoute();
- core.clearContinueAutomaticRoute();
- if (callback) {
- core.status.replay.animate = true;
- core.lockControl();
- core.status.automaticRoute.moveDirectly = false;
- setTimeout(function () {
- core.status.replay.animate = false;
- if (core.isset(lastDirection))
- core.setHeroLoc('direction', lastDirection);
- core.drawHero();
- callback();
- }, core.status.replay.speed == 24 ? 1 : 30);
- }
-}
+ var lastDirection = core.status.automaticRoute.lastDirection;
+ core.stopAutomaticRoute();
+ core.clearContinueAutomaticRoute();
+ if (callback) {
+ core.status.replay.animate = true;
+ core.lockControl();
+ core.status.automaticRoute.moveDirectly = false;
+ setTimeout(
+ function () {
+ core.status.replay.animate = false;
+ if (core.isset(lastDirection))
+ core.setHeroLoc("direction", lastDirection);
+ core.drawHero();
+ callback();
+ },
+ core.status.replay.speed == 24 ? 1 : 30
+ );
+ }
+};
////// 转向 //////
control.prototype.turnHero = function (direction) {
- if (direction) {
- core.setHeroLoc('direction', direction);
- core.drawHero();
- core.status.route.push("turn:" + direction);
- return;
- }
- core.setHeroLoc('direction', core.turnDirection(':right'));
+ if (direction) {
+ core.setHeroLoc("direction", direction);
core.drawHero();
- core.status.route.push("turn");
- core.checkRouteFolding();
-}
+ core.status.route.push("turn:" + direction);
+ return;
+ }
+ core.setHeroLoc("direction", core.turnDirection(":right"));
+ core.drawHero();
+ core.status.route.push("turn");
+ core.checkRouteFolding();
+};
////// 瞬间移动 //////
control.prototype.moveDirectly = function (destX, destY, ignoreSteps) {
- return this.controldata.moveDirectly(destX, destY, ignoreSteps);
-}
+ return this.controldata.moveDirectly(destX, destY, ignoreSteps);
+};
////// 尝试瞬间移动 //////
control.prototype.tryMoveDirectly = function (destX, destY) {
- if (this.nearHero(destX, destY)) return false;
- var canMoveArray = core.maps.generateMovableArray();
- var dirs = [[destX, destY], [destX - 1, destY, "right"], [destX, destY - 1, "down"], [destX, destY + 1, "up"], [destX + 1, destY, "left"]];
- var canMoveDirectlyArray = core.canMoveDirectlyArray(dirs, canMoveArray);
+ if (this.nearHero(destX, destY)) return false;
+ var canMoveArray = core.maps.generateMovableArray();
+ var dirs = [
+ [destX, destY],
+ [destX - 1, destY, "right"],
+ [destX, destY - 1, "down"],
+ [destX, destY + 1, "up"],
+ [destX + 1, destY, "left"],
+ ];
+ var canMoveDirectlyArray = core.canMoveDirectlyArray(dirs, canMoveArray);
- for (var i = 0; i < dirs.length; ++i) {
- var d = dirs[i], dx = d[0], dy = d[1], dir = d[2];
- if (dx < 0 || dx >= core.bigmap.width || dy < 0 || dy >= core.bigmap.height) continue;
- if (dir && !core.inArray(canMoveArray[dx][dy], dir)) continue;
- if (canMoveDirectlyArray[i] < 0) continue;
- if (core.control.moveDirectly(dx, dy, canMoveDirectlyArray[i])) {
- if (dir) core.moveHero(dir, function () { });
- return true;
- }
+ for (var i = 0; i < dirs.length; ++i) {
+ var d = dirs[i],
+ dx = d[0],
+ dy = d[1],
+ dir = d[2];
+ if (dx < 0 || dx >= core.bigmap.width || dy < 0 || dy >= core.bigmap.height)
+ continue;
+ if (dir && !core.inArray(canMoveArray[dx][dy], dir)) continue;
+ if (canMoveDirectlyArray[i] < 0) continue;
+ if (core.control.moveDirectly(dx, dy, canMoveDirectlyArray[i])) {
+ if (dir) core.moveHero(dir, function () {});
+ return true;
}
- return false;
-}
+ }
+ return false;
+};
////// 绘制勇士 //////
control.prototype.drawHero = function (status, offset, frame) {
- if (!core.isPlaying() || !core.status.floorId || core.status.gameOver) return;
- var x = core.getHeroLoc('x'), y = core.getHeroLoc('y'), direction = core.getHeroLoc('direction');
- status = status || 'stop';
- if (!offset) offset = 0;
+ if (!core.isPlaying() || !core.status.floorId || core.status.gameOver) return;
+ var x = core.getHeroLoc("x"),
+ y = core.getHeroLoc("y"),
+ direction = core.getHeroLoc("direction");
+ status = status || "stop";
+ if (!offset) offset = 0;
- var way = core.utils.scan2[direction];
- var dx = way.x, dy = way.y;
- var offsetX = typeof offset == 'number' ? dx * offset : (offset.x || 0);
- var offsetY = typeof offset == 'number' ? dy * offset : (offset.y || 0);
- offset = { x: offsetX, y: offsetY, offset: offset };
+ var way = core.utils.scan2[direction];
+ var dx = way.x,
+ dy = way.y;
+ var offsetX = typeof offset == "number" ? dx * offset : offset.x || 0;
+ var offsetY = typeof offset == "number" ? dy * offset : offset.y || 0;
+ offset = { x: offsetX, y: offsetY, offset: offset };
- core.clearAutomaticRouteNode(x + dx, y + dy);
- core.clearMap('hero');
- core.status.heroCenter.px = 32 * x + offsetX + 16;
- core.status.heroCenter.py = 32 * y + offsetY + 32 - core.material.icons.hero.height / 2;
+ core.clearAutomaticRouteNode(x + dx, y + dy);
+ core.clearMap("hero");
+ core.status.heroCenter.px = 32 * x + offsetX + 16;
+ core.status.heroCenter.py =
+ 32 * y + offsetY + 32 - core.material.icons.hero.height / 2;
- // 重置hero层画布
- core.setGameCanvasTranslate('hero', 0, 0);
- delete core.canvas.hero._px;
- delete core.canvas.hero._py;
- core.status.preview.enabled = false;
- if (!core.hasFlag('__lockViewport__')) {
- this._drawHero_updateViewport(x, y, offset);
- }
+ // 重置hero层画布
+ core.setGameCanvasTranslate("hero", 0, 0);
+ delete core.canvas.hero._px;
+ delete core.canvas.hero._py;
+ core.status.preview.enabled = false;
+ if (!core.hasFlag("__lockViewport__")) {
+ this._drawHero_updateViewport(x, y, offset);
+ }
- this._drawHero_draw(direction, x, y, status, offset, frame);
-}
+ this._drawHero_draw(direction, x, y, status, offset, frame);
+};
control.prototype._drawHero_updateViewport = function (x, y, offset) {
- core.bigmap.offsetX = core.clamp((x - core._HALF_WIDTH_) * 32 + offset.x, 0, Math.max(32 * core.bigmap.width - core._PX_, 0));
- core.bigmap.offsetY = core.clamp((y - core._HALF_HEIGHT_) * 32 + offset.y, 0, Math.max(32 * core.bigmap.height - core._PY_, 0));
- core.control.updateViewport();
-}
+ core.bigmap.offsetX = core.clamp(
+ (x - core._HALF_WIDTH_) * 32 + offset.x,
+ 0,
+ Math.max(32 * core.bigmap.width - core._PX_, 0)
+ );
+ core.bigmap.offsetY = core.clamp(
+ (y - core._HALF_HEIGHT_) * 32 + offset.y,
+ 0,
+ Math.max(32 * core.bigmap.height - core._PY_, 0)
+ );
+ core.control.updateViewport();
+};
-control.prototype._drawHero_draw = function (direction, x, y, status, offset, frame) {
- offset = offset || { x: 0, y: 0, offset: 0, px: 0, py: 0 };
- var opacity = core.setAlpha('hero', core.getFlag('__heroOpacity__', 1))
- this._drawHero_getDrawObjs(direction, x, y, status, offset).forEach(function (block) {
- core.drawImage('hero', block.img, (block.heroIcon[block.status] + (frame || 0)) % 4 * block.width,
- block.heroIcon.loc * block.height, block.width, block.height,
- block.posx + (32 - block.width) / 2, block.posy + 32 - block.height, block.width, block.height);
- });
- core.setAlpha('hero', opacity);
-}
+control.prototype._drawHero_draw = function (
+ direction,
+ x,
+ y,
+ status,
+ offset,
+ frame
+) {
+ offset = offset || { x: 0, y: 0, offset: 0, px: 0, py: 0 };
+ var opacity = core.setAlpha("hero", core.getFlag("__heroOpacity__", 1));
+ this._drawHero_getDrawObjs(direction, x, y, status, offset).forEach(function (
+ block
+ ) {
+ core.drawImage(
+ "hero",
+ block.img,
+ ((block.heroIcon[block.status] + (frame || 0)) % 4) * block.width,
+ block.heroIcon.loc * block.height,
+ block.width,
+ block.height,
+ block.posx + (32 - block.width) / 2,
+ block.posy + 32 - block.height,
+ block.width,
+ block.height
+ );
+ });
+ core.setAlpha("hero", opacity);
+};
-control.prototype._drawHero_getDrawObjs = function (direction, x, y, status, offset) {
- var heroIconArr = core.material.icons.hero, drawObjs = [], index = 0;
- drawObjs.push({
- "img": core.material.images.hero,
- "width": core.material.icons.hero.width || 32,
- "height": core.material.icons.hero.height,
- "heroIcon": heroIconArr[direction],
- "posx": x * 32 - core.bigmap.offsetX + offset.x,
- "posy": y * 32 - core.bigmap.offsetY + offset.y,
- "status": status,
- "index": index++,
+control.prototype._drawHero_getDrawObjs = function (
+ direction,
+ x,
+ y,
+ status,
+ offset
+) {
+ var heroIconArr = core.material.icons.hero,
+ drawObjs = [],
+ index = 0;
+ drawObjs.push({
+ img: core.material.images.hero,
+ width: core.material.icons.hero.width || 32,
+ height: core.material.icons.hero.height,
+ heroIcon: heroIconArr[direction],
+ posx: x * 32 - core.bigmap.offsetX + offset.x,
+ posy: y * 32 - core.bigmap.offsetY + offset.y,
+ status: status,
+ index: index++,
+ });
+ if (typeof offset.offset == "number") {
+ core.status.hero.followers.forEach(function (t) {
+ drawObjs.push({
+ img: core.material.images.images[t.name],
+ width: core.material.images.images[t.name].width / 4,
+ height: core.material.images.images[t.name].height / 4,
+ heroIcon: heroIconArr[t.direction],
+ posx:
+ 32 * t.x -
+ core.bigmap.offsetX +
+ (t.stop
+ ? 0
+ : core.utils.scan2[t.direction].x * Math.abs(offset.offset)),
+ posy:
+ 32 * t.y -
+ core.bigmap.offsetY +
+ (t.stop
+ ? 0
+ : core.utils.scan2[t.direction].y * Math.abs(offset.offset)),
+ status: t.stop ? "stop" : status,
+ index: index++,
+ });
});
- if (typeof offset.offset == 'number') {
- core.status.hero.followers.forEach(function (t) {
- drawObjs.push({
- "img": core.material.images.images[t.name],
- "width": core.material.images.images[t.name].width / 4,
- "height": core.material.images.images[t.name].height / 4,
- "heroIcon": heroIconArr[t.direction],
- "posx": 32 * t.x - core.bigmap.offsetX + (t.stop ? 0 : core.utils.scan2[t.direction].x * Math.abs(offset.offset)),
- "posy": 32 * t.y - core.bigmap.offsetY + (t.stop ? 0 : core.utils.scan2[t.direction].y * Math.abs(offset.offset)),
- "status": t.stop ? "stop" : status,
- "index": index++
- });
- });
+ }
+ return drawObjs.sort(function (a, b) {
+ return a.posy == b.posy ? b.index - a.index : a.posy - b.posy;
+ });
+};
+
+control.prototype.setHeroOpacity = function (
+ opacity,
+ moveMode,
+ time,
+ callback
+) {
+ time = time || 0;
+ if (time == 0) {
+ core.setFlag("__heroOpacity__", opacity);
+ core.drawHero();
+ if (callback) callback();
+ return;
+ }
+ time /= Math.max(core.status.replay.speed, 1);
+
+ var fromOpacity = core.getFlag("__heroOpacity__", 1);
+ var step = 0,
+ steps = parseInt(time / 10);
+ if (steps <= 0) steps = 1;
+ var moveFunc = core.applyEasing(moveMode);
+
+ var animate = setInterval(function () {
+ step++;
+ core.setFlag(
+ "__heroOpacity__",
+ fromOpacity + (opacity - fromOpacity) * moveFunc(step / steps)
+ );
+ core.drawHero();
+ if (step == steps) {
+ delete core.animateFrame.asyncId[animate];
+ clearInterval(animate);
+ if (callback) callback();
}
- return drawObjs.sort(function (a, b) {
- return a.posy == b.posy ? b.index - a.index : a.posy - b.posy;
- });
-}
+ }, 10);
-control.prototype.setHeroOpacity = function (opacity, moveMode, time, callback) {
- time = time || 0;
- if (time == 0) {
- core.setFlag('__heroOpacity__', opacity);
- core.drawHero();
- if (callback) callback();
- return;
- }
- time /= Math.max(core.status.replay.speed, 1)
-
- var fromOpacity = core.getFlag('__heroOpacity__', 1);
- var step = 0, steps = parseInt(time / 10);
- if (steps <= 0) steps = 1;
- var moveFunc = core.applyEasing(moveMode);
-
- var animate = setInterval(function () {
- step++;
- core.setFlag('__heroOpacity__', fromOpacity + (opacity - fromOpacity) * moveFunc(step / steps));
- core.drawHero();
- if (step == steps) {
- delete core.animateFrame.asyncId[animate];
- clearInterval(animate);
- if (callback) callback();
- }
- }, 10);
-
- core.animateFrame.lastAsyncId = animate;
- core.animateFrame.asyncId[animate] = callback;
-}
+ core.animateFrame.lastAsyncId = animate;
+ core.animateFrame.asyncId[animate] = callback;
+};
// ------ 画布、位置、阻激夹域,显伤 ------ //
////// 设置画布偏移
control.prototype.setGameCanvasTranslate = function (canvas, x, y) {
- var c = core.dom.gameCanvas[canvas];
- x = x * core.domStyle.scale;
- y = y * core.domStyle.scale;
- c.style.transform = 'translate(' + x + 'px,' + y + 'px)';
- c.style.webkitTransform = 'translate(' + x + 'px,' + y + 'px)';
- c.style.OTransform = 'translate(' + x + 'px,' + y + 'px)';
- c.style.MozTransform = 'translate(' + x + 'px,' + y + 'px)';
- if (main.mode === 'editor' && editor.isMobile) {
- c.style.transform = 'translate(' + (x / core._PX_ * 96) + 'vw,' + (y / core._PY_ * 96) + 'vw)';
- c.style.webkitTransform = 'translate(' + (x / core._PX_ * 96) + 'vw,' + (y / core._PY_ * 96) + 'vw)';
- c.style.OTransform = 'translate(' + (x / core._PX_ * 96) + 'vw,' + (y / core._PY_ * 96) + 'vw)';
- c.style.MozTransform = 'translate(' + (x / core._PX_ * 96) + 'vw,' + (y / core._PY_ * 96) + 'vw)';
- }
+ var c = core.dom.gameCanvas[canvas];
+ x = x * core.domStyle.scale;
+ y = y * core.domStyle.scale;
+ c.style.transform = "translate(" + x + "px," + y + "px)";
+ c.style.webkitTransform = "translate(" + x + "px," + y + "px)";
+ c.style.OTransform = "translate(" + x + "px," + y + "px)";
+ c.style.MozTransform = "translate(" + x + "px," + y + "px)";
+ if (main.mode === "editor" && editor.isMobile) {
+ c.style.transform =
+ "translate(" +
+ (x / core._PX_) * 96 +
+ "vw," +
+ (y / core._PY_) * 96 +
+ "vw)";
+ c.style.webkitTransform =
+ "translate(" +
+ (x / core._PX_) * 96 +
+ "vw," +
+ (y / core._PY_) * 96 +
+ "vw)";
+ c.style.OTransform =
+ "translate(" +
+ (x / core._PX_) * 96 +
+ "vw," +
+ (y / core._PY_) * 96 +
+ "vw)";
+ c.style.MozTransform =
+ "translate(" +
+ (x / core._PX_) * 96 +
+ "vw," +
+ (y / core._PY_) * 96 +
+ "vw)";
+ }
};
////// 加减画布偏移
control.prototype.addGameCanvasTranslate = function (x, y) {
- for (var ii = 0, canvas; canvas = core.dom.gameCanvas[ii]; ii++) {
- var id = canvas.getAttribute('id');
- if (id == 'ui' || id == 'data') continue; // UI层和data层不移动
- var offsetX = x, offsetY = y;
- if (core.bigmap.canvas.indexOf(id) >= 0) {
- if (core.bigmap.v2) {
- offsetX -= (core.bigmap.offsetX - 32 * core.bigmap.posX) + 32;
- offsetY -= (core.bigmap.offsetY - 32 * core.bigmap.posY) + 32;
- } else {
- offsetX -= core.bigmap.offsetX;
- offsetY -= core.bigmap.offsetY;
- }
- }
- core.control.setGameCanvasTranslate(id, offsetX, offsetY);
+ for (var ii = 0, canvas; (canvas = core.dom.gameCanvas[ii]); ii++) {
+ var id = canvas.getAttribute("id");
+ if (id == "ui" || id == "data") continue; // UI层和data层不移动
+ var offsetX = x,
+ offsetY = y;
+ if (core.bigmap.canvas.indexOf(id) >= 0) {
+ if (core.bigmap.v2) {
+ offsetX -= core.bigmap.offsetX - 32 * core.bigmap.posX + 32;
+ offsetY -= core.bigmap.offsetY - 32 * core.bigmap.posY + 32;
+ } else {
+ offsetX -= core.bigmap.offsetX;
+ offsetY -= core.bigmap.offsetY;
+ }
}
-}
+ core.control.setGameCanvasTranslate(id, offsetX, offsetY);
+ }
+};
////// 更新视野范围 //////
control.prototype.updateViewport = function () {
- // 当前是否应该重绘?
- if (core.bigmap.v2) {
- if (core.bigmap.offsetX >= core.bigmap.posX * 32 + 32
- || core.bigmap.offsetX <= core.bigmap.posX * 32 - 32
- || core.bigmap.offsetY >= core.bigmap.posY * 32 + 32
- || core.bigmap.offsetY <= core.bigmap.posY * 32 - 32) {
- core.bigmap.posX = parseInt(core.bigmap.offsetX / 32);
- core.bigmap.posY = parseInt(core.bigmap.offsetY / 32);
- core.redrawMap();
- }
- } else {
- core.bigmap.posX = core.bigmap.posY = 0;
+ // 当前是否应该重绘?
+ if (core.bigmap.v2) {
+ if (
+ core.bigmap.offsetX >= core.bigmap.posX * 32 + 32 ||
+ core.bigmap.offsetX <= core.bigmap.posX * 32 - 32 ||
+ core.bigmap.offsetY >= core.bigmap.posY * 32 + 32 ||
+ core.bigmap.offsetY <= core.bigmap.posY * 32 - 32
+ ) {
+ core.bigmap.posX = parseInt(core.bigmap.offsetX / 32);
+ core.bigmap.posY = parseInt(core.bigmap.offsetY / 32);
+ core.redrawMap();
}
- var offsetX = core.bigmap.v2 ? -(core.bigmap.offsetX - 32 * core.bigmap.posX) - 32 : -core.bigmap.offsetX;
- var offsetY = core.bigmap.v2 ? -(core.bigmap.offsetY - 32 * core.bigmap.posY) - 32 : -core.bigmap.offsetY;
+ } else {
+ core.bigmap.posX = core.bigmap.posY = 0;
+ }
+ var offsetX = core.bigmap.v2
+ ? -(core.bigmap.offsetX - 32 * core.bigmap.posX) - 32
+ : -core.bigmap.offsetX;
+ var offsetY = core.bigmap.v2
+ ? -(core.bigmap.offsetY - 32 * core.bigmap.posY) - 32
+ : -core.bigmap.offsetY;
- core.bigmap.canvas.forEach(function (cn) {
- core.control.setGameCanvasTranslate(cn, offsetX, offsetY);
- });
- // ------ 路线
- core.relocateCanvas('route', core.status.automaticRoute.offsetX - core.bigmap.offsetX, core.status.automaticRoute.offsetY - core.bigmap.offsetY);
- // ------ 所有的大怪物也都需要重定位
- for (var one in core.dymCanvas) {
- if (one.startsWith('_bigImage_')) {
- var ox = core.dymCanvas[one].canvas.getAttribute('_ox');
- var oy = core.dymCanvas[one].canvas.getAttribute('_oy');
- if (ox != null && oy != null) {
- core.relocateCanvas(one, parseInt(ox) - core.bigmap.offsetX, parseInt(oy) - core.bigmap.offsetY);
- }
- }
+ core.bigmap.canvas.forEach(function (cn) {
+ core.control.setGameCanvasTranslate(cn, offsetX, offsetY);
+ });
+ // ------ 路线
+ core.relocateCanvas(
+ "route",
+ core.status.automaticRoute.offsetX - core.bigmap.offsetX,
+ core.status.automaticRoute.offsetY - core.bigmap.offsetY
+ );
+ // ------ 所有的大怪物也都需要重定位
+ for (var one in core.dymCanvas) {
+ if (one.startsWith("_bigImage_")) {
+ var ox = core.dymCanvas[one].canvas.getAttribute("_ox");
+ var oy = core.dymCanvas[one].canvas.getAttribute("_oy");
+ if (ox != null && oy != null) {
+ core.relocateCanvas(
+ one,
+ parseInt(ox) - core.bigmap.offsetX,
+ parseInt(oy) - core.bigmap.offsetY
+ );
+ }
}
-
-}
+ }
+};
////// 设置视野范围 //////
control.prototype.setViewport = function (px, py) {
- var originOffsetX = core.bigmap.offsetX, originOffsetY = core.bigmap.offsetY;
- core.bigmap.offsetX = core.clamp(px, 0, 32 * core.bigmap.width - core._PX_);
- core.bigmap.offsetY = core.clamp(py, 0, 32 * core.bigmap.height - core._PY_);
- this.updateViewport();
- // ------ hero层也需要!
- var px = parseFloat(core.canvas.hero._px) || 0;
- var py = parseFloat(core.canvas.hero._py) || 0;
- px += originOffsetX - core.bigmap.offsetX;
- py += originOffsetY - core.bigmap.offsetY;
- core.control.setGameCanvasTranslate('hero', px, py);
- core.canvas.hero._px = px;
- core.canvas.hero._py = py;
-}
+ var originOffsetX = core.bigmap.offsetX,
+ originOffsetY = core.bigmap.offsetY;
+ core.bigmap.offsetX = core.clamp(px, 0, 32 * core.bigmap.width - core._PX_);
+ core.bigmap.offsetY = core.clamp(py, 0, 32 * core.bigmap.height - core._PY_);
+ this.updateViewport();
+ // ------ hero层也需要!
+ var px = parseFloat(core.canvas.hero._px) || 0;
+ var py = parseFloat(core.canvas.hero._py) || 0;
+ px += originOffsetX - core.bigmap.offsetX;
+ py += originOffsetY - core.bigmap.offsetY;
+ core.control.setGameCanvasTranslate("hero", px, py);
+ core.canvas.hero._px = px;
+ core.canvas.hero._py = py;
+};
////// 移动视野范围 //////
control.prototype.moveViewport = function (x, y, moveMode, time, callback) {
- time = time || 0;
- time /= Math.max(core.status.replay.speed, 1)
- var per_time = 10, step = 0, steps = parseInt(time / per_time);
- if (steps <= 0) {
- this.setViewport(32 * x, 32 * y);
- if (callback) callback();
- return;
+ time = time || 0;
+ time /= Math.max(core.status.replay.speed, 1);
+ var per_time = 10,
+ step = 0,
+ steps = parseInt(time / per_time);
+ if (steps <= 0) {
+ this.setViewport(32 * x, 32 * y);
+ if (callback) callback();
+ return;
+ }
+ var px = core.clamp(32 * x, 0, 32 * core.bigmap.width - core._PX_);
+ var py = core.clamp(32 * y, 0, 32 * core.bigmap.height - core._PY_);
+ var cx = core.bigmap.offsetX;
+ var cy = core.bigmap.offsetY;
+ var moveFunc = core.applyEasing(moveMode);
+
+ var animate = window.setInterval(function () {
+ step++;
+ core.setViewport(
+ cx + moveFunc(step / steps) * (px - cx),
+ cy + moveFunc(step / steps) * (py - cy)
+ );
+ if (step == steps) {
+ delete core.animateFrame.asyncId[animate];
+ clearInterval(animate);
+ core.setViewport(px, py);
+ if (callback) callback();
}
- var px = core.clamp(32 * x, 0, 32 * core.bigmap.width - core._PX_);
- var py = core.clamp(32 * y, 0, 32 * core.bigmap.height - core._PY_);
- var cx = core.bigmap.offsetX;
- var cy = core.bigmap.offsetY;
- var moveFunc = core.applyEasing(moveMode);
+ }, per_time);
- var animate = window.setInterval(function () {
- step++;
- core.setViewport(cx + moveFunc(step / steps) * (px - cx), cy + moveFunc(step / steps) * (py - cy));
- if (step == steps) {
- delete core.animateFrame.asyncId[animate];
- clearInterval(animate);
- core.setViewport(px, py);
- if (callback) callback();
- }
- }, per_time);
-
- core.animateFrame.lastAsyncId = animate;
- core.animateFrame.asyncId[animate] = callback;
-}
+ core.animateFrame.lastAsyncId = animate;
+ core.animateFrame.asyncId[animate] = callback;
+};
////// 获得勇士面对位置的x坐标 //////
control.prototype.nextX = function (n) {
- if (n == null) n = 1;
- return core.getHeroLoc('x') + core.utils.scan[core.getHeroLoc('direction')].x * n;
-}
+ if (n == null) n = 1;
+ return (
+ core.getHeroLoc("x") + core.utils.scan[core.getHeroLoc("direction")].x * n
+ );
+};
////// 获得勇士面对位置的y坐标 //////
control.prototype.nextY = function (n) {
- if (n == null) n = 1;
- return core.getHeroLoc('y') + core.utils.scan[core.getHeroLoc('direction')].y * n;
-}
+ if (n == null) n = 1;
+ return (
+ core.getHeroLoc("y") + core.utils.scan[core.getHeroLoc("direction")].y * n
+ );
+};
////// 某个点是否在勇士旁边 //////
control.prototype.nearHero = function (x, y, n) {
- if (n == null) n = 1;
- return Math.abs(x - core.getHeroLoc('x')) + Math.abs(y - core.getHeroLoc('y')) <= n;
-}
+ if (n == null) n = 1;
+ return (
+ Math.abs(x - core.getHeroLoc("x")) + Math.abs(y - core.getHeroLoc("y")) <= n
+ );
+};
////// 聚集跟随者 //////
control.prototype.gatherFollowers = function () {
- var x = core.getHeroLoc('x'), y = core.getHeroLoc('y'), dir = core.getHeroLoc('direction');
- core.status.hero.followers.forEach(function (t) {
- t.x = x;
- t.y = y;
- t.stop = true;
- t.direction = dir;
- });
-}
+ var x = core.getHeroLoc("x"),
+ y = core.getHeroLoc("y"),
+ dir = core.getHeroLoc("direction");
+ core.status.hero.followers.forEach(function (t) {
+ t.x = x;
+ t.y = y;
+ t.stop = true;
+ t.direction = dir;
+ });
+};
////// 更新跟随者坐标 //////
control.prototype.updateFollowers = function () {
- core.status.hero.followers.forEach(function (t) {
- if (!t.stop) {
- t.x += core.utils.scan2[t.direction].x;
- t.y += core.utils.scan2[t.direction].y;
- }
- })
+ core.status.hero.followers.forEach(function (t) {
+ if (!t.stop) {
+ t.x += core.utils.scan2[t.direction].x;
+ t.y += core.utils.scan2[t.direction].y;
+ }
+ });
- var nowx = core.getHeroLoc('x'), nowy = core.getHeroLoc('y');
- core.status.hero.followers.forEach(function (t) {
- t.stop = true;
- var dx = nowx - t.x, dy = nowy - t.y;
- for (var dir in core.utils.scan2) {
- if (core.utils.scan2[dir].x == dx && core.utils.scan2[dir].y == dy) {
- t.stop = false;
- t.direction = dir;
- }
- }
- nowx = t.x; nowy = t.y;
- })
-}
+ var nowx = core.getHeroLoc("x"),
+ nowy = core.getHeroLoc("y");
+ core.status.hero.followers.forEach(function (t) {
+ t.stop = true;
+ var dx = nowx - t.x,
+ dy = nowy - t.y;
+ for (var dir in core.utils.scan2) {
+ if (core.utils.scan2[dir].x == dx && core.utils.scan2[dir].y == dy) {
+ t.stop = false;
+ t.direction = dir;
+ }
+ }
+ nowx = t.x;
+ nowy = t.y;
+ });
+};
////// 瞬移更新跟随者坐标 //////
control.prototype._moveDirectyFollowers = function (x, y) {
- var route = core.automaticRoute(x, y);
- if (route.length == 0) route = [{ x: x, y: y, direction: core.getHeroLoc('direction') }];
+ var route = core.automaticRoute(x, y);
+ if (route.length == 0)
+ route = [{ x: x, y: y, direction: core.getHeroLoc("direction") }];
- var nowx = x, nowy = y;
- for (var i = 0; i < core.status.hero.followers.length; ++i) {
- var t = core.status.hero.followers[i];
- var index = route.length - i - 2;
- if (index < 0) index = 0;
- t.stop = true;
- t.x = route[index].x;
- t.y = route[index].y;
- t.direction = route[index].direction;
- var dx = nowx - t.x, dy = nowy - t.y;
- for (var dir in core.utils.scan2) {
- if (core.utils.scan2[dir].x == dx && core.utils.scan2[dir].y == dy) {
- t.stop = false;
- t.direction = dir;
- }
- }
- nowx = t.x; nowy = t.y;
+ var nowx = x,
+ nowy = y;
+ for (var i = 0; i < core.status.hero.followers.length; ++i) {
+ var t = core.status.hero.followers[i];
+ var index = route.length - i - 2;
+ if (index < 0) index = 0;
+ t.stop = true;
+ t.x = route[index].x;
+ t.y = route[index].y;
+ t.direction = route[index].direction;
+ var dx = nowx - t.x,
+ dy = nowy - t.y;
+ for (var dir in core.utils.scan2) {
+ if (core.utils.scan2[dir].x == dx && core.utils.scan2[dir].y == dy) {
+ t.stop = false;
+ t.direction = dir;
+ }
}
-}
+ nowx = t.x;
+ nowy = t.y;
+ }
+};
////// 更新领域、夹击、阻击的伤害地图 //////
control.prototype.updateCheckBlock = function (floorId) {
- return this.controldata.updateCheckBlock(floorId);
-}
+ return this.controldata.updateCheckBlock(floorId);
+};
////// 检查并执行领域、夹击、阻击事件 //////
control.prototype.checkBlock = function () {
- var x = core.getHeroLoc('x'), y = core.getHeroLoc('y'), loc = x + "," + y;
- var damage = core.status.checkBlock.damage[loc];
- if (damage) {
- core.status.hero.hp -= damage;
- var text = (Object.keys(core.status.checkBlock.type[loc] || {}).join(",")) || "伤害";
- core.drawTip("受到" + text + damage + "点");
- core.drawHeroAnimate("zone");
- this._checkBlock_disableQuickShop();
- core.status.hero.statistics.extraDamage += damage;
- if (core.status.hero.hp <= 0) {
- core.status.hero.hp = 0;
- core.updateStatusBar(false, true);
- core.events.lose();
- return;
- } else {
- core.updateStatusBar(false, true);
- }
+ var x = core.getHeroLoc("x"),
+ y = core.getHeroLoc("y"),
+ loc = x + "," + y;
+ var damage = core.status.checkBlock.damage[loc];
+ if (damage) {
+ core.status.hero.hp -= damage;
+ var text =
+ Object.keys(core.status.checkBlock.type[loc] || {}).join(",") || "伤害";
+ core.drawTip("受到" + text + damage + "点");
+ core.drawHeroAnimate("zone");
+ this._checkBlock_disableQuickShop();
+ core.status.hero.statistics.extraDamage += damage;
+ if (core.status.hero.hp <= 0) {
+ core.status.hero.hp = 0;
+ core.updateStatusBar(false, true);
+ core.events.lose();
+ return;
+ } else {
+ core.updateStatusBar(false, true);
}
- this._checkBlock_ambush(core.status.checkBlock.ambush[loc]);
- this._checkBlock_repulse(core.status.checkBlock.repulse[loc]);
-}
+ }
+ this._checkBlock_ambush(core.status.checkBlock.ambush[loc]);
+ this._checkBlock_repulse(core.status.checkBlock.repulse[loc]);
+};
control.prototype._checkBlock_disableQuickShop = function () {
- // 禁用快捷商店
- if (core.flags.disableShopOnDamage) {
- Object.keys(core.status.shops).forEach(function (shopId) {
- core.setShopVisited(shopId, false);
- });
- }
-}
+ // 禁用快捷商店
+ if (core.flags.disableShopOnDamage) {
+ Object.keys(core.status.shops).forEach(function (shopId) {
+ core.setShopVisited(shopId, false);
+ });
+ }
+};
////// 阻击 //////
control.prototype._checkBlock_repulse = function (repulse) {
- if (!repulse || repulse.length == 0) return;
- var actions = [];
- repulse.forEach(function (t) {
- actions.push({ "type": "move", "loc": [t[0], t[1]], "steps": [t[3]], "time": 250, "keep": true, "async": true });
+ if (!repulse || repulse.length == 0) return;
+ var actions = [];
+ repulse.forEach(function (t) {
+ actions.push({
+ type: "move",
+ loc: [t[0], t[1]],
+ steps: [t[3]],
+ time: 250,
+ keep: true,
+ async: true,
});
- actions.push({ "type": "waitAsync" });
- core.insertAction(actions);
-}
+ });
+ actions.push({ type: "waitAsync" });
+ core.insertAction(actions);
+};
////// 捕捉 //////
control.prototype._checkBlock_ambush = function (ambush) {
- if (!ambush || ambush.length == 0) return;
- // 捕捉效果
- var actions = [];
- ambush.forEach(function (t) {
- actions.push({ "type": "move", "loc": [t[0], t[1]], "steps": [t[3]], "time": 250, "keep": false, "async": true });
+ if (!ambush || ambush.length == 0) return;
+ // 捕捉效果
+ var actions = [];
+ ambush.forEach(function (t) {
+ actions.push({
+ type: "move",
+ loc: [t[0], t[1]],
+ steps: [t[3]],
+ time: 250,
+ keep: false,
+ async: true,
});
- actions.push({ "type": "waitAsync" });
- // 强制战斗
- ambush.forEach(function (t) {
- actions.push({
- "type": "function", "function": "function() { " +
- "core.battle('" + t[2] + "', " + t[0] + "," + t[1] + ", true, core.doAction); " +
- "}", "async": true
- });
+ });
+ actions.push({ type: "waitAsync" });
+ // 强制战斗
+ ambush.forEach(function (t) {
+ actions.push({
+ type: "function",
+ function:
+ "function() { " +
+ "core.battle('" +
+ t[2] +
+ "', " +
+ t[0] +
+ "," +
+ t[1] +
+ ", true, core.doAction); " +
+ "}",
+ async: true,
});
- core.insertAction(actions);
-}
+ });
+ core.insertAction(actions);
+};
////// 更新全地图显伤 //////
control.prototype.updateDamage = function (floorId, ctx) {
- floorId = floorId || core.status.floorId;
- if (!floorId || core.status.gameOver || main.mode != 'play') return;
- var onMap = ctx == null;
+ floorId = floorId || core.status.floorId;
+ if (!floorId || core.status.gameOver || main.mode != "play") return;
+ var onMap = ctx == null;
- // 没有怪物手册
- if (!core.hasItem('book')) return;
- core.status.damage.posX = core.bigmap.posX;
- core.status.damage.posY = core.bigmap.posY;
- if (!onMap) {
- var width = core.floors[floorId].width, height = core.floors[floorId].height;
- // 地图过大的缩略图不绘制显伤
- if (width * height > core.bigmap.threshold) return;
- }
- this._updateDamage_damage(floorId, onMap);
- this._updateDamage_extraDamage(floorId, onMap);
- this.drawDamage(ctx);
-}
+ // 没有怪物手册
+ if (!core.hasItem("book")) return;
+ core.status.damage.posX = core.bigmap.posX;
+ core.status.damage.posY = core.bigmap.posY;
+ if (!onMap) {
+ var width = core.floors[floorId].width,
+ height = core.floors[floorId].height;
+ // 地图过大的缩略图不绘制显伤
+ if (width * height > core.bigmap.threshold) return;
+ }
+ this._updateDamage_damage(floorId, onMap);
+ this._updateDamage_extraDamage(floorId, onMap);
+ this.drawDamage(ctx);
+};
control.prototype._updateDamage_damage = function (floorId, onMap) {
- core.status.damage.data = [];
- if (!core.flags.displayEnemyDamage && !core.flags.displayExtraDamage) return;
+ core.status.damage.data = [];
+ if (!core.flags.displayEnemyDamage && !core.flags.displayExtraDamage) return;
- core.extractBlocks(floorId);
- core.status.maps[floorId].blocks.forEach(function (block) {
- var x = block.x, y = block.y;
+ core.extractBlocks(floorId);
+ core.status.maps[floorId].blocks.forEach(function (block) {
+ var x = block.x,
+ y = block.y;
- // v2优化,只绘制范围内的部分
- if (onMap && core.bigmap.v2) {
- if (x < core.bigmap.posX - core.bigmap.extend || x > core.bigmap.posX + core._WIDTH_ + core.bigmap.extend
- || y < core.bigmap.posY - core.bigmap.extend || y > core.bigmap.posY + core._HEIGHT_ + core.bigmap.extend) {
- return;
- }
- }
+ // v2优化,只绘制范围内的部分
+ if (onMap && core.bigmap.v2) {
+ if (
+ x < core.bigmap.posX - core.bigmap.extend ||
+ x > core.bigmap.posX + core._WIDTH_ + core.bigmap.extend ||
+ y < core.bigmap.posY - core.bigmap.extend ||
+ y > core.bigmap.posY + core._HEIGHT_ + core.bigmap.extend
+ ) {
+ return;
+ }
+ }
- if (!block.disable && block.event.cls.indexOf('enemy') == 0 && block.event.displayDamage !== false) {
- if (core.flags.displayEnemyDamage) {
- var damageString = core.enemys.getDamageString(block.event.id, x, y, floorId);
- core.status.damage.data.push({ text: damageString.damage, px: 32 * x + 1, py: 32 * (y + 1) - 1, color: damageString.color });
- }
- if (core.flags.displayCritical) {
- var critical = core.enemys.nextCriticals(block.event.id, 1, x, y, floorId);
- critical = core.formatBigNumber((critical[0] || [])[0], true);
- if (critical == '???') critical = '?';
- core.status.damage.data.push({ text: critical, px: 32 * x + 1, py: 32 * (y + 1) - 11, color: '#FFFFFF' });
- }
- }
- });
-}
+ if (
+ !block.disable &&
+ block.event.cls.indexOf("enemy") == 0 &&
+ block.event.displayDamage !== false
+ ) {
+ if (core.flags.displayEnemyDamage) {
+ var damageString = core.enemys.getDamageString(
+ block.event.id,
+ x,
+ y,
+ floorId
+ );
+ core.status.damage.data.push({
+ text: damageString.damage,
+ px: 32 * x + 1,
+ py: 32 * (y + 1) - 1,
+ color: damageString.color,
+ });
+ }
+ if (core.flags.displayCritical) {
+ var critical = core.enemys.nextCriticals(
+ block.event.id,
+ 1,
+ x,
+ y,
+ floorId
+ );
+ critical = core.formatBigNumber((critical[0] || [])[0], true);
+ if (critical == "???") critical = "?";
+ core.status.damage.data.push({
+ text: critical,
+ px: 32 * x + 1,
+ py: 32 * (y + 1) - 11,
+ color: "#FFFFFF",
+ });
+ }
+ }
+ });
+};
control.prototype._updateDamage_extraDamage = function (floorId, onMap) {
- core.status.damage.extraData = [];
- if (!core.flags.displayExtraDamage) return;
+ core.status.damage.extraData = [];
+ if (!core.flags.displayExtraDamage) return;
- var width = core.floors[floorId].width, height = core.floors[floorId].height;
- var startX = onMap && core.bigmap.v2 ? Math.max(0, core.bigmap.posX - core.bigmap.extend) : 0;
- var endX = onMap && core.bigmap.v2 ? Math.min(width, core.bigmap.posX + core._WIDTH_ + core.bigmap.extend + 1) : width;
- var startY = onMap && core.bigmap.v2 ? Math.max(0, core.bigmap.posY - core.bigmap.extend) : 0;
- var endY = onMap && core.bigmap.v2 ? Math.min(height, core.bigmap.posY + core._HEIGHT_ + core.bigmap.extend + 1) : height;
+ var width = core.floors[floorId].width,
+ height = core.floors[floorId].height;
+ var startX =
+ onMap && core.bigmap.v2
+ ? Math.max(0, core.bigmap.posX - core.bigmap.extend)
+ : 0;
+ var endX =
+ onMap && core.bigmap.v2
+ ? Math.min(
+ width,
+ core.bigmap.posX + core._WIDTH_ + core.bigmap.extend + 1
+ )
+ : width;
+ var startY =
+ onMap && core.bigmap.v2
+ ? Math.max(0, core.bigmap.posY - core.bigmap.extend)
+ : 0;
+ var endY =
+ onMap && core.bigmap.v2
+ ? Math.min(
+ height,
+ core.bigmap.posY + core._HEIGHT_ + core.bigmap.extend + 1
+ )
+ : height;
- for (var x = startX; x < endX; x++) {
- for (var y = startY; y < endY; y++) {
- var alpha = 1;
- if (core.noPass(x, y, floorId)) {
- if (core.flags.extraDamageType == 2) alpha = 0;
- else if (core.flags.extraDamageType == 1) alpha = 0.6;
- }
- var damage = core.status.checkBlock.damage[x + "," + y] || 0;
- if (damage > 0) { // 该点伤害
- damage = core.formatBigNumber(damage, true);
- core.status.damage.extraData.push({ text: damage, px: 32 * x + 16, py: 32 * (y + 1) - 14, color: '#ffaa33', alpha: alpha });
- }
- else { // 检查捕捉
- if (core.status.checkBlock.ambush[x + "," + y]) {
- core.status.damage.extraData.push({ text: '!', px: 32 * x + 16, py: 32 * (y + 1) - 14, color: '#ffaa33', alpha: alpha });
- }
- }
+ for (var x = startX; x < endX; x++) {
+ for (var y = startY; y < endY; y++) {
+ var alpha = 1;
+ if (core.noPass(x, y, floorId)) {
+ if (core.flags.extraDamageType == 2) alpha = 0;
+ else if (core.flags.extraDamageType == 1) alpha = 0.6;
+ }
+ var damage = core.status.checkBlock.damage[x + "," + y] || 0;
+ if (damage > 0) {
+ // 该点伤害
+ damage = core.formatBigNumber(damage, true);
+ core.status.damage.extraData.push({
+ text: damage,
+ px: 32 * x + 16,
+ py: 32 * (y + 1) - 14,
+ color: "#ffaa33",
+ alpha: alpha,
+ });
+ } else {
+ // 检查捕捉
+ if (core.status.checkBlock.ambush[x + "," + y]) {
+ core.status.damage.extraData.push({
+ text: "!",
+ px: 32 * x + 16,
+ py: 32 * (y + 1) - 14,
+ color: "#ffaa33",
+ alpha: alpha,
+ });
}
+ }
}
-}
+ }
+};
////// 重绘地图显伤 //////
control.prototype.drawDamage = function (ctx) {
- if (core.status.gameOver || !core.status.damage || main.mode != 'play') return;
- var onMap = false;
- if (ctx == null) {
- ctx = core.canvas.damage;
- core.clearMap('damage');
- onMap = true;
- }
+ if (core.status.gameOver || !core.status.damage || main.mode != "play")
+ return;
+ var onMap = false;
+ if (ctx == null) {
+ ctx = core.canvas.damage;
+ core.clearMap("damage");
+ onMap = true;
+ }
- if (onMap && core.bigmap.v2) {
- // 检查是否需要重算...
- if (Math.abs(core.bigmap.posX - core.status.damage.posX) >= core.bigmap.extend - 1
- || Math.abs(core.bigmap.posY - core.status.damage.posY) >= core.bigmap.extend - 1) {
- return this.updateDamage();
- }
+ if (onMap && core.bigmap.v2) {
+ // 检查是否需要重算...
+ if (
+ Math.abs(core.bigmap.posX - core.status.damage.posX) >=
+ core.bigmap.extend - 1 ||
+ Math.abs(core.bigmap.posY - core.status.damage.posY) >=
+ core.bigmap.extend - 1
+ ) {
+ return this.updateDamage();
}
- return this._drawDamage_draw(ctx, onMap);
-}
+ }
+ return this._drawDamage_draw(ctx, onMap);
+};
control.prototype._drawDamage_draw = function (ctx, onMap) {
- if (!core.hasItem('book')) return;
+ if (!core.hasItem("book")) return;
- core.setFont(ctx, "bold 11px Arial");
- core.setTextAlign(ctx, 'left');
- core.status.damage.data.forEach(function (one) {
- var px = one.px, py = one.py;
- if (onMap && core.bigmap.v2) {
- px -= core.bigmap.posX * 32;
- py -= core.bigmap.posY * 32;
- if (px < -32 * 2 || px > core._PX_ + 32 || py < -32 || py > core._PY_ + 32)
- return;
- }
- core.fillBoldText(ctx, one.text, px, py, one.color);
- });
+ core.setFont(ctx, "bold 11px Arial");
+ core.setTextAlign(ctx, "left");
+ core.status.damage.data.forEach(function (one) {
+ var px = one.px,
+ py = one.py;
+ if (onMap && core.bigmap.v2) {
+ px -= core.bigmap.posX * 32;
+ py -= core.bigmap.posY * 32;
+ if (
+ px < -32 * 2 ||
+ px > core._PX_ + 32 ||
+ py < -32 ||
+ py > core._PY_ + 32
+ )
+ return;
+ }
+ core.fillBoldText(ctx, one.text, px, py, one.color);
+ });
- core.setTextAlign(ctx, 'center');
- core.status.damage.extraData.forEach(function (one) {
- var px = one.px, py = one.py;
- if (onMap && core.bigmap.v2) {
- px -= core.bigmap.posX * 32;
- py -= core.bigmap.posY * 32;
- if (px < -32 || px > core._PX_ + 32 || py < -32 || py > core._PY_ + 32)
- return;
- }
- var alpha = core.setAlpha(ctx, one.alpha);
- core.fillBoldText(ctx, one.text, px, py, one.color);
- core.setAlpha(ctx, alpha);
- });
-}
+ core.setTextAlign(ctx, "center");
+ core.status.damage.extraData.forEach(function (one) {
+ var px = one.px,
+ py = one.py;
+ if (onMap && core.bigmap.v2) {
+ px -= core.bigmap.posX * 32;
+ py -= core.bigmap.posY * 32;
+ if (px < -32 || px > core._PX_ + 32 || py < -32 || py > core._PY_ + 32)
+ return;
+ }
+ var alpha = core.setAlpha(ctx, one.alpha);
+ core.fillBoldText(ctx, one.text, px, py, one.color);
+ core.setAlpha(ctx, alpha);
+ });
+};
// ------ 录像相关 ------ //
////// 选择录像文件 //////
control.prototype.chooseReplayFile = function () {
- core.readFile(function (obj) {
- if (obj.name != core.firstData.name) return alert("存档和游戏不一致!");
- if (!obj.route) return alert("无效的录像!");
- var _replay = function () {
- core.startGame(core.flags.startUsingCanvas ? '' : obj.hard || '', obj.seed, core.decodeRoute(obj.route));
- }
- if (obj.version && obj.version != core.firstData.version) {
- core.myconfirm("游戏版本不一致!\n你仍然想播放录像吗?", _replay);
- return;
- }
- _replay();
- }, null, ".h5route");
-}
+ core.readFile(
+ function (obj) {
+ if (obj.name != core.firstData.name) return alert("存档和游戏不一致!");
+ if (!obj.route) return alert("无效的录像!");
+ var _replay = function () {
+ core.startGame(
+ core.flags.startUsingCanvas ? "" : obj.hard || "",
+ obj.seed,
+ core.decodeRoute(obj.route)
+ );
+ };
+ if (obj.version && obj.version != core.firstData.version) {
+ core.myconfirm("游戏版本不一致!\n你仍然想播放录像吗?", _replay);
+ return;
+ }
+ _replay();
+ },
+ null,
+ ".h5route"
+ );
+};
////// 开始播放 //////
control.prototype.startReplay = function (list) {
- if (!core.isPlaying()) return;
- core.status.replay.replaying = true;
- core.status.replay.pausing = true;
- core.status.replay.failed = false;
- core.status.replay.speed = 1.0;
- core.status.replay.toReplay = core.cloneArray(list);
- core.status.replay.totalList = core.status.route.concat(list);
- core.status.replay.steps = 0;
- core.status.replay.save = [];
- core.createCanvas('replay', 0, core._PY_ - 40, core._PX_, 40, 199);
- core.setOpacity('replay', 0.6);
- this._replay_drawProgress();
- core.updateStatusBar(false, true);
- core.drawTip("开始播放");
- this.replay();
-}
+ if (!core.isPlaying()) return;
+ core.status.replay.replaying = true;
+ core.status.replay.pausing = true;
+ core.status.replay.failed = false;
+ core.status.replay.speed = 1.0;
+ core.status.replay.toReplay = core.cloneArray(list);
+ core.status.replay.totalList = core.status.route.concat(list);
+ core.status.replay.steps = 0;
+ core.status.replay.save = [];
+ core.createCanvas("replay", 0, core._PY_ - 40, core._PX_, 40, 199);
+ core.setOpacity("replay", 0.6);
+ this._replay_drawProgress();
+ core.updateStatusBar(false, true);
+ core.drawTip("开始播放");
+ this.replay();
+};
////// 更改播放状态 //////
control.prototype.triggerReplay = function () {
- if (core.status.replay.pausing) this.resumeReplay();
- else this.pauseReplay();
-}
+ if (core.status.replay.pausing) this.resumeReplay();
+ else this.pauseReplay();
+};
////// 暂停播放 //////
control.prototype.pauseReplay = function () {
- if (!core.isPlaying() || !core.isReplaying()) return;
- core.status.replay.pausing = true;
- core.updateStatusBar(false, true);
- core.drawTip("暂停播放");
-}
+ if (!core.isPlaying() || !core.isReplaying()) return;
+ core.status.replay.pausing = true;
+ core.updateStatusBar(false, true);
+ core.drawTip("暂停播放");
+};
////// 恢复播放 //////
control.prototype.resumeReplay = function () {
- if (!core.isPlaying() || !core.isReplaying()) return;
- if (core.isMoving() || core.status.replay.animate || core.status.event.id) {
- core.playSound('操作失败');
- return core.drawTip("请等待当前事件的处理结束");
- }
- core.status.replay.pausing = false;
- core.updateStatusBar(false, true);
- core.drawTip("恢复播放");
- core.replay();
-}
+ if (!core.isPlaying() || !core.isReplaying()) return;
+ if (core.isMoving() || core.status.replay.animate || core.status.event.id) {
+ core.playSound("操作失败");
+ return core.drawTip("请等待当前事件的处理结束");
+ }
+ core.status.replay.pausing = false;
+ core.updateStatusBar(false, true);
+ core.drawTip("恢复播放");
+ core.replay();
+};
////// 单步播放 //////
control.prototype.stepReplay = function () {
- if (!core.isPlaying() || !core.isReplaying()) return;
- if (!core.status.replay.pausing) {
- core.playSound('操作失败');
- return core.drawTip("请先暂停录像");
- }
- if (core.isMoving() || core.status.replay.animate || core.status.event.id) {
- core.playSound('操作失败');
- return core.drawTip("请等待当前事件的处理结束");
- }
- core.replay(true);
-}
+ if (!core.isPlaying() || !core.isReplaying()) return;
+ if (!core.status.replay.pausing) {
+ core.playSound("操作失败");
+ return core.drawTip("请先暂停录像");
+ }
+ if (core.isMoving() || core.status.replay.animate || core.status.event.id) {
+ core.playSound("操作失败");
+ return core.drawTip("请等待当前事件的处理结束");
+ }
+ core.replay(true);
+};
////// 加速播放 //////
control.prototype.speedUpReplay = function () {
- if (!core.isPlaying() || !core.isReplaying()) return;
- var speeds = [0.2, 0.5, 1, 2, 3, 6, 12, 24];
- for (var i = speeds.length - 2; i >= 0; i--) {
- if (speeds[i] <= core.status.replay.speed) {
- core.status.replay.speed = speeds[i + 1];
- break;
- }
+ if (!core.isPlaying() || !core.isReplaying()) return;
+ var speeds = [0.2, 0.5, 1, 2, 3, 6, 12, 24];
+ for (var i = speeds.length - 2; i >= 0; i--) {
+ if (speeds[i] <= core.status.replay.speed) {
+ core.status.replay.speed = speeds[i + 1];
+ break;
}
- core.drawTip("x" + core.status.replay.speed + "倍");
-}
+ }
+ core.drawTip("x" + core.status.replay.speed + "倍");
+};
////// 减速播放 //////
control.prototype.speedDownReplay = function () {
- if (!core.isPlaying() || !core.isReplaying()) return;
- var speeds = [0.2, 0.5, 1, 2, 3, 6, 12, 24];
- for (var i = 1; i <= speeds.length; i++) {
- if (speeds[i] >= core.status.replay.speed) {
- core.status.replay.speed = speeds[i - 1];
- break;
- }
+ if (!core.isPlaying() || !core.isReplaying()) return;
+ var speeds = [0.2, 0.5, 1, 2, 3, 6, 12, 24];
+ for (var i = 1; i <= speeds.length; i++) {
+ if (speeds[i] >= core.status.replay.speed) {
+ core.status.replay.speed = speeds[i - 1];
+ break;
}
- core.drawTip("x" + core.status.replay.speed + "倍");
-}
+ }
+ core.drawTip("x" + core.status.replay.speed + "倍");
+};
////// 设置播放速度 //////
control.prototype.setReplaySpeed = function (speed) {
- if (!core.isPlaying() || !core.isReplaying()) return;
- core.status.replay.speed = speed;
- core.drawTip("x" + core.status.replay.speed + "倍");
-}
+ if (!core.isPlaying() || !core.isReplaying()) return;
+ core.status.replay.speed = speed;
+ core.drawTip("x" + core.status.replay.speed + "倍");
+};
////// 停止播放 //////
control.prototype.stopReplay = function (force) {
- if (!core.isPlaying()) return;
- if (!core.isReplaying() && !force) return;
- core.status.replay.toReplay = [];
- core.status.replay.totalList = [];
- core.status.replay.replaying = false;
- core.status.replay.pausing = false;
- core.status.replay.failed = false;
- core.status.replay.speed = 1.0;
- core.status.replay.steps = 0;
- core.status.replay.save = [];
- core.deleteCanvas('replay');
- core.updateStatusBar(false, true);
- core.drawTip("停止播放并恢复游戏");
-}
+ if (!core.isPlaying()) return;
+ if (!core.isReplaying() && !force) return;
+ core.status.replay.toReplay = [];
+ core.status.replay.totalList = [];
+ core.status.replay.replaying = false;
+ core.status.replay.pausing = false;
+ core.status.replay.failed = false;
+ core.status.replay.speed = 1.0;
+ core.status.replay.steps = 0;
+ core.status.replay.save = [];
+ core.deleteCanvas("replay");
+ core.updateStatusBar(false, true);
+ core.drawTip("停止播放并恢复游戏");
+};
////// 回退 //////
control.prototype.rewindReplay = function () {
- if (!core.isPlaying() || !core.isReplaying()) return;
- if (!core.status.replay.pausing) {
- core.playSound('操作失败');
- return core.drawTip("请先暂停录像");
- }
- if (core.isMoving() || core.status.replay.animate || core.status.event.id) {
- core.playSound('操作失败');
- return core.drawTip("请等待当前事件的处理结束");
- }
- if (core.status.replay.save.length == 0) {
- core.playSound('操作失败');
- return core.drawTip("无法再回到上一个节点");
- }
- var save = core.status.replay.save, data = save.pop();
- core.loadData(data.data, function () {
- core.removeFlag('__fromLoad__');
- core.status.replay = {
- "replaying": true,
- "pausing": true,
- "animate": false,
- "toReplay": data.replay.toReplay,
- "totalList": data.replay.totalList,
- "speed": core.status.replay.speed,
- "steps": data.replay.steps,
- "save": save
- }
- core.createCanvas('replay', 0, core._PY_ - 40, core._PX_, 40, 199);
- core.setOpacity('replay', 0.6);
- core.control._replay_drawProgress();
- core.updateStatusBar(false, true);
- core.drawTip("成功回退到上一个节点");
- });
-}
+ if (!core.isPlaying() || !core.isReplaying()) return;
+ if (!core.status.replay.pausing) {
+ core.playSound("操作失败");
+ return core.drawTip("请先暂停录像");
+ }
+ if (core.isMoving() || core.status.replay.animate || core.status.event.id) {
+ core.playSound("操作失败");
+ return core.drawTip("请等待当前事件的处理结束");
+ }
+ if (core.status.replay.save.length == 0) {
+ core.playSound("操作失败");
+ return core.drawTip("无法再回到上一个节点");
+ }
+ var save = core.status.replay.save,
+ data = save.pop();
+ core.loadData(data.data, function () {
+ core.removeFlag("__fromLoad__");
+ core.status.replay = {
+ replaying: true,
+ pausing: true,
+ animate: false,
+ toReplay: data.replay.toReplay,
+ totalList: data.replay.totalList,
+ speed: core.status.replay.speed,
+ steps: data.replay.steps,
+ save: save,
+ };
+ core.createCanvas("replay", 0, core._PY_ - 40, core._PX_, 40, 199);
+ core.setOpacity("replay", 0.6);
+ core.control._replay_drawProgress();
+ core.updateStatusBar(false, true);
+ core.drawTip("成功回退到上一个节点");
+ });
+};
////// 回放时存档 //////
control.prototype._replay_SL = function () {
- if (!core.isPlaying() || !core.isReplaying()) return;
- if (!core.status.replay.pausing) {
- core.playSound('操作失败');
- return core.drawTip("请先暂停录像");
- }
- if (core.isMoving() || core.status.replay.animate || core.status.event.id) {
- core.playSound('操作失败');
- return core.drawTip("请等待当前事件的处理结束");
- }
- if (core.hasFlag('__forbidSave__')) {
- core.playSound('操作失败');
- return core.drawTip('当前禁止存档');
- }
- this._replay_hideProgress();
+ if (!core.isPlaying() || !core.isReplaying()) return;
+ if (!core.status.replay.pausing) {
+ core.playSound("操作失败");
+ return core.drawTip("请先暂停录像");
+ }
+ if (core.isMoving() || core.status.replay.animate || core.status.event.id) {
+ core.playSound("操作失败");
+ return core.drawTip("请等待当前事件的处理结束");
+ }
+ if (core.hasFlag("__forbidSave__")) {
+ core.playSound("操作失败");
+ return core.drawTip("当前禁止存档");
+ }
+ this._replay_hideProgress();
- core.lockControl();
- core.status.event.id = 'save';
- var saveIndex = core.saves.saveIndex;
- var page = parseInt((saveIndex - 1) / 5), offset = saveIndex - 5 * page;
+ core.lockControl();
+ core.status.event.id = "save";
+ var saveIndex = core.saves.saveIndex;
+ var page = parseInt((saveIndex - 1) / 5),
+ offset = saveIndex - 5 * page;
- core.ui._drawSLPanel(10 * page + offset);
-}
+ core.ui._drawSLPanel(10 * page + offset);
+};
////// 回放时查看怪物手册 //////
control.prototype._replay_book = function () {
- if (!core.isPlaying() || !core.isReplaying()) return;
- if (!core.status.replay.pausing) {
- core.playSound('操作失败');
- return core.drawTip("请先暂停录像");
- }
- if (core.isMoving() || core.status.replay.animate || (core.status.event.id && core.status.event.id != 'viewMaps')) {
- core.playSound('操作失败');
- return core.drawTip("请等待当前事件的处理结束");
- }
- if (!core.hasItem('book')) {
- core.playSound('操作失败');
- return core.drawTip('你没有' + core.material.items['book'].name, 'book');
- }
- this._replay_hideProgress();
+ if (!core.isPlaying() || !core.isReplaying()) return;
+ if (!core.status.replay.pausing) {
+ core.playSound("操作失败");
+ return core.drawTip("请先暂停录像");
+ }
+ if (
+ core.isMoving() ||
+ core.status.replay.animate ||
+ (core.status.event.id && core.status.event.id != "viewMaps")
+ ) {
+ core.playSound("操作失败");
+ return core.drawTip("请等待当前事件的处理结束");
+ }
+ if (!core.hasItem("book")) {
+ core.playSound("操作失败");
+ return core.drawTip("你没有" + core.material.items["book"].name, "book");
+ }
+ this._replay_hideProgress();
- // 从“浏览地图”页面打开
- if (core.status.event.id == 'viewMaps')
- core.status.event.ui = core.status.event.data;
+ // 从“浏览地图”页面打开
+ if (core.status.event.id == "viewMaps")
+ core.status.event.ui = core.status.event.data;
- core.lockControl();
- core.status.event.id = 'book';
- core.useItem('book', true);
-}
+ core.lockControl();
+ core.status.event.id = "book";
+ core.useItem("book", true);
+};
////// 回放录像时浏览地图 //////
control.prototype._replay_viewMap = function () {
- if (!core.isPlaying() || !core.isReplaying()) return;
- if (!core.status.replay.pausing) {
- core.playSound('操作失败');
- return core.drawTip("请先暂停录像");
- }
- if (core.isMoving() || core.status.replay.animate || core.status.event.id) {
- core.playSound('操作失败');
- return core.drawTip("请等待当前事件的处理结束");
- }
- this._replay_hideProgress();
+ if (!core.isPlaying() || !core.isReplaying()) return;
+ if (!core.status.replay.pausing) {
+ core.playSound("操作失败");
+ return core.drawTip("请先暂停录像");
+ }
+ if (core.isMoving() || core.status.replay.animate || core.status.event.id) {
+ core.playSound("操作失败");
+ return core.drawTip("请等待当前事件的处理结束");
+ }
+ this._replay_hideProgress();
- core.lockControl();
- core.status.event.id = 'viewMaps';
- core.ui._drawViewMaps();
-}
+ core.lockControl();
+ core.status.event.id = "viewMaps";
+ core.ui._drawViewMaps();
+};
control.prototype._replay_toolbox = function () {
- if (!core.isPlaying() || !core.isReplaying()) return;
- if (!core.status.replay.pausing) {
- core.playSound('操作失败');
- return core.drawTip("请先暂停录像");
- }
- if (core.isMoving() || core.status.replay.animate || core.status.event.id) {
- core.playSound('操作失败');
- return core.drawTip("请等待当前事件的处理结束");
- }
- this._replay_hideProgress();
+ if (!core.isPlaying() || !core.isReplaying()) return;
+ if (!core.status.replay.pausing) {
+ core.playSound("操作失败");
+ return core.drawTip("请先暂停录像");
+ }
+ if (core.isMoving() || core.status.replay.animate || core.status.event.id) {
+ core.playSound("操作失败");
+ return core.drawTip("请等待当前事件的处理结束");
+ }
+ this._replay_hideProgress();
- core.lockControl();
- core.status.event.id = 'toolbox';
- core.ui._drawToolbox();
-}
+ core.lockControl();
+ core.status.event.id = "toolbox";
+ core.ui._drawToolbox();
+};
control.prototype._replay_equipbox = function () {
- if (!core.isPlaying() || !core.isReplaying()) return;
- if (!core.status.replay.pausing) {
- core.playSound('操作失败');
- return core.drawTip("请先暂停录像");
- }
- if (core.isMoving() || core.status.replay.animate || core.status.event.id) {
- core.playSound('操作失败');
- return core.drawTip("请等待当前事件的处理结束");
- }
- this._replay_hideProgress();
+ if (!core.isPlaying() || !core.isReplaying()) return;
+ if (!core.status.replay.pausing) {
+ core.playSound("操作失败");
+ return core.drawTip("请先暂停录像");
+ }
+ if (core.isMoving() || core.status.replay.animate || core.status.event.id) {
+ core.playSound("操作失败");
+ return core.drawTip("请等待当前事件的处理结束");
+ }
+ this._replay_hideProgress();
- core.lockControl();
- core.status.event.id = 'equipbox';
- core.ui._drawEquipbox();
-}
+ core.lockControl();
+ core.status.event.id = "equipbox";
+ core.ui._drawEquipbox();
+};
////// 是否正在播放录像 //////
control.prototype.isReplaying = function () {
- return (core.status.replay || {}).replaying;
-}
+ return (core.status.replay || {}).replaying;
+};
////// 回放 //////
control.prototype.replay = function (force) {
- if (!core.isPlaying() || !core.isReplaying()
- || core.status.replay.animate || core.status.event.id || core.status.replay.failed) return;
- if (core.status.replay.pausing && !force) return;
- this._replay_drawProgress();
- if (core.status.replay.toReplay.length == 0)
- return this._replay_finished();
- this._replay_save();
- var action = core.status.replay.toReplay.shift();
- if (this._doReplayAction(action)) return;
- this._replay_error(action);
-}
+ if (
+ !core.isPlaying() ||
+ !core.isReplaying() ||
+ core.status.replay.animate ||
+ core.status.event.id ||
+ core.status.replay.failed
+ )
+ return;
+ if (core.status.replay.pausing && !force) return;
+ this._replay_drawProgress();
+ if (core.status.replay.toReplay.length == 0) return this._replay_finished();
+ this._replay_save();
+ var action = core.status.replay.toReplay.shift();
+ if (this._doReplayAction(action)) return;
+ this._replay_error(action);
+};
////// 注册一个录像行为 //////
// name:自定义名称,可用于注销使用
@@ -1608,1958 +2039,2394 @@ control.prototype.replay = function (force) {
// 需要接受一个action参数,代表录像回放时的下一个操作
// func返回true代表成功处理了此录像行为,false代表没有处理此录像行为。
control.prototype.registerReplayAction = function (name, func) {
- this.unregisterReplayAction(name);
- this.replayActions.push({ name: name, func: func });
-}
+ this.unregisterReplayAction(name);
+ this.replayActions.push({ name: name, func: func });
+};
////// 注销一个录像行为 //////
control.prototype.unregisterReplayAction = function (name) {
- this.replayActions = this.replayActions.filter(function (b) { return b.name != name; });
-}
+ this.replayActions = this.replayActions.filter(function (b) {
+ return b.name != name;
+ });
+};
////// 执行录像行为,会在注册的函数中依次执行直到得到true为止 //////
control.prototype._doReplayAction = function (action) {
- for (var i in this.replayActions) {
- try {
- if (core.doFunc(this.replayActions[i].func, this, action)) return true;
- } catch (e) {
- console.error(e);
- console.error("ERROR in replayActions[" + this.replayActions[i].name + "]:已自动注销该项。");
- core.unregisterReplayAction(this.replayActions[i].name);
- }
+ for (var i in this.replayActions) {
+ try {
+ if (core.doFunc(this.replayActions[i].func, this, action)) return true;
+ } catch (e) {
+ console.error(e);
+ console.error(
+ "ERROR in replayActions[" +
+ this.replayActions[i].name +
+ "]:已自动注销该项。"
+ );
+ core.unregisterReplayAction(this.replayActions[i].name);
}
- return false;
-}
+ }
+ return false;
+};
control.prototype._replay_finished = function () {
- core.status.replay.replaying = false;
- core.status.replay.failed = false;
- core.status.event.selection = 0;
- var str = "录像播放完毕,你想退出播放吗?";
- if (core.status.route.length != core.status.replay.totalList.length
- || core.subarray(core.status.route, core.status.replay.totalList) == null) {
- str = "录像播放完毕,但记录不一致。\n请检查录像播放时的二次记录问题。\n你想退出播放吗?";
+ core.status.replay.replaying = false;
+ core.status.replay.failed = false;
+ core.status.event.selection = 0;
+ var str = "录像播放完毕,你想退出播放吗?";
+ if (
+ core.status.route.length != core.status.replay.totalList.length ||
+ core.subarray(core.status.route, core.status.replay.totalList) == null
+ ) {
+ str =
+ "录像播放完毕,但记录不一致。\n请检查录像播放时的二次记录问题。\n你想退出播放吗?";
+ }
+ core.ui.drawConfirmBox(
+ str,
+ function () {
+ core.ui.closePanel();
+ core.stopReplay(true);
+ },
+ function () {
+ core.status.replay.replaying = true;
+ core.ui.closePanel();
+ core.pauseReplay();
}
- core.ui.drawConfirmBox(str, function () {
- core.ui.closePanel();
- core.stopReplay(true);
- }, function () {
- core.status.replay.replaying = true;
- core.ui.closePanel();
- core.pauseReplay();
- });
-}
+ );
+};
control.prototype._replay_save = function () {
- core.status.replay.steps++;
- if (core.status.replay.steps % 40 == 1) {
- if (core.status.replay.save.length == 30)
- core.status.replay.save.shift();
- core.status.replay.save.push({
- "data": core.saveData(), "replay": {
- "totalList": core.cloneArray(core.status.replay.totalList),
- "toReplay": core.cloneArray(core.status.replay.toReplay),
- "steps": core.status.replay.steps
- }
- });
- }
-}
+ core.status.replay.steps++;
+ if (core.status.replay.steps % 40 == 1) {
+ if (core.status.replay.save.length == 30) core.status.replay.save.shift();
+ core.status.replay.save.push({
+ data: core.saveData(),
+ replay: {
+ totalList: core.cloneArray(core.status.replay.totalList),
+ toReplay: core.cloneArray(core.status.replay.toReplay),
+ steps: core.status.replay.steps,
+ },
+ });
+ }
+};
control.prototype._replay_error = function (action, callback) {
- core.ui.closePanel();
- core.status.replay.replaying = false;
- core.status.replay.failed = true;
- var len = core.status.replay.toReplay.length;
- var prevList = core.status.replay.totalList.slice(-len - 11, -len - 1);
- var nextList = core.status.replay.toReplay.slice(0, 10);
- console.log("录像文件出错,当前操作:" + action);
- console.log("之前的10个操作是:\n" + prevList.toString());
- console.log("接下来10个操作是:\n" + nextList.toString());
- core.ui.drawConfirmBox("录像文件出错,你想回到上个节点吗?", function () {
- core.status.replay.failed = false;
- core.ui.closePanel();
- if (core.status.replay.save.length > 0) {
- core.status.replay.replaying = true;
- core.status.replay.pausing = true;
- core.rewindReplay();
- }
- else {
- core.playSound('操作失败');
- core.stopReplay(true);
- core.drawTip("无法回到上一个节点");
- if (callback) callback();
- }
- }, function () {
- core.status.replay.failed = false;
- core.ui.closePanel();
+ core.ui.closePanel();
+ core.status.replay.replaying = false;
+ core.status.replay.failed = true;
+ var len = core.status.replay.toReplay.length;
+ var prevList = core.status.replay.totalList.slice(-len - 11, -len - 1);
+ var nextList = core.status.replay.toReplay.slice(0, 10);
+ console.log("录像文件出错,当前操作:" + action);
+ console.log("之前的10个操作是:\n" + prevList.toString());
+ console.log("接下来10个操作是:\n" + nextList.toString());
+ core.ui.drawConfirmBox(
+ "录像文件出错,你想回到上个节点吗?",
+ function () {
+ core.status.replay.failed = false;
+ core.ui.closePanel();
+ if (core.status.replay.save.length > 0) {
+ core.status.replay.replaying = true;
+ core.status.replay.pausing = true;
+ core.rewindReplay();
+ } else {
+ core.playSound("操作失败");
core.stopReplay(true);
+ core.drawTip("无法回到上一个节点");
if (callback) callback();
- });
-}
+ }
+ },
+ function () {
+ core.status.replay.failed = false;
+ core.ui.closePanel();
+ core.stopReplay(true);
+ if (callback) callback();
+ }
+ );
+};
control.prototype._replay_hideProgress = function () {
- if (core.dymCanvas.replay) core.dymCanvas.replay.canvas.style.display = 'none';
-}
+ if (core.dymCanvas.replay)
+ core.dymCanvas.replay.canvas.style.display = "none";
+};
control.prototype._replay_drawProgress = function () {
- if (!core.dymCanvas.replay) return;
- if (core.dymCanvas.replay.canvas.style.display == 'none') core.dymCanvas.replay.canvas.style.display = 'block';
- var total = core.status.replay.totalList.length, left = total - core.status.replay.toReplay.length;
- var content = '播放进度:' + left + ' / ' + total + '(' + (left / total * 100).toFixed(2) + '%)';
- var width = 26 + core.calWidth('replay', content, "16px Arial");
- core.clearMap('replay');
- core.fillRect('replay', 0, 0, width, 40, '#000000');
- core.fillText('replay', content, 16, 27, '#FFFFFF');
-}
+ if (!core.dymCanvas.replay) return;
+ if (core.dymCanvas.replay.canvas.style.display == "none")
+ core.dymCanvas.replay.canvas.style.display = "block";
+ var total = core.status.replay.totalList.length,
+ left = total - core.status.replay.toReplay.length;
+ var content =
+ "播放进度:" +
+ left +
+ " / " +
+ total +
+ "(" +
+ ((left / total) * 100).toFixed(2) +
+ "%)";
+ var width = 26 + core.calWidth("replay", content, "16px Arial");
+ core.clearMap("replay");
+ core.fillRect("replay", 0, 0, width, 40, "#000000");
+ core.fillText("replay", content, 16, 27, "#FFFFFF");
+};
control.prototype.__replay_getTimeout = function () {
- if (core.status.replay.speed == 24) return 0;
- return 750 / Math.max(1, core.status.replay.speed);
-}
+ if (core.status.replay.speed == 24) return 0;
+ return 750 / Math.max(1, core.status.replay.speed);
+};
control.prototype._replayAction_move = function (action) {
- if (["up", "down", "left", "right"].indexOf(action) < 0) return false;
- core.moveHero(action, core.replay);
- return true;
-}
+ if (["up", "down", "left", "right"].indexOf(action) < 0) return false;
+ core.moveHero(action, core.replay);
+ return true;
+};
control.prototype._replayAction_item = function (action) {
- if (action.indexOf("item:") != 0) return false;
- var itemId = action.substring(5);
- if (!core.canUseItem(itemId)) return false;
- if (core.material.items[itemId].hideInReplay || core.status.replay.speed == 24) {
- core.useItem(itemId, false, core.replay);
- return true;
- }
- var tools = core.getToolboxItems('tools'),
- constants = core.getToolboxItems('constants');
- var index, per = core._WIDTH_ - 1;
- if ((index = tools.indexOf(itemId)) >= 0) {
- core.status.event.data = { "toolsPage": Math.floor(index / per) + 1, "constantsPage": 1 };
- index = index % per;
- }
- else if ((index = constants.indexOf(itemId)) >= 0) {
- core.status.event.data = { "toolsPage": 1, "constantsPage": Math.floor(index / per) + 1 };
- index = index % per + per;
- }
- if (index < 0) return false;
- core.ui._drawToolbox(index);
- setTimeout(function () {
- core.ui.closePanel();
- core.useItem(itemId, false, core.replay);
- }, core.control.__replay_getTimeout());
+ if (action.indexOf("item:") != 0) return false;
+ var itemId = action.substring(5);
+ if (!core.canUseItem(itemId)) return false;
+ if (
+ core.material.items[itemId].hideInReplay ||
+ core.status.replay.speed == 24
+ ) {
+ core.useItem(itemId, false, core.replay);
return true;
-}
+ }
+ var tools = core.getToolboxItems("tools"),
+ constants = core.getToolboxItems("constants");
+ var index,
+ per = core._WIDTH_ - 1;
+ if ((index = tools.indexOf(itemId)) >= 0) {
+ core.status.event.data = {
+ toolsPage: Math.floor(index / per) + 1,
+ constantsPage: 1,
+ };
+ index = index % per;
+ } else if ((index = constants.indexOf(itemId)) >= 0) {
+ core.status.event.data = {
+ toolsPage: 1,
+ constantsPage: Math.floor(index / per) + 1,
+ };
+ index = (index % per) + per;
+ }
+ if (index < 0) return false;
+ core.ui._drawToolbox(index);
+ setTimeout(function () {
+ core.ui.closePanel();
+ core.useItem(itemId, false, core.replay);
+ }, core.control.__replay_getTimeout());
+ return true;
+};
control.prototype._replayAction_equip = function (action) {
- if (action.indexOf("equip:") != 0) return false;
- var equipId = action.substring(6);
- var ownEquipment = core.getToolboxItems('equips');
- var index = ownEquipment.indexOf(equipId), per = core._WIDTH_ - 1;
- if (index < 0) {
- core.removeFlag('__doNotCheckAutoEvents__');
- return false;
- }
+ if (action.indexOf("equip:") != 0) return false;
+ var equipId = action.substring(6);
+ var ownEquipment = core.getToolboxItems("equips");
+ var index = ownEquipment.indexOf(equipId),
+ per = core._WIDTH_ - 1;
+ if (index < 0) {
+ core.removeFlag("__doNotCheckAutoEvents__");
+ return false;
+ }
- var cb = function () {
- var next = core.status.replay.toReplay[0] || "";
- if (!next.startsWith('equip:') && !next.startsWith('unEquip:')) {
- core.removeFlag('__doNotCheckAutoEvents__');
- core.checkAutoEvents();
- }
- core.replay();
+ var cb = function () {
+ var next = core.status.replay.toReplay[0] || "";
+ if (!next.startsWith("equip:") && !next.startsWith("unEquip:")) {
+ core.removeFlag("__doNotCheckAutoEvents__");
+ core.checkAutoEvents();
}
- core.setFlag('__doNotCheckAutoEvents__', true);
+ core.replay();
+ };
+ core.setFlag("__doNotCheckAutoEvents__", true);
- core.status.route.push(action);
- if (core.material.items[equipId].hideInReplay || core.status.replay.speed == 24) {
- core.loadEquip(equipId, cb);
- return true;
- }
- core.status.event.data = { "page": Math.floor(index / per) + 1, "selectId": null };
- index = index % per + per;
- core.ui._drawEquipbox(index);
- setTimeout(function () {
- core.ui.closePanel();
- core.loadEquip(equipId, cb);
- }, core.control.__replay_getTimeout());
+ core.status.route.push(action);
+ if (
+ core.material.items[equipId].hideInReplay ||
+ core.status.replay.speed == 24
+ ) {
+ core.loadEquip(equipId, cb);
return true;
-}
+ }
+ core.status.event.data = {
+ page: Math.floor(index / per) + 1,
+ selectId: null,
+ };
+ index = (index % per) + per;
+ core.ui._drawEquipbox(index);
+ setTimeout(function () {
+ core.ui.closePanel();
+ core.loadEquip(equipId, cb);
+ }, core.control.__replay_getTimeout());
+ return true;
+};
control.prototype._replayAction_unEquip = function (action) {
- if (action.indexOf("unEquip:") != 0) return false;
- var equipType = parseInt(action.substring(8));
- if (!core.isset(equipType)) {
- core.removeFlag('__doNotCheckAutoEvents__');
- return false;
- }
+ if (action.indexOf("unEquip:") != 0) return false;
+ var equipType = parseInt(action.substring(8));
+ if (!core.isset(equipType)) {
+ core.removeFlag("__doNotCheckAutoEvents__");
+ return false;
+ }
- var cb = function () {
- var next = core.status.replay.toReplay[0] || "";
- if (!next.startsWith('equip:') && !next.startsWith('unEquip:')) {
- core.removeFlag('__doNotCheckAutoEvents__');
- core.checkAutoEvents();
- }
- core.replay();
+ var cb = function () {
+ var next = core.status.replay.toReplay[0] || "";
+ if (!next.startsWith("equip:") && !next.startsWith("unEquip:")) {
+ core.removeFlag("__doNotCheckAutoEvents__");
+ core.checkAutoEvents();
}
- core.setFlag('__doNotCheckAutoEvents__', true);
+ core.replay();
+ };
+ core.setFlag("__doNotCheckAutoEvents__", true);
- core.ui._drawEquipbox(equipType);
- core.status.route.push(action);
- if (core.status.replay.speed == 24) {
- core.unloadEquip(equipType, cb);
- return true;
- }
- setTimeout(function () {
- core.ui.closePanel();
- core.unloadEquip(equipType, cb);
- }, core.control.__replay_getTimeout());
+ core.ui._drawEquipbox(equipType);
+ core.status.route.push(action);
+ if (core.status.replay.speed == 24) {
+ core.unloadEquip(equipType, cb);
return true;
-}
+ }
+ setTimeout(function () {
+ core.ui.closePanel();
+ core.unloadEquip(equipType, cb);
+ }, core.control.__replay_getTimeout());
+ return true;
+};
control.prototype._replayAction_saveEquip = function (action) {
- if (action.indexOf('saveEquip:') != 0) return false;
- core.quickSaveEquip(parseInt(action.substring(10)));
- core.replay();
- return true;
-}
+ if (action.indexOf("saveEquip:") != 0) return false;
+ core.quickSaveEquip(parseInt(action.substring(10)));
+ core.replay();
+ return true;
+};
control.prototype._replayAction_loadEquip = function (action) {
- if (action.indexOf('loadEquip:') != 0) return false;
- core.quickLoadEquip(parseInt(action.substring(10)));
- core.replay();
- return true;
-}
+ if (action.indexOf("loadEquip:") != 0) return false;
+ core.quickLoadEquip(parseInt(action.substring(10)));
+ core.replay();
+ return true;
+};
control.prototype._replayAction_fly = function (action) {
- if (action.indexOf("fly:") != 0) return false;
- var floorId = action.substring(4);
- var toIndex = core.floorIds.indexOf(floorId);
- if (!core.canUseItem('fly') || (core.flags.flyNearStair && !core.nearStair())) return false;
- core.ui.drawFly(toIndex);
- if (core.status.replay.speed == 24) {
- if (!core.flyTo(floorId, core.replay))
- core.control._replay_error(action);
- return true;
- }
- setTimeout(function () {
- if (!core.flyTo(floorId, core.replay))
- core.control._replay_error(action);
- }, core.control.__replay_getTimeout());
+ if (action.indexOf("fly:") != 0) return false;
+ var floorId = action.substring(4);
+ var toIndex = core.floorIds.indexOf(floorId);
+ if (
+ !core.canUseItem("fly") ||
+ (core.flags.flyNearStair && !core.nearStair() && !flags.canMoveFloor)
+ )
+ return false;
+ core.ui.drawFly(toIndex);
+ if (core.status.replay.speed == 24) {
+ if (!core.flyTo(floorId, core.replay)) core.control._replay_error(action);
return true;
-}
+ }
+ setTimeout(function () {
+ if (!core.flyTo(floorId, core.replay)) core.control._replay_error(action);
+ }, core.control.__replay_getTimeout());
+ return true;
+};
control.prototype._replayAction_shop = function (action) {
- if (action.indexOf("shop:") != 0) return false;
- var shopId = action.substring(5);
- if (core.canUseQuickShop(shopId) != null || !core.canOpenShop(shopId)) {
- this._replay_error(shopId);
- return true;
- }
- core.openShop(shopId, false);
- core.replay();
+ if (action.indexOf("shop:") != 0) return false;
+ var shopId = action.substring(5);
+ if (core.canUseQuickShop(shopId) != null || !core.canOpenShop(shopId)) {
+ this._replay_error(shopId);
return true;
-}
+ }
+ core.openShop(shopId, false);
+ core.replay();
+ return true;
+};
control.prototype._replayAction_turn = function (action) {
- if (action != 'turn' && action.indexOf('turn:') != 0) return false;
- if (action == 'turn') core.turnHero();
- else core.turnHero(action.substring(5));
- core.replay();
- return true;
-}
+ if (action != "turn" && action.indexOf("turn:") != 0) return false;
+ if (action == "turn") core.turnHero();
+ else core.turnHero(action.substring(5));
+ core.replay();
+ return true;
+};
control.prototype._replayAction_getNext = function (action) {
- if (action != "getNext") return false;
- core.getNextItem();
- core.replay();
- return true;
-}
+ if (action != "getNext") return false;
+ core.getNextItem();
+ core.replay();
+ return true;
+};
control.prototype._replayAction_moveDirectly = function (action) {
- if (action.indexOf("move:") != 0) return false;
- // 忽略连续的瞬移事件;如果大地图某一边超过计算范围则不合并
- if (!core.hasFlag('poison') && core.status.thisMap.width < 2 * core.bigmap.extend + core._WIDTH_
- && core.status.thisMap.height < 2 * core.bigmap.extend + core._HEIGHT_) {
- while (core.status.replay.toReplay.length > 0 &&
- core.status.replay.toReplay[0].indexOf('move:') == 0) {
- core.status.route.push(action);
- action = core.status.replay.toReplay.shift();
- }
+ if (action.indexOf("move:") != 0) return false;
+ // 忽略连续的瞬移事件;如果大地图某一边超过计算范围则不合并
+ if (
+ !core.hasFlag("poison") &&
+ core.status.thisMap.width < 2 * core.bigmap.extend + core._WIDTH_ &&
+ core.status.thisMap.height < 2 * core.bigmap.extend + core._HEIGHT_
+ ) {
+ while (
+ core.status.replay.toReplay.length > 0 &&
+ core.status.replay.toReplay[0].indexOf("move:") == 0
+ ) {
+ core.status.route.push(action);
+ action = core.status.replay.toReplay.shift();
}
+ }
- var pos = action.substring(5).split(":");
- var x = parseInt(pos[0]), y = parseInt(pos[1]);
- var nowx = core.getHeroLoc('x'), nowy = core.getHeroLoc('y');
- var ignoreSteps = core.canMoveDirectly(x, y);
- if (!core.moveDirectly(x, y, ignoreSteps)) return false;
- if (core.status.replay.speed == 24) {
- core.replay();
- return true;
- }
-
- core.ui.drawArrow('ui', 32 * nowx + 16 - core.bigmap.offsetX, 32 * nowy + 16 - core.bigmap.offsetY,
- 32 * x + 16 - core.bigmap.offsetX, 32 * y + 16 - core.bigmap.offsetY, '#FF0000', 3);
- var timeout = this.__replay_getTimeout();
- if (ignoreSteps < 10) timeout = timeout * ignoreSteps / 10;
- setTimeout(function () {
- core.clearMap('ui');
- core.replay();
- }, timeout);
+ var pos = action.substring(5).split(":");
+ var x = parseInt(pos[0]),
+ y = parseInt(pos[1]);
+ var nowx = core.getHeroLoc("x"),
+ nowy = core.getHeroLoc("y");
+ var ignoreSteps = core.canMoveDirectly(x, y);
+ if (!core.moveDirectly(x, y, ignoreSteps)) return false;
+ if (core.status.replay.speed == 24) {
+ core.replay();
return true;
-}
+ }
+
+ core.ui.drawArrow(
+ "ui",
+ 32 * nowx + 16 - core.bigmap.offsetX,
+ 32 * nowy + 16 - core.bigmap.offsetY,
+ 32 * x + 16 - core.bigmap.offsetX,
+ 32 * y + 16 - core.bigmap.offsetY,
+ "#FF0000",
+ 3
+ );
+ var timeout = this.__replay_getTimeout();
+ if (ignoreSteps < 10) timeout = (timeout * ignoreSteps) / 10;
+ setTimeout(function () {
+ core.clearMap("ui");
+ core.replay();
+ }, timeout);
+ return true;
+};
control.prototype._replayAction_key = function (action) {
- if (action.indexOf("key:") != 0) return false;
- core.actions.keyUp(parseInt(action.substring(4)), false, true);
- core.replay();
- return true;
-}
+ if (action.indexOf("key:") != 0) return false;
+ core.actions.keyUp(parseInt(action.substring(4)), false, true);
+ core.replay();
+ return true;
+};
control.prototype._replayAction_click = function (action) {
- if (action.indexOf("click:") != 0) return false;
- var p = action.split(":");
- if (p.length != 4) return false;
- core.actions.doRegisteredAction("onStatusBarClick", parseInt(p[2]), parseInt(p[3]), parseInt(p[1]));
- core.replay();
- return true;
-}
+ if (action.indexOf("click:") != 0) return false;
+ var p = action.split(":");
+ if (p.length != 4) return false;
+ core.actions.doRegisteredAction(
+ "onStatusBarClick",
+ parseInt(p[2]),
+ parseInt(p[3]),
+ parseInt(p[1])
+ );
+ core.replay();
+ return true;
+};
control.prototype._replayAction_ignoreInput = function (action) {
- if (action.indexOf('input:') == 0 || action.indexOf('input2:') == 0 || action.indexOf('choices:') == 0 || action.indexOf('random:') == 0) {
- console.warn('警告!录像播放中出现了未知的 ' + action + '!');
- core.replay();
- return true;
- }
- return false;
-}
-
-control.prototype._replayAction_no = function (action) {
- if (action != 'no') return false;
- core.status.route.push(action);
+ if (
+ action.indexOf("input:") == 0 ||
+ action.indexOf("input2:") == 0 ||
+ action.indexOf("choices:") == 0 ||
+ action.indexOf("random:") == 0
+ ) {
+ console.warn("警告!录像播放中出现了未知的 " + action + "!");
core.replay();
return true;
-}
+ }
+ return false;
+};
+
+control.prototype._replayAction_no = function (action) {
+ if (action != "no") return false;
+ core.status.route.push(action);
+ core.replay();
+ return true;
+};
// ------ 存读档相关 ------ //
////// 自动存档 //////
control.prototype.autosave = function (removeLast) {
- if (core.hasFlag('__forbidSave__')) return;
- var x = null;
- if (removeLast) {
- x = core.status.route.pop();
- core.status.route.push("turn:" + core.getHeroLoc('direction'));
+ if (core.hasFlag("__forbidSave__")) return;
+ var x = null;
+ if (removeLast) {
+ x = core.status.route.pop();
+ core.status.route.push("turn:" + core.getHeroLoc("direction"));
+ }
+ if (core.status.event.id == "action" && !removeLast)
+ // 事件中自动存档,读档后是否回到事件触发前
+ core.setFlag("__events__", core.clone(core.status.event.data));
+ if (core.saves.autosave.data == null) {
+ core.saves.autosave.data = [];
+ }
+ core.saves.autosave.data.splice(core.saves.autosave.now, 0, core.saveData());
+ core.saves.autosave.now += 1;
+ if (core.saves.autosave.data.length > core.saves.autosave.max) {
+ if (core.saves.autosave.now < core.saves.autosave.max / 2)
+ core.saves.autosave.data.pop();
+ else {
+ core.saves.autosave.data.shift();
+ core.saves.autosave.now = core.saves.autosave.now - 1;
}
- if (core.status.event.id == 'action' && !removeLast) // 事件中自动存档,读档后是否回到事件触发前
- core.setFlag("__events__", core.clone(core.status.event.data));
- if (core.saves.autosave.data == null) {
- core.saves.autosave.data = [];
- }
- core.saves.autosave.data.splice(core.saves.autosave.now, 0, core.saveData());
- core.saves.autosave.now += 1;
- if (core.saves.autosave.data.length > core.saves.autosave.max) {
- if (core.saves.autosave.now < core.saves.autosave.max / 2)
- core.saves.autosave.data.pop();
- else {
- core.saves.autosave.data.shift();
- core.saves.autosave.now = core.saves.autosave.now - 1;
- }
- }
- core.saves.autosave.updated = true;
- core.saves.ids[0] = true;
- core.removeFlag("__events__");
- if (removeLast) {
- core.status.route.pop();
- if (x) core.status.route.push(x);
- }
-}
+ }
+ core.saves.autosave.updated = true;
+ core.saves.ids[0] = true;
+ core.removeFlag("__events__");
+ if (removeLast) {
+ core.status.route.pop();
+ if (x) core.status.route.push(x);
+ }
+};
/////// 实际进行自动存档 //////
control.prototype.checkAutosave = function () {
- if (!core.animateFrame || !core.saves || !core.saves.autosave) return;
- core.setLocalStorage('totalTime', core.animateFrame.totalTime);
- var autosave = core.saves.autosave;
- if (autosave.data == null || !autosave.updated || !autosave.storage) return;
- autosave.updated = false;
- if (autosave.data.length >= 1) {
- core.setLocalForage("autoSave", autosave.data[autosave.now - 1]);
- }
-}
+ if (!core.animateFrame || !core.saves || !core.saves.autosave) return;
+ core.setLocalStorage("totalTime", core.animateFrame.totalTime);
+ var autosave = core.saves.autosave;
+ if (autosave.data == null || !autosave.updated || !autosave.storage) return;
+ autosave.updated = false;
+ if (autosave.data.length >= 1) {
+ core.setLocalForage("autoSave", autosave.data[autosave.now - 1]);
+ }
+};
////// 实际进行存读档事件 //////
control.prototype.doSL = function (id, type) {
- switch (type) {
- case 'save': this._doSL_save(id); break;
- case 'load': this._doSL_load(id, this._doSL_load_afterGet); break;
- case 'reload': this._doSL_reload(id, this._doSL_load_afterGet); break;
- case 'replayLoad': this._doSL_load(id, this._doSL_replayLoad_afterGet); break;
- case 'replayRemain': this._doSL_load(id, this._doSL_replayRemain_afterGet); break;
- case 'replaySince': this._doSL_load(id, this._doSL_replaySince_afterGet); break;
- }
-}
+ switch (type) {
+ case "save":
+ this._doSL_save(id);
+ break;
+ case "load":
+ this._doSL_load(id, this._doSL_load_afterGet);
+ break;
+ case "reload":
+ this._doSL_reload(id, this._doSL_load_afterGet);
+ break;
+ case "replayLoad":
+ this._doSL_load(id, this._doSL_replayLoad_afterGet);
+ break;
+ case "replayRemain":
+ this._doSL_load(id, this._doSL_replayRemain_afterGet);
+ break;
+ case "replaySince":
+ this._doSL_load(id, this._doSL_replaySince_afterGet);
+ break;
+ }
+};
control.prototype._doSL_save = function (id) {
- if (id == 'autoSave') {
- core.playSound('操作失败');
- return core.drawTip('不能覆盖自动存档!');
+ if (id == "autoSave") {
+ core.playSound("操作失败");
+ return core.drawTip("不能覆盖自动存档!");
+ }
+ // 在事件中的存档
+ if (core.status.event.interval != null)
+ core.setFlag("__events__", core.status.event.interval);
+ var data = core.saveData();
+ if (core.isReplaying() && core.status.replay.toReplay.length > 0) {
+ data.__toReplay__ = core.encodeRoute(core.status.replay.toReplay);
+ }
+ core.setLocalForage(
+ "save" + id,
+ data,
+ function () {
+ core.saves.saveIndex = id;
+ core.setLocalStorage("saveIndex", core.saves.saveIndex);
+ // 恢复事件
+ if (!core.events.recoverEvents(core.status.event.interval))
+ core.ui.closePanel();
+ core.playSound("存档");
+ core.drawTip("存档成功!");
+ },
+ function (err) {
+ console.error(err);
+ alert("存档失败,错误信息:\n" + err);
}
- // 在事件中的存档
- if (core.status.event.interval != null)
- core.setFlag("__events__", core.status.event.interval);
- var data = core.saveData();
- if (core.isReplaying() && core.status.replay.toReplay.length > 0) {
- data.__toReplay__ = core.encodeRoute(core.status.replay.toReplay);
- }
- core.setLocalForage("save" + id, data, function () {
- core.saves.saveIndex = id;
- core.setLocalStorage('saveIndex', core.saves.saveIndex);
- // 恢复事件
- if (!core.events.recoverEvents(core.status.event.interval))
- core.ui.closePanel();
- core.playSound('存档');
- core.drawTip('存档成功!');
- }, function (err) {
- console.error(err);
- alert("存档失败,错误信息:\n" + err);
- });
- core.removeFlag("__events__");
- return;
-}
+ );
+ core.removeFlag("__events__");
+ return;
+};
control.prototype._doSL_load = function (id, callback) {
- if (id == 'autoSave' && core.saves.autosave.data != null) {
- core.saves.autosave.now -= 1;
- var data = core.saves.autosave.data.splice(core.saves.autosave.now, 1)[0];
- if (core.isPlaying() && !core.status.gameOver) {
- core.control.autosave(0);
- core.saves.autosave.now -= 1;
- }
- if (core.saves.autosave.now == 0) {
- core.saves.autosave.data.unshift(core.clone(data));
- core.saves.autosave.now += 1;
+ if (id == "autoSave" && core.saves.autosave.data != null) {
+ core.saves.autosave.now -= 1;
+ var data = core.saves.autosave.data.splice(core.saves.autosave.now, 1)[0];
+ if (core.isPlaying() && !core.status.gameOver) {
+ core.control.autosave(0);
+ core.saves.autosave.now -= 1;
+ }
+ if (core.saves.autosave.now == 0) {
+ core.saves.autosave.data.unshift(core.clone(data));
+ core.saves.autosave.now += 1;
+ }
+ callback(id, data);
+ } else {
+ core.getLocalForage(
+ id == "autoSave" ? id : "save" + id,
+ null,
+ function (data) {
+ if (id == "autoSave" && data != null) {
+ core.saves.autosave.data = data;
+ if (!(core.saves.autosave.data instanceof Array)) {
+ core.saves.autosave.data = [core.saves.autosave.data];
+ }
+ core.saves.autosave.now = core.saves.autosave.data.length;
+ return core.control._doSL_load(id, callback);
}
callback(id, data);
- }
- else {
- core.getLocalForage(id == 'autoSave' ? id : "save" + id, null, function (data) {
- if (id == 'autoSave' && data != null) {
- core.saves.autosave.data = data;
- if (!(core.saves.autosave.data instanceof Array)) {
- core.saves.autosave.data = [core.saves.autosave.data];
- }
- core.saves.autosave.now = core.saves.autosave.data.length;
- return core.control._doSL_load(id, callback);
- }
- callback(id, data);
- }, function (err) {
- console.error(err);
- alert("无效的存档");
- })
- }
- return;
-}
+ },
+ function (err) {
+ console.error(err);
+ alert("无效的存档");
+ }
+ );
+ }
+ return;
+};
control.prototype._doSL_reload = function (id, callback) {
- if (core.saves.autosave.data != null && core.saves.autosave.now < core.saves.autosave.data.length) {
- var data = core.saves.autosave.data.splice(core.saves.autosave.now, 1)[0];
- core.control.autosave(false);
- callback(id, data);
- }
- return;
-}
+ if (
+ core.saves.autosave.data != null &&
+ core.saves.autosave.now < core.saves.autosave.data.length
+ ) {
+ var data = core.saves.autosave.data.splice(core.saves.autosave.now, 1)[0];
+ core.control.autosave(false);
+ callback(id, data);
+ }
+ return;
+};
control.prototype._doSL_load_afterGet = function (id, data) {
- if (!data) return alert("无效的存档");
- var _replay = function () {
- core.startGame(data.hard, data.hero.flags.__seed__, core.decodeRoute(data.route));
- };
- if (data.version != core.firstData.version) {
- core.myconfirm("存档版本不匹配!\n你想回放此存档的录像吗?\n可以随时停止录像播放以继续游戏。", _replay);
- return;
+ if (!data) return alert("无效的存档");
+ var _replay = function () {
+ core.startGame(
+ data.hard,
+ data.hero.flags.__seed__,
+ core.decodeRoute(data.route)
+ );
+ };
+ if (data.version != core.firstData.version) {
+ core.myconfirm(
+ "存档版本不匹配!\n你想回放此存档的录像吗?\n可以随时停止录像播放以继续游戏。",
+ _replay
+ );
+ return;
+ }
+ if (data.hero.flags.__events__ && data.guid != core.getGuid()) {
+ core.myconfirm("此存档可能存在风险,你想要播放录像么?", _replay);
+ return;
+ }
+ core.ui.closePanel();
+ core.loadData(data, function () {
+ core.removeFlag("__fromLoad__");
+ core.drawTip("读档成功");
+ if (id != "autoSave") {
+ core.saves.saveIndex = id;
+ core.setLocalStorage("saveIndex", core.saves.saveIndex);
}
- if (data.hero.flags.__events__ && data.guid != core.getGuid()) {
- core.myconfirm("此存档可能存在风险,你想要播放录像么?", _replay);
- return;
- }
- core.ui.closePanel();
- core.loadData(data, function () {
- core.removeFlag('__fromLoad__');
- core.drawTip("读档成功");
- if (id != "autoSave") {
- core.saves.saveIndex = id;
- core.setLocalStorage('saveIndex', core.saves.saveIndex);
- }
- });
-}
+ });
+};
control.prototype._doSL_replayLoad_afterGet = function (id, data) {
- if (!data) {
- core.playSound('操作失败');
- return core.drawTip("无效的存档");
- }
- if (data.version != core.firstData.version) {
- core.playSound('操作失败');
- return core.drawTip("存档版本不匹配");
- }
- if (data.hero.flags.__events__ && data.guid != core.getGuid()) {
- core.playSound('操作失败');
- return core.drawTip("此存档可能存在风险,无法读档");
- }
- var route = core.subarray(core.status.route, core.decodeRoute(data.route));
- if (route == null) {
- core.playSound('操作失败');
- return core.drawTip("无法从此存档回放录像");
- }
- core.loadData(data, function () {
- core.removeFlag('__fromLoad__');
- core.startReplay(route);
- core.drawTip("回退到存档节点");
- });
-}
+ if (!data) {
+ core.playSound("操作失败");
+ return core.drawTip("无效的存档");
+ }
+ if (data.version != core.firstData.version) {
+ core.playSound("操作失败");
+ return core.drawTip("存档版本不匹配");
+ }
+ if (data.hero.flags.__events__ && data.guid != core.getGuid()) {
+ core.playSound("操作失败");
+ return core.drawTip("此存档可能存在风险,无法读档");
+ }
+ var route = core.subarray(core.status.route, core.decodeRoute(data.route));
+ if (route == null) {
+ core.playSound("操作失败");
+ return core.drawTip("无法从此存档回放录像");
+ }
+ core.loadData(data, function () {
+ core.removeFlag("__fromLoad__");
+ core.startReplay(route);
+ core.drawTip("回退到存档节点");
+ });
+};
control.prototype._doSL_replayRemain_afterGet = function (id, data) {
- if (!data) {
- core.playSound('操作失败');
- return core.drawTip("无效的存档");
- }
- var route = core.decodeRoute(data.route);
- if (core.status.tempRoute) {
- var remainRoute = core.subarray(route, core.status.tempRoute);
- if (remainRoute == null)
- return alert("无法接续播放录像!\n该存档必须是前一个选择的存档的后续内容。");
- delete core.status.tempRoute;
- core.ui.closePanel();
- core.startReplay(remainRoute);
- core.drawTip("接续播放录像");
- return;
- }
- else if (data.floorId != core.status.floorId || data.hero.loc.x != core.getHeroLoc('x') || data.hero.loc.y != core.getHeroLoc('y'))
- return alert("楼层或坐标不一致!");
-
- core.status.tempRoute = route;
+ if (!data) {
+ core.playSound("操作失败");
+ return core.drawTip("无效的存档");
+ }
+ var route = core.decodeRoute(data.route);
+ if (core.status.tempRoute) {
+ var remainRoute = core.subarray(route, core.status.tempRoute);
+ if (remainRoute == null)
+ return alert(
+ "无法接续播放录像!\n该存档必须是前一个选择的存档的后续内容。"
+ );
+ delete core.status.tempRoute;
core.ui.closePanel();
- core.drawText("\t[步骤2]请选择第二个存档。\n\r[yellow]该存档必须是前一个存档的后续。\r\n将尝试播放到此存档。", function () {
- core.status.event.id = 'replayRemain';
- core.lockControl();
- var saveIndex = core.saves.saveIndex;
- var page = parseInt((saveIndex - 1) / 5), offset = saveIndex - 5 * page;
- core.ui._drawSLPanel(10 * page + offset);
- });
-}
+ core.startReplay(remainRoute);
+ core.drawTip("接续播放录像");
+ return;
+ } else if (
+ data.floorId != core.status.floorId ||
+ data.hero.loc.x != core.getHeroLoc("x") ||
+ data.hero.loc.y != core.getHeroLoc("y")
+ )
+ return alert("楼层或坐标不一致!");
+
+ core.status.tempRoute = route;
+ core.ui.closePanel();
+ core.drawText(
+ "\t[步骤2]请选择第二个存档。\n\r[yellow]该存档必须是前一个存档的后续。\r\n将尝试播放到此存档。",
+ function () {
+ core.status.event.id = "replayRemain";
+ core.lockControl();
+ var saveIndex = core.saves.saveIndex;
+ var page = parseInt((saveIndex - 1) / 5),
+ offset = saveIndex - 5 * page;
+ core.ui._drawSLPanel(10 * page + offset);
+ }
+ );
+};
control.prototype._doSL_replaySince_afterGet = function (id, data) {
- if (data.floorId != core.status.floorId || data.hero.loc.x != core.getHeroLoc('x') || data.hero.loc.y != core.getHeroLoc('y'))
- return alert("楼层或坐标不一致!");
- if (!data.__toReplay__) return alert('该存档没有剩余录像!');
- core.ui.closePanel();
- core.startReplay(core.decodeRoute(data.__toReplay__));
- core.drawTip("播放存档剩余录像");
- return;
-}
+ if (
+ data.floorId != core.status.floorId ||
+ data.hero.loc.x != core.getHeroLoc("x") ||
+ data.hero.loc.y != core.getHeroLoc("y")
+ )
+ return alert("楼层或坐标不一致!");
+ if (!data.__toReplay__) return alert("该存档没有剩余录像!");
+ core.ui.closePanel();
+ core.startReplay(core.decodeRoute(data.__toReplay__));
+ core.drawTip("播放存档剩余录像");
+ return;
+};
////// 同步存档到服务器 //////
control.prototype.syncSave = function (type) {
- core.ui.drawWaiting("正在同步,请稍候...");
- var callback = function (saves) {
- core.control._syncSave_http(type, saves);
- }
- if (type == 'all') core.getAllSaves(callback);
- else core.getSave(core.saves.saveIndex, callback);
-}
+ core.ui.drawWaiting("正在同步,请稍候...");
+ var callback = function (saves) {
+ core.control._syncSave_http(type, saves);
+ };
+ if (type == "all") core.getAllSaves(callback);
+ else core.getSave(core.saves.saveIndex, callback);
+};
control.prototype._syncSave_http = function (type, saves) {
- if (!saves) return core.drawText("没有要同步的存档");
- var formData = new FormData();
- formData.append('type', 'save');
- formData.append('name', core.firstData.name);
- formData.append('data', LZString.compressToBase64(JSON.stringify(saves)));
- formData.append('shorten', '1');
+ if (!saves) return core.drawText("没有要同步的存档");
+ var formData = new FormData();
+ formData.append("type", "save");
+ formData.append("name", core.firstData.name);
+ formData.append("data", LZString.compressToBase64(JSON.stringify(saves)));
+ formData.append("shorten", "1");
- core.http("POST", "/games/sync.php", formData, function (data) {
- var response = JSON.parse(data);
- if (response.code < 0) {
- core.drawText("出错啦!\n无法同步存档到服务器。\n错误原因:" + response.msg);
- }
- else {
- core.drawText((type == 'all' ? "所有存档" : "存档" + core.saves.saveIndex) + "同步成功!\n\n您的存档编号+密码: \r[yellow]"
- + response.code + response.msg
- + "\r\n\n请牢记以上信息(如截图等),在从服务器\n同步存档时使用。\n\r[yellow]另外请注意,存档同步只会保存一个月的时间。\r")
- }
- }, function (e) {
- core.drawText("出错啦!\n无法同步存档到服务器。\n错误原因:" + e);
- })
-}
+ core.http(
+ "POST",
+ "/games/sync.php",
+ formData,
+ function (data) {
+ var response = JSON.parse(data);
+ if (response.code < 0) {
+ core.drawText(
+ "出错啦!\n无法同步存档到服务器。\n错误原因:" + response.msg
+ );
+ } else {
+ core.drawText(
+ (type == "all" ? "所有存档" : "存档" + core.saves.saveIndex) +
+ "同步成功!\n\n您的存档编号+密码: \r[yellow]" +
+ response.code +
+ response.msg +
+ "\r\n\n请牢记以上信息(如截图等),在从服务器\n同步存档时使用。\n\r[yellow]另外请注意,存档同步只会保存一个月的时间。\r"
+ );
+ }
+ },
+ function (e) {
+ core.drawText("出错啦!\n无法同步存档到服务器。\n错误原因:" + e);
+ }
+ );
+};
////// 从服务器加载存档 //////
control.prototype.syncLoad = function () {
- core.myprompt("请输入存档编号+密码", null, function (idpassword) {
- if (!idpassword) return core.ui._drawSyncSave();
- if (!/^\d{6}\w{4}$/.test(idpassword) && !/^\d{4}\w{3}$/.test(idpassword)) {
- core.drawText("不合法的存档编号+密码!");
- return;
- }
- core.ui.drawWaiting("正在同步,请稍候...");
- if (idpassword.length == 7) {
- core.control._syncLoad_http(idpassword.substring(0, 4), idpassword.substring(4));
- } else {
- core.control._syncLoad_http(idpassword.substring(0, 6), idpassword.substring(6));
- }
- });
-}
+ core.myprompt("请输入存档编号+密码", null, function (idpassword) {
+ if (!idpassword) return core.ui._drawSyncSave();
+ if (!/^\d{6}\w{4}$/.test(idpassword) && !/^\d{4}\w{3}$/.test(idpassword)) {
+ core.drawText("不合法的存档编号+密码!");
+ return;
+ }
+ core.ui.drawWaiting("正在同步,请稍候...");
+ if (idpassword.length == 7) {
+ core.control._syncLoad_http(
+ idpassword.substring(0, 4),
+ idpassword.substring(4)
+ );
+ } else {
+ core.control._syncLoad_http(
+ idpassword.substring(0, 6),
+ idpassword.substring(6)
+ );
+ }
+ });
+};
control.prototype._syncLoad_http = function (id, password) {
- var formData = new FormData();
- formData.append('type', 'load');
- formData.append('name', core.firstData.name);
- formData.append('id', id);
- formData.append('password', password);
+ var formData = new FormData();
+ formData.append("type", "load");
+ formData.append("name", core.firstData.name);
+ formData.append("id", id);
+ formData.append("password", password);
- core.http("POST", "/games/sync.php", formData, function (data) {
- var response = JSON.parse(data);
- if (response.code == 0) {
- var msg = null;
- try {
- msg = JSON.parse(LZString.decompressFromBase64(response.msg));
- } catch (e) { }
- if (!msg) {
- try {
- msg = JSON.parse(response.msg);
- } catch (e) { }
- }
- if (msg) {
- core.control._syncLoad_write(msg);
- } else {
- core.drawText("出错啦!\n存档解析失败!");
- }
+ core.http(
+ "POST",
+ "/games/sync.php",
+ formData,
+ function (data) {
+ var response = JSON.parse(data);
+ if (response.code == 0) {
+ var msg = null;
+ try {
+ msg = JSON.parse(LZString.decompressFromBase64(response.msg));
+ } catch (e) {}
+ if (!msg) {
+ try {
+ msg = JSON.parse(response.msg);
+ } catch (e) {}
}
- else {
- core.drawText("出错啦!\n无法从服务器同步存档。\n错误原因:" + response.msg);
+ if (msg) {
+ core.control._syncLoad_write(msg);
+ } else {
+ core.drawText("出错啦!\n存档解析失败!");
}
- }, function (e) {
- core.drawText("出错啦!\n无法从服务器同步存档。\n错误原因:" + e);
- });
-}
+ } else {
+ core.drawText(
+ "出错啦!\n无法从服务器同步存档。\n错误原因:" + response.msg
+ );
+ }
+ },
+ function (e) {
+ core.drawText("出错啦!\n无法从服务器同步存档。\n错误原因:" + e);
+ }
+ );
+};
control.prototype._syncLoad_write = function (data) {
- if (data instanceof Array) {
- core.status.event.selection = 1;
- core.ui.drawConfirmBox("所有本地存档都将被覆盖,确认?", function () {
- for (var i = 1; i <= 5 * (main.savePages || 30); i++) {
- if (i <= data.length)
- core.setLocalForage("save" + i, data[i - 1]);
- else if (core.saves.ids[i])
- core.removeLocalForage("save" + i);
- }
- core.ui.closePanel();
- core.drawText("同步成功!\n你的本地所有存档均已被覆盖。");
- }, function () {
- core.status.event.selection = 0;
- core.ui._drawSyncSave();
- });
- }
- else {
- // 只覆盖单存档
- core.setLocalForage("save" + core.saves.saveIndex, data, function () {
- core.drawText("同步成功!\n单存档已覆盖至存档" + core.saves.saveIndex);
- });
- }
-}
+ if (data instanceof Array) {
+ core.status.event.selection = 1;
+ core.ui.drawConfirmBox(
+ "所有本地存档都将被覆盖,确认?",
+ function () {
+ for (var i = 1; i <= 5 * (main.savePages || 30); i++) {
+ if (i <= data.length) core.setLocalForage("save" + i, data[i - 1]);
+ else if (core.saves.ids[i]) core.removeLocalForage("save" + i);
+ }
+ core.ui.closePanel();
+ core.drawText("同步成功!\n你的本地所有存档均已被覆盖。");
+ },
+ function () {
+ core.status.event.selection = 0;
+ core.ui._drawSyncSave();
+ }
+ );
+ } else {
+ // 只覆盖单存档
+ core.setLocalForage("save" + core.saves.saveIndex, data, function () {
+ core.drawText("同步成功!\n单存档已覆盖至存档" + core.saves.saveIndex);
+ });
+ }
+};
////// 存档到本地 //////
control.prototype.saveData = function () {
- return this.controldata.saveData();
-}
+ return this.controldata.saveData();
+};
////// 从本地读档 //////
control.prototype.loadData = function (data, callback) {
- return this.controldata.loadData(data, callback);
-}
+ return this.controldata.loadData(data, callback);
+};
control.prototype.getSave = function (index, callback) {
- if (index == 0) {
- // --- 自动存档先从缓存中获取
- if (core.saves.autosave.data != null)
- callback(core.saves.autosave.data);
- else {
- core.getLocalForage("autoSave", null, function (data) {
- if (data != null) {
- core.saves.autosave.data = data;
- if (!(core.saves.autosave.data instanceof Array)) {
- core.saves.autosave.data = [core.saves.autosave.data];
- }
- core.saves.autosave.now = core.saves.autosave.data.length;
- }
- callback(core.saves.autosave.data);
- }, function (err) {
- console.error(err);
- callback(null);
- });
+ if (index == 0) {
+ // --- 自动存档先从缓存中获取
+ if (core.saves.autosave.data != null) callback(core.saves.autosave.data);
+ else {
+ core.getLocalForage(
+ "autoSave",
+ null,
+ function (data) {
+ if (data != null) {
+ core.saves.autosave.data = data;
+ if (!(core.saves.autosave.data instanceof Array)) {
+ core.saves.autosave.data = [core.saves.autosave.data];
+ }
+ core.saves.autosave.now = core.saves.autosave.data.length;
+ }
+ callback(core.saves.autosave.data);
+ },
+ function (err) {
+ console.error(err);
+ callback(null);
}
- return;
+ );
}
- core.getLocalForage("save" + index, null, function (data) {
- if (callback) callback(data);
- }, function (err) {
- console.error(err);
- if (callback) callback(null);
- });
-}
+ return;
+ }
+ core.getLocalForage(
+ "save" + index,
+ null,
+ function (data) {
+ if (callback) callback(data);
+ },
+ function (err) {
+ console.error(err);
+ if (callback) callback(null);
+ }
+ );
+};
control.prototype.getSaves = function (ids, callback) {
- if (!(ids instanceof Array)) return this.getSave(ids, callback);
- var count = ids.length, data = {};
- for (var i = 0; i < ids.length; ++i) {
- (function (i) {
- core.getSave(ids[i], function (result) {
- data[i] = result;
- if (Object.keys(data).length == count)
- callback(data);
- })
- })(i);
- }
-}
+ if (!(ids instanceof Array)) return this.getSave(ids, callback);
+ var count = ids.length,
+ data = {};
+ for (var i = 0; i < ids.length; ++i) {
+ (function (i) {
+ core.getSave(ids[i], function (result) {
+ data[i] = result;
+ if (Object.keys(data).length == count) callback(data);
+ });
+ })(i);
+ }
+};
control.prototype.getAllSaves = function (callback) {
- var ids = Object.keys(core.saves.ids).filter(function (x) { return x != 0; })
- .sort(function (a, b) { return a - b; }), saves = [];
- this.getSaves(ids, function (data) {
- for (var i = 0; i < ids.length; ++i) {
- if (data[i] != null)
- saves.push(data[i]);
- }
- callback(saves);
- });
-}
+ var ids = Object.keys(core.saves.ids)
+ .filter(function (x) {
+ return x != 0;
+ })
+ .sort(function (a, b) {
+ return a - b;
+ }),
+ saves = [];
+ this.getSaves(ids, function (data) {
+ for (var i = 0; i < ids.length; ++i) {
+ if (data[i] != null) saves.push(data[i]);
+ }
+ callback(saves);
+ });
+};
////// 获得所有存在存档的存档位 //////
control.prototype.getSaveIndexes = function (callback) {
- var indexes = {};
- core.keysLocalForage(function (err, keys) {
- if (err) {
- console.error(err);
- return callback(indexes);
- }
- keys.forEach(function (key) {
- core.control._getSaveIndexes_getIndex(indexes, key);
- });
- callback(indexes);
+ var indexes = {};
+ core.keysLocalForage(function (err, keys) {
+ if (err) {
+ console.error(err);
+ return callback(indexes);
+ }
+ keys.forEach(function (key) {
+ core.control._getSaveIndexes_getIndex(indexes, key);
});
-}
+ callback(indexes);
+ });
+};
control.prototype._getSaveIndexes_getIndex = function (indexes, name) {
- var e = new RegExp('^' + core.firstData.name + "_(save\\d+|autoSave)$").exec(name);
- if (e) {
- if (e[1] == 'autoSave') indexes[0] = true;
- else indexes[parseInt(e[1].substring(4))] = true;
- }
-}
+ var e = new RegExp("^" + core.firstData.name + "_(save\\d+|autoSave)$").exec(
+ name
+ );
+ if (e) {
+ if (e[1] == "autoSave") indexes[0] = true;
+ else indexes[parseInt(e[1].substring(4))] = true;
+ }
+};
////// 判断某个存档位是否存在存档 //////
control.prototype.hasSave = function (index) {
- return core.saves.ids[index] || false;
-}
+ return core.saves.ids[index] || false;
+};
////// 删除某个存档
control.prototype.removeSave = function (index, callback) {
- if (index == 0 || index == "autoSave") {
- index = "autoSave";
- core.removeLocalForage(index, function () {
- core.saves.autosave.data = null;
- core.saves.autosave.updated = false;
- if (callback) callback();
- });
- return;
- }
- core.removeLocalForage("save" + index, function () {
- core.saves.favorite = core.saves.favorite.filter(function (i) { return core.hasSave(i); });
- delete core.saves.favoriteName[index];
- core.control._updateFavoriteSaves();
- if (callback) callback();
- }, function () {
- core.playSound('操作失败');
- core.drawTip("无法删除存档!");
- if (callback) callback();
+ if (index == 0 || index == "autoSave") {
+ index = "autoSave";
+ core.removeLocalForage(index, function () {
+ core.saves.autosave.data = null;
+ core.saves.autosave.updated = false;
+ if (callback) callback();
});
-}
+ return;
+ }
+ core.removeLocalForage(
+ "save" + index,
+ function () {
+ core.saves.favorite = core.saves.favorite.filter(function (i) {
+ return core.hasSave(i);
+ });
+ delete core.saves.favoriteName[index];
+ core.control._updateFavoriteSaves();
+ if (callback) callback();
+ },
+ function () {
+ core.playSound("操作失败");
+ core.drawTip("无法删除存档!");
+ if (callback) callback();
+ }
+ );
+};
////// 读取收藏信息
control.prototype._loadFavoriteSaves = function () {
- core.saves.favorite = core.getLocalStorage("favorite", []);
- // --- 移除不存在的收藏
- core.saves.favorite = core.saves.favorite.filter(function (i) { return core.hasSave(i); });
- core.saves.favoriteName = core.getLocalStorage("favoriteName", {});
-}
+ core.saves.favorite = core.getLocalStorage("favorite", []);
+ // --- 移除不存在的收藏
+ core.saves.favorite = core.saves.favorite.filter(function (i) {
+ return core.hasSave(i);
+ });
+ core.saves.favoriteName = core.getLocalStorage("favoriteName", {});
+};
control.prototype._updateFavoriteSaves = function () {
- core.setLocalStorage("favorite", core.saves.favorite);
- core.setLocalStorage("favoriteName", core.saves.favoriteName);
-}
+ core.setLocalStorage("favorite", core.saves.favorite);
+ core.setLocalStorage("favoriteName", core.saves.favoriteName);
+};
// ------ 属性,状态,位置,buff,变量,锁定控制等 ------ //
////// 设置勇士属性 //////
control.prototype.setStatus = function (name, value) {
- if (!core.status.hero) return;
- if (name == 'x' || name == 'y' || name == 'direction')
- this.setHeroLoc(name, value);
- else
- core.status.hero[name] = value;
-}
+ if (!core.status.hero) return;
+ if (name == "x" || name == "y" || name == "direction")
+ this.setHeroLoc(name, value);
+ else core.status.hero[name] = value;
+};
////// 增减勇士属性 //////
control.prototype.addStatus = function (name, value) {
- this.setStatus(name, this.getStatus(name) + value);
-}
+ this.setStatus(name, this.getStatus(name) + value);
+};
////// 获得勇士属性 //////
control.prototype.getStatus = function (name) {
- if (!core.status.hero) return null;
- if (name == 'x' || name == 'y' || name == 'direction')
- return this.getHeroLoc(name);
- if (main.mode == 'editor' && !core.hasFlag('__statistics__')) {
- return data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.firstData.hero[name];
- }
- return core.status.hero[name];
-}
+ if (!core.status.hero) return null;
+ if (name == "x" || name == "y" || name == "direction")
+ return this.getHeroLoc(name);
+ if (main.mode == "editor" && !core.hasFlag("__statistics__")) {
+ return data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.firstData.hero[name];
+ }
+ return core.status.hero[name];
+};
////// 从status中获得属性,如果不存在则从勇士属性中获取 //////
control.prototype.getStatusOrDefault = function (status, name) {
- if (status && name in status)
- return Math.floor(status[name]);
- return Math.floor(this.getStatus(name));
-}
+ if (status && name in status) return Math.floor(status[name]);
+ return Math.floor(this.getStatus(name));
+};
////// 获得勇士实际属性(增幅后的) //////
control.prototype.getRealStatus = function (name) {
- return this.getRealStatusOrDefault(null, name);
-}
+ return this.getRealStatusOrDefault(null, name);
+};
////// 从status中获得实际属性(增幅后的),如果不存在则从勇士属性中获取 //////
control.prototype.getRealStatusOrDefault = function (status, name) {
- return Math.floor(this.getStatusOrDefault(status, name) * this.getBuff(name));
-}
+ return Math.floor(this.getStatusOrDefault(status, name) * this.getBuff(name));
+};
////// 获得勇士原始属性(无装备和衰弱影响) //////
control.prototype.getNakedStatus = function (name) {
- var value = this.getStatus(name);
- if (value == null) return value;
- // 装备增幅
- core.status.hero.equipment.forEach(function (v) {
- if (!v || !(core.material.items[v] || {}).equip) return;
- value -= core.material.items[v].equip.value[name] || 0;
- });
- // 衰弱扣除
- if (core.hasFlag('weak') && core.values.weakValue >= 1 && (name == 'atk' || name == 'def')) {
- value += core.values.weakValue;
- }
- return value;
-}
+ var value = this.getStatus(name);
+ if (value == null) return value;
+ // 装备增幅
+ core.status.hero.equipment.forEach(function (v) {
+ if (!v || !(core.material.items[v] || {}).equip) return;
+ value -= core.material.items[v].equip.value[name] || 0;
+ });
+ // 衰弱扣除
+ if (
+ core.hasFlag("weak") &&
+ core.values.weakValue >= 1 &&
+ (name == "atk" || name == "def")
+ ) {
+ value += core.values.weakValue;
+ }
+ return value;
+};
////// 获得某个属性的名字 //////
control.prototype.getStatusLabel = function (name) {
- if (this.controldata.getStatusLabel) {
- return this.controldata.getStatusLabel(name) || name;
- }
- return {
- name: "名称", lv: "等级", hpmax: "生命上限", hp: "生命", manamax: "魔力上限", mana: "魔力",
- atk: "攻击", def: "防御", mdef: "护盾", money: "金币", exp: "经验", point: "加点", steps: "步数"
- }[name] || name;
-}
+ if (this.controldata.getStatusLabel) {
+ return this.controldata.getStatusLabel(name) || name;
+ }
+ return (
+ {
+ name: "名称",
+ lv: "等级",
+ hpmax: "生命上限",
+ hp: "生命",
+ manamax: "魔力上限",
+ mana: "魔力",
+ atk: "攻击",
+ def: "防御",
+ mdef: "护盾",
+ money: "金币",
+ exp: "经验",
+ point: "加点",
+ steps: "步数",
+ }[name] || name
+ );
+};
////// 设置某个属性的增幅值 //////
control.prototype.setBuff = function (name, value) {
- // 仅保留三位有效buff值
- value = parseFloat(value.toFixed(3));
- this.setFlag('__' + name + '_buff__', value);
-}
+ // 仅保留三位有效buff值
+ value = parseFloat(value.toFixed(3));
+ this.setFlag("__" + name + "_buff__", value);
+};
////// 加减某个属性的增幅值 //////
control.prototype.addBuff = function (name, value) {
- var buff = this.getBuff(name) + value;
- // 仅保留三位有效buff值
- buff = parseFloat(buff.toFixed(3));
- this.setFlag('__' + name + '_buff__', buff);
-}
+ var buff = this.getBuff(name) + value;
+ // 仅保留三位有效buff值
+ buff = parseFloat(buff.toFixed(3));
+ this.setFlag("__" + name + "_buff__", buff);
+};
////// 获得某个属性的增幅值 //////
control.prototype.getBuff = function (name) {
- return core.getFlag('__' + name + '_buff__', 1);
-}
+ return core.getFlag("__" + name + "_buff__", 1);
+};
////// 获得或移除毒衰咒效果 //////
control.prototype.triggerDebuff = function (action, type) {
- return this.controldata.triggerDebuff(action, type);
-}
+ return this.controldata.triggerDebuff(action, type);
+};
////// 设置勇士的位置 //////
control.prototype.setHeroLoc = function (name, value, noGather) {
- if (!core.status.hero) return;
- core.status.hero.loc[name] = value;
- if ((name == 'x' || name == 'y') && !noGather) {
- this.gatherFollowers();
- }
- core.ui.drawStatusBar();
-}
+ if (!core.status.hero) return;
+ core.status.hero.loc[name] = value;
+ if ((name == "x" || name == "y") && !noGather) {
+ this.gatherFollowers();
+ }
+ core.ui.drawStatusBar();
+};
////// 获得勇士的位置 //////
control.prototype.getHeroLoc = function (name) {
- if (!core.status.hero) return;
- if (main.mode == 'editor') {
- if (name == null) return data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.firstData.hero.loc;
- return data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.firstData.hero.loc[name];
- }
- if (name == null) return core.status.hero.loc;
- return core.status.hero.loc[name];
-}
+ if (!core.status.hero) return;
+ if (main.mode == "editor") {
+ if (name == null)
+ return data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.firstData.hero.loc;
+ return data_a1e2fb4a_e986_4524_b0da_9b7ba7c0874d.firstData.hero.loc[name];
+ }
+ if (name == null) return core.status.hero.loc;
+ return core.status.hero.loc[name];
+};
////// 获得某个等级的名称 //////
control.prototype.getLvName = function (lv) {
- if (!core.status.hero) return null;
- if (lv == null) lv = core.status.hero.lv;
- return ((core.firstData.levelUp || [])[lv - 1] || {}).title || lv;
-}
+ if (!core.status.hero) return null;
+ if (lv == null) lv = core.status.hero.lv;
+ return ((core.firstData.levelUp || [])[lv - 1] || {}).title || lv;
+};
////// 获得下个等级所需经验;如果不存在下个等级,返回null。 //////
control.prototype.getNextLvUpNeed = function () {
- if (!core.status.hero) return null;
- if (core.status.hero.lv >= core.firstData.levelUp.length) return null;
- var need = core.calValue(core.firstData.levelUp[core.status.hero.lv].need);
- if (core.flags.statusBarItems.indexOf('levelUpLeftMode') >= 0)
- return Math.max(need - core.getStatus('exp'), 0);
- else return need;
-}
+ if (!core.status.hero) return null;
+ if (core.status.hero.lv >= core.firstData.levelUp.length) return null;
+ var need = core.calValue(core.firstData.levelUp[core.status.hero.lv].need);
+ if (core.flags.statusBarItems.indexOf("levelUpLeftMode") >= 0)
+ return Math.max(need - core.getStatus("exp"), 0);
+ else return need;
+};
////// 设置某个自定义变量或flag //////
control.prototype.setFlag = function (name, value) {
- if (value == null) return this.removeFlag(name);
- if (!core.status.hero) return;
- core.status.hero.flags[name] = value;
-}
+ if (value == null) return this.removeFlag(name);
+ if (!core.status.hero) return;
+ core.status.hero.flags[name] = value;
+};
////// 增加某个flag数值 //////
control.prototype.addFlag = function (name, value) {
- if (!core.status.hero) return;
- core.setFlag(name, core.getFlag(name, 0) + value);
-}
+ if (!core.status.hero) return;
+ core.setFlag(name, core.getFlag(name, 0) + value);
+};
////// 获得某个自定义变量或flag //////
control.prototype.getFlag = function (name, defaultValue) {
- if (!core.status.hero) return defaultValue;
- var value = core.status.hero.flags[name];
- return value != null ? value : defaultValue;
-}
+ if (!core.status.hero) return defaultValue;
+ var value = core.status.hero.flags[name];
+ return value != null ? value : defaultValue;
+};
////// 是否存在某个自定义变量或flag,且值为true //////
control.prototype.hasFlag = function (name) {
- return !!core.getFlag(name);
-}
+ return !!core.getFlag(name);
+};
////// 删除某个自定义变量或flag //////
control.prototype.removeFlag = function (name) {
- if (!core.status.hero) return;
- delete core.status.hero.flags[name];
-}
+ if (!core.status.hero) return;
+ delete core.status.hero.flags[name];
+};
////// 获得某个点的独立开关 //////
control.prototype.getSwitch = function (x, y, floorId, name, defaultValue) {
- var prefix = [floorId || core.status.floorId || ":f", x != null ? x : "x", y != null ? y : "y"].join("@");
- return this.getFlag(prefix + "@" + name, defaultValue);
-}
+ var prefix = [
+ floorId || core.status.floorId || ":f",
+ x != null ? x : "x",
+ y != null ? y : "y",
+ ].join("@");
+ return this.getFlag(prefix + "@" + name, defaultValue);
+};
////// 设置某个点的独立开关 //////
control.prototype.setSwitch = function (x, y, floorId, name, value) {
- var prefix = [floorId || core.status.floorId || ":f", x != null ? x : "x", y != null ? y : "y"].join("@");
- return this.setFlag(prefix + "@" + name, value);
-}
+ var prefix = [
+ floorId || core.status.floorId || ":f",
+ x != null ? x : "x",
+ y != null ? y : "y",
+ ].join("@");
+ return this.setFlag(prefix + "@" + name, value);
+};
////// 增加某个点的独立开关 //////
control.prototype.addSwitch = function (x, y, floorId, name, value) {
- var prefix = [floorId || core.status.floorId || ":f", x != null ? x : "x", y != null ? y : "y"].join("@");
- return this.addFlag(prefix + "@" + name, value);
-}
+ var prefix = [
+ floorId || core.status.floorId || ":f",
+ x != null ? x : "x",
+ y != null ? y : "y",
+ ].join("@");
+ return this.addFlag(prefix + "@" + name, value);
+};
////// 判定某个点的独立开关 //////
control.prototype.hasSwitch = function (x, y, floorId, name) {
- var prefix = [floorId || core.status.floorId || ":f", x != null ? x : "x", y != null ? y : "y"].join("@");
- return this.hasFlag(prefix + "@" + name);
-}
+ var prefix = [
+ floorId || core.status.floorId || ":f",
+ x != null ? x : "x",
+ y != null ? y : "y",
+ ].join("@");
+ return this.hasFlag(prefix + "@" + name);
+};
////// 删除某个点的独立开关 //////
control.prototype.removeSwitch = function (x, y, floorId, name) {
- var prefix = [floorId || core.status.floorId || ":f", x != null ? x : "x", y != null ? y : "y"].join("@");
- return this.removeFlag(prefix + "@" + name);
-}
+ var prefix = [
+ floorId || core.status.floorId || ":f",
+ x != null ? x : "x",
+ y != null ? y : "y",
+ ].join("@");
+ return this.removeFlag(prefix + "@" + name);
+};
////// 锁定状态栏,常常用于事件处理 //////
control.prototype.lockControl = function () {
- core.status.lockControl = true;
-}
+ core.status.lockControl = true;
+};
////// 解锁状态栏 //////
control.prototype.unlockControl = function () {
- core.status.lockControl = false;
-}
+ core.status.lockControl = false;
+};
////// 开启debug模式 //////
control.prototype.debug = function () {
- core.setFlag('debug', true);
- core.drawText("\t[调试模式开启]此模式下按住Ctrl键(或Ctrl+Shift键)可以穿墙并忽略一切事件。\n此模式下将无法上传成绩。");
-}
+ core.setFlag("debug", true);
+ core.drawText(
+ "\t[调试模式开启]此模式下按住Ctrl键(或Ctrl+Shift键)可以穿墙并忽略一切事件。\n此模式下将无法上传成绩。"
+ );
+};
control.prototype._bindRoutePush = function () {
- core.status.route.push = function (element) {
- // 忽视移动、转向、瞬移
- if (["up", "down", "left", "right", "turn"].indexOf(element) < 0 && !element.startsWith("move:")) {
- core.clearRouteFolding();
- }
- Array.prototype.push.call(core.status.route, element);
+ core.status.route.push = function (element) {
+ // 忽视移动、转向、瞬移
+ if (
+ ["up", "down", "left", "right", "turn"].indexOf(element) < 0 &&
+ !element.startsWith("move:")
+ ) {
+ core.clearRouteFolding();
}
-}
+ Array.prototype.push.call(core.status.route, element);
+ };
+};
////// 清除录像折叠信息 //////
control.prototype.clearRouteFolding = function () {
- core.status.routeFolding = {};
-}
+ core.status.routeFolding = {};
+};
////// 检查录像折叠 //////
control.prototype.checkRouteFolding = function () {
- // 未开启、未开始游戏、录像播放中、正在事件中:不执行
- if (!core.flags.enableRouteFolding || !core.isPlaying() || core.isReplaying() || core.status.event.id) {
- return this.clearRouteFolding();
+ // 未开启、未开始游戏、录像播放中、正在事件中:不执行
+ if (
+ !core.flags.enableRouteFolding ||
+ !core.isPlaying() ||
+ core.isReplaying() ||
+ core.status.event.id
+ ) {
+ return this.clearRouteFolding();
+ }
+ var hero = core.clone(core.status.hero, function (name, value) {
+ return name != "steps" && typeof value == "number";
+ });
+ var index = [
+ core.getHeroLoc("x"),
+ core.getHeroLoc("y"),
+ core.getHeroLoc("direction").charAt(0),
+ ].join(",");
+ core.status.routeFolding = core.status.routeFolding || {};
+ if (core.status.routeFolding[index]) {
+ var one = core.status.routeFolding[index];
+ if (core.same(one.hero, hero) && one.length < core.status.route.length) {
+ Object.keys(core.status.routeFolding).forEach(function (v) {
+ if (core.status.routeFolding[v].length >= one.length)
+ delete core.status.routeFolding[v];
+ });
+ core.status.route = core.status.route.slice(0, one.length);
+ this._bindRoutePush();
}
- var hero = core.clone(core.status.hero, function (name, value) {
- return name != 'steps' && typeof value == 'number';
- });
- var index = [core.getHeroLoc('x'), core.getHeroLoc('y'), core.getHeroLoc('direction').charAt(0)].join(',');
- core.status.routeFolding = core.status.routeFolding || {};
- if (core.status.routeFolding[index]) {
- var one = core.status.routeFolding[index];
- if (core.same(one.hero, hero) && one.length < core.status.route.length) {
- Object.keys(core.status.routeFolding).forEach(function (v) {
- if (core.status.routeFolding[v].length >= one.length) delete core.status.routeFolding[v];
- });
- core.status.route = core.status.route.slice(0, one.length);
- this._bindRoutePush();
- }
- }
- core.status.routeFolding[index] = { hero: hero, length: core.status.route.length };
-}
+ }
+ core.status.routeFolding[index] = {
+ hero: hero,
+ length: core.status.route.length,
+ };
+};
// ------ 天气,色调,BGM ------ //
control.prototype.getMappedName = function (name) {
- return core.getFlag('__nameMap__', {})[name] || (main.nameMap || {})[name] || name;
-}
+ return (
+ core.getFlag("__nameMap__", {})[name] || (main.nameMap || {})[name] || name
+ );
+};
////// 更改天气效果 //////
control.prototype.setWeather = function (type, level) {
- // 非雨雪
- if (type == null || !this.weathers[type]) {
- core.deleteCanvas('weather')
- core.animateFrame.weather.type = null;
- core.animateFrame.weather.nodes = [];
- return;
- }
- if (level == null) level = core.animateFrame.weather.level;
- level = core.clamp(parseInt(level) || 5, 1, 10);
- // 当前天气:则忽略
- if (type == core.animateFrame.weather.type && level == core.animateFrame.weather.level) return;
-
- // 计算当前的宽高
- core.createCanvas('weather', 0, 0, core._PX_, core._PY_, 80);
- core.setOpacity('weather', 1.0);
- core.animateFrame.weather.type = type;
- core.animateFrame.weather.level = level;
+ // 非雨雪
+ if (type == null || !this.weathers[type]) {
+ core.deleteCanvas("weather");
+ core.animateFrame.weather.type = null;
core.animateFrame.weather.nodes = [];
- try {
- core.doFunc(this.weathers[type].initFunc, this, level);
- } catch (e) {
- console.error(e);
- console.error("ERROR in weather[" + type + "]:已自动注销该项。");
- core.unregisterWeather(type);
- }
-}
+ return;
+ }
+ if (level == null) level = core.animateFrame.weather.level;
+ level = core.clamp(parseInt(level) || 5, 1, 10);
+ // 当前天气:则忽略
+ if (
+ type == core.animateFrame.weather.type &&
+ level == core.animateFrame.weather.level
+ )
+ return;
+
+ // 计算当前的宽高
+ core.createCanvas("weather", 0, 0, core._PX_, core._PY_, 80);
+ core.setOpacity("weather", 1.0);
+ core.animateFrame.weather.type = type;
+ core.animateFrame.weather.level = level;
+ core.animateFrame.weather.nodes = [];
+ try {
+ core.doFunc(this.weathers[type].initFunc, this, level);
+ } catch (e) {
+ console.error(e);
+ console.error("ERROR in weather[" + type + "]:已自动注销该项。");
+ core.unregisterWeather(type);
+ }
+};
////// 注册一个天气 //////
// name为天气类型,如 sun, rain, snow 等
// initFunc 为设置为此天气时的初始化,接受level参数
// frameFunc 为该天气下每帧的效果,接受和timestamp参数(从页面加载完毕到当前经过的时间)
control.prototype.registerWeather = function (name, initFunc, frameFunc) {
- this.unregisterWeather(name);
- this.weathers[name] = { initFunc: initFunc, frameFunc: frameFunc };
-}
+ this.unregisterWeather(name);
+ this.weathers[name] = { initFunc: initFunc, frameFunc: frameFunc };
+};
////// 取消注册一个天气 //////
control.prototype.unregisterWeather = function (name) {
- delete this.weathers[name];
- if (core.animateFrame.weather.type == name) {
- this.setWeather(null);
- }
-}
+ delete this.weathers[name];
+ if (core.animateFrame.weather.type == name) {
+ this.setWeather(null);
+ }
+};
control.prototype._weather_rain = function (level) {
- var number = level * parseInt(20 * core.bigmap.width * core.bigmap.height / (core._WIDTH_ * core._HEIGHT_));
- for (var a = 0; a < number; a++) {
- core.animateFrame.weather.nodes.push({
- 'x': Math.random() * core.bigmap.width * 32,
- 'y': Math.random() * core.bigmap.height * 32,
- 'l': Math.random() * 2.5,
- 'xs': -4 + Math.random() * 4 + 2,
- 'ys': Math.random() * 10 + 10
- })
- }
-}
+ var number =
+ level *
+ parseInt(
+ (20 * core.bigmap.width * core.bigmap.height) /
+ (core._WIDTH_ * core._HEIGHT_)
+ );
+ for (var a = 0; a < number; a++) {
+ core.animateFrame.weather.nodes.push({
+ x: Math.random() * core.bigmap.width * 32,
+ y: Math.random() * core.bigmap.height * 32,
+ l: Math.random() * 2.5,
+ xs: -4 + Math.random() * 4 + 2,
+ ys: Math.random() * 10 + 10,
+ });
+ }
+};
control.prototype._weather_snow = function (level) {
- var number = level * parseInt(20 * core.bigmap.width * core.bigmap.height / (core._WIDTH_ * core._HEIGHT_));
- for (var a = 0; a < number; a++) {
- core.animateFrame.weather.nodes.push({
- 'x': Math.random() * core.bigmap.width * 32,
- 'y': Math.random() * core.bigmap.height * 32,
- 'r': Math.random() * 5 + 1,
- 'd': Math.random() * Math.min(level, 200),
- })
- }
-}
+ var number =
+ level *
+ parseInt(
+ (20 * core.bigmap.width * core.bigmap.height) /
+ (core._WIDTH_ * core._HEIGHT_)
+ );
+ for (var a = 0; a < number; a++) {
+ core.animateFrame.weather.nodes.push({
+ x: Math.random() * core.bigmap.width * 32,
+ y: Math.random() * core.bigmap.height * 32,
+ r: Math.random() * 5 + 1,
+ d: Math.random() * Math.min(level, 200),
+ });
+ }
+};
control.prototype._weather_fog = function (level) {
- if (!core.animateFrame.weather.fog) return;
- core.animateFrame.weather.nodes = [{
- 'image': core.animateFrame.weather.fog,
- 'level': 40 * level,
- 'x': 0,
- 'y': -core._PY_ / 2,
- 'dx': -Math.random() * 1.5,
- 'dy': Math.random(),
- 'delta': 0.001,
- }];
-}
+ if (!core.animateFrame.weather.fog) return;
+ core.animateFrame.weather.nodes = [
+ {
+ image: core.animateFrame.weather.fog,
+ level: 40 * level,
+ x: 0,
+ y: -core._PY_ / 2,
+ dx: -Math.random() * 1.5,
+ dy: Math.random(),
+ delta: 0.001,
+ },
+ ];
+};
control.prototype._weather_cloud = function (level) {
- if (!core.animateFrame.weather.cloud) return;
- core.animateFrame.weather.nodes = [{
- 'image': core.animateFrame.weather.cloud,
- 'level': 40 * level,
- 'x': 0,
- 'y': -core._PY_ / 2,
- 'dx': -Math.random() * 1.5,
- 'dy': Math.random(),
- 'delta': 0.001,
- }];
-}
+ if (!core.animateFrame.weather.cloud) return;
+ core.animateFrame.weather.nodes = [
+ {
+ image: core.animateFrame.weather.cloud,
+ level: 40 * level,
+ x: 0,
+ y: -core._PY_ / 2,
+ dx: -Math.random() * 1.5,
+ dy: Math.random(),
+ delta: 0.001,
+ },
+ ];
+};
control.prototype._weather_sun = function (level) {
- if (!core.animateFrame.weather.sun) return;
- // 直接绘制
- core.clearMap('weather');
- core.drawImage(
- 'weather', core.animateFrame.weather.sun, 0, 0, core.animateFrame.weather.sun.width, core.animateFrame.weather.sun.height, 0, 0, core._PX_, core._PY_
- );
- core.setOpacity('weather', level / 10);
- core.animateFrame.weather.nodes = [{ opacity: level / 10, delta: 0.01 }];
-}
+ if (!core.animateFrame.weather.sun) return;
+ // 直接绘制
+ core.clearMap("weather");
+ core.drawImage(
+ "weather",
+ core.animateFrame.weather.sun,
+ 0,
+ 0,
+ core.animateFrame.weather.sun.width,
+ core.animateFrame.weather.sun.height,
+ 0,
+ 0,
+ core._PX_,
+ core._PY_
+ );
+ core.setOpacity("weather", level / 10);
+ core.animateFrame.weather.nodes = [{ opacity: level / 10, delta: 0.01 }];
+};
////// 更改画面色调 //////
control.prototype.setCurtain = function (color, time, moveMode, callback) {
- if (time == null) time = 750;
- if (time <= 0) time = 0;
- if (!core.status.curtainColor)
- core.status.curtainColor = [0, 0, 0, 0];
- if (!color) color = [0, 0, 0, 0];
- if (color[3] == null) color[3] = 1;
- color[3] = core.clamp(color[3], 0, 1);
+ if (time == null) time = 750;
+ if (time <= 0) time = 0;
+ if (!core.status.curtainColor) core.status.curtainColor = [0, 0, 0, 0];
+ if (!color) color = [0, 0, 0, 0];
+ if (color[3] == null) color[3] = 1;
+ color[3] = core.clamp(color[3], 0, 1);
- if (time == 0) {
- // 直接变色
- core.clearMap('curtain');
- core.fillRect('curtain', 0, 0, core._PX_, core._PY_, core.arrayToRGBA(color));
- core.status.curtainColor = color;
- if (callback) callback();
- return;
+ if (time == 0) {
+ // 直接变色
+ core.clearMap("curtain");
+ core.fillRect(
+ "curtain",
+ 0,
+ 0,
+ core._PX_,
+ core._PY_,
+ core.arrayToRGBA(color)
+ );
+ core.status.curtainColor = color;
+ if (callback) callback();
+ return;
+ }
+
+ this._setCurtain_animate(
+ core.status.curtainColor,
+ color,
+ time,
+ moveMode,
+ callback
+ );
+};
+
+control.prototype._setCurtain_animate = function (
+ nowColor,
+ color,
+ time,
+ moveMode,
+ callback
+) {
+ time /= Math.max(core.status.replay.speed, 1);
+ var per_time = 10,
+ step = 0,
+ steps = parseInt(time / per_time);
+ if (steps <= 0) steps = 1;
+ var curr = nowColor;
+ var moveFunc = core.applyEasing(moveMode);
+
+ var cb = function () {
+ core.status.curtainColor = curr;
+ if (callback) callback();
+ };
+ var animate = setInterval(function () {
+ step++;
+ curr = [
+ nowColor[0] + (color[0] - nowColor[0]) * moveFunc(step / steps),
+ nowColor[1] + (color[1] - nowColor[1]) * moveFunc(step / steps),
+ nowColor[2] + (color[2] - nowColor[2]) * moveFunc(step / steps),
+ nowColor[3] + (color[3] - nowColor[3]) * moveFunc(step / steps),
+ ];
+ core.clearMap("curtain");
+ core.fillRect(
+ "curtain",
+ 0,
+ 0,
+ core._PX_,
+ core._PY_,
+ core.arrayToRGBA(curr)
+ );
+ if (step == steps) {
+ delete core.animateFrame.asyncId[animate];
+ clearInterval(animate);
+ cb();
}
+ }, per_time);
- this._setCurtain_animate(core.status.curtainColor, color, time, moveMode, callback);
-}
-
-control.prototype._setCurtain_animate = function (nowColor, color, time, moveMode, callback) {
- time /= Math.max(core.status.replay.speed, 1)
- var per_time = 10, step = 0, steps = parseInt(time / per_time);
- if (steps <= 0) steps = 1;
- var curr = nowColor;
- var moveFunc = core.applyEasing(moveMode);
-
- var cb = function () {
- core.status.curtainColor = curr;
- if (callback) callback();
- }
- var animate = setInterval(function () {
- step++;
- curr = [
- nowColor[0] + (color[0] - nowColor[0]) * moveFunc(step / steps),
- nowColor[1] + (color[1] - nowColor[1]) * moveFunc(step / steps),
- nowColor[2] + (color[2] - nowColor[2]) * moveFunc(step / steps),
- nowColor[3] + (color[3] - nowColor[3]) * moveFunc(step / steps),
- ]
- core.clearMap('curtain');
- core.fillRect('curtain', 0, 0, core._PX_, core._PY_, core.arrayToRGBA(curr));
- if (step == steps) {
- delete core.animateFrame.asyncId[animate];
- clearInterval(animate);
- cb();
- }
- }, per_time);
-
- core.animateFrame.lastAsyncId = animate;
- core.animateFrame.asyncId[animate] = cb;
-}
+ core.animateFrame.lastAsyncId = animate;
+ core.animateFrame.asyncId[animate] = cb;
+};
////// 画面闪烁 //////
-control.prototype.screenFlash = function (color, time, times, moveMode, callback) {
- times = times || 1;
- time = time / 3;
- var nowColor = core.clone(core.status.curtainColor);
- core.setCurtain(color, time, moveMode, function () {
- core.setCurtain(nowColor, time * 2, moveMode, function () {
- if (times > 1)
- core.screenFlash(color, time * 3, times - 1, moveMode, callback);
- else {
- if (callback) callback();
- }
- });
+control.prototype.screenFlash = function (
+ color,
+ time,
+ times,
+ moveMode,
+ callback
+) {
+ times = times || 1;
+ time = time / 3;
+ var nowColor = core.clone(core.status.curtainColor);
+ core.setCurtain(color, time, moveMode, function () {
+ core.setCurtain(nowColor, time * 2, moveMode, function () {
+ if (times > 1)
+ core.screenFlash(color, time * 3, times - 1, moveMode, callback);
+ else {
+ if (callback) callback();
+ }
});
-}
+ });
+};
////// 播放背景音乐 //////
control.prototype.playBgm = function (bgm, startTime) {
- bgm = core.getMappedName(bgm);
- if (main.mode != 'play' || !core.material.bgms[bgm]) return;
- // 如果不允许播放
- if (!core.musicStatus.bgmStatus) {
- try {
- core.musicStatus.playingBgm = bgm;
- core.musicStatus.lastBgm = bgm;
- core.material.bgms[bgm].pause();
- }
- catch (e) {
- console.error(e);
- }
- return;
- }
- this.setMusicBtn();
-
+ bgm = core.getMappedName(bgm);
+ if (main.mode != "play" || !core.material.bgms[bgm]) return;
+ // 如果不允许播放
+ if (!core.musicStatus.bgmStatus) {
try {
- this._playBgm_play(bgm, startTime);
+ core.musicStatus.playingBgm = bgm;
+ core.musicStatus.lastBgm = bgm;
+ core.material.bgms[bgm].pause();
+ } catch (e) {
+ console.error(e);
}
- catch (e) {
- console.log("无法播放BGM " + bgm);
- console.error(e);
- core.musicStatus.playingBgm = null;
- }
-}
+ return;
+ }
+ this.setMusicBtn();
+
+ try {
+ this._playBgm_play(bgm, startTime);
+ } catch (e) {
+ console.log("无法播放BGM " + bgm);
+ console.error(e);
+ core.musicStatus.playingBgm = null;
+ }
+};
control.prototype._playBgm_play = function (bgm, startTime) {
- // 如果当前正在播放,且和本BGM相同,直接忽略
- if (core.musicStatus.playingBgm == bgm && !core.material.bgms[core.musicStatus.playingBgm].paused) {
- return;
- }
- // 如果正在播放中,暂停
- if (core.musicStatus.playingBgm) {
- core.material.bgms[core.musicStatus.playingBgm].pause();
- }
- // 缓存BGM
- core.loader.loadBgm(bgm);
- // 播放当前BGM
- core.material.bgms[bgm].volume = core.musicStatus.userVolume * core.musicStatus.designVolume;
- core.material.bgms[bgm].currentTime = startTime || 0;
- core.material.bgms[bgm].play();
- core.musicStatus.playingBgm = bgm;
- core.musicStatus.lastBgm = bgm;
- core.setBgmSpeed(100);
-}
+ // 如果当前正在播放,且和本BGM相同,直接忽略
+ if (
+ core.musicStatus.playingBgm == bgm &&
+ !core.material.bgms[core.musicStatus.playingBgm].paused
+ ) {
+ return;
+ }
+ // 如果正在播放中,暂停
+ if (core.musicStatus.playingBgm) {
+ core.material.bgms[core.musicStatus.playingBgm].pause();
+ }
+ // 缓存BGM
+ core.loader.loadBgm(bgm);
+ // 播放当前BGM
+ core.material.bgms[bgm].volume =
+ core.musicStatus.userVolume * core.musicStatus.designVolume;
+ core.material.bgms[bgm].currentTime = startTime || 0;
+ core.material.bgms[bgm].play();
+ core.musicStatus.playingBgm = bgm;
+ core.musicStatus.lastBgm = bgm;
+ core.setBgmSpeed(100);
+};
///// 设置当前背景音乐的播放速度 //////
control.prototype.setBgmSpeed = function (speed, usePitch) {
- var bgm = core.musicStatus.playingBgm;
- if (main.mode != 'play' || !core.material.bgms[bgm]) return;
- bgm = core.material.bgms[bgm];
- if (speed < 30 || speed > 300) return;
- bgm.playbackRate = speed / 100;
- core.musicStatus.bgmSpeed = speed;
+ var bgm = core.musicStatus.playingBgm;
+ if (main.mode != "play" || !core.material.bgms[bgm]) return;
+ bgm = core.material.bgms[bgm];
+ if (speed < 30 || speed > 300) return;
+ bgm.playbackRate = speed / 100;
+ core.musicStatus.bgmSpeed = speed;
- if (bgm.preservesPitch != null) {
- if (bgm.__preservesPitch == null) bgm.__preservesPitch = bgm.preservesPitch;
- if (usePitch == null) bgm.preservesPitch = bgm.__preservesPitch;
- else if (usePitch) bgm.preservesPitch = false;
- else bgm.preservesPitch = true;
- core.musicStatus.bgmUsePitch = usePitch;
- }
-}
+ if (bgm.preservesPitch != null) {
+ if (bgm.__preservesPitch == null) bgm.__preservesPitch = bgm.preservesPitch;
+ if (usePitch == null) bgm.preservesPitch = bgm.__preservesPitch;
+ else if (usePitch) bgm.preservesPitch = false;
+ else bgm.preservesPitch = true;
+ core.musicStatus.bgmUsePitch = usePitch;
+ }
+};
////// 暂停背景音乐的播放 //////
control.prototype.pauseBgm = function () {
- if (main.mode != 'play') return;
- try {
- if (core.musicStatus.playingBgm) {
- core.musicStatus.pauseTime = core.material.bgms[core.musicStatus.playingBgm].currentTime;
- core.material.bgms[core.musicStatus.playingBgm].pause();
- core.musicStatus.playingBgm = null;
- }
+ if (main.mode != "play") return;
+ try {
+ if (core.musicStatus.playingBgm) {
+ core.musicStatus.pauseTime =
+ core.material.bgms[core.musicStatus.playingBgm].currentTime;
+ core.material.bgms[core.musicStatus.playingBgm].pause();
+ core.musicStatus.playingBgm = null;
}
- catch (e) {
- console.log("无法暂停BGM");
- console.error(e);
- }
- this.setMusicBtn();
-}
+ } catch (e) {
+ console.log("无法暂停BGM");
+ console.error(e);
+ }
+ this.setMusicBtn();
+};
////// 恢复背景音乐的播放 //////
control.prototype.resumeBgm = function (resumeTime) {
- if (main.mode != 'play') return;
- try {
- var speed = core.musicStatus.bgmSpeed;
- var usePitch = core.musicStatus.bgmUsePitch;
- core.playBgm(core.musicStatus.playingBgm || core.musicStatus.lastBgm || main.startBgm,
- resumeTime ? core.musicStatus.pauseTime : 0);
- if (resumeTime) {
- core.setBgmSpeed(speed, usePitch);
- }
+ if (main.mode != "play") return;
+ try {
+ var speed = core.musicStatus.bgmSpeed;
+ var usePitch = core.musicStatus.bgmUsePitch;
+ core.playBgm(
+ core.musicStatus.playingBgm || core.musicStatus.lastBgm || main.startBgm,
+ resumeTime ? core.musicStatus.pauseTime : 0
+ );
+ if (resumeTime) {
+ core.setBgmSpeed(speed, usePitch);
}
- catch (e) {
- console.log("无法恢复BGM");
- console.error(e);
- }
- this.setMusicBtn();
-}
+ } catch (e) {
+ console.log("无法恢复BGM");
+ console.error(e);
+ }
+ this.setMusicBtn();
+};
control.prototype.setMusicBtn = function () {
- if (core.musicStatus.bgmStatus)
- core.dom.musicBtn.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAMAAADzN3VRAAABWVBMVEX///9iYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmL///8AAAC5ubn+/v6xsbEtLS0MDAxmZmZoaGhvb2/c3Nzd3d38/Pz9/f0oKCgpKSl0dHR1dXW6urrb29v7+/v09PTv7+/39/cgICACAgImJibh4eGFhYWGhoaHh4eOjo5paWm7u7vDw8PMzMwyMjI7OztAQEDe3t5FRUVMTEzj4+Pl5eXm5ubp6enr6+tcXFzi4uL19fVeXl74+PgjIyNkZGQGBgaSkpKYmJiampqenp4DAwMwMDBnZ2cICAivr68eHh63t7cLCwsSEhLw8PBhYWEUFBQVFRXNzc3Pz8/Z2dna2toaGhqkpKSlpaWpqamrq6tFOUNAAAAAc3RSTlMAAwQFBhUWGxwkJSYyO0dISVBRUmpvj5CSk5SVoaOlpqiysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKyA0IuUgAAAVdJREFUeF5NkVVbw0AQRTcQrLR4IIEGcidJoaUuQHF3d3d3+P/CkuxCzss8nG++mbnDBJXhNt2CpbeFK1kQpSEKidlc8S9qdATRa6UIdQMoxEpDA0Ov3wUAPfW+qLWACydNv9zMrzkJwPK6FB3oHyOfXfuNxvoBQ+GmBYinhHB77TmiVBxoYUw1AYcEq332AS8OYKosAuTT0nza9uU2USYPRJgGxEiSOFywJ3mNARozgBJJzkfLvfu8JgGDWcC9FEsjWzR+y80gYDEAA8QZ3N6kmP1Fs3fEASB7pob7Hh+Wz5L0ci17Or05J7bH6B6dZv05XWK3rG+myV05Ert592Qo55sPuoIr7hEZHHtieIPWy0RU9DLwc3Mnck/vi8/E8XNrDWQtEVnL/ySKMrv0jPwPp870fprcyYifmiEmqGpHkI5q9ofSFIUk2qiwIGpEMyxYhhZRRcMPz89RJ2s9W8wAAAAASUVORK5CYII=";
- else
- core.dom.musicBtn.src = "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAMAAADzN3VRAAABYlBMVEX///9iYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmL////8/PwAAABmZmZoaGihoaGioqKxsbG5ubnb29vc3Nzd3d3h4eHi4uL9/f3+/v4tLS1nZ2d0dHSUlJSenp66uroMDAz7+/spKSkoKCgUFBRpaWkVFRVvb291dXU7OzuVlZWYmJhkZGQgICAjIyOkpKQCAgK3t7cGBgbv7++pqamrq6seHh4mJiZhYWGamprp6enr6+saGhpeXl7j4+Pl5eXm5uZKSkrw8PD09PT19fW7u7vDw8PMzMwICAgwMDAyMjILCwtAQECGhoaHh4eBgYGFhYUSEhJXV1dZWVlcXFyOjo6SkpLNzc339/fPz8/Z2dna2tqTk5OlpaWxOPeTAAAAdnRSTlMAAwQFBhUWGxwkJSYyO0dISVBRUmpvj5CSk5SVoaOlpqiysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKyNuo+uwAAAWJJREFUeF5NkmV34zAQReUm7WbTuJBNunY3bvXGDjNTkZkZlpn5/9eR5FPfbzr3jGb0RkwRiMQMDm7EIgHmRxtLwMOaHHoQjwz4MUKeCM8AWMrmd7u7f/aXAMyOShHiQD1n04DtN5e5FMBFlSauIsm585dKi4CpuSYKJIv1tBDVmvOSqJgEoowFLSBHaQh10XHWiCgHWEGmAw2blPrvOK/KRJUGoLM4kCVSKrWz7HwgoiwQZyaQJ0+9PvxV23BNATAZB25IqX9b3+jTW9fcApwB6NLgUD5NY3mPXnwmFwBezff1ztzRFzTp94FXMy36HDuCa2RafdnnmZqtL818Gl9/qNnEeyrUk2aTPiKj3qMyWBVi/YSuWq5qiwxkbtX3vYWzdz/l8M0k8ERlvViiB1Ygslb7SbVtJezncj+Cx5bYaeGuonZqhZlieAp+no74/s5EAh6JcY35Cepxk4ObcT3IJPe/1lKsDpFCFQAAAABJRU5ErkJggg==";
-}
+ if (core.musicStatus.bgmStatus)
+ core.dom.musicBtn.src =
+ "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAMAAADzN3VRAAABWVBMVEX///9iYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmL///8AAAC5ubn+/v6xsbEtLS0MDAxmZmZoaGhvb2/c3Nzd3d38/Pz9/f0oKCgpKSl0dHR1dXW6urrb29v7+/v09PTv7+/39/cgICACAgImJibh4eGFhYWGhoaHh4eOjo5paWm7u7vDw8PMzMwyMjI7OztAQEDe3t5FRUVMTEzj4+Pl5eXm5ubp6enr6+tcXFzi4uL19fVeXl74+PgjIyNkZGQGBgaSkpKYmJiampqenp4DAwMwMDBnZ2cICAivr68eHh63t7cLCwsSEhLw8PBhYWEUFBQVFRXNzc3Pz8/Z2dna2toaGhqkpKSlpaWpqamrq6tFOUNAAAAAc3RSTlMAAwQFBhUWGxwkJSYyO0dISVBRUmpvj5CSk5SVoaOlpqiysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKyA0IuUgAAAVdJREFUeF5NkVVbw0AQRTcQrLR4IIEGcidJoaUuQHF3d3d3+P/CkuxCzss8nG++mbnDBJXhNt2CpbeFK1kQpSEKidlc8S9qdATRa6UIdQMoxEpDA0Ov3wUAPfW+qLWACydNv9zMrzkJwPK6FB3oHyOfXfuNxvoBQ+GmBYinhHB77TmiVBxoYUw1AYcEq332AS8OYKosAuTT0nza9uU2USYPRJgGxEiSOFywJ3mNARozgBJJzkfLvfu8JgGDWcC9FEsjWzR+y80gYDEAA8QZ3N6kmP1Fs3fEASB7pob7Hh+Wz5L0ci17Or05J7bH6B6dZv05XWK3rG+myV05Ert592Qo55sPuoIr7hEZHHtieIPWy0RU9DLwc3Mnck/vi8/E8XNrDWQtEVnL/ySKMrv0jPwPp870fprcyYifmiEmqGpHkI5q9ofSFIUk2qiwIGpEMyxYhhZRRcMPz89RJ2s9W8wAAAAASUVORK5CYII=";
+ else
+ core.dom.musicBtn.src =
+ "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABkAAAAZCAMAAADzN3VRAAABYlBMVEX///9iYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmJiYmL////8/PwAAABmZmZoaGihoaGioqKxsbG5ubnb29vc3Nzd3d3h4eHi4uL9/f3+/v4tLS1nZ2d0dHSUlJSenp66uroMDAz7+/spKSkoKCgUFBRpaWkVFRVvb291dXU7OzuVlZWYmJhkZGQgICAjIyOkpKQCAgK3t7cGBgbv7++pqamrq6seHh4mJiZhYWGamprp6enr6+saGhpeXl7j4+Pl5eXm5uZKSkrw8PD09PT19fW7u7vDw8PMzMwICAgwMDAyMjILCwtAQECGhoaHh4eBgYGFhYUSEhJXV1dZWVlcXFyOjo6SkpLNzc339/fPz8/Z2dna2tqTk5OlpaWxOPeTAAAAdnRSTlMAAwQFBhUWGxwkJSYyO0dISVBRUmpvj5CSk5SVoaOlpqiysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKysrKyNuo+uwAAAWJJREFUeF5NkmV34zAQReUm7WbTuJBNunY3bvXGDjNTkZkZlpn5/9eR5FPfbzr3jGb0RkwRiMQMDm7EIgHmRxtLwMOaHHoQjwz4MUKeCM8AWMrmd7u7f/aXAMyOShHiQD1n04DtN5e5FMBFlSauIsm585dKi4CpuSYKJIv1tBDVmvOSqJgEoowFLSBHaQh10XHWiCgHWEGmAw2blPrvOK/KRJUGoLM4kCVSKrWz7HwgoiwQZyaQJ0+9PvxV23BNATAZB25IqX9b3+jTW9fcApwB6NLgUD5NY3mPXnwmFwBezff1ztzRFzTp94FXMy36HDuCa2RafdnnmZqtL818Gl9/qNnEeyrUk2aTPiKj3qMyWBVi/YSuWq5qiwxkbtX3vYWzdz/l8M0k8ERlvViiB1Ygslb7SbVtJezncj+Cx5bYaeGuonZqhZlieAp+no74/s5EAh6JcY35Cepxk4ObcT3IJPe/1lKsDpFCFQAAAABJRU5ErkJggg==";
+};
////// 更改背景音乐的播放 //////
control.prototype.triggerBgm = function () {
- if (main.mode != 'play') return;
+ if (main.mode != "play") return;
- core.musicStatus.bgmStatus = !core.musicStatus.bgmStatus;
- if (core.musicStatus.bgmStatus)
- this.resumeBgm();
- else
- this.pauseBgm();
- core.setLocalStorage('bgmStatus', core.musicStatus.bgmStatus);
-}
+ core.musicStatus.bgmStatus = !core.musicStatus.bgmStatus;
+ if (core.musicStatus.bgmStatus) this.resumeBgm();
+ else this.pauseBgm();
+ core.setLocalStorage("bgmStatus", core.musicStatus.bgmStatus);
+};
////// 播放音频 //////
control.prototype.playSound = function (sound, pitch, callback) {
- sound = core.getMappedName(sound);
- if (main.mode != 'play' || !core.musicStatus.soundStatus || !core.material.sounds[sound]) return;
- try {
- if (core.musicStatus.audioContext != null) {
- var source = core.musicStatus.audioContext.createBufferSource();
- source.__name = sound;
- source.buffer = core.material.sounds[sound];
- source.connect(core.musicStatus.gainNode);
- var id = setTimeout(null);
- if (pitch && pitch >= 30 && pitch <= 300) {
- source.playbackRate.setValueAtTime(pitch / 100, 0);
- }
- source.onended = function () {
- delete core.musicStatus.playingSounds[id];
- if (callback) callback();
- }
- core.musicStatus.playingSounds[id] = source;
- if (source.start) source.start(0);
- else if (source.noteOn) source.noteOn(0);
- return id;
- }
- else {
- core.material.sounds[sound].volume = core.musicStatus.userVolume;
- core.material.sounds[sound].play();
- if (callback) callback();
- }
+ sound = core.getMappedName(sound);
+ if (
+ main.mode != "play" ||
+ !core.musicStatus.soundStatus ||
+ !core.material.sounds[sound]
+ )
+ return;
+ try {
+ if (core.musicStatus.audioContext != null) {
+ var source = core.musicStatus.audioContext.createBufferSource();
+ source.__name = sound;
+ source.buffer = core.material.sounds[sound];
+ source.connect(core.musicStatus.gainNode);
+ var id = setTimeout(null);
+ if (pitch && pitch >= 30 && pitch <= 300) {
+ source.playbackRate.setValueAtTime(pitch / 100, 0);
+ }
+ source.onended = function () {
+ delete core.musicStatus.playingSounds[id];
+ if (callback) callback();
+ };
+ core.musicStatus.playingSounds[id] = source;
+ if (source.start) source.start(0);
+ else if (source.noteOn) source.noteOn(0);
+ return id;
+ } else {
+ core.material.sounds[sound].volume = core.musicStatus.userVolume;
+ core.material.sounds[sound].play();
+ if (callback) callback();
}
- catch (e) {
- console.log("无法播放SE " + sound);
- console.error(e);
- }
-}
+ } catch (e) {
+ console.log("无法播放SE " + sound);
+ console.error(e);
+ }
+};
////// 停止所有音频 //////
control.prototype.stopSound = function (id) {
- if (id == null) {
- Object.keys(core.musicStatus.playingSounds).forEach(function (id) {
- core.control.stopSound(id);
- });
- return;
- }
- var source = core.musicStatus.playingSounds[id];
- if (!source) return;
- try {
- if (source.stop) source.stop();
- else if (source.noteOff) source.noteOff();
- }
- catch (e) {
- console.error(e);
- }
- delete core.musicStatus.playingSounds[id];
-}
+ if (id == null) {
+ Object.keys(core.musicStatus.playingSounds).forEach(function (id) {
+ core.control.stopSound(id);
+ });
+ return;
+ }
+ var source = core.musicStatus.playingSounds[id];
+ if (!source) return;
+ try {
+ if (source.stop) source.stop();
+ else if (source.noteOff) source.noteOff();
+ } catch (e) {
+ console.error(e);
+ }
+ delete core.musicStatus.playingSounds[id];
+};
////// 获得当前正在播放的所有(指定)音效的id列表 //////
control.prototype.getPlayingSounds = function (name) {
- name = core.getMappedName(name);
- return Object.keys(core.musicStatus.playingSounds).filter(function (one) {
- return name == null || core.musicStatus.playingSounds[one].__name == name
- });
-}
+ name = core.getMappedName(name);
+ return Object.keys(core.musicStatus.playingSounds).filter(function (one) {
+ return name == null || core.musicStatus.playingSounds[one].__name == name;
+ });
+};
////// 检查bgm状态 //////
control.prototype.checkBgm = function () {
- core.playBgm(core.musicStatus.playingBgm || main.startBgm);
-}
+ core.playBgm(core.musicStatus.playingBgm || main.startBgm);
+};
///// 设置屏幕放缩 //////
control.prototype.setDisplayScale = function (delta) {
- var index = core.domStyle.availableScale.indexOf(core.domStyle.scale);
- if (index < 0) return;
- index = (index + delta + core.domStyle.availableScale.length) % core.domStyle.availableScale.length;
- core.domStyle.scale = core.domStyle.availableScale[index];
- core.setLocalStorage('scale', core.domStyle.scale);
- core.resize();
-}
+ var index = core.domStyle.availableScale.indexOf(core.domStyle.scale);
+ if (index < 0) return;
+ index =
+ (index + delta + core.domStyle.availableScale.length) %
+ core.domStyle.availableScale.length;
+ core.domStyle.scale = core.domStyle.availableScale[index];
+ core.setLocalStorage("scale", core.domStyle.scale);
+ core.resize();
+};
// ------ 状态栏,工具栏等相关 ------ //
////// 清空状态栏 //////
control.prototype.clearStatusBar = function () {
- Object.keys(core.statusBar).forEach(function (e) {
- if (core.statusBar[e].innerHTML != null) {
- core.statusBar[e].innerHTML = " ";
- core.statusBar[e].removeAttribute('_style');
- core.statusBar[e].removeAttribute('_value');
- }
- })
- core.statusBar.image.book.style.opacity = 0.3;
- if (!core.flags.equipboxButton)
- core.statusBar.image.fly.style.opacity = 0.3;
-}
+ Object.keys(core.statusBar).forEach(function (e) {
+ if (core.statusBar[e].innerHTML != null) {
+ core.statusBar[e].innerHTML = " ";
+ core.statusBar[e].removeAttribute("_style");
+ core.statusBar[e].removeAttribute("_value");
+ }
+ });
+ core.statusBar.image.book.style.opacity = 0.3;
+ if (!core.flags.equipboxButton) core.statusBar.image.fly.style.opacity = 0.3;
+};
////// 更新状态栏 //////
control.prototype.updateStatusBar = function (doNotCheckAutoEvents, immediate) {
- if (!core.isPlaying()) return;
- if (immediate) {
- return this.updateStatusBar_update();
- }
- if (!doNotCheckAutoEvents) this.noAutoEvents = false;
- if (core.isReplaying()) return this.updateStatusBar_update();
- if (!core.control.updateNextFrame) {
- core.control.updateNextFrame = true;
- requestAnimationFrame(this.updateStatusBar_update);
- }
+ if (!core.isPlaying()) return;
+ if (immediate) {
+ return this.updateStatusBar_update();
+ }
+ if (!doNotCheckAutoEvents) this.noAutoEvents = false;
+ if (core.isReplaying()) return this.updateStatusBar_update();
+ if (!core.control.updateNextFrame) {
+ core.control.updateNextFrame = true;
+ requestAnimationFrame(this.updateStatusBar_update);
+ }
};
control.prototype.updateStatusBar_update = function () {
- core.control.updateNextFrame = false;
- if (!core.isPlaying() || core.hasFlag('__statistics__')) return;
- core.control.controldata.updateStatusBar();
- if (!core.control.noAutoEvents) core.checkAutoEvents();
- core.control._updateStatusBar_setToolboxIcon();
- core.clearRouteFolding();
- core.control.noAutoEvents = true;
+ core.control.updateNextFrame = false;
+ if (!core.isPlaying() || core.hasFlag("__statistics__")) return;
+ core.control.controldata.updateStatusBar();
+ if (!core.control.noAutoEvents) core.checkAutoEvents();
+ core.control._updateStatusBar_setToolboxIcon();
+ core.clearRouteFolding();
+ core.control.noAutoEvents = true;
};
control.prototype._updateStatusBar_setToolboxIcon = function () {
- if (core.isReplaying()) {
- core.statusBar.image.book.src = core.status.replay.pausing ? core.statusBar.icons.play.src : core.statusBar.icons.pause.src;
- core.statusBar.image.book.style.opacity = 1;
- core.statusBar.image.fly.src = core.statusBar.icons.stop.src;
- core.statusBar.image.fly.style.opacity = 1;
- core.statusBar.image.toolbox.src = core.statusBar.icons.rewind.src;
- core.statusBar.image.keyboard.src = core.statusBar.icons.book.src;
- core.statusBar.image.shop.src = core.statusBar.icons.floor.src;
- core.statusBar.image.save.src = core.statusBar.icons.speedDown.src;
- core.statusBar.image.save.style.opacity = 1;
- core.statusBar.image.load.src = core.statusBar.icons.speedUp.src;
- core.statusBar.image.settings.src = core.statusBar.icons.save.src;
+ if (core.isReplaying()) {
+ core.statusBar.image.book.src = core.status.replay.pausing
+ ? core.statusBar.icons.play.src
+ : core.statusBar.icons.pause.src;
+ core.statusBar.image.book.style.opacity = 1;
+ core.statusBar.image.fly.src = core.statusBar.icons.stop.src;
+ core.statusBar.image.fly.style.opacity = 1;
+ core.statusBar.image.toolbox.src = core.statusBar.icons.rewind.src;
+ core.statusBar.image.keyboard.src = core.statusBar.icons.book.src;
+ core.statusBar.image.shop.src = core.statusBar.icons.floor.src;
+ core.statusBar.image.save.src = core.statusBar.icons.speedDown.src;
+ core.statusBar.image.save.style.opacity = 1;
+ core.statusBar.image.load.src = core.statusBar.icons.speedUp.src;
+ core.statusBar.image.settings.src = core.statusBar.icons.save.src;
+ } else {
+ core.statusBar.image.book.src = core.statusBar.icons.book.src;
+ core.statusBar.image.book.style.opacity = core.hasItem("book") ? 1 : 0.3;
+ if (!core.flags.equipboxButton) {
+ core.statusBar.image.fly.src = core.statusBar.icons.fly.src;
+ core.statusBar.image.fly.style.opacity = core.hasItem("fly") ? 1 : 0.3;
+ } else {
+ core.statusBar.image.fly.src = core.statusBar.icons.equipbox.src;
+ core.statusBar.image.fly.style.opacity = 1;
}
- else {
- core.statusBar.image.book.src = core.statusBar.icons.book.src;
- core.statusBar.image.book.style.opacity = core.hasItem('book') ? 1 : 0.3;
- if (!core.flags.equipboxButton) {
- core.statusBar.image.fly.src = core.statusBar.icons.fly.src;
- core.statusBar.image.fly.style.opacity = core.hasItem('fly') ? 1 : 0.3;
- }
- else {
- core.statusBar.image.fly.src = core.statusBar.icons.equipbox.src;
- core.statusBar.image.fly.style.opacity = 1;
- }
- core.statusBar.image.toolbox.src = core.statusBar.icons.toolbox.src;
- core.statusBar.image.keyboard.src = core.statusBar.icons.keyboard.src;
- core.statusBar.image.shop.src = core.statusBar.icons.shop.src;
- core.statusBar.image.save.src = core.statusBar.icons.save.src;
- core.statusBar.image.save.style.opacity = core.hasFlag('__forbidSave__') ? 0.3 : 1;
- core.statusBar.image.load.src = core.statusBar.icons.load.src;
- core.statusBar.image.settings.src = core.statusBar.icons.settings.src;
- }
-}
+ core.statusBar.image.toolbox.src = core.statusBar.icons.toolbox.src;
+ core.statusBar.image.keyboard.src = core.statusBar.icons.keyboard.src;
+ core.statusBar.image.shop.src = core.statusBar.icons.shop.src;
+ core.statusBar.image.save.src = core.statusBar.icons.save.src;
+ core.statusBar.image.save.style.opacity = core.hasFlag("__forbidSave__")
+ ? 0.3
+ : 1;
+ core.statusBar.image.load.src = core.statusBar.icons.load.src;
+ core.statusBar.image.settings.src = core.statusBar.icons.settings.src;
+ }
+};
control.prototype.showStatusBar = function () {
- if (main.mode == 'editor') return;
- if (core.domStyle.showStatusBar) return;
- var statusItems = core.dom.status;
- core.domStyle.showStatusBar = true;
- core.removeFlag('hideStatusBar');
- // 显示
- for (var i = 0; i < statusItems.length; ++i)
- statusItems[i].style.opacity = 1;
- this.setToolbarButton(false);
- core.dom.tools.hard.style.display = 'block';
- core.dom.toolBar.style.display = 'block';
-}
+ if (main.mode == "editor") return;
+ if (core.domStyle.showStatusBar) return;
+ var statusItems = core.dom.status;
+ core.domStyle.showStatusBar = true;
+ core.removeFlag("hideStatusBar");
+ // 显示
+ for (var i = 0; i < statusItems.length; ++i) statusItems[i].style.opacity = 1;
+ this.setToolbarButton(false);
+ core.dom.tools.hard.style.display = "block";
+ core.dom.toolBar.style.display = "block";
+};
control.prototype.hideStatusBar = function (showToolbox) {
- if (main.mode == 'editor') return;
+ if (main.mode == "editor") return;
- // 如果原本就是隐藏的,则先显示
- if (!core.domStyle.showStatusBar)
- this.showStatusBar();
- if (core.isReplaying()) showToolbox = true;
+ // 如果原本就是隐藏的,则先显示
+ if (!core.domStyle.showStatusBar) this.showStatusBar();
+ if (core.isReplaying()) showToolbox = true;
- var statusItems = core.dom.status, toolItems = core.dom.tools;
- core.domStyle.showStatusBar = false;
- core.setFlag('hideStatusBar', true);
- core.setFlag('showToolbox', showToolbox || null);
- // 隐藏
- for (var i = 0; i < statusItems.length; ++i)
- statusItems[i].style.opacity = 0;
- if ((!core.domStyle.isVertical && !core.flags.extendToolbar) || !showToolbox) {
- for (var i = 0; i < toolItems.length; ++i)
- toolItems[i].style.display = 'none';
- }
- if (!core.domStyle.isVertical && !core.flags.extendToolbar) {
- core.dom.toolBar.style.display = 'none';
- }
-}
+ var statusItems = core.dom.status,
+ toolItems = core.dom.tools;
+ core.domStyle.showStatusBar = false;
+ core.setFlag("hideStatusBar", true);
+ core.setFlag("showToolbox", showToolbox || null);
+ // 隐藏
+ for (var i = 0; i < statusItems.length; ++i) statusItems[i].style.opacity = 0;
+ if (
+ (!core.domStyle.isVertical && !core.flags.extendToolbar) ||
+ !showToolbox
+ ) {
+ for (var i = 0; i < toolItems.length; ++i)
+ toolItems[i].style.display = "none";
+ }
+ if (!core.domStyle.isVertical && !core.flags.extendToolbar) {
+ core.dom.toolBar.style.display = "none";
+ }
+};
////// 更新状态栏的勇士图标 //////
control.prototype.updateHeroIcon = function (name) {
- name = name || "hero.png";
- if (core.statusBar.icons.name == name) return;
- core.statusBar.icons.name = name;
+ name = name || "hero.png";
+ if (core.statusBar.icons.name == name) return;
+ core.statusBar.icons.name = name;
- var image = core.material.images.hero;
- // 全身图
- var w = core.material.icons.hero.width || 32;
- var h = core.material.icons.hero.height || 48;
- var ratio = Math.min(w / h, 1), width = 32 * ratio, left = 16 - width / 2;
+ var image = core.material.images.hero;
+ // 全身图
+ var w = core.material.icons.hero.width || 32;
+ var h = core.material.icons.hero.height || 48;
+ var ratio = Math.min(w / h, 1),
+ width = 32 * ratio,
+ left = 16 - width / 2;
- var canvas = document.createElement("canvas");
- var ctx = canvas.getContext("2d");
- canvas.width = 32;
- canvas.height = 32;
- core.drawImage(ctx, image, 0, 0, w, h, left, 0, width, 32);
+ var canvas = document.createElement("canvas");
+ var ctx = canvas.getContext("2d");
+ canvas.width = 32;
+ canvas.height = 32;
+ core.drawImage(ctx, image, 0, 0, w, h, left, 0, width, 32);
- core.statusBar.image.name.src = canvas.toDataURL("image/png");
-}
+ core.statusBar.image.name.src = canvas.toDataURL("image/png");
+};
////// 改变工具栏为按钮1-8 //////
control.prototype.setToolbarButton = function (useButton) {
- if (!core.domStyle.showStatusBar) {
- // 隐藏状态栏时检查竖屏
- if (!core.domStyle.isVertical && !core.flags.extendToolbar) {
- for (var i = 0; i < core.dom.tools.length; ++i)
- core.dom.tools[i].style.display = 'none';
- return;
- }
- if (!core.hasFlag('showToolbox')) return;
- else core.dom.tools.hard.style.display = 'block';
+ if (!core.domStyle.showStatusBar) {
+ // 隐藏状态栏时检查竖屏
+ if (!core.domStyle.isVertical && !core.flags.extendToolbar) {
+ for (var i = 0; i < core.dom.tools.length; ++i)
+ core.dom.tools[i].style.display = "none";
+ return;
}
+ if (!core.hasFlag("showToolbox")) return;
+ else core.dom.tools.hard.style.display = "block";
+ }
- if (useButton == null) useButton = core.domStyle.toolbarBtn;
- if ((!core.domStyle.isVertical && !core.flags.extendToolbar)) useButton = false;
- core.domStyle.toolbarBtn = useButton;
+ if (useButton == null) useButton = core.domStyle.toolbarBtn;
+ if (!core.domStyle.isVertical && !core.flags.extendToolbar) useButton = false;
+ core.domStyle.toolbarBtn = useButton;
- if (useButton) {
- ["book", "fly", "toolbox", "keyboard", "shop", "save", "load", "settings"].forEach(function (t) {
- core.statusBar.image[t].style.display = 'none';
- });
- ["btn1", "btn2", "btn3", "btn4", "btn5", "btn6", "btn7", "btn8"].forEach(function (t) {
- core.statusBar.image[t].style.display = 'block';
- })
- main.statusBar.image.btn8.style.filter = core.getLocalStorage('altKey') ? 'sepia(1) contrast(1.5)' : '';
- }
- else {
- ["btn1", "btn2", "btn3", "btn4", "btn5", "btn6", "btn7", "btn8"].forEach(function (t) {
- core.statusBar.image[t].style.display = 'none';
- });
- ["book", "fly", "toolbox", "save", "load", "settings"].forEach(function (t) {
- core.statusBar.image[t].style.display = 'block';
- });
- core.statusBar.image.keyboard.style.display
- = core.statusBar.image.shop.style.display
- = core.domStyle.isVertical || core.flags.extendToolbar ? "block" : "none";
- }
-}
+ if (useButton) {
+ [
+ "book",
+ "fly",
+ "toolbox",
+ "keyboard",
+ "shop",
+ "save",
+ "load",
+ "settings",
+ ].forEach(function (t) {
+ core.statusBar.image[t].style.display = "none";
+ });
+ ["btn1", "btn2", "btn3", "btn4", "btn5", "btn6", "btn7", "btn8"].forEach(
+ function (t) {
+ core.statusBar.image[t].style.display = "block";
+ }
+ );
+ main.statusBar.image.btn8.style.filter = core.getLocalStorage("altKey")
+ ? "sepia(1) contrast(1.5)"
+ : "";
+ } else {
+ ["btn1", "btn2", "btn3", "btn4", "btn5", "btn6", "btn7", "btn8"].forEach(
+ function (t) {
+ core.statusBar.image[t].style.display = "none";
+ }
+ );
+ ["book", "fly", "toolbox", "save", "load", "settings"].forEach(function (
+ t
+ ) {
+ core.statusBar.image[t].style.display = "block";
+ });
+ core.statusBar.image.keyboard.style.display =
+ core.statusBar.image.shop.style.display =
+ core.domStyle.isVertical || core.flags.extendToolbar ? "block" : "none";
+ }
+};
////// ------ resize处理 ------ //
control.prototype._shouldDisplayStatus = function (id) {
- if (id == null) {
- var toDraw = [], status = core.dom.status;
- for (var i = 0; i < status.length; ++i) {
- var dom = core.dom.status[i], idCol = dom.id;
- if (idCol.indexOf("Col") != idCol.length - 3) continue;
- var id = idCol.substring(0, idCol.length - 3);
- if (!this._shouldDisplayStatus(id)) continue;
- toDraw.push(id);
- }
- return toDraw;
+ if (id == null) {
+ var toDraw = [],
+ status = core.dom.status;
+ for (var i = 0; i < status.length; ++i) {
+ var dom = core.dom.status[i],
+ idCol = dom.id;
+ if (idCol.indexOf("Col") != idCol.length - 3) continue;
+ var id = idCol.substring(0, idCol.length - 3);
+ if (!this._shouldDisplayStatus(id)) continue;
+ toDraw.push(id);
}
- var obj = {};
- core.flags.statusBarItems.forEach(function (v) { obj[v] = true; })
- switch (id) {
- case 'floor': return obj.enableFloor;
- case 'name': return obj.enableName;
- case 'lv': return obj.enableLv;
- case 'hp': return obj.enableHP;
- case 'hpmax': return obj.enableHPMax;
- case 'mana': return obj.enableMana;
- case 'atk': return obj.enableAtk;
- case 'def': return obj.enableDef;
- case 'mdef': return obj.enableMDef;
- case 'money': return obj.enableMoney;
- case 'exp': return obj.enableExp && !obj.levelUpLeftMode;
- case 'up': return obj.enableLevelUp;
- case 'skill': return obj.enableSkill;
- case 'key': return obj.enableKeys;
- case 'pzf': return obj.enablePZF;
- case 'debuff': return obj.enableDebuff;
- default: return true;
- }
-}
+ return toDraw;
+ }
+ var obj = {};
+ core.flags.statusBarItems.forEach(function (v) {
+ obj[v] = true;
+ });
+ switch (id) {
+ case "floor":
+ return obj.enableFloor;
+ case "name":
+ return obj.enableName;
+ case "lv":
+ return obj.enableLv;
+ case "hp":
+ return obj.enableHP;
+ case "hpmax":
+ return obj.enableHPMax;
+ case "mana":
+ return obj.enableMana;
+ case "atk":
+ return obj.enableAtk;
+ case "def":
+ return obj.enableDef;
+ case "mdef":
+ return obj.enableMDef;
+ case "money":
+ return obj.enableMoney;
+ case "exp":
+ return obj.enableExp && !obj.levelUpLeftMode;
+ case "up":
+ return obj.enableLevelUp;
+ case "skill":
+ return obj.enableSkill;
+ case "key":
+ return obj.enableKeys;
+ case "pzf":
+ return obj.enablePZF;
+ case "debuff":
+ return obj.enableDebuff;
+ default:
+ return true;
+ }
+};
////// 注册一个resize函数 //////
// name为名称,可供注销使用
// func可以是一个函数,或者是插件中的函数名;可以接受obj参数,详见resize函数。
control.prototype.registerResize = function (name, func) {
- this.unregisterResize(name);
- this.resizes.push({ name: name, func: func });
-}
+ this.unregisterResize(name);
+ this.resizes.push({ name: name, func: func });
+};
////// 注销一个resize函数 //////
control.prototype.unregisterResize = function (name) {
- this.resizes = this.resizes.filter(function (b) { return b.name != name; });
-}
+ this.resizes = this.resizes.filter(function (b) {
+ return b.name != name;
+ });
+};
control.prototype._doResize = function (obj) {
- for (var i in this.resizes) {
- try {
- if (core.doFunc(this.resizes[i].func, this, obj)) return true;
- } catch (e) {
- console.error(e);
- console.error("ERROR in resizes[" + this.resizes[i].name + "]:已自动注销该项。");
- this.unregisterResize(this.resizes[i].name);
- }
+ for (var i in this.resizes) {
+ try {
+ if (core.doFunc(this.resizes[i].func, this, obj)) return true;
+ } catch (e) {
+ console.error(e);
+ console.error(
+ "ERROR in resizes[" + this.resizes[i].name + "]:已自动注销该项。"
+ );
+ this.unregisterResize(this.resizes[i].name);
}
- return false;
-}
+ }
+ return false;
+};
////// 屏幕分辨率改变后重新自适应 //////
control.prototype.resize = function () {
- if (main.mode == 'editor') return;
- var clientWidth = main.dom.body.clientWidth, clientHeight = main.dom.body.clientHeight;
- var BORDER = 3;
- var extendToolbar = core.flags.extendToolbar;
- let hideLeftStatusBar = core.flags.hideLeftStatusBar;
- var BAR_WIDTH = hideLeftStatusBar ? 0 : Math.round(core._PY_ * 0.31);
+ if (main.mode == "editor") return;
+ var clientWidth = main.dom.body.clientWidth,
+ clientHeight = main.dom.body.clientHeight;
+ var BORDER = 3;
+ var extendToolbar = core.flags.extendToolbar;
+ let hideLeftStatusBar = core.flags.hideLeftStatusBar;
+ var BAR_WIDTH = hideLeftStatusBar ? 0 : Math.round(core._PY_ * 0.31);
- var horizontalMaxRatio = (clientHeight - 2 * BORDER - (hideLeftStatusBar ? BORDER : 0)) / (core._PY_ + (hideLeftStatusBar ? 38 : 0));
+ var horizontalMaxRatio =
+ (clientHeight - 2 * BORDER - (hideLeftStatusBar ? BORDER : 0)) /
+ (core._PY_ + (hideLeftStatusBar ? 38 : 0));
- if (clientWidth - 3 * BORDER >= core._PX_ + BAR_WIDTH || (clientWidth > clientHeight && horizontalMaxRatio < 1)) {
- // 横屏
- core.domStyle.isVertical = false;
+ if (
+ clientWidth - 3 * BORDER >= core._PX_ + BAR_WIDTH ||
+ (clientWidth > clientHeight && horizontalMaxRatio < 1)
+ ) {
+ // 横屏
+ core.domStyle.isVertical = false;
- core.domStyle.availableScale = [];
- [1, 1.25, 1.5, 1.75, 2, 2.25, 2.5].forEach(function (v) {
- if (clientWidth - 3 * BORDER >= v * (core._PX_ + BAR_WIDTH) && horizontalMaxRatio >= v) {
- core.domStyle.availableScale.push(v);
- }
- });
- if (core.domStyle.availableScale.indexOf(core.domStyle.scale) < 0) {
- core.domStyle.scale = Math.min(1, horizontalMaxRatio);
- }
- }
- else {
- // 竖屏
- core.domStyle.isVertical = true;
- core.domStyle.scale = Math.min((clientWidth - 2 * BORDER) / core._PX_);
- core.domStyle.availableScale = [];
- extendToolbar = false;
- hideLeftStatusBar = false;
- BAR_WIDTH = Math.round(core._PX_ * 0.3);
+ core.domStyle.availableScale = [];
+ [1, 1.25, 1.5, 1.75, 2, 2.25, 2.5].forEach(function (v) {
+ if (
+ clientWidth - 3 * BORDER >= v * (core._PX_ + BAR_WIDTH) &&
+ horizontalMaxRatio >= v
+ ) {
+ core.domStyle.availableScale.push(v);
+ }
+ });
+ if (core.domStyle.availableScale.indexOf(core.domStyle.scale) < 0) {
+ core.domStyle.scale = Math.min(1, horizontalMaxRatio);
}
+ } else {
+ // 竖屏
+ core.domStyle.isVertical = true;
+ core.domStyle.scale = Math.min((clientWidth - 2 * BORDER) / core._PX_);
+ core.domStyle.availableScale = [];
+ extendToolbar = false;
+ hideLeftStatusBar = false;
+ BAR_WIDTH = Math.round(core._PX_ * 0.3);
+ }
- var statusDisplayArr = this._shouldDisplayStatus(), count = statusDisplayArr.length;
- var statusCanvas = core.flags.statusCanvas, statusCanvasRows = core.values.statusCanvasRowsOnMobile || 3;
- var col = statusCanvas ? statusCanvasRows : Math.ceil(count / 3);
- if (col > 5) {
- if (statusCanvas) alert("自绘状态栏的在竖屏下的行数应不超过5!");
- else alert("当前状态栏数目(" + count + ")大于15,请调整到不超过15以避免手机端出现显示问题。");
- }
- var globalAttribute = core.status.globalAttribute || core.initStatus.globalAttribute;
+ var statusDisplayArr = this._shouldDisplayStatus(),
+ count = statusDisplayArr.length;
+ var statusCanvas = core.flags.statusCanvas,
+ statusCanvasRows = core.values.statusCanvasRowsOnMobile || 3;
+ var col = statusCanvas ? statusCanvasRows : Math.ceil(count / 3);
+ if (col > 5) {
+ if (statusCanvas) alert("自绘状态栏的在竖屏下的行数应不超过5!");
+ else
+ alert(
+ "当前状态栏数目(" +
+ count +
+ ")大于15,请调整到不超过15以避免手机端出现显示问题。"
+ );
+ }
+ var globalAttribute =
+ core.status.globalAttribute || core.initStatus.globalAttribute;
- var obj = {
- clientWidth: clientWidth,
- clientHeight: clientHeight,
- BORDER: BORDER,
- BAR_WIDTH: BAR_WIDTH,
- TOOLBAR_HEIGHT: 38,
- outerWidth: core._PX_ * core.domStyle.scale + 2 * BORDER,
- outerHeight: core._PY_ * core.domStyle.scale + 2 * BORDER,
- globalAttribute: globalAttribute,
- border: '3px ' + core.arrayToRGBA(globalAttribute.borderColor) + ' solid',
- statusDisplayArr: statusDisplayArr,
- count: count,
- col: col,
- statusBarHeightInVertical: core.domStyle.isVertical ? (32 * col + 6) * core.domStyle.scale + 2 * BORDER : 0,
- toolbarHeightInVertical: core.domStyle.isVertical ? 38 * core.domStyle.scale + 2 * BORDER : 0,
- extendToolbar: extendToolbar,
- is15x15: false,
- hideLeftStatusBar
- };
+ var obj = {
+ clientWidth: clientWidth,
+ clientHeight: clientHeight,
+ BORDER: BORDER,
+ BAR_WIDTH: BAR_WIDTH,
+ TOOLBAR_HEIGHT: 38,
+ outerWidth: core._PX_ * core.domStyle.scale + 2 * BORDER,
+ outerHeight: core._PY_ * core.domStyle.scale + 2 * BORDER,
+ globalAttribute: globalAttribute,
+ border: "3px " + core.arrayToRGBA(globalAttribute.borderColor) + " solid",
+ statusDisplayArr: statusDisplayArr,
+ count: count,
+ col: col,
+ statusBarHeightInVertical: core.domStyle.isVertical
+ ? (32 * col + 6) * core.domStyle.scale + 2 * BORDER
+ : 0,
+ toolbarHeightInVertical: core.domStyle.isVertical
+ ? 38 * core.domStyle.scale + 2 * BORDER
+ : 0,
+ extendToolbar: extendToolbar,
+ is15x15: false,
+ hideLeftStatusBar,
+ };
- this._doResize(obj);
- this.setToolbarButton();
- core.updateStatusBar();
-}
+ this._doResize(obj);
+ this.setToolbarButton();
+ core.updateStatusBar();
+};
control.prototype._resize_gameGroup = function (obj) {
- var startBackground = core.domStyle.isVertical ? (main.styles.startVerticalBackground || main.styles.startBackground) : main.styles.startBackground;
- if (main.dom.startBackground.getAttribute('__src__') != startBackground) {
- main.dom.startBackground.setAttribute('__src__', startBackground);
- main.dom.startBackground.src = startBackground;
- }
+ var startBackground = core.domStyle.isVertical
+ ? main.styles.startVerticalBackground || main.styles.startBackground
+ : main.styles.startBackground;
+ if (main.dom.startBackground.getAttribute("__src__") != startBackground) {
+ main.dom.startBackground.setAttribute("__src__", startBackground);
+ main.dom.startBackground.src = startBackground;
+ }
- var gameGroup = core.dom.gameGroup;
- var totalWidth, totalHeight;
- if (core.domStyle.isVertical) {
- totalWidth = obj.outerWidth;
- totalHeight = obj.outerHeight + obj.statusBarHeightInVertical + obj.toolbarHeightInVertical
- }
- else {
- totalWidth = obj.outerWidth + obj.BAR_WIDTH * core.domStyle.scale + (obj.hideLeftStatusBar ? 0 : obj.BORDER);
- totalHeight = obj.outerHeight + (obj.extendToolbar ? obj.TOOLBAR_HEIGHT * core.domStyle.scale + obj.BORDER : 0);
- }
- gameGroup.style.width = totalWidth + "px";
- gameGroup.style.height = totalHeight + "px";
- gameGroup.style.left = (obj.clientWidth - totalWidth) / 2 + "px";
- gameGroup.style.top = (obj.clientHeight - totalHeight) / 2 + "px";
- // floorMsgGroup
- var floorMsgGroup = core.dom.floorMsgGroup;
- floorMsgGroup.style = obj.globalAttribute.floorChangingStyle;
- floorMsgGroup.style.width = obj.outerWidth - 2 * obj.BORDER + "px";
- floorMsgGroup.style.height = totalHeight - 2 * obj.BORDER + "px";
- floorMsgGroup.style.fontSize = 16 * core.domStyle.scale + "px";
- // startPanel
- core.dom.startPanel.style.fontSize = 16 * core.domStyle.scale + "px";
- // musicBtn
- if (core.domStyle.isVertical || core.domStyle.scale < 1) {
- core.dom.musicBtn.style.right = core.dom.musicBtn.style.bottom = "3px";
- }
- else {
- core.dom.musicBtn.style.right = (obj.clientWidth - totalWidth) / 2 + "px";
- core.dom.musicBtn.style.bottom = (obj.clientHeight - totalHeight) / 2 - 27 + "px";
- }
-}
+ var gameGroup = core.dom.gameGroup;
+ var totalWidth, totalHeight;
+ if (core.domStyle.isVertical) {
+ totalWidth = obj.outerWidth;
+ totalHeight =
+ obj.outerHeight +
+ obj.statusBarHeightInVertical +
+ obj.toolbarHeightInVertical;
+ } else {
+ totalWidth =
+ obj.outerWidth +
+ obj.BAR_WIDTH * core.domStyle.scale +
+ (obj.hideLeftStatusBar ? 0 : obj.BORDER);
+ totalHeight =
+ obj.outerHeight +
+ (obj.extendToolbar
+ ? obj.TOOLBAR_HEIGHT * core.domStyle.scale + obj.BORDER
+ : 0);
+ }
+ gameGroup.style.width = totalWidth + "px";
+ gameGroup.style.height = totalHeight + "px";
+ gameGroup.style.left = (obj.clientWidth - totalWidth) / 2 + "px";
+ gameGroup.style.top = (obj.clientHeight - totalHeight) / 2 + "px";
+ // floorMsgGroup
+ var floorMsgGroup = core.dom.floorMsgGroup;
+ floorMsgGroup.style = obj.globalAttribute.floorChangingStyle;
+ floorMsgGroup.style.width = obj.outerWidth - 2 * obj.BORDER + "px";
+ floorMsgGroup.style.height = totalHeight - 2 * obj.BORDER + "px";
+ floorMsgGroup.style.fontSize = 16 * core.domStyle.scale + "px";
+ // startPanel
+ core.dom.startPanel.style.fontSize = 16 * core.domStyle.scale + "px";
+ // musicBtn
+ if (core.domStyle.isVertical || core.domStyle.scale < 1) {
+ core.dom.musicBtn.style.right = core.dom.musicBtn.style.bottom = "3px";
+ } else {
+ core.dom.musicBtn.style.right = (obj.clientWidth - totalWidth) / 2 + "px";
+ core.dom.musicBtn.style.bottom =
+ (obj.clientHeight - totalHeight) / 2 - 27 + "px";
+ }
+};
control.prototype._resize_canvas = function (obj) {
- var innerWidth = (core._PX_ * core.domStyle.scale) + "px", innerHeight = (core._PY_ * core.domStyle.scale) + "px";
- if (!core.isPlaying()) {
- for (var i = 0; i < core.dom.gameCanvas.length; ++i) {
- var ctx = core.dom.gameCanvas[i].getContext('2d');
- core.resizeCanvas(ctx, core._PX_, core._PY_);
- core.dom.gameCanvas[i].style.width = innerWidth;
- core.dom.gameCanvas[i].style.height = innerHeight;
- }
- } else {
- requestAnimationFrame(function () {
- for (var i = 0; i < core.dom.gameCanvas.length; ++i) {
- core.dom.gameCanvas[i].style.width = innerWidth;
- core.dom.gameCanvas[i].style.height = innerHeight;
- }
- });
+ var innerWidth = core._PX_ * core.domStyle.scale + "px",
+ innerHeight = core._PY_ * core.domStyle.scale + "px";
+ if (!core.isPlaying()) {
+ for (var i = 0; i < core.dom.gameCanvas.length; ++i) {
+ var ctx = core.dom.gameCanvas[i].getContext("2d");
+ core.resizeCanvas(ctx, core._PX_, core._PY_);
+ core.dom.gameCanvas[i].style.width = innerWidth;
+ core.dom.gameCanvas[i].style.height = innerHeight;
}
- core.dom.gif.style.width = innerWidth;
- core.dom.gif.style.height = innerHeight;
- core.dom.gif2.style.width = innerWidth;
- core.dom.gif2.style.height = innerHeight;
- core.dom.gameDraw.style.width = innerWidth;
- core.dom.gameDraw.style.height = innerHeight;
- core.dom.gameDraw.style.top = obj.statusBarHeightInVertical + "px";
- core.dom.gameDraw.style.right = 0;
- core.dom.gameDraw.style.border = obj.border;
- // resize bigmap
- core.bigmap.canvas.forEach(function (cn) {
- var ratio = core.canvas[cn].canvas.hasAttribute('isHD') ? core.domStyle.ratio : 1;
- core.canvas[cn].canvas.style.width = core.canvas[cn].canvas.width / ratio * core.domStyle.scale + "px";
- core.canvas[cn].canvas.style.height = core.canvas[cn].canvas.height / ratio * core.domStyle.scale + "px";
+ } else {
+ requestAnimationFrame(function () {
+ for (var i = 0; i < core.dom.gameCanvas.length; ++i) {
+ core.dom.gameCanvas[i].style.width = innerWidth;
+ core.dom.gameCanvas[i].style.height = innerHeight;
+ }
});
- // resize dynamic canvas
- if (!core.isPlaying()) {
- for (var name in core.dymCanvas) {
- var ctx = core.dymCanvas[name], canvas = ctx.canvas;
- // core.maps._setHDCanvasSize(ctx, parseFloat(canvas.getAttribute('_width')), parseFloat(canvas.getAttribute('_height')));
- canvas.style.left = parseFloat(canvas.getAttribute("_left")) * core.domStyle.scale + "px";
- canvas.style.top = parseFloat(canvas.getAttribute("_top")) * core.domStyle.scale + "px";
- var scale = canvas.getAttribute('_scale') || 1;
- core.resizeCanvas(canvas, canvas.width * scale / core.domStyle.scale, canvas.height * scale / core.domStyle.scale);
- }
- } else {
- for (var name in core.dymCanvas) {
- var ctx = core.dymCanvas[name], canvas = ctx.canvas;
- core.resizeCanvas(ctx, parseFloat(canvas.getAttribute("_width")), parseFloat(canvas.getAttribute("_height")))
- canvas.style.left = parseFloat(canvas.getAttribute("_left")) * core.domStyle.scale + "px";
- canvas.style.top = parseFloat(canvas.getAttribute("_top")) * core.domStyle.scale + "px";
- }
+ }
+ core.dom.gif.style.width = innerWidth;
+ core.dom.gif.style.height = innerHeight;
+ core.dom.gif2.style.width = innerWidth;
+ core.dom.gif2.style.height = innerHeight;
+ core.dom.gameDraw.style.width = innerWidth;
+ core.dom.gameDraw.style.height = innerHeight;
+ core.dom.gameDraw.style.top = obj.statusBarHeightInVertical + "px";
+ core.dom.gameDraw.style.right = 0;
+ core.dom.gameDraw.style.border = obj.border;
+ // resize bigmap
+ core.bigmap.canvas.forEach(function (cn) {
+ var ratio = core.canvas[cn].canvas.hasAttribute("isHD")
+ ? core.domStyle.ratio
+ : 1;
+ core.canvas[cn].canvas.style.width =
+ (core.canvas[cn].canvas.width / ratio) * core.domStyle.scale + "px";
+ core.canvas[cn].canvas.style.height =
+ (core.canvas[cn].canvas.height / ratio) * core.domStyle.scale + "px";
+ });
+ // resize dynamic canvas
+ if (!core.isPlaying()) {
+ for (var name in core.dymCanvas) {
+ var ctx = core.dymCanvas[name],
+ canvas = ctx.canvas;
+ // core.maps._setHDCanvasSize(ctx, parseFloat(canvas.getAttribute('_width')), parseFloat(canvas.getAttribute('_height')));
+ canvas.style.left =
+ parseFloat(canvas.getAttribute("_left")) * core.domStyle.scale + "px";
+ canvas.style.top =
+ parseFloat(canvas.getAttribute("_top")) * core.domStyle.scale + "px";
+ var scale = canvas.getAttribute("_scale") || 1;
+ core.resizeCanvas(
+ canvas,
+ (canvas.width * scale) / core.domStyle.scale,
+ (canvas.height * scale) / core.domStyle.scale
+ );
}
- // resize next
- main.dom.next.style.width = main.dom.next.style.height = 5 * core.domStyle.scale + "px";
- main.dom.next.style.borderBottomWidth = main.dom.next.style.borderRightWidth = 4 * core.domStyle.scale + "px";
-}
+ } else {
+ for (var name in core.dymCanvas) {
+ var ctx = core.dymCanvas[name],
+ canvas = ctx.canvas;
+ core.resizeCanvas(
+ ctx,
+ parseFloat(canvas.getAttribute("_width")),
+ parseFloat(canvas.getAttribute("_height"))
+ );
+ canvas.style.left =
+ parseFloat(canvas.getAttribute("_left")) * core.domStyle.scale + "px";
+ canvas.style.top =
+ parseFloat(canvas.getAttribute("_top")) * core.domStyle.scale + "px";
+ }
+ }
+ // resize next
+ main.dom.next.style.width = main.dom.next.style.height =
+ 5 * core.domStyle.scale + "px";
+ main.dom.next.style.borderBottomWidth = main.dom.next.style.borderRightWidth =
+ 4 * core.domStyle.scale + "px";
+};
control.prototype._resize_statusBar = function (obj) {
- // statusBar
- var statusBar = core.dom.statusBar;
- if (core.domStyle.isVertical) {
- statusBar.style.width = obj.outerWidth + "px";
- statusBar.style.height = obj.statusBarHeightInVertical + "px";
- statusBar.style.background = obj.globalAttribute.statusTopBackground;
- statusBar.style.fontSize = 16 * core.domStyle.scale + "px";
+ // statusBar
+ var statusBar = core.dom.statusBar;
+ if (core.domStyle.isVertical) {
+ statusBar.style.width = obj.outerWidth + "px";
+ statusBar.style.height = obj.statusBarHeightInVertical + "px";
+ statusBar.style.background = obj.globalAttribute.statusTopBackground;
+ statusBar.style.fontSize = 16 * core.domStyle.scale + "px";
+ } else {
+ statusBar.style.width =
+ obj.BAR_WIDTH * core.domStyle.scale + obj.BORDER + "px";
+ statusBar.style.height =
+ obj.outerHeight +
+ (obj.extendToolbar
+ ? obj.TOOLBAR_HEIGHT * core.domStyle.scale + obj.BORDER
+ : 0) +
+ "px";
+ statusBar.style.background = obj.globalAttribute.statusLeftBackground;
+ // --- 计算文字大小
+ if (obj.hideLeftStatusBar) {
+ statusBar.style.fontSize = 16 * core.domStyle.scale + "px";
+ } else {
+ statusBar.style.fontSize =
+ 16 *
+ Math.min(1, (core._HEIGHT_ - 4) / obj.count) *
+ core.domStyle.scale +
+ "px";
}
- else {
- statusBar.style.width = (obj.BAR_WIDTH * core.domStyle.scale + obj.BORDER) + "px";
- statusBar.style.height = obj.outerHeight + (obj.extendToolbar ? obj.TOOLBAR_HEIGHT * core.domStyle.scale + obj.BORDER : 0) + "px";
- statusBar.style.background = obj.globalAttribute.statusLeftBackground;
- // --- 计算文字大小
- if (obj.hideLeftStatusBar) {
- statusBar.style.fontSize = 16 * core.domStyle.scale + "px";
- } else {
- statusBar.style.fontSize = 16 * Math.min(1, (core._HEIGHT_ - 4) / obj.count) * core.domStyle.scale + "px";
- }
- }
- statusBar.style.display = obj.hideLeftStatusBar ? 'none' : 'block';
- statusBar.style.borderTop = statusBar.style.borderLeft = obj.border;
- statusBar.style.borderRight = core.domStyle.isVertical ? obj.border : '';
- statusBar.style.borderBottom = core.domStyle.isVertical ? '' : obj.border;
- // 自绘状态栏
- if (core.domStyle.isVertical) {
- core.dom.statusCanvas.style.width = core._PX_ * core.domStyle.scale + "px";
- core.dom.statusCanvas.style.height = obj.statusBarHeightInVertical - 3 + "px";
- core.maps._setHDCanvasSize(core.dom.statusCanvasCtx, core._PX_, obj.col * 32 + 9);
- }
- else {
- core.dom.statusCanvas.style.width = obj.BAR_WIDTH * core.domStyle.scale + "px";
- core.dom.statusCanvas.style.height = obj.outerHeight - 2 * obj.BORDER + (obj.extendToolbar ? obj.TOOLBAR_HEIGHT * core.domStyle.scale + obj.BORDER : 0) + "px";
- core.maps._setHDCanvasSize(core.dom.statusCanvasCtx, obj.BAR_WIDTH, core._PY_ + (obj.extendToolbar ? obj.TOOLBAR_HEIGHT + obj.BORDER : 0));
- }
- core.dom.statusCanvas.style.display = core.flags.statusCanvas && !obj.hideLeftStatusBar ? "block" : "none";
-}
+ }
+ statusBar.style.display = obj.hideLeftStatusBar ? "none" : "block";
+ statusBar.style.borderTop = statusBar.style.borderLeft = obj.border;
+ statusBar.style.borderRight = core.domStyle.isVertical ? obj.border : "";
+ statusBar.style.borderBottom = core.domStyle.isVertical ? "" : obj.border;
+ // 自绘状态栏
+ if (core.domStyle.isVertical) {
+ core.dom.statusCanvas.style.width = core._PX_ * core.domStyle.scale + "px";
+ core.dom.statusCanvas.style.height =
+ obj.statusBarHeightInVertical - 3 + "px";
+ core.maps._setHDCanvasSize(
+ core.dom.statusCanvasCtx,
+ core._PX_,
+ obj.col * 32 + 9
+ );
+ } else {
+ core.dom.statusCanvas.style.width =
+ obj.BAR_WIDTH * core.domStyle.scale + "px";
+ core.dom.statusCanvas.style.height =
+ obj.outerHeight -
+ 2 * obj.BORDER +
+ (obj.extendToolbar
+ ? obj.TOOLBAR_HEIGHT * core.domStyle.scale + obj.BORDER
+ : 0) +
+ "px";
+ core.maps._setHDCanvasSize(
+ core.dom.statusCanvasCtx,
+ obj.BAR_WIDTH,
+ core._PY_ + (obj.extendToolbar ? obj.TOOLBAR_HEIGHT + obj.BORDER : 0)
+ );
+ }
+ core.dom.statusCanvas.style.display =
+ core.flags.statusCanvas && !obj.hideLeftStatusBar ? "block" : "none";
+};
control.prototype._resize_status = function (obj) {
- var statusHeight;
- if (core.domStyle.isVertical) {
- statusHeight = 32 * core.domStyle.scale * 0.8;
- } else {
- statusHeight = (obj.hideLeftStatusBar ? core._HEIGHT_ : core._HEIGHT_ - 4) / obj.count * 32 * core.domStyle.scale * 0.8;
- }
- // status
- for (var i = 0; i < core.dom.status.length; ++i) {
- var id = core.dom.status[i].id, style = core.dom.status[i].style;
- if (id.endsWith("Col")) id = id.substring(0, id.length - 3);
- style.display = core.flags.statusCanvas || obj.statusDisplayArr.indexOf(id) < 0 ? 'none' : 'block';
- style.margin = 3 * core.domStyle.scale + "px";
- style.height = statusHeight + "px";
- style.maxWidth = obj.BAR_WIDTH * core.domStyle.scale * (core.domStyle.isVertical ? 0.95 : 1) + obj.BORDER + "px";
- if (obj.is15x15 && !core.domStyle.isVertical)
- style.marginLeft = 11 * core.domStyle.scale + "px";
- }
- // statusLabels, statusTexts
- for (var i = 0; i < core.dom.statusLabels.length; ++i) {
- core.dom.statusLabels[i].style.lineHeight = statusHeight + "px";
- core.dom.statusLabels[i].style.marginLeft = 6 * core.domStyle.scale + "px";
- }
- for (var i = 0; i < core.dom.statusTexts.length; ++i) {
- core.dom.statusTexts[i].style.color = core.arrayToRGBA(obj.globalAttribute.statusBarColor);
- }
- // keys
- if (core.flags.statusBarItems.indexOf('enableGreenKey') >= 0) {
- core.dom.keyCol.style.fontSize = '0.75em';
- core.statusBar.greenKey.style.display = '';
- } else {
- core.dom.keyCol.style.fontSize = '';
- core.statusBar.greenKey.style.display = 'none';
- }
-}
+ var statusHeight;
+ if (core.domStyle.isVertical) {
+ statusHeight = 32 * core.domStyle.scale * 0.8;
+ } else {
+ statusHeight =
+ ((obj.hideLeftStatusBar ? core._HEIGHT_ : core._HEIGHT_ - 4) /
+ obj.count) *
+ 32 *
+ core.domStyle.scale *
+ 0.8;
+ }
+ // status
+ for (var i = 0; i < core.dom.status.length; ++i) {
+ var id = core.dom.status[i].id,
+ style = core.dom.status[i].style;
+ if (id.endsWith("Col")) id = id.substring(0, id.length - 3);
+ style.display =
+ core.flags.statusCanvas || obj.statusDisplayArr.indexOf(id) < 0
+ ? "none"
+ : "block";
+ style.margin = 3 * core.domStyle.scale + "px";
+ style.height = statusHeight + "px";
+ style.maxWidth =
+ obj.BAR_WIDTH *
+ core.domStyle.scale *
+ (core.domStyle.isVertical ? 0.95 : 1) +
+ obj.BORDER +
+ "px";
+ if (obj.is15x15 && !core.domStyle.isVertical)
+ style.marginLeft = 11 * core.domStyle.scale + "px";
+ }
+ // statusLabels, statusTexts
+ for (var i = 0; i < core.dom.statusLabels.length; ++i) {
+ core.dom.statusLabels[i].style.lineHeight = statusHeight + "px";
+ core.dom.statusLabels[i].style.marginLeft = 6 * core.domStyle.scale + "px";
+ }
+ for (var i = 0; i < core.dom.statusTexts.length; ++i) {
+ core.dom.statusTexts[i].style.color = core.arrayToRGBA(
+ obj.globalAttribute.statusBarColor
+ );
+ }
+ // keys
+ if (core.flags.statusBarItems.indexOf("enableGreenKey") >= 0) {
+ core.dom.keyCol.style.fontSize = "0.75em";
+ core.statusBar.greenKey.style.display = "";
+ } else {
+ core.dom.keyCol.style.fontSize = "";
+ core.statusBar.greenKey.style.display = "none";
+ }
+};
control.prototype._resize_toolBar = function (obj) {
- // toolBar
- var toolBar = core.dom.toolBar;
- if (core.domStyle.isVertical) {
- toolBar.style.left = 0;
- toolBar.style.right = "";
- toolBar.style.width = obj.outerWidth + "px";
- toolBar.style.top = obj.statusBarHeightInVertical + obj.outerHeight + "px";
- toolBar.style.height = obj.toolbarHeightInVertical + "px";
- toolBar.style.background = obj.globalAttribute.toolsBackground;
- }
- else {
- if (obj.extendToolbar || obj.hideLeftStatusBar) {
- toolBar.style.left = "";
- toolBar.style.right = 0;
- toolBar.style.width = obj.outerWidth + "px";
- toolBar.style.top = obj.outerHeight + "px";
- toolBar.style.height = obj.TOOLBAR_HEIGHT * core.domStyle.scale + obj.BORDER + "px";
- toolBar.style.background = obj.globalAttribute.toolsBackground;
- } else {
- toolBar.style.left = 0;
- toolBar.style.right = "";
- toolBar.style.width = obj.BAR_WIDTH * core.domStyle.scale + obj.BORDER + "px";
- toolBar.style.top = 0.75 * obj.outerHeight + "px";
- toolBar.style.height = 0.25 * obj.outerHeight + "px";
- toolBar.style.background = 'transparent';
- }
- }
- toolBar.style.borderLeft = obj.border;
- toolBar.style.borderRight = toolBar.style.borderBottom = core.domStyle.isVertical || obj.extendToolbar ? obj.border : '';
- toolBar.style.fontSize = 16 * core.domStyle.scale + "px";
-
- if (!core.domStyle.showStatusBar && !core.domStyle.isVertical && !obj.extendToolbar) {
- toolBar.style.display = 'none';
+ // toolBar
+ var toolBar = core.dom.toolBar;
+ if (core.domStyle.isVertical) {
+ toolBar.style.left = 0;
+ toolBar.style.right = "";
+ toolBar.style.width = obj.outerWidth + "px";
+ toolBar.style.top = obj.statusBarHeightInVertical + obj.outerHeight + "px";
+ toolBar.style.height = obj.toolbarHeightInVertical + "px";
+ toolBar.style.background = obj.globalAttribute.toolsBackground;
+ } else {
+ if (obj.extendToolbar || obj.hideLeftStatusBar) {
+ toolBar.style.left = "";
+ toolBar.style.right = 0;
+ toolBar.style.width = obj.outerWidth + "px";
+ toolBar.style.top = obj.outerHeight + "px";
+ toolBar.style.height =
+ obj.TOOLBAR_HEIGHT * core.domStyle.scale + obj.BORDER + "px";
+ toolBar.style.background = obj.globalAttribute.toolsBackground;
} else {
- toolBar.style.display = 'block';
+ toolBar.style.left = 0;
+ toolBar.style.right = "";
+ toolBar.style.width =
+ obj.BAR_WIDTH * core.domStyle.scale + obj.BORDER + "px";
+ toolBar.style.top = 0.75 * obj.outerHeight + "px";
+ toolBar.style.height = 0.25 * obj.outerHeight + "px";
+ toolBar.style.background = "transparent";
}
-}
+ }
+ toolBar.style.borderLeft = obj.border;
+ toolBar.style.borderRight = toolBar.style.borderBottom =
+ core.domStyle.isVertical || obj.extendToolbar ? obj.border : "";
+ toolBar.style.fontSize = 16 * core.domStyle.scale + "px";
+
+ if (
+ !core.domStyle.showStatusBar &&
+ !core.domStyle.isVertical &&
+ !obj.extendToolbar
+ ) {
+ toolBar.style.display = "none";
+ } else {
+ toolBar.style.display = "block";
+ }
+};
control.prototype._resize_tools = function (obj) {
- var toolsHeight = 32 * core.domStyle.scale * ((core.domStyle.isVertical || obj.extendToolbar) && !obj.is15x15 ? 0.95 : 1);
- var toolsMarginLeft;
- if (core.domStyle.isVertical || obj.extendToolbar)
- toolsMarginLeft = (core._HALF_WIDTH_ - 3) * 3 * core.domStyle.scale;
- else
- toolsMarginLeft = (obj.BAR_WIDTH * core.domStyle.scale - 9 - toolsHeight * 3) / 4;
- for (var i = 0; i < core.dom.tools.length; ++i) {
- var style = core.dom.tools[i].style;
- style.height = toolsHeight + "px";
- style.marginLeft = toolsMarginLeft + "px";
- style.marginTop = 3 * core.domStyle.scale + "px"
- }
- core.dom.hard.style.lineHeight = toolsHeight + "px";
- if (core.domStyle.isVertical || obj.extendToolbar) {
- core.dom.hard.style.width = obj.outerWidth - 9 * toolsMarginLeft - 8.5 * toolsHeight - 12 + "px";
- }
- else {
- core.dom.hard.style.width = obj.BAR_WIDTH * core.domStyle.scale - 9 - 2 * toolsMarginLeft + "px";
- if (!obj.is15x15) core.dom.hard.style.marginTop = 0;
- }
-}
+ var toolsHeight =
+ 32 *
+ core.domStyle.scale *
+ ((core.domStyle.isVertical || obj.extendToolbar) && !obj.is15x15
+ ? 0.95
+ : 1);
+ var toolsMarginLeft;
+ if (core.domStyle.isVertical || obj.extendToolbar)
+ toolsMarginLeft = (core._HALF_WIDTH_ - 3) * 3 * core.domStyle.scale;
+ else
+ toolsMarginLeft =
+ (obj.BAR_WIDTH * core.domStyle.scale - 9 - toolsHeight * 3) / 4;
+ for (var i = 0; i < core.dom.tools.length; ++i) {
+ var style = core.dom.tools[i].style;
+ style.height = toolsHeight + "px";
+ style.marginLeft = toolsMarginLeft + "px";
+ style.marginTop = 3 * core.domStyle.scale + "px";
+ }
+ core.dom.hard.style.lineHeight = toolsHeight + "px";
+ if (core.domStyle.isVertical || obj.extendToolbar) {
+ core.dom.hard.style.width =
+ obj.outerWidth - 9 * toolsMarginLeft - 8.5 * toolsHeight - 12 + "px";
+ } else {
+ core.dom.hard.style.width =
+ obj.BAR_WIDTH * core.domStyle.scale - 9 - 2 * toolsMarginLeft + "px";
+ if (!obj.is15x15) core.dom.hard.style.marginTop = 0;
+ }
+};
diff --git a/libs/events.js b/libs/events.js
index 66d9954..41c383d 100644
--- a/libs/events.js
+++ b/libs/events.js
@@ -1,429 +1,485 @@
-
"use strict";
-function events () {
- this._init();
+function events() {
+ this._init();
}
////// 初始化 //////
events.prototype._init = function () {
- this.eventdata = functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a.events;
- this.commonEvent = events_c12a15a8_c380_4b28_8144_256cba95f760.commonEvent;
- this.systemEvents = {};
- this.actions = {};
-}
+ this.eventdata = functions_d6ad677b_427a_4623_b50f_a445a3b0ef8a.events;
+ this.commonEvent = events_c12a15a8_c380_4b28_8144_256cba95f760.commonEvent;
+ this.systemEvents = {};
+ this.actions = {};
+};
// ------ 初始化,开始和结束 ------ //
/// 初始化游戏
events.prototype.resetGame = function (hero, hard, floorId, maps, values) {
- this.eventdata.resetGame(hero, hard, floorId, maps, values);
-}
+ this.eventdata.resetGame(hero, hard, floorId, maps, values);
+};
////// 游戏开始事件 //////
events.prototype.startGame = function (hard, seed, route, callback) {
- main.dom.levelChooseButtons.style.display = 'none';
- main.dom.startButtonGroup.style.display = 'none';
- hard = hard || "";
+ main.dom.levelChooseButtons.style.display = "none";
+ main.dom.startButtonGroup.style.display = "none";
+ hard = hard || "";
- if (main.mode != 'play') return;
+ if (main.mode != "play") return;
- // 无动画的开始游戏
- if (core.flags.startUsingCanvas || route != null) {
- core.dom.startPanel.style.display = 'none';
- this._startGame_start(hard, seed, route, callback);
- }
- else {
- core.hideStartAnimate(function () {
- core.events._startGame_start(hard, seed, route, callback);
- });
- }
-}
+ // 无动画的开始游戏
+ if (core.flags.startUsingCanvas || route != null) {
+ core.dom.startPanel.style.display = "none";
+ this._startGame_start(hard, seed, route, callback);
+ } else {
+ core.hideStartAnimate(function () {
+ core.events._startGame_start(hard, seed, route, callback);
+ });
+ }
+};
events.prototype._startGame_start = function (hard, seed, route, callback) {
- core.resetGame(core.firstData.hero, hard, null, core.cloneArray(core.initStatus.maps));
- core.setHeroLoc('x', -1);
- core.setHeroLoc('y', -1);
+ core.resetGame(
+ core.firstData.hero,
+ hard,
+ null,
+ core.cloneArray(core.initStatus.maps)
+ );
+ core.setHeroLoc("x", -1);
+ core.setHeroLoc("y", -1);
- if (seed != null && seed > 0) {
- core.setFlag('__seed__', seed);
- core.setFlag('__rand__', seed);
- }
- else core.utils.__init_seed();
- core.clearStatusBar();
+ if (seed != null && seed > 0) {
+ core.setFlag("__seed__", seed);
+ core.setFlag("__rand__", seed);
+ } else core.utils.__init_seed();
+ core.clearStatusBar();
- var todo = [];
- if (core.flags.startUsingCanvas) {
- core.hideStatusBar();
- core.dom.musicBtn.style.display = 'block';
- core.push(todo, core.firstData.startCanvas);
- }
- core.push(todo, { "type": "function", "function": "function() { core.events._startGame_setHard(); }" })
- core.push(todo, core.firstData.startText);
- this.insertAction(todo, null, null, function () {
- core.events._startGame_afterStart(callback);
- });
+ var todo = [];
+ if (core.flags.startUsingCanvas) {
+ core.hideStatusBar();
+ core.dom.musicBtn.style.display = "block";
+ core.push(todo, core.firstData.startCanvas);
+ }
+ core.push(todo, {
+ type: "function",
+ function: "function() { core.events._startGame_setHard(); }",
+ });
+ core.push(todo, core.firstData.startText);
+ this.insertAction(todo, null, null, function () {
+ core.events._startGame_afterStart(callback);
+ });
- if (route != null) core.startReplay(route);
-}
+ if (route != null) core.startReplay(route);
+};
events.prototype._startGame_setHard = function () {
- // 根据难度设置flag:hard
- // 这一段应当在startCanvas之后,startText之前做
- var hardValue = 0;
- var hardColor = 'red';
- main.levelChoose.forEach(function (one) {
- if (one.name == core.status.hard) {
- hardValue = one.hard;
- hardColor = core.arrayToRGBA(one.color || [255, 0, 0, 1]);
- core.insertAction(one.action);
- }
- });
- core.setFlag('hard', hardValue || 0);
- core.setFlag('__hardColor__', hardColor);
-}
+ // 根据难度设置flag:hard
+ // 这一段应当在startCanvas之后,startText之前做
+ var hardValue = 0;
+ var hardColor = "red";
+ main.levelChoose.forEach(function (one) {
+ if (one.name == core.status.hard) {
+ hardValue = one.hard;
+ hardColor = core.arrayToRGBA(one.color || [255, 0, 0, 1]);
+ core.insertAction(one.action);
+ }
+ });
+ core.setFlag("hard", hardValue || 0);
+ core.setFlag("__hardColor__", hardColor);
+};
events.prototype._startGame_afterStart = function (callback) {
- core.ui.closePanel();
- core.changeFloor(core.firstData.floorId, null, core.firstData.hero.loc, null, function () {
- // 插入一个空事件避免直接回放录像出错
- core.insertAction([]);
- if (callback) callback();
- });
- this._startGame_upload();
-}
+ core.ui.closePanel();
+ core.changeFloor(
+ core.firstData.floorId,
+ null,
+ core.firstData.hero.loc,
+ null,
+ function () {
+ // 插入一个空事件避免直接回放录像出错
+ core.insertAction([]);
+ if (callback) callback();
+ }
+ );
+ this._startGame_upload();
+};
events.prototype._startGame_upload = function () {
- // Upload
- var formData = new FormData();
- formData.append('type', 'people');
- formData.append('name', core.firstData.name);
- formData.append('version', core.firstData.version);
- formData.append('platform', core.platform.string);
- formData.append('hard', core.encodeBase64(core.status.hard));
- formData.append('hardCode', core.getFlag('hard', 0));
- formData.append('base64', 1);
+ // Upload
+ var formData = new FormData();
+ formData.append("type", "people");
+ formData.append("name", core.firstData.name);
+ formData.append("version", core.firstData.version);
+ formData.append("platform", core.platform.string);
+ formData.append("hard", core.encodeBase64(core.status.hard));
+ formData.append("hardCode", core.getFlag("hard", 0));
+ formData.append("base64", 1);
- core.utils.http("POST", "/games/upload.php", formData);
-}
+ core.utils.http("POST", "/games/upload.php", formData);
+};
////// 游戏获胜事件 //////
events.prototype.win = function (reason, norank, noexit) {
- if (!noexit) core.status.gameOver = true;
- return this.eventdata.win(reason, norank, noexit);
-}
+ if (!noexit) core.status.gameOver = true;
+ return this.eventdata.win(reason, norank, noexit);
+};
////// 游戏失败事件 //////
events.prototype.lose = function (reason) {
- if (core.isReplaying()) return core.control._replay_error(reason, function () { core.lose(reason); });
- core.status.gameOver = true;
- return this.eventdata.lose(reason);
-}
+ if (core.isReplaying())
+ return core.control._replay_error(reason, function () {
+ core.lose(reason);
+ });
+ core.status.gameOver = true;
+ return this.eventdata.lose(reason);
+};
////// 游戏结束 //////
events.prototype.gameOver = function (ending, fromReplay, norank) {
- if (!core.status.extraEvent) {
- core.clearMap('all');
- core.deleteAllCanvas();
- core.dom.gif2.innerHTML = "";
- core.setWeather();
- }
- core.ui.closePanel();
+ if (!core.status.extraEvent) {
+ core.clearMap("all");
+ core.deleteAllCanvas();
+ core.dom.gif2.innerHTML = "";
+ core.setWeather();
+ }
+ core.ui.closePanel();
- if (main.isCompetition && ending != null) {
- if (ending == "") ending = "恭喜通关";
- ending += "[比赛]";
- }
+ if (main.isCompetition && ending != null) {
+ if (ending == "") ending = "恭喜通关";
+ ending += "[比赛]";
+ }
- var reason = null;
- if (fromReplay) reason = "录像回放完毕!";
- else if (core.hasFlag("debug")) reason = "\t[系统提示]调试模式下无法上传成绩";
+ var reason = null;
+ if (fromReplay) reason = "录像回放完毕!";
+ else if (core.hasFlag("debug")) reason = "\t[系统提示]调试模式下无法上传成绩";
- if (reason != null)
- core.drawText(reason, core.restart);
- else
- this._gameOver_confirmUpload(ending, norank);
-}
+ if (reason != null) core.drawText(reason, core.restart);
+ else this._gameOver_confirmUpload(ending, norank);
+};
events.prototype._gameOver_confirmUpload = function (ending, norank) {
- core.ui.closePanel();
+ core.ui.closePanel();
- if (ending == null) {
- this._gameOver_confirmDownload(ending);
- return;
+ if (ending == null) {
+ this._gameOver_confirmDownload(ending);
+ return;
+ }
+ core.ui.drawConfirmBox(
+ "你想记录你的ID和成绩吗?",
+ function () {
+ if (main.isCompetition) {
+ core.events._gameOver_doUpload("", ending, norank);
+ } else {
+ var id = core.getCookie("id") || "";
+ var hint =
+ "请输入你的ID:\n(登录状态下输入数字用户编号可成为蓝名成绩并计入用户通关数)";
+ if (id)
+ hint =
+ "请输入你的ID:\n(输入数字用户编号" +
+ id +
+ "可成为蓝名成绩并计入用户通关数)";
+ core.myprompt(hint, id, function (username) {
+ core.events._gameOver_doUpload(username, ending, norank);
+ });
+ }
+ },
+ function () {
+ if (main.isCompetition) core.events._gameOver_confirmDownload(ending);
+ else core.events._gameOver_doUpload(null, ending, norank);
}
- core.ui.drawConfirmBox("你想记录你的ID和成绩吗?", function () {
- if (main.isCompetition) {
- core.events._gameOver_doUpload("", ending, norank);
- }
- else {
- var id = core.getCookie('id') || "";
- var hint = "请输入你的ID:\n(登录状态下输入数字用户编号可成为蓝名成绩并计入用户通关数)";
- if (id) hint = "请输入你的ID:\n(输入数字用户编号" + id + "可成为蓝名成绩并计入用户通关数)";
- core.myprompt(hint, id, function (username) {
- core.events._gameOver_doUpload(username, ending, norank);
- });
- }
- }, function () {
- if (main.isCompetition)
- core.events._gameOver_confirmDownload(ending);
- else
- core.events._gameOver_doUpload(null, ending, norank);
- })
-}
+ );
+};
events.prototype._gameOver_doUpload = function (username, ending, norank) {
- var hp = core.status.hero.hp;
- if (username == null) hp = 1;
- core.ui.closePanel();
- // upload
- var formData = new FormData();
- formData.append('type', 'score');
- formData.append('name', core.firstData.name);
- formData.append('version', core.firstData.version);
- formData.append('platform', core.platform.string);
- formData.append('hard', core.encodeBase64(core.status.hard));
- formData.append('username', core.encodeBase64(username || ""));
- formData.append('ending', core.encodeBase64(ending));
- formData.append('lv', core.status.hero.lv);
- formData.append('hp', Math.min(hp, Math.pow(2, 63)));
- formData.append('atk', core.status.hero.atk);
- formData.append('def', core.status.hero.def);
- formData.append('mdef', core.status.hero.mdef);
- formData.append('money', core.status.hero.money);
- formData.append('experience', core.status.hero.exp);
- formData.append('steps', core.status.hero.steps);
- formData.append('norank', norank ? 1 : 0);
- formData.append('seed', core.getFlag('__seed__'));
- formData.append('totalTime', Math.floor(core.status.hero.statistics.totalTime / 1000));
- formData.append('route', core.encodeRoute(core.status.route));
- formData.append('base64', 1);
+ var hp = core.status.hero.hp;
+ if (username == null) hp = 1;
+ core.ui.closePanel();
+ // upload
+ var formData = new FormData();
+ formData.append("type", "score");
+ formData.append("name", core.firstData.name);
+ formData.append("version", core.firstData.version);
+ formData.append("platform", core.platform.string);
+ formData.append("hard", core.encodeBase64(core.status.hard));
+ formData.append("username", core.encodeBase64(username || ""));
+ formData.append("ending", core.encodeBase64(ending));
+ formData.append("lv", core.status.hero.lv);
+ formData.append("hp", Math.min(hp, Math.pow(2, 63)));
+ formData.append("atk", core.status.hero.atk);
+ formData.append("def", core.status.hero.def);
+ formData.append("mdef", core.status.hero.mdef);
+ formData.append("money", core.status.hero.money);
+ formData.append("experience", core.status.hero.exp);
+ formData.append("steps", core.status.hero.steps);
+ formData.append("norank", norank ? 1 : 0);
+ formData.append("seed", core.getFlag("__seed__"));
+ formData.append(
+ "totalTime",
+ Math.floor(core.status.hero.statistics.totalTime / 1000)
+ );
+ formData.append("route", core.encodeRoute(core.status.route));
+ formData.append("base64", 1);
- if (main.isCompetition)
- core.http("POST", "/games/competition/upload.php", formData);
- else
- core.http("POST", "/games/upload.php", formData);
+ if (main.isCompetition)
+ core.http("POST", "/games/competition/upload.php", formData);
+ else core.http("POST", "/games/upload.php", formData);
- core.events._gameOver_confirmDownload(ending);
-}
+ core.events._gameOver_confirmDownload(ending);
+};
events.prototype._gameOver_confirmDownload = function (ending) {
- core.ui.closePanel();
- core.ui.drawConfirmBox("你想下载录像吗?", function () {
- var obj = {
- 'name': core.firstData.name,
- 'version': core.firstData.version,
- 'hard': core.status.hard,
- 'seed': core.getFlag('__seed__'),
- 'route': core.encodeRoute(core.status.route)
- }
- core.download(core.firstData.name + "_" + core.formatDate2(new Date()) + ".h5route",
- LZString.compressToBase64(JSON.stringify(obj)));
- core.events._gameOver_askRate(ending);
- }, function () {
- core.events._gameOver_askRate(ending);
- });
-}
+ core.ui.closePanel();
+ core.ui.drawConfirmBox(
+ "你想下载录像吗?",
+ function () {
+ var obj = {
+ name: core.firstData.name,
+ version: core.firstData.version,
+ hard: core.status.hard,
+ seed: core.getFlag("__seed__"),
+ route: core.encodeRoute(core.status.route),
+ };
+ core.download(
+ core.firstData.name + "_" + core.formatDate2(new Date()) + ".h5route",
+ LZString.compressToBase64(JSON.stringify(obj))
+ );
+ core.events._gameOver_askRate(ending);
+ },
+ function () {
+ core.events._gameOver_askRate(ending);
+ }
+ );
+};
events.prototype._gameOver_askRate = function (ending) {
- core.ui.closePanel();
+ core.ui.closePanel();
- // 继续接下来的事件
- if (core.status.extraEvent) {
- core.status.event = core.status.extraEvent;
- delete core.status.extraEvent;
- core.lockControl();
- core.doAction();
- return;
+ // 继续接下来的事件
+ if (core.status.extraEvent) {
+ core.status.event = core.status.extraEvent;
+ delete core.status.extraEvent;
+ core.lockControl();
+ core.doAction();
+ return;
+ }
+
+ if (ending == null) {
+ if (!core.hasSave(0)) {
+ core.ui.closePanel();
+ core.restart();
+ return;
}
- if (ending == null) {
- if (!core.hasSave(0)) {
- core.ui.closePanel();
- core.restart();
- return;
- }
-
- core.status.event.selection = 0;
- core.ui.drawConfirmBox("你想读取自动存档么?", function () {
- core.ui.closePanel();
- core.doSL("autoSave", "load");
- }, function () {
- core.ui.closePanel();
- core.restart();
- });
- return;
- }
-
- core.ui.drawConfirmBox("恭喜通关!你想查看榜单、评论,\n以及评分和标色投票吗?", function () {
- if (core.platform.isPC) {
- window.open("/tower/?name=" + core.firstData.name, "_blank");
- core.restart();
- }
- else {
- window.location.href = "/tower/?name=" + core.firstData.name;
- }
- }, function () {
+ core.status.event.selection = 0;
+ core.ui.drawConfirmBox(
+ "你想读取自动存档么?",
+ function () {
+ core.ui.closePanel();
+ core.doSL("autoSave", "load");
+ },
+ function () {
+ core.ui.closePanel();
core.restart();
- });
-}
+ }
+ );
+ return;
+ }
+
+ core.ui.drawConfirmBox(
+ "恭喜通关!你想查看榜单、评论,\n以及评分和标色投票吗?",
+ function () {
+ if (core.platform.isPC) {
+ window.open("/tower/?name=" + core.firstData.name, "_blank");
+ core.restart();
+ } else {
+ window.location.href = "/tower/?name=" + core.firstData.name;
+ }
+ },
+ function () {
+ core.restart();
+ }
+ );
+};
////// 重新开始游戏;此函数将回到标题页面 //////
events.prototype.restart = function () {
- core.showStartAnimate();
- core.playBgm(main.startBgm);
-}
+ core.showStartAnimate();
+ core.playBgm(main.startBgm);
+};
////// 询问是否需要重新开始 //////
events.prototype.confirmRestart = function () {
- core.playSound('打开界面');
- core.status.event.selection = 1;
- core.ui.drawConfirmBox("你确定要返回标题页面吗?", function () {
- core.playSound('确定');
- core.ui.closePanel();
- core.restart();
- }, function () {
- core.playSound('取消');
- core.ui.closePanel();
- });
-}
+ core.playSound("打开界面");
+ core.status.event.selection = 1;
+ core.ui.drawConfirmBox(
+ "你确定要返回标题页面吗?",
+ function () {
+ core.playSound("确定");
+ core.ui.closePanel();
+ core.restart();
+ },
+ function () {
+ core.playSound("取消");
+ core.ui.closePanel();
+ }
+ );
+};
// ------ 系统事件的处理 ------ //
////// 注册一个系统事件 //////
// type为事件名,func为事件的处理函数,可接受(data, callback)参数
events.prototype.registerSystemEvent = function (type, func) {
- this.systemEvents[type] = func;
-}
+ this.systemEvents[type] = func;
+};
////// 注销一个系统事件 //////
events.prototype.unregisterSystemEvent = function (type) {
- delete this.systemEvents[type];
-}
+ delete this.systemEvents[type];
+};
////// 执行一个系统事件 //////
events.prototype.doSystemEvent = function (type, data, callback) {
- core.clearRouteFolding();
- if (this.systemEvents[type]) {
- try {
- return core.doFunc(this.systemEvents[type], this, data, callback);
- }
- catch (e) {
- console.error(e);
- console.error("ERROR in systemEvents[" + type + "]");
- }
+ core.clearRouteFolding();
+ if (this.systemEvents[type]) {
+ try {
+ return core.doFunc(this.systemEvents[type], this, data, callback);
+ } catch (e) {
+ console.error(e);
+ console.error("ERROR in systemEvents[" + type + "]");
}
- if (this["_sys_" + type]) return this["_sys_" + type](data, callback);
- console.error("未知的系统事件: " + type + "!");
- if (callback) callback();
-}
+ }
+ if (this["_sys_" + type]) return this["_sys_" + type](data, callback);
+ console.error("未知的系统事件: " + type + "!");
+ if (callback) callback();
+};
////// 触发(x,y)点的事件 //////
events.prototype.trigger = function (x, y, callback) {
- var _executeCallback = function () {
- // 因为trigger之后还有可能触发其他同步脚本(比如阻激夹域检测)
- // 所以这里强制callback被异步触发
- if (callback) {
- setTimeout(callback, 1); // +1是为了录像检测系统
- }
- return;
- }
- if (core.status.gameOver) return _executeCallback();
- if (core.status.event.id == 'action') {
- core.insertAction({ "type": "function", "function": "function () { core.events._trigger_inAction(" + x + "," + y + "); }", "async": true },
- null, null, null, true);
- return _executeCallback();
- }
- if (core.status.event.id) return _executeCallback();
-
- var block = core.getBlock(x, y);
- if (block == null) return _executeCallback();
-
- // 执行该点的脚本
- if (block.event.script) {
- core.clearRouteFolding();
- try {
- eval(block.event.script);
- } catch (ee) { console.error(ee) }
- }
-
- // 碰触事件
- if (block.event.event) {
- core.clearRouteFolding();
- core.insertAction(block.event.event, block.x, block.y);
- // 不再执行该点的系统事件
- return _executeCallback();
- }
-
- if (block.event.trigger && block.event.trigger != 'null') {
- var noPass = block.event.noPass, trigger = block.event.trigger;
- if (noPass) core.clearAutomaticRouteNode(x, y);
-
- // 转换楼层能否穿透
- if (trigger == 'changeFloor' && !noPass && this._trigger_ignoreChangeFloor(block))
- return _executeCallback();
- core.status.automaticRoute.moveDirectly = false;
- this.doSystemEvent(trigger, block);
+ var _executeCallback = function () {
+ // 因为trigger之后还有可能触发其他同步脚本(比如阻激夹域检测)
+ // 所以这里强制callback被异步触发
+ if (callback) {
+ setTimeout(callback, 1); // +1是为了录像检测系统
}
+ return;
+ };
+ if (core.status.gameOver) return _executeCallback();
+ if (core.status.event.id == "action") {
+ core.insertAction(
+ {
+ type: "function",
+ function:
+ "function () { core.events._trigger_inAction(" + x + "," + y + "); }",
+ async: true,
+ },
+ null,
+ null,
+ null,
+ true
+ );
return _executeCallback();
-}
+ }
+ if (core.status.event.id) return _executeCallback();
+
+ var block = core.getBlock(x, y);
+ if (block == null) return _executeCallback();
+
+ // 执行该点的脚本
+ if (block.event.script) {
+ core.clearRouteFolding();
+ try {
+ eval(block.event.script);
+ } catch (ee) {
+ console.error(ee);
+ }
+ }
+
+ // 碰触事件
+ if (block.event.event) {
+ core.clearRouteFolding();
+ core.insertAction(block.event.event, block.x, block.y);
+ // 不再执行该点的系统事件
+ return _executeCallback();
+ }
+
+ if (block.event.trigger && block.event.trigger != "null") {
+ var noPass = block.event.noPass,
+ trigger = block.event.trigger;
+ if (noPass) core.clearAutomaticRouteNode(x, y);
+
+ // 转换楼层能否穿透
+ if (
+ trigger == "changeFloor" &&
+ !noPass &&
+ this._trigger_ignoreChangeFloor(block)
+ )
+ return _executeCallback();
+ core.status.automaticRoute.moveDirectly = false;
+ this.doSystemEvent(trigger, block);
+ }
+ return _executeCallback();
+};
events.prototype._trigger_inAction = function (x, y) {
- if (core.status.gameOver || core.status.event.id != 'action') return;
+ if (core.status.gameOver || core.status.event.id != "action") return;
- var block = core.getBlock(x, y);
- if (block == null) return core.doAction();
+ var block = core.getBlock(x, y);
+ if (block == null) return core.doAction();
- // 执行该点的脚本
- try {
- eval(block.event.script);
- } catch (ee) { console.error(ee) }
+ // 执行该点的脚本
+ try {
+ eval(block.event.script);
+ } catch (ee) {
+ console.error(ee);
+ }
- // 碰触事件
- if (block.event.event) {
- core.clearRouteFolding();
- core.insertAction(block.event.event, block.x, block.y);
- // 不再执行该点的系统事件
- return core.doAction();
- }
-
- if (block.event.trigger && block.event.trigger != 'null') {
- this.setEvents(null, x, y);
- if (block.event.trigger == 'action') {
- this.insertAction(block.event.data);
- }
- else {
- this.doSystemEvent(block.event.trigger, block, core.doAction);
- return;
- }
- }
+ // 碰触事件
+ if (block.event.event) {
+ core.clearRouteFolding();
+ core.insertAction(block.event.event, block.x, block.y);
+ // 不再执行该点的系统事件
return core.doAction();
-}
+ }
+
+ if (block.event.trigger && block.event.trigger != "null") {
+ this.setEvents(null, x, y);
+ if (block.event.trigger == "action") {
+ this.insertAction(block.event.data);
+ } else {
+ this.doSystemEvent(block.event.trigger, block, core.doAction);
+ return;
+ }
+ }
+ return core.doAction();
+};
events.prototype._trigger_ignoreChangeFloor = function (block) {
- var able = core.flags.ignoreChangeFloor;
- if (block.event.data && block.event.data.ignoreChangeFloor != null)
- able = block.event.data.ignoreChangeFloor;
- if (able) {
- if (core.isReplaying()) {
- if (core.status.replay.toReplay[0] == 'no') {
- core.status.replay.toReplay.shift();
- core.status.route.push("no");
- return true;
- }
- }
- else if (core.status.automaticRoute.autoHeroMove
- || core.status.automaticRoute.autoStep < core.status.automaticRoute.autoStepRoutes.length) {
- core.status.route.push("no");
- return true;
- }
+ var able = core.flags.ignoreChangeFloor;
+ if (block.event.data && block.event.data.ignoreChangeFloor != null)
+ able = block.event.data.ignoreChangeFloor;
+ if (able) {
+ if (core.isReplaying()) {
+ if (core.status.replay.toReplay[0] == "no") {
+ core.status.replay.toReplay.shift();
+ core.status.route.push("no");
+ return true;
+ }
+ } else if (
+ core.status.automaticRoute.autoHeroMove ||
+ core.status.automaticRoute.autoStep <
+ core.status.automaticRoute.autoStepRoutes.length
+ ) {
+ core.status.route.push("no");
+ return true;
}
- return false;
-}
+ }
+ return false;
+};
events.prototype._sys_battle = function (data, callback) {
- // 检查是否需要改变朝向
- /* if (data.x == core.nextX() && data.y == core.nextY()) {
+ // 检查是否需要改变朝向
+ /* if (data.x == core.nextX() && data.y == core.nextY()) {
var dir = core.turnDirection(":back");
var id = data.event.id, toId = (data.event.faceIds || {})[dir];
if (toId && id != toId) {
@@ -433,499 +489,554 @@ events.prototype._sys_battle = function (data, callback) {
}
} */
- // 检查战前事件
- var beforeBattle = [];
- core.push(beforeBattle, core.floors[core.status.floorId].beforeBattle[data.x + "," + data.y]);
- core.push(beforeBattle, (core.material.enemys[data.event.id] || {}).beforeBattle);
- if (beforeBattle.length > 0) {
- core.push(beforeBattle, [{ "type": "battle", "x": data.x, "y": data.y }]);
- core.clearContinueAutomaticRoute();
+ // 检查战前事件
+ var beforeBattle = [];
+ core.push(
+ beforeBattle,
+ core.floors[core.status.floorId].beforeBattle[data.x + "," + data.y]
+ );
+ core.push(
+ beforeBattle,
+ (core.material.enemys[data.event.id] || {}).beforeBattle
+ );
+ if (beforeBattle.length > 0) {
+ core.push(beforeBattle, [{ type: "battle", x: data.x, y: data.y }]);
+ core.clearContinueAutomaticRoute();
- // 自动存档
- var inAction = core.status.event.id == 'action';
- if (inAction) {
- core.insertAction(beforeBattle, data.x, data.y);
- core.doAction();
- } else {
- core.autosave(true);
- core.insertAction(beforeBattle, data.x, data.y, callback);
- }
+ // 自动存档
+ var inAction = core.status.event.id == "action";
+ if (inAction) {
+ core.insertAction(beforeBattle, data.x, data.y);
+ core.doAction();
} else {
- this.battle(data.event.id, data.x, data.y, false, callback);
+ core.autosave(true);
+ core.insertAction(beforeBattle, data.x, data.y, callback);
}
-}
+ } else {
+ this.battle(data.event.id, data.x, data.y, false, callback);
+ }
+};
////// 战斗 //////
events.prototype.battle = function (id, x, y, force, callback) {
- core.saveAndStopAutomaticRoute();
- id = id || core.getBlockId(x, y);
- if (!id) return core.clearContinueAutomaticRoute(callback);
- // 非强制战斗
- if (!core.enemys.canBattle(id, x, y) && !force && !core.status.event.id) {
- core.stopSound();
- core.playSound('操作失败');
- core.drawTip("你打不过此怪物!", id);
- return core.clearContinueAutomaticRoute(callback);
- }
- // 自动存档
- if (!core.status.event.id) core.autosave(true);
- // 战前事件
- if (!this.beforeBattle(id, x, y))
- return core.clearContinueAutomaticRoute(callback);
- // 战后事件
- this.afterBattle(id, x, y);
- if (callback) callback();
-}
+ core.saveAndStopAutomaticRoute();
+ id = id || core.getBlockId(x, y);
+ if (!id) return core.clearContinueAutomaticRoute(callback);
+ // 非强制战斗
+ if (!core.enemys.canBattle(id, x, y) && !force && !core.status.event.id) {
+ core.stopSound();
+ core.playSound("操作失败");
+ core.drawTip("你打不过此怪物!", id);
+ return core.clearContinueAutomaticRoute(callback);
+ }
+ // 自动存档
+ if (!core.status.event.id) core.autosave(true);
+ // 战前事件
+ if (!this.beforeBattle(id, x, y))
+ return core.clearContinueAutomaticRoute(callback);
+ // 战后事件
+ this.afterBattle(id, x, y);
+ if (callback) callback();
+};
////// 战斗前触发的事件 //////
events.prototype.beforeBattle = function (enemyId, x, y) {
- return this.eventdata.beforeBattle(enemyId, x, y)
-}
+ return this.eventdata.beforeBattle(enemyId, x, y);
+};
////// 战斗结束后触发的事件 //////
events.prototype.afterBattle = function (enemyId, x, y) {
- return this.eventdata.afterBattle(enemyId, x, y);
-}
+ return this.eventdata.afterBattle(enemyId, x, y);
+};
events.prototype._sys_openDoor = function (data, callback) {
- this.openDoor(data.x, data.y, true, function () {
- core.replay();
- if (callback) callback();
- });
-}
+ this.openDoor(data.x, data.y, true, function () {
+ core.replay();
+ if (callback) callback();
+ });
+};
////// 开门 //////
events.prototype.openDoor = function (x, y, needKey, callback) {
- var block = core.getBlock(x, y);
- core.saveAndStopAutomaticRoute();
- if (!this._openDoor_check(block, x, y, needKey)) {
- var locked = core.status.lockControl;
- core.waitHeroToStop(function () {
- if (!locked) core.unlockControl();
- if (callback) callback();
- });
- return;
- }
- if (core.status.replay.speed == 24) {
- core.status.replay.animate = true;
- core.removeBlock(x, y);
- setTimeout(function () {
- core.status.replay.animate = false;
- core.events.afterOpenDoor(block.event.id, x, y);
- if (callback) callback();
- }, 1); // +1是为了录像检测系统
- } else {
- this._openDoor_animate(block, x, y, callback);
- }
-}
-
-events.prototype._openDoor_check = function (block, x, y, needKey) {
- var clearAndReturn = function () {
- core.clearContinueAutomaticRoute();
- return false;
- }
-
- if (block == null || block.event == null) return clearAndReturn();
- var id = block.event.id;
-
- // 是否存在门或暗墙
- if (core.material.icons.animates[id] == null && core.material.icons.npc48[id] == null) {
- return clearAndReturn();
- }
-
- if (id == 'steelDoor' && core.flags.steelDoorWithoutKey)
- needKey = false;
- var doorInfo = block.event.doorInfo;
- if (doorInfo == null) return clearAndReturn();
- // Check all keys
- var keyInfo = doorInfo.keys || {};
- if (needKey) {
- for (var keyName in keyInfo) {
- var keyValue = keyInfo[keyName];
- if (keyName.endsWith(':o')) keyName = keyName.substring(0, keyName.length - 2);
-
- // --- 如果是一个不存在的道具,则直接认为无法开启
- if (!core.material.items[keyName]) {
- core.stopSound();
- core.playSound('操作失败');
- core.drawTip("无法开启此门");
- return clearAndReturn();
- }
- if (core.itemCount(keyName) < keyValue) {
- core.stopSound();
- core.playSound('操作失败');
- core.drawTip("你的" + ((core.material.items[keyName] || {}).name || "钥匙") + "不足!", null, true);
- return false;
- }
- }
- if (!core.status.event.id) core.autosave(true);
- for (var keyName in keyInfo) {
- if (!keyName.endsWith(':o')) core.removeItem(keyName, keyInfo[keyName]);
- }
- }
- core.playSound(doorInfo.openSound);
- return true;
-}
-
-events.prototype._openDoor_animate = function (block, x, y, callback) {
- var blockInfo = core.getBlockInfo(block);
- blockInfo.opacity = block.opacity;
- blockInfo.filter = block.filter;
-
- var speed = (block.event.doorInfo.time || 160) / 4;
-
+ var block = core.getBlock(x, y);
+ core.saveAndStopAutomaticRoute();
+ if (!this._openDoor_check(block, x, y, needKey)) {
var locked = core.status.lockControl;
- core.lockControl();
+ core.waitHeroToStop(function () {
+ if (!locked) core.unlockControl();
+ if (callback) callback();
+ });
+ return;
+ }
+ if (core.status.replay.speed == 24) {
core.status.replay.animate = true;
core.removeBlock(x, y);
+ setTimeout(function () {
+ core.status.replay.animate = false;
+ core.events.afterOpenDoor(block.event.id, x, y);
+ if (callback) callback();
+ }, 1); // +1是为了录像检测系统
+ } else {
+ this._openDoor_animate(block, x, y, callback);
+ }
+};
- blockInfo.posX = 0;
- core.maps._drawBlockInfo(blockInfo, x, y);
+events.prototype._openDoor_check = function (block, x, y, needKey) {
+ var clearAndReturn = function () {
+ core.clearContinueAutomaticRoute();
+ return false;
+ };
- var cb = function () {
- core.maps._removeBlockFromMap(core.status.floorId, block);
- if (!locked) core.unlockControl();
- core.status.replay.animate = false;
- core.events.afterOpenDoor(block.event.id, x, y);
- if (callback) callback();
+ if (block == null || block.event == null) return clearAndReturn();
+ var id = block.event.id;
+
+ // 是否存在门或暗墙
+ if (
+ core.material.icons.animates[id] == null &&
+ core.material.icons.npc48[id] == null
+ ) {
+ return clearAndReturn();
+ }
+
+ if (id == "steelDoor" && core.flags.steelDoorWithoutKey) needKey = false;
+ var doorInfo = block.event.doorInfo;
+ if (doorInfo == null) return clearAndReturn();
+ // Check all keys
+ var keyInfo = doorInfo.keys || {};
+ if (needKey) {
+ for (var keyName in keyInfo) {
+ var keyValue = keyInfo[keyName];
+ if (keyName.endsWith(":o"))
+ keyName = keyName.substring(0, keyName.length - 2);
+
+ // --- 如果是一个不存在的道具,则直接认为无法开启
+ if (!core.material.items[keyName]) {
+ core.stopSound();
+ core.playSound("操作失败");
+ core.drawTip("无法开启此门");
+ return clearAndReturn();
+ }
+ if (core.itemCount(keyName) < keyValue) {
+ core.stopSound();
+ core.playSound("操作失败");
+ core.drawTip(
+ "你的" +
+ ((core.material.items[keyName] || {}).name || "钥匙") +
+ "不足!",
+ null,
+ true
+ );
+ return false;
+ }
}
+ if (!core.status.event.id) core.autosave(true);
+ for (var keyName in keyInfo) {
+ if (!keyName.endsWith(":o")) core.removeItem(keyName, keyInfo[keyName]);
+ }
+ }
+ core.playSound(doorInfo.openSound);
+ return true;
+};
- var animate = window.setInterval(function () {
- blockInfo.posX++;
- if (blockInfo.posX == 4) {
- clearInterval(animate);
- delete core.animateFrame.asyncId[animate];
- cb();
- return;
- }
- core.maps._drawBlockInfo(blockInfo, x, y);
- }, core.status.replay.speed == 24 ? 1 : speed / Math.max(core.status.replay.speed, 1));
+events.prototype._openDoor_animate = function (block, x, y, callback) {
+ var blockInfo = core.getBlockInfo(block);
+ blockInfo.opacity = block.opacity;
+ blockInfo.filter = block.filter;
- core.animateFrame.lastAsyncId = animate;
- core.animateFrame.asyncId[animate] = cb;
-}
+ var speed = (block.event.doorInfo.time || 160) / 4;
+
+ var locked = core.status.lockControl;
+ core.lockControl();
+ core.status.replay.animate = true;
+ core.removeBlock(x, y);
+
+ blockInfo.posX = 0;
+ core.maps._drawBlockInfo(blockInfo, x, y);
+
+ var cb = function () {
+ core.maps._removeBlockFromMap(core.status.floorId, block);
+ if (!locked) core.unlockControl();
+ core.status.replay.animate = false;
+ core.events.afterOpenDoor(block.event.id, x, y);
+ if (callback) callback();
+ };
+
+ var animate = window.setInterval(
+ function () {
+ blockInfo.posX++;
+ if (blockInfo.posX == 4) {
+ clearInterval(animate);
+ delete core.animateFrame.asyncId[animate];
+ cb();
+ return;
+ }
+ core.maps._drawBlockInfo(blockInfo, x, y);
+ },
+ core.status.replay.speed == 24
+ ? 1
+ : speed / Math.max(core.status.replay.speed, 1)
+ );
+
+ core.animateFrame.lastAsyncId = animate;
+ core.animateFrame.asyncId[animate] = cb;
+};
////// 开一个门后触发的事件 //////
events.prototype.afterOpenDoor = function (doorId, x, y) {
- return this.eventdata.afterOpenDoor(doorId, x, y);
-}
+ return this.eventdata.afterOpenDoor(doorId, x, y);
+};
events.prototype._sys_getItem = function (data, callback) {
- this.getItem(data.event.id, 1, data.x, data.y, false, callback);
-}
+ this.getItem(data.event.id, 1, data.x, data.y, false, callback);
+};
////// 获得某个物品 //////
events.prototype.getItem = function (id, num, x, y, isGentleClick, callback) {
- if (num == null) num = 1;
- var itemCls = core.material.items[id].cls;
- core.removeBlock(x, y);
- core.items.getItemEffect(id, num);
- var text = '获得 ' + core.material.items[id].name;
- if (num > 1) text += "x" + num;
- if (itemCls === 'items' && num == 1) text += core.items.getItemEffectTip(id);
- core.drawTip(text, id);
+ if (num == null) num = 1;
+ var itemCls = core.material.items[id].cls;
+ core.removeBlock(x, y);
+ core.items.getItemEffect(id, num);
+ var text = "获得 " + core.material.items[id].name;
+ if (num > 1) text += "x" + num;
+ if (itemCls === "items" && num == 1) text += core.items.getItemEffectTip(id);
+ core.drawTip(text, id);
- // --- 首次获得道具的提示
- if (!core.hasFlag("__itemHint__")) core.setFlag("__itemHint__", []);
- var itemHint = core.getFlag("__itemHint__");
- if (core.flags.itemFirstText && itemHint.indexOf(id) < 0 && itemCls != 'items') {
- var hint = core.material.items[id].text || "该道具暂无描述";
- try {
- hint = core.replaceText(hint);
- } catch (e) { }
- if (!core.status.event.id || core.status.event.id == 'action') {
- core.insertAction("\t[" + core.material.items[id].name + "," + id + "]" + hint + "\n"
- + (id.endsWith('Key') ? "(钥匙类道具,遇到对应的门时自动打开)"
- : itemCls == 'tools' ? "(消耗类道具,请按T在道具栏使用)"
- : itemCls == 'constants' ? "(永久类道具,请按T在道具栏使用)"
- : itemCls == 'equips' ? "(装备类道具,请按Q在装备栏进行装备)" : ""));
- }
- itemHint.push(id);
+ // --- 首次获得道具的提示
+ if (!core.hasFlag("__itemHint__")) core.setFlag("__itemHint__", []);
+ var itemHint = core.getFlag("__itemHint__");
+ if (
+ core.flags.itemFirstText &&
+ itemHint.indexOf(id) < 0 &&
+ itemCls != "items"
+ ) {
+ var hint = core.material.items[id].text || "该道具暂无描述";
+ try {
+ hint = core.replaceText(hint);
+ } catch (e) {}
+ if (!core.status.event.id || core.status.event.id == "action") {
+ core.insertAction(
+ "\t[" +
+ core.material.items[id].name +
+ "," +
+ id +
+ "]" +
+ hint +
+ "\n" +
+ (id.endsWith("Key")
+ ? "(钥匙类道具,遇到对应的门时自动打开)"
+ : itemCls == "tools"
+ ? "(消耗类道具,请按T在道具栏使用)"
+ : itemCls == "constants"
+ ? "(永久类道具,请按T在道具栏使用)"
+ : itemCls == "equips"
+ ? "(装备类道具,请按Q在装备栏进行装备)"
+ : "")
+ );
}
+ itemHint.push(id);
+ }
- this.afterGetItem(id, x, y, isGentleClick);
- if (callback) callback();
-}
+ this.afterGetItem(id, x, y, isGentleClick);
+ if (callback) callback();
+};
events.prototype.afterGetItem = function (id, x, y, isGentleClick) {
- this.eventdata.afterGetItem(id, x, y, isGentleClick);
-}
+ this.eventdata.afterGetItem(id, x, y, isGentleClick);
+};
////// 获得面前的物品(轻按) //////
events.prototype.getNextItem = function (noRoute) {
- if (core.isMoving() || !core.flags.enableGentleClick) return false;
- if (this._canGetNextItem()) return this._getNextItem(null, noRoute);
+ if (core.isMoving() || !core.flags.enableGentleClick) return false;
+ if (this._canGetNextItem()) return this._getNextItem(null, noRoute);
- var directions = ["up", "down", "left", "right"].filter(function (dir) {
- return core.events._canGetNextItem(dir);
- });
- return directions.length > 0 ? this._getNextItem(directions[0], noRoute) : false;
-}
+ var directions = ["up", "down", "left", "right"].filter(function (dir) {
+ return core.events._canGetNextItem(dir);
+ });
+ return directions.length > 0
+ ? this._getNextItem(directions[0], noRoute)
+ : false;
+};
events.prototype._canGetNextItem = function (direction) {
- direction = direction || core.getHeroLoc('direction');
- if (!core.canMoveHero(null, null, direction)) return;
- var nx = core.getHeroLoc('x') + core.utils.scan[direction].x;
- var ny = core.getHeroLoc('y') + core.utils.scan[direction].y;
- var block = core.getBlock(nx, ny);
- return block != null && !block.event.script && !block.event.event && block.event.trigger == 'getItem';
-}
+ direction = direction || core.getHeroLoc("direction");
+ if (!core.canMoveHero(null, null, direction)) return;
+ var nx = core.getHeroLoc("x") + core.utils.scan[direction].x;
+ var ny = core.getHeroLoc("y") + core.utils.scan[direction].y;
+ var block = core.getBlock(nx, ny);
+ return (
+ block != null &&
+ !block.event.script &&
+ !block.event.event &&
+ block.event.trigger == "getItem"
+ );
+};
events.prototype._getNextItem = function (direction, noRoute) {
- direction = direction || core.getHeroLoc('direction');
- var nx = core.getHeroLoc('x') + core.utils.scan[direction].x;
- var ny = core.getHeroLoc('y') + core.utils.scan[direction].y;
- if (!noRoute) core.status.route.push("getNext");
- this.getItem(core.getBlockId(nx, ny), 1, nx, ny, true);
- return true;
-}
+ direction = direction || core.getHeroLoc("direction");
+ var nx = core.getHeroLoc("x") + core.utils.scan[direction].x;
+ var ny = core.getHeroLoc("y") + core.utils.scan[direction].y;
+ if (!noRoute) core.status.route.push("getNext");
+ this.getItem(core.getBlockId(nx, ny), 1, nx, ny, true);
+ return true;
+};
events.prototype._sys_changeFloor = function (data, callback) {
- data = data.event.data;
- var heroLoc = {};
- if (data.loc) heroLoc = { 'x': data.loc[0], 'y': data.loc[1] };
- if (data.direction) heroLoc.direction = data.direction;
- if (core.status.event.id != 'action') core.status.event.id = null;
- core.changeFloor(data.floorId, data.stair, heroLoc, data.time, function () {
- core.replay();
- if (callback) callback();
- });
-}
+ data = data.event.data;
+ var heroLoc = {};
+ if (data.loc) heroLoc = { x: data.loc[0], y: data.loc[1] };
+ if (data.direction) heroLoc.direction = data.direction;
+ if (core.status.event.id != "action") core.status.event.id = null;
+ core.changeFloor(data.floorId, data.stair, heroLoc, data.time, function () {
+ core.replay();
+ if (callback) callback();
+ });
+};
////// 楼层切换 //////
-events.prototype.changeFloor = function (floorId, stair, heroLoc, time, callback) {
- var info = this._changeFloor_getInfo(floorId, stair, heroLoc, time);
- if (info == null) {
- if (callback) callback();
- return;
- }
- floorId = info.floorId;
- info.locked = core.status.lockControl;
+events.prototype.changeFloor = function (
+ floorId,
+ stair,
+ heroLoc,
+ time,
+ callback
+) {
+ var info = this._changeFloor_getInfo(floorId, stair, heroLoc, time);
+ if (info == null) {
+ if (callback) callback();
+ return;
+ }
+ floorId = info.floorId;
+ info.locked = core.status.lockControl;
- core.dom.floorNameLabel.innerText = core.status.maps[floorId].title;
- core.lockControl();
- core.stopAutomaticRoute();
- core.clearContinueAutomaticRoute();
- core.status.replay.animate = true;
- clearInterval(core.interval.onDownInterval);
- core.interval.onDownInterval = 'tmp';
+ core.dom.floorNameLabel.innerText = core.status.maps[floorId].title;
+ core.lockControl();
+ core.stopAutomaticRoute();
+ core.clearContinueAutomaticRoute();
+ core.status.replay.animate = true;
+ clearInterval(core.interval.onDownInterval);
+ core.interval.onDownInterval = "tmp";
- this._changeFloor_beforeChange(info, callback);
-}
+ this._changeFloor_beforeChange(info, callback);
+};
-events.prototype._changeFloor_getInfo = function (floorId, stair, heroLoc, time) {
- floorId = floorId || core.status.floorId;
- if (floorId == ':before') {
- var index = core.floorIds.indexOf(core.status.floorId);
- if (index > 0) floorId = core.floorIds[index - 1];
- else floorId = core.status.floorId;
- }
- else if (floorId == ':next') {
- var index = core.floorIds.indexOf(core.status.floorId);
- if (index < core.floorIds.length - 1) floorId = core.floorIds[index + 1];
- else floorId = core.status.floorId;
- } else if (floorId == ':now') {
- floorId = core.status.floorId;
- }
- if (!core.status.maps[floorId]) {
- console.error("不存在的楼层:" + floorId);
- return null;
- }
+events.prototype._changeFloor_getInfo = function (
+ floorId,
+ stair,
+ heroLoc,
+ time
+) {
+ floorId = floorId || core.status.floorId;
+ if (floorId == ":before") {
+ var index = core.floorIds.indexOf(core.status.floorId);
+ if (index > 0) floorId = core.floorIds[index - 1];
+ else floorId = core.status.floorId;
+ } else if (floorId == ":next") {
+ var index = core.floorIds.indexOf(core.status.floorId);
+ if (index < core.floorIds.length - 1) floorId = core.floorIds[index + 1];
+ else floorId = core.status.floorId;
+ } else if (floorId == ":now") {
+ floorId = core.status.floorId;
+ }
+ if (!core.status.maps[floorId]) {
+ console.error("不存在的楼层:" + floorId);
+ return null;
+ }
- if (main.mode != 'play' || core.isReplaying()) time = 0;
- if (time == null) time = core.values.floorChangeTime;
- time /= 20;
+ if (main.mode != "play" || core.isReplaying()) time = 0;
+ if (time == null) time = core.values.floorChangeTime;
+ time /= 20;
- return {
- floorId: floorId,
- time: time,
- heroLoc: core.clone(this._changeFloor_getHeroLoc(floorId, stair, heroLoc))
- };
-}
+ return {
+ floorId: floorId,
+ time: time,
+ heroLoc: core.clone(this._changeFloor_getHeroLoc(floorId, stair, heroLoc)),
+ };
+};
events.prototype._changeFloor_getHeroLoc = function (floorId, stair, heroLoc) {
- if (!heroLoc)
- heroLoc = core.clone(core.status.hero.loc);
- if (stair) {
- // --- 对称
- if (stair == ':now')
- heroLoc = core.clone(core.status.hero.loc);
- else if (stair == ':symmetry') {
- heroLoc.x = core.bigmap.width - 1 - core.getHeroLoc('x');
- heroLoc.y = core.bigmap.height - 1 - core.getHeroLoc('y');
- }
- else if (stair == ':symmetry_x')
- heroLoc.x = core.bigmap.width - 1 - core.getHeroLoc('x');
- else if (stair == ':symmetry_y')
- heroLoc.y = core.bigmap.height - 1 - core.getHeroLoc('y');
- // 检查该层地图的 upFloor & downFloor & flyPoint
- else if (core.status.maps[floorId][stair]) {
- heroLoc.x = core.status.maps[floorId][stair][0];
- heroLoc.y = core.status.maps[floorId][stair][1];
- }
- else {
- core.extractBlocks(floorId);
- var blocks = core.status.maps[floorId].blocks;
- for (var i in blocks) {
- if (!blocks[i].disable && blocks[i].event.id === stair) {
- heroLoc.x = blocks[i].x;
- heroLoc.y = blocks[i].y;
- break;
- }
- }
+ if (!heroLoc) heroLoc = core.clone(core.status.hero.loc);
+ if (stair) {
+ // --- 对称
+ if (stair == ":now") heroLoc = core.clone(core.status.hero.loc);
+ else if (stair == ":symmetry") {
+ heroLoc.x = core.bigmap.width - 1 - core.getHeroLoc("x");
+ heroLoc.y = core.bigmap.height - 1 - core.getHeroLoc("y");
+ } else if (stair == ":symmetry_x")
+ heroLoc.x = core.bigmap.width - 1 - core.getHeroLoc("x");
+ else if (stair == ":symmetry_y")
+ heroLoc.y = core.bigmap.height - 1 - core.getHeroLoc("y");
+ // 检查该层地图的 upFloor & downFloor & flyPoint
+ else if (core.status.maps[floorId][stair]) {
+ heroLoc.x = core.status.maps[floorId][stair][0];
+ heroLoc.y = core.status.maps[floorId][stair][1];
+ } else {
+ core.extractBlocks(floorId);
+ var blocks = core.status.maps[floorId].blocks;
+ for (var i in blocks) {
+ if (!blocks[i].disable && blocks[i].event.id === stair) {
+ heroLoc.x = blocks[i].x;
+ heroLoc.y = blocks[i].y;
+ break;
}
+ }
}
- ['x', 'y', 'direction'].forEach(function (name) {
- if (heroLoc[name] == null)
- heroLoc[name] = core.getHeroLoc(name);
- });
- return heroLoc;
-}
+ }
+ ["x", "y", "direction"].forEach(function (name) {
+ if (heroLoc[name] == null) heroLoc[name] = core.getHeroLoc(name);
+ });
+ return heroLoc;
+};
events.prototype._changeFloor_beforeChange = function (info, callback) {
- this._changeFloor_playSound();
- // 需要 setTimeout 执行,不然会出错
- window.setTimeout(function () {
- if (info.time == 0)
- core.events._changeFloor_changing(info, callback);
- else
- core.showWithAnimate(core.dom.floorMsgGroup, info.time / 2, function () {
- core.events._changeFloor_changing(info, callback);
- });
- }, 25)
-}
+ this._changeFloor_playSound();
+ // 需要 setTimeout 执行,不然会出错
+ window.setTimeout(function () {
+ if (info.time == 0) core.events._changeFloor_changing(info, callback);
+ else
+ core.showWithAnimate(core.dom.floorMsgGroup, info.time / 2, function () {
+ core.events._changeFloor_changing(info, callback);
+ });
+ }, 25);
+};
events.prototype._changeFloor_playSound = function () {
- // 播放换层音效
- if (core.hasFlag('__fromLoad__')) // 是否是读档造成的切换
- core.playSound('读档');
- else if (core.hasFlag('__isFlying__')) // 是否是楼传造成的切换
- core.playSound('飞行器');
- else
- core.playSound('上下楼');
-}
+ // 播放换层音效
+ if (core.hasFlag("__fromLoad__"))
+ // 是否是读档造成的切换
+ core.playSound("读档");
+ else if (core.hasFlag("__isFlying__"))
+ // 是否是楼传造成的切换
+ core.playSound("飞行器");
+ else core.playSound("上下楼");
+};
events.prototype._changeFloor_changing = function (info, callback) {
- this.changingFloor(info.floorId, info.heroLoc);
- // 回归视角
- var __lockViewport__ = flags.__lockViewport__;
- core.setFlag('__lockViewport__', null);
- core.drawHero();
- core.setFlag('__lockViewport__', __lockViewport__);
+ this.changingFloor(info.floorId, info.heroLoc);
+ // 回归视角
+ var __lockViewport__ = flags.__lockViewport__;
+ core.setFlag("__lockViewport__", null);
+ core.drawHero();
+ core.setFlag("__lockViewport__", __lockViewport__);
- if (info.time == 0)
- this._changeFloor_afterChange(info, callback);
- else
- core.hideWithAnimate(core.dom.floorMsgGroup, info.time / 4, function () {
- core.events._changeFloor_afterChange(info, callback);
- });
-}
+ if (info.time == 0) this._changeFloor_afterChange(info, callback);
+ else
+ core.hideWithAnimate(core.dom.floorMsgGroup, info.time / 4, function () {
+ core.events._changeFloor_afterChange(info, callback);
+ });
+};
events.prototype._changeFloor_afterChange = function (info, callback) {
- if (!info.locked) core.unlockControl();
- core.status.replay.animate = false;
- core.events.afterChangeFloor(info.floorId);
+ if (!info.locked) core.unlockControl();
+ core.status.replay.animate = false;
+ core.events.afterChangeFloor(info.floorId);
- if (callback) callback();
-}
+ if (callback) callback();
+};
events.prototype.changingFloor = function (floorId, heroLoc) {
- this.eventdata.changingFloor(floorId, heroLoc);
-}
+ this.eventdata.changingFloor(floorId, heroLoc);
+};
////// 转换楼层结束的事件 //////
events.prototype.afterChangeFloor = function (floorId) {
- if (main.mode != 'play') return;
- return this.eventdata.afterChangeFloor(floorId);
-}
+ if (main.mode != "play") return;
+ return this.eventdata.afterChangeFloor(floorId);
+};
////// 是否到达过某个楼层 //////
events.prototype.hasVisitedFloor = function (floorId) {
- if (!core.hasFlag("__visited__")) core.setFlag("__visited__", {});
- return core.getFlag("__visited__")[floorId] || false;
-}
+ if (!core.hasFlag("__visited__")) core.setFlag("__visited__", {});
+ return core.getFlag("__visited__")[floorId] || false;
+};
////// 到达某楼层 //////
events.prototype.visitFloor = function (floorId) {
- if (!core.hasFlag("__visited__")) core.setFlag("__visited__", {});
- core.getFlag("__visited__")[floorId] = true;
-}
+ if (!core.hasFlag("__visited__")) core.setFlag("__visited__", {});
+ core.getFlag("__visited__")[floorId] = true;
+};
events.prototype._sys_pushBox = function (data, callback) {
- this.pushBox(data);
- if (callback) callback();
-}
+ this.pushBox(data);
+ if (callback) callback();
+};
////// 推箱子 //////
events.prototype.pushBox = function (data) {
- if (data.event.id != 'box' && data.event.id != 'boxed') return;
+ if (data.event.id != "box" && data.event.id != "boxed") return;
- // 判断还能否前进,看看是否存在事件
- var direction = core.getHeroLoc('direction'),
- nx = data.x + core.utils.scan[direction].x, ny = data.y + core.utils.scan[direction].y;
+ // 判断还能否前进,看看是否存在事件
+ var direction = core.getHeroLoc("direction"),
+ nx = data.x + core.utils.scan[direction].x,
+ ny = data.y + core.utils.scan[direction].y;
- // 检测能否推上去
- if (!core.canMoveHero()) return;
- var canGoDeadZone = core.flags.canGoDeadZone;
- core.flags.canGoDeadZone = true;
- if (!core.canMoveHero(data.x, data.y, direction)) {
- core.flags.canGoDeadZone = canGoDeadZone;
- return;
- }
+ // 检测能否推上去
+ if (!core.canMoveHero()) return;
+ var canGoDeadZone = core.flags.canGoDeadZone;
+ core.flags.canGoDeadZone = true;
+ if (!core.canMoveHero(data.x, data.y, direction)) {
core.flags.canGoDeadZone = canGoDeadZone;
+ return;
+ }
+ core.flags.canGoDeadZone = canGoDeadZone;
- var nextId = core.getBlockId(nx, ny);
- if (nextId != null && nextId != 'flower') return;
+ var nextId = core.getBlockId(nx, ny);
+ if (nextId != null && nextId != "flower") return;
- core.setBlock(nextId == null ? 'box' : 'boxed', nx, ny);
+ core.setBlock(nextId == null ? "box" : "boxed", nx, ny);
- if (data.event.id == 'box')
- core.removeBlock(data.x, data.y);
- else
- core.setBlock('flower', data.x, data.y);
- // 勇士前进一格,然后触发推箱子后事件
- core.insertAction([
- { "type": "moveAction" },
- { "type": "function", "function": "function() { core.afterPushBox(); }" }
- ]);
-}
+ if (data.event.id == "box") core.removeBlock(data.x, data.y);
+ else core.setBlock("flower", data.x, data.y);
+ // 勇士前进一格,然后触发推箱子后事件
+ core.insertAction([
+ { type: "moveAction" },
+ { type: "function", function: "function() { core.afterPushBox(); }" },
+ ]);
+};
////// 推箱子后的事件 //////
events.prototype.afterPushBox = function () {
- return this.eventdata.afterPushBox();
-}
+ return this.eventdata.afterPushBox();
+};
events.prototype._sys_ski = function (data, callback) {
- core.insertAction(["V2.6后,请将滑冰放在背景层!"], data.x, data.y);
- if (callback) callback();
-}
+ core.insertAction(["V2.6后,请将滑冰放在背景层!"], data.x, data.y);
+ if (callback) callback();
+};
/// 当前是否在冰上
events.prototype.onSki = function (number) {
- if (number == null) number = core.getBgNumber();
- var block = core.getBlockByNumber(number);
- return block && block.event && block.event.trigger == 'ski';
-}
+ if (number == null) number = core.getBgNumber();
+ var block = core.getBlockByNumber(number);
+ return block && block.event && block.event.trigger == "ski";
+};
events.prototype._sys_action = function (data, callback) {
- var ev = core.clone(data.event.data), ex = data.x, ey = data.y;
- // 检查是否需要改变朝向
- if (ex == core.nextX() && ey == core.nextY()) {
- var dir = core.turnDirection(":back");
- var id = data.event.id, toId = (data.event.faceIds || {})[dir];
- if (toId && id != toId) {
- var number = core.getNumberById(toId);
- if (number > 0)
- core.setBlock(number, ex, ey);
- }
+ var ev = core.clone(data.event.data),
+ ex = data.x,
+ ey = data.y;
+ // 检查是否需要改变朝向
+ if (ex == core.nextX() && ey == core.nextY()) {
+ var dir = core.turnDirection(":back");
+ var id = data.event.id,
+ toId = (data.event.faceIds || {})[dir];
+ if (toId && id != toId) {
+ var number = core.getNumberById(toId);
+ if (number > 0) core.setBlock(number, ex, ey);
}
- this.insertAction(ev, ex, ey, callback);
-}
+ }
+ this.insertAction(ev, ex, ey, callback);
+};
events.prototype._sys_custom = function (data, callback) {
- core.insertAction(["请使用\r[yellow]core.registerSystemEvent('custom', func)\r来处理自己添加的系统触发器!"],
- data.x, data.y, callback);
-}
+ core.insertAction(
+ [
+ "请使用\r[yellow]core.registerSystemEvent('custom', func)\r来处理自己添加的系统触发器!",
+ ],
+ data.x,
+ data.y,
+ callback
+ );
+};
// ------ 自定义事件的处理 ------ //
@@ -933,2856 +1044,3552 @@ events.prototype._sys_custom = function (data, callback) {
// type为事件名,func为事件的处理函数,可接受(data, x, y, prefix)参数
// data为事件内容,x和y为当前点坐标(可为null),prefix为当前点前缀
events.prototype.registerEvent = function (type, func) {
- this.actions[type] = func;
-}
+ this.actions[type] = func;
+};
////// 注销一个自定义事件
events.prototype.unregisterEvent = function (type) {
- delete this.actions[type];
-}
+ delete this.actions[type];
+};
////// 执行一个自定义事件
events.prototype.doEvent = function (data, x, y, prefix) {
- var type = data.type;
- if (this.actions[type]) {
- try {
- return core.doFunc(this.actions[type], this, data, x, y, prefix);
- }
- catch (e) {
- console.error(e);
- console.error("ERROR in actions[" + type + "]");
- }
+ var type = data.type;
+ if (this.actions[type]) {
+ try {
+ return core.doFunc(this.actions[type], this, data, x, y, prefix);
+ } catch (e) {
+ console.error(e);
+ console.error("ERROR in actions[" + type + "]");
}
- if (this["_action_" + type]) return this["_action_" + type](data, x, y, prefix);
- core.insertAction("未知的自定义事件: " + type + "!");
- core.doAction();
-}
+ }
+ if (this["_action_" + type])
+ return this["_action_" + type](data, x, y, prefix);
+ core.insertAction("未知的自定义事件: " + type + "!");
+ core.doAction();
+};
events.prototype.setEvents = function (list, x, y, callback) {
- var data = core.status.event.data || {};
- if (list) {
- var l = core.clone(list);
- if (!(l instanceof Array)) l = [l];
- l.push({ "type": "_label" });
- data.list = [{ todo: l, total: core.clone(l), condition: "false" }];
- // 结束所有正在执行的自动事件
- if (list.length == 0) {
- core.status.autoEvents.forEach(function (autoEvent) {
- core.autoEventExecuting(autoEvent.symbol, false);
- });
- }
+ var data = core.status.event.data || {};
+ if (list) {
+ var l = core.clone(list);
+ if (!(l instanceof Array)) l = [l];
+ l.push({ type: "_label" });
+ data.list = [{ todo: l, total: core.clone(l), condition: "false" }];
+ // 结束所有正在执行的自动事件
+ if (list.length == 0) {
+ core.status.autoEvents.forEach(function (autoEvent) {
+ core.autoEventExecuting(autoEvent.symbol, false);
+ });
}
- if (x != null) data.x = x;
- if (y != null) data.y = y;
- if (callback) data.callback = callback;
- if (!data.appendingEvents) data.appendingEvents = [];
- if (!data.locStack) data.locStack = [];
- core.status.event.id = 'action';
- core.status.event.data = data;
-}
+ }
+ if (x != null) data.x = x;
+ if (y != null) data.y = y;
+ if (callback) data.callback = callback;
+ if (!data.appendingEvents) data.appendingEvents = [];
+ if (!data.locStack) data.locStack = [];
+ core.status.event.id = "action";
+ core.status.event.data = data;
+};
////// 开始执行一系列自定义事件 //////
events.prototype.startEvents = function (list, x, y, callback) {
- if (!list) return;
- if (!(list instanceof Array)) {
- list = [list];
- }
- this.setEvents(list, x, y, callback);
- // 停止勇士
- core.waitHeroToStop(function () {
- core.lockControl();
- core.doAction();
- });
-}
+ if (!list) return;
+ if (!(list instanceof Array)) {
+ list = [list];
+ }
+ this.setEvents(list, x, y, callback);
+ // 停止勇士
+ core.waitHeroToStop(function () {
+ core.lockControl();
+ core.doAction();
+ });
+};
////// 执行当前自定义事件列表中的下一个事件 //////
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();
- data.floorId = data.floorId || floorId;
- core.status.event.data.type = data.type;
- this.doEvent(data, x, y, prefix);
- return;
-}
+ // 清空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();
+ data.floorId = data.floorId || floorId;
+ core.status.event.data.type = data.type;
+ this.doEvent(data, x, y, prefix);
+ return;
+};
events.prototype._doAction_finishEvents = function () {
- if (core.status.event.id != 'action') return true;
- // 事件处理完毕
- if (core.status.event.data.list.length == 0) {
- // 检测并执行延迟自动事件
- if (core.status.event.data.appendingEvents.length > 0) {
- this.setEvents(core.status.event.data.appendingEvents.shift());
- return false;
- }
- var callback = core.status.event.data.callback;
- core.ui.closePanel();
- if (callback) callback();
- core.replay();
- return true;
+ if (core.status.event.id != "action") return true;
+ // 事件处理完毕
+ if (core.status.event.data.list.length == 0) {
+ // 检测并执行延迟自动事件
+ if (core.status.event.data.appendingEvents.length > 0) {
+ this.setEvents(core.status.event.data.appendingEvents.shift());
+ return false;
}
- return false;
-}
+ var callback = core.status.event.data.callback;
+ core.ui.closePanel();
+ if (callback) callback();
+ core.replay();
+ return true;
+ }
+ return false;
+};
events.prototype._popEvents = function (current, prefix) {
- if (current.todo.length == 0) { // current list is empty
- if (core.calValue(current.condition, prefix)) { // check condition
- current.todo = core.clone(current.total);
- }
- else {
- core.status.event.data.list.shift(); // remove stack
- }
- core.doAction();
- return true;
+ if (current.todo.length == 0) {
+ // current list is empty
+ if (core.calValue(current.condition, prefix)) {
+ // check condition
+ current.todo = core.clone(current.total);
+ } else {
+ core.status.event.data.list.shift(); // remove stack
}
- return false;
-}
+ core.doAction();
+ return true;
+ }
+ return false;
+};
////// 往当前事件列表之前或之后添加一个或多个事件 //////
events.prototype.insertAction = function (action, x, y, callback, addToLast) {
- if (core.hasFlag("__statistics__")) return;
- if (core.status.gameOver) return;
- if (!action) return;
- core.clearRouteFolding();
+ if (core.hasFlag("__statistics__")) return;
+ if (core.status.gameOver) return;
+ if (!action) return;
+ core.clearRouteFolding();
- action = this.precompile(action);
+ action = this.precompile(action);
- if (core.status.event.id != 'action') {
- this.startEvents(action, x, y, callback);
- }
- else {
- if (addToLast) {
- var list = core.status.event.data.list[0].todo;
- var index = 0;
- for (var index = 0; index < list.length; index++) {
- if (list[index].type == '_label') {
- list.splice(index, 0, action);
- break;
- }
- }
+ if (core.status.event.id != "action") {
+ this.startEvents(action, x, y, callback);
+ } else {
+ if (addToLast) {
+ var list = core.status.event.data.list[0].todo;
+ var index = 0;
+ for (var index = 0; index < list.length; index++) {
+ if (list[index].type == "_label") {
+ list.splice(index, 0, action);
+ break;
}
- else core.unshift(core.status.event.data.list[0].todo, action);
- this.setEvents(null, x, y, callback);
- }
-}
+ }
+ } else core.unshift(core.status.event.data.list[0].todo, action);
+ this.setEvents(null, x, y, callback);
+ }
+};
////// 往当前事件列表之前或之后添加一个公共事件 //////
-events.prototype.insertCommonEvent = function (name, args, x, y, callback, addToLast) {
- var commonEvent = this.getCommonEvent(name);
- if (!commonEvent) {
- if (callback) callback();
- return;
- }
+events.prototype.insertCommonEvent = function (
+ name,
+ args,
+ x,
+ y,
+ callback,
+ addToLast
+) {
+ var commonEvent = this.getCommonEvent(name);
+ if (!commonEvent) {
+ if (callback) callback();
+ return;
+ }
- // 设置参数
- core.setFlag('arg0', name);
- if (args instanceof Array) {
- for (var i = 0; i < args.length; ++i) {
- try {
- if (args[i] != null)
- core.setFlag('arg' + (i + 1), args[i]);
- } catch (ee) { console.error(ee) }
- }
+ // 设置参数
+ core.setFlag("arg0", name);
+ if (args instanceof Array) {
+ for (var i = 0; i < args.length; ++i) {
+ try {
+ if (args[i] != null) core.setFlag("arg" + (i + 1), args[i]);
+ } catch (ee) {
+ console.error(ee);
+ }
}
+ }
- this.insertAction({ "type": "dowhile", "condition": "false", "data": commonEvent }, x, y, callback, addToLast);
-}
+ this.insertAction(
+ { type: "dowhile", condition: "false", data: commonEvent },
+ x,
+ y,
+ callback,
+ addToLast
+ );
+};
////// 获得一个公共事件 //////
events.prototype.getCommonEvent = function (name) {
- if (!name || typeof name !== 'string') return null;
- return this.commonEvent[name] || null;
-}
+ if (!name || typeof name !== "string") return null;
+ return this.commonEvent[name] || null;
+};
////// 恢复一个事件 //////
events.prototype.recoverEvents = function (data) {
- if (data) {
- core.ui.closePanel();
- core.lockControl();
- core.status.event.id = 'action';
- core.status.event.data = data;
- setTimeout(function () {
- core.doAction();
- }, 30);
- return true;
- }
- return false;
-}
+ if (data) {
+ core.ui.closePanel();
+ core.lockControl();
+ core.status.event.id = "action";
+ core.status.event.data = data;
+ setTimeout(function () {
+ core.doAction();
+ }, 30);
+ return true;
+ }
+ return false;
+};
////// 检测自动事件 //////
events.prototype.checkAutoEvents = function () {
- // 只有在无操作或事件流中才能执行自动事件!
- if (!core.isPlaying() || (core.status.lockControl && core.status.event.id != 'action')) return;
- if (core.hasFlag('__doNotCheckAutoEvents__')) return;
- var todo = [], delay = [];
- core.status.autoEvents.forEach(function (autoEvent) {
- var symbol = autoEvent.symbol, x = autoEvent.x, y = autoEvent.y, floorId = autoEvent.floorId;
- // 不在当前楼层 or 已经执行过 or 已被分区 or 正在执行中
- if (autoEvent.currentFloor && floorId != core.status.floorId) return;
- if (!autoEvent.multiExecute && core.autoEventExecuted(symbol)) return;
- if ((flags.__removed__ || []).indexOf(floorId) >= 0) return;
- if (core.autoEventExecuting(symbol)) return;
- var prefix = floorId + "@" + x + "@" + y;
- try {
- if (!core.calValue(autoEvent.condition, prefix)) return;
- } catch (e) {
- return;
- }
-
- core.autoEventExecuting(symbol, true);
- core.autoEventExecuted(symbol, true);
-
- var event;
- if (x == null && y == null) {
- event = [
- // 用do-while(0)包一层防止break影响事件流
- { "type": "dowhile", "condition": "false", "data": autoEvent.data },
- {
- "type": "function", "function":
- "function() { core.autoEventExecuting('" + symbol + "', false); }"
- }
- ];
- } else {
- event = [
- {
- "type": "function", "function":
- "function() { core.pushEventLoc(" + x + ", " + y + ", '" + floorId + "' ); }"
- },
- // 用do-while(0)包一层防止break影响事件流
- { "type": "dowhile", "condition": "false", "data": autoEvent.data },
- {
- "type": "function", "function":
- "function() { core.popEventLoc(); core.autoEventExecuting('" + symbol + "', false); }"
- }
- ];
- }
-
- if (autoEvent.delayExecute)
- delay.push(event);
- else
- core.push(todo, event);
- });
-
- if (todo.length == 0 && delay.length == 0) return;
-
- if (core.status.event.id == 'action' || todo.length > 0) {
- core.insertAction(todo);
- core.push(core.status.event.data.appendingEvents, delay);
- } else {
- core.insertAction(delay[0]);
- if (delay.length > 0) {
- core.insertAction(delay.slice(1));
- }
+ // 只有在无操作或事件流中才能执行自动事件!
+ if (
+ !core.isPlaying() ||
+ (core.status.lockControl && core.status.event.id != "action")
+ )
+ return;
+ if (core.hasFlag("__doNotCheckAutoEvents__")) return;
+ var todo = [],
+ delay = [];
+ core.status.autoEvents.forEach(function (autoEvent) {
+ var symbol = autoEvent.symbol,
+ x = autoEvent.x,
+ y = autoEvent.y,
+ floorId = autoEvent.floorId;
+ // 不在当前楼层 or 已经执行过 or 已被分区 or 正在执行中
+ if (autoEvent.currentFloor && floorId != core.status.floorId) return;
+ if (!autoEvent.multiExecute && core.autoEventExecuted(symbol)) return;
+ if ((flags.__removed__ || []).indexOf(floorId) >= 0) return;
+ if (core.autoEventExecuting(symbol)) return;
+ var prefix = floorId + "@" + x + "@" + y;
+ try {
+ if (!core.calValue(autoEvent.condition, prefix)) return;
+ } catch (e) {
+ return;
}
-}
+ core.autoEventExecuting(symbol, true);
+ core.autoEventExecuted(symbol, true);
+
+ var event;
+ if (x == null && y == null) {
+ event = [
+ // 用do-while(0)包一层防止break影响事件流
+ { type: "dowhile", condition: "false", data: autoEvent.data },
+ {
+ type: "function",
+ function:
+ "function() { core.autoEventExecuting('" + symbol + "', false); }",
+ },
+ ];
+ } else {
+ event = [
+ {
+ type: "function",
+ function:
+ "function() { core.pushEventLoc(" +
+ x +
+ ", " +
+ y +
+ ", '" +
+ floorId +
+ "' ); }",
+ },
+ // 用do-while(0)包一层防止break影响事件流
+ { type: "dowhile", condition: "false", data: autoEvent.data },
+ {
+ type: "function",
+ function:
+ "function() { core.popEventLoc(); core.autoEventExecuting('" +
+ symbol +
+ "', false); }",
+ },
+ ];
+ }
+
+ if (autoEvent.delayExecute) delay.push(event);
+ else core.push(todo, event);
+ });
+
+ if (todo.length == 0 && delay.length == 0) return;
+
+ if (core.status.event.id == "action" || todo.length > 0) {
+ core.insertAction(todo);
+ core.push(core.status.event.data.appendingEvents, delay);
+ } else {
+ core.insertAction(delay[0]);
+ if (delay.length > 0) {
+ core.insertAction(delay.slice(1));
+ }
+ }
+};
events.prototype.autoEventExecuting = function (symbol, value) {
- var aei = core.getFlag('__aei__', []);
- if (value == null) return aei.indexOf(symbol) >= 0;
- else {
- aei = aei.filter(function (one) { return one != symbol; });
- if (value) aei.push(symbol);
- core.setFlag('__aei__', aei);
- }
-}
+ var aei = core.getFlag("__aei__", []);
+ if (value == null) return aei.indexOf(symbol) >= 0;
+ else {
+ aei = aei.filter(function (one) {
+ return one != symbol;
+ });
+ if (value) aei.push(symbol);
+ core.setFlag("__aei__", aei);
+ }
+};
events.prototype.autoEventExecuted = function (symbol, value) {
- var aed = core.getFlag('__aed__', []);
- if (value == null) return aed.indexOf(symbol) >= 0;
- else {
- aed = aed.filter(function (one) { return one != symbol; });
- if (value) aed.push(symbol);
- core.setFlag('__aed__', aed);
- }
-}
+ var aed = core.getFlag("__aed__", []);
+ if (value == null) return aed.indexOf(symbol) >= 0;
+ else {
+ aed = aed.filter(function (one) {
+ return one != symbol;
+ });
+ if (value) aed.push(symbol);
+ core.setFlag("__aed__", aed);
+ }
+};
events.prototype.pushEventLoc = function (x, y, floorId) {
- if (core.status.event.id != 'action') return;
- core.status.event.data.locStack.push({
- x: core.status.event.data.x,
- y: core.status.event.data.y,
- floorId: core.status.event.data.floorId
- });
- core.status.event.data.x = x;
- core.status.event.data.y = y;
- core.status.event.data.floorId = floorId;
-}
+ if (core.status.event.id != "action") return;
+ core.status.event.data.locStack.push({
+ x: core.status.event.data.x,
+ y: core.status.event.data.y,
+ floorId: core.status.event.data.floorId,
+ });
+ core.status.event.data.x = x;
+ core.status.event.data.y = y;
+ core.status.event.data.floorId = floorId;
+};
events.prototype.popEventLoc = function () {
- if (core.status.event.id != 'action') return;
- var loc = core.status.event.data.locStack.shift();
- if (loc) {
- core.status.event.data.x = loc.x;
- core.status.event.data.y = loc.y;
- core.status.event.data.floorId = loc.floorId;
- }
-}
+ if (core.status.event.id != "action") return;
+ var loc = core.status.event.data.locStack.shift();
+ if (loc) {
+ core.status.event.data.x = loc.x;
+ core.status.event.data.y = loc.y;
+ core.status.event.data.floorId = loc.floorId;
+ }
+};
events.prototype.precompile = function (data) {
- var array = this.__precompile_getArray();
- if (typeof data == 'string') {
- return this.__precompile_text(data);
- }
- if (data instanceof Array) {
- for (var i = 0; i < data.length; ++i) {
- data[i] = this.precompile(data[i]);
- }
- return data;
- }
- if (data && data.type) {
- if (this["_precompile_" + data.type]) {
- data = this["_precompile_" + data.type](data);
- }
- if (array.texts.indexOf(data.type) >= 0) {
- data.text = this.__precompile_text(data.text);
- }
- if (array.locs.indexOf(data.type) >= 0) {
- data.loc = this.__precompile_array(data.loc);
- }
- if (array.values.indexOf(data.type) >= 0) {
- data.value = core.replaceValue(data.value);
- }
- if (array.uievents.indexOf(data.type) >= 0) {
- data.x = core.replaceValue(data.x);
- data.y = core.replaceValue(data.y);
- data.width = core.replaceValue(data.width);
- data.height = core.replaceValue(data.height);
- }
- if (data.type in array.others) {
- array.others[data.type].forEach(function (field) {
- data[field] = core.replaceValue(data[field]);
- })
- }
+ var array = this.__precompile_getArray();
+ if (typeof data == "string") {
+ return this.__precompile_text(data);
+ }
+ if (data instanceof Array) {
+ for (var i = 0; i < data.length; ++i) {
+ data[i] = this.precompile(data[i]);
}
return data;
-}
+ }
+ if (data && data.type) {
+ if (this["_precompile_" + data.type]) {
+ data = this["_precompile_" + data.type](data);
+ }
+ if (array.texts.indexOf(data.type) >= 0) {
+ data.text = this.__precompile_text(data.text);
+ }
+ if (array.locs.indexOf(data.type) >= 0) {
+ data.loc = this.__precompile_array(data.loc);
+ }
+ if (array.values.indexOf(data.type) >= 0) {
+ data.value = core.replaceValue(data.value);
+ }
+ if (array.uievents.indexOf(data.type) >= 0) {
+ data.x = core.replaceValue(data.x);
+ data.y = core.replaceValue(data.y);
+ data.width = core.replaceValue(data.width);
+ data.height = core.replaceValue(data.height);
+ }
+ if (data.type in array.others) {
+ array.others[data.type].forEach(function (field) {
+ data[field] = core.replaceValue(data[field]);
+ });
+ }
+ }
+ return data;
+};
events.prototype.__precompile_getArray = function () {
- var texts = [
- "text", "autoText", "scrollText", "tip", "textImage", "input", "input2",
- "choices", "confirm", "fillText", "fillBoldText", "drawTextContent"
- ];
- var locs = [
- "show", "hide", "setBlock", "setBlockOpacity", "showFloorImg", "hideFloorImg", "showBgFgMap",
- "hideBgFgMap", "setBgFgBlock", "animate", "setViewport", "move", "jumoHero",
- "changeFloor", "changePos", "showTextImage", "showGif", "openDoor",
- "closeDoor", "battle", "trigger", "insert", "setEnemyOnPoint", "resetEnemyOnPoint"
- ];
- var values = [
- "setValue", "setEnemy", "setEnemyOnPoint", "setEquip", "setFloor", "setGlobalValue",
- ];
- var uievents = [
- "clearMap", "fillText", "fillBoldText", "fillRect", "strokeRect", "fillEllipse", "strokeEllipse",
- "fillArc", "strokeArc", "drawIcon", "drawSelector", "drawBackground",
- ];
- var others = {
- "fillEllipse": ["a", "b", "angle"],
- "strokeEllipse": ["a", "b", "angle"],
- "fillRect": ["radius", "angle"],
- "strokeRect": ["radius", "angle"],
- "fillArc": ["r", "start", "end"],
- "strokeArc": ["r", "start", "end"],
- "drawLine": ["x1", "y1", "x2", "y2"],
- "drawArrow": ["x1", "y1", "x2", "y2"],
- "drawImage": ["x", "y", "w", "h", "x1", "y1", "w1", "h1", "angle"],
- "drawTextContent": ["left", "top"],
- };
- return {
- texts: texts,
- locs: locs,
- values: values,
- uievents: uievents,
- others: others
- };
-}
+ var texts = [
+ "text",
+ "autoText",
+ "scrollText",
+ "tip",
+ "textImage",
+ "input",
+ "input2",
+ "choices",
+ "confirm",
+ "fillText",
+ "fillBoldText",
+ "drawTextContent",
+ ];
+ var locs = [
+ "show",
+ "hide",
+ "setBlock",
+ "setBlockOpacity",
+ "showFloorImg",
+ "hideFloorImg",
+ "showBgFgMap",
+ "hideBgFgMap",
+ "setBgFgBlock",
+ "animate",
+ "setViewport",
+ "move",
+ "jumoHero",
+ "changeFloor",
+ "changePos",
+ "showTextImage",
+ "showGif",
+ "openDoor",
+ "closeDoor",
+ "battle",
+ "trigger",
+ "insert",
+ "setEnemyOnPoint",
+ "resetEnemyOnPoint",
+ ];
+ var values = [
+ "setValue",
+ "setEnemy",
+ "setEnemyOnPoint",
+ "setEquip",
+ "setFloor",
+ "setGlobalValue",
+ ];
+ var uievents = [
+ "clearMap",
+ "fillText",
+ "fillBoldText",
+ "fillRect",
+ "strokeRect",
+ "fillEllipse",
+ "strokeEllipse",
+ "fillArc",
+ "strokeArc",
+ "drawIcon",
+ "drawSelector",
+ "drawBackground",
+ ];
+ var others = {
+ fillEllipse: ["a", "b", "angle"],
+ strokeEllipse: ["a", "b", "angle"],
+ fillRect: ["radius", "angle"],
+ strokeRect: ["radius", "angle"],
+ fillArc: ["r", "start", "end"],
+ strokeArc: ["r", "start", "end"],
+ drawLine: ["x1", "y1", "x2", "y2"],
+ drawArrow: ["x1", "y1", "x2", "y2"],
+ drawImage: ["x", "y", "w", "h", "x1", "y1", "w1", "h1", "angle"],
+ drawTextContent: ["left", "top"],
+ };
+ return {
+ texts: texts,
+ locs: locs,
+ values: values,
+ uievents: uievents,
+ others: others,
+ };
+};
events.prototype.__precompile_text = function (text) {
- if (typeof text != 'string') return text;
- return text.replace(/\${(.*?)}/g, function (word, value) {
- return "${" + core.replaceValue(value) + "}";
- });
-}
+ if (typeof text != "string") return text;
+ return text.replace(/\${(.*?)}/g, function (word, value) {
+ return "${" + core.replaceValue(value) + "}";
+ });
+};
events.prototype.__precompile_array = function (value) {
- if (typeof value == 'string') {
- value = core.replaceValue(value);
- return value;
- }
- if (value instanceof Array) {
- for (var i = 0; i < value.length; ++i) {
- value[i] = this.__precompile_array(value[i]);
- }
- }
+ if (typeof value == "string") {
+ value = core.replaceValue(value);
return value;
-}
+ }
+ if (value instanceof Array) {
+ for (var i = 0; i < value.length; ++i) {
+ value[i] = this.__precompile_array(value[i]);
+ }
+ }
+ return value;
+};
// ------ 样板提供的的自定义事件 ------ //
events.prototype.__action_checkReplaying = function () {
- if (core.isReplaying()) {
- core.doAction();
- return true;
- }
- return false;
-}
+ if (core.isReplaying()) {
+ core.doAction();
+ return true;
+ }
+ return false;
+};
events.prototype.__action_getLoc = function (loc, x, y, prefix) {
- if (loc) {
- x = core.calValue(loc[0], prefix);
- y = core.calValue(loc[1], prefix);
- }
- return [x, y];
-}
+ if (loc) {
+ x = core.calValue(loc[0], prefix);
+ y = core.calValue(loc[1], prefix);
+ }
+ return [x, y];
+};
events.prototype.__action_getHeroLoc = function (loc, prefix) {
- return this.__action_getLoc(loc, core.getHeroLoc('x'), core.getHeroLoc('y'), prefix);
-}
+ return this.__action_getLoc(
+ loc,
+ core.getHeroLoc("x"),
+ core.getHeroLoc("y"),
+ prefix
+ );
+};
events.prototype.__action_getLoc2D = function (loc, x, y, prefix) {
- if (!(loc && loc[0] instanceof Array))
- loc = [this.__action_getLoc(loc, x, y, prefix)];
- return loc;
-}
+ if (!(loc && loc[0] instanceof Array))
+ loc = [this.__action_getLoc(loc, x, y, prefix)];
+ return loc;
+};
events.prototype.__action_doAsyncFunc = function (isAsync, func) {
- var parameters = Array.prototype.slice.call(arguments, 2);
- if (isAsync) {
- func.apply(this, parameters);
- core.doAction();
- }
- else {
- func.apply(this, parameters.concat(core.doAction));
- }
-}
+ var parameters = Array.prototype.slice.call(arguments, 2);
+ if (isAsync) {
+ func.apply(this, parameters);
+ core.doAction();
+ } else {
+ func.apply(this, parameters.concat(core.doAction));
+ }
+};
events.prototype._action_text = function (data, x, y, prefix) {
- if (this.__action_checkReplaying()) return;
- data.text = core.replaceText(data.text, prefix);
- var ctx = data.code ? ('__text__' + data.code) : null;;
- data.ctx = ctx;
- if (core.getContextByName(ctx) && !data.showAll) {
- core.ui._animateUI('hide', ctx, function () {
- core.ui.drawTextBox(data.text, data);
- core.ui._animateUI('show', ctx, function () {
- if (data.async) core.doAction();
- });
- });
- return;
- }
- core.ui.drawTextBox(data.text, data);
- if (!data.showAll) {
- core.ui._animateUI('show', ctx, function () {
- if (data.async) core.doAction();
- });
- }
-}
+ if (this.__action_checkReplaying()) return;
+ data.text = core.replaceText(data.text, prefix);
+ var ctx = data.code ? "__text__" + data.code : null;
+ data.ctx = ctx;
+ if (core.getContextByName(ctx) && !data.showAll) {
+ core.ui._animateUI("hide", ctx, function () {
+ core.ui.drawTextBox(data.text, data);
+ core.ui._animateUI("show", ctx, function () {
+ if (data.async) core.doAction();
+ });
+ });
+ return;
+ }
+ core.ui.drawTextBox(data.text, data);
+ if (!data.showAll) {
+ core.ui._animateUI("show", ctx, function () {
+ if (data.async) core.doAction();
+ });
+ }
+};
events.prototype._action_moveTextBox = function (data, x, y, prefix) {
- if (this.__action_checkReplaying()) return;
- this.__action_doAsyncFunc(data.async, core.moveTextBox,
- data.code, this.__action_getLoc(data.loc, x, y, prefix), data.relative, data.moveMode, data.time);
-}
+ if (this.__action_checkReplaying()) return;
+ this.__action_doAsyncFunc(
+ data.async,
+ core.moveTextBox,
+ data.code,
+ this.__action_getLoc(data.loc, x, y, prefix),
+ data.relative,
+ data.moveMode,
+ data.time
+ );
+};
events.prototype._action_clearTextBox = function (data, x, y, prefix) {
- if (this.__action_checkReplaying()) return;
- core.clearTextBox(data.code, core.doAction);
-}
+ if (this.__action_checkReplaying()) return;
+ core.clearTextBox(data.code, core.doAction);
+};
events.prototype._action_autoText = function (data, x, y, prefix) {
- if (this.__action_checkReplaying()) return;
- data.text = core.replaceText(data.text, prefix);
- core.ui.drawTextBox(data.text);
- setTimeout(core.doAction, data.time || 3000);
-}
+ if (this.__action_checkReplaying()) return;
+ data.text = core.replaceText(data.text, prefix);
+ core.ui.drawTextBox(data.text);
+ setTimeout(core.doAction, data.time || 3000);
+};
events.prototype._action_scrollText = function (data, x, y, prefix) {
- if (this.__action_checkReplaying()) return;
- data.text = core.replaceText(data.text, prefix);
- this.__action_doAsyncFunc(data.async, core.drawScrollText, data.text, data.time || 5000, data.lineHeight || 1.4);
-}
+ if (this.__action_checkReplaying()) return;
+ data.text = core.replaceText(data.text, prefix);
+ this.__action_doAsyncFunc(
+ data.async,
+ core.drawScrollText,
+ data.text,
+ data.time || 5000,
+ data.lineHeight || 1.4
+ );
+};
events.prototype._action_comment = function (data, x, y, prefix) {
- core.doAction();
-}
+ core.doAction();
+};
events.prototype._action__label = function (data, x, y, prefix) {
- core.doAction();
-}
+ core.doAction();
+};
events.prototype._action_setText = function (data, x, y, prefix) {
- this.setTextAttribute(data);
- core.doAction();
-}
+ this.setTextAttribute(data);
+ core.doAction();
+};
events.prototype._action_tip = function (data, x, y, prefix) {
- core.drawTip(core.replaceText(data.text, prefix), data.icon);
- core.doAction();
-}
+ core.drawTip(core.replaceText(data.text, prefix), data.icon);
+ core.doAction();
+};
events.prototype._action_show = function (data, x, y, prefix) {
- data.loc = this.__action_getLoc2D(data.loc, x, y, prefix);
- if (data.time > 0 && data.floorId == core.status.floorId) {
- this.__action_doAsyncFunc(data.async, core.animateBlock, data.loc, 'show', data.time);
- }
- else {
- data.loc.forEach(function (t) {
- core.showBlock(t[0], t[1], data.floorId);
- });
- core.doAction();
- }
-}
+ data.loc = this.__action_getLoc2D(data.loc, x, y, prefix);
+ if (data.time > 0 && data.floorId == core.status.floorId) {
+ this.__action_doAsyncFunc(
+ data.async,
+ core.animateBlock,
+ data.loc,
+ "show",
+ data.time
+ );
+ } else {
+ data.loc.forEach(function (t) {
+ core.showBlock(t[0], t[1], data.floorId);
+ });
+ core.doAction();
+ }
+};
events.prototype._action_hide = function (data, x, y, prefix) {
- data.loc = this.__action_getLoc2D(data.loc, x, y, prefix);
- if (data.time > 0 && data.floorId == core.status.floorId) {
- this.__action_doAsyncFunc(data.async, core.animateBlock, data.loc, data.remove ? 'remove' : 'hide', data.time);
- }
- else {
- data.loc.forEach(function (t) {
- if (data.remove) core.removeBlock(t[0], t[1], data.floorId);
- else core.hideBlock(t[0], t[1], data.floorId);
- });
- core.doAction();
- }
-}
+ data.loc = this.__action_getLoc2D(data.loc, x, y, prefix);
+ if (data.time > 0 && data.floorId == core.status.floorId) {
+ this.__action_doAsyncFunc(
+ data.async,
+ core.animateBlock,
+ data.loc,
+ data.remove ? "remove" : "hide",
+ data.time
+ );
+ } else {
+ data.loc.forEach(function (t) {
+ if (data.remove) core.removeBlock(t[0], t[1], data.floorId);
+ else core.hideBlock(t[0], t[1], data.floorId);
+ });
+ core.doAction();
+ }
+};
events.prototype._action_setBlock = function (data, x, y, prefix) {
- data.loc = this.__action_getLoc2D(data.loc, x, y, prefix);
- data.time = data.time || 0;
- data.floorId = data.floorId || core.status.floorId;
- if (data.time > 0 && data.floorId == core.status.floorId) {
- this.__action_doAsyncFunc(data.async, core.animateSetBlocks, data.number, data.loc, data.floorId, data.time);
- } else {
- data.loc.forEach(function (loc) {
- core.setBlock(data.number, loc[0], loc[1], data.floorId);
- });
- core.doAction();
- }
-}
+ data.loc = this.__action_getLoc2D(data.loc, x, y, prefix);
+ data.time = data.time || 0;
+ data.floorId = data.floorId || core.status.floorId;
+ if (data.time > 0 && data.floorId == core.status.floorId) {
+ this.__action_doAsyncFunc(
+ data.async,
+ core.animateSetBlocks,
+ data.number,
+ data.loc,
+ data.floorId,
+ data.time
+ );
+ } else {
+ data.loc.forEach(function (loc) {
+ core.setBlock(data.number, loc[0], loc[1], data.floorId);
+ });
+ core.doAction();
+ }
+};
events.prototype._action_setBlockOpacity = function (data, x, y, prefix) {
- data.loc = this.__action_getLoc2D(data.loc, x, y, prefix);
- if (data.time > 0 && data.floorId == core.status.floorId) {
- this.__action_doAsyncFunc(data.async, core.animateBlock, data.loc, data.opacity, data.time);
- }
- else {
- data.loc.forEach(function (t) {
- core.setBlockOpacity(data.opacity, t[0], t[1], data.floorId);
- });
- core.doAction();
- }
-}
+ data.loc = this.__action_getLoc2D(data.loc, x, y, prefix);
+ if (data.time > 0 && data.floorId == core.status.floorId) {
+ this.__action_doAsyncFunc(
+ data.async,
+ core.animateBlock,
+ data.loc,
+ data.opacity,
+ data.time
+ );
+ } else {
+ data.loc.forEach(function (t) {
+ core.setBlockOpacity(data.opacity, t[0], t[1], data.floorId);
+ });
+ core.doAction();
+ }
+};
events.prototype._action_setBlockFilter = function (data, x, y, prefix) {
- data.loc = this.__action_getLoc2D(data.loc, x, y, prefix);
- data.loc.forEach(function (t) {
- core.setBlockFilter(data, t[0], t[1], data.floorId);
- });
- core.doAction();
-}
+ data.loc = this.__action_getLoc2D(data.loc, x, y, prefix);
+ data.loc.forEach(function (t) {
+ core.setBlockFilter(data, t[0], t[1], data.floorId);
+ });
+ core.doAction();
+};
events.prototype._action_turnBlock = function (data, x, y, prefix) {
- data.loc = this.__action_getLoc2D(data.loc, x, y, prefix);
- data.loc.forEach(function (t) {
- core.turnBlock(data.direction, t[0], t[1], data.floorId);
- });
- core.doAction();
-}
+ data.loc = this.__action_getLoc2D(data.loc, x, y, prefix);
+ data.loc.forEach(function (t) {
+ core.turnBlock(data.direction, t[0], t[1], data.floorId);
+ });
+ core.doAction();
+};
events.prototype._action_showFloorImg = function (data, x, y, prefix) {
- core.maps.showFloorImage(this.__action_getLoc2D(data.loc, x, y, prefix), data.floorId, core.doAction);
-}
+ core.maps.showFloorImage(
+ this.__action_getLoc2D(data.loc, x, y, prefix),
+ data.floorId,
+ core.doAction
+ );
+};
events.prototype._action_hideFloorImg = function (data, x, y, prefix) {
- core.maps.hideFloorImage(this.__action_getLoc2D(data.loc, x, y, prefix), data.floorId, core.doAction);
-}
+ core.maps.hideFloorImage(
+ this.__action_getLoc2D(data.loc, x, y, prefix),
+ data.floorId,
+ core.doAction
+ );
+};
events.prototype._action_showBgFgMap = function (data, x, y, prefix) {
- core.maps.showBgFgMap(data.name, this.__action_getLoc2D(data.loc, x, y, prefix), data.floorId, core.doAction)
-}
+ core.maps.showBgFgMap(
+ data.name,
+ this.__action_getLoc2D(data.loc, x, y, prefix),
+ data.floorId,
+ core.doAction
+ );
+};
events.prototype._action_hideBgFgMap = function (data, x, y, prefix) {
- core.maps.hideBgFgMap(data.name, this.__action_getLoc2D(data.loc, x, y, prefix), data.floorId, core.doAction);
-}
+ core.maps.hideBgFgMap(
+ data.name,
+ this.__action_getLoc2D(data.loc, x, y, prefix),
+ data.floorId,
+ core.doAction
+ );
+};
events.prototype._action_setBgFgBlock = function (data, x, y, prefix) {
- data.loc = this.__action_getLoc2D(data.loc, x, y, prefix);
- data.loc.forEach(function (t) {
- core.setBgFgBlock(data.name, data.number, t[0], t[1], data.floorId);
- });
- core.doAction();
-}
+ data.loc = this.__action_getLoc2D(data.loc, x, y, prefix);
+ data.loc.forEach(function (t) {
+ core.setBgFgBlock(data.name, data.number, t[0], t[1], data.floorId);
+ });
+ core.doAction();
+};
events.prototype._action_follow = function (data, x, y, prefix) {
- this.follow(data.name);
- core.doAction();
-}
+ this.follow(data.name);
+ core.doAction();
+};
events.prototype._action_unfollow = function (data, x, y, prefix) {
- this.unfollow(data.name);
- core.doAction();
-}
+ this.unfollow(data.name);
+ core.doAction();
+};
events.prototype._action_animate = function (data, x, y, prefix) {
- if (data.loc == 'hero') {
- this.__action_doAsyncFunc(data.async, core.drawHeroAnimate, data.name);
- } else {
- data.loc = this.__action_getLoc(data.loc, x, y, prefix);
- this.__action_doAsyncFunc(data.async, core.drawAnimate, data.name, data.loc[0], data.loc[1], data.alignWindow);
- }
-}
+ if (data.loc == "hero") {
+ this.__action_doAsyncFunc(data.async, core.drawHeroAnimate, data.name);
+ } else {
+ data.loc = this.__action_getLoc(data.loc, x, y, prefix);
+ this.__action_doAsyncFunc(
+ data.async,
+ core.drawAnimate,
+ data.name,
+ data.loc[0],
+ data.loc[1],
+ data.alignWindow
+ );
+ }
+};
events.prototype._action_stopAnimate = function (data, x, y, prefix) {
- core.stopAnimate(null, data.doCallback);
- core.doAction();
-}
+ core.stopAnimate(null, data.doCallback);
+ core.doAction();
+};
events.prototype._action_setViewport = function (data, x, y, prefix) {
- if (data.dxy != null) {
- data.loc = [core.bigmap.offsetX / 32 + (core.calValue(data.dxy[0], prefix) || 0), core.bigmap.offsetY / 32 + (core.calValue(data.dxy[1], prefix) || 0)];
- } else if (data.loc == null) {
- data.loc = [core.getHeroLoc('x') - core._HALF_WIDTH_, core.getHeroLoc('y') - core._HALF_HEIGHT_];
- } else {
- data.loc = this.__action_getLoc(data.loc, x, y, prefix);
- }
- this.__action_doAsyncFunc(data.async, core.moveViewport, data.loc[0], data.loc[1], data.moveMode, data.time);
-}
+ if (data.dxy != null) {
+ data.loc = [
+ core.bigmap.offsetX / 32 + (core.calValue(data.dxy[0], prefix) || 0),
+ core.bigmap.offsetY / 32 + (core.calValue(data.dxy[1], prefix) || 0),
+ ];
+ } else if (data.loc == null) {
+ data.loc = [
+ core.getHeroLoc("x") - core._HALF_WIDTH_,
+ core.getHeroLoc("y") - core._HALF_HEIGHT_,
+ ];
+ } else {
+ data.loc = this.__action_getLoc(data.loc, x, y, prefix);
+ }
+ this.__action_doAsyncFunc(
+ data.async,
+ core.moveViewport,
+ data.loc[0],
+ data.loc[1],
+ data.moveMode,
+ data.time
+ );
+};
events.prototype._action_lockViewport = function (data, x, y, prefix) {
- core.setFlag('__lockViewport__', data.lock || null);
- core.doAction();
-}
+ core.setFlag("__lockViewport__", data.lock || null);
+ core.doAction();
+};
events.prototype._action_move = function (data, x, y, prefix) {
- var loc = this.__action_getLoc(data.loc, x, y, prefix);
- this.__action_doAsyncFunc(data.async, core.moveBlock, loc[0], loc[1], data.steps, data.time, data.keep);
-}
+ var loc = this.__action_getLoc(data.loc, x, y, prefix);
+ this.__action_doAsyncFunc(
+ data.async,
+ core.moveBlock,
+ loc[0],
+ loc[1],
+ data.steps,
+ data.time,
+ data.keep
+ );
+};
events.prototype._action_moveAction = function (data, x, y, prefix) {
- // 检查下一个点是否可通行
- if (core.canMoveHero()) {
- var nx = core.nextX(), ny = core.nextY();
- // 检查noPass决定是撞击还是移动
- if (core.noPass(nx, ny)) {
- core.insertAction([
- { "type": "trigger", "loc": [nx, ny] }
- ]);
- } else {
- // 先移动一格,然后尝试触发事件
- core.insertAction([
- { "type": "moveHero", "steps": ["forward"] },
- { "type": "function", "function": "function() { core.moveOneStep(core.doAction); }", "async": true },
- { "type": "_label" },
- ]);
- }
+ // 检查下一个点是否可通行
+ if (core.canMoveHero()) {
+ var nx = core.nextX(),
+ ny = core.nextY();
+ // 检查noPass决定是撞击还是移动
+ if (core.noPass(nx, ny)) {
+ core.insertAction([{ type: "trigger", loc: [nx, ny] }]);
+ } else {
+ // 先移动一格,然后尝试触发事件
+ core.insertAction([
+ { type: "moveHero", steps: ["forward"] },
+ {
+ type: "function",
+ function: "function() { core.moveOneStep(core.doAction); }",
+ async: true,
+ },
+ { type: "_label" },
+ ]);
}
- core.doAction();
-}
+ }
+ core.doAction();
+};
events.prototype._action_moveHero = function (data, x, y, prefix) {
- this.__action_doAsyncFunc(data.async, core.eventMoveHero, data.steps, data.time);
-}
+ this.__action_doAsyncFunc(
+ data.async,
+ core.eventMoveHero,
+ data.steps,
+ data.time
+ );
+};
events.prototype._action_jump = function (data, x, y, prefix) {
- var from = this.__action_getLoc(data.from, x, y, prefix), to;
- if (data.dxy) {
- to = [from[0] + (core.calValue(data.dxy[0], prefix) || 0), from[1] + (core.calValue(data.dxy[1], prefix) || 0)];
- } else {
- to = this.__action_getLoc(data.to, x, y, prefix);
- }
- this.__action_doAsyncFunc(data.async, core.jumpBlock, from[0], from[1], to[0], to[1], data.time, data.keep);
-}
+ var from = this.__action_getLoc(data.from, x, y, prefix),
+ to;
+ if (data.dxy) {
+ to = [
+ from[0] + (core.calValue(data.dxy[0], prefix) || 0),
+ from[1] + (core.calValue(data.dxy[1], prefix) || 0),
+ ];
+ } else {
+ to = this.__action_getLoc(data.to, x, y, prefix);
+ }
+ this.__action_doAsyncFunc(
+ data.async,
+ core.jumpBlock,
+ from[0],
+ from[1],
+ to[0],
+ to[1],
+ data.time,
+ data.keep
+ );
+};
events.prototype._precompile_jump = function (data) {
- data.from = this.__precompile_array(data.from);
- data.to = this.__precompile_array(data.to);
- data.dxy = this.__precompile_array(data.dxy);
- return data;
-}
+ data.from = this.__precompile_array(data.from);
+ data.to = this.__precompile_array(data.to);
+ data.dxy = this.__precompile_array(data.dxy);
+ return data;
+};
events.prototype._action_jumpHero = function (data, x, y, prefix) {
- var loc;
- if (data.dxy) {
- loc = [core.getHeroLoc('x') + (core.calValue(data.dxy[0], prefix) || 0), core.getHeroLoc('y') + (core.calValue(data.dxy[1], prefix) || 0)];
- } else {
- loc = this.__action_getHeroLoc(data.loc, prefix);
- }
- this.__action_doAsyncFunc(data.async, core.jumpHero, loc[0], loc[1], data.time);
-}
+ var loc;
+ if (data.dxy) {
+ loc = [
+ core.getHeroLoc("x") + (core.calValue(data.dxy[0], prefix) || 0),
+ core.getHeroLoc("y") + (core.calValue(data.dxy[1], prefix) || 0),
+ ];
+ } else {
+ loc = this.__action_getHeroLoc(data.loc, prefix);
+ }
+ this.__action_doAsyncFunc(
+ data.async,
+ core.jumpHero,
+ loc[0],
+ loc[1],
+ data.time
+ );
+};
events.prototype._action_changeFloor = function (data, x, y, prefix) {
- var loc = this.__action_getHeroLoc(data.loc, prefix);
- var heroLoc = { x: loc[0], y: loc[1], direction: data.direction };
- core.changeFloor(data.floorId, data.stair, heroLoc, data.time, core.doAction);
-}
+ var loc = this.__action_getHeroLoc(data.loc, prefix);
+ var heroLoc = { x: loc[0], y: loc[1], direction: data.direction };
+ core.changeFloor(data.floorId, data.stair, heroLoc, data.time, core.doAction);
+};
events.prototype._action_changePos = function (data, x, y, prefix) {
- core.clearMap('hero');
- if (!data.loc && data.direction) {
- core.setHeroLoc('direction', core.turnDirection(data.direction), true);
- core.drawHero();
- return core.doAction();
- }
-
- var loc = this.__action_getHeroLoc(data.loc, prefix);
- core.setHeroLoc('x', loc[0]);
- core.setHeroLoc('y', loc[1]);
- if (data.direction) core.setHeroLoc('direction', core.turnDirection(data.direction));
+ core.clearMap("hero");
+ if (!data.loc && data.direction) {
+ core.setHeroLoc("direction", core.turnDirection(data.direction), true);
core.drawHero();
- core.doAction();
-}
+ return core.doAction();
+ }
+
+ var loc = this.__action_getHeroLoc(data.loc, prefix);
+ core.setHeroLoc("x", loc[0]);
+ core.setHeroLoc("y", loc[1]);
+ if (data.direction)
+ core.setHeroLoc("direction", core.turnDirection(data.direction));
+ core.drawHero();
+ core.doAction();
+};
events.prototype._action_showImage = function (data, x, y, prefix) {
- if (core.isReplaying()) data.time = 0;
- this.__action_doAsyncFunc(data.async || data.time == 0, core.showImage,
- data.code, data.image + (data.reverse || ''), data.sloc, data.loc, data.opacity, data.time);
-}
+ if (core.isReplaying()) data.time = 0;
+ this.__action_doAsyncFunc(
+ data.async || data.time == 0,
+ core.showImage,
+ data.code,
+ data.image + (data.reverse || ""),
+ data.sloc,
+ data.loc,
+ data.opacity,
+ data.time
+ );
+};
events.prototype._precompile_showImage = function (data) {
- data.sloc = this.__precompile_array(data.sloc);
- data.loc = this.__precompile_array(data.loc);
- return data;
-}
+ data.sloc = this.__precompile_array(data.sloc);
+ data.loc = this.__precompile_array(data.loc);
+ return data;
+};
events.prototype._action_showTextImage = function (data, x, y, prefix) {
- var loc = this.__action_getLoc(data.loc, 0, 0, prefix);
- if (core.isReplaying()) data.time = 0;
- data.text = core.replaceText(data.text, prefix);
- var __tmpName = (Math.random() + "_" + Math.random()).replace(/\./g, "") + ".png";
- core.material.images.images[__tmpName] = core.ui.textImage(data.text);
- this.__action_doAsyncFunc(data.async || data.time == 0, core.showImage,
- data.code, __tmpName + (data.reverse || ""), null, loc, data.opacity, data.time);
- delete core.material.images.images[__tmpName];
-}
+ var loc = this.__action_getLoc(data.loc, 0, 0, prefix);
+ if (core.isReplaying()) data.time = 0;
+ data.text = core.replaceText(data.text, prefix);
+ var __tmpName =
+ (Math.random() + "_" + Math.random()).replace(/\./g, "") + ".png";
+ core.material.images.images[__tmpName] = core.ui.textImage(data.text);
+ this.__action_doAsyncFunc(
+ data.async || data.time == 0,
+ core.showImage,
+ data.code,
+ __tmpName + (data.reverse || ""),
+ null,
+ loc,
+ data.opacity,
+ data.time
+ );
+ delete core.material.images.images[__tmpName];
+};
events.prototype._action_hideImage = function (data, x, y, prefix) {
- if (core.isReplaying()) data.time = 0;
- this.__action_doAsyncFunc(data.async || data.time == 0, core.hideImage, data.code, data.time);
-}
+ if (core.isReplaying()) data.time = 0;
+ this.__action_doAsyncFunc(
+ data.async || data.time == 0,
+ core.hideImage,
+ data.code,
+ data.time
+ );
+};
events.prototype._action_showGif = function (data, x, y, prefix) {
- var loc = this.__action_getLoc(data.loc, 0, 0, prefix);
- this.showGif(data.name, loc[0], loc[1]);
- core.doAction();
-}
+ var loc = this.__action_getLoc(data.loc, 0, 0, prefix);
+ this.showGif(data.name, loc[0], loc[1]);
+ core.doAction();
+};
events.prototype._action_moveImage = function (data, x, y, prefix) {
- if (this.__action_checkReplaying()) return;
- this.__action_doAsyncFunc(data.async, core.moveImage, data.code, data.to, data.opacity, data.moveMode, data.time);
-}
+ if (this.__action_checkReplaying()) return;
+ this.__action_doAsyncFunc(
+ data.async,
+ core.moveImage,
+ data.code,
+ data.to,
+ data.opacity,
+ data.moveMode,
+ data.time
+ );
+};
events.prototype._precompile_moveImage = function (data) {
- data.to = this.__precompile_array(data.to);
- return data;
-}
+ data.to = this.__precompile_array(data.to);
+ return data;
+};
events.prototype._action_rotateImage = function (data, x, y, prefix) {
- if (this.__action_checkReplaying()) return;
- this.__action_doAsyncFunc(data.async, core.rotateImage, data.code, data.center, data.angle, data.moveMode, data.time);
-}
+ if (this.__action_checkReplaying()) return;
+ this.__action_doAsyncFunc(
+ data.async,
+ core.rotateImage,
+ data.code,
+ data.center,
+ data.angle,
+ data.moveMode,
+ data.time
+ );
+};
events.prototype._precompile_rotateImage = function (data) {
- data.center = this.__precompile_array(data.center);
- return data;
-}
+ data.center = this.__precompile_array(data.center);
+ return data;
+};
events.prototype._action_scaleImage = function (data, x, y, prefix) {
- if (this.__action_checkReplaying()) return;
- this.__action_doAsyncFunc(data.async, core.scaleImage, data.code, data.center, data.scale, data.moveMode, data.time);
-}
+ if (this.__action_checkReplaying()) return;
+ this.__action_doAsyncFunc(
+ data.async,
+ core.scaleImage,
+ data.code,
+ data.center,
+ data.scale,
+ data.moveMode,
+ data.time
+ );
+};
events.prototype._precompile_scaleImage = function (data) {
- data.center = this.__precompile_array(data.center);
- return data;
-}
+ data.center = this.__precompile_array(data.center);
+ return data;
+};
events.prototype._action_setCurtain = function (data, x, y, prefix) {
- if (data.async) {
- core.setCurtain(data.color || core.status.thisMap.color, data.time, data.moveMode);
- if (data.color == null || data.keep) core.setFlag('__color__', data.color || null);
+ if (data.async) {
+ core.setCurtain(
+ data.color || core.status.thisMap.color,
+ data.time,
+ data.moveMode
+ );
+ if (data.color == null || data.keep)
+ core.setFlag("__color__", data.color || null);
+ core.doAction();
+ } else {
+ core.setCurtain(
+ data.color || core.status.thisMap.color,
+ data.time,
+ data.moveMode,
+ function () {
+ if (data.color == null || data.keep)
+ core.setFlag("__color__", data.color || null);
core.doAction();
- }
- else {
- core.setCurtain(data.color || core.status.thisMap.color, data.time, data.moveMode, function () {
- if (data.color == null || data.keep) core.setFlag('__color__', data.color || null);
- core.doAction();
- });
- }
-}
+ }
+ );
+ }
+};
events.prototype._action_screenFlash = function (data, x, y, prefix) {
- this.__action_doAsyncFunc(data.async, core.screenFlash, data.color, data.time, data.times, data.moveMode);
-}
+ this.__action_doAsyncFunc(
+ data.async,
+ core.screenFlash,
+ data.color,
+ data.time,
+ data.times,
+ data.moveMode
+ );
+};
events.prototype._action_setWeather = function (data, x, y, prefix) {
- core.setWeather(data.name, data.level);
- if (data.keep && ['rain', 'snow', 'sun', 'fog', 'cloud'].indexOf(data.name) >= 0)
- core.setFlag('__weather__', [data.name, data.level]);
- else core.removeFlag('__weather__');
- core.doAction();
-}
+ core.setWeather(data.name, data.level);
+ if (
+ data.keep &&
+ ["rain", "snow", "sun", "fog", "cloud"].indexOf(data.name) >= 0
+ )
+ core.setFlag("__weather__", [data.name, data.level]);
+ else core.removeFlag("__weather__");
+ core.doAction();
+};
events.prototype._action_openDoor = function (data, x, y, prefix) {
- var loc = this.__action_getLoc(data.loc, x, y, prefix);
- var floorId = data.floorId;
- if (floorId == core.status.floorId) {
- this.__action_doAsyncFunc(data.async, core.openDoor, loc[0], loc[1], data.needKey);
- }
- else {
- core.removeBlock(loc[0], loc[1], floorId);
- core.doAction();
- }
-}
+ var loc = this.__action_getLoc(data.loc, x, y, prefix);
+ var floorId = data.floorId;
+ if (floorId == core.status.floorId) {
+ this.__action_doAsyncFunc(
+ data.async,
+ core.openDoor,
+ loc[0],
+ loc[1],
+ data.needKey
+ );
+ } else {
+ core.removeBlock(loc[0], loc[1], floorId);
+ core.doAction();
+ }
+};
events.prototype._action_closeDoor = function (data, x, y, prefix) {
- var loc = this.__action_getLoc(data.loc, x, y, prefix);
- this.__action_doAsyncFunc(data.async, core.closeDoor, loc[0], loc[1], data.id);
-}
+ var loc = this.__action_getLoc(data.loc, x, y, prefix);
+ this.__action_doAsyncFunc(
+ data.async,
+ core.closeDoor,
+ loc[0],
+ loc[1],
+ data.id
+ );
+};
events.prototype._action_useItem = function (data, x, y, prefix) {
- // 考虑到可能覆盖楼传事件的问题,这里不对fly进行检查。
- if (data.id != 'book' && core.canUseItem(data.id)) {
- core.useItem(data.id, true, core.doAction);
- }
- else {
- core.playSound('操作失败');
- core.drawTip("当前无法使用" + ((core.material.items[data.id] || {}).name || "未知道具"));
- core.doAction();
- }
-}
-
-events.prototype._action_loadEquip = function (data, x, y, prefix) {
- core.loadEquip(data.id);
- core.doAction();
-}
-
-events.prototype._action_unloadEquip = function (data, x, y, prefix) {
- core.unloadEquip(data.pos);
- core.doAction();
-}
-
-events.prototype._action_openShop = function (data, x, y, prefix) {
- core.setShopVisited(data.id, true);
- if (data.open) core.openShop(data.id, true);
- core.doAction();
-}
-
-events.prototype._action_disableShop = function (data, x, y, prefix) {
- core.setShopVisited(data.id, false);
- core.doAction();
-}
-
-events.prototype._action_battle = function (data, x, y, prefix) {
- if (data.id) {
- this.battle(data.id, null, null, true, core.doAction);
- }
- else {
- if (data.floorId != core.status.floorId) {
- core.doAction();
- return;
- }
- var loc = this.__action_getLoc(data.loc, x, y, prefix);
- this.battle(null, loc[0], loc[1], true, core.doAction);
- }
-}
-
-events.prototype._action_trigger = function (data, x, y, prefix) {
- var loc = this.__action_getLoc(data.loc, x, y, prefix);
- this._trigger_inAction(loc[0], loc[1]);
-}
-
-events.prototype._action_insert = function (data, x, y, prefix) {
- if (data.name) { // 公共事件
- core.insertCommonEvent(data.name, data.args);
- }
- else {
- // 设置参数
- if (data.args instanceof Array) {
- for (var i = 0; i < data.args.length; ++i) {
- try {
- if (data.args[i] != null)
- core.setFlag('arg' + (i + 1), data.args[i]);
- } catch (ee) { console.error(ee) }
- }
- }
- var loc = this.__action_getLoc(data.loc, x, y, prefix);
- core.setFlag('arg0', loc);
- var floorId = data.floorId;
- var which = data.which || "events";
- var event = (core.floors[floorId][which] || [])[loc[0] + "," + loc[1]];
- if (event) this.insertAction(event.data || event);
- }
- core.doAction();
-}
-
-events.prototype._action_playBgm = function (data, x, y, prefix) {
- core.playBgm(data.name, data.startTime || 0);
- core.setFlag("__bgm__", data.keep ? data.name : null);
- core.doAction();
-}
-
-events.prototype._action_pauseBgm = function (data, x, y, prefix) {
- core.pauseBgm();
- core.doAction();
-}
-
-events.prototype._action_resumeBgm = function (data, x, y, prefix) {
- core.resumeBgm(data.resume);
- core.doAction();
-}
-
-events.prototype._action_loadBgm = function (data, x, y, prefix) {
- core.loadBgm(data.name);
- core.doAction();
-}
-
-events.prototype._action_freeBgm = function (data, x, y, prefix) {
- core.freeBgm(data.name);
- core.doAction();
-}
-
-events.prototype._action_playSound = function (data, x, y, prefix) {
- if (data.stop) core.stopSound();
- if (data.sync) {
- core.playSound(data.name, data.pitch, core.doAction);
- } else {
- core.playSound(data.name, data.pitch);
- core.doAction();
- }
-}
-
-events.prototype._action_stopSound = function (data, x, y, prefix) {
- core.stopSound();
- core.doAction();
-}
-
-events.prototype._action_setVolume = function (data, x, y, prefix) {
- data.value = core.clamp(parseInt(data.value) / 100, 0, 1);
- core.setFlag("__volume__", data.value);
- this.__action_doAsyncFunc(data.async, core.setVolume, data.value, data.time || 0);
-}
-
-events.prototype._action_setBgmSpeed = function (data, x, y, prefix) {
- core.setBgmSpeed(data.value, data.pitch || false);
- core.doAction();
-}
-
-events.prototype._action_setValue = function (data, x, y, prefix) {
- this.setValue(data.name, data.operator, data.value, prefix);
- if (!data.norefresh) {
- if (core.status.hero.hp <= 0) {
- core.status.hero.hp = 0;
- core.updateStatusBar();
- core.events.lose();
- } else {
- core.updateStatusBar();
- }
- }
- core.doAction();
-}
-
-events.prototype._action_addValue = function (data, x, y, prefix) {
- data.operator = '+=';
- this._action_setValue(data, x, y, prefix);
-}
-
-events.prototype._action_setEnemy = function (data, x, y, prefix) {
- this.setEnemy(data.id, data.name, data.value, data.operator, prefix, data.norefresh);
- core.doAction();
-}
-
-events.prototype._action_setEnemyOnPoint = function (data, x, y, prefix) {
- var loc = this.__action_getLoc2D(data.loc, x, y, prefix);
- loc.forEach(function (one) {
- core.setEnemyOnPoint(one[0], one[1], data.floorId, data.name, data.value, data.operator, prefix, data.norefresh);
- });
- core.doAction();
-}
-
-events.prototype._action_resetEnemyOnPoint = function (data, x, y, prefix) {
- var loc = this.__action_getLoc2D(data.loc, x, y, prefix);
- loc.forEach(function (one) {
- core.resetEnemyOnPoint(one[0], one[1], data.floorId, data.norefresh);
- });
- core.doAction();
-}
-
-events.prototype._precompile_moveEnemyOnPoint = function (data) {
- data.from = this.__precompile_array(data.from);
- data.to = this.__precompile_array(data.to);
- data.dxy = this.__precompile_array(data.dxy);
- return data;
-}
-
-events.prototype._action_moveEnemyOnPoint = function (data, x, y, prefix) {
- var from = this.__action_getLoc(data.from, x, y, prefix), to;
- if (data.dxy) {
- to = [from[0] + (core.calValue(data.dxy[0], prefix) || 0), from[1] + (core.calValue(data.dxy[1], prefix) || 0)];
- } else {
- to = this.__action_getLoc(data.to, x, y, prefix);
- }
- this.moveEnemyOnPoint(from[0], from[1], to[0], to[1], data.floorId, data.norefresh);
- core.doAction();
-}
-
-events.prototype._action_setEquip = function (data, x, y, prefix) {
- core.setEquip(data.id, data.valueType, data.name, data.value, data.operator, prefix);
- core.doAction();
-}
-
-events.prototype._action_setFloor = function (data, x, y, prefix) {
- this.setFloorInfo(data.name, data.value, data.floorId, prefix);
- core.doAction();
-}
-
-events.prototype._action_setGlobalAttribute = function (data, x, y, prefix) {
- this.setGlobalAttribute(data.name, data.value);
- core.doAction();
-}
-
-events.prototype._action_setGlobalValue = function (data, x, y, prefix) {
- core.values[data.name] = data.value;
- core.doAction();
-}
-
-events.prototype._action_setGlobalFlag = function (data, x, y, prefix) {
- this.setGlobalFlag(data.name, data.value);
- core.doAction();
-}
-
-events.prototype._action_setNameMap = function (data, x, y, floorId) {
- this.setNameMap(data.name, data.value);
- core.doAction();
-}
-
-events.prototype._action_setHeroIcon = function (data, x, y, prefix) {
- this.setHeroIcon(data.name, data.noDraw);
- core.doAction();
-}
-
-events.prototype._action_input = function (data, x, y, prefix) {
- this.__action_getInput(core.replaceText(data.text, prefix), false, function (value) {
- value = parseInt(value) || 0; // 允许负整数
- core.status.route.push("input:" + value);
- core.setFlag("input", value);
- core.doAction();
- });
-}
-
-events.prototype._action_input2 = function (data, x, y, prefix) {
- this.__action_getInput(core.replaceText(data.text, prefix), true, function (value) {
- value = value || "";
- core.status.route.push("input2:" + core.encodeBase64(value));
- core.setFlag("input", value);
- core.doAction();
- });
-}
-
-events.prototype.__action_getInput = function (hint, isText, callback) {
- var value, prefix = isText ? "input2:" : "input:";
- if (core.isReplaying()) {
- var action = core.status.replay.toReplay.shift();
- try {
- if (action.indexOf(prefix) != 0) {
- console.warn("警告!当前需要一个 " + prefix + " 项,实际为 " + action);
- core.status.replay.toReplay.unshift(action);
- return callback(isText ? '' : 0);
- }
- if (isText) value = core.decodeBase64(action.substring(7));
- else value = parseInt(action.substring(6));
- callback(value);
- }
- catch (e) {
- core.control._replay_error(action);
- return;
- }
- }
- else {
- core.myprompt(core.replaceText(hint), null, callback);
- }
-}
-
-events.prototype._action_if = function (data, x, y, prefix) {
- if (core.calValue(data.condition, prefix))
- core.events.insertAction(data["true"])
- else
- core.events.insertAction(data["false"])
- core.doAction();
-}
-
-events.prototype._precompile_if = function (data) {
- data.condition = core.replaceValue(data.condition);
- data["true"] = this.precompile(data["true"]);
- data["false"] = this.precompile(data["false"]);
- return data;
-}
-
-events.prototype._action_switch = function (data, x, y, prefix) {
- var key = core.calValue(data.condition, prefix)
- var list = [];
- for (var i = 0; i < data.caseList.length; i++) {
- if (data.caseList[i]._disabled) continue;
- var condition = data.caseList[i]["case"];
- if (condition == "default" || core.calValue(condition, prefix) === key) {
- core.push(list, data.caseList[i].action);
- if (!data.caseList[i].nobreak)
- break;
- }
- }
- core.insertAction(list);
- core.doAction();
-}
-
-events.prototype._precompile_switch = function (data) {
- data.condition = core.replaceValue(data.condition);
- for (var i = 0; i < data.caseList.length; i++) {
- data.caseList[i]["case"] = core.replaceValue(data.caseList[i]["case"]);
- data.caseList[i].action = this.precompile(data.caseList[i].action);
- }
- return data;
-}
-
-events.prototype._action_choices = function (data, x, y, prefix) {
- data.choices = data.choices.filter(function (x) {
- if (x._disabled) return false;
- if (x.condition == null || x.condition == '') return true;
- try { return core.calValue(x.condition, prefix); } catch (e) { return true; }
- })
- if (data.choices.length == 0) return this.doAction();
- if (core.isReplaying()) {
- var action = core.status.replay.toReplay.shift();
- if (action.indexOf('choices:') == 0 && !(action == 'choices:none' && !data.timeout)) {
- var index = action.substring(8);
- if (!this.__action_choices_replaying(data, index)) {
- core.control._replay_error(action);
- return;
- }
- } else {
- // 容错录像
- if (main.replayChecking) {
- // 录像验证系统中选最后一项
- if (action != 'choices:none') core.status.replay.toReplay.unshift(action); // 首先归还刚才读出的下一步操作
- core.events.__action_choices_replaying(data, -1);
- } else {
- // 正常游戏中弹窗选择
- core.myprompt('录像回放出错!当前需要执行选择项但录像中未记录。\n如需修复请输入您要选的项(从0起),点击取消将不会修复。', 0, function (value) {
- if (value == null) {
- core.control._replay_error(action);
- return;
- }
- if (action != 'choices:none') core.status.replay.toReplay.unshift(action); // 首先归还刚才读出的下一步操作
- core.events.__action_choices_replaying(data, ((parseInt(value) || 0) + data.choices.length) % data.choices.length);
- });
- }
- }
- } else {
- if (data.timeout) {
- core.status.event.interval = setTimeout(function () {
- core.status.route.push("choices:none");
- core.setFlag('timeout', 0);
- core.doAction();
- }, data.timeout);
- }
- core.status.event.timeout = new Date().getTime() + (data.timeout || 0);
- }
- for (var i = 0; i < data.choices.length; i++) {
- if (typeof data.choices[i] === 'string')
- data.choices[i] = { "text": data.choices[i] };
- data.choices[i].text = core.replaceText(data.choices[i].text, prefix);
- }
- core.ui.drawChoices(core.replaceText(data.text, prefix), data.choices, data.width);
-}
-
-events.prototype.__action_choices_replaying = function (data, index) {
- var selection = index;
- if (index != 'none') {
- selection = parseInt(index);
- if (isNaN(selection)) return false;
- if (selection < 0) selection += data.choices.length;
- if (selection < 0) return false;
- if (selection % 100 > 50) selection += data.choices.length;
- if (selection % 100 > data.choices.length) return false;
- var timeout = Math.floor(selection / 100) || 0;
- core.setFlag('timeout', timeout);
- selection %= 100;
- } else core.setFlag('timeout', 0);
- core.status.event.selection = selection;
- setTimeout(function () {
- core.status.route.push("choices:" + index);
- if (selection != 'none') {
- // 检查
- var choice = data.choices[selection];
- if (choice.need != null && choice.need != '' && !core.calValue(choice.need)) {
- // 无法选择此项
- core.control._replay_error("无法选择项:" + index);
- return;
- } else {
- core.insertAction(choice.action);
- }
- }
- core.doAction();
- }, core.status.replay.speed == 24 ? 1 : 750 / Math.max(1, core.status.replay.speed));
- return true;
-}
-
-events.prototype._precompile_choices = function (data) {
- if (!(data.choices instanceof Array)) return data;
- for (var i = 0; i < data.choices.length; ++i) {
- data.choices[i].condition = core.replaceValue(data.choices[i].condition);
- data.choices[i].text = this.__precompile_text(data.choices[i].text);
- data.choices[i].action = this.precompile(data.choices[i].action);
- }
- return data;
-}
-
-events.prototype._action_confirm = function (data, x, y, prefix) {
- data.text = core.replaceText(data.text, prefix);
- core.status.event.ui = { "text": data.text, "yes": data.yes, "no": data.no };
- if (core.isReplaying()) {
- var action = core.status.replay.toReplay.shift();
- if (action.indexOf('choices:') == 0 && !(action == 'choices:none' && !data.timeout)) {
- var index = action.substring(8);
- if (index == 'none' || ((index = parseInt(index)) >= 0) && index % 100 < 2) {
- this.__action_confirm_replaying(data, index);
- } else {
- core.control._replay_error(action);
- return;
- }
- } else {
- // 录像中未记录选了哪个,则选默认值,而不是直接报错
- if (action != 'choices:none') core.status.replay.toReplay.unshift(action);
- this.__action_confirm_replaying(data, data["default"] ? 0 : 1);
- }
- }
- else {
- core.status.event.selection = data["default"] ? 0 : 1;
- if (data.timeout) {
- core.status.event.interval = setTimeout(function () {
- core.status.route.push("choices:none");
- core.setFlag('timeout', 0);
- core.doAction();
- }, data.timeout);
- }
- core.status.event.timeout = new Date().getTime() + (data.timeout || 0);
- }
- core.ui.drawConfirmBox(data.text);
-}
-
-events.prototype.__action_confirm_replaying = function (data, index) {
- if (index != 'none') {
- var timeout = Math.floor(index / 100) || 0;
- core.setFlag('timeout', timeout);
- index %= 100;
- } else core.setFlag('timeout', 0);
- core.status.event.selection = index;
- setTimeout(function () {
- core.status.route.push("choices:" + index);
- if (index != 'none') {
- if (index == 0) core.insertAction(data.yes);
- else core.insertAction(data.no);
- }
- core.doAction();
- }, core.status.replay.speed == 24 ? 1 : 750 / Math.max(1, core.status.replay.speed));
-}
-
-events.prototype._precompile_confirm = function (data) {
- data.yes = this.precompile(data.yes);
- data.no = this.precompile(data.no);
- return data;
-}
-
-events.prototype._action_for = function (data, x, y, prefix) {
- // Only support temp:A
- if (!/^temp:[A-Z]$/.test(data.name)) {
- core.insertAction('循环遍历事件只支持临时变量!');
- return core.doAction();
- }
- var from = core.calValue(data.from);
- var to = core.calValue(data.to);
- var step = core.calValue(data.step);
- if (typeof from != 'number' || typeof to != 'number' || typeof step != 'number') {
- core.insertAction('循环遍历事件要求【起始点】【终止点】【每步】仅能是数字!');
- return core.doAction();
- }
- // 首次判定
- if ((step > 0 && from > to) || (step < 0 && from < to)) {
- core.doAction();
- return;
- }
-
- var letter = data.name.substring(5);
- core.setFlag('@temp@' + letter, from);
- var toName = '@temp@for-to@' + letter;
- var stepName = '@temp@for-step@' + letter;
- core.setFlag(toName, data.to);
- core.setFlag(stepName, data.step);
- var condition = "(function () {" +
- "var to = core.calValue(core.getFlag('" + toName + "'));" +
- "var step = core.calValue(core.getFlag('" + stepName + "'));" +
- "if (typeof step != 'number' || typeof to != 'number') return false;" +
- "if (step == 0) return true;" +
- "var currentValue = core.getFlag('@temp@" + letter + "');" +
- "currentValue += step;" +
- "core.setFlag('@temp@" + letter + "', currentValue);" +
- "if (step > 0) { return currentValue <= to; }" +
- "else { return currentValue >= to; }" +
- "})()";
- return this._action_dowhile({ "condition": condition, "data": data.data }, x, y, prefix);
-}
-
-events.prototype._precompile_for = function (data) {
- data.from = core.replaceValue(data.from);
- data.to = core.replaceValue(data.to);
- data.step = core.replaceValue(data.step);
- data.data = this.precompile(data.data);
- return data;
-}
-
-events.prototype._action_forEach = function (data, x, y, prefix) {
- // Only support temp:A
- if (!/^temp:[A-Z]$/.test(data.name)) {
- core.insertAction(['循环遍历事件只支持临时变量!']);
- return core.doAction();
- }
- var listName = '@temp@forEach@' + data.name.substring(5);
- core.setFlag(listName, core.clone(data.list));
- var condition = "(function () {" +
- "var list = core.getFlag('" + listName + "', []);" +
- "if (list.length == 0) return false;" +
- "core.setFlag('@temp@'+'" + data.name.substring(5) + "', list.shift());" +
- "return true;" +
- "})()";
- return this._action_while({ "condition": condition, "data": data.data }, x, y, prefix);
-}
-
-events.prototype._precompile_forEach = function (data) {
- data.data = this.precompile(data.data);
- return data;
-}
-
-events.prototype._action_while = function (data, x, y, prefix) {
- if (core.calValue(data.condition, prefix)) {
- var list = core.clone(data.data);
- if (!(list instanceof Array)) list = [list];
- list.push({ "type": "_label" });
- core.unshift(core.status.event.data.list,
- { "todo": list, "total": core.clone(list), "condition": data.condition }
- );
- }
- core.doAction();
-}
-
-events.prototype._precompile_while = function (data) {
- data.condition = core.replaceValue(data.condition);
- data.data = this.precompile(data.data);
- return data;
-}
-
-events.prototype._action_dowhile = function (data, x, y, prefix) {
- var list = core.clone(data.data);
- if (!(list instanceof Array)) list = [list];
- list.push({ "type": "_label" });
- core.unshift(core.status.event.data.list,
- { "todo": list, "total": core.clone(list), "condition": data.condition }
+ // 考虑到可能覆盖楼传事件的问题,这里不对fly进行检查。
+ if (data.id != "book" && core.canUseItem(data.id)) {
+ core.useItem(data.id, true, core.doAction);
+ } else {
+ core.playSound("操作失败");
+ core.drawTip(
+ "当前无法使用" + ((core.material.items[data.id] || {}).name || "未知道具")
);
core.doAction();
-}
+ }
+};
-events.prototype._precompile_dowhile = function (data) {
- data.condition = core.replaceValue(data.condition);
- data.data = this.precompile(data.data);
- return data;
-}
+events.prototype._action_loadEquip = function (data, x, y, prefix) {
+ core.loadEquip(data.id);
+ core.doAction();
+};
-events.prototype._action_break = function (data, x, y, prefix) {
- var n = data.n || 1;
- while (n--) {
- if (core.status.event.data.list.length > 1)
- core.status.event.data.list.shift();
+events.prototype._action_unloadEquip = function (data, x, y, prefix) {
+ core.unloadEquip(data.pos);
+ core.doAction();
+};
+
+events.prototype._action_openShop = function (data, x, y, prefix) {
+ core.setShopVisited(data.id, true);
+ if (data.open) core.openShop(data.id, true);
+ core.doAction();
+};
+
+events.prototype._action_disableShop = function (data, x, y, prefix) {
+ core.setShopVisited(data.id, false);
+ core.doAction();
+};
+
+events.prototype._action_battle = function (data, x, y, prefix) {
+ if (data.id) {
+ this.battle(data.id, null, null, true, core.doAction);
+ } else {
+ if (data.floorId != core.status.floorId) {
+ core.doAction();
+ return;
}
- core.doAction();
-}
+ var loc = this.__action_getLoc(data.loc, x, y, prefix);
+ this.battle(null, loc[0], loc[1], true, core.doAction);
+ }
+};
-events.prototype._action_continue = function (data, x, y, prefix) {
- var n = data.n || 1;
- while (n-- > 1) {
- if (core.status.event.data.list.length > 1)
- core.status.event.data.list.shift();
- }
- if (core.status.event.data.list.length > 1) {
- if (core.calValue(core.status.event.data.list[0].condition, prefix)) {
- core.status.event.data.list[0].todo = core.clone(core.status.event.data.list[0].total);
- }
- else {
- core.status.event.data.list.shift();
+events.prototype._action_trigger = function (data, x, y, prefix) {
+ var loc = this.__action_getLoc(data.loc, x, y, prefix);
+ this._trigger_inAction(loc[0], loc[1]);
+};
+
+events.prototype._action_insert = function (data, x, y, prefix) {
+ if (data.name) {
+ // 公共事件
+ core.insertCommonEvent(data.name, data.args);
+ } else {
+ // 设置参数
+ if (data.args instanceof Array) {
+ for (var i = 0; i < data.args.length; ++i) {
+ try {
+ if (data.args[i] != null) core.setFlag("arg" + (i + 1), data.args[i]);
+ } catch (ee) {
+ console.error(ee);
}
+ }
}
+ var loc = this.__action_getLoc(data.loc, x, y, prefix);
+ core.setFlag("arg0", loc);
+ var floorId = data.floorId;
+ var which = data.which || "events";
+ var event = (core.floors[floorId][which] || [])[loc[0] + "," + loc[1]];
+ if (event) this.insertAction(event.data || event);
+ }
+ core.doAction();
+};
+
+events.prototype._action_playBgm = function (data, x, y, prefix) {
+ core.playBgm(data.name, data.startTime || 0);
+ core.setFlag("__bgm__", data.keep ? data.name : null);
+ core.doAction();
+};
+
+events.prototype._action_pauseBgm = function (data, x, y, prefix) {
+ core.pauseBgm();
+ core.doAction();
+};
+
+events.prototype._action_resumeBgm = function (data, x, y, prefix) {
+ core.resumeBgm(data.resume);
+ core.doAction();
+};
+
+events.prototype._action_loadBgm = function (data, x, y, prefix) {
+ core.loadBgm(data.name);
+ core.doAction();
+};
+
+events.prototype._action_freeBgm = function (data, x, y, prefix) {
+ core.freeBgm(data.name);
+ core.doAction();
+};
+
+events.prototype._action_playSound = function (data, x, y, prefix) {
+ if (data.stop) core.stopSound();
+ if (data.sync) {
+ core.playSound(data.name, data.pitch, core.doAction);
+ } else {
+ core.playSound(data.name, data.pitch);
core.doAction();
-}
+ }
+};
-events.prototype._action_win = function (data, x, y, prefix) {
- this.win(core.replaceText(data.reason, prefix), data.norank, data.noexit);
-}
+events.prototype._action_stopSound = function (data, x, y, prefix) {
+ core.stopSound();
+ core.doAction();
+};
-events.prototype._action_lose = function (data, x, y, prefix) {
- this.lose(core.replaceText(data.reason, prefix));
-}
+events.prototype._action_setVolume = function (data, x, y, prefix) {
+ data.value = core.clamp(parseInt(data.value) / 100, 0, 1);
+ core.setFlag("__volume__", data.value);
+ this.__action_doAsyncFunc(
+ data.async,
+ core.setVolume,
+ data.value,
+ data.time || 0
+ );
+};
-events.prototype._action_restart = function (data, x, y, prefix) {
- core.restart();
-}
+events.prototype._action_setBgmSpeed = function (data, x, y, prefix) {
+ core.setBgmSpeed(data.value, data.pitch || false);
+ core.doAction();
+};
-events.prototype._action_function = function (data, x, y, prefix) {
- var func = data["function"];
- try {
- if (typeof func == "string" && func.indexOf("function") == 0) {
- eval('(' + func + ')()');
- }
- } catch (e) {
- console.error(e);
- }
- if (!data.async)
- core.doAction();
-}
-
-events.prototype._action_update = function (data, x, y, prefix) {
- core.updateStatusBar(data.doNotCheckAutoEvents, true);
- core.doAction();
-}
-
-events.prototype._action_showStatusBar = function (data, x, y, prefix) {
- core.showStatusBar();
- core.doAction();
-}
-
-events.prototype._action_hideStatusBar = function (data, x, y, prefix) {
- core.hideStatusBar(data.toolbox);
- core.doAction();
-}
-
-events.prototype._action_showHero = function (data, x, y, prefix) {
- data.opacity = 1;
- return this._action_setHeroOpacity(data, x, y, prefix);
-}
-
-events.prototype._action_hideHero = function (data, x, y, prefix) {
- data.opacity = 0;
- return this._action_setHeroOpacity(data, x, y, prefix);
-}
-
-events.prototype._action_setHeroOpacity = function (data, x, y, prefix) {
- data.time = data.time || 0;
- if (data.opacity == null) data.opacity = 1;
- if (data.time > 0) {
- this.__action_doAsyncFunc(data.async, core.setHeroOpacity, data.opacity, data.moveMode, data.time);
+events.prototype._action_setValue = function (data, x, y, prefix) {
+ this.setValue(data.name, data.operator, data.value, prefix);
+ if (!data.norefresh) {
+ if (core.status.hero.hp <= 0) {
+ core.status.hero.hp = 0;
+ core.updateStatusBar();
+ core.events.lose();
} else {
- core.setFlag('__heroOpacity__', data.opacity);
- core.drawHero();
- core.doAction();
+ core.updateStatusBar();
}
-}
+ }
+ core.doAction();
+};
-events.prototype._action_vibrate = function (data, x, y, prefix) {
- this.__action_doAsyncFunc(data.async, core.vibrate, data.direction, data.time, data.speed, data.power);
-}
+events.prototype._action_addValue = function (data, x, y, prefix) {
+ data.operator = "+=";
+ this._action_setValue(data, x, y, prefix);
+};
-events.prototype._action_sleep = function (data, x, y, prefix) {
- core.timeout.sleepTimeout = setTimeout(function () {
- core.timeout.sleepTimeout = null;
- core.doAction();
- }, core.isReplaying() ? Math.min(data.time, 20) : data.time);
-}
+events.prototype._action_setEnemy = function (data, x, y, prefix) {
+ this.setEnemy(
+ data.id,
+ data.name,
+ data.value,
+ data.operator,
+ prefix,
+ data.norefresh
+ );
+ core.doAction();
+};
-events.prototype._action_wait = function (data, x, y, prefix) {
- if (core.isReplaying()) {
- var code = core.status.replay.toReplay.shift();
- if (code.indexOf("input:") == 0 && !(code == "input:none" && !data.timeout)) {
- if (code == "input:none") {
- core.status.route.push("input:none");
- core.setFlag("type", -1);
- core.setFlag("timeout", 0);
- this.__action_wait_afterGet(data);
- return core.doAction();
- } else {
- var value = parseInt(code.substring(6));
- core.status.route.push("input:" + value);
- this.__action_wait_getValue(value);
- if (this.__action_wait_afterGet(data) || !data.forceChild) return core.doAction();
- }
- }
- core.control._replay_error(code);
+events.prototype._action_setEnemyOnPoint = function (data, x, y, prefix) {
+ var loc = this.__action_getLoc2D(data.loc, x, y, prefix);
+ loc.forEach(function (one) {
+ core.setEnemyOnPoint(
+ one[0],
+ one[1],
+ data.floorId,
+ data.name,
+ data.value,
+ data.operator,
+ prefix,
+ data.norefresh
+ );
+ });
+ core.doAction();
+};
+
+events.prototype._action_resetEnemyOnPoint = function (data, x, y, prefix) {
+ var loc = this.__action_getLoc2D(data.loc, x, y, prefix);
+ loc.forEach(function (one) {
+ core.resetEnemyOnPoint(one[0], one[1], data.floorId, data.norefresh);
+ });
+ core.doAction();
+};
+
+events.prototype._precompile_moveEnemyOnPoint = function (data) {
+ data.from = this.__precompile_array(data.from);
+ data.to = this.__precompile_array(data.to);
+ data.dxy = this.__precompile_array(data.dxy);
+ return data;
+};
+
+events.prototype._action_moveEnemyOnPoint = function (data, x, y, prefix) {
+ var from = this.__action_getLoc(data.from, x, y, prefix),
+ to;
+ if (data.dxy) {
+ to = [
+ from[0] + (core.calValue(data.dxy[0], prefix) || 0),
+ from[1] + (core.calValue(data.dxy[1], prefix) || 0),
+ ];
+ } else {
+ to = this.__action_getLoc(data.to, x, y, prefix);
+ }
+ this.moveEnemyOnPoint(
+ from[0],
+ from[1],
+ to[0],
+ to[1],
+ data.floorId,
+ data.norefresh
+ );
+ core.doAction();
+};
+
+events.prototype._action_setEquip = function (data, x, y, prefix) {
+ core.setEquip(
+ data.id,
+ data.valueType,
+ data.name,
+ data.value,
+ data.operator,
+ prefix
+ );
+ core.doAction();
+};
+
+events.prototype._action_setFloor = function (data, x, y, prefix) {
+ this.setFloorInfo(data.name, data.value, data.floorId, prefix);
+ core.doAction();
+};
+
+events.prototype._action_setGlobalAttribute = function (data, x, y, prefix) {
+ this.setGlobalAttribute(data.name, data.value);
+ core.doAction();
+};
+
+events.prototype._action_setGlobalValue = function (data, x, y, prefix) {
+ core.values[data.name] = data.value;
+ core.doAction();
+};
+
+events.prototype._action_setGlobalFlag = function (data, x, y, prefix) {
+ this.setGlobalFlag(data.name, data.value);
+ core.doAction();
+};
+
+events.prototype._action_setNameMap = function (data, x, y, floorId) {
+ this.setNameMap(data.name, data.value);
+ core.doAction();
+};
+
+events.prototype._action_setHeroIcon = function (data, x, y, prefix) {
+ this.setHeroIcon(data.name, data.noDraw);
+ core.doAction();
+};
+
+events.prototype._action_input = function (data, x, y, prefix) {
+ this.__action_getInput(
+ core.replaceText(data.text, prefix),
+ false,
+ function (value) {
+ value = parseInt(value) || 0; // 允许负整数
+ core.status.route.push("input:" + value);
+ core.setFlag("input", value);
+ core.doAction();
+ }
+ );
+};
+
+events.prototype._action_input2 = function (data, x, y, prefix) {
+ this.__action_getInput(
+ core.replaceText(data.text, prefix),
+ true,
+ function (value) {
+ value = value || "";
+ core.status.route.push("input2:" + core.encodeBase64(value));
+ core.setFlag("input", value);
+ core.doAction();
+ }
+ );
+};
+
+events.prototype.__action_getInput = function (hint, isText, callback) {
+ var value,
+ prefix = isText ? "input2:" : "input:";
+ if (core.isReplaying()) {
+ var action = core.status.replay.toReplay.shift();
+ try {
+ if (action.indexOf(prefix) != 0) {
+ console.warn("警告!当前需要一个 " + prefix + " 项,实际为 " + action);
+ core.status.replay.toReplay.unshift(action);
+ return callback(isText ? "" : 0);
+ }
+ if (isText) value = core.decodeBase64(action.substring(7));
+ else value = parseInt(action.substring(6));
+ callback(value);
+ } catch (e) {
+ core.control._replay_error(action);
+ return;
+ }
+ } else {
+ core.myprompt(core.replaceText(hint), null, callback);
+ }
+};
+
+events.prototype._action_if = function (data, x, y, prefix) {
+ if (core.calValue(data.condition, prefix))
+ core.events.insertAction(data["true"]);
+ else core.events.insertAction(data["false"]);
+ core.doAction();
+};
+
+events.prototype._precompile_if = function (data) {
+ data.condition = core.replaceValue(data.condition);
+ data["true"] = this.precompile(data["true"]);
+ data["false"] = this.precompile(data["false"]);
+ return data;
+};
+
+events.prototype._action_switch = function (data, x, y, prefix) {
+ var key = core.calValue(data.condition, prefix);
+ var list = [];
+ for (var i = 0; i < data.caseList.length; i++) {
+ if (data.caseList[i]._disabled) continue;
+ var condition = data.caseList[i]["case"];
+ if (condition == "default" || core.calValue(condition, prefix) === key) {
+ core.push(list, data.caseList[i].action);
+ if (!data.caseList[i].nobreak) break;
+ }
+ }
+ core.insertAction(list);
+ core.doAction();
+};
+
+events.prototype._precompile_switch = function (data) {
+ data.condition = core.replaceValue(data.condition);
+ for (var i = 0; i < data.caseList.length; i++) {
+ data.caseList[i]["case"] = core.replaceValue(data.caseList[i]["case"]);
+ data.caseList[i].action = this.precompile(data.caseList[i].action);
+ }
+ return data;
+};
+
+events.prototype._action_choices = function (data, x, y, prefix) {
+ data.choices = data.choices.filter(function (x) {
+ if (x._disabled) return false;
+ if (x.condition == null || x.condition == "") return true;
+ try {
+ return core.calValue(x.condition, prefix);
+ } catch (e) {
+ return true;
+ }
+ });
+ if (data.choices.length == 0) return this.doAction();
+ if (core.isReplaying()) {
+ var action = core.status.replay.toReplay.shift();
+ if (
+ action.indexOf("choices:") == 0 &&
+ !(action == "choices:none" && !data.timeout)
+ ) {
+ var index = action.substring(8);
+ if (!this.__action_choices_replaying(data, index)) {
+ core.control._replay_error(action);
return;
- } else if (data.timeout) {
- core.status.event.interval = setTimeout(function () {
- core.status.route.push("input:none");
- core.setFlag("type", -1);
- core.setFlag("timeout", 0);
- core.events.__action_wait_afterGet(data);
- core.doAction();
- }, data.timeout);
+ }
+ } else {
+ // 容错录像
+ if (main.replayChecking) {
+ // 录像验证系统中选最后一项
+ if (action != "choices:none")
+ core.status.replay.toReplay.unshift(action); // 首先归还刚才读出的下一步操作
+ core.events.__action_choices_replaying(data, -1);
+ } else {
+ // 正常游戏中弹窗选择
+ core.myprompt(
+ "录像回放出错!当前需要执行选择项但录像中未记录。\n如需修复请输入您要选的项(从0起),点击取消将不会修复。",
+ 0,
+ function (value) {
+ if (value == null) {
+ core.control._replay_error(action);
+ return;
+ }
+ if (action != "choices:none")
+ core.status.replay.toReplay.unshift(action); // 首先归还刚才读出的下一步操作
+ core.events.__action_choices_replaying(
+ data,
+ ((parseInt(value) || 0) + data.choices.length) %
+ data.choices.length
+ );
+ }
+ );
+ }
+ }
+ } else {
+ if (data.timeout) {
+ core.status.event.interval = setTimeout(function () {
+ core.status.route.push("choices:none");
+ core.setFlag("timeout", 0);
+ core.doAction();
+ }, data.timeout);
}
core.status.event.timeout = new Date().getTime() + (data.timeout || 0);
-}
+ }
+ for (var i = 0; i < data.choices.length; i++) {
+ if (typeof data.choices[i] === "string")
+ data.choices[i] = { text: data.choices[i] };
+ data.choices[i].text = core.replaceText(data.choices[i].text, prefix);
+ }
+ core.ui.drawChoices(
+ core.replaceText(data.text, prefix),
+ data.choices,
+ data.width
+ );
+};
+
+events.prototype.__action_choices_replaying = function (data, index) {
+ var selection = index;
+ if (index != "none") {
+ selection = parseInt(index);
+ if (isNaN(selection)) return false;
+ if (selection < 0) selection += data.choices.length;
+ if (selection < 0) return false;
+ if (selection % 100 > 50) selection += data.choices.length;
+ if (selection % 100 > data.choices.length) return false;
+ var timeout = Math.floor(selection / 100) || 0;
+ core.setFlag("timeout", timeout);
+ selection %= 100;
+ } else core.setFlag("timeout", 0);
+ core.status.event.selection = selection;
+ setTimeout(
+ function () {
+ core.status.route.push("choices:" + index);
+ if (selection != "none") {
+ // 检查
+ var choice = data.choices[selection];
+ if (
+ choice.need != null &&
+ choice.need != "" &&
+ !core.calValue(choice.need)
+ ) {
+ // 无法选择此项
+ core.control._replay_error("无法选择项:" + index);
+ return;
+ } else {
+ core.insertAction(choice.action);
+ }
+ }
+ core.doAction();
+ },
+ core.status.replay.speed == 24
+ ? 1
+ : 750 / Math.max(1, core.status.replay.speed)
+ );
+ return true;
+};
+
+events.prototype._precompile_choices = function (data) {
+ if (!(data.choices instanceof Array)) return data;
+ for (var i = 0; i < data.choices.length; ++i) {
+ data.choices[i].condition = core.replaceValue(data.choices[i].condition);
+ data.choices[i].text = this.__precompile_text(data.choices[i].text);
+ data.choices[i].action = this.precompile(data.choices[i].action);
+ }
+ return data;
+};
+
+events.prototype._action_confirm = function (data, x, y, prefix) {
+ data.text = core.replaceText(data.text, prefix);
+ core.status.event.ui = { text: data.text, yes: data.yes, no: data.no };
+ if (core.isReplaying()) {
+ var action = core.status.replay.toReplay.shift();
+ if (
+ action.indexOf("choices:") == 0 &&
+ !(action == "choices:none" && !data.timeout)
+ ) {
+ var index = action.substring(8);
+ if (
+ index == "none" ||
+ ((index = parseInt(index)) >= 0 && index % 100 < 2)
+ ) {
+ this.__action_confirm_replaying(data, index);
+ } else {
+ core.control._replay_error(action);
+ return;
+ }
+ } else {
+ // 录像中未记录选了哪个,则选默认值,而不是直接报错
+ if (action != "choices:none") core.status.replay.toReplay.unshift(action);
+ this.__action_confirm_replaying(data, data["default"] ? 0 : 1);
+ }
+ } else {
+ core.status.event.selection = data["default"] ? 0 : 1;
+ if (data.timeout) {
+ core.status.event.interval = setTimeout(function () {
+ core.status.route.push("choices:none");
+ core.setFlag("timeout", 0);
+ core.doAction();
+ }, data.timeout);
+ }
+ core.status.event.timeout = new Date().getTime() + (data.timeout || 0);
+ }
+ core.ui.drawConfirmBox(data.text);
+};
+
+events.prototype.__action_confirm_replaying = function (data, index) {
+ if (index != "none") {
+ var timeout = Math.floor(index / 100) || 0;
+ core.setFlag("timeout", timeout);
+ index %= 100;
+ } else core.setFlag("timeout", 0);
+ core.status.event.selection = index;
+ setTimeout(
+ function () {
+ core.status.route.push("choices:" + index);
+ if (index != "none") {
+ if (index == 0) core.insertAction(data.yes);
+ else core.insertAction(data.no);
+ }
+ core.doAction();
+ },
+ core.status.replay.speed == 24
+ ? 1
+ : 750 / Math.max(1, core.status.replay.speed)
+ );
+};
+
+events.prototype._precompile_confirm = function (data) {
+ data.yes = this.precompile(data.yes);
+ data.no = this.precompile(data.no);
+ return data;
+};
+
+events.prototype._action_for = function (data, x, y, prefix) {
+ // Only support temp:A
+ if (!/^temp:[A-Z]$/.test(data.name)) {
+ core.insertAction("循环遍历事件只支持临时变量!");
+ return core.doAction();
+ }
+ var from = core.calValue(data.from);
+ var to = core.calValue(data.to);
+ var step = core.calValue(data.step);
+ if (
+ typeof from != "number" ||
+ typeof to != "number" ||
+ typeof step != "number"
+ ) {
+ core.insertAction(
+ "循环遍历事件要求【起始点】【终止点】【每步】仅能是数字!"
+ );
+ return core.doAction();
+ }
+ // 首次判定
+ if ((step > 0 && from > to) || (step < 0 && from < to)) {
+ core.doAction();
+ return;
+ }
+
+ var letter = data.name.substring(5);
+ core.setFlag("@temp@" + letter, from);
+ var toName = "@temp@for-to@" + letter;
+ var stepName = "@temp@for-step@" + letter;
+ core.setFlag(toName, data.to);
+ core.setFlag(stepName, data.step);
+ var condition =
+ "(function () {" +
+ "var to = core.calValue(core.getFlag('" +
+ toName +
+ "'));" +
+ "var step = core.calValue(core.getFlag('" +
+ stepName +
+ "'));" +
+ "if (typeof step != 'number' || typeof to != 'number') return false;" +
+ "if (step == 0) return true;" +
+ "var currentValue = core.getFlag('@temp@" +
+ letter +
+ "');" +
+ "currentValue += step;" +
+ "core.setFlag('@temp@" +
+ letter +
+ "', currentValue);" +
+ "if (step > 0) { return currentValue <= to; }" +
+ "else { return currentValue >= to; }" +
+ "})()";
+ return this._action_dowhile(
+ { condition: condition, data: data.data },
+ x,
+ y,
+ prefix
+ );
+};
+
+events.prototype._precompile_for = function (data) {
+ data.from = core.replaceValue(data.from);
+ data.to = core.replaceValue(data.to);
+ data.step = core.replaceValue(data.step);
+ data.data = this.precompile(data.data);
+ return data;
+};
+
+events.prototype._action_forEach = function (data, x, y, prefix) {
+ // Only support temp:A
+ if (!/^temp:[A-Z]$/.test(data.name)) {
+ core.insertAction(["循环遍历事件只支持临时变量!"]);
+ return core.doAction();
+ }
+ var listName = "@temp@forEach@" + data.name.substring(5);
+ core.setFlag(listName, core.clone(data.list));
+ var condition =
+ "(function () {" +
+ "var list = core.getFlag('" +
+ listName +
+ "', []);" +
+ "if (list.length == 0) return false;" +
+ "core.setFlag('@temp@'+'" +
+ data.name.substring(5) +
+ "', list.shift());" +
+ "return true;" +
+ "})()";
+ return this._action_while(
+ { condition: condition, data: data.data },
+ x,
+ y,
+ prefix
+ );
+};
+
+events.prototype._precompile_forEach = function (data) {
+ data.data = this.precompile(data.data);
+ return data;
+};
+
+events.prototype._action_while = function (data, x, y, prefix) {
+ if (core.calValue(data.condition, prefix)) {
+ var list = core.clone(data.data);
+ if (!(list instanceof Array)) list = [list];
+ list.push({ type: "_label" });
+ core.unshift(core.status.event.data.list, {
+ todo: list,
+ total: core.clone(list),
+ condition: data.condition,
+ });
+ }
+ core.doAction();
+};
+
+events.prototype._precompile_while = function (data) {
+ data.condition = core.replaceValue(data.condition);
+ data.data = this.precompile(data.data);
+ return data;
+};
+
+events.prototype._action_dowhile = function (data, x, y, prefix) {
+ var list = core.clone(data.data);
+ if (!(list instanceof Array)) list = [list];
+ list.push({ type: "_label" });
+ core.unshift(core.status.event.data.list, {
+ todo: list,
+ total: core.clone(list),
+ condition: data.condition,
+ });
+ core.doAction();
+};
+
+events.prototype._precompile_dowhile = function (data) {
+ data.condition = core.replaceValue(data.condition);
+ data.data = this.precompile(data.data);
+ return data;
+};
+
+events.prototype._action_break = function (data, x, y, prefix) {
+ var n = data.n || 1;
+ while (n--) {
+ if (core.status.event.data.list.length > 1)
+ core.status.event.data.list.shift();
+ }
+ core.doAction();
+};
+
+events.prototype._action_continue = function (data, x, y, prefix) {
+ var n = data.n || 1;
+ while (n-- > 1) {
+ if (core.status.event.data.list.length > 1)
+ core.status.event.data.list.shift();
+ }
+ if (core.status.event.data.list.length > 1) {
+ if (core.calValue(core.status.event.data.list[0].condition, prefix)) {
+ core.status.event.data.list[0].todo = core.clone(
+ core.status.event.data.list[0].total
+ );
+ } else {
+ core.status.event.data.list.shift();
+ }
+ }
+ core.doAction();
+};
+
+events.prototype._action_win = function (data, x, y, prefix) {
+ this.win(core.replaceText(data.reason, prefix), data.norank, data.noexit);
+};
+
+events.prototype._action_lose = function (data, x, y, prefix) {
+ this.lose(core.replaceText(data.reason, prefix));
+};
+
+events.prototype._action_restart = function (data, x, y, prefix) {
+ core.restart();
+};
+
+events.prototype._action_function = function (data, x, y, prefix) {
+ var func = data["function"];
+ try {
+ if (typeof func == "string" && func.indexOf("function") == 0) {
+ eval("(" + func + ")()");
+ }
+ } catch (e) {
+ console.error(e);
+ }
+ if (!data.async) core.doAction();
+};
+
+events.prototype._action_update = function (data, x, y, prefix) {
+ core.updateStatusBar(data.doNotCheckAutoEvents, true);
+ core.doAction();
+};
+
+events.prototype._action_showStatusBar = function (data, x, y, prefix) {
+ core.showStatusBar();
+ core.doAction();
+};
+
+events.prototype._action_hideStatusBar = function (data, x, y, prefix) {
+ core.hideStatusBar(data.toolbox);
+ core.doAction();
+};
+
+events.prototype._action_showHero = function (data, x, y, prefix) {
+ data.opacity = 1;
+ return this._action_setHeroOpacity(data, x, y, prefix);
+};
+
+events.prototype._action_hideHero = function (data, x, y, prefix) {
+ data.opacity = 0;
+ return this._action_setHeroOpacity(data, x, y, prefix);
+};
+
+events.prototype._action_setHeroOpacity = function (data, x, y, prefix) {
+ data.time = data.time || 0;
+ if (data.opacity == null) data.opacity = 1;
+ if (data.time > 0) {
+ this.__action_doAsyncFunc(
+ data.async,
+ core.setHeroOpacity,
+ data.opacity,
+ data.moveMode,
+ data.time
+ );
+ } else {
+ core.setFlag("__heroOpacity__", data.opacity);
+ core.drawHero();
+ core.doAction();
+ }
+};
+
+events.prototype._action_vibrate = function (data, x, y, prefix) {
+ this.__action_doAsyncFunc(
+ data.async,
+ core.vibrate,
+ data.direction,
+ data.time,
+ data.speed,
+ data.power
+ );
+};
+
+events.prototype._action_sleep = function (data, x, y, prefix) {
+ core.timeout.sleepTimeout = setTimeout(
+ function () {
+ core.timeout.sleepTimeout = null;
+ core.doAction();
+ },
+ core.isReplaying() ? Math.min(data.time, 20) : data.time
+ );
+};
+
+events.prototype._action_wait = function (data, x, y, prefix) {
+ if (core.isReplaying()) {
+ var code = core.status.replay.toReplay.shift();
+ if (
+ code.indexOf("input:") == 0 &&
+ !(code == "input:none" && !data.timeout)
+ ) {
+ if (code == "input:none") {
+ core.status.route.push("input:none");
+ core.setFlag("type", -1);
+ core.setFlag("timeout", 0);
+ this.__action_wait_afterGet(data);
+ return core.doAction();
+ } else {
+ var value = parseInt(code.substring(6));
+ core.status.route.push("input:" + value);
+ this.__action_wait_getValue(value);
+ if (this.__action_wait_afterGet(data) || !data.forceChild)
+ return core.doAction();
+ }
+ }
+ core.control._replay_error(code);
+ return;
+ } else if (data.timeout) {
+ core.status.event.interval = setTimeout(function () {
+ core.status.route.push("input:none");
+ core.setFlag("type", -1);
+ core.setFlag("timeout", 0);
+ core.events.__action_wait_afterGet(data);
+ core.doAction();
+ }, data.timeout);
+ }
+ core.status.event.timeout = new Date().getTime() + (data.timeout || 0);
+};
events.prototype.__action_wait_getValue = function (value) {
- core.setFlag("timeout", Math.floor(value / 1e8) || 0);
- value %= 1e8;
- if (value >= 1000000) {
- core.setFlag('type', 1);
- var px = parseInt((value - 1000000) / 1000), py = value % 1000;
- core.setFlag('px', px);
- core.setFlag('py', py);
- core.setFlag('x', parseInt(px / 32));
- core.setFlag('y', parseInt(py / 32));
- }
- else if (value >= 10000) {
- core.setFlag('type', 1);
- var x = parseInt((value - 10000) / 100), y = value % 100;
- core.setFlag('px', 32 * x + 16);
- core.setFlag('py', 32 * y + 16);
- core.setFlag('x', x);
- core.setFlag('y', y);
- }
- else if (value > 0) {
- core.setFlag('type', 0);
- core.setFlag('keycode', value);
- }
-}
+ core.setFlag("timeout", Math.floor(value / 1e8) || 0);
+ value %= 1e8;
+ if (value >= 1000000) {
+ core.setFlag("type", 1);
+ var px = parseInt((value - 1000000) / 1000),
+ py = value % 1000;
+ core.setFlag("px", px);
+ core.setFlag("py", py);
+ core.setFlag("x", parseInt(px / 32));
+ core.setFlag("y", parseInt(py / 32));
+ } else if (value >= 10000) {
+ core.setFlag("type", 1);
+ var x = parseInt((value - 10000) / 100),
+ y = value % 100;
+ core.setFlag("px", 32 * x + 16);
+ core.setFlag("py", 32 * y + 16);
+ core.setFlag("x", x);
+ core.setFlag("y", y);
+ } else if (value > 0) {
+ core.setFlag("type", 0);
+ core.setFlag("keycode", value);
+ }
+};
events.prototype.__action_wait_afterGet = function (data) {
- if (!data.data) return false;
- var todo = [];
- var stop = false;
- var found = false;
- data.data.forEach(function (one) {
- if (one._disabled || stop) return;
- if (one["case"] == "keyboard" && core.getFlag("type") == 0) {
- (one.keycode + "").split(",").forEach(function (keycode) {
- if (core.getFlag("keycode", 0) == keycode) {
- found = true;
- core.push(todo, one.action);
- if (one["break"]) stop = true;
- }
- });
+ if (!data.data) return false;
+ var todo = [];
+ var stop = false;
+ var found = false;
+ data.data.forEach(function (one) {
+ if (one._disabled || stop) return;
+ if (one["case"] == "keyboard" && core.getFlag("type") == 0) {
+ (one.keycode + "").split(",").forEach(function (keycode) {
+ if (core.getFlag("keycode", 0) == keycode) {
+ found = true;
+ core.push(todo, one.action);
+ if (one["break"]) stop = true;
}
- if (one["case"] == "mouse" && one.px instanceof Array
- && one.py instanceof Array && core.getFlag("type") == 1) {
- var pxmin = core.calValue(one.px[0]);
- var pxmax = core.calValue(one.px[1]);
- var pymin = core.calValue(one.py[0]);
- var pymax = core.calValue(one.py[1]);
- var px = core.getFlag("px", 0), py = core.getFlag("py", 0);
- if (px >= pxmin && px <= pxmax && py >= pymin && py <= pymax) {
- found = true;
- core.push(todo, one.action);
- if (one["break"]) stop = true;
- }
- }
- if (one["case"] == "condition") {
- var condition = false;
- try { condition = core.calValue(one.condition); } catch (e) { }
- if (condition) {
- found = true;
- core.push(todo, one.action);
- if (one["break"]) stop = true;
- }
- }
- if (one["case"] == "timeout" && core.getFlag("type") == -1) {
- found = true;
- core.push(todo, one.action);
- if (one["break"]) stop = true;
- }
- })
- if (found) {
- core.insertAction(todo);
- return true;
+ });
}
- return false;
-}
+ if (
+ one["case"] == "mouse" &&
+ one.px instanceof Array &&
+ one.py instanceof Array &&
+ core.getFlag("type") == 1
+ ) {
+ var pxmin = core.calValue(one.px[0]);
+ var pxmax = core.calValue(one.px[1]);
+ var pymin = core.calValue(one.py[0]);
+ var pymax = core.calValue(one.py[1]);
+ var px = core.getFlag("px", 0),
+ py = core.getFlag("py", 0);
+ if (px >= pxmin && px <= pxmax && py >= pymin && py <= pymax) {
+ found = true;
+ core.push(todo, one.action);
+ if (one["break"]) stop = true;
+ }
+ }
+ if (one["case"] == "condition") {
+ var condition = false;
+ try {
+ condition = core.calValue(one.condition);
+ } catch (e) {}
+ if (condition) {
+ found = true;
+ core.push(todo, one.action);
+ if (one["break"]) stop = true;
+ }
+ }
+ if (one["case"] == "timeout" && core.getFlag("type") == -1) {
+ found = true;
+ core.push(todo, one.action);
+ if (one["break"]) stop = true;
+ }
+ });
+ if (found) {
+ core.insertAction(todo);
+ return true;
+ }
+ return false;
+};
events.prototype._precompile_wait = function (data) {
- if (data.data) {
- data.data.forEach(function (v) {
- if (v.px != null) v.px = this.__precompile_array(v.px);
- if (v.py != null) v.py = this.__precompile_array(v.py);
- if (v.condition != null) v.condition = this.__precompile_array(v.condition);
- v.action = this.precompile(v.action);
- }, this);
- }
- return data;
-}
+ if (data.data) {
+ data.data.forEach(function (v) {
+ if (v.px != null) v.px = this.__precompile_array(v.px);
+ if (v.py != null) v.py = this.__precompile_array(v.py);
+ if (v.condition != null)
+ v.condition = this.__precompile_array(v.condition);
+ v.action = this.precompile(v.action);
+ }, this);
+ }
+ return data;
+};
events.prototype._action_waitAsync = function (data, x, y, prefix) {
- var test = window.setInterval(function () {
- if (!core.hasAsync()
- && (data.excludeAnimates || core.isReplaying() || core.getPlayingAnimates().length == 0)
- && (!data.includeSounds || core.isReplaying() || core.getPlayingSounds().length == 0)) {
- clearInterval(test);
- core.doAction();
- }
- }, 50 / core.status.replay.speed);
-}
+ var test = window.setInterval(function () {
+ if (
+ !core.hasAsync() &&
+ (data.excludeAnimates ||
+ core.isReplaying() ||
+ core.getPlayingAnimates().length == 0) &&
+ (!data.includeSounds ||
+ core.isReplaying() ||
+ core.getPlayingSounds().length == 0)
+ ) {
+ clearInterval(test);
+ core.doAction();
+ }
+ }, 50 / core.status.replay.speed);
+};
events.prototype._action_stopAsync = function (data, x, y, prefix) {
- core.stopAsync();
- core.doAction();
-}
+ core.stopAsync();
+ core.doAction();
+};
events.prototype._action_callBook = function (data, x, y, prefix) {
- if (core.isReplaying() || !core.hasItem('book')) {
- core.doAction();
- }
- else {
- var e = core.clone(core.status.event.data);
- core.ui.closePanel();
- core.openBook();
- core.status.event.interval = e;
- }
-}
-
-events.prototype._action_callSave = function (data, x, y, prefix) {
- if (core.isReplaying() || core.hasFlag("__events__")) {
- core.removeFlag("__events__");
- core.doAction();
- }
- else {
- var e = core.clone(core.status.event.data);
- core.ui.closePanel();
- var forbidSave = core.hasFlag('__forbidSave__');
- core.removeFlag('__forbidSave__');
- core.save();
- if (forbidSave) core.setFlag('__forbidSave__', true);
- core.status.event.interval = e;
- }
-}
-
-events.prototype._action_autoSave = function (data, x, y, prefix) {
- var forbidSave = core.hasFlag('__forbidSave__');
- core.removeFlag('__forbidSave__');
- core.autosave(data.removeLast);
- if (forbidSave) core.setFlag('__forbidSave__', true);
+ if (core.isReplaying() || !core.hasItem("book")) {
core.doAction();
-}
-
-events.prototype._action_forbidSave = function (data, x, y, prefix) {
- core.setFlag('__forbidSave__', data.forbid || null);
- core.doAction();
-}
-
-events.prototype._action_callLoad = function (data, x, y, prefix) {
- if (this.__action_checkReplaying()) return;
+ } else {
var e = core.clone(core.status.event.data);
core.ui.closePanel();
- core.load();
+ core.openBook();
core.status.event.interval = e;
-}
+ }
+};
+
+events.prototype._action_callSave = function (data, x, y, prefix) {
+ if (core.isReplaying() || core.hasFlag("__events__")) {
+ core.removeFlag("__events__");
+ core.doAction();
+ } else {
+ var e = core.clone(core.status.event.data);
+ core.ui.closePanel();
+ var forbidSave = core.hasFlag("__forbidSave__");
+ core.removeFlag("__forbidSave__");
+ core.save();
+ if (forbidSave) core.setFlag("__forbidSave__", true);
+ core.status.event.interval = e;
+ }
+};
+
+events.prototype._action_autoSave = function (data, x, y, prefix) {
+ var forbidSave = core.hasFlag("__forbidSave__");
+ core.removeFlag("__forbidSave__");
+ core.autosave(data.removeLast);
+ if (forbidSave) core.setFlag("__forbidSave__", true);
+ core.doAction();
+};
+
+events.prototype._action_forbidSave = function (data, x, y, prefix) {
+ core.setFlag("__forbidSave__", data.forbid || null);
+ core.doAction();
+};
+
+events.prototype._action_callLoad = function (data, x, y, prefix) {
+ if (this.__action_checkReplaying()) return;
+ var e = core.clone(core.status.event.data);
+ core.ui.closePanel();
+ core.load();
+ core.status.event.interval = e;
+};
events.prototype._action_exit = function (data, x, y, prefix) {
- this.setEvents([]);
- core.doAction();
-}
+ this.setEvents([]);
+ core.doAction();
+};
events.prototype._action_previewUI = function (data, x, y, prefix) {
- this.insertAction(data.action);
- core.doAction();
-}
+ this.insertAction(data.action);
+ core.doAction();
+};
events.prototype._precompile_previewUI = function (data) {
- data.action = this.precompile(data.action);
- return data;
-}
+ data.action = this.precompile(data.action);
+ return data;
+};
events.prototype.__action_doUIEvent = function (data) {
- this.__action_doUIEvent_doOne(data);
- var current = core.status.event.data.list[0];
- while (current.todo.length > 0) {
- data = current.todo[0];
- if (this.__action_doUIEvent_doOne(current.todo[0]))
- current.todo.shift();
- else break;
- }
- core.doAction();
-}
+ this.__action_doUIEvent_doOne(data);
+ var current = core.status.event.data.list[0];
+ while (current.todo.length > 0) {
+ data = current.todo[0];
+ if (this.__action_doUIEvent_doOne(current.todo[0])) current.todo.shift();
+ else break;
+ }
+ core.doAction();
+};
events.prototype.__action_doUIEvent_doOne = function (data) {
- if (core.ui['_uievent_' + data.type]) {
- core.ui['_uievent_' + data.type](data);
- return true;
- }
- return false;
-}
+ if (core.ui["_uievent_" + data.type]) {
+ core.ui["_uievent_" + data.type](data);
+ return true;
+ }
+ return false;
+};
events.prototype._action_clearMap = function (data, x, y, prefix) {
- this.__action_doUIEvent(data);
-}
+ this.__action_doUIEvent(data);
+};
events.prototype._action_fillText = function (data, x, y, prefix) {
- data.text = core.replaceText(data.text, prefix);
- this.__action_doUIEvent(data);
-}
+ data.text = core.replaceText(data.text, prefix);
+ this.__action_doUIEvent(data);
+};
events.prototype._action_fillBoldText = function (data, x, y, prefix) {
- data.text = core.replaceText(data.text, prefix);
- this.__action_doUIEvent(data);
-}
+ data.text = core.replaceText(data.text, prefix);
+ this.__action_doUIEvent(data);
+};
events.prototype._action_fillRect = function (data, x, y, prefix) {
- this.__action_doUIEvent(data);
-}
+ this.__action_doUIEvent(data);
+};
events.prototype._action_fillPolygon = function (data, x, y, prefix) {
- this.__action_doUIEvent(data);
-}
+ this.__action_doUIEvent(data);
+};
events.prototype._precompile_fillPolygon = function (data) {
- data.nodes = this.__precompile_array(data.nodes);
- return data;
-}
+ data.nodes = this.__precompile_array(data.nodes);
+ return data;
+};
events.prototype._action_strokeRect = function (data, x, y, prefix) {
- this.__action_doUIEvent(data);
-}
+ this.__action_doUIEvent(data);
+};
events.prototype._action_strokePolygon = function (data, x, y, prefix) {
- this.__action_doUIEvent(data);
-}
+ this.__action_doUIEvent(data);
+};
events.prototype._precompile_strokePolygon = function (data) {
- data.nodes = this.__precompile_array(data.nodes);
- return data;
-}
+ data.nodes = this.__precompile_array(data.nodes);
+ return data;
+};
events.prototype._action_fillEllipse = function (data, x, y, prefix) {
- this.__action_doUIEvent(data);
-}
+ this.__action_doUIEvent(data);
+};
events.prototype._action_strokeEllipse = function (data, x, y, prefix) {
- this.__action_doUIEvent(data);
-}
+ this.__action_doUIEvent(data);
+};
events.prototype._action_fillArc = function (data, x, y, prefix) {
- this.__action_doUIEvent(data);
-}
+ this.__action_doUIEvent(data);
+};
events.prototype._action_strokeArc = function (data, x, y, prefix) {
- this.__action_doUIEvent(data);
-}
+ this.__action_doUIEvent(data);
+};
events.prototype._action_drawLine = function (data, x, y, prefix) {
- this.__action_doUIEvent(data);
-}
+ this.__action_doUIEvent(data);
+};
events.prototype._action_drawArrow = function (data, x, y, prefix) {
- this.__action_doUIEvent(data);
-}
+ this.__action_doUIEvent(data);
+};
events.prototype._action_setAttribute = function (data, x, y, prefix) {
- this.__action_doUIEvent(data);
-}
+ this.__action_doUIEvent(data);
+};
events.prototype._action_setFilter = function (data, x, y, prefix) {
- this.__action_doUIEvent(data);
-}
+ this.__action_doUIEvent(data);
+};
events.prototype._action_drawImage = function (data, x, y, prefix) {
- this.__action_doUIEvent(data);
-}
+ this.__action_doUIEvent(data);
+};
events.prototype._action_drawIcon = function (data, x, y, prefix) {
- this.__action_doUIEvent(data);
-}
+ this.__action_doUIEvent(data);
+};
events.prototype._action_drawSelector = function (data, x, y, prefix) {
- this.__action_doUIEvent(data);
-}
+ this.__action_doUIEvent(data);
+};
events.prototype._action_drawBackground = function (data, x, y, prefix) {
- this.__action_doUIEvent(data);
-}
+ this.__action_doUIEvent(data);
+};
events.prototype._action_drawTextContent = function (data, x, y, prefix) {
- data.text = core.replaceText(data.text, prefix);
- this.__action_doUIEvent(data);
-}
+ data.text = core.replaceText(data.text, prefix);
+ this.__action_doUIEvent(data);
+};
// ------ 点击状态栏图标所进行的一些操作 ------ //
////// 判断当前能否进入某个事件 //////
events.prototype._checkStatus = function (name, fromUserAction, checkItem) {
- if (fromUserAction && core.status.event.id == name) {
- core.ui.closePanel();
- return false;
- }
- if (fromUserAction && core.status.lockControl) return false;
- if (checkItem && !core.hasItem(name)) {
- core.playSound('操作失败');
- core.drawTip("你没有" + core.material.items[name].name, name);
- return false;
- }
- if (core.isMoving()) {
- core.playSound('操作失败');
- core.drawTip("请先停止勇士行动");
- return false;
- }
- core.lockControl();
- core.status.event.id = name;
- return true;
-}
+ if (fromUserAction && core.status.event.id == name) {
+ core.ui.closePanel();
+ return false;
+ }
+ if (fromUserAction && core.status.lockControl) return false;
+ if (checkItem && !core.hasItem(name)) {
+ core.playSound("操作失败");
+ core.drawTip("你没有" + core.material.items[name].name, name);
+ return false;
+ }
+ if (core.isMoving()) {
+ core.playSound("操作失败");
+ core.drawTip("请先停止勇士行动");
+ return false;
+ }
+ core.lockControl();
+ core.status.event.id = name;
+ return true;
+};
////// 点击怪物手册时的打开操作 //////
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') {
- fromUserAction = false;
- core.status.event.ui = core.status.event.data;
- }
- if (!this._checkStatus('book', fromUserAction, true)) return;
- core.playSound('打开界面');
- core.useItem('book', true);
-}
+ 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") {
+ fromUserAction = false;
+ core.status.event.ui = core.status.event.data;
+ }
+ if (!this._checkStatus("book", fromUserAction, true)) return;
+ core.playSound("打开界面");
+ core.useItem("book", true);
+};
////// 点击楼层传送器时的打开操作 //////
events.prototype.useFly = function (fromUserAction) {
- if (core.isReplaying()) return;
- // 从“浏览地图”页面:尝试直接传送到该层
- if (core.status.event.id == 'viewMaps') {
- if (!core.hasItem('fly')) {
- core.playSound('操作失败');
- core.drawTip('你没有' + core.material.items['fly'].name, 'fly');
- } else if (!core.canUseItem('fly') || (core.flags.flyNearStair && !core.nearStair())) {
- core.playSound('操作失败');
- core.drawTip('无法传送到当前层', 'fly');
- } else {
- core.flyTo(core.status.event.data.floorId);
- }
- return;
+ if (core.isReplaying()) return;
+ // 从“浏览地图”页面:尝试直接传送到该层
+ if (core.status.event.id == "viewMaps") {
+ if (!core.hasItem("fly")) {
+ core.playSound("操作失败");
+ core.drawTip("你没有" + core.material.items["fly"].name, "fly");
+ } else if (
+ !core.canUseItem("fly") ||
+ (core.flags.flyNearStair && !core.nearStair())
+ ) {
+ core.playSound("操作失败");
+ core.drawTip("无法传送到当前层", "fly");
+ } else {
+ core.flyTo(core.status.event.data.floorId);
}
-
- if (!this._checkStatus('fly', fromUserAction, true)) return;
- if (core.flags.flyNearStair && !core.nearStair()) {
- core.playSound('操作失败');
- core.drawTip("只有在楼梯边才能使用" + core.material.items['fly'].name, 'fly');
- core.unlockControl();
- core.status.event.data = null;
- core.status.event.id = null;
- return;
- }
- if (!core.canUseItem('fly')) {
- core.playSound('操作失败');
- core.drawTip(core.material.items['fly'].name + "好像失效了", 'fly');
- core.unlockControl();
- core.status.event.data = null;
- core.status.event.id = null;
- return;
- }
- core.playSound('打开界面');
- core.useItem('fly', true);
return;
-}
+ }
+
+ if (!this._checkStatus("fly", fromUserAction, true)) return;
+ if (core.flags.flyNearStair && !core.nearStair()) {
+ core.playSound("操作失败");
+ core.drawTip(
+ "只有在楼梯边才能使用" + core.material.items["fly"].name,
+ "fly"
+ );
+ core.unlockControl();
+ core.status.event.data = null;
+ core.status.event.id = null;
+ return;
+ }
+ if (!core.canUseItem("fly")) {
+ core.playSound("操作失败");
+ core.drawTip(core.material.items["fly"].name + "好像失效了", "fly");
+ core.unlockControl();
+ core.status.event.data = null;
+ core.status.event.id = null;
+ return;
+ }
+ core.playSound("打开界面");
+ core.useItem("fly", true);
+ return;
+};
events.prototype.flyTo = function (toId, callback) {
- return this.eventdata.flyTo(toId, callback);
-}
+ return this.eventdata.flyTo(toId, callback);
+};
////// 点击装备栏时的打开操作 //////
events.prototype.openEquipbox = function (fromUserAction) {
- if (core.isReplaying()) return;
- if (!this._checkStatus('equipbox', fromUserAction)) return;
- core.playSound('打开界面');
- core.ui._drawEquipbox();
-}
+ if (core.isReplaying()) return;
+ if (!this._checkStatus("equipbox", fromUserAction)) return;
+ core.playSound("打开界面");
+ core.ui._drawEquipbox();
+};
////// 点击工具栏时的打开操作 //////
events.prototype.openToolbox = function (fromUserAction) {
- if (core.isReplaying()) return;
- if (!this._checkStatus('toolbox', fromUserAction)) return;
- core.playSound('打开界面');
- core.ui._drawToolbox();
-}
+ if (core.isReplaying()) return;
+ if (!this._checkStatus("toolbox", fromUserAction)) return;
+ core.playSound("打开界面");
+ core.ui._drawToolbox();
+};
////// 点击快捷商店按钮时的打开操作 //////
events.prototype.openQuickShop = function (fromUserAction) {
- if (core.isReplaying()) return;
+ if (core.isReplaying()) return;
- if (Object.keys(core.status.shops).length == 0) {
- core.playSound('操作失败');
- core.drawTip("本游戏没有快捷商店!");
- return;
+ if (Object.keys(core.status.shops).length == 0) {
+ core.playSound("操作失败");
+ core.drawTip("本游戏没有快捷商店!");
+ return;
+ }
+
+ // --- 如果只有一个商店,则直接打开之
+ if (Object.keys(core.status.shops).length == 1) {
+ var shopId = Object.keys(core.status.shops)[0];
+ if (core.status.event.id != null) return;
+ if (!core.canOpenShop(shopId)) {
+ core.playSound("操作失败");
+ core.drawTip("当前无法打开快捷商店!");
+ return;
}
-
- // --- 如果只有一个商店,则直接打开之
- if (Object.keys(core.status.shops).length == 1) {
- var shopId = Object.keys(core.status.shops)[0];
- if (core.status.event.id != null) return;
- if (!core.canOpenShop(shopId)) {
- core.playSound('操作失败');
- core.drawTip("当前无法打开快捷商店!");
- return;
- }
- var message = core.canUseQuickShop(shopId);
- if (message != null) {
- core.playSound('操作失败');
- core.drawTip(message);
- return;
- }
- core.openShop(shopId, false);
- return;
+ var message = core.canUseQuickShop(shopId);
+ if (message != null) {
+ core.playSound("操作失败");
+ core.drawTip(message);
+ return;
}
+ core.openShop(shopId, false);
+ return;
+ }
- if (!this._checkStatus('selectShop', fromUserAction)) return;
- core.ui._drawQuickShop();
-}
+ if (!this._checkStatus("selectShop", fromUserAction)) return;
+ core.ui._drawQuickShop();
+};
events.prototype.openKeyBoard = function (fromUserAction) {
- if (core.isReplaying()) return;
- if (!this._checkStatus('keyBoard', fromUserAction)) return;
- core.ui._drawKeyBoard();
-}
+ if (core.isReplaying()) return;
+ if (!this._checkStatus("keyBoard", fromUserAction)) return;
+ core.ui._drawKeyBoard();
+};
////// 点击保存按钮时的打开操作 //////
events.prototype.save = function (fromUserAction) {
- if (core.isReplaying()) return;
- if (core.hasFlag('__forbidSave__')) {
- core.playSound('操作失败');
- core.drawTip('当前禁止存档');
- return;
- }
- if (core.status.event.id == 'save' && core.events.recoverEvents(core.status.event.interval))
- return;
- if (!this._checkStatus('save', fromUserAction)) return;
- var saveIndex = core.saves.saveIndex;
- var page = parseInt((saveIndex - 1) / 5), offset = saveIndex - 5 * page;
- core.playSound('打开界面');
- core.ui._drawSLPanel(10 * page + offset);
-}
+ if (core.isReplaying()) return;
+ if (core.hasFlag("__forbidSave__")) {
+ core.playSound("操作失败");
+ core.drawTip("当前禁止存档");
+ return;
+ }
+ if (
+ core.status.event.id == "save" &&
+ core.events.recoverEvents(core.status.event.interval)
+ )
+ return;
+ if (!this._checkStatus("save", fromUserAction)) return;
+ var saveIndex = core.saves.saveIndex;
+ var page = parseInt((saveIndex - 1) / 5),
+ offset = saveIndex - 5 * page;
+ core.playSound("打开界面");
+ core.ui._drawSLPanel(10 * page + offset);
+};
////// 点击读取按钮时的打开操作 //////
events.prototype.load = function (fromUserAction) {
- if (core.isReplaying()) return;
- var saveIndex = core.saves.saveIndex;
- var page = parseInt((saveIndex - 1) / 5), offset = saveIndex - 5 * page;
- // 游戏开始前读档
- if (!core.isPlaying()) {
- core.dom.startPanel.style.display = 'none';
- core.clearStatus();
- core.clearMap('all');
- core.status.event = { 'id': 'load', 'data': null };
- core.status.lockControl = true;
- core.playSound('打开界面');
- core.ui._drawSLPanel(10 * page + offset);
- return;
- }
- if (core.status.event.id == 'load' && core.events.recoverEvents(core.status.event.interval))
- return;
- if (!this._checkStatus('load', fromUserAction)) return;
- core.playSound('打开界面');
+ if (core.isReplaying()) return;
+ var saveIndex = core.saves.saveIndex;
+ var page = parseInt((saveIndex - 1) / 5),
+ offset = saveIndex - 5 * page;
+ // 游戏开始前读档
+ if (!core.isPlaying()) {
+ core.dom.startPanel.style.display = "none";
+ core.clearStatus();
+ core.clearMap("all");
+ core.status.event = { id: "load", data: null };
+ core.status.lockControl = true;
+ core.playSound("打开界面");
core.ui._drawSLPanel(10 * page + offset);
-}
+ return;
+ }
+ if (
+ core.status.event.id == "load" &&
+ core.events.recoverEvents(core.status.event.interval)
+ )
+ return;
+ if (!this._checkStatus("load", fromUserAction)) return;
+ core.playSound("打开界面");
+ core.ui._drawSLPanel(10 * page + offset);
+};
////// 点击设置按钮时的操作 //////
events.prototype.openSettings = function (fromUserAction) {
- if (core.isReplaying()) return;
- if (!this._checkStatus('settings', fromUserAction))
- return;
- core.playSound('打开界面');
- core.ui._drawSettings();
-}
+ if (core.isReplaying()) return;
+ if (!this._checkStatus("settings", fromUserAction)) return;
+ core.playSound("打开界面");
+ core.ui._drawSettings();
+};
// ------ 一些事件的具体执行过程 ------ //
events.prototype.hasAsync = function () {
- return Object.keys(core.animateFrame.asyncId).length > 0;
-}
+ return Object.keys(core.animateFrame.asyncId).length > 0;
+};
////// 立刻停止所有异步事件 //////
events.prototype.stopAsync = function () {
- var callbacks = [];
- for (var id in core.animateFrame.asyncId) {
- clearInterval(id);
- callbacks.push(core.animateFrame.asyncId[id]);
- }
- core.animateFrame.asyncId = {};
- callbacks.forEach(function (cb) {
- if (cb && cb instanceof Function) cb();
- });
-}
+ var callbacks = [];
+ for (var id in core.animateFrame.asyncId) {
+ clearInterval(id);
+ callbacks.push(core.animateFrame.asyncId[id]);
+ }
+ core.animateFrame.asyncId = {};
+ callbacks.forEach(function (cb) {
+ if (cb && cb instanceof Function) cb();
+ });
+};
events.prototype.hasAsyncAnimate = function () {
- return (core.status.animateObjs || []).length > 0;
-}
+ return (core.status.animateObjs || []).length > 0;
+};
////// 跟随 //////
events.prototype.follow = function (name) {
- name = core.getMappedName(name);
- if (core.material.images.images[name]) {
- core.status.hero.followers.push({ "name": name });
- core.gatherFollowers();
- core.clearMap('hero');
- core.drawHero();
- }
- core.clearRouteFolding();
-}
+ name = core.getMappedName(name);
+ if (core.material.images.images[name]) {
+ core.status.hero.followers.push({ name: name });
+ core.gatherFollowers();
+ core.clearMap("hero");
+ core.drawHero();
+ }
+ core.clearRouteFolding();
+};
////// 取消跟随 //////
events.prototype.unfollow = function (name) {
- if (!name) {
- core.status.hero.followers = [];
+ if (!name) {
+ core.status.hero.followers = [];
+ } else {
+ name = core.getMappedName(name);
+ for (var i = 0; i < core.status.hero.followers.length; i++) {
+ if (core.status.hero.followers[i].name == name) {
+ core.status.hero.followers.splice(i, 1);
+ break;
+ }
}
- else {
- name = core.getMappedName(name);
- for (var i = 0; i < core.status.hero.followers.length; i++) {
- if (core.status.hero.followers[i].name == name) {
- core.status.hero.followers.splice(i, 1);
- break;
- }
- }
- }
- core.gatherFollowers();
- core.clearMap('hero');
- core.drawHero();
- core.clearRouteFolding();
-}
+ }
+ core.gatherFollowers();
+ core.clearMap("hero");
+ core.drawHero();
+ core.clearRouteFolding();
+};
-events.prototype._updateValueByOperator = function (value, originValue, operator) {
- switch (operator) {
- case '+=': value = originValue + value; break;
- case '-=': value = originValue - value; break;
- case '*=': value = originValue * value; break;
- case '/=': value = originValue / value; break;
- case '**=': value = Math.pow(originValue, value); break;
- case '//=': value = Math.trunc(originValue / value); break;
- case '%=': value = originValue % value; break;
- case 'min=': value = Math.min(originValue, value); break;
- case 'max=': value = Math.max(originValue, value); break;
- default: break;
- }
- return value;
-}
+events.prototype._updateValueByOperator = function (
+ value,
+ originValue,
+ operator
+) {
+ switch (operator) {
+ case "+=":
+ value = originValue + value;
+ break;
+ case "-=":
+ value = originValue - value;
+ break;
+ case "*=":
+ value = originValue * value;
+ break;
+ case "/=":
+ value = originValue / value;
+ break;
+ case "**=":
+ value = Math.pow(originValue, value);
+ break;
+ case "//=":
+ value = Math.trunc(originValue / value);
+ break;
+ case "%=":
+ value = originValue % value;
+ break;
+ case "min=":
+ value = Math.min(originValue, value);
+ break;
+ case "max=":
+ value = Math.max(originValue, value);
+ break;
+ default:
+ break;
+ }
+ return value;
+};
////// 数值操作 //////
events.prototype.setValue = function (name, operator, value, prefix) {
- value = this._updateValueByOperator(core.calValue(value, prefix), core.calValue(name, prefix), operator);
- this._setValue_setStatus(name, value);
- this._setValue_setBuff(name, value);
- this._setValue_setItem(name, value);
- this._setValue_setFlag(name, value);
- this._setValue_setSwitch(name, value, prefix);
- this._setValue_setTemp(name, value, prefix);
- this._setValue_setGlobal(name, value);
-}
+ value = this._updateValueByOperator(
+ core.calValue(value, prefix),
+ core.calValue(name, prefix),
+ operator
+ );
+ this._setValue_setStatus(name, value);
+ this._setValue_setBuff(name, value);
+ this._setValue_setItem(name, value);
+ this._setValue_setFlag(name, value);
+ this._setValue_setSwitch(name, value, prefix);
+ this._setValue_setTemp(name, value, prefix);
+ this._setValue_setGlobal(name, value);
+};
events.prototype._setValue_setStatus = function (name, value) {
- if (name.indexOf("status:") !== 0) return;
- core.setStatus(name.substring(7), value);
-}
+ if (name.indexOf("status:") !== 0) return;
+ core.setStatus(name.substring(7), value);
+};
events.prototype._setValue_setBuff = function (name, value) {
- if (name.indexOf('buff:') !== 0) return;
- core.setBuff(name.substring(5), value);
-}
+ if (name.indexOf("buff:") !== 0) return;
+ core.setBuff(name.substring(5), value);
+};
events.prototype._setValue_setItem = function (name, value) {
- if (name.indexOf("item:") !== 0) return;
- var itemId = name.substring(5), count = core.itemCount(itemId);
- if (value > count) core.getItem(itemId, value - count);
- else core.setItem(itemId, value);
-}
+ if (name.indexOf("item:") !== 0) return;
+ var itemId = name.substring(5),
+ count = core.itemCount(itemId);
+ if (value > count) core.getItem(itemId, value - count);
+ else core.setItem(itemId, value);
+};
events.prototype._setValue_setFlag = function (name, value) {
- if (name.indexOf("flag:") !== 0) return;
- core.setFlag(name.substring(5), value);
-}
+ if (name.indexOf("flag:") !== 0) return;
+ core.setFlag(name.substring(5), value);
+};
events.prototype._setValue_setSwitch = function (name, value, prefix) {
- if (name.indexOf("switch:") !== 0) return;
- core.setFlag((prefix || ":f@x@y") + "@" + name.substring(7), value);
-}
+ if (name.indexOf("switch:") !== 0) return;
+ core.setFlag((prefix || ":f@x@y") + "@" + name.substring(7), value);
+};
events.prototype._setValue_setTemp = function (name, value) {
- if (name.indexOf("temp:") !== 0) return;
- core.setFlag("@temp@" + name.substring(5), value);
-}
+ if (name.indexOf("temp:") !== 0) return;
+ core.setFlag("@temp@" + name.substring(5), value);
+};
events.prototype._setValue_setGlobal = function (name, value) {
- if (name.indexOf("global:") !== 0) return;
- core.setGlobal(name.substring(7), value);
-}
+ if (name.indexOf("global:") !== 0) return;
+ core.setGlobal(name.substring(7), value);
+};
////// 设置一个怪物属性 //////
-events.prototype.setEnemy = function (id, name, value, operator, prefix, norefresh) {
- if (!core.hasFlag('enemyInfo')) {
- core.setFlag('enemyInfo', {});
- }
- var enemyInfo = core.getFlag('enemyInfo');
- if (!enemyInfo[id]) enemyInfo[id] = {};
- if (typeof value === 'string' && name == 'name') value = value.replace(/\r/g, '\\r');
- value = this._updateValueByOperator(core.calValue(value, prefix), (core.material.enemys[id] || {})[name], operator);
- enemyInfo[id][name] = value;
- (core.material.enemys[id] || {})[name] = core.clone(value);
- if (!norefresh) core.updateStatusBar();
-}
+events.prototype.setEnemy = function (
+ id,
+ name,
+ value,
+ operator,
+ prefix,
+ norefresh
+) {
+ if (!core.hasFlag("enemyInfo")) {
+ core.setFlag("enemyInfo", {});
+ }
+ var enemyInfo = core.getFlag("enemyInfo");
+ if (!enemyInfo[id]) enemyInfo[id] = {};
+ if (typeof value === "string" && name == "name")
+ value = value.replace(/\r/g, "\\r");
+ value = this._updateValueByOperator(
+ core.calValue(value, prefix),
+ (core.material.enemys[id] || {})[name],
+ operator
+ );
+ enemyInfo[id][name] = value;
+ (core.material.enemys[id] || {})[name] = core.clone(value);
+ if (!norefresh) core.updateStatusBar();
+};
////// 设置某个点上的怪物属性 //////
-events.prototype.setEnemyOnPoint = function (x, y, floorId, name, value, operator, prefix, norefresh) {
- floorId = floorId || core.status.floorId;
- var block = core.getBlock(x, y, floorId);
- if (block == null) return;
- if (block.event.cls.indexOf('enemy') != 0) return;
- var enemy = core.material.enemys[block.event.id];
- if (enemy == null) return;
- if (typeof value === 'string' && name == 'name') value = value.replaceAll(/\r/g, '\\r');
- value = this._updateValueByOperator(core.calValue(value, prefix), core.getEnemyValue(enemy, name, x, y, floorId), operator);
- flags.enemyOnPoint = flags.enemyOnPoint || {};
- flags.enemyOnPoint[floorId] = flags.enemyOnPoint[floorId] || {};
- flags.enemyOnPoint[floorId][x + "," + y] = flags.enemyOnPoint[floorId][x + "," + y] || {};
- flags.enemyOnPoint[floorId][x + "," + y][name] = value;
- if (!norefresh) core.updateStatusBar();
-}
+events.prototype.setEnemyOnPoint = function (
+ x,
+ y,
+ floorId,
+ name,
+ value,
+ operator,
+ prefix,
+ norefresh
+) {
+ floorId = floorId || core.status.floorId;
+ var block = core.getBlock(x, y, floorId);
+ if (block == null) return;
+ if (block.event.cls.indexOf("enemy") != 0) return;
+ var enemy = core.material.enemys[block.event.id];
+ if (enemy == null) return;
+ if (typeof value === "string" && name == "name")
+ value = value.replaceAll(/\r/g, "\\r");
+ value = this._updateValueByOperator(
+ core.calValue(value, prefix),
+ core.getEnemyValue(enemy, name, x, y, floorId),
+ operator
+ );
+ flags.enemyOnPoint = flags.enemyOnPoint || {};
+ flags.enemyOnPoint[floorId] = flags.enemyOnPoint[floorId] || {};
+ flags.enemyOnPoint[floorId][x + "," + y] =
+ flags.enemyOnPoint[floorId][x + "," + y] || {};
+ flags.enemyOnPoint[floorId][x + "," + y][name] = value;
+ if (!norefresh) core.updateStatusBar();
+};
////// 重置某个点上的怪物属性 //////
events.prototype.resetEnemyOnPoint = function (x, y, floorId, norefresh) {
- delete ((flags.enemyOnPoint || {})[floorId || core.status.floorId] || {})[x + "," + y];
- if (!norefresh) core.updateStatusBar();
-}
+ delete ((flags.enemyOnPoint || {})[floorId || core.status.floorId] || {})[
+ x + "," + y
+ ];
+ if (!norefresh) core.updateStatusBar();
+};
////// 将某个点上已经设置的怪物属性移动到其他点 //////
-events.prototype.moveEnemyOnPoint = function (fromX, fromY, toX, toY, floorId, norefresh) {
- floorId = floorId || core.status.floorId;
- if (((flags.enemyOnPoint || {})[floorId] || {})[fromX + "," + fromY]) {
- flags.enemyOnPoint[floorId][toX + "," + toY] = flags.enemyOnPoint[floorId][fromX + "," + fromY];
- delete flags.enemyOnPoint[floorId][fromX + "," + fromY];
- if (!norefresh) core.updateStatusBar();
- }
-}
+events.prototype.moveEnemyOnPoint = function (
+ fromX,
+ fromY,
+ toX,
+ toY,
+ floorId,
+ norefresh
+) {
+ floorId = floorId || core.status.floorId;
+ if (((flags.enemyOnPoint || {})[floorId] || {})[fromX + "," + fromY]) {
+ flags.enemyOnPoint[floorId][toX + "," + toY] =
+ flags.enemyOnPoint[floorId][fromX + "," + fromY];
+ delete flags.enemyOnPoint[floorId][fromX + "," + fromY];
+ if (!norefresh) core.updateStatusBar();
+ }
+};
////// 设置楼层属性 //////
events.prototype.setFloorInfo = function (name, value, floorId, prefix) {
- floorId = floorId || core.status.floorId;
- core.status.maps[floorId][name] = value;
- core.updateStatusBar();
-}
+ floorId = floorId || core.status.floorId;
+ core.status.maps[floorId][name] = value;
+ core.updateStatusBar();
+};
////// 设置全塔属性 //////
events.prototype.setGlobalAttribute = function (name, value) {
- if (typeof value == 'string') {
- if ((value.charAt(0) == '"' && value.charAt(value.length - 1) == '"')
- || (value.charAt(0) == "'" && value.charAt(value.length - 1) == "'"))
- value = value.substring(1, value.length - 1);
- // --- 检查 []
- if (value.charAt(0) == '[' && value.charAt(value.length - 1) == ']')
- value = eval(value);
- // --- 检查颜色
- if (/^[0-9 ]+,[0-9 ]+,[0-9 ]+(,[0-9. ]+)?$/.test(value)) {
- value = 'rgba(' + value + ')';
- }
+ if (typeof value == "string") {
+ if (
+ (value.charAt(0) == '"' && value.charAt(value.length - 1) == '"') ||
+ (value.charAt(0) == "'" && value.charAt(value.length - 1) == "'")
+ )
+ value = value.substring(1, value.length - 1);
+ // --- 检查 []
+ if (value.charAt(0) == "[" && value.charAt(value.length - 1) == "]")
+ value = eval(value);
+ // --- 检查颜色
+ if (/^[0-9 ]+,[0-9 ]+,[0-9 ]+(,[0-9. ]+)?$/.test(value)) {
+ value = "rgba(" + value + ")";
}
- core.status.globalAttribute[name] = value;
- core.setFlag('globalAttribute', core.status.globalAttribute);
- core.resize();
-}
+ }
+ core.status.globalAttribute[name] = value;
+ core.setFlag("globalAttribute", core.status.globalAttribute);
+ core.resize();
+};
////// 设置全局开关 //////
events.prototype.setGlobalFlag = function (name, value) {
- var flags = core.getFlag("globalFlags", {});
- if (name.startsWith('s:')) {
- name = name.substring(2);
- var statusBarItems = core.flags.statusBarItems.filter(function (v) { return v != name; });
- if (value) statusBarItems.push(name);
- core.flags.statusBarItems = statusBarItems;
- flags.statusBarItems = core.clone(statusBarItems);
- } else {
- flags[name] = core.flags[name] = value;
- }
- core.setFlag("globalFlags", flags);
- core.resize();
- if (name == 'blurFg')
- core.redrawMap();
-}
+ var flags = core.getFlag("globalFlags", {});
+ if (name.startsWith("s:")) {
+ name = name.substring(2);
+ var statusBarItems = core.flags.statusBarItems.filter(function (v) {
+ return v != name;
+ });
+ if (value) statusBarItems.push(name);
+ core.flags.statusBarItems = statusBarItems;
+ flags.statusBarItems = core.clone(statusBarItems);
+ } else {
+ flags[name] = core.flags[name] = value;
+ }
+ core.setFlag("globalFlags", flags);
+ core.resize();
+ if (name == "blurFg") core.redrawMap();
+};
////// 设置文件别名 //////
events.prototype.setNameMap = function (name, value) {
- if (!core.hasFlag('__nameMap__')) core.setFlag('__nameMap__', {});
- flags.__nameMap__[name] = value;
-}
+ if (!core.hasFlag("__nameMap__")) core.setFlag("__nameMap__", {});
+ flags.__nameMap__[name] = value;
+};
////// 设置剧情文本的属性 //////
events.prototype.setTextAttribute = function (data) {
- if (!core.isPlaying()) return;
- ["position", "offset", "align", "bold", "titlefont", "textfont", "lineHeight", "time", "letterSpacing", "animateTime"].forEach(function (t) {
- if (data[t] != null) core.status.textAttribute[t] = data[t];
- });
- ["background", "title", "text"].forEach(function (t) {
- if ((data[t] instanceof Array) && data[t].length >= 3) {
- if (data[t].length == 3) data[t].push(1);
- core.status.textAttribute[t] = data[t];
- }
- if (t == 'background') {
- var name = core.getMappedName(data[t]);
- var img = core.material.images.images[name];
- if (img && img.width == 192 && img.height == 128) {
- core.status.textAttribute[t] = name;
- }
- }
- });
- if (main.mode == 'play') core.setFlag('textAttribute', core.status.textAttribute);
-}
-
-events.prototype.moveTextBox = function (code, loc, relative, moveMode, time, callback) {
- var ctx = core.getContextByName('__text__' + code);
- if (!ctx) {
- if (callback) callback();
- return;
+ if (!core.isPlaying()) return;
+ [
+ "position",
+ "offset",
+ "align",
+ "bold",
+ "titlefont",
+ "textfont",
+ "lineHeight",
+ "time",
+ "letterSpacing",
+ "animateTime",
+ ].forEach(function (t) {
+ if (data[t] != null) core.status.textAttribute[t] = data[t];
+ });
+ ["background", "title", "text"].forEach(function (t) {
+ if (data[t] instanceof Array && data[t].length >= 3) {
+ if (data[t].length == 3) data[t].push(1);
+ core.status.textAttribute[t] = data[t];
}
- var sx = parseInt(ctx.canvas.getAttribute('_text_left')) || 0;
- var sy = parseInt(ctx.canvas.getAttribute('_text_top')) || 0;
- var dx = relative ? loc[0] : (loc[0] - sx);
- var dy = relative ? loc[1] : (loc[1] - sy);
- var ox = parseInt(ctx.canvas.getAttribute('_left')) || 0;
- var oy = parseInt(ctx.canvas.getAttribute('_top')) || 0;
-
- if (!time) {
- core.relocateCanvas(ctx, ox + dx, oy + dy);
- ctx.canvas.setAttribute('_text_left', loc[0]);
- ctx.canvas.setAttribute('_text_top', loc[1]);
- if (callback) callback();
- return;
+ if (t == "background") {
+ var name = core.getMappedName(data[t]);
+ var img = core.material.images.images[name];
+ if (img && img.width == 192 && img.height == 128) {
+ core.status.textAttribute[t] = name;
+ }
}
+ });
+ if (main.mode == "play")
+ core.setFlag("textAttribute", core.status.textAttribute);
+};
- var moveInfo = {
- sx: sx, sy: sy, dx: dx, dy: dy, ox: ox, oy: oy,
- moveMode: moveMode, time: time / Math.max(core.status.replay.speed, 1)
- };
- this._moveTextBox_moving(ctx, moveInfo, callback);
-}
+events.prototype.moveTextBox = function (
+ code,
+ loc,
+ relative,
+ moveMode,
+ time,
+ callback
+) {
+ var ctx = core.getContextByName("__text__" + code);
+ if (!ctx) {
+ if (callback) callback();
+ return;
+ }
+ var sx = parseInt(ctx.canvas.getAttribute("_text_left")) || 0;
+ var sy = parseInt(ctx.canvas.getAttribute("_text_top")) || 0;
+ var dx = relative ? loc[0] : loc[0] - sx;
+ var dy = relative ? loc[1] : loc[1] - sy;
+ var ox = parseInt(ctx.canvas.getAttribute("_left")) || 0;
+ var oy = parseInt(ctx.canvas.getAttribute("_top")) || 0;
+
+ if (!time) {
+ core.relocateCanvas(ctx, ox + dx, oy + dy);
+ ctx.canvas.setAttribute("_text_left", loc[0]);
+ ctx.canvas.setAttribute("_text_top", loc[1]);
+ if (callback) callback();
+ return;
+ }
+
+ var moveInfo = {
+ sx: sx,
+ sy: sy,
+ dx: dx,
+ dy: dy,
+ ox: ox,
+ oy: oy,
+ moveMode: moveMode,
+ time: time / Math.max(core.status.replay.speed, 1),
+ };
+ this._moveTextBox_moving(ctx, moveInfo, callback);
+};
events.prototype._moveTextBox_moving = function (ctx, moveInfo, callback) {
- var step = 0, steps = moveInfo.time / 10;
- if (steps <= 0) steps = 1;
- var moveFunc = core.applyEasing(moveInfo.moveMode);
- var animate = setInterval(function () {
- step++;
- var dx = moveInfo.dx * moveFunc(step / steps);
- var dy = moveInfo.dy * moveFunc(step / steps);
- core.relocateCanvas(ctx, parseInt(moveInfo.ox + dx), parseInt(moveInfo.oy + dy));
- ctx.canvas.setAttribute('_text_left', moveInfo.sx + dx);
- ctx.canvas.setAttribute('_text_top', moveInfo.sy + dy);
- if (step == steps) {
- delete core.animateFrame.asyncId[animate];
- clearInterval(animate);
- if (callback) callback();
- }
- }, 10);
+ var step = 0,
+ steps = moveInfo.time / 10;
+ if (steps <= 0) steps = 1;
+ var moveFunc = core.applyEasing(moveInfo.moveMode);
+ var animate = setInterval(function () {
+ step++;
+ var dx = moveInfo.dx * moveFunc(step / steps);
+ var dy = moveInfo.dy * moveFunc(step / steps);
+ core.relocateCanvas(
+ ctx,
+ parseInt(moveInfo.ox + dx),
+ parseInt(moveInfo.oy + dy)
+ );
+ ctx.canvas.setAttribute("_text_left", moveInfo.sx + dx);
+ ctx.canvas.setAttribute("_text_top", moveInfo.sy + dy);
+ if (step == steps) {
+ delete core.animateFrame.asyncId[animate];
+ clearInterval(animate);
+ if (callback) callback();
+ }
+ }, 10);
- core.animateFrame.lastAsyncId = animate;
- core.animateFrame.asyncId[animate] = callback;
-}
+ core.animateFrame.lastAsyncId = animate;
+ core.animateFrame.asyncId[animate] = callback;
+};
////// 清除对话框 //////
events.prototype.clearTextBox = function (code, callback) {
- if (code == null) {
- code = Object.keys(core.dymCanvas).filter(function (one) { return one.startsWith('__text__') })
- .map(function (one) { return one.substring('__text__'.length); })
- }
+ if (code == null) {
+ code = Object.keys(core.dymCanvas)
+ .filter(function (one) {
+ return one.startsWith("__text__");
+ })
+ .map(function (one) {
+ return one.substring("__text__".length);
+ });
+ }
- if (!(code instanceof Array)) code = [code];
- var index = 0;
- var _work = function () {
- if (index == code.length) {
- if (callback) callback();
- return;
- }
- var ctx = '__text__' + code[index++];
- if (!core.getContextByName(ctx)) return _work();
- core.ui._animateUI('hide', ctx, function () {
- core.deleteCanvas(ctx);
- _work();
- });
- };
- _work();
-}
+ if (!(code instanceof Array)) code = [code];
+ var index = 0;
+ var _work = function () {
+ if (index == code.length) {
+ if (callback) callback();
+ return;
+ }
+ var ctx = "__text__" + code[index++];
+ if (!core.getContextByName(ctx)) return _work();
+ core.ui._animateUI("hide", ctx, function () {
+ core.deleteCanvas(ctx);
+ _work();
+ });
+ };
+ _work();
+};
////// 关门 //////
events.prototype.closeDoor = function (x, y, id, callback) {
- id = id || "";
- if ((core.material.icons.animates[id] == null && core.material.icons.npc48[id] == null)
- || core.getBlock(x, y) != null) {
- if (callback) callback();
+ id = id || "";
+ if (
+ (core.material.icons.animates[id] == null &&
+ core.material.icons.npc48[id] == null) ||
+ core.getBlock(x, y) != null
+ ) {
+ if (callback) callback();
+ return;
+ }
+ var block = core.getBlockById(id);
+ var doorInfo = (block.event || {}).doorInfo;
+ if (!doorInfo) {
+ if (callback) callback();
+ return;
+ }
+
+ core.playSound(doorInfo.closeSound);
+ var blockInfo = core.getBlockInfo(block);
+ var speed = (doorInfo.time || 160) / 4;
+ blockInfo.posX = 3;
+ core.maps._drawBlockInfo(blockInfo, x, y);
+
+ var cb = function () {
+ core.setBlock(id, x, y);
+ core.showBlock(x, y);
+ if (callback) callback();
+ };
+
+ var animate = window.setInterval(
+ function () {
+ blockInfo.posX--;
+ if (blockInfo.posX < 0) {
+ clearInterval(animate);
+ delete core.animateFrame.asyncId[animate];
+ cb();
return;
- }
- var block = core.getBlockById(id);
- var doorInfo = (block.event || {}).doorInfo;
- if (!doorInfo) {
- if (callback) callback();
- return;
- }
+ }
+ core.maps._drawBlockInfo(blockInfo, x, y);
+ },
+ core.status.replay.speed == 24
+ ? 1
+ : speed / Math.max(core.status.replay.speed, 1)
+ );
- core.playSound(doorInfo.closeSound);
- var blockInfo = core.getBlockInfo(block);
- var speed = (doorInfo.time || 160) / 4;
- blockInfo.posX = 3;
- core.maps._drawBlockInfo(blockInfo, x, y);
-
- var cb = function () {
- core.setBlock(id, x, y);
- core.showBlock(x, y);
- if (callback) callback();
- }
-
- var animate = window.setInterval(function () {
- blockInfo.posX--;
- if (blockInfo.posX < 0) {
- clearInterval(animate);
- delete core.animateFrame.asyncId[animate];
- cb();
- return;
- }
- core.maps._drawBlockInfo(blockInfo, x, y);
- }, core.status.replay.speed == 24 ? 1 : speed / Math.max(core.status.replay.speed, 1));
-
- core.animateFrame.lastAsyncId = animate;
- core.animateFrame.asyncId[animate] = cb;
-}
+ core.animateFrame.lastAsyncId = animate;
+ core.animateFrame.asyncId[animate] = cb;
+};
////// 显示图片 //////
-events.prototype.showImage = function (code, image, sloc, loc, opacityVal, time, callback) {
- var imageName = null;
- if (typeof image == 'string') {
- imageName = image;
- if (image.endsWith(':x') || image.endsWith(':y') || image.endsWith(':o')) {
- image = image.substring(0, image.length - 2);
- }
- image = core.getMappedName(image);
- image = core.material.images.images[image];
+events.prototype.showImage = function (
+ code,
+ image,
+ sloc,
+ loc,
+ opacityVal,
+ time,
+ callback
+) {
+ var imageName = null;
+ if (typeof image == "string") {
+ imageName = image;
+ if (image.endsWith(":x") || image.endsWith(":y") || image.endsWith(":o")) {
+ image = image.substring(0, image.length - 2);
}
- if (!image) {
- if (callback) callback();
- return;
- }
- sloc = sloc || [];
- var sx = core.calValue(sloc[0]) || 0, sy = core.calValue(sloc[1]) || 0;
- var sw = core.calValue(sloc[2]), sh = core.calValue(sloc[3]);
- if (sw == null) sw = image.width;
- if (sh == null) sh = image.height;
- loc = loc || [];
- var x = core.calValue(loc[0]) || 0, y = core.calValue(loc[1]) || 0;
- var w = core.calValue(loc[2]), h = core.calValue(loc[3]);
- if (w == null) w = sw;
- if (h == null) h = sh;
- var zIndex = code + 100;
- time = time || 0;
- var name = "image" + zIndex;
- var ctx = core.createCanvas(name, x, y, w, h, zIndex);
- core.drawImage(ctx, imageName == null ? image : imageName, sx, sy, sw, sh, 0, 0, w, h);
- if (time == 0) {
- core.setOpacity(name, opacityVal);
- if (callback) callback();
- return;
- }
- core.setOpacity(name, 0);
- this.moveImage(code, null, opacityVal, null, time, callback);
-}
+ image = core.getMappedName(image);
+ image = core.material.images.images[image];
+ }
+ if (!image) {
+ if (callback) callback();
+ return;
+ }
+ sloc = sloc || [];
+ var sx = core.calValue(sloc[0]) || 0,
+ sy = core.calValue(sloc[1]) || 0;
+ var sw = core.calValue(sloc[2]),
+ sh = core.calValue(sloc[3]);
+ if (sw == null) sw = image.width;
+ if (sh == null) sh = image.height;
+ loc = loc || [];
+ var x = core.calValue(loc[0]) || 0,
+ y = core.calValue(loc[1]) || 0;
+ var w = core.calValue(loc[2]),
+ h = core.calValue(loc[3]);
+ if (w == null) w = sw;
+ if (h == null) h = sh;
+ var zIndex = code + 100;
+ time = time || 0;
+ var name = "image" + zIndex;
+ var ctx = core.createCanvas(name, x, y, w, h, zIndex);
+ core.drawImage(
+ ctx,
+ imageName == null ? image : imageName,
+ sx,
+ sy,
+ sw,
+ sh,
+ 0,
+ 0,
+ w,
+ h
+ );
+ if (time == 0) {
+ core.setOpacity(name, opacityVal);
+ if (callback) callback();
+ return;
+ }
+ core.setOpacity(name, 0);
+ this.moveImage(code, null, opacityVal, null, time, callback);
+};
////// 隐藏图片 //////
events.prototype.hideImage = function (code, time, callback) {
- time = time || 0;
- var name = "image" + (code + 100);
- if (time == 0 || !core.dymCanvas[name]) {
- core.deleteCanvas(name);
- if (callback) callback();
- return;
- }
- this.moveImage(code, null, 0, null, time, function () {
- core.deleteCanvas(name);
- if (callback) callback();
- });
-}
+ time = time || 0;
+ var name = "image" + (code + 100);
+ if (time == 0 || !core.dymCanvas[name]) {
+ core.deleteCanvas(name);
+ if (callback) callback();
+ return;
+ }
+ this.moveImage(code, null, 0, null, time, function () {
+ core.deleteCanvas(name);
+ if (callback) callback();
+ });
+};
////// 移动图片 //////
-events.prototype.moveImage = function (code, to, opacityVal, moveMode, time, callback) {
- to = to || [];
- var name = "image" + (code + 100);
- if (!core.dymCanvas[name]) {
- if (callback) callback();
- return;
- }
- var getOrDefault = function (a, b) {
- a = core.calValue(a);
- return a != null ? a : b;
- }
- var canvas = core.dymCanvas[name].canvas;
- var fromX = parseFloat(canvas.getAttribute("_left")),
- fromY = parseFloat(canvas.getAttribute("_top")),
- toX = getOrDefault(to[0], fromX), toY = getOrDefault(to[1], fromY);
+events.prototype.moveImage = function (
+ code,
+ to,
+ opacityVal,
+ moveMode,
+ time,
+ callback
+) {
+ to = to || [];
+ var name = "image" + (code + 100);
+ if (!core.dymCanvas[name]) {
+ if (callback) callback();
+ return;
+ }
+ var getOrDefault = function (a, b) {
+ a = core.calValue(a);
+ return a != null ? a : b;
+ };
+ var canvas = core.dymCanvas[name].canvas;
+ var fromX = parseFloat(canvas.getAttribute("_left")),
+ fromY = parseFloat(canvas.getAttribute("_top")),
+ toX = getOrDefault(to[0], fromX),
+ toY = getOrDefault(to[1], fromY);
- var opacity = parseFloat(canvas.style.opacity), toOpacity = getOrDefault(opacityVal, opacity);
+ var opacity = parseFloat(canvas.style.opacity),
+ toOpacity = getOrDefault(opacityVal, opacity);
- if (!time) {
- core.relocateCanvas(name, toX, toY);
- core.setOpacity(toOpacity);
- if (callback) callback();
- return;
- }
+ if (!time) {
+ core.relocateCanvas(name, toX, toY);
+ core.setOpacity(toOpacity);
+ if (callback) callback();
+ return;
+ }
- this._moveImage_moving(name, {
- fromX: fromX, fromY: fromY, toX: toX, toY: toY, opacity: opacity, toOpacity: toOpacity,
- moveMode: moveMode, time: time / Math.max(core.status.replay.speed, 1)
- }, callback)
-}
+ this._moveImage_moving(
+ name,
+ {
+ fromX: fromX,
+ fromY: fromY,
+ toX: toX,
+ toY: toY,
+ opacity: opacity,
+ toOpacity: toOpacity,
+ moveMode: moveMode,
+ time: time / Math.max(core.status.replay.speed, 1),
+ },
+ callback
+ );
+};
events.prototype._moveImage_moving = function (name, moveInfo, callback) {
- var per_time = 10, step = 0, steps = parseInt(moveInfo.time / per_time);
- if (steps <= 0) steps = 1;
- var fromX = moveInfo.fromX, fromY = moveInfo.fromY, toX = moveInfo.toX, toY = moveInfo.toY,
- opacity = moveInfo.opacity, toOpacity = moveInfo.toOpacity;
- var currX = fromX, currY = fromY, currOpacity = opacity;
- var moveFunc = core.applyEasing(moveInfo.moveMode);
- var animate = setInterval(function () {
- step++;
- currOpacity = opacity + (toOpacity - opacity) * moveFunc(step / steps);
- currX = parseInt(fromX + (toX - fromX) * moveFunc(step / steps));
- currY = parseInt(fromY + (toY - fromY) * moveFunc(step / steps));
- core.setOpacity(name, currOpacity);
- core.relocateCanvas(name, currX, currY);
- if (step == steps) {
- delete core.animateFrame.asyncId[animate];
- clearInterval(animate);
- if (callback) callback();
- }
- }, per_time);
+ var per_time = 10,
+ step = 0,
+ steps = parseInt(moveInfo.time / per_time);
+ if (steps <= 0) steps = 1;
+ var fromX = moveInfo.fromX,
+ fromY = moveInfo.fromY,
+ toX = moveInfo.toX,
+ toY = moveInfo.toY,
+ opacity = moveInfo.opacity,
+ toOpacity = moveInfo.toOpacity;
+ var currX = fromX,
+ currY = fromY,
+ currOpacity = opacity;
+ var moveFunc = core.applyEasing(moveInfo.moveMode);
+ var animate = setInterval(function () {
+ step++;
+ currOpacity = opacity + (toOpacity - opacity) * moveFunc(step / steps);
+ currX = parseInt(fromX + (toX - fromX) * moveFunc(step / steps));
+ currY = parseInt(fromY + (toY - fromY) * moveFunc(step / steps));
+ core.setOpacity(name, currOpacity);
+ core.relocateCanvas(name, currX, currY);
+ if (step == steps) {
+ delete core.animateFrame.asyncId[animate];
+ clearInterval(animate);
+ if (callback) callback();
+ }
+ }, per_time);
- core.animateFrame.lastAsyncId = animate;
- core.animateFrame.asyncId[animate] = callback;
-}
+ core.animateFrame.lastAsyncId = animate;
+ core.animateFrame.asyncId[animate] = callback;
+};
////// 旋转图片 //////
-events.prototype.rotateImage = function (code, center, angle, moveMode, time, callback) {
- center = center || [];
- var name = "image" + (code + 100);
- if (!core.dymCanvas[name]) {
- if (callback) callback();
- return;
- }
- var canvas = core.dymCanvas[name].canvas;
- var centerX = core.calValue(center[0]), centerY = core.calValue(center[1]);
+events.prototype.rotateImage = function (
+ code,
+ center,
+ angle,
+ moveMode,
+ time,
+ callback
+) {
+ center = center || [];
+ var name = "image" + (code + 100);
+ if (!core.dymCanvas[name]) {
+ if (callback) callback();
+ return;
+ }
+ var canvas = core.dymCanvas[name].canvas;
+ var centerX = core.calValue(center[0]),
+ centerY = core.calValue(center[1]);
- var fromAngle = parseFloat(canvas.getAttribute('_angle')) || 0;
+ var fromAngle = parseFloat(canvas.getAttribute("_angle")) || 0;
- if (!time) {
- core.rotateCanvas(name, fromAngle + angle, centerX, centerY);
- if (callback) callback();
- return;
- }
+ if (!time) {
+ core.rotateCanvas(name, fromAngle + angle, centerX, centerY);
+ if (callback) callback();
+ return;
+ }
- var rotateInfo = {
- fromAngle: fromAngle, angle: angle, centerX: centerX, centerY: centerY,
- moveMode: moveMode, time: time / Math.max(core.status.replay.speed, 1)
- }
- this._rotateImage_rotating(name, rotateInfo, callback);
-}
+ var rotateInfo = {
+ fromAngle: fromAngle,
+ angle: angle,
+ centerX: centerX,
+ centerY: centerY,
+ moveMode: moveMode,
+ time: time / Math.max(core.status.replay.speed, 1),
+ };
+ this._rotateImage_rotating(name, rotateInfo, callback);
+};
events.prototype._rotateImage_rotating = function (name, rotateInfo, callback) {
- var per_time = 10, step = 0, steps = parseInt(rotateInfo.time / per_time);
- if (steps <= 0) steps = 1;
- var moveFunc = core.applyEasing(rotateInfo.moveMode);
- var animate = setInterval(function () {
- step++;
- var currAngle = rotateInfo.fromAngle + rotateInfo.angle * moveFunc(step / steps);
- core.rotateCanvas(name, currAngle, rotateInfo.centerX, rotateInfo.centerY);
- if (step == steps) {
- delete core.animateFrame.asyncId[animate];
- clearInterval(animate);
- if (callback) callback();
- }
- }, per_time);
+ var per_time = 10,
+ step = 0,
+ steps = parseInt(rotateInfo.time / per_time);
+ if (steps <= 0) steps = 1;
+ var moveFunc = core.applyEasing(rotateInfo.moveMode);
+ var animate = setInterval(function () {
+ step++;
+ var currAngle =
+ rotateInfo.fromAngle + rotateInfo.angle * moveFunc(step / steps);
+ core.rotateCanvas(name, currAngle, rotateInfo.centerX, rotateInfo.centerY);
+ if (step == steps) {
+ delete core.animateFrame.asyncId[animate];
+ clearInterval(animate);
+ if (callback) callback();
+ }
+ }, per_time);
- core.animateFrame.lastAsyncId = animate;
- core.animateFrame.asyncId[animate] = callback;
-}
+ core.animateFrame.lastAsyncId = animate;
+ core.animateFrame.asyncId[animate] = callback;
+};
////// 放缩一张图片 //////
-events.prototype.scaleImage = function (code, center, scale, moveMode, time, callback) {
- center = center || [];
- var name = "image" + (code + 100);
- if (!core.dymCanvas[name]) {
- if (callback) callback();
- return;
- }
- var ctx = core.dymCanvas[name];
- var currScale = 1.0;
- if (ctx.canvas.hasAttribute('_scale')) {
- currScale = parseFloat(ctx.canvas.getAttribute('_scale'));
- }
- var ratio = ctx.canvas.hasAttribute('isHD') ? core.domStyle.ratio : 1;
- var width = ctx.canvas.width / ratio, height = ctx.canvas.height / ratio;
- var currLeft = parseFloat(ctx.canvas.getAttribute("_left"));
- var currTop = parseFloat(ctx.canvas.getAttribute("_top"));
- var centerX = core.calValue(center[0]), centerY = core.calValue(center[1]);
- if (centerX == null || centerY == null) {
- centerX = currLeft + width * currScale / 2;
- centerY = currTop + height * currScale / 2;
- }
- var scaleInfo = {
- x: (currLeft - centerX) / currScale, y: (currTop - centerY) / currScale, centerX: centerX, centerY: centerY,
- width: width, height: height, currScale: currScale, scale: scale, moveMode: moveMode, time: time
- }
- this._scaleImage_scale(ctx, scaleInfo, callback);
-}
+events.prototype.scaleImage = function (
+ code,
+ center,
+ scale,
+ moveMode,
+ time,
+ callback
+) {
+ center = center || [];
+ var name = "image" + (code + 100);
+ if (!core.dymCanvas[name]) {
+ if (callback) callback();
+ return;
+ }
+ var ctx = core.dymCanvas[name];
+ var currScale = 1.0;
+ if (ctx.canvas.hasAttribute("_scale")) {
+ currScale = parseFloat(ctx.canvas.getAttribute("_scale"));
+ }
+ var ratio = ctx.canvas.hasAttribute("isHD") ? core.domStyle.ratio : 1;
+ var width = ctx.canvas.width / ratio,
+ height = ctx.canvas.height / ratio;
+ var currLeft = parseFloat(ctx.canvas.getAttribute("_left"));
+ var currTop = parseFloat(ctx.canvas.getAttribute("_top"));
+ var centerX = core.calValue(center[0]),
+ centerY = core.calValue(center[1]);
+ if (centerX == null || centerY == null) {
+ centerX = currLeft + (width * currScale) / 2;
+ centerY = currTop + (height * currScale) / 2;
+ }
+ var scaleInfo = {
+ x: (currLeft - centerX) / currScale,
+ y: (currTop - centerY) / currScale,
+ centerX: centerX,
+ centerY: centerY,
+ width: width,
+ height: height,
+ currScale: currScale,
+ scale: scale,
+ moveMode: moveMode,
+ time: time,
+ };
+ this._scaleImage_scale(ctx, scaleInfo, callback);
+};
events.prototype._scaleInfo_scale = function (ctx, scaleInfo, scale) {
- core.resizeCanvas(ctx, scaleInfo.width * scale, scaleInfo.height * scale, true);
- core.relocateCanvas(ctx, scaleInfo.centerX + scaleInfo.x * scale, scaleInfo.centerY + scaleInfo.y * scale);
- ctx.canvas.setAttribute('_scale', scale);
-}
+ core.resizeCanvas(
+ ctx,
+ scaleInfo.width * scale,
+ scaleInfo.height * scale,
+ true
+ );
+ core.relocateCanvas(
+ ctx,
+ scaleInfo.centerX + scaleInfo.x * scale,
+ scaleInfo.centerY + scaleInfo.y * scale
+ );
+ ctx.canvas.setAttribute("_scale", scale);
+};
events.prototype._scaleImage_scale = function (ctx, scaleInfo, callback) {
- if (!scaleInfo.time) {
- this._scaleInfo_scale(ctx, scaleInfo, scaleInfo.scale);
- if (callback) callback();
- return;
+ if (!scaleInfo.time) {
+ this._scaleInfo_scale(ctx, scaleInfo, scaleInfo.scale);
+ if (callback) callback();
+ return;
+ }
+
+ var per_time = 10,
+ step = 0,
+ steps = parseInt(scaleInfo.time / per_time);
+ if (steps <= 0) steps = 1;
+ var moveFunc = core.applyEasing(scaleInfo.moveMode);
+
+ var animate = setInterval(function () {
+ step++;
+ var scale =
+ scaleInfo.currScale +
+ (scaleInfo.scale - scaleInfo.currScale) * moveFunc(step / steps);
+ core.events._scaleInfo_scale(ctx, scaleInfo, scale);
+ if (step == steps) {
+ delete core.animateFrame.asyncId[animate];
+ clearInterval(animate);
+ if (callback) callback();
}
+ }, per_time);
- var per_time = 10, step = 0, steps = parseInt(scaleInfo.time / per_time);
- if (steps <= 0) steps = 1;
- var moveFunc = core.applyEasing(scaleInfo.moveMode);
-
- var animate = setInterval(function () {
- step++;
- var scale = scaleInfo.currScale + (scaleInfo.scale - scaleInfo.currScale) * moveFunc(step / steps);
- core.events._scaleInfo_scale(ctx, scaleInfo, scale);
- if (step == steps) {
- delete core.animateFrame.asyncId[animate];
- clearInterval(animate);
- if (callback) callback();
- }
- }, per_time);
-
- core.animateFrame.lastAsyncId = animate;
- core.animateFrame.asyncId[animate] = callback;
-}
+ core.animateFrame.lastAsyncId = animate;
+ core.animateFrame.asyncId[animate] = callback;
+};
////// 绘制或取消一张gif图片 //////
events.prototype.showGif = function (name, x, y) {
- name = core.getMappedName(name);
- var image = core.material.images.images[name];
- if (image) {
- var gif = new Image();
- gif.src = image.src;
- gif.style.position = 'absolute';
- gif.style.left = x * core.domStyle.scale + "px";
- gif.style.top = y * core.domStyle.scale + "px";
- gif.style.width = image.width * core.domStyle.scale + "px";
- gif.style.height = image.height * core.domStyle.scale + "px";
- core.dom.gif2.appendChild(gif);
- }
- else {
- core.dom.gif2.innerHTML = "";
- }
-}
+ name = core.getMappedName(name);
+ var image = core.material.images.images[name];
+ if (image) {
+ var gif = new Image();
+ gif.src = image.src;
+ gif.style.position = "absolute";
+ gif.style.left = x * core.domStyle.scale + "px";
+ gif.style.top = y * core.domStyle.scale + "px";
+ gif.style.width = image.width * core.domStyle.scale + "px";
+ gif.style.height = image.height * core.domStyle.scale + "px";
+ core.dom.gif2.appendChild(gif);
+ } else {
+ core.dom.gif2.innerHTML = "";
+ }
+};
////// 淡入淡出音乐 //////
events.prototype.setVolume = function (value, time, callback) {
- var set = function (value) {
- core.musicStatus.designVolume = value;
- if (core.musicStatus.playingBgm)
- core.material.bgms[core.musicStatus.playingBgm].volume = core.musicStatus.userVolume * core.musicStatus.designVolume;
+ var set = function (value) {
+ core.musicStatus.designVolume = value;
+ if (core.musicStatus.playingBgm)
+ core.material.bgms[core.musicStatus.playingBgm].volume =
+ core.musicStatus.userVolume * core.musicStatus.designVolume;
+ };
+ if (!time || time < 100) {
+ set(value);
+ if (callback) callback();
+ return;
+ }
+ var currVolume = core.musicStatus.designVolume;
+ time /= Math.max(core.status.replay.speed, 1);
+ var per_time = 10,
+ step = 0,
+ steps = parseInt(time / per_time);
+ if (steps <= 0) steps = 1;
+ var animate = setInterval(function () {
+ step++;
+ set(currVolume + ((value - currVolume) * step) / steps);
+ if (step >= steps) {
+ delete core.animateFrame.asyncId[animate];
+ clearInterval(animate);
+ if (callback) callback();
}
- if (!time || time < 100) {
- set(value);
- if (callback) callback();
- return;
- }
- var currVolume = core.musicStatus.designVolume;
- time /= Math.max(core.status.replay.speed, 1);
- var per_time = 10, step = 0, steps = parseInt(time / per_time);
- if (steps <= 0) steps = 1;
- var animate = setInterval(function () {
- step++;
- set(currVolume + (value - currVolume) * step / steps);
- if (step >= steps) {
- delete core.animateFrame.asyncId[animate];
- clearInterval(animate);
- if (callback) callback();
- }
- }, per_time);
+ }, per_time);
- core.animateFrame.lastAsyncId = animate;
- core.animateFrame.asyncId[animate] = callback;
-}
+ core.animateFrame.lastAsyncId = animate;
+ core.animateFrame.asyncId[animate] = callback;
+};
////// 画面震动 //////
events.prototype.vibrate = function (direction, time, speed, power, callback) {
- if (core.isReplaying()) {
- if (callback) callback();
- return;
+ if (core.isReplaying()) {
+ if (callback) callback();
+ return;
+ }
+ if (!time) time = 1000;
+ speed = speed || 10;
+ power = power || 10;
+ var shakeInfo = {
+ duration: parseInt(time / 10),
+ speed: speed,
+ power: power,
+ direction: 1,
+ shake: 0,
+ };
+ if (direction == "random") {
+ direction = ["horizontal", "vertical", "diagonal1", "diagonal2"][
+ Math.floor(Math.random() * 4)
+ ];
+ }
+ var cb = function () {
+ core.addGameCanvasTranslate(0, 0);
+ if (callback) callback();
+ };
+ var animate = setInterval(function () {
+ core.events._vibrate_update(shakeInfo);
+ switch (direction) {
+ case "vertical":
+ core.addGameCanvasTranslate(0, shakeInfo.shake);
+ break;
+ case "diagonal1":
+ core.addGameCanvasTranslate(shakeInfo.shake, shakeInfo.shake);
+ break;
+ case "diagonal2":
+ core.addGameCanvasTranslate(-shakeInfo.shake, shakeInfo.shake);
+ break;
+ default:
+ core.addGameCanvasTranslate(shakeInfo.shake, 0);
}
- if (!time) time = 1000;
- speed = speed || 10;
- power = power || 10;
- var shakeInfo = { duration: parseInt(time / 10), speed: speed, power: power, direction: 1, shake: 0 };
- if (direction == 'random') {
- direction = ['horizontal', 'vertical', 'diagonal1', 'diagonal2'][Math.floor(Math.random() * 4)];
+ if (shakeInfo.duration === 0 && shakeInfo.shake == 0) {
+ delete core.animateFrame.asyncId[animate];
+ clearInterval(animate);
+ cb();
}
- var cb = function () {
- core.addGameCanvasTranslate(0, 0);
- if (callback) callback();
- }
- var animate = setInterval(function () {
- core.events._vibrate_update(shakeInfo);
- switch (direction) {
- case 'vertical': core.addGameCanvasTranslate(0, shakeInfo.shake); break;
- case 'diagonal1': core.addGameCanvasTranslate(shakeInfo.shake, shakeInfo.shake); break;
- case 'diagonal2': core.addGameCanvasTranslate(-shakeInfo.shake, shakeInfo.shake); break;
- default: core.addGameCanvasTranslate(shakeInfo.shake, 0);
- }
- if (shakeInfo.duration === 0 && shakeInfo.shake == 0) {
- delete core.animateFrame.asyncId[animate];
- clearInterval(animate);
- cb();
- }
- }, 10);
+ }, 10);
- core.animateFrame.lastAsyncId = animate;
- core.animateFrame.asyncId[animate] = cb;
-}
+ core.animateFrame.lastAsyncId = animate;
+ core.animateFrame.asyncId[animate] = cb;
+};
events.prototype._vibrate_update = function (shakeInfo) {
- if (shakeInfo.duration >= 1 || shakeInfo.shake != 0) {
- var delta = shakeInfo.speed * shakeInfo.direction / 6;
- if (shakeInfo.duration <= 1 && shakeInfo.shake * (shakeInfo.shake + delta) < 0) {
- shakeInfo.shake = 0;
- } else {
- shakeInfo.shake += delta;
- }
- if (shakeInfo.shake > shakeInfo.power) {
- shakeInfo.direction = -1;
- }
- if (shakeInfo.shake < -shakeInfo.power) {
- shakeInfo.direction = 1;
- }
- if (shakeInfo.duration >= 1) {
- shakeInfo.duration -= 1
- }
+ if (shakeInfo.duration >= 1 || shakeInfo.shake != 0) {
+ var delta = (shakeInfo.speed * shakeInfo.direction) / 6;
+ if (
+ shakeInfo.duration <= 1 &&
+ shakeInfo.shake * (shakeInfo.shake + delta) < 0
+ ) {
+ shakeInfo.shake = 0;
+ } else {
+ shakeInfo.shake += delta;
}
-}
+ if (shakeInfo.shake > shakeInfo.power) {
+ shakeInfo.direction = -1;
+ }
+ if (shakeInfo.shake < -shakeInfo.power) {
+ shakeInfo.direction = 1;
+ }
+ if (shakeInfo.duration >= 1) {
+ shakeInfo.duration -= 1;
+ }
+ }
+};
/////// 使用事件让勇士移动。这个函数将不会触发任何事件 //////
events.prototype.eventMoveHero = function (steps, time, callback) {
- time = time || core.values.moveSpeed;
- var step = 0, moveSteps = (steps || []).map(function (t) {
- return [t.split(':')[0], parseInt(t.split(':')[1] || "1")];
- }).filter(function (t) {
- return ['up', 'down', 'left', 'right', 'forward', 'backward', 'leftup', 'leftdown', 'rightup', 'rightdown', 'speed'].indexOf(t[0]) >= 0
- && !(t[0] == 'speed' && t[1] < 16);
- });
- core.status.heroMoving = -1;
- var _run = function () {
- var cb = function () {
- core.status.heroMoving = 0;
- core.drawHero();
- if (callback) callback();
- }
-
- var animate = window.setInterval(function () {
- if (moveSteps.length == 0) {
- delete core.animateFrame.asyncId[animate];
- clearInterval(animate);
- cb();
- }
- else {
- if (step == 0 && moveSteps[0][0] == 'speed' && moveSteps[0][1] >= 16) {
- time = moveSteps[0][1];
- moveSteps.shift();
- clearInterval(animate);
- delete core.animateFrame.asyncId[animate];
- _run();
- }
- else if (core.events._eventMoveHero_moving(++step, moveSteps))
- step = 0;
- }
- }, core.status.replay.speed == 24 ? 1 : time / 8 / core.status.replay.speed);
-
- core.animateFrame.lastAsyncId = animate;
- core.animateFrame.asyncId[animate] = cb;
- }
- _run();
-}
-
-events.prototype._eventMoveHero_moving = function (step, moveSteps) {
- var curr = moveSteps[0];
- var direction = curr[0], x = core.getHeroLoc('x'), y = core.getHeroLoc('y');
- // ------ 前进/后退
- var o = direction == 'backward' ? -1 : 1;
- if (direction == 'forward' || direction == 'backward') direction = core.getHeroLoc('direction');
- var faceDirection = direction;
- if (direction == 'leftup' || direction == 'leftdown') faceDirection = 'left';
- if (direction == 'rightup' || direction == 'rightdown') faceDirection = 'right';
- core.setHeroLoc('direction', direction);
- if (curr[1] <= 0) {
- core.setHeroLoc('direction', faceDirection);
- moveSteps.shift();
- return true;
- }
- if (step <= 4) {
- core.drawHero('leftFoot', 4 * o * step);
- }
- else if (step <= 8) {
- core.drawHero('rightFoot', 4 * o * step);
- }
- if (step == 8) {
- core.setHeroLoc('x', x + o * core.utils.scan2[direction].x, true);
- core.setHeroLoc('y', y + o * core.utils.scan2[direction].y, true);
- core.updateFollowers();
- curr[1]--;
- if (curr[1] <= 0) moveSteps.shift();
- core.setHeroLoc('direction', faceDirection);
- return true;
- }
- return false;
-}
-
-////// 勇士跳跃事件 //////
-events.prototype.jumpHero = function (ex, ey, time, callback) {
- var sx = core.getHeroLoc('x'), sy = core.getHeroLoc('y');
- if (ex == null) ex = sx;
- if (ey == null) ey = sy;
- var sx = core.status.hero.loc.x, sy = core.status.hero.loc.y;
- if (!core.isset(ex)) ex = sx;
- if (!core.isset(ey)) ey = sy;
- var jumpInfo = core.maps.__generateJumpInfo(sx, sy, ex, ey, time || 500);
- jumpInfo.icon = core.material.icons.hero[core.getHeroLoc('direction')];
- jumpInfo.width = core.material.icons.hero.width || 32;
- jumpInfo.height = core.material.icons.hero.height;
-
- this._jumpHero_doJump(jumpInfo, callback);
-}
-
-events.prototype._jumpHero_doJump = function (jumpInfo, callback) {
+ time = time || core.values.moveSpeed;
+ var step = 0,
+ moveSteps = (steps || [])
+ .map(function (t) {
+ return [t.split(":")[0], parseInt(t.split(":")[1] || "1")];
+ })
+ .filter(function (t) {
+ return (
+ [
+ "up",
+ "down",
+ "left",
+ "right",
+ "forward",
+ "backward",
+ "leftup",
+ "leftdown",
+ "rightup",
+ "rightdown",
+ "speed",
+ ].indexOf(t[0]) >= 0 && !(t[0] == "speed" && t[1] < 16)
+ );
+ });
+ core.status.heroMoving = -1;
+ var _run = function () {
var cb = function () {
- core.setHeroLoc('x', jumpInfo.ex);
- core.setHeroLoc('y', jumpInfo.ey);
- core.status.heroMoving = 0;
- core.drawHero();
- if (callback) callback();
- }
+ core.status.heroMoving = 0;
+ core.drawHero();
+ if (callback) callback();
+ };
- core.status.heroMoving = -1;
- var animate = window.setInterval(function () {
- if (jumpInfo.jump_count > 0)
- core.events._jumpHero_jumping(jumpInfo)
- else {
- delete core.animateFrame.asyncId[animate];
+ var animate = window.setInterval(
+ function () {
+ if (moveSteps.length == 0) {
+ delete core.animateFrame.asyncId[animate];
+ clearInterval(animate);
+ cb();
+ } else {
+ if (
+ step == 0 &&
+ moveSteps[0][0] == "speed" &&
+ moveSteps[0][1] >= 16
+ ) {
+ time = moveSteps[0][1];
+ moveSteps.shift();
clearInterval(animate);
- cb();
+ delete core.animateFrame.asyncId[animate];
+ _run();
+ } else if (core.events._eventMoveHero_moving(++step, moveSteps))
+ step = 0;
}
- }, jumpInfo.per_time);
+ },
+ core.status.replay.speed == 24 ? 1 : time / 8 / core.status.replay.speed
+ );
core.animateFrame.lastAsyncId = animate;
core.animateFrame.asyncId[animate] = cb;
-}
+ };
+ _run();
+};
+
+events.prototype._eventMoveHero_moving = function (step, moveSteps) {
+ var curr = moveSteps[0];
+ var direction = curr[0],
+ x = core.getHeroLoc("x"),
+ y = core.getHeroLoc("y");
+ // ------ 前进/后退
+ var o = direction == "backward" ? -1 : 1;
+ if (direction == "forward" || direction == "backward")
+ direction = core.getHeroLoc("direction");
+ var faceDirection = direction;
+ if (direction == "leftup" || direction == "leftdown") faceDirection = "left";
+ if (direction == "rightup" || direction == "rightdown")
+ faceDirection = "right";
+ core.setHeroLoc("direction", direction);
+ if (curr[1] <= 0) {
+ core.setHeroLoc("direction", faceDirection);
+ moveSteps.shift();
+ return true;
+ }
+ if (step <= 4) {
+ core.drawHero("leftFoot", 4 * o * step);
+ } else if (step <= 8) {
+ core.drawHero("rightFoot", 4 * o * step);
+ }
+ if (step == 8) {
+ core.setHeroLoc("x", x + o * core.utils.scan2[direction].x, true);
+ core.setHeroLoc("y", y + o * core.utils.scan2[direction].y, true);
+ core.updateFollowers();
+ curr[1]--;
+ if (curr[1] <= 0) moveSteps.shift();
+ core.setHeroLoc("direction", faceDirection);
+ return true;
+ }
+ return false;
+};
+
+////// 勇士跳跃事件 //////
+events.prototype.jumpHero = function (ex, ey, time, callback) {
+ var sx = core.getHeroLoc("x"),
+ sy = core.getHeroLoc("y");
+ if (ex == null) ex = sx;
+ if (ey == null) ey = sy;
+ var sx = core.status.hero.loc.x,
+ sy = core.status.hero.loc.y;
+ if (!core.isset(ex)) ex = sx;
+ if (!core.isset(ey)) ey = sy;
+ var jumpInfo = core.maps.__generateJumpInfo(sx, sy, ex, ey, time || 500);
+ jumpInfo.icon = core.material.icons.hero[core.getHeroLoc("direction")];
+ jumpInfo.width = core.material.icons.hero.width || 32;
+ jumpInfo.height = core.material.icons.hero.height;
+
+ this._jumpHero_doJump(jumpInfo, callback);
+};
+
+events.prototype._jumpHero_doJump = function (jumpInfo, callback) {
+ var cb = function () {
+ core.setHeroLoc("x", jumpInfo.ex);
+ core.setHeroLoc("y", jumpInfo.ey);
+ core.status.heroMoving = 0;
+ core.drawHero();
+ if (callback) callback();
+ };
+
+ core.status.heroMoving = -1;
+ var animate = window.setInterval(function () {
+ if (jumpInfo.jump_count > 0) core.events._jumpHero_jumping(jumpInfo);
+ else {
+ delete core.animateFrame.asyncId[animate];
+ clearInterval(animate);
+ cb();
+ }
+ }, jumpInfo.per_time);
+
+ core.animateFrame.lastAsyncId = animate;
+ core.animateFrame.asyncId[animate] = cb;
+};
events.prototype._jumpHero_jumping = function (jumpInfo) {
- core.clearMap('hero');
- core.maps.__updateJumpInfo(jumpInfo);
- var x = core.getHeroLoc('x'),
- y = core.getHeroLoc('y');
- var nowx = jumpInfo.px, nowy = jumpInfo.py, width = jumpInfo.width || 32, height = jumpInfo.height;
- core.drawHero('stop', { x: nowx - 32 * x, y: nowy - 32 * y });
-}
+ core.clearMap("hero");
+ core.maps.__updateJumpInfo(jumpInfo);
+ var x = core.getHeroLoc("x"),
+ y = core.getHeroLoc("y");
+ var nowx = jumpInfo.px,
+ nowy = jumpInfo.py,
+ width = jumpInfo.width || 32,
+ height = jumpInfo.height;
+ core.drawHero("stop", { x: nowx - 32 * x, y: nowy - 32 * y });
+};
////// 设置角色行走图 //////
events.prototype.setHeroIcon = function (name, noDraw) {
- name = core.getMappedName(name);
- var img = core.material.images.images[name];
- if (!img) {
- console.error("找不到图片: " + img);
- return;
- }
- if (core.material.images.hero == img) return;
- core.status.hero.image = name;
- core.material.images.hero = img;
- core.material.icons.hero.width = img.width / 4;
- core.material.icons.hero.height = img.height / 4;
- core.control.updateHeroIcon(name);
- if (!noDraw) core.drawHero();
-}
+ name = core.getMappedName(name);
+ var img = core.material.images.images[name];
+ if (!img) {
+ console.error("找不到图片: " + img);
+ return;
+ }
+ if (core.material.images.hero == img) return;
+ core.status.hero.image = name;
+ core.material.images.hero = img;
+ core.material.icons.hero.width = img.width / 4;
+ core.material.icons.hero.height = img.height / 4;
+ core.control.updateHeroIcon(name);
+ if (!noDraw) core.drawHero();
+};
////// 检查升级事件 //////
events.prototype.checkLvUp = function () {
- var actions = [];
- while (true) {
- var next = this._checkLvUp_check();
- if (next == null) break;
- actions = actions.concat(next);
- }
- if (actions.length > 0) core.insertAction(actions);
-}
+ var actions = [];
+ while (true) {
+ var next = this._checkLvUp_check();
+ if (next == null) break;
+ actions = actions.concat(next);
+ }
+ if (actions.length > 0) core.insertAction(actions);
+};
events.prototype._checkLvUp_check = function () {
- if (core.flags.statusBarItems.indexOf('enableLevelUp') < 0 || !core.firstData.levelUp
- || core.status.hero.lv >= core.firstData.levelUp.length) return null;
- // 计算下一个所需要的数值
- var next = (core.firstData.levelUp[core.status.hero.lv] || {});
- var need = core.calValue(next.need);
- if (need == null) return null;
- if (core.status.hero.exp >= need) {
- // 升级
- core.status.hero.lv++;
- if (next.clear) core.status.hero.exp -= need;
- return next.action || [];
- }
+ if (
+ core.flags.statusBarItems.indexOf("enableLevelUp") < 0 ||
+ !core.firstData.levelUp ||
+ core.status.hero.lv >= core.firstData.levelUp.length
+ )
return null;
-}
+ // 计算下一个所需要的数值
+ var next = core.firstData.levelUp[core.status.hero.lv] || {};
+ var need = core.calValue(next.need);
+ if (need == null) return null;
+ if (core.status.hero.exp >= need) {
+ // 升级
+ core.status.hero.lv++;
+ if (next.clear) core.status.hero.exp -= need;
+ return next.action || [];
+ }
+ return null;
+};
////// 尝试使用道具 //////
events.prototype.tryUseItem = function (itemId) {
- if (itemId == 'book') {
- core.ui.closePanel();
- return core.openBook(false);
- }
- if (itemId == 'fly') {
- core.ui.closePanel();
- return core.useFly(false);
- }
- if (itemId == 'centerFly') {
- core.ui.closePanel();
- return core.ui._drawCenterFly();
- }
- if (core.canUseItem(itemId)) {
- core.ui.closePanel();
- core.useItem(itemId);
- } else {
- core.playSound('操作失败');
- core.drawTip("当前无法使用" + core.material.items[itemId].name, itemId);
- }
-}
+ if (itemId == "book") {
+ core.ui.closePanel();
+ return core.openBook(false);
+ }
+ if (itemId == "fly") {
+ core.ui.closePanel();
+ return core.useFly(false);
+ }
+ if (itemId == "centerFly") {
+ core.ui.closePanel();
+ return core.ui._drawCenterFly();
+ }
+ if (core.canUseItem(itemId)) {
+ core.ui.closePanel();
+ core.useItem(itemId);
+ } else {
+ core.playSound("操作失败");
+ core.drawTip("当前无法使用" + core.material.items[itemId].name, itemId);
+ }
+};
diff --git a/libs/loader.js b/libs/loader.js
index e00620d..b81aba2 100644
--- a/libs/loader.js
+++ b/libs/loader.js
@@ -1,606 +1,818 @@
-
/*
loader.js:负责对资源的加载
*/
"use strict";
-function loader () {
- this._init();
+function loader() {
+ this._init();
}
-loader.prototype._init = function () {
-
-}
+loader.prototype._init = function () {};
////// 设置加载进度条进度 //////
loader.prototype._setStartProgressVal = function (val) {
- core.dom.startTopProgress.style.width = val + '%';
-}
+ core.dom.startTopProgress.style.width = val + "%";
+};
////// 设置加载进度条提示文字 //////
loader.prototype._setStartLoadTipText = function (text) {
- core.dom.startTopLoadTips.innerText = text;
-}
+ core.dom.startTopLoadTips.innerText = text;
+};
loader.prototype._load = function (callback) {
- this._loadMusics();
- if (main.useCompress) {
- this._load_async(callback);
- } else {
- this._load_sync(callback);
- }
-}
+ this._loadMusics();
+ if (main.useCompress) {
+ this._load_async(callback);
+ } else {
+ this._load_sync(callback);
+ }
+};
loader.prototype._load_sync = function (callback) {
- this._loadAnimates_sync();
- this._loadSounds_sync();
- core.loader._loadMaterials_sync(function () {
- core.loader._loadExtraImages_sync(function () {
- core.loader._loadAutotiles_sync(function () {
- core.loader._loadTilesets_sync(callback);
- })
- })
+ this._loadAnimates_sync();
+ this._loadSounds_sync();
+ core.loader._loadMaterials_sync(function () {
+ core.loader._loadExtraImages_sync(function () {
+ core.loader._loadAutotiles_sync(function () {
+ core.loader._loadTilesets_sync(callback);
+ });
});
-}
+ });
+};
loader.prototype._load_async = function (callback) {
- core.loader._setStartLoadTipText('正在加载资源文件...');
- const all = {};
+ core.loader._setStartLoadTipText("正在加载资源文件...");
+ const all = {};
- const _makeOnProgress = function (name) {
- if (!all[name]) all[name] = { loaded: 0, total: 0, finished: false };
- return (loaded, total) => {
- all[name].loaded = loaded;
- all[name].total = total;
- let allLoaded = 0, allTotal = 0;
- for (const one of Object.values(all)) {
- allLoaded += one.loaded;
- allTotal += one.total;
- }
- console.log(allLoaded. allTotal);
- if (allTotal > 0) {
- if (allLoaded == allTotal) {
- core.loader._setStartLoadTipText("正在处理资源文件... 请稍候...");
- } else {
- core.loader._setStartLoadTipText('正在加载资源文件... ' +
- core.formatSize(allLoaded) + " / " + core.formatSize(allTotal) +
- " (" + (allLoaded / allTotal * 100).toFixed(2) + "%)");
- }
- core.loader._setStartProgressVal(allLoaded / allTotal * 100);
- }
- };
- }
- const _makeOnFinished = function (name) {
- return () => {
- setTimeout(() => {
- all[name].finished = true;
- for (var one in all) {
- if (!all[one].finished) return;
- }
- callback();
- });
+ const _makeOnProgress = function (name) {
+ if (!all[name]) all[name] = { loaded: 0, total: 0, finished: false };
+ return (loaded, total) => {
+ all[name].loaded = loaded;
+ all[name].total = total;
+ let allLoaded = 0,
+ allTotal = 0;
+ for (const one of Object.values(all)) {
+ allLoaded += one.loaded;
+ allTotal += one.total;
+ }
+ console.log(allLoaded.allTotal);
+ if (allTotal > 0) {
+ if (allLoaded == allTotal) {
+ core.loader._setStartLoadTipText("正在处理资源文件... 请稍候...");
+ } else {
+ core.loader._setStartLoadTipText(
+ "正在加载资源文件... " +
+ core.formatSize(allLoaded) +
+ " / " +
+ core.formatSize(allTotal) +
+ " (" +
+ ((allLoaded / allTotal) * 100).toFixed(2) +
+ "%)"
+ );
}
- }
+ core.loader._setStartProgressVal((allLoaded / allTotal) * 100);
+ }
+ };
+ };
+ const _makeOnFinished = function (name) {
+ return () => {
+ setTimeout(() => {
+ all[name].finished = true;
+ for (var one in all) {
+ if (!all[one].finished) return;
+ }
+ callback();
+ });
+ };
+ };
- if (main.splitChunkMap) {
- this._loadAnimates_chunked(main.splitChunkMap.animates, _makeOnProgress, _makeOnFinished);
- this._loadSounds_chunked(main.splitChunkMap.sounds, _makeOnProgress, _makeOnFinished);
- this._loadMaterials_chunked(main.splitChunkMap.materials, _makeOnProgress, _makeOnFinished);
- this._loadExtraImages_chunked(main.splitChunkMap.images, _makeOnProgress, _makeOnFinished);
- this._loadAutotiles_chunked(main.splitChunkMap.autotiles, _makeOnProgress, _makeOnFinished);
- this._loadTilesets_chunked(main.splitChunkMap.tilesets, _makeOnProgress, _makeOnFinished);
- } else {
- this._loadAnimates_async(_makeOnProgress('animates'), _makeOnFinished('animates'));
- this._loadSounds_async(_makeOnProgress('sounds'), _makeOnFinished('sounds'));
- this._loadMaterials_async(_makeOnProgress('materials'), _makeOnFinished('materials'));
- this._loadExtraImages_async(_makeOnProgress('images'), _makeOnFinished('images'));
- this._loadAutotiles_async(_makeOnProgress('autotiles'), _makeOnFinished('autotiles'));
- this._loadTilesets_async(_makeOnProgress('tilesets'), _makeOnFinished('tilesets'));
- }
-}
+ if (main.splitChunkMap) {
+ this._loadAnimates_chunked(
+ main.splitChunkMap.animates,
+ _makeOnProgress,
+ _makeOnFinished
+ );
+ this._loadSounds_chunked(
+ main.splitChunkMap.sounds,
+ _makeOnProgress,
+ _makeOnFinished
+ );
+ this._loadMaterials_chunked(
+ main.splitChunkMap.materials,
+ _makeOnProgress,
+ _makeOnFinished
+ );
+ this._loadExtraImages_chunked(
+ main.splitChunkMap.images,
+ _makeOnProgress,
+ _makeOnFinished
+ );
+ this._loadAutotiles_chunked(
+ main.splitChunkMap.autotiles,
+ _makeOnProgress,
+ _makeOnFinished
+ );
+ this._loadTilesets_chunked(
+ main.splitChunkMap.tilesets,
+ _makeOnProgress,
+ _makeOnFinished
+ );
+ } else {
+ this._loadAnimates_async(
+ _makeOnProgress("animates"),
+ _makeOnFinished("animates")
+ );
+ this._loadSounds_async(
+ _makeOnProgress("sounds"),
+ _makeOnFinished("sounds")
+ );
+ this._loadMaterials_async(
+ _makeOnProgress("materials"),
+ _makeOnFinished("materials")
+ );
+ this._loadExtraImages_async(
+ _makeOnProgress("images"),
+ _makeOnFinished("images")
+ );
+ this._loadAutotiles_async(
+ _makeOnProgress("autotiles"),
+ _makeOnFinished("autotiles")
+ );
+ this._loadTilesets_async(
+ _makeOnProgress("tilesets"),
+ _makeOnFinished("tilesets")
+ );
+ }
+};
// ----- 加载资源文件 ------ //
loader.prototype._loadMaterials_sync = function (callback) {
- this._setStartLoadTipText("正在加载资源文件...");
- this.loadImages("materials", core.materials, core.material.images, function () {
- core.loader._loadMaterials_afterLoad();
- callback();
- });
-}
+ this._setStartLoadTipText("正在加载资源文件...");
+ this.loadImages(
+ "materials",
+ core.materials,
+ core.material.images,
+ function () {
+ core.loader._loadMaterials_afterLoad();
+ callback();
+ }
+ );
+};
loader.prototype._loadMaterials_async = function (onprogress, onfinished) {
- this.loadImagesFromZip('project/materials/materials.h5data', core.materials, core.material.images, onprogress, function () {
- core.loader._loadMaterials_afterLoad();
- onfinished();
- });
-}
+ this.loadImagesFromZip(
+ "project/materials/materials.h5data",
+ core.materials,
+ core.material.images,
+ onprogress,
+ function () {
+ core.loader._loadMaterials_afterLoad();
+ onfinished();
+ }
+ );
+};
-loader.prototype._loadMaterials_chunked = async function (chunks, makeOnProgress, makeOnFinished) {
- await this._loadImagesFromChunks(chunks, core.materials, core.material.images, makeOnProgress, makeOnFinished);
- core.loader._loadMaterials_afterLoad();
-}
+loader.prototype._loadMaterials_chunked = async function (
+ chunks,
+ makeOnProgress,
+ makeOnFinished
+) {
+ await this._loadImagesFromChunks(
+ chunks,
+ core.materials,
+ core.material.images,
+ makeOnProgress,
+ makeOnFinished
+ );
+ core.loader._loadMaterials_afterLoad();
+};
loader.prototype._loadMaterials_afterLoad = function () {
- const images = core.splitImage(core.material.images['icons']);
- for (let key in core.statusBar.icons) {
- if (typeof core.statusBar.icons[key] == 'number') {
- core.statusBar.icons[key] = images[core.statusBar.icons[key]];
- if (core.statusBar.image[key] != null)
- core.statusBar.image[key].src = core.statusBar.icons[key].src;
- }
+ const images = core.splitImage(core.material.images["icons"]);
+ for (let key in core.statusBar.icons) {
+ if (typeof core.statusBar.icons[key] == "number") {
+ core.statusBar.icons[key] = images[core.statusBar.icons[key]];
+ if (core.statusBar.image[key] != null)
+ core.statusBar.image[key].src = core.statusBar.icons[key].src;
}
-}
+ }
+};
// ------ 加载使用的图片 ------ //
loader.prototype._loadExtraImages_sync = function (callback) {
- core.material.images.images = {};
- this._setStartLoadTipText("正在加载图片文件...");
- core.loadImages("images", core.images, core.material.images.images, callback);
-}
+ core.material.images.images = {};
+ this._setStartLoadTipText("正在加载图片文件...");
+ core.loadImages("images", core.images, core.material.images.images, callback);
+};
loader.prototype._loadExtraImages_async = function (onprogress, onfinished) {
- core.material.images.images = {};
-
- // Check .gif
- const gifs = images.filter(function (name) {
- return name.toLowerCase().endsWith('.gif');
- });
- // gif没有被压缩在zip中,延迟加载...
- this._loadExtraImages_loadLazy(gifs);
+ core.material.images.images = {};
- images = images.filter((name) => !name.toLowerCase().endsWith('.gif'));
+ // Check .gif
+ const gifs = images.filter(function (name) {
+ return name.toLowerCase().endsWith(".gif");
+ });
+ // gif没有被压缩在zip中,延迟加载...
+ this._loadExtraImages_loadLazy(gifs);
- this.loadImagesFromZip('project/images/images.h5data', images, core.material.images.images, onprogress, onfinished);
-}
+ images = images.filter((name) => !name.toLowerCase().endsWith(".gif"));
-loader.prototype._loadExtraImages_chunked = function (chunks, makeOnProgress, makeOnFinished) {
- core.material.images.images = {};
- let images = core.images;
+ this.loadImagesFromZip(
+ "project/images/images.h5data",
+ images,
+ core.material.images.images,
+ onprogress,
+ onfinished
+ );
+};
- // Check .gif
- const gifs = images.filter(function (name) {
- return name.toLowerCase().endsWith('.gif');
- });
- // gif没有被压缩在zip中,延迟加载...
- this._loadExtraImages_loadLazy(gifs);
+loader.prototype._loadExtraImages_chunked = function (
+ chunks,
+ makeOnProgress,
+ makeOnFinished
+) {
+ core.material.images.images = {};
+ let images = core.images;
- images = images.filter((name) => !name.toLowerCase().endsWith('.gif'));
+ // Check .gif
+ const gifs = images.filter(function (name) {
+ return name.toLowerCase().endsWith(".gif");
+ });
+ // gif没有被压缩在zip中,延迟加载...
+ this._loadExtraImages_loadLazy(gifs);
- this._loadImagesFromChunks(chunks, images, core.material.images.images, makeOnProgress, makeOnFinished);
-}
+ images = images.filter((name) => !name.toLowerCase().endsWith(".gif"));
+
+ this._loadImagesFromChunks(
+ chunks,
+ images,
+ core.material.images.images,
+ makeOnProgress,
+ makeOnFinished
+ );
+};
loader.prototype._loadExtraImages_loadLazy = function (list) {
- list.forEach(function (gif) {
- this.loadImage("images", gif, (id, image) => {
- if (image != null) {
- core.material.images.images[gif] = image;
- }
- });
- }, this);
-}
+ list.forEach(function (gif) {
+ this.loadImage("images", gif, (id, image) => {
+ if (image != null) {
+ core.material.images.images[gif] = image;
+ }
+ });
+ }, this);
+};
// ------ 加载自动元件 ------ //
loader.prototype._loadAutotiles_sync = function (callback) {
- core.material.images.autotile = {};
- var keys = Object.keys(core.material.icons.autotile);
- var autotiles = {};
+ core.material.images.autotile = {};
+ var keys = Object.keys(core.material.icons.autotile);
+ var autotiles = {};
- this._setStartLoadTipText("正在加载自动元件...");
- this.loadImages("autotiles", keys, autotiles, function () {
- core.loader._loadAutotiles_afterLoad(keys, autotiles);
- callback();
- });
-}
+ this._setStartLoadTipText("正在加载自动元件...");
+ this.loadImages("autotiles", keys, autotiles, function () {
+ core.loader._loadAutotiles_afterLoad(keys, autotiles);
+ callback();
+ });
+};
loader.prototype._loadAutotiles_async = function (onprogress, onfinished) {
- core.material.images.autotile = {};
- var keys = Object.keys(core.material.icons.autotile);
- var autotiles = {};
+ core.material.images.autotile = {};
+ var keys = Object.keys(core.material.icons.autotile);
+ var autotiles = {};
- this.loadImagesFromZip('project/autotiles/autotiles.h5data', keys, autotiles, onprogress, function () {
- core.loader._loadAutotiles_afterLoad(keys, autotiles);
- onfinished();
- });
-}
+ this.loadImagesFromZip(
+ "project/autotiles/autotiles.h5data",
+ keys,
+ autotiles,
+ onprogress,
+ function () {
+ core.loader._loadAutotiles_afterLoad(keys, autotiles);
+ onfinished();
+ }
+ );
+};
-loader.prototype._loadAutotiles_chunked = async function (chunks, makeOnProgress, makeOnFinished) {
- core.material.images.autotile = {};
- const keys = Object.keys(core.material.icons.autotile);
- const autotiles = {};
+loader.prototype._loadAutotiles_chunked = async function (
+ chunks,
+ makeOnProgress,
+ makeOnFinished
+) {
+ core.material.images.autotile = {};
+ const keys = Object.keys(core.material.icons.autotile);
+ const autotiles = {};
- await this._loadImagesFromChunks(chunks, keys, autotiles, makeOnProgress, makeOnFinished);
- core.loader._loadAutotiles_afterLoad(keys, autotiles);
-}
+ await this._loadImagesFromChunks(
+ chunks,
+ keys,
+ autotiles,
+ makeOnProgress,
+ makeOnFinished
+ );
+ core.loader._loadAutotiles_afterLoad(keys, autotiles);
+};
loader.prototype._loadAutotiles_afterLoad = function (keys, autotiles) {
- // autotile需要保证顺序
- keys.forEach(function (v) {
- core.material.images.autotile[v] = autotiles[v];
- });
+ // autotile需要保证顺序
+ keys.forEach(function (v) {
+ core.material.images.autotile[v] = autotiles[v];
+ });
- setTimeout(function () {
- core.maps._makeAutotileEdges();
- });
-
-}
+ setTimeout(function () {
+ core.maps._makeAutotileEdges();
+ });
+};
// ------ 加载额外素材 ------ //
loader.prototype._loadTilesets_sync = function (callback) {
- core.material.images.tilesets = {};
- this._setStartLoadTipText("正在加载额外素材...");
- this.loadImages("tilesets", core.tilesets, core.material.images.tilesets, function () {
- core.loader._loadTilesets_afterLoad();
- callback();
- });
-}
+ core.material.images.tilesets = {};
+ this._setStartLoadTipText("正在加载额外素材...");
+ this.loadImages(
+ "tilesets",
+ core.tilesets,
+ core.material.images.tilesets,
+ function () {
+ core.loader._loadTilesets_afterLoad();
+ callback();
+ }
+ );
+};
loader.prototype._loadTilesets_async = function (onprogress, onfinished) {
- core.material.images.tilesets = {};
- this.loadImagesFromZip('project/tilesets/tilesets.h5data', core.tilesets, core.material.images.tilesets, onprogress, function () {
- core.loader._loadTilesets_afterLoad();
- onfinished();
- });
-}
+ core.material.images.tilesets = {};
+ this.loadImagesFromZip(
+ "project/tilesets/tilesets.h5data",
+ core.tilesets,
+ core.material.images.tilesets,
+ onprogress,
+ function () {
+ core.loader._loadTilesets_afterLoad();
+ onfinished();
+ }
+ );
+};
-loader.prototype._loadTilesets_chunked = async function (chunks, makeOnProgress, makeOnFinished) {
- core.material.images.tilesets = {};
- await this._loadImagesFromChunks(chunks, core.tilesets, core.material.images.tilesets, makeOnProgress, makeOnFinished);
- core.loader._loadTilesets_afterLoad();
-}
+loader.prototype._loadTilesets_chunked = async function (
+ chunks,
+ makeOnProgress,
+ makeOnFinished
+) {
+ core.material.images.tilesets = {};
+ await this._loadImagesFromChunks(
+ chunks,
+ core.tilesets,
+ core.material.images.tilesets,
+ makeOnProgress,
+ makeOnFinished
+ );
+ core.loader._loadTilesets_afterLoad();
+};
loader.prototype._loadTilesets_afterLoad = function () {
- // 检查宽高是32倍数,如果出错在控制台报错
- for (var imgName in core.material.images.tilesets) {
- var img = core.material.images.tilesets[imgName];
- if (img.width % 32 != 0 || img.height % 32 != 0) {
- console.warn("警告!" + imgName + "的宽或高不是32的倍数!");
- }
- if (img.width * img.height > 32 * 32 * 3000) {
- console.warn("警告!" + imgName + "上的图块素材个数大于3000!");
- }
+ // 检查宽高是32倍数,如果出错在控制台报错
+ for (var imgName in core.material.images.tilesets) {
+ var img = core.material.images.tilesets[imgName];
+ if (img.width % 32 != 0 || img.height % 32 != 0) {
+ console.warn("警告!" + imgName + "的宽或高不是32的倍数!");
}
-}
+ if (img.width * img.height > 32 * 32 * 3000) {
+ console.warn("警告!" + imgName + "上的图块素材个数大于3000!");
+ }
+ }
+};
// ------ 实际加载一系列图片 ------ //
loader.prototype.loadImages = function (dir, names, toSave, callback) {
- if (!names || names.length == 0) {
- if (callback) callback();
+ if (!names || names.length == 0) {
+ if (callback) callback();
+ return;
+ }
+ var items = 0;
+ for (var i = 0; i < names.length; i++) {
+ this.loadImage(dir, names[i], function (id, image) {
+ core.loader._setStartLoadTipText("正在加载图片 " + id + "...");
+ if (toSave[id] !== undefined) {
+ if (image != null) toSave[id] = image;
return;
- }
- var items = 0;
- for (var i = 0; i < names.length; i++) {
- this.loadImage(dir, names[i], function (id, image) {
- core.loader._setStartLoadTipText('正在加载图片 ' + id + "...");
- if (toSave[id] !== undefined) {
- if (image != null)
- toSave[id] = image;
- return;
- }
- toSave[id] = image;
- items++;
- core.loader._setStartProgressVal(items * (100 / names.length));
- if (items == names.length) {
- if (callback) callback();
- }
- })
- }
-}
+ }
+ toSave[id] = image;
+ items++;
+ core.loader._setStartProgressVal(items * (100 / names.length));
+ if (items == names.length) {
+ if (callback) callback();
+ }
+ });
+ }
+};
loader.prototype.loadImage = function (dir, imgName, callback) {
- try {
- var name = imgName;
- if (name.indexOf(".") < 0)
- name = name + ".png";
- var image = new Image();
- image.onload = function () {
- image.setAttribute('_width', image.width);
- image.setAttribute('_height', image.height);
- callback(imgName, image);
- }
- image.onerror = function () {
- callback(imgName, null);
- }
- image.src = 'project/' + dir + '/' + name + "?v=" + main.version;
- if (name.endsWith('.gif'))
- callback(imgName, null);
- }
- catch (e) {
- console.error(e);
- }
-}
+ try {
+ var name = imgName;
+ if (name.indexOf(".") < 0) name = name + ".png";
+ var image = new Image();
+ image.onload = function () {
+ image.setAttribute("_width", image.width);
+ image.setAttribute("_height", image.height);
+ callback(imgName, image);
+ };
+ image.onerror = function () {
+ callback(imgName, null);
+ };
+ image.src = "project/" + dir + "/" + name + "?v=" + main.version;
+ if (name.endsWith(".gif")) callback(imgName, null);
+ } catch (e) {
+ console.error(e);
+ }
+};
// ------ 从zip中加载一系列图片 ------ //
-loader.prototype.loadImagesFromZip = function (url, names, toSave, onprogress, onfinished) {
- if (!names || names.length == 0) {
- if (onfinished) onfinished();
- return;
- }
+loader.prototype.loadImagesFromZip = function (
+ url,
+ names,
+ toSave,
+ onprogress,
+ onfinished
+) {
+ if (!names || names.length == 0) {
+ if (onfinished) onfinished();
+ return;
+ }
- core.unzip(url + "?v=" + main.version, function (data) {
- var cnt = 1;
- names.forEach(function (name) {
- var imgName = name;
- if (imgName.indexOf('.') < 0) imgName += '.png';
- if (imgName in data) {
- var img = new Image();
- var url = URL.createObjectURL(data[imgName]);
- cnt++;
- img.onload = function () {
- cnt--;
- URL.revokeObjectURL(url);
- img.setAttribute('_width', img.width);
- img.setAttribute('_height', img.height);
- if (cnt == 0 && onfinished) onfinished();
- }
- img.src = url;
- toSave[name] = img;
- }
- });
- cnt--;
- if (cnt == 0 && onfinished) onfinished();
- }, null, false, onprogress);
-}
+ core.unzip(
+ url + "?v=" + main.version,
+ function (data) {
+ var cnt = 1;
+ names.forEach(function (name) {
+ var imgName = name;
+ if (imgName.indexOf(".") < 0) imgName += ".png";
+ if (imgName in data) {
+ var img = new Image();
+ var url = URL.createObjectURL(data[imgName]);
+ cnt++;
+ img.onload = function () {
+ cnt--;
+ URL.revokeObjectURL(url);
+ img.setAttribute("_width", img.width);
+ img.setAttribute("_height", img.height);
+ if (cnt == 0 && onfinished) onfinished();
+ };
+ img.src = url;
+ toSave[name] = img;
+ }
+ });
+ cnt--;
+ if (cnt == 0 && onfinished) onfinished();
+ },
+ null,
+ false,
+ onprogress
+ );
+};
-loader.prototype._loadImagesFromChunks = async function (chunks, names, toSave, makeOnProgress, makeOnFinished) {
- await Promise.all(chunks.map((chunk) => {
- const onfinished = makeOnFinished(chunk);
- const onprogress = makeOnProgress(chunk);
- return new Promise((resolve) => {
- this.loadImagesFromZip(chunk, names, toSave, onprogress, () => {
- onfinished();
- resolve();
- });
+loader.prototype._loadImagesFromChunks = async function (
+ chunks,
+ names,
+ toSave,
+ makeOnProgress,
+ makeOnFinished
+) {
+ await Promise.all(
+ chunks.map((chunk) => {
+ const onfinished = makeOnFinished(chunk);
+ const onprogress = makeOnProgress(chunk);
+ return new Promise((resolve) => {
+ this.loadImagesFromZip(chunk, names, toSave, onprogress, () => {
+ onfinished();
+ resolve();
});
- }));
-}
+ });
+ })
+ );
+};
// ------ 加载动画文件 ------ //
loader.prototype._loadAnimates_sync = function () {
- this._setStartLoadTipText("正在加载动画文件...");
+ this._setStartLoadTipText("正在加载动画文件...");
- if (main.supportBunch) {
- if (core.animates.length > 0) {
- core.http('GET', '__all_animates__?v=' + main.version + '&id=' + core.animates.join(','), null, function (content) {
- var u = content.split('@@@~~~###~~~@@@');
- for (var i = 0; i < core.animates.length; ++i) {
- if (u[i] != '') {
- core.material.animates[core.animates[i]] = core.loader._loadAnimate(u[i]);
- } else {
- console.error('无法找到动画文件' + core.animates[i] + '!');
- }
- }
- }, "text/plain; charset=x-user-defined");
- }
- return;
+ if (main.supportBunch) {
+ if (core.animates.length > 0) {
+ core.http(
+ "GET",
+ "__all_animates__?v=" + main.version + "&id=" + core.animates.join(","),
+ null,
+ function (content) {
+ var u = content.split("@@@~~~###~~~@@@");
+ for (var i = 0; i < core.animates.length; ++i) {
+ if (u[i] != "") {
+ core.material.animates[core.animates[i]] =
+ core.loader._loadAnimate(u[i]);
+ } else {
+ console.error("无法找到动画文件" + core.animates[i] + "!");
+ }
+ }
+ },
+ "text/plain; charset=x-user-defined"
+ );
}
+ return;
+ }
- core.animates.forEach(function (t) {
- core.http('GET', 'project/animates/' + t + ".animate?v=" + main.version, null, function (content) {
- core.material.animates[t] = core.loader._loadAnimate(content);
- }, function (e) {
- console.error(e);
- core.material.animates[t] = null;
- }, "text/plain; charset=x-user-defined")
- });
-}
+ core.animates.forEach(function (t) {
+ core.http(
+ "GET",
+ "project/animates/" + t + ".animate?v=" + main.version,
+ null,
+ function (content) {
+ core.material.animates[t] = core.loader._loadAnimate(content);
+ },
+ function (e) {
+ console.error(e);
+ core.material.animates[t] = null;
+ },
+ "text/plain; charset=x-user-defined"
+ );
+ });
+};
loader.prototype._loadAnimates_async = function (onprogress, onfinished) {
- this._loadFileFromZip('project/animates/animates.h5data', this._saveAnimate, true, onprogress, onfinished);
-}
+ this._loadFileFromZip(
+ "project/animates/animates.h5data",
+ this._saveAnimate,
+ true,
+ onprogress,
+ onfinished
+ );
+};
-loader.prototype._loadAnimates_chunked = function (chunks, makeOnProgress, makeOnFinished) {
- this._loadFileFromChunks(chunks, this._saveAnimate, true, makeOnProgress, makeOnFinished);
-}
+loader.prototype._loadAnimates_chunked = function (
+ chunks,
+ makeOnProgress,
+ makeOnFinished
+) {
+ this._loadFileFromChunks(
+ chunks,
+ this._saveAnimate,
+ true,
+ makeOnProgress,
+ makeOnFinished
+ );
+};
loader.prototype._saveAnimate = function (animates, onfinished) {
- for (var name in animates) {
- if (name.endsWith(".animate")) {
- var t = name.substring(0, name.length - 8);
- if (core.animates.indexOf(t) >= 0)
- core.material.animates[t] = core.loader._loadAnimate(animates[name]);
- }
+ for (var name in animates) {
+ if (name.endsWith(".animate")) {
+ var t = name.substring(0, name.length - 8);
+ if (core.animates.indexOf(t) >= 0)
+ core.material.animates[t] = core.loader._loadAnimate(animates[name]);
}
- onfinished();
-}
+ }
+ onfinished();
+};
loader.prototype._loadAnimate = function (content) {
- try {
- content = JSON.parse(content);
- var data = {};
- data.ratio = content.ratio;
- data.se = content.se;
- data.pitch = content.pitch;
- data.images = [];
- content.bitmaps.forEach(function (t2) {
- if (!t2) {
- data.images.push(null);
- }
- else {
- try {
- var image = new Image();
- image.src = t2;
- data.images.push(image);
- } catch (e) {
- console.error(e);
- data.images.push(null);
- }
- }
- })
- data.frame = content.frame_max;
- data.frames = [];
- content.frames.forEach(function (t2) {
- var info = [];
- t2.forEach(function (t3) {
- info.push({
- 'index': t3[0],
- 'x': t3[1],
- 'y': t3[2],
- 'zoom': t3[3],
- 'opacity': t3[4],
- 'mirror': t3[5] || 0,
- 'angle': t3[6] || 0,
- })
- })
- data.frames.push(info);
+ try {
+ content = JSON.parse(content);
+ var data = {};
+ data.ratio = content.ratio;
+ data.se = content.se;
+ data.pitch = content.pitch;
+ data.images = [];
+ content.bitmaps.forEach(function (t2) {
+ if (!t2) {
+ data.images.push(null);
+ } else {
+ try {
+ var image = new Image();
+ image.src = t2;
+ data.images.push(image);
+ } catch (e) {
+ console.error(e);
+ data.images.push(null);
+ }
+ }
+ });
+ data.frame = content.frame_max;
+ data.frames = [];
+ content.frames.forEach(function (t2) {
+ var info = [];
+ t2.forEach(function (t3) {
+ info.push({
+ index: t3[0],
+ x: t3[1],
+ y: t3[2],
+ zoom: t3[3],
+ opacity: t3[4],
+ mirror: t3[5] || 0,
+ angle: t3[6] || 0,
});
- return data;
- }
- catch (e) {
- console.error(e);
- return null;
- }
-}
+ });
+ data.frames.push(info);
+ });
+ return data;
+ } catch (e) {
+ console.error(e);
+ return null;
+ }
+};
// ------ 加载音乐和音效 ------ //
loader.prototype._loadMusics = function () {
- core.bgms.forEach(function (t) {
- core.loader.loadOneMusic(t);
- });
- // 直接开始播放
- core.playBgm(main.startBgm);
-}
+ core.bgms.forEach(function (t) {
+ core.loader.loadOneMusic(t);
+ });
+ // 直接开始播放
+ core.playBgm(main.startBgm);
+};
loader.prototype._loadSounds_sync = function () {
- this._setStartLoadTipText("正在加载音效文件...");
- core.sounds.forEach(function (t) {
- core.loader.loadOneSound(t);
- });
-}
+ this._setStartLoadTipText("正在加载音效文件...");
+ core.sounds.forEach(function (t) {
+ core.loader.loadOneSound(t);
+ });
+};
loader.prototype._loadSounds_async = function (onprogress, onfinished) {
- this._loadFileFromZip('project/sounds/sounds.h5data', this._saveSounds, false, onprogress, onfinished);
-}
+ this._loadFileFromZip(
+ "project/sounds/sounds.h5data",
+ this._saveSounds,
+ false,
+ onprogress,
+ onfinished
+ );
+};
-loader.prototype._loadSounds_chunked = function (chunks, makeOnProgress, makeOnFinished) {
- this._loadFileFromChunks(chunks, this._saveSounds, false, makeOnProgress, makeOnFinished);
-}
+loader.prototype._loadSounds_chunked = function (
+ chunks,
+ makeOnProgress,
+ makeOnFinished
+) {
+ this._loadFileFromChunks(
+ chunks,
+ this._saveSounds,
+ false,
+ makeOnProgress,
+ makeOnFinished
+ );
+};
loader.prototype._saveSounds = function (data, onfinished) {
- // 延迟解析
- setTimeout(function () {
- for (var name in data) {
- if (core.sounds.indexOf(name) >= 0) {
- core.loader._loadOneSound_decodeData(name, data[name]);
- }
- }
- onfinished();
- });
-}
+ // 延迟解析
+ setTimeout(function () {
+ for (var name in data) {
+ if (core.sounds.indexOf(name) >= 0) {
+ core.loader._loadOneSound_decodeData(name, data[name]);
+ }
+ }
+ onfinished();
+ });
+};
loader.prototype.loadOneMusic = function (name) {
- var music = new Audio();
- music.preload = 'none';
- if (main.bgmRemote) music.src = main.bgmRemoteRoot + core.firstData.name + '/' + name;
- else music.src = 'project/bgms/' + name;
- music.loop = 'loop';
- core.material.bgms[name] = music;
-}
+ /* var music = new Audio();
+ music.preload = "none";
+ if (main.bgmRemote)
+ music.src = main.bgmRemoteRoot + core.firstData.name + "/" + name;
+ else music.src = "project/bgms/" + name;
+ music.loop = "loop";
+ core.material.bgms[name] = music;*/
+};
loader.prototype.loadOneSound = function (name) {
- core.http('GET', 'project/sounds/' + name + "?v=" + main.version, null, function (data) {
- core.loader._loadOneSound_decodeData(name, data);
- }, function (e) {
- console.error(e);
- core.material.sounds[name] = null;
- }, null, 'arraybuffer');
-}
+ core.http(
+ "GET",
+ "project/sounds/" + name + "?v=" + main.version,
+ null,
+ function (data) {
+ core.loader._loadOneSound_decodeData(name, data);
+ },
+ function (e) {
+ console.error(e);
+ core.material.sounds[name] = null;
+ },
+ null,
+ "arraybuffer"
+ );
+};
loader.prototype._loadOneSound_decodeData = function (name, data) {
- if (data instanceof Blob) {
- var blobReader = new zip.BlobReader(data);
- blobReader.init(function () {
- blobReader.readUint8Array(0, blobReader.size, function (uint8) {
- core.loader._loadOneSound_decodeData(name, uint8.buffer);
- })
- });
- return;
- }
- try {
- core.musicStatus.audioContext.decodeAudioData(data, function (buffer) {
- core.material.sounds[name] = buffer;
- }, function (e) {
- console.error(e);
- core.material.sounds[name] = null;
- })
- }
- catch (e) {
+ if (data instanceof Blob) {
+ var blobReader = new zip.BlobReader(data);
+ blobReader.init(function () {
+ blobReader.readUint8Array(0, blobReader.size, function (uint8) {
+ core.loader._loadOneSound_decodeData(name, uint8.buffer);
+ });
+ });
+ return;
+ }
+ try {
+ core.musicStatus.audioContext.decodeAudioData(
+ data,
+ function (buffer) {
+ core.material.sounds[name] = buffer;
+ },
+ function (e) {
console.error(e);
core.material.sounds[name] = null;
- }
-}
+ }
+ );
+ } catch (e) {
+ console.error(e);
+ core.material.sounds[name] = null;
+ }
+};
loader.prototype.loadBgm = function (name) {
- name = core.getMappedName(name);
- if (!core.material.bgms[name]) return;
- // 如果没开启音乐,则不预加载
- if (!core.musicStatus.bgmStatus) return;
- // 是否已经预加载过
- var index = core.musicStatus.cachedBgms.indexOf(name);
- if (index >= 0) {
- core.musicStatus.cachedBgms.splice(index, 1);
+ name = core.getMappedName(name);
+ if (!core.material.bgms[name]) return;
+ // 如果没开启音乐,则不预加载
+ if (!core.musicStatus.bgmStatus) return;
+ // 是否已经预加载过
+ var index = core.musicStatus.cachedBgms.indexOf(name);
+ if (index >= 0) {
+ core.musicStatus.cachedBgms.splice(index, 1);
+ } else {
+ // 预加载BGM
+ this._preloadBgm(core.material.bgms[name]);
+ // core.material.bgms[name].load();
+ // 清理尾巴
+ if (core.musicStatus.cachedBgms.length == core.musicStatus.cachedBgmCount) {
+ this.freeBgm(core.musicStatus.cachedBgms.pop());
}
- else {
- // 预加载BGM
- this._preloadBgm(core.material.bgms[name]);
- // core.material.bgms[name].load();
- // 清理尾巴
- if (core.musicStatus.cachedBgms.length == core.musicStatus.cachedBgmCount) {
- this.freeBgm(core.musicStatus.cachedBgms.pop());
- }
- }
- // 移动到缓存最前方
- core.musicStatus.cachedBgms.unshift(name);
-}
+ }
+ // 移动到缓存最前方
+ core.musicStatus.cachedBgms.unshift(name);
+};
loader.prototype._preloadBgm = function (bgm) {
- bgm.volume = 0;
- bgm.play();
-}
+ bgm.volume = 0;
+ bgm.play();
+};
loader.prototype.freeBgm = function (name) {
- name = core.getMappedName(name);
- if (!core.material.bgms[name]) return;
- // 从cachedBgms中删除
- core.musicStatus.cachedBgms = core.musicStatus.cachedBgms.filter(function (t) {
- return t != name;
- });
- // 清掉缓存
- core.material.bgms[name].removeAttribute("src");
- core.material.bgms[name].load();
- core.material.bgms[name] = null;
- if (name == core.musicStatus.playingBgm) {
- core.musicStatus.playingBgm = null;
- }
- // 三秒后重新加载
- setTimeout(function () {
- core.loader.loadOneMusic(name);
- }, 3000);
-}
+ name = core.getMappedName(name);
+ if (!core.material.bgms[name]) return;
+ // 从cachedBgms中删除
+ core.musicStatus.cachedBgms = core.musicStatus.cachedBgms.filter(function (
+ t
+ ) {
+ return t != name;
+ });
+ // 清掉缓存
+ core.material.bgms[name].removeAttribute("src");
+ core.material.bgms[name].load();
+ core.material.bgms[name] = null;
+ if (name == core.musicStatus.playingBgm) {
+ core.musicStatus.playingBgm = null;
+ }
+ // 三秒后重新加载
+ setTimeout(function () {
+ core.loader.loadOneMusic(name);
+ }, 3000);
+};
-loader.prototype._loadFileFromZip = function (url, save, convertToText, onprogress, onfinished) {
- core.unzip(url + '?v=' + main.version, function (data) {
- save(data, onfinished);
- }, null, convertToText, onprogress);
-}
+loader.prototype._loadFileFromZip = function (
+ url,
+ save,
+ convertToText,
+ onprogress,
+ onfinished
+) {
+ core.unzip(
+ url + "?v=" + main.version,
+ function (data) {
+ save(data, onfinished);
+ },
+ null,
+ convertToText,
+ onprogress
+ );
+};
-loader.prototype._loadFileFromChunks = async function (chunks, save, convertToText, makeOnProgress, makeOnFinished) {
- await Promise.all(chunks.map((chunk) => {
- const onfinished = makeOnFinished(chunk);
- const onprogress = makeOnProgress(chunk);
- return new Promise((resolve) => {
- this._loadFileFromZip(chunk, save, convertToText, onprogress, () => {
- onfinished();
- resolve();
- });
+loader.prototype._loadFileFromChunks = async function (
+ chunks,
+ save,
+ convertToText,
+ makeOnProgress,
+ makeOnFinished
+) {
+ await Promise.all(
+ chunks.map((chunk) => {
+ const onfinished = makeOnFinished(chunk);
+ const onprogress = makeOnProgress(chunk);
+ return new Promise((resolve) => {
+ this._loadFileFromZip(chunk, save, convertToText, onprogress, () => {
+ onfinished();
+ resolve();
});
- }));
-}
+ });
+ })
+ );
+};
diff --git a/libs/thirdparty/codec-parser.min.js b/libs/thirdparty/codec-parser.min.js
new file mode 100644
index 0000000..fb4ac2e
--- /dev/null
+++ b/libs/thirdparty/codec-parser.min.js
@@ -0,0 +1 @@
+var CodecParser=function(e){"use strict";const t=Symbol,s=(()=>{const e="left",t="center",s="right";return["","front ","side ","rear "].map((i=>[[e,s],[e,s,t],[e,t,s],[t,e,s],[t]].flatMap((e=>e.map((e=>i+e)).join(", ")))))})(),i="LFE",r="monophonic (mono)",n="stereo",a="surround",o=(e,...t)=>`${[r,n,`linear ${a}`,"quadraphonic",`5.0 ${a}`,`5.1 ${a}`,`6.1 ${a}`,`7.1 ${a}`][e-1]} (${t.join(", ")})`,h=[r,o(2,s[0][0]),o(3,s[0][2]),o(4,s[1][0],s[3][0]),o(5,s[1][2],s[3][0]),o(6,s[1][2],s[3][0],i),o(7,s[1][2],s[2][0],s[3][4],i),o(8,s[1][2],s[2][0],s[3][0],i)],c=48e3,l=44100,u=32e3,d=24e3,p=22050,_=16e3,m=8e3,g="absoluteGranulePosition",f="bandwidth",b="bitDepth",C="bitrate",y=C+"Maximum",S=C+"Minimum",w=C+"Nominal",P="buffer",k=P+"Fullness",v="codec",F=v+"Frames",x="coupledStreamCount",H="crc",I=H+"16",M=H+"32",U="data",O="description",N="duration",$="emphasis",A="hasOpusPadding",R="header",B="isContinuedPacket",L="isCopyrighted",D="isFirstPage",T="isHome",E="isLastPage",G="isOriginal",z="isPrivate",q="isVbr",V="layer",j="length",W="mode",J=W+"Extension",K="mpeg",Q=K+"Version",X="numberAACFrames",Y="outputGain",Z="preSkip",ee="profile",te=t(),se="protection",ie="rawData",re="segments",ne="subarray",ae="version",oe="vorbis",he=oe+"Comments",ce=oe+"Setup",le="block",ue=le+"ingStrategy",de=t(),pe=le+"Size",_e=le+"size0",me=le+"size1",ge=t(),fe="channel",be=fe+"MappingFamily",Ce=fe+"MappingTable",ye=fe+"Mode",Se=t(),we=fe+"s",Pe="copyright",ke=Pe+"Id",ve=Pe+"IdStart",Fe="frame",xe=Fe+"Count",He=Fe+"Length",Ie="Number",Me=Fe+Ie,Ue=Fe+"Padding",Oe=Fe+"Size",Ne="Rate",$e="inputSample"+Ne,Ae="page",Re=Ae+"Checksum",Be=t(),Le=Ae+"SegmentTable",De=Ae+"Sequence"+Ie,Te="sample",Ee=Te+Ie,Ge=Te+Ne,ze=t(),qe=Te+"s",Ve="stream",je=Ve+"Count",We=Ve+"Info",Je=Ve+"Serial"+Ie,Ke=Ve+"StructureVersion",Qe="total",Xe=Qe+"BytesOut",Ye=Qe+"Duration",Ze=Qe+"Samples",et=t(),tt=t(),st=t(),it=t(),rt=t(),nt=t(),at=t(),ot=t(),ht=t(),ct=t(),lt=t(),ut=t(),dt=t(),pt=t(),_t=t(),mt=t(),gt=t(),ft=t(),bt=Uint8Array,Ct=DataView,yt="reserved",St="bad",wt="free",Pt="none",kt="16bit CRC",vt=(e,t,s)=>{for(let i=0;i
0;e--)r=s(r);e[i]=r}return e},Ft=vt(new bt(256),(e=>e),(e=>128&e?7^e<<1:e<<1)),xt=[vt(new Uint16Array(256),(e=>e<<8),(e=>e<<1^(32768&e?32773:0)))],Ht=[vt(new Uint32Array(256),(e=>e),(e=>e>>>1^3988292384*(1&e)))];for(let e=0;e<15;e++){xt.push(new Uint16Array(256)),Ht.push(new Uint32Array(256));for(let t=0;t<=255;t++)xt[e+1][t]=xt[0][xt[e][t]>>>8]^xt[e][t]<<8,Ht[e+1][t]=Ht[e][t]>>>8^Ht[0][255&Ht[e][t]]}const It=e=>{const t=e[j],s=t-16;let i=0,r=0;for(;r<=s;)i=Ht[15][255&(e[r++]^i)]^Ht[14][255&(e[r++]^i>>>8)]^Ht[13][255&(e[r++]^i>>>16)]^Ht[12][e[r++]^i>>>24]^Ht[11][e[r++]]^Ht[10][e[r++]]^Ht[9][e[r++]]^Ht[8][e[r++]]^Ht[7][e[r++]]^Ht[6][e[r++]]^Ht[5][e[r++]]^Ht[4][e[r++]]^Ht[3][e[r++]]^Ht[2][e[r++]]^Ht[1][e[r++]]^Ht[0][e[r++]];for(;r!==t;)i=Ht[0][255&(i^e[r++])]^i>>>8;return~i},Mt=(...e)=>{const t=new bt(e.reduce(((e,t)=>e+t[j]),0));return e.reduce(((e,s)=>(t.set(s,e),e+s[j])),0),t},Ut=e=>String.fromCharCode(...e),Ot=[0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15],Nt=e=>Ot[15&e]<<4|Ot[e>>4];class $t{constructor(e){this._data=e,this._pos=8*e[j]}set position(e){this._pos=e}get position(){return this._pos}read(e){const t=Math.floor(this._pos/8),s=this._pos%8;this._pos-=e;return(Nt(this._data[t-1])<<8)+Nt(this._data[t])>>7-s&255}}class At{constructor(e,t){this._onCodecHeader=e,this._onCodecUpdate=t,this[_t]()}[mt](){this._isEnabled=!0}[_t](){this._headerCache=new Map,this._codecUpdateData=new WeakMap,this._codecHeaderSent=!1,this._codecShouldUpdate=!1,this._bitrate=null,this._isEnabled=!1}[pt](e,t){if(this._onCodecUpdate){this._bitrate!==e&&(this._bitrate=e,this._codecShouldUpdate=!0);const s=this._codecUpdateData.get(this._headerCache.get(this._currentHeader));this._codecShouldUpdate&&s&&this._onCodecUpdate({bitrate:e,...s},t),this._codecShouldUpdate=!1}}[ht](e){const t=this._headerCache.get(e);return t&&this._updateCurrentHeader(e),t}[ct](e,t,s){this._isEnabled&&(this._codecHeaderSent||(this._onCodecHeader({...t}),this._codecHeaderSent=!0),this._updateCurrentHeader(e),this._headerCache.set(e,t),this._codecUpdateData.set(t,s))}_updateCurrentHeader(e){this._onCodecUpdate&&e!==this._currentHeader&&(this._codecShouldUpdate=!0,this._currentHeader=e)}}const Rt=new WeakMap,Bt=new WeakMap;class Lt{constructor(e,t){this._codecParser=e,this._headerCache=t}*[at](){let e;for(;;){if(e=yield*this.Frame[lt](this._codecParser,this._headerCache,0),e)return e;this._codecParser[tt](1)}}*[ot](e){let t=yield*this[at]();const s=Bt.get(t)[j];if(e||this._codecParser._flushing||(yield*this.Header[ht](this._codecParser,this._headerCache,s)))return this._headerCache[mt](),this._codecParser[tt](s),this._codecParser[it](t),t;this._codecParser[rt](`Missing ${Fe} at ${s} bytes from current position.`,`Dropping current ${Fe} and trying again.`),this._headerCache[_t](),this._codecParser[tt](1)}}class Dt{constructor(e,t){Bt.set(this,{[R]:e}),this[U]=t}}class Tt extends Dt{static*[lt](e,t,s,i,r){const n=yield*e[ht](s,i,r);if(n){const e=Rt.get(n)[He],i=Rt.get(n)[qe];return new t(n,(yield*s[et](e,r))[ne](0,e),i)}return null}constructor(e,t,s){super(e,t),this[R]=e,this[qe]=s,this[N]=s/e[Ge]*1e3,this[Me]=null,this[Xe]=null,this[Ze]=null,this[Ye]=null,Bt.get(this)[j]=t[j]}}const Et="unsynchronizationFlag",Gt="extendedHeaderFlag",zt="experimentalFlag",qt="footerPresent";class Vt{static*getID3v2Header(e,t,s){const i={};let r=yield*e[et](3,s);if(73!==r[0]||68!==r[1]||51!==r[2])return null;if(r=yield*e[et](10,s),i[ae]=`id3v2.${r[3]}.${r[4]}`,15&r[5])return null;if(i[Et]=!!(128&r[5]),i[Gt]=!!(64&r[5]),i[zt]=!!(32&r[5]),i[qt]=!!(16&r[5]),128&r[6]||128&r[7]||128&r[8]||128&r[9])return null;const n=r[6]<<21|r[7]<<14|r[8]<<7|r[9];return i[j]=10+n,new Vt(i)}constructor(e){this[ae]=e[ae],this[Et]=e[Et],this[Gt]=e[Gt],this[zt]=e[zt],this[qt]=e[qt],this[j]=e[j]}}class jt{constructor(e){Rt.set(this,e),this[b]=e[b],this[C]=null,this[we]=e[we],this[ye]=e[ye],this[Ge]=e[Ge]}}const Wt={0:[wt,wt,wt,wt,wt],16:[32,32,32,32,8],240:[St,St,St,St,St]},Jt=(e,t,s)=>8*((e+s)%t+t)*(1<<(e+s)/t)-8*t*(t/8|0);for(let e=2;e<15;e++)Wt[e<<4]=[32*e,Jt(e,4,0),Jt(e,4,-1),Jt(e,8,4),Jt(e,8,0)];const Kt="bands ",Qt=" to 31",Xt={0:Kt+4+Qt,16:Kt+8+Qt,32:Kt+12+Qt,48:Kt+16+Qt},Yt="bitrateIndex",Zt="v2",es="v1",ts="Intensity stereo ",ss=", MS stereo ",is="on",rs="off",ns={0:ts+rs+ss+rs,16:ts+is+ss+rs,32:ts+rs+ss+is,48:ts+is+ss+is},as={0:{[O]:yt},2:{[O]:"Layer III",[Ue]:1,[J]:ns,[es]:{[Yt]:2,[qe]:1152},[Zt]:{[Yt]:4,[qe]:576}},4:{[O]:"Layer II",[Ue]:1,[J]:Xt,[qe]:1152,[es]:{[Yt]:1},[Zt]:{[Yt]:4}},6:{[O]:"Layer I",[Ue]:4,[J]:Xt,[qe]:384,[es]:{[Yt]:0},[Zt]:{[Yt]:3}}},os="MPEG Version ",hs="ISO/IEC ",cs={0:{[O]:`${os}2.5 (later extension of MPEG 2)`,[V]:Zt,[Ge]:{0:11025,4:12e3,8:m,12:yt}},8:{[O]:yt},16:{[O]:`${os}2 (${hs}13818-3)`,[V]:Zt,[Ge]:{0:p,4:d,8:_,12:yt}},24:{[O]:`${os}1 (${hs}11172-3)`,[V]:es,[Ge]:{0:l,4:c,8:u,12:yt}},length:j},ls={0:kt,1:Pt},us={0:Pt,1:"50/15 ms",2:yt,3:"CCIT J.17"},ds={0:{[we]:2,[O]:n},64:{[we]:2,[O]:"joint "+n},128:{[we]:2,[O]:"dual channel"},192:{[we]:1,[O]:r}};class ps extends jt{static*[ht](e,t,s){const i={},r=yield*Vt.getID3v2Header(e,t,s);r&&(yield*e[et](r[j],s),e[tt](r[j]));const n=yield*e[et](4,s),a=Ut(n[ne](0,4)),o=t[ht](a);if(o)return new ps(o);if(255!==n[0]||n[1]<224)return null;const h=cs[24&n[1]];if(h[O]===yt)return null;const c=6&n[1];if(as[c][O]===yt)return null;const l={...as[c],...as[c][h[V]]};if(i[Q]=h[O],i[V]=l[O],i[qe]=l[qe],i[se]=ls[1&n[1]],i[j]=4,i[C]=Wt[240&n[2]][l[Yt]],i[C]===St)return null;if(i[Ge]=h[Ge][12&n[2]],i[Ge]===yt)return null;if(i[Ue]=2&n[2]&&l[Ue],i[z]=!!(1&n[2]),i[He]=Math.floor(125*i[C]*i[qe]/i[Ge]+i[Ue]),!i[He])return null;const u=192&n[3];if(i[ye]=ds[u][O],i[we]=ds[u][we],i[J]=l[J][48&n[3]],i[L]=!!(8&n[3]),i[G]=!!(4&n[3]),i[$]=us[3&n[3]],i[$]===yt)return null;i[b]=16;{const{length:e,frameLength:s,samples:r,...n}=i;t[ct](a,i,n)}return new ps(i)}constructor(e){super(e),this[C]=e[C],this[$]=e[$],this[Ue]=e[Ue],this[L]=e[L],this[G]=e[G],this[z]=e[z],this[V]=e[V],this[J]=e[J],this[Q]=e[Q],this[se]=e[se]}}class _s extends Tt{static*[lt](e,t,s){return yield*super[lt](ps,_s,e,t,s)}constructor(e,t,s){super(e,t,s)}}class ms extends Lt{constructor(e,t,s){super(e,t),this.Frame=_s,this.Header=ps,s(this[v])}get[v](){return K}*[ut](){return yield*this[ot]()}}const gs={0:"MPEG-4",8:"MPEG-2"},fs={0:"valid",2:St,4:St,6:St},bs={0:kt,1:Pt},Cs={0:"AAC Main",64:"AAC LC (Low Complexity)",128:"AAC SSR (Scalable Sample Rate)",192:"AAC LTP (Long Term Prediction)"},ys={0:96e3,4:88200,8:64e3,12:c,16:l,20:u,24:d,28:p,32:_,36:12e3,40:11025,44:m,48:7350,52:yt,56:yt,60:"frequency is written explicitly"},Ss={0:{[we]:0,[O]:"Defined in AOT Specific Config"},64:{[we]:1,[O]:r},128:{[we]:2,[O]:o(2,s[0][0])},192:{[we]:3,[O]:o(3,s[1][3])},256:{[we]:4,[O]:o(4,s[1][3],s[3][4])},320:{[we]:5,[O]:o(5,s[1][3],s[3][0])},384:{[we]:6,[O]:o(6,s[1][3],s[3][0],i)},448:{[we]:8,[O]:o(8,s[1][3],s[2][0],s[3][0],i)}};class ws extends jt{static*[ht](e,t,s){const i={},r=yield*e[et](7,s),n=Ut([r[0],r[1],r[2],252&r[3]|3&r[6]]),a=t[ht](n);if(a)Object.assign(i,a);else{if(255!==r[0]||r[1]<240)return null;if(i[Q]=gs[8&r[1]],i[V]=fs[6&r[1]],i[V]===St)return null;const e=1&r[1];i[se]=bs[e],i[j]=e?7:9,i[te]=192&r[2],i[ze]=60&r[2];const s=2&r[2];if(i[ee]=Cs[i[te]],i[Ge]=ys[i[ze]],i[Ge]===yt)return null;i[z]=!!s,i[Se]=448&(r[2]<<8|r[3]),i[ye]=Ss[i[Se]][O],i[we]=Ss[i[Se]][we],i[G]=!!(32&r[3]),i[T]=!!(8&r[3]),i[ke]=!!(8&r[3]),i[ve]=!!(4&r[3]),i[b]=16,i[qe]=1024,i[X]=3&r[6];{const{length:e,channelModeBits:s,profileBits:r,sampleRateBits:a,frameLength:o,samples:h,numberAACFrames:c,...l}=i;t[ct](n,i,l)}}if(i[He]=8191&(r[3]<<11|r[4]<<3|r[5]>>5),!i[He])return null;const o=2047&(r[5]<<6|r[6]>>2);return i[k]=2047===o?"VBR":o,new ws(i)}constructor(e){super(e),this[ke]=e[ke],this[ve]=e[ve],this[k]=e[k],this[T]=e[T],this[G]=e[G],this[z]=e[z],this[V]=e[V],this[j]=e[j],this[Q]=e[Q],this[X]=e[X],this[ee]=e[ee],this[se]=e[se]}get audioSpecificConfig(){const e=Rt.get(this),t=e[te]+64<<5|e[ze]<<5|e[Se]>>3,s=new bt(2);return new Ct(s[P]).setUint16(0,t,!1),s}}class Ps extends Tt{static*[lt](e,t,s){return yield*super[lt](ws,Ps,e,t,s)}constructor(e,t,s){super(e,t,s)}}class ks extends Lt{constructor(e,t,s){super(e,t),this.Frame=Ps,this.Header=ws,s(this[v])}get[v](){return"aac"}*[ut](){return yield*this[ot]()}}class vs extends Tt{static _getFrameFooterCrc16(e){return(e[e[j]-2]<<8)+e[e[j]-1]}static[ft](e){const t=vs._getFrameFooterCrc16(e),s=(e=>{const t=e[j],s=t-16;let i=0,r=0;for(;r<=s;)i^=e[r++]<<8|e[r++],i=xt[15][i>>8]^xt[14][255&i]^xt[13][e[r++]]^xt[12][e[r++]]^xt[11][e[r++]]^xt[10][e[r++]]^xt[9][e[r++]]^xt[8][e[r++]]^xt[7][e[r++]]^xt[6][e[r++]]^xt[5][e[r++]]^xt[4][e[r++]]^xt[3][e[r++]]^xt[2][e[r++]]^xt[1][e[r++]]^xt[0][e[r++]];for(;r!==t;)i=(255&i)<<8^xt[0][i>>8^e[r++]];return i})(e[ne](0,-2));return t===s}constructor(e,t,s){t[We]=s,t[I]=vs._getFrameFooterCrc16(e),super(t,e,Rt.get(t)[qe])}}const Fs="get from STREAMINFO metadata block",xs={0:"Fixed",1:"Variable"},Hs={0:yt,16:192};for(let e=2;e<16;e++)Hs[e<<4]=e<6?576*2**(e-2):2**e;const Is={0:Fs,1:88200,2:176400,3:192e3,4:m,5:_,6:p,7:d,8:u,9:l,10:c,11:96e3,15:St},Ms={0:{[we]:1,[O]:r},16:{[we]:2,[O]:o(2,s[0][0])},32:{[we]:3,[O]:o(3,s[0][1])},48:{[we]:4,[O]:o(4,s[1][0],s[3][0])},64:{[we]:5,[O]:o(5,s[1][1],s[3][0])},80:{[we]:6,[O]:o(6,s[1][1],i,s[3][0])},96:{[we]:7,[O]:o(7,s[1][1],i,s[3][4],s[2][0])},112:{[we]:8,[O]:o(8,s[1][1],i,s[3][0],s[2][0])},128:{[we]:2,[O]:`${n} (left, diff)`},144:{[we]:2,[O]:`${n} (diff, right)`},160:{[we]:2,[O]:`${n} (avg, diff)`},176:yt,192:yt,208:yt,224:yt,240:yt},Us={0:Fs,2:8,4:12,6:yt,8:16,10:20,12:24,14:yt};class Os extends jt{static _decodeUTF8Int(e){if(e[0]>254)return null;if(e[0]<128)return{value:e[0],length:1};let t=1;for(let s=64;s&e[0];s>>=1)t++;let s=t-1,i=0,r=0;for(;s>0;r+=6,s--){if(128!=(192&e[s]))return null;i|=(63&e[s])<>t)<{let t=0;const s=e[j];for(let i=0;i!==s;i++)t=Ft[t^e[i]];return t})(i[ne](0,r[j]-1)))return null;if(!a){const{blockingStrategyBits:e,frameNumber:s,sampleNumber:i,samples:a,sampleRateBits:o,blockSizeBits:h,crc:c,length:l,...u}=r;t[ct](n,r,u)}return new Os(r)}constructor(e){super(e),this[I]=null,this[ue]=e[ue],this[pe]=e[pe],this[Me]=e[Me],this[Ee]=e[Ee],this[We]=null}}class Ns extends Lt{constructor(e,t,s){super(e,t),this.Frame=vs,this.Header=Os,s(this[v])}get[v](){return"flac"}*_getNextFrameSyncOffset(e){const t=yield*this._codecParser[et](2,0),s=t[j]-2;for(;e{const t=Os[gt](e,this._headerCache);if(t)return new vs(e,t,this._streamInfo);this._codecParser[rt]("Failed to parse Ogg FLAC frame","Skipping invalid FLAC frame")})).filter((e=>!!e))),e}}class $s{static*[ht](e,t,s){const i={};let r=yield*e[et](28,s);if(79!==r[0]||103!==r[1]||103!==r[2]||83!==r[3])return null;i[Ke]=r[4];if(248&r[5])return null;i[E]=!!(4&r[5]),i[D]=!!(2&r[5]),i[B]=!!(1&r[5]);const n=new Ct(bt.from(r[ne](0,28))[P]);i[g]=((e,t)=>{try{return e.getBigInt64(t,!0)}catch{const s=128&e.getUint8(t+7)?-1:1;let i=e.getUint32(t,!0),r=e.getUint32(t+4,!0);return-1===s&&(i=1+~i,r=1+~r),r>1048575&&console.warn("This platform does not support BigInt"),s*(i+r*2**32)}})(n,6),i[Je]=n.getInt32(14,!0),i[De]=n.getInt32(18,!0),i[Re]=n.getInt32(22,!0);const a=r[26];i[j]=a+27,r=yield*e[et](i[j],s),i[He]=0,i[Le]=[],i[Be]=bt.from(r[ne](27,i[j]));for(let e=0,t=0;e{const t=Ws[gt](this._identificationHeader,e,this._headerCache);if(t){null===this._preSkipRemaining&&(this._preSkipRemaining=t[Z]);let s=t[Oe]*t[xe]/1e3*t[Ge];return this._preSkipRemaining>0&&(this._preSkipRemaining-=s,s=this._preSkipRemaining<0?-this._preSkipRemaining:0),new Rs(e,t,s)}this._codecParser[nt]("Failed to parse Ogg Opus Header","Not a valid Ogg Opus file")}))),e}}class Ks extends Tt{constructor(e,t,s){super(t,e,s)}}const Qs={};for(let e=0;e<8;e++)Qs[e+6]=2**(6+e);class Xs extends jt{static[gt](e,t,s,i){if(e[j]<30)throw new Error("Out of data while inside an Ogg Page");const r=Ut(e[ne](0,30)),n=t[ht](r);if(n)return new Xs(n);const a={[j]:30};if("vorbis"!==r.substr(0,7))return null;a[U]=bt.from(e[ne](0,30));const o=new Ct(a[U][P]);if(a[ae]=o.getUint32(7,!0),0!==a[ae])return null;if(a[we]=e[11],a[ye]=h[a[we]-1]||"application defined",a[Ge]=o.getUint32(12,!0),a[y]=o.getInt32(16,!0),a[w]=o.getInt32(20,!0),a[S]=o.getInt32(24,!0),a[me]=Qs[(240&e[28])>>4],a[_e]=Qs[15&e[28]],a[_e]>a[me])return null;if(1!==e[29])return null;a[b]=32,a[ce]=i,a[he]=s;{const{length:e,data:s,version:i,vorbisSetup:n,vorbisComments:o,...h}=a;t[ct](r,a,h)}return new Xs(a)}constructor(e){super(e),this[y]=e[y],this[S]=e[S],this[w]=e[w],this[_e]=e[_e],this[me]=e[me],this[U]=e[U],this[he]=e[he],this[ce]=e[ce]}}class Ys extends Lt{constructor(e,t,s){super(e,t),this.Frame=Ks,s(this[v]),this._identificationHeader=null,this._setupComplete=!1,this._prevBlockSize=null}get[v](){return oe}[dt](e){e[F]=[];for(const t of Bt.get(e)[re])if(1===t[0])this._headerCache[mt](),this._identificationHeader=e[U],this._setupComplete=!1;else if(3===t[0])this._vorbisComments=t;else if(5===t[0])this._vorbisSetup=t,this._mode=this._parseSetupHeader(t),this._setupComplete=!0;else if(this._setupComplete){const s=Xs[gt](this._identificationHeader,this._headerCache,this._vorbisComments,this._vorbisSetup);s?e[F].push(new Ks(t,s,this._getSamples(t,s))):this._codecParser[logError]("Failed to parse Ogg Vorbis Header","Not a valid Ogg Vorbis file")}return e}_getSamples(e,t){const s=this._mode.blockFlags[e[0]>>1&this._mode.mask]?t[me]:t[_e],i=null===this._prevBlockSize?0:(this._prevBlockSize+s)/4;return this._prevBlockSize=s,i}_parseSetupHeader(e){const t=new $t(e),s={count:0,blockFlags:[]};for(;1&~t.read(1););let i;for(;s.count<64&&t.position>0;){Nt(t.read(8));let e=0;for(;0===t.read(8)&&e++<3;);if(4!==e){1+((126&Nt(i))>>1)!==s.count&&this._codecParser[rt]("vorbis derived mode count did not match actual mode count");break}i=t.read(7),s.blockFlags.unshift(1&i),t.position+=6,s.count++}return s.mask=(1<1&&e[De]>1&&this._codecParser[rt]("Unexpected gap in Ogg Page Sequence Number.",`Expected: ${this._pageSequenceNumber+1}, Got: ${e[De]}`),this._pageSequenceNumber=e[De]}_parsePage(e){null===this._isSupported&&(this._pageSequenceNumber=e[De],this._isSupported=this._checkCodecSupport(e)),this._checkPageSequenceNumber(e);const t=Bt.get(e),s=Rt.get(t[R]);let i=0;if(t[re]=s[Le].map((t=>e[U][ne](i,i+=t))),this._continuedPacket[j]&&(t[re][0]=Mt(this._continuedPacket,t[re][0]),this._continuedPacket=new bt),255===s[Be][s[Be][j]-1]&&(this._continuedPacket=Mt(this._continuedPacket,t[re].pop())),null!==this._previousAbsoluteGranulePosition&&(e[qe]=Number(e[g]-this._previousAbsoluteGranulePosition)),this._previousAbsoluteGranulePosition=e[g],this._isSupported){const t=this._parser[dt](e);return this._codecParser[it](t),t}return e}}class ei extends Lt{constructor(e,t,s){super(e,t),this._onCodec=s,this.Frame=As,this.Header=$s,this._streams=new Map,this._currentSerialNumber=null}get[v](){const e=this._streams.get(this._currentSerialNumber);return e?e.codec:""}*[ut](){const e=yield*this[ot](!0);this._currentSerialNumber=e[Je];let t=this._streams.get(this._currentSerialNumber);return t||(t=new Zs(this._codecParser,this._headerCache,this._onCodec),this._streams.set(this._currentSerialNumber,t)),e[E]&&this._streams.delete(this._currentSerialNumber),t._parsePage(e)}}const ti=()=>{};const si=g,ii=f,ri=b,ni=C,ai=y,oi=S,hi=w,ci=P,li=k,ui=v,di=F,pi=x,_i=H,mi=I,gi=M,fi=U,bi=O,Ci=N,yi=$,Si=A,wi=R,Pi=B,ki=L,vi=D,Fi=T,xi=E,Hi=G,Ii=z,Mi=q,Ui=V,Oi=j,Ni=W,$i=J,Ai=K,Ri=Q,Bi=X,Li=Y,Di=Z,Ti=ee,Ei=se,Gi=ie,zi=re,qi=ne,Vi=ae,ji=oe,Wi=he,Ji=ce,Ki=ue,Qi=pe,Xi=_e,Yi=me,Zi=be,er=Ce,tr=ye,sr=we,ir=ke,rr=ve,nr=Fe,ar=xe,or=He,hr=Me,cr=Ue,lr=Oe,ur=$e,dr=Re,pr=Le,_r=De,mr=Ee,gr=Ge,fr=qe,br=je,Cr=We,yr=Je,Sr=Ke,wr=Xe,Pr=Ye,kr=Ze;return e.CodecParser=class{constructor(e,{onCodec:t,onCodecHeader:s,onCodecUpdate:i,enableLogging:r=!1,enableFrameCRC32:n=!0}={}){this._inputMimeType=e,this._onCodec=t||ti,this._onCodecHeader=s||ti,this._onCodecUpdate=i,this._enableLogging=r,this._crc32=n?It:ti,this[_t]()}get[v](){return this._parser?this._parser[v]:""}[_t](){this._headerCache=new At(this._onCodecHeader,this._onCodecUpdate),this._generator=this._getGenerator(),this._generator.next()}*flush(){this._flushing=!0;for(let e=this._generator.next();e.value;e=this._generator.next())yield e.value;this._flushing=!1,this[_t]()}*parseChunk(e){for(let t=this._generator.next(e);t.value;t=this._generator.next())yield t.value}parseAll(e){return[...this.parseChunk(e),...this.flush()]}*_getGenerator(){if(this._inputMimeType.match(/aac/))this._parser=new ks(this,this._headerCache,this._onCodec);else if(this._inputMimeType.match(/mpeg/))this._parser=new ms(this,this._headerCache,this._onCodec);else if(this._inputMimeType.match(/flac/))this._parser=new Ns(this,this._headerCache,this._onCodec);else{if(!this._inputMimeType.match(/ogg/))throw new Error(`Unsupported Codec ${mimeType}`);this._parser=new ei(this,this._headerCache,this._onCodec)}for(this._frameNumber=0,this._currentReadPosition=0,this._totalBytesIn=0,this._totalBytesOut=0,this._totalSamples=0,this._sampleRate=void 0,this._rawData=new Uint8Array(0);;){const e=yield*this._parser[ut]();e&&(yield e)}}*[et](e=0,t=0){let s;for(;this._rawData[j]<=e+t;){if(s=yield,this._flushing)return this._rawData[ne](t);s&&(this._totalBytesIn+=s[j],this._rawData=Mt(this._rawData,s))}return this._rawData[ne](t)}[tt](e){this._currentReadPosition+=e,this._rawData=this._rawData[ne](e)}[st](e){this._sampleRate=e[R][Ge],e[R][C]=e[N]>0?8*Math.round(e[U][j]/e[N]):0,e[Me]=this._frameNumber++,e[Xe]=this._totalBytesOut,e[Ze]=this._totalSamples,e[Ye]=this._totalSamples/this._sampleRate*1e3,e[M]=this._crc32(e[U]),this._headerCache[pt](e[R][C],e[Ye]),this._totalBytesOut+=e[U][j],this._totalSamples+=e[qe]}[it](e){if(e[F]){if(e[E]){let t=e[qe];e[F].forEach((e=>{const s=e[qe];t0?t:0,e[N]=e[qe]/e[R][Ge]*1e3),t-=s,this[st](e)}))}else e[qe]=0,e[F].forEach((t=>{e[qe]+=t[qe],this[st](t)}));e[N]=e[qe]/this._sampleRate*1e3||0,e[Ze]=this._totalSamples,e[Ye]=this._totalSamples/this._sampleRate*1e3||0,e[Xe]=this._totalBytesOut}else this[st](e)}_log(e,t){if(this._enableLogging){const s=[`${v}: ${this[v]}`,`inputMimeType: ${this._inputMimeType}`,`readPosition: ${this._currentReadPosition}`,`totalBytesIn: ${this._totalBytesIn}`,`${Xe}: ${this._totalBytesOut}`],i=Math.max(...s.map((e=>e[j])));t.push(`--stats--${"-".repeat(i-9)}`,...s,"-".repeat(i)),e("codec-parser",t.reduce(((e,t)=>e+"\n "+t),""))}}[rt](...e){this._log(console.warn,e)}[nt](...e){this._log(console.error,e)}},e.absoluteGranulePosition=si,e.bandwidth=ii,e.bitDepth=ri,e.bitrate=ni,e.bitrateMaximum=ai,e.bitrateMinimum=oi,e.bitrateNominal=hi,e.blockSize=Qi,e.blockingStrategy=Ki,e.blocksize0=Xi,e.blocksize1=Yi,e.buffer=ci,e.bufferFullness=li,e.channelMappingFamily=Zi,e.channelMappingTable=er,e.channelMode=tr,e.channels=sr,e.codec=ui,e.codecFrames=di,e.copyrightId=ir,e.copyrightIdStart=rr,e.coupledStreamCount=pi,e.crc=_i,e.crc16=mi,e.crc32=gi,e.data=fi,e.description=bi,e.duration=Ci,e.emphasis=yi,e.frame=nr,e.frameCount=ar,e.frameLength=or,e.frameNumber=hr,e.framePadding=cr,e.frameSize=lr,e.hasOpusPadding=Si,e.header=wi,e.inputSampleRate=ur,e.isContinuedPacket=Pi,e.isCopyrighted=ki,e.isFirstPage=vi,e.isHome=Fi,e.isLastPage=xi,e.isOriginal=Hi,e.isPrivate=Ii,e.isVbr=Mi,e.layer=Ui,e.length=Oi,e.mode=Ni,e.modeExtension=$i,e.mpeg=Ai,e.mpegVersion=Ri,e.numberAACFrames=Bi,e.outputGain=Li,e.pageChecksum=dr,e.pageSegmentTable=pr,e.pageSequenceNumber=_r,e.preSkip=Di,e.profile=Ti,e.protection=Ei,e.rawData=Gi,e.sampleNumber=mr,e.sampleRate=gr,e.samples=fr,e.segments=zi,e.streamCount=br,e.streamInfo=Cr,e.streamSerialNumber=yr,e.streamStructureVersion=Sr,e.subarray=qi,e.totalBytesOut=wr,e.totalDuration=Pr,e.totalSamples=kr,e.version=Vi,e.vorbis=ji,e.vorbisComments=Wi,e.vorbisSetup=Ji,e}({});
diff --git a/libs/thirdparty/ogg-opus-decoder.min.js b/libs/thirdparty/ogg-opus-decoder.min.js
new file mode 100644
index 0000000..9525201
Binary files /dev/null and b/libs/thirdparty/ogg-opus-decoder.min.js differ
diff --git a/libs/thirdparty/ogg-vorbis-decoder.min.js b/libs/thirdparty/ogg-vorbis-decoder.min.js
new file mode 100644
index 0000000..0f030ae
--- /dev/null
+++ b/libs/thirdparty/ogg-vorbis-decoder.min.js
@@ -0,0 +1,195 @@
+/* Copyright 2021-2023 Ethan Halsall. This file is part of wasm-audio-decoders. https://github.com/eshaz/wasm-audio-decoders */
+var t,s;t=this,s=function(t,s){const i=(t,s=4294967295,i=79764919)=>{const e=new Int32Array(256);let r,n,h,o=s;for(r=0;r<256;r++){for(h=r<<24,n=8;n>0;--n)h=2147483648&h?h<<1^i:h<<1;e[r]=h}for(r=0;r>24^t[r])];return o},e=(t,s=i)=>{const e=t=>new Uint8Array(t.length/2).map(((s,i)=>parseInt(t.substring(2*i,2*(i+1)),16))),r=t=>e(t)[0],n=new Map;[,8364,,8218,402,8222,8230,8224,8225,710,8240,352,8249,338,,381,,,8216,8217,8220,8221,8226,8211,8212,732,8482,353,8250,339,,382,376].forEach(((t,s)=>n.set(t,s)));const h=new Uint8Array(t.length);let o,a,l,c=!1,u=0,U=42,d=t.length>13&&"dynEncode"===t.substring(0,9),f=0;d&&(f=11,a=r(t.substring(9,f)),a<=1&&(f+=2,U=r(t.substring(11,f))),1===a&&(f+=8,l=(t=>new DataView(e(t).buffer).getInt32(0,!0))(t.substring(13,f))));const p=256-U;for(let i=f;i255){const t=n.get(o);t&&(o=t+127)}c&&(c=!1,o-=64),h[u++]=o0?o+p:o-U}else c=!0;const M=h.subarray(0,u);if(d&&1===a){const t=s(M);if(t!==l){const s="Decode failed crc32 validation";throw console.error("`simple-yenc`\n",s+"\n","Expected: "+l+"; Got: "+t+"\n","Visit https://github.com/eshaz/simple-yenc for more information"),Error(s)}}return M};function r(){const t=Uint8Array,s=Float32Array;r.t||Object.defineProperties(r,{t:{value:new WeakMap},u:{value(t,s){r.t.set(t,Promise.resolve(s))}},U:{value(t,s){let i=r.t.get(t);return i||(s?i=WebAssembly.compile(e(s)):(s=t.M,i=r.Y(s).then((t=>WebAssembly.compile(t)))),r.t.set(t,i)),i}},T:{value(t,i){let e=new s(i),r=0,n=0;for(;r({O:t,channelData:s,samplesDecoded:i,sampleRate:e,bitDepth:r})},v:{value(t,s,i,e,n,h){let o,a,l=[];for(o=0;o{const e=String.raw`dynEncode0114db91da9bu*ttt$#U¤¤U¤¤3yzzss|yusvuyÚ&4<054<,5T44^T44<(6U~J(44< ~A544U~6J0444545 444J0444J,4U4U
Ò7U454U4Z4U4U^/6545T4T44BU~64CU~O4U54U~5 U5T4B4Z!4U~5U5U5T4U~6U4ZTU5U5T44~4O4U2ZTU5T44Z!4B6T44U~64B6U~O44U~4O4U~54U~5 44~C4~54U~5 44~5454U4B6Ub!444~UO4U~5 U54U4ZTU#44U$464<4~B6^4<444~U~B4U~54U544~544~U5 µUä#UJUè#5TT4U0ZTTUX5U5T4T4Uà#~4OU4U $~C4~54U~5 T44$6U\!TTT4UaT4<6T4<64<Z!44~4N4<U~5 4UZ!4U±_TU#44UU6UÔ~B$544$6U\!4U6U¤#~B44Uä#~B$~64<6_TU#444U~B~6~54<Y!44<_!T4Y!4<64~444~AN44<U~6J4U5 44J4U[!U#44UO4U~54U~5 U54 7U6844J44J 4UJ4UJ04VK(44<J44<J$4U´~54U~5 4U¤~5!TTT4U$5"U5TTTTTTT4U$"4VK,U54<(6U~64<$6_!4< 64~6A54A544U~6#J(U54A4U[!44J(44#~A4U6UUU
[!4464~64_!4<64~54<6T4<4]TU5 T4Y!44~44~AN4U~54U~54U5 44J(44J UÄA!U5U#UôJU"UÔJU#UÔ"JU#U´"JT4U´ZTU5T4UôZTU5T4UDZTU5T4U$[T44~UO4U~5 UÔUô4U~U´$.U5T4UP[T4U~4~UO4U~5 U#<U#<4U~U2$.UÄUN 44 ~UO4U~5 44!~UO4U~5 4U~4~UO4U~5 44J44J(U5 44U¤~J@44Uä~J<44UD~J844U~J44U$54U$5U54U$54U1^4U1^!4U~54U~5U54U~6U4U^/65T4T4U$54U~4BU~4O4U54U~5 UU'464U'_/54UU~5T4T4U~4BU~UO4U54U~5 U54Uä~4U¤~4U~U'$!44~5U5T44\T44U<~$6U\!4U#aT4U~4U~4O4U~5 U5U5U5TTT4U$"4YTU5 4U4~C5U5 U5U5444$4~64~\TU5 4U~4U~5T4Y!44O4U~54U~54U5 4CYTU5 4Uä~4U¤~4U~4$6TU54U\!44Bæ4Bä~[!4U~4UD~4U~4U~4$6TU54U\!44B4B~[!44U<~4U4~$5 4U"U#$544"Y!454U^!44<J44<(J454U~84UN!#%'+/37?GOWgw·×÷Uä;U9$%& !"#`;r.U(r,e).then((t=>WebAssembly.instantiate(t,{}))).then((({exports:e})=>{const r=new Map(Object.entries(e)),n=r.get("puff"),h=r.get("memory").buffer,o=new t(h),a=new DataView(h);let l=r.get("__heap_base");const c=s.length,u=l;l+=4,a.setInt32(u,c,!0);const U=l;l+=c,o.set(s,U);const d=l;l+=4,a.setInt32(d,o.byteLength-l,!0),n(l,d,U,u),i(o.slice(l,l+a.getInt32(d,!0)))}))}))}}}),Object.defineProperty(this,"M",{enumerable:!0,get:()=>this.B}),this.F=(t,s,i)=>{let e=[],r=0;for(;r{const e=this.B.V(s.BYTES_PER_ELEMENT*t);return i&&this.S.add(e),{H:e,$:t,C:new s(this.B.I,e,t)}},this.free=()=>{this.S.forEach((t=>{this.B.free(t)})),this.S.clear()},this.J=t=>{const s=[],i=new Uint8Array(this.B.I);for(let e=i[t];0!==e;e=i[++t])s.push(e);return String.fromCharCode.apply(null,s)},this.P=(t,s,i,e,r,n)=>{t.push({message:s,frameLength:i,frameNumber:e,inputBytes:r,outputSamples:n})},this.instantiate=(t,s)=>(s&&r.u(t,s),this.B=new t(r).instantiate(),this.S=new Set,this.B.ready.then((()=>this)))}class n extends((()=>globalThis.Worker||s)()){constructor(t,s,i,e){r.t||new r;let n=r.t.get(i);if(!n){let t,s="text/javascript",h=`'use strict';(${""+((t,s,i)=>{let e,r,n=new Promise((t=>{r=t}));self.onmessage=({data:{id:h,command:o,data:a}})=>{let l,c=n,u={id:h};"init"===o?(Object.defineProperties(t,{D:{value:s},N:{value:i},module:{value:a.module},Z:{value:!0}}),e=new t(a.options),r()):"free"===o?e.free():"ready"===o?c=c.then((()=>e.ready)):"reset"===o?c=c.then((()=>e.reset())):(Object.assign(u,e[o](Array.isArray(a)?a.map((t=>new Uint8Array(t))):new Uint8Array(a))),l=u.channelData?u.channelData.map((t=>t.buffer)):[]),c.then((()=>self.postMessage(u,l)))}})})(${i}, ${r}, ${e})`;try{t=void 0!==process.versions.node}catch{}n=t?`data:${s};base64,${Buffer.from(h).toString("base64")}`:URL.createObjectURL(new Blob([h],{type:s})),r.t.set(i,n)}super(n,{name:s}),this.K=Number.MIN_SAFE_INTEGER,this.R=new Map,this.onmessage=({data:t})=>{const{id:s,...i}=t;this.R.get(s)(i),this.R.delete(s)},new e(r).U().then((s=>{this.G("init",{module:s,options:t})}))}async G(t,s){return new Promise((i=>{this.postMessage({command:t,id:this.K,data:s}),this.R.set(this.K++,i)}))}get ready(){return this.G("ready")}async free(){await this.G("free").finally((()=>{this.terminate()}))}async reset(){await this.G("reset")}}const h=(t,s)=>{Object.defineProperty(t,"name",{value:s})},o=Symbol,a=(()=>{const t="left",s="center",i="right";return["","front ","side ","rear "].map((e=>[[t,i],[t,i,s],[t,s,i],[s,t,i],[s]].flatMap((t=>t.map((t=>e+t)).join(", ")))))})(),l="LFE",c="monophonic (mono)",u="stereo",U="surround",d=(t,...s)=>`${[c,u,"linear "+U,"quadraphonic","5.0 "+U,"5.1 "+U,"6.1 "+U,"7.1 "+U][t-1]} (${s.join(", ")})`,f=[c,d(2,a[0][0]),d(3,a[0][2]),d(4,a[1][0],a[3][0]),d(5,a[1][2],a[3][0]),d(6,a[1][2],a[3][0],l),d(7,a[1][2],a[2][0],a[3][4],l),d(8,a[1][2],a[2][0],a[3][0],l)],p=48e3,M=44100,y=32e3,m=24e3,w=22050,g=16e3,Y=8e3,T="absoluteGranulePosition",b="bandwidth",A="bitDepth",O="bitrate",v=O+"Maximum",B=O+"Minimum",F=O+"Nominal",_="buffer",V=_+"Fullness",k="codec",S=k+"Frames",q="coupledStreamCount",H="crc",$=H+"16",C=H+"32",I="data",j="description",J="duration",x="emphasis",P="hasOpusPadding",D="header",E="isContinuedPacket",N="isCopyrighted",Z="isFirstPage",z="isHome",K="isLastPage",Q="isOriginal",R="isPrivate",G="isVbr",X="layer",L="length",W="mode",tt=W+"Extension",st="mpeg",it=st+"Version",et="numberAACFrames",rt="outputGain",nt="preSkip",ht="profile",ot=o(),at="protection",lt="segments",ct="subarray",ut="version",Ut="vorbis",dt=Ut+"Comments",ft=Ut+"Setup",pt="block",Mt=pt+"ingStrategy",yt=o(),mt=pt+"Size",wt=pt+"size0",gt=pt+"size1",Yt=o(),Tt="channel",bt=Tt+"MappingFamily",At=Tt+"MappingTable",Ot=Tt+"Mode",vt=o(),Bt=Tt+"s",Ft="copyright",_t=Ft+"Id",Vt=Ft+"IdStart",kt="frame",St=kt+"Count",qt=kt+"Length",Ht="Number",$t=kt+Ht,Ct=kt+"Padding",It=kt+"Size",jt="Rate",Jt="inputSample"+jt,xt="page",Pt=xt+"Checksum",Dt=o(),Et=xt+"SegmentTable",Nt=xt+"Sequence"+Ht,Zt="sample",zt=Zt+Ht,Kt=Zt+jt,Qt=o(),Rt=Zt+"s",Gt="stream",Xt=Gt+"Count",Lt=Gt+"Info",Wt=Gt+"Serial"+Ht,ts=Gt+"StructureVersion",ss="total",is=ss+"BytesOut",es=ss+"Duration",rs=ss+"Samples",ns=o(),hs=o(),os=o(),as=o(),ls=o(),cs=o(),us=o(),Us=o(),ds=o(),fs=o(),ps=o(),Ms=o(),ys=o(),ms=o(),ws=o(),gs=o(),Ys=o(),Ts=o(),bs=Uint8Array,As=DataView,Os="reserved",vs="bad",Bs="free",Fs="none",_s="16bit CRC",Vs=(t,s,i)=>{for(let e=0;e0;t--)r=i(r);t[e]=r}return t},ks=Vs(new bs(256),(t=>t),(t=>128&t?7^t<<1:t<<1)),Ss=[Vs(new Uint16Array(256),(t=>t<<8),(t=>t<<1^(32768&t?32773:0)))],qs=[Vs(new Uint32Array(256),(t=>t),(t=>t>>>1^3988292384*(1&t)))];for(let Ye=0;Ye<15;Ye++){Ss.push(new Uint16Array(256)),qs.push(new Uint32Array(256));for(let t=0;t<=255;t++)Ss[Ye+1][t]=Ss[0][Ss[Ye][t]>>>8]^Ss[Ye][t]<<8,qs[Ye+1][t]=qs[Ye][t]>>>8^qs[0][255&qs[Ye][t]]}const Hs=t=>{const s=t[L],i=s-16;let e=0,r=0;for(;r<=i;)e=qs[15][255&(t[r++]^e)]^qs[14][255&(t[r++]^e>>>8)]^qs[13][255&(t[r++]^e>>>16)]^qs[12][t[r++]^e>>>24]^qs[11][t[r++]]^qs[10][t[r++]]^qs[9][t[r++]]^qs[8][t[r++]]^qs[7][t[r++]]^qs[6][t[r++]]^qs[5][t[r++]]^qs[4][t[r++]]^qs[3][t[r++]]^qs[2][t[r++]]^qs[1][t[r++]]^qs[0][t[r++]];for(;r!==s;)e=qs[0][255&(e^t[r++])]^e>>>8;return~e},$s=(...t)=>{const s=new bs(t.reduce(((t,s)=>t+s[L]),0));return t.reduce(((t,i)=>(s.set(i,t),t+i[L])),0),s},Cs=t=>String.fromCharCode(...t),Is=[0,8,4,12,2,10,6,14,1,9,5,13,3,11,7,15],js=t=>Is[15&t]<<4|Is[t>>4];class Js{constructor(t){this.X=t,this.L=8*t[L]}set position(t){this.L=t}get position(){return this.L}read(t){const s=Math.floor(this.L/8),i=this.L%8;return this.L-=t,(js(this.X[s-1])<<8)+js(this.X[s])>>7-i&255}}class xs{constructor(t,s){this.W=t,this.tt=s,this[ws]()}[gs](){this.st=!0}[ws](){this.it=new Map,this.et=new WeakMap,this.rt=!1,this.nt=!1,this.ht=null,this.st=!1}[ms](t,s){if(this.tt){this.ht!==t&&(this.ht=t,this.nt=!0);const i=this.et.get(this.it.get(this.ot));this.nt&&i&&this.tt({lt:t,...i},s),this.nt=!1}}[ds](t){const s=this.it.get(t);return s&&this.ct(t),s}[fs](t,s,i){this.st&&(this.rt||(this.W({...s}),this.rt=!0),this.ct(t),this.it.set(t,s),this.et.set(s,i))}ct(t){this.tt&&t!==this.ot&&(this.nt=!0,this.ot=t)}}const Ps=new WeakMap,Ds=new WeakMap;class Es{constructor(t,s){this.ut=t,this.it=s}*[us](){let t;for(;;){if(t=yield*this.Ut[ps](this.ut,this.it,0),t)return t;this.ut[hs](1)}}*[Us](t){let s=yield*this[us]();const i=Ds.get(s)[L];if(t||this.ut.dt||(yield*this.ft[ds](this.ut,this.it,i)))return this.it[gs](),this.ut[hs](i),this.ut[as](s),s;this.ut[ls](`Missing ${kt} at ${i} bytes from current position.`,`Dropping current ${kt} and trying again.`),this.it[ws](),this.ut[hs](1)}}class Ns{constructor(t,s){Ds.set(this,{[D]:t}),this[I]=s}}class Zs extends Ns{static*[ps](t,s,i,e,r){const n=yield*t[ds](i,e,r);if(n){const t=Ps.get(n)[qt],e=Ps.get(n)[Rt];return new s(n,(yield*i[ns](t,r))[ct](0,t),e)}return null}constructor(t,s,i){super(t,s),this[D]=t,this[Rt]=i,this[J]=i/t[Kt]*1e3,this[$t]=null,this[is]=null,this[rs]=null,this[es]=null,Ds.get(this)[L]=s[L]}}const zs="unsynchronizationFlag",Ks="extendedHeaderFlag",Qs="experimentalFlag",Rs="footerPresent";class Gs{static*Mt(t,s,i){const e={};let r=yield*t[ns](3,i);if(73!==r[0]||68!==r[1]||51!==r[2])return null;if(r=yield*t[ns](10,i),e[ut]=`id3v2.${r[3]}.${r[4]}`,15&r[5])return null;if(e[zs]=!!(128&r[5]),e[Ks]=!!(64&r[5]),e[Qs]=!!(32&r[5]),e[Rs]=!!(16&r[5]),128&r[6]||128&r[7]||128&r[8]||128&r[9])return null;const n=r[6]<<21|r[7]<<14|r[8]<<7|r[9];return e[L]=10+n,new Gs(e)}constructor(t){this[ut]=t[ut],this[zs]=t[zs],this[Ks]=t[Ks],this[Qs]=t[Qs],this[Rs]=t[Rs],this[L]=t[L]}}class Xs{constructor(t){Ps.set(this,t),this[A]=t[A],this[O]=null,this[Bt]=t[Bt],this[Ot]=t[Ot],this[Kt]=t[Kt]}}const Ls={0:[Bs,Bs,Bs,Bs,Bs],16:[32,32,32,32,8],240:[vs,vs,vs,vs,vs]},Ws=(t,s,i)=>8*((t+i)%s+s)*(1<<(t+i)/s)-8*s*(s/8|0);for(let Ye=2;Ye<15;Ye++)Ls[Ye<<4]=[32*Ye,Ws(Ye,4,0),Ws(Ye,4,-1),Ws(Ye,8,4),Ws(Ye,8,0)];const ti="bands ",si=" to 31",ii={0:ti+4+si,16:ti+8+si,32:ti+12+si,48:ti+16+si},ei="bitrateIndex",ri="v2",ni="v1",hi="Intensity stereo ",oi=", MS stereo ",ai="on",li="off",ci={0:hi+li+oi+li,16:hi+ai+oi+li,32:hi+li+oi+ai,48:hi+ai+oi+ai},ui={0:{[j]:Os},2:{[j]:"Layer III",[Ct]:1,[tt]:ci,[ni]:{[ei]:2,[Rt]:1152},[ri]:{[ei]:4,[Rt]:576}},4:{[j]:"Layer II",[Ct]:1,[tt]:ii,[Rt]:1152,[ni]:{[ei]:1},[ri]:{[ei]:4}},6:{[j]:"Layer I",[Ct]:4,[tt]:ii,[Rt]:384,[ni]:{[ei]:0},[ri]:{[ei]:3}}},Ui="MPEG Version ",di="ISO/IEC ",fi={0:{[j]:Ui+"2.5 (later extension of MPEG 2)",[X]:ri,[Kt]:{0:11025,4:12e3,8:Y,12:Os}},8:{[j]:Os},16:{[j]:`${Ui}2 (${di}13818-3)`,[X]:ri,[Kt]:{0:w,4:m,8:g,12:Os}},24:{[j]:`${Ui}1 (${di}11172-3)`,[X]:ni,[Kt]:{0:M,4:p,8:y,12:Os}},length:L},pi={0:_s,1:Fs},Mi={0:Fs,1:"50/15 ms",2:Os,3:"CCIT J.17"},yi={0:{[Bt]:2,[j]:u},64:{[Bt]:2,[j]:"joint "+u},128:{[Bt]:2,[j]:"dual channel"},192:{[Bt]:1,[j]:c}};class mi extends Xs{static*[ds](t,s,i){const e={},r=yield*Gs.Mt(t,s,i);r&&(yield*t[ns](r[L],i),t[hs](r[L]));const n=yield*t[ns](4,i),h=Cs(n[ct](0,4)),o=s[ds](h);if(o)return new mi(o);if(255!==n[0]||n[1]<224)return null;const a=fi[24&n[1]];if(a[j]===Os)return null;const l=6&n[1];if(ui[l][j]===Os)return null;const c={...ui[l],...ui[l][a[X]]};if(e[it]=a[j],e[X]=c[j],e[Rt]=c[Rt],e[at]=pi[1&n[1]],e[L]=4,e[O]=Ls[240&n[2]][c[ei]],e[O]===vs)return null;if(e[Kt]=a[Kt][12&n[2]],e[Kt]===Os)return null;if(e[Ct]=2&n[2]&&c[Ct],e[R]=!!(1&n[2]),e[qt]=Math.floor(125*e[O]*e[Rt]/e[Kt]+e[Ct]),!e[qt])return null;const u=192&n[3];if(e[Ot]=yi[u][j],e[Bt]=yi[u][Bt],e[tt]=c[tt][48&n[3]],e[N]=!!(8&n[3]),e[Q]=!!(4&n[3]),e[x]=Mi[3&n[3]],e[x]===Os)return null;e[A]=16;{const{length:t,frameLength:i,yt:r,...n}=e;s[fs](h,e,n)}return new mi(e)}constructor(t){super(t),this[O]=t[O],this[x]=t[x],this[Ct]=t[Ct],this[N]=t[N],this[Q]=t[Q],this[R]=t[R],this[X]=t[X],this[tt]=t[tt],this[it]=t[it],this[at]=t[at]}}class wi extends Zs{static*[ps](t,s,i){return yield*super[ps](mi,wi,t,s,i)}constructor(t,s,i){super(t,s,i)}}class gi extends Es{constructor(t,s,i){super(t,s),this.Ut=wi,this.ft=mi,i(this[k])}get[k](){return st}*[Ms](){return yield*this[Us]()}}const Yi={0:"MPEG-4",8:"MPEG-2"},Ti={0:"valid",2:vs,4:vs,6:vs},bi={0:_s,1:Fs},Ai={0:"AAC Main",64:"AAC LC (Low Complexity)",128:"AAC SSR (Scalable Sample Rate)",192:"AAC LTP (Long Term Prediction)"},Oi={0:96e3,4:88200,8:64e3,12:p,16:M,20:y,24:m,28:w,32:g,36:12e3,40:11025,44:Y,48:7350,52:Os,56:Os,60:"frequency is written explicitly"},vi={0:{[Bt]:0,[j]:"Defined in AOT Specific Config"},64:{[Bt]:1,[j]:c},128:{[Bt]:2,[j]:d(2,a[0][0])},192:{[Bt]:3,[j]:d(3,a[1][3])},256:{[Bt]:4,[j]:d(4,a[1][3],a[3][4])},320:{[Bt]:5,[j]:d(5,a[1][3],a[3][0])},384:{[Bt]:6,[j]:d(6,a[1][3],a[3][0],l)},448:{[Bt]:8,[j]:d(8,a[1][3],a[2][0],a[3][0],l)}};class Bi extends Xs{static*[ds](t,s,i){const e={},r=yield*t[ns](7,i),n=Cs([r[0],r[1],r[2],252&r[3]|3&r[6]]),h=s[ds](n);if(h)Object.assign(e,h);else{if(255!==r[0]||r[1]<240)return null;if(e[it]=Yi[8&r[1]],e[X]=Ti[6&r[1]],e[X]===vs)return null;const t=1&r[1];e[at]=bi[t],e[L]=t?7:9,e[ot]=192&r[2],e[Qt]=60&r[2];const i=2&r[2];if(e[ht]=Ai[e[ot]],e[Kt]=Oi[e[Qt]],e[Kt]===Os)return null;e[R]=!!i,e[vt]=448&(r[2]<<8|r[3]),e[Ot]=vi[e[vt]][j],e[Bt]=vi[e[vt]][Bt],e[Q]=!!(32&r[3]),e[z]=!!(8&r[3]),e[_t]=!!(8&r[3]),e[Vt]=!!(4&r[3]),e[A]=16,e[Rt]=1024,e[et]=3&r[6];{const{length:t,wt:i,gt:r,Yt:h,frameLength:o,yt:a,Tt:l,...c}=e;s[fs](n,e,c)}}if(e[qt]=8191&(r[3]<<11|r[4]<<3|r[5]>>5),!e[qt])return null;const o=2047&(r[5]<<6|r[6]>>2);return e[V]=2047===o?"VBR":o,new Bi(e)}constructor(t){super(t),this[_t]=t[_t],this[Vt]=t[Vt],this[V]=t[V],this[z]=t[z],this[Q]=t[Q],this[R]=t[R],this[X]=t[X],this[L]=t[L],this[it]=t[it],this[et]=t[et],this[ht]=t[ht],this[at]=t[at]}get bt(){const t=Ps.get(this),s=t[ot]+64<<5|t[Qt]<<5|t[vt]>>3,i=new bs(2);return new As(i[_]).setUint16(0,s,!1),i}}class Fi extends Zs{static*[ps](t,s,i){return yield*super[ps](Bi,Fi,t,s,i)}constructor(t,s,i){super(t,s,i)}}class _i extends Es{constructor(t,s,i){super(t,s),this.Ut=Fi,this.ft=Bi,i(this[k])}get[k](){return"aac"}*[Ms](){return yield*this[Us]()}}class Vi extends Zs{static At(t){return(t[t[L]-2]<<8)+t[t[L]-1]}static[Ts](t){const s=Vi.At(t),i=(t=>{const s=t[L],i=s-16;let e=0,r=0;for(;r<=i;)e^=t[r++]<<8|t[r++],e=Ss[15][e>>8]^Ss[14][255&e]^Ss[13][t[r++]]^Ss[12][t[r++]]^Ss[11][t[r++]]^Ss[10][t[r++]]^Ss[9][t[r++]]^Ss[8][t[r++]]^Ss[7][t[r++]]^Ss[6][t[r++]]^Ss[5][t[r++]]^Ss[4][t[r++]]^Ss[3][t[r++]]^Ss[2][t[r++]]^Ss[1][t[r++]]^Ss[0][t[r++]];for(;r!==s;)e=(255&e)<<8^Ss[0][e>>8^t[r++]];return e})(t[ct](0,-2));return s===i}constructor(t,s,i){s[Lt]=i,s[$]=Vi.At(t),super(s,t,Ps.get(s)[Rt])}}const ki="get from STREAMINFO metadata block",Si={0:"Fixed",1:"Variable"},qi={0:Os,16:192};for(let Ye=2;Ye<16;Ye++)qi[Ye<<4]=Ye<6?576*2**(Ye-2):2**Ye;const Hi={0:ki,1:88200,2:176400,3:192e3,4:Y,5:g,6:w,7:m,8:y,9:M,10:p,11:96e3,15:vs},$i={0:{[Bt]:1,[j]:c},16:{[Bt]:2,[j]:d(2,a[0][0])},32:{[Bt]:3,[j]:d(3,a[0][1])},48:{[Bt]:4,[j]:d(4,a[1][0],a[3][0])},64:{[Bt]:5,[j]:d(5,a[1][1],a[3][0])},80:{[Bt]:6,[j]:d(6,a[1][1],l,a[3][0])},96:{[Bt]:7,[j]:d(7,a[1][1],l,a[3][4],a[2][0])},112:{[Bt]:8,[j]:d(8,a[1][1],l,a[3][0],a[2][0])},128:{[Bt]:2,[j]:u+" (left, diff)"},144:{[Bt]:2,[j]:u+" (diff, right)"},160:{[Bt]:2,[j]:u+" (avg, diff)"},176:Os,192:Os,208:Os,224:Os,240:Os},Ci={0:ki,2:8,4:12,6:Os,8:16,10:20,12:24,14:Os};class Ii extends Xs{static Ot(t){if(t[0]>254)return null;if(t[0]<128)return{value:t[0],length:1};let s=1;for(let n=64;n&t[0];n>>=1)s++;let i=s-1,e=0,r=0;for(;i>0;r+=6,i--){if(128!=(192&t[i]))return null;e|=(63&t[i])<>s)<{let s=0;const i=t[L];for(let e=0;e!==i;e++)s=ks[s^t[e]];return s})(e[ct](0,r[L]-1)))return null;if(!h){const{vt:t,frameNumber:i,Bt:e,yt:h,Yt:o,Ft:a,_t:l,length:c,...u}=r;s[fs](n,r,u)}return new Ii(r)}constructor(t){super(t),this[$]=null,this[Mt]=t[Mt],this[mt]=t[mt],this[$t]=t[$t],this[zt]=t[zt],this[Lt]=null}}class ji extends Es{constructor(t,s,i){super(t,s),this.Ut=Vi,this.ft=Ii,i(this[k])}get[k](){return"flac"}*Vt(t){const s=yield*this.ut[ns](2,0),i=s[L]-2;for(;t{const s=Ii[Ys](t,this.it);if(s)return new Vi(t,s,this.kt);this.ut[ls]("Failed to parse Ogg FLAC frame","Skipping invalid FLAC frame")})).filter((t=>!!t))),t}}class Ji{static*[ds](t,s,i){const e={};let r=yield*t[ns](28,i);if(79!==r[0]||103!==r[1]||103!==r[2]||83!==r[3])return null;if(e[ts]=r[4],248&r[5])return null;e[K]=!!(4&r[5]),e[Z]=!!(2&r[5]),e[E]=!!(1&r[5]);const n=new As(bs.from(r[ct](0,28))[_]);e[T]=(t=>{try{return t.getBigInt64(6,!0)}catch{const s=128&t.getUint8(13)?-1:1;let i=t.getUint32(6,!0),e=t.getUint32(10,!0);return-1===s&&(i=1+~i,e=1+~e),e>1048575&&console.warn("This platform does not support BigInt"),s*(i+e*2**32)}})(n),e[Wt]=n.getInt32(14,!0),e[Nt]=n.getInt32(18,!0),e[Pt]=n.getInt32(22,!0);const h=r[26];e[L]=h+27,r=yield*t[ns](e[L],i),e[qt]=0,e[Et]=[],e[Dt]=bs.from(r[ct](27,e[L]));for(let o=0,a=0;o{const s=Li[Ys](this.Ht,t,this.it);if(s){null===this.$t&&(this.$t=s[nt]);let i=s[It]*s[St]/1e3*s[Kt];return this.$t>0&&(this.$t-=i,i=this.$t<0?-this.$t:0),new Pi(t,s,i)}this.ut[cs]("Failed to parse Ogg Opus Header","Not a valid Ogg Opus file")}))),t}}class te extends Zs{constructor(t,s,i){super(s,t,i)}}const se={};for(let Ye=0;Ye<8;Ye++)se[Ye+6]=2**(6+Ye);class ie extends Xs{static[Ys](t,s,i,e){if(t[L]<30)throw Error("Out of data while inside an Ogg Page");const r=Cs(t[ct](0,30)),n=s[ds](r);if(n)return new ie(n);const h={[L]:30};if("vorbis"!==r.substr(0,7))return null;h[I]=bs.from(t[ct](0,30));const o=new As(h[I][_]);if(h[ut]=o.getUint32(7,!0),0!==h[ut])return null;if(h[Bt]=t[11],h[Ot]=f[h[Bt]-1]||"application defined",h[Kt]=o.getUint32(12,!0),h[v]=o.getInt32(16,!0),h[F]=o.getInt32(20,!0),h[B]=o.getInt32(24,!0),h[gt]=se[(240&t[28])>>4],h[wt]=se[15&t[28]],h[wt]>h[gt])return null;if(1!==t[29])return null;h[A]=32,h[ft]=e,h[dt]=i;{const{length:t,data:i,version:e,Ct:n,It:o,...a}=h;s[fs](r,h,a)}return new ie(h)}constructor(t){super(t),this[v]=t[v],this[B]=t[B],this[F]=t[F],this[wt]=t[wt],this[gt]=t[gt],this[I]=t[I],this[dt]=t[dt],this[ft]=t[ft]}}class ee extends Es{constructor(t,s,i){super(t,s),this.Ut=te,i(this[k]),this.Ht=null,this.jt=!1,this.Jt=null}get[k](){return Ut}[ys](t){t[S]=[];for(const s of Ds.get(t)[lt])if(1===s[0])this.it[gs](),this.Ht=t[I],this.jt=!1;else if(3===s[0])this.xt=s;else if(5===s[0])this.Pt=s,this.Dt=this.Et(s),this.jt=!0;else if(this.jt){const i=ie[Ys](this.Ht,this.it,this.xt,this.Pt);i?t[S].push(new te(s,i,this.Nt(s,i))):this.ut[logError]("Failed to parse Ogg Vorbis Header","Not a valid Ogg Vorbis file")}return t}Nt(t,s){const i=this.Dt.Zt[t[0]>>1&this.Dt.mask]?s[gt]:s[wt],e=null===this.Jt?0:(this.Jt+i)/4;return this.Jt=i,e}Et(t){const s=new Js(t),i={count:0,Zt:[]};for(;1&~s.read(1););let e;for(;i.count<64&&s.position>0;){js(s.read(8));let t=0;for(;0===s.read(8)&&t++<3;);if(4!==t){1+((126&js(e))>>1)!==i.count&&this.ut[ls]("vorbis derived mode count did not match actual mode count");break}e=s.read(7),i.Zt.unshift(1&e),s.position+=6,i.count++}return i.mask=(1<1&&t[Nt]>1&&this.ut[ls]("Unexpected gap in Ogg Page Sequence Number.",`Expected: ${this.ss+1}, Got: ${t[Nt]}`),this.ss=t[Nt]}es(t){null===this.Rt&&(this.ss=t[Nt],this.Rt=this.Wt(t)),this.ts(t);const s=Ds.get(t),i=Ps.get(s[D]);let e=0;if(s[lt]=i[Et].map((s=>t[I][ct](e,e+=s))),this.Kt[L]&&(s[lt][0]=$s(this.Kt,s[lt][0]),this.Kt=new bs),255===i[Dt][i[Dt][L]-1]&&(this.Kt=$s(this.Kt,s[lt].pop())),null!==this.Gt&&(t[Rt]=Number(t[T]-this.Gt)),this.Gt=t[T],this.Rt){const s=this.Lt[ys](t);return this.ut[as](s),s}return t}}class ne extends Es{constructor(t,s,i){super(t,s),this.zt=i,this.Ut=xi,this.ft=Ji,this.rs=new Map,this.ns=null}get[k](){const t=this.rs.get(this.ns);return t?t.hs:""}*[Ms](){const t=yield*this[Us](!0);this.ns=t[Wt];let s=this.rs.get(this.ns);return s||(s=new re(this.ut,this.it,this.zt),this.rs.set(this.ns,s)),t[K]&&this.rs.delete(this.ns),s.es(t)}}const he=()=>{};class oe{constructor(t,{os:s,ls:i,cs:e,us:r=!1,Us:n=!0}={}){this.ds=t,this.zt=s||he,this.W=i||he,this.tt=e,this.fs=r,this.ps=n?Hs:he,this[ws]()}get[k](){return this.Lt?this.Lt[k]:""}[ws](){this.it=new xs(this.W,this.tt),this.Ms=this.ys(),this.Ms.next()}*flush(){this.dt=!0;for(let t=this.Ms.next();t.value;t=this.Ms.next())yield t.value;this.dt=!1,this[ws]()}*ws(t){for(let s=this.Ms.next(t);s.value;s=this.Ms.next())yield s.value}parseAll(t){return[...this.ws(t),...this.flush()]}*ys(){if(this.ds.match(/aac/))this.Lt=new _i(this,this.it,this.zt);else if(this.ds.match(/mpeg/))this.Lt=new gi(this,this.it,this.zt);else if(this.ds.match(/flac/))this.Lt=new ji(this,this.it,this.zt);else{if(!this.ds.match(/ogg/))throw Error("Unsupported Codec "+mimeType);this.Lt=new ne(this,this.it,this.zt)}for(this.gs=0,this.Ys=0,this.Ts=0,this.bs=0,this.As=0,this.Os=void 0,this.vs=new Uint8Array(0);;){const t=yield*this.Lt[Ms]();t&&(yield t)}}*[ns](t=0,s=0){let i;for(;this.vs[L]<=t+s;){if(i=yield,this.dt)return this.vs[ct](s);i&&(this.Ts+=i[L],this.vs=$s(this.vs,i))}return this.vs[ct](s)}[hs](t){this.Ys+=t,this.vs=this.vs[ct](t)}[os](t){this.Os=t[D][Kt],t[D][O]=t[J]>0?8*Math.round(t[I][L]/t[J]):0,t[$t]=this.gs++,t[is]=this.bs,t[rs]=this.As,t[es]=this.As/this.Os*1e3,t[C]=this.ps(t[I]),this.it[ms](t[D][O],t[es]),this.bs+=t[I][L],this.As+=t[Rt]}[as](t){if(t[S]){if(t[K]){let s=t[Rt];t[S].forEach((t=>{const i=t[Rt];s0?s:0,t[J]=t[Rt]/t[D][Kt]*1e3),s-=i,this[os](t)}))}else t[Rt]=0,t[S].forEach((s=>{t[Rt]+=s[Rt],this[os](s)}));t[J]=t[Rt]/this.Os*1e3||0,t[rs]=this.As,t[es]=this.As/this.Os*1e3||0,t[is]=this.bs}else this[os](t)}Bs(t,s){if(this.fs){const i=[`${k}: ${this[k]}`,"inputMimeType: "+this.ds,"readPosition: "+this.Ys,"totalBytesIn: "+this.Ts,`${is}: ${this.bs}`],e=Math.max(...i.map((t=>t[L])));s.push("--stats--"+"-".repeat(e-9),...i,"-".repeat(e)),t("codec-parser",s.reduce(((t,s)=>t+"\n "+s),""))}}[ls](...t){this.Bs(console.warn,t)}[cs](...t){this.Bs(console.error,t)}}const ae=S,le=I,ce=D,ue=K,Ue=dt,de=ft,fe=rs;function pe(t){function s(){}for(var i=new Uint8Array(123),e=25;e>=0;--e)i[48+e]=52+e,i[65+e]=e,i[97+e]=26+e;var r,n;i[43]=62,i[47]=63,pe.M||Object.defineProperty(pe,"M",{get:()=>String.raw`dynEncode01a33fc84f8dïoØå§ä³¨s¢þéõ?§æQ¬·ñì>_åè£Mí'
ËÏÊí çåzmòeúaݧ¢é,î= 9z
ó¡= $.JõT¬K'¨®ç äÓ·ßéàäà(u¾Ã÷¯ÃìÍ H¶3KQtí;Çø=}ÉóX=}Çã»°£)½SÉVy{oEqûUHhéì8÷7ó[¼iÖ¨A2º»È(ä+Ú»Ðé*7ç}ìÏÖ@ü¿À¿B;?=}A?>ýÿûüÿ~{xÎ#ë5X.]J
+=Mi=M°UH
+5⪱ÀéOmrn¿¯2Ljª{ ÝájÔÖ ±Û©bÕé)j{èüül8üàJr/¡¨²Ýþ^UÜàÈO6Ü
jÙ5èâ×að1ºHH=M2Û6íÊóI̧[TÜïÚÉ) ÁW|âßHeF,l Ì¥'0Äb8ÏKßè!eJ
+vÑz& WrnV"5Ê ñ ýkwP4Ãp¨¸RAx[p¼Ïó;7>ÃÑþ¨VU?°Rq9~òQÚwI=} fòÔ·rñ¾ª¸gðx7QE5-±®MßÂãl?£ÁãÃE óØ{ËÒÂÌ@µz5fñ}.;¾ê%Mi_³ZU@å.Éñî¾ÞmÄt×¢.,ä²BB;æ¤äûûZ_¡V)ªAUµ¾BfÈé Ò&§¦$¢»ôåÀk£z(_zÜ^r>ï ¾b>Áð/ªÄDTçQlÄIÒ°Q}:8_þ!@ßvñ!Oö
+\\ebVpȱÖ~\¥NÐ'eBb·#ÈN¥Y ßà#W´0a]¼!þ½\nרT¿¿¶çÉSîäx7óÎ6ñI-ììùpfåh¸Çú,cµÔeiÂeicÓÂç#ê²up¹aÛÝb0¼þ7Ü>F3ÞÔTþñfkï±bxööfÙ±
6HÎÊß6 Ò°ÂyV¶Á?»@?{¨Q¥+=}¥±ÿÔÌá9%û!>Âì&¸Õ@ÓUùq÷?ñqt¿çIU+÷gy+5sä
+¼¬åíGÖ®S1K;
B\©fhXd)ºÐ¿²Uw ûûX15°Ò1LÁ-;j= piN:}îºB¯ÅÉwXtô§¶¸3y¶¯oJáàL¸jÎn®În -¸ýûÄàsT½ÎòÓÄes ´{OsèÚÎþ´Çå9SekFTV³úK-÷WE¾OÔ
+µR½ø*ÙvVèJ°§¼Å¤ªàCsr²^Õvü3ããÔ¯/´ Poü|$RÞ§KuÉ#þ [ªß{¦ÑVú>ý>Ôws~~9=Mz¶-Úhiò>ñ²1düÿ!ü>ý>í¾¿ñèµÀ /«~yæ¨Êwórb0©ì! ~°»Ïøj§Ý#ß88÷AlÛ¦3¹ÇS8oK:xÜ×'dAkÉÜ<É;)3ÀbÐ{í«Û5?þ
+ÈNøRÙá¾¹/+ß>Û¾6åô}mzQ|p÷M¼ðjÑí©;2½&Ì#g×g|/[k*Zõ8ZvãXçàFª¯a*÷«ª+V,\¨rÏâ'É:G-àëW£óÿî8rpÿ ]k=Mîéû|]´$Î"îáVìD_d%~m¢>aj%U6¨^8"b ]¥®}lìïèÈfõlÔÖçÝÜIÃqÜ;ñ°[ÙåTàÆä>í÷õ{¯oí½3*iúD¿gÔæÁ@sÙ ÑèÚ=MÉkáÑüçuêÕÙðw¨ À³Fô~{ï_µ9Ѭ5,}í5×0ÿ>_6l*{îò)¯GjE7(aôrÃbôÚjǽ T°ÜÃÄgk;ß_ßÂÖûÄRZðùÒ¸§=MX*gê[ÉXÚ©^uN~u~®
+:Õ_NøWëP\^WpÀttØ÷2ÿ2wTØï2þ2v6y6;VÌÛI÷?ªê̶^&>&í£F]VBf¨Tße|þîõ¹ù±úÁ$]ö wáyÏV.îbÁÛÆ.Þð¡ØÛ ïtnZ$þ:KÌòñÓð?«»
±lâ¶
+SÓÿZ·©'7
+s%»4äcL+øÈ{
+^ÑKCU¨n9ðÑ~g³/rÓV$
+[cÉ6 &(¿ôqðx úÆ6 ÞYSÇO×Èò{-L;áèÚÆUhk(öyÄè7´Þ1CY¤Dèé×40,ä$Em9¦S£"¨üÇkUô¹Ë UgÎ{>%[2\ösiUîçÓ.À¨ãôÂÏûÇ~që¤
+$¼À&*ãhæM#Ïî8å#ûûU@·I§aÂú[Hc°c¥öém¶«è䪪#÷ñg;ß¾óº/9í? g~ïB9¨'Süß.),gi±Æèzåëf¹,Èâ^k¿|Ð= ÿÉUvî©ñÚÍÖÙ"&|ª[Å¢lyD¸ÖÏñI´QCÑWõÈà°zÈ2_Ǹß(ËÒ¹pi}çkUÌ-PV$MÍ)}éD×q¹{¤aä.|í+/ýºIë¸××I¥^bü½ö?Ñ/ưuCH¥g±|¹MÞ#L²ææûºÿ'îA-÷B¿7<ÞÔ9ì&Ô¢fÓ1EãÈ/ cE%5ÙO£.uK~¨¸;Ëíô°ÿu7uRö¦×³
®= °~£30ÈöpIìxû)þÏXËyeyo I%Ùý°ðà8Kð!9¡C£'Ý Y0¶±Ú}îùÛÆze"ߦ[ÌM
÷qA?¬;QWetbW¬ýÛ)aWet+*¾j¥h8Î
+ÉëÎ
+~øqù|ô*= DÑW©â
+q'$iÇùçÆ®sç4|¶¢USæK|cÅÀ(46?µ#ËM0÷rYNAP÷r¦á«Ò×{²¶ÁØäpg´eÂÝ|¸ìH=MïmÿOn@óå+(÷ÐMI3ìñÈóåÓz*^,áÿJ²Úz* [Òíxê|fpûÂûûBf4þs*þs*ö [ñÂbG²ÐnjÄ%Àßñ«Zù\è¬è K-ÚÈ®Û×ÎVyT´1bØüJÅZÕüJÅÚ=}<ó´nul/6|@{æÔî½àb|é ª³½wTAª³uêÀ.¸NvÎæSUL-÷hrH7ÙV
+VÕ-pL¿ã.PÒ¿êÃÿqÎÁEk
ܦÙÇéÙ²l¥(t³pOYúHpcÖ¸óæÞy5½¶ÎÕ9ȳ³²ô³2§'6´É»_9É^¿Ï«;ÙËa&rbf±_ZØÀª%#Îh?Ã;zÀVj¿2lúêGÂ^hì
+ÊÀþßðTGximü1Oå®&¥ïßµecË/9/ÍNÍê¤MÎü´M
+]Fökj®òJ¤C©K'îO§GiÆb6ô¡ØfÒéþh°¶À= µfaGHߵѬÃàÖO¥*Ýh·s-#ýtúø*³D¡S6(t,ÀF0(´¡¿n,ÙádýY@²íÛâÀnhé9ÿ{~@øJèT\VåÔOó¢üdrí¦ür
+¨&
+ÝJB¸V%trQóÓOVåâ SBi¾ÿÚçÜÄ6OLi.p·Å(ÕxD¨
+D¨¼¬Øª¼L9¯¨ÌÓn¤°BªbêtÓ«óÚ;[K°èî¦AÀÎ0ý'ð§|ÌÒÌ÷´rq½óĵazûû8m´Ê/V:È&®¬ØÌZ&Uk£r¿Ãî9>ÊRrѤçÅz"ÈBw&!Aúÿüd&ù¤º¤ûë©ÿ?þlâSwÉ£kl¾2Â9²bÏáz«®k(Ȫ-ÐgýuäÆªaß÷Ðî5A3*®ÖÖ»·GV@øb1r#éof:&z:ryG~qbf ÜV\Q°%¿¦cåþ¤6á0n"ÕaÕ:¬®{ $îN³ºüÜ~=}Ä6¬ÁÛÏÓ¥Y¬ÆmÝÜÀ,ØAà64æ0kÐÇiL#=MMôk%9ÿ[þ|Ä[Á<