polyfill & kill bug

This commit is contained in:
unamed 2022-02-01 22:22:52 +08:00
parent 01fbd7647c
commit 4a801cbc85
5 changed files with 354 additions and 340 deletions

View File

@ -189,6 +189,7 @@
</div> </div>
</div> </div>
<!-- injection --> <!-- injection -->
<script src='libs/thirdparty/browser-polyfill.min.js'></script>
<script src='libs/thirdparty/lz-string.min.js'></script> <script src='libs/thirdparty/lz-string.min.js'></script>
<script src='libs/thirdparty/priority-queue.min.js'></script> <script src='libs/thirdparty/priority-queue.min.js'></script>
<script src='libs/thirdparty/localforage.min.js'></script> <script src='libs/thirdparty/localforage.min.js'></script>

View File

@ -2,7 +2,7 @@
"use strict"; "use strict";
function events() { function events () {
this._init(); this._init();
} }
@ -61,7 +61,7 @@ events.prototype._startGame_start = function (hard, seed, route, callback) {
core.dom.enlargeBtn.style.display = 'block'; core.dom.enlargeBtn.style.display = 'block';
core.push(todo, core.firstData.startCanvas); core.push(todo, core.firstData.startCanvas);
} }
core.push(todo, {"type": "function", "function": "function() { core.events._startGame_setHard(); }"}) core.push(todo, { "type": "function", "function": "function() { core.events._startGame_setHard(); }" })
core.push(todo, core.firstData.startText); core.push(todo, core.firstData.startText);
this.insertAction(todo, null, null, function () { this.insertAction(todo, null, null, function () {
core.events._startGame_afterStart(callback); core.events._startGame_afterStart(callback);
@ -78,7 +78,7 @@ events.prototype._startGame_setHard = function () {
main.levelChoose.forEach(function (one) { main.levelChoose.forEach(function (one) {
if (one.name == core.status.hard) { if (one.name == core.status.hard) {
hardValue = one.hard; hardValue = one.hard;
hardColor = core.arrayToRGBA(one.color || [255,0,0,1]); hardColor = core.arrayToRGBA(one.color || [255, 0, 0, 1]);
core.insertAction(one.action); core.insertAction(one.action);
} }
}); });
@ -162,8 +162,8 @@ events.prototype._gameOver_confirmUpload = function (ending, norank) {
else { else {
var id = core.getCookie('id') || ""; var id = core.getCookie('id') || "";
var hint = "请输入你的ID\n登录状态下输入数字用户编号可成为蓝名成绩并计入用户通关数"; var hint = "请输入你的ID\n登录状态下输入数字用户编号可成为蓝名成绩并计入用户通关数";
if (id) hint = "请输入你的ID\n输入数字用户编号"+id+ "可成为蓝名成绩并计入用户通关数)"; if (id) hint = "请输入你的ID\n输入数字用户编号" + id + "可成为蓝名成绩并计入用户通关数)";
core.myprompt(hint, id, function (username) { core.myprompt(hint, id, function (username) {
core.events._gameOver_doUpload(username, ending, norank); core.events._gameOver_doUpload(username, ending, norank);
}); });
} }
@ -272,7 +272,7 @@ events.prototype._gameOver_askRate = function (ending) {
} }
////// 重新开始游戏;此函数将回到标题页面 ////// ////// 重新开始游戏;此函数将回到标题页面 //////
events.prototype.restart = function() { events.prototype.restart = function () {
core.showStartAnimate(); core.showStartAnimate();
core.playBgm(main.startBgm); core.playBgm(main.startBgm);
} }
@ -313,7 +313,7 @@ events.prototype.doSystemEvent = function (type, data, callback) {
} }
catch (e) { catch (e) {
main.log(e); main.log(e);
main.log("ERROR in systemEvents["+type+"]"); main.log("ERROR in systemEvents[" + type + "]");
} }
} }
if (this["_sys_" + type]) return this["_sys_" + type](data, callback); if (this["_sys_" + type]) return this["_sys_" + type](data, callback);
@ -333,7 +333,7 @@ events.prototype.trigger = function (x, y, callback) {
} }
if (core.status.gameOver) return _executeCallback(); if (core.status.gameOver) return _executeCallback();
if (core.status.event.id == 'action') { if (core.status.event.id == 'action') {
core.insertAction({"type": "function", "function": "function () { core.events._trigger_inAction("+x+","+y+"); }", "async": true}, core.insertAction({ "type": "function", "function": "function () { core.events._trigger_inAction(" + x + "," + y + "); }", "async": true },
null, null, null, true); null, null, null, true);
return _executeCallback(); return _executeCallback();
} }
@ -439,9 +439,9 @@ events.prototype._sys_battle = function (data, callback) {
// 检查战前事件 // 检查战前事件
var beforeBattle = []; var beforeBattle = [];
core.push(beforeBattle, core.floors[core.status.floorId].beforeBattle[data.x + "," + data.y]); core.push(beforeBattle, core.floors[core.status.floorId].beforeBattle[data.x + "," + data.y]);
core.push(beforeBattle, (core.material.enemys[data.event.id]||{}).beforeBattle); core.push(beforeBattle, (core.material.enemys[data.event.id] || {}).beforeBattle);
if (beforeBattle.length > 0) { if (beforeBattle.length > 0) {
core.push(beforeBattle, [{"type": "battle", "x": data.x, "y": data.y}]); core.push(beforeBattle, [{ "type": "battle", "x": data.x, "y": data.y }]);
core.clearContinueAutomaticRoute(); core.clearContinueAutomaticRoute();
// 自动存档 // 自动存档
@ -593,7 +593,7 @@ events.prototype._openDoor_animate = function (block, x, y, callback) {
if (callback) callback(); if (callback) callback();
} }
var animate = window.setInterval(function() { var animate = window.setInterval(function () {
blockInfo.posX++; blockInfo.posX++;
if (blockInfo.posX == 4) { if (blockInfo.posX == 4) {
clearInterval(animate); clearInterval(animate);
@ -635,13 +635,13 @@ events.prototype.getItem = function (id, num, x, y, isGentleClick, callback) {
var hint = core.material.items[id].text || "该道具暂无描述"; var hint = core.material.items[id].text || "该道具暂无描述";
try { try {
hint = core.replaceText(hint); hint = core.replaceText(hint);
} catch (e) {} } catch (e) { }
if (!core.status.event.id || core.status.event.id=='action') { if (!core.status.event.id || core.status.event.id == 'action') {
core.insertAction("\t["+core.material.items[id].name+","+id+"]" + hint + "\n" core.insertAction("\t[" + core.material.items[id].name + "," + id + "]" + hint + "\n"
+ (id.endsWith('Key') ? "(钥匙类道具,遇到对应的门时自动打开)" + (id.endsWith('Key') ? "(钥匙类道具,遇到对应的门时自动打开)"
: itemCls == 'tools' ? "消耗类道具请按T在道具栏使用" : itemCls == 'tools' ? "消耗类道具请按T在道具栏使用"
: itemCls == 'constants' ? "永久类道具请按T在道具栏使用" : itemCls == 'constants' ? "永久类道具请按T在道具栏使用"
: itemCls == 'equips' ? "装备类道具请按Q在装备栏进行装备" : "")); : itemCls == 'equips' ? "装备类道具请按Q在装备栏进行装备" : ""));
} }
itemHint.push(id); itemHint.push(id);
} }
@ -686,7 +686,7 @@ events.prototype._getNextItem = function (direction, noRoute) {
events.prototype._sys_changeFloor = function (data, callback) { events.prototype._sys_changeFloor = function (data, callback) {
data = data.event.data; data = data.event.data;
var heroLoc = {}; var heroLoc = {};
if (data.loc) heroLoc = {'x': data.loc[0], 'y': data.loc[1]}; if (data.loc) heroLoc = { 'x': data.loc[0], 'y': data.loc[1] };
if (data.direction) heroLoc.direction = data.direction; if (data.direction) heroLoc.direction = data.direction;
if (core.status.event.id != 'action') core.status.event.id = null; if (core.status.event.id != 'action') core.status.event.id = null;
core.changeFloor(data.floorId, data.stair, heroLoc, data.time, function () { core.changeFloor(data.floorId, data.stair, heroLoc, data.time, function () {
@ -799,13 +799,13 @@ events.prototype._changeFloor_beforeChange = function (info, callback) {
} }
events.prototype._changeFloor_playSound = function () { events.prototype._changeFloor_playSound = function () {
// 播放换层音效 // 播放换层音效
if (core.hasFlag('__fromLoad__')) // 是否是读档造成的切换 if (core.hasFlag('__fromLoad__')) // 是否是读档造成的切换
core.playSound('读档'); core.playSound('读档');
else if (core.hasFlag('__isFlying__')) // 是否是楼传造成的切换 else if (core.hasFlag('__isFlying__')) // 是否是楼传造成的切换
core.playSound('飞行器'); core.playSound('飞行器');
else else
core.playSound('上下楼'); core.playSound('上下楼');
} }
events.prototype._changeFloor_changing = function (info, callback) { events.prototype._changeFloor_changing = function (info, callback) {
@ -888,8 +888,8 @@ events.prototype.pushBox = function (data) {
core.setBlock('flower', data.x, data.y); core.setBlock('flower', data.x, data.y);
// 勇士前进一格,然后触发推箱子后事件 // 勇士前进一格,然后触发推箱子后事件
core.insertAction([ core.insertAction([
{"type": "moveAction"}, { "type": "moveAction" },
{"type": "function", "function": "function() { core.afterPushBox(); }"} { "type": "function", "function": "function() { core.afterPushBox(); }" }
]); ]);
} }
@ -953,7 +953,7 @@ events.prototype.doEvent = function (data, x, y, prefix) {
} }
catch (e) { catch (e) {
main.log(e); main.log(e);
main.log("ERROR in actions["+type+"]"); main.log("ERROR in actions[" + type + "]");
} }
} }
if (this["_action_" + type]) return this["_action_" + type](data, x, y, prefix); if (this["_action_" + type]) return this["_action_" + type](data, x, y, prefix);
@ -966,8 +966,8 @@ events.prototype.setEvents = function (list, x, y, callback) {
if (list) { if (list) {
var l = core.clone(list); var l = core.clone(list);
if (!(l instanceof Array)) l = [l]; if (!(l instanceof Array)) l = [l];
l.push({"type": "_label"}); l.push({ "type": "_label" });
data.list = [{todo: l, total: core.clone(l), condition: "false"}]; data.list = [{ todo: l, total: core.clone(l), condition: "false" }];
// 结束所有正在执行的自动事件 // 结束所有正在执行的自动事件
if (list.length == 0) { if (list.length == 0) {
core.status.autoEvents.forEach(function (autoEvent) { core.status.autoEvents.forEach(function (autoEvent) {
@ -1020,7 +1020,7 @@ events.prototype.doAction = function () {
var data = current.todo.shift(); var data = current.todo.shift();
core.status.event.data.current = data; core.status.event.data.current = data;
if (typeof data == "string") if (typeof data == "string")
data = {"type": "text", "text": data}; data = { "type": "text", "text": data };
// 该事件块已经被禁用 // 该事件块已经被禁用
if (data._disabled) return core.doAction(); if (data._disabled) return core.doAction();
data.floorId = data.floorId || floorId; data.floorId = data.floorId || floorId;
@ -1103,12 +1103,12 @@ events.prototype.insertCommonEvent = function (name, args, x, y, callback, addTo
for (var i = 0; i < args.length; ++i) { for (var i = 0; i < args.length; ++i) {
try { try {
if (args[i] != null) if (args[i] != null)
core.setFlag('arg'+(i+1), args[i]); core.setFlag('arg' + (i + 1), args[i]);
} catch (e) { main.log(e); } } catch (e) { main.log(e); }
} }
} }
this.insertAction({"type": "dowhile", "condition": "false", "data": commonEvent}, x, y, callback, addToLast); this.insertAction({ "type": "dowhile", "condition": "false", "data": commonEvent }, x, y, callback, addToLast);
} }
////// 获得一个公共事件 ////// ////// 获得一个公共事件 //////
@ -1143,7 +1143,7 @@ events.prototype.checkAutoEvents = function () {
// 不在当前楼层 or 已经执行过 or 已被分区 or 正在执行中 // 不在当前楼层 or 已经执行过 or 已被分区 or 正在执行中
if (autoEvent.currentFloor && floorId != core.status.floorId) return; if (autoEvent.currentFloor && floorId != core.status.floorId) return;
if (!autoEvent.multiExecute && core.autoEventExecuted(symbol)) return; if (!autoEvent.multiExecute && core.autoEventExecuted(symbol)) return;
if ((flags.__removed__||[]).indexOf(floorId) >= 0) return; if ((flags.__removed__ || []).indexOf(floorId) >= 0) return;
if (core.autoEventExecuting(symbol)) return; if (core.autoEventExecuting(symbol)) return;
var prefix = floorId + "@" + x + "@" + y; var prefix = floorId + "@" + x + "@" + y;
try { try {
@ -1159,18 +1159,24 @@ events.prototype.checkAutoEvents = function () {
if (x == null && y == null) { if (x == null && y == null) {
event = [ event = [
// 用do-while(0)包一层防止break影响事件流 // 用do-while(0)包一层防止break影响事件流
{"type": "dowhile", "condition": "false", "data": autoEvent.data}, { "type": "dowhile", "condition": "false", "data": autoEvent.data },
{"type": "function", "function": {
"function() { core.autoEventExecuting('" + symbol + "', false); }"} "type": "function", "function":
"function() { core.autoEventExecuting('" + symbol + "', false); }"
}
]; ];
} else { } else {
event = [ event = [
{"type": "function", "function": {
"function() { core.pushEventLoc(" + x + ", " + y + ", '" + floorId + "' ); }"}, "type": "function", "function":
"function() { core.pushEventLoc(" + x + ", " + y + ", '" + floorId + "' ); }"
},
// 用do-while(0)包一层防止break影响事件流 // 用do-while(0)包一层防止break影响事件流
{"type": "dowhile", "condition": "false", "data": autoEvent.data}, { "type": "dowhile", "condition": "false", "data": autoEvent.data },
{"type": "function", "function": {
"function() { core.popEventLoc(); core.autoEventExecuting('" + symbol + "', false); }"} "type": "function", "function":
"function() { core.popEventLoc(); core.autoEventExecuting('" + symbol + "', false); }"
}
]; ];
} }
@ -1439,7 +1445,7 @@ events.prototype._action_tip = function (data, x, y, prefix) {
events.prototype._action_show = function (data, x, y, prefix) { events.prototype._action_show = function (data, x, y, prefix) {
data.loc = this.__action_getLoc2D(data.loc, x, y, prefix); data.loc = this.__action_getLoc2D(data.loc, x, y, prefix);
if (data.time > 0 && data.floorId == core.status.floorId) { if (data.time > 0 && data.floorId == core.status.floorId) {
this.__action_doAsyncFunc(data.async, core.animateBlock, data.loc, 'show', data.time); this.__action_doAsyncFunc(data.async, core.animateBlock, data.loc, 'show', data.time);
} }
else { else {
@ -1583,14 +1589,14 @@ events.prototype._action_moveAction = function (data, x, y, prefix) {
// 检查noPass决定是撞击还是移动 // 检查noPass决定是撞击还是移动
if (core.noPass(nx, ny)) { if (core.noPass(nx, ny)) {
core.insertAction([ core.insertAction([
{"type": "trigger", "loc": [nx, ny]} { "type": "trigger", "loc": [nx, ny] }
]); ]);
} else { } else {
// 先移动一格,然后尝试触发事件 // 先移动一格,然后尝试触发事件
core.insertAction([ core.insertAction([
{"type": "moveHero", "steps": ["forward"]}, { "type": "moveHero", "steps": ["forward"] },
{"type": "function", "function": "function() { core.moveOneStep(core.doAction); }", "async": true}, { "type": "function", "function": "function() { core.moveOneStep(core.doAction); }", "async": true },
{"type": "_label"}, { "type": "_label" },
]); ]);
} }
} }
@ -1630,7 +1636,7 @@ events.prototype._action_jumpHero = function (data, x, y, prefix) {
events.prototype._action_changeFloor = function (data, x, y, prefix) { events.prototype._action_changeFloor = function (data, x, y, prefix) {
var loc = this.__action_getHeroLoc(data.loc, prefix); var loc = this.__action_getHeroLoc(data.loc, prefix);
var heroLoc = {x: loc[0], y: loc[1], direction: data.direction}; var heroLoc = { x: loc[0], y: loc[1], direction: data.direction };
core.changeFloor(data.floorId, data.stair, heroLoc, data.time, core.doAction); core.changeFloor(data.floorId, data.stair, heroLoc, data.time, core.doAction);
} }
@ -1666,7 +1672,7 @@ events.prototype._action_showTextImage = function (data, x, y, prefix) {
var loc = this.__action_getLoc(data.loc, 0, 0, prefix); var loc = this.__action_getLoc(data.loc, 0, 0, prefix);
if (core.isReplaying()) data.time = 0; if (core.isReplaying()) data.time = 0;
data.text = core.replaceText(data.text, prefix); data.text = core.replaceText(data.text, prefix);
var __tmpName = (Math.random()+"_"+Math.random()).replace(/\./g, "") + ".png"; var __tmpName = (Math.random() + "_" + Math.random()).replace(/\./g, "") + ".png";
core.material.images.images[__tmpName] = core.ui.textImage(data.text); core.material.images.images[__tmpName] = core.ui.textImage(data.text);
this.__action_doAsyncFunc(data.async || data.time == 0, core.showImage, this.__action_doAsyncFunc(data.async || data.time == 0, core.showImage,
data.code, __tmpName + (data.reverse || ""), null, loc, data.opacity, data.time); data.code, __tmpName + (data.reverse || ""), null, loc, data.opacity, data.time);
@ -1816,18 +1822,18 @@ events.prototype._action_insert = function (data, x, y, prefix) {
else { else {
// 设置参数 // 设置参数
if (data.args instanceof Array) { if (data.args instanceof Array) {
for (var i = 0; i < data.args.length; ++i) { for (var i = 0; i < data.args.length; ++i) {
try { try {
if (data.args[i] != null) if (data.args[i] != null)
core.setFlag('arg'+(i+1), data.args[i]); core.setFlag('arg' + (i + 1), data.args[i]);
} catch (e) { main.log(e); } } catch (e) { main.log(e); }
} }
} }
var loc = this.__action_getLoc(data.loc, x, y, prefix); var loc = this.__action_getLoc(data.loc, x, y, prefix);
core.setFlag('arg0', loc); core.setFlag('arg0', loc);
var floorId = data.floorId; var floorId = data.floorId;
var which = data.which || "events"; var which = data.which || "events";
var event = (core.floors[floorId][which]||[])[loc[0] + "," + loc[1]]; var event = (core.floors[floorId][which] || [])[loc[0] + "," + loc[1]];
if (event) this.insertAction(event.data || event); if (event) this.insertAction(event.data || event);
} }
core.doAction(); core.doAction();
@ -2105,7 +2111,7 @@ events.prototype._action_choices = function (data, x, y, prefix) {
} }
for (var i = 0; i < data.choices.length; i++) { for (var i = 0; i < data.choices.length; i++) {
if (typeof data.choices[i] === 'string') if (typeof data.choices[i] === 'string')
data.choices[i] = {"text": data.choices[i]}; data.choices[i] = { "text": data.choices[i] };
data.choices[i].text = core.replaceText(data.choices[i].text, prefix); data.choices[i].text = core.replaceText(data.choices[i].text, prefix);
} }
core.ui.drawChoices(core.replaceText(data.text, prefix), data.choices, data.width); core.ui.drawChoices(core.replaceText(data.text, prefix), data.choices, data.width);
@ -2126,13 +2132,13 @@ events.prototype.__action_choices_replaying = function (data, index) {
} else core.setFlag('timeout', 0); } else core.setFlag('timeout', 0);
core.status.event.selection = selection; core.status.event.selection = selection;
setTimeout(function () { setTimeout(function () {
core.status.route.push("choices:"+index); core.status.route.push("choices:" + index);
if (selection != 'none') { if (selection != 'none') {
// 检查 // 检查
var choice = data.choices[selection]; var choice = data.choices[selection];
if (choice.need != null && choice.need != '' && !core.calValue(choice.need)) { if (choice.need != null && choice.need != '' && !core.calValue(choice.need)) {
// 无法选择此项 // 无法选择此项
core.control._replay_error("无法选择项:"+index); core.control._replay_error("无法选择项:" + index);
return; return;
} else { } else {
core.insertAction(choice.action); core.insertAction(choice.action);
@ -2155,7 +2161,7 @@ events.prototype._precompile_choices = function (data) {
events.prototype._action_confirm = function (data, x, y, prefix) { events.prototype._action_confirm = function (data, x, y, prefix) {
data.text = core.replaceText(data.text, prefix); data.text = core.replaceText(data.text, prefix);
core.status.event.ui = {"text": data.text, "yes": data.yes, "no": data.no}; core.status.event.ui = { "text": data.text, "yes": data.yes, "no": data.no };
if (core.isReplaying()) { if (core.isReplaying()) {
var action = core.status.replay.toReplay.shift(); var action = core.status.replay.toReplay.shift();
if (action.indexOf('choices:') == 0 && !(action == 'choices:none' && !data.timeout)) { if (action.indexOf('choices:') == 0 && !(action == 'choices:none' && !data.timeout)) {
@ -2194,7 +2200,7 @@ events.prototype.__action_confirm_replaying = function (data, index) {
} else core.setFlag('timeout', 0); } else core.setFlag('timeout', 0);
core.status.event.selection = index; core.status.event.selection = index;
setTimeout(function () { setTimeout(function () {
core.status.route.push("choices:"+index); core.status.route.push("choices:" + index);
if (index != 'none') { if (index != 'none') {
if (index == 0) core.insertAction(data.yes); if (index == 0) core.insertAction(data.yes);
else core.insertAction(data.no); else core.insertAction(data.no);
@ -2218,7 +2224,7 @@ events.prototype._action_for = function (data, x, y, prefix) {
var from = core.calValue(data.from); var from = core.calValue(data.from);
var to = core.calValue(data.to); var to = core.calValue(data.to);
var step = core.calValue(data.step); var step = core.calValue(data.step);
if (typeof from != 'number' || typeof to !='number' || typeof step != 'number') { if (typeof from != 'number' || typeof to != 'number' || typeof step != 'number') {
core.insertAction('循环遍历事件要求【起始点】【终止点】【每步】仅能是数字!'); core.insertAction('循环遍历事件要求【起始点】【终止点】【每步】仅能是数字!');
return core.doAction(); return core.doAction();
} }
@ -2234,18 +2240,18 @@ events.prototype._action_for = function (data, x, y, prefix) {
var stepName = '@temp@for-step@' + letter; var stepName = '@temp@for-step@' + letter;
core.setFlag(toName, data.to); core.setFlag(toName, data.to);
core.setFlag(stepName, data.step); core.setFlag(stepName, data.step);
var condition = "(function () {"+ var condition = "(function () {" +
"var to = core.calValue(core.getFlag('" + toName + "'));"+ "var to = core.calValue(core.getFlag('" + toName + "'));" +
"var step = core.calValue(core.getFlag('" + stepName + "'));"+ "var step = core.calValue(core.getFlag('" + stepName + "'));" +
"if (typeof step != 'number' || typeof to != 'number') return false;"+ "if (typeof step != 'number' || typeof to != 'number') return false;" +
"if (step == 0) return true;"+ "if (step == 0) return true;" +
"var currentValue = core.getFlag('@temp@" + letter + "');"+ "var currentValue = core.getFlag('@temp@" + letter + "');" +
"currentValue += step;"+ "currentValue += step;" +
"core.setFlag('@temp@" + letter + "', currentValue);"+ "core.setFlag('@temp@" + letter + "', currentValue);" +
"if (step > 0) { return currentValue <= to; }"+ "if (step > 0) { return currentValue <= to; }" +
"else { return currentValue >= to; }"+ "else { return currentValue >= to; }" +
"})()"; "})()";
return this._action_dowhile({"condition": condition, "data": data.data}, x, y, prefix); return this._action_dowhile({ "condition": condition, "data": data.data }, x, y, prefix);
} }
events.prototype._precompile_for = function (data) { events.prototype._precompile_for = function (data) {
@ -2265,12 +2271,12 @@ events.prototype._action_forEach = function (data, x, y, prefix) {
var listName = '@temp@forEach@' + data.name.substring(5); var listName = '@temp@forEach@' + data.name.substring(5);
core.setFlag(listName, core.clone(data.list)); core.setFlag(listName, core.clone(data.list));
var condition = "(function () {" + var condition = "(function () {" +
"var list = core.getFlag('"+listName+"', []);"+ "var list = core.getFlag('" + listName + "', []);" +
"if (list.length == 0) return false;"+ "if (list.length == 0) return false;" +
"core.setFlag('@temp@'+'" + data.name.substring(5) + "', list.shift());"+ "core.setFlag('@temp@'+'" + data.name.substring(5) + "', list.shift());" +
"return true;"+ "return true;" +
"})()"; "})()";
return this._action_while({"condition": condition, "data": data.data}, x, y, prefix); return this._action_while({ "condition": condition, "data": data.data }, x, y, prefix);
} }
events.prototype._precompile_forEach = function (data) { events.prototype._precompile_forEach = function (data) {
@ -2282,9 +2288,9 @@ events.prototype._action_while = function (data, x, y, prefix) {
if (core.calValue(data.condition, prefix)) { if (core.calValue(data.condition, prefix)) {
var list = core.clone(data.data); var list = core.clone(data.data);
if (!(list instanceof Array)) list = [list]; if (!(list instanceof Array)) list = [list];
list.push({"type": "_label"}); list.push({ "type": "_label" });
core.unshift(core.status.event.data.list, core.unshift(core.status.event.data.list,
{"todo": list, "total": core.clone(list), "condition": data.condition} { "todo": list, "total": core.clone(list), "condition": data.condition }
); );
} }
core.doAction(); core.doAction();
@ -2299,9 +2305,9 @@ events.prototype._precompile_while = function (data) {
events.prototype._action_dowhile = function (data, x, y, prefix) { events.prototype._action_dowhile = function (data, x, y, prefix) {
var list = core.clone(data.data); var list = core.clone(data.data);
if (!(list instanceof Array)) list = [list]; if (!(list instanceof Array)) list = [list];
list.push({"type": "_label"}); list.push({ "type": "_label" });
core.unshift(core.status.event.data.list, core.unshift(core.status.event.data.list,
{"todo": list, "total": core.clone(list), "condition": data.condition} { "todo": list, "total": core.clone(list), "condition": data.condition }
); );
core.doAction(); core.doAction();
} }
@ -2431,7 +2437,7 @@ events.prototype._action_wait = function (data, x, y, prefix) {
core.control._replay_error(code); core.control._replay_error(code);
return; return;
} else if (data.timeout) { } else if (data.timeout) {
core.status.event.interval = setTimeout(function() { core.status.event.interval = setTimeout(function () {
core.status.route.push("input:none"); core.status.route.push("input:none");
core.setFlag("type", -1); core.setFlag("type", -1);
core.setFlag("timeout", 0); core.setFlag("timeout", 0);
@ -2498,7 +2504,7 @@ events.prototype.__action_wait_afterGet = function (data) {
} }
if (one["case"] == "condition") { if (one["case"] == "condition") {
var condition = false; var condition = false;
try { condition = core.calValue(one.condition); } catch (e) {} try { condition = core.calValue(one.condition); } catch (e) { }
if (condition) { if (condition) {
found = true; found = true;
core.push(todo, one.action); core.push(todo, one.action);
@ -2533,8 +2539,8 @@ events.prototype._precompile_wait = function (data) {
events.prototype._action_waitAsync = function (data, x, y, prefix) { events.prototype._action_waitAsync = function (data, x, y, prefix) {
var test = window.setInterval(function () { var test = window.setInterval(function () {
if (!core.hasAsync() if (!core.hasAsync()
&& (data.excludeAnimates || core.isReplaying() || core.getPlayingAnimates().length == 0) && (data.excludeAnimates || core.isReplaying() || core.getPlayingAnimates().length == 0)
&& (!data.includeSounds || core.isReplaying() || core.getPlayingSounds().length == 0)) { && (!data.includeSounds || core.isReplaying() || core.getPlayingSounds().length == 0)) {
clearInterval(test); clearInterval(test);
core.doAction(); core.doAction();
} }
@ -2778,7 +2784,7 @@ events.prototype.useFly = function (fromUserAction) {
if (!core.hasItem('fly')) { if (!core.hasItem('fly')) {
core.playSound('操作失败'); core.playSound('操作失败');
core.drawTip('你没有' + core.material.items['fly'].name, 'fly'); core.drawTip('你没有' + core.material.items['fly'].name, 'fly');
} else if (!core.canUseItem('fly')) { } else if (!core.canUseItem('fly') || (core.flags.flyNearStair && !core.nearStair())) {
core.playSound('操作失败'); core.playSound('操作失败');
core.drawTip('无法传送到当前层', 'fly'); core.drawTip('无法传送到当前层', 'fly');
} else { } else {
@ -2880,32 +2886,32 @@ events.prototype.save = function (fromUserAction) {
return; return;
if (!this._checkStatus('save', fromUserAction)) return; if (!this._checkStatus('save', fromUserAction)) return;
var saveIndex = core.saves.saveIndex; var saveIndex = core.saves.saveIndex;
var page=parseInt((saveIndex-1)/5), offset=saveIndex-5*page; var page = parseInt((saveIndex - 1) / 5), offset = saveIndex - 5 * page;
core.playSound('打开界面'); core.playSound('打开界面');
core.ui._drawSLPanel(10*page+offset); core.ui._drawSLPanel(10 * page + offset);
} }
////// 点击读取按钮时的打开操作 ////// ////// 点击读取按钮时的打开操作 //////
events.prototype.load = function (fromUserAction) { events.prototype.load = function (fromUserAction) {
if (core.isReplaying()) return; if (core.isReplaying()) return;
var saveIndex = core.saves.saveIndex; var saveIndex = core.saves.saveIndex;
var page=parseInt((saveIndex-1)/5), offset=saveIndex-5*page; var page = parseInt((saveIndex - 1) / 5), offset = saveIndex - 5 * page;
// 游戏开始前读档 // 游戏开始前读档
if (!core.isPlaying()) { if (!core.isPlaying()) {
core.dom.startPanel.style.display = 'none'; core.dom.startPanel.style.display = 'none';
core.clearStatus(); core.clearStatus();
core.clearMap('all'); core.clearMap('all');
core.status.event = {'id': 'load', 'data': null}; core.status.event = { 'id': 'load', 'data': null };
core.status.lockControl = true; core.status.lockControl = true;
core.playSound('打开界面'); core.playSound('打开界面');
core.ui._drawSLPanel(10*page+offset); core.ui._drawSLPanel(10 * page + offset);
return; return;
} }
if (core.status.event.id == 'load' && core.events.recoverEvents(core.status.event.interval)) if (core.status.event.id == 'load' && core.events.recoverEvents(core.status.event.interval))
return; return;
if (!this._checkStatus('load', fromUserAction)) return; if (!this._checkStatus('load', fromUserAction)) return;
core.playSound('打开界面'); core.playSound('打开界面');
core.ui._drawSLPanel(10*page+offset); core.ui._drawSLPanel(10 * page + offset);
} }
////// 点击设置按钮时的操作 ////// ////// 点击设置按钮时的操作 //////
@ -2944,7 +2950,7 @@ events.prototype.hasAsyncAnimate = function () {
events.prototype.follow = function (name) { events.prototype.follow = function (name) {
name = core.getMappedName(name); name = core.getMappedName(name);
if (core.material.images.images[name]) { if (core.material.images.images[name]) {
core.status.hero.followers.push({"name": name}); core.status.hero.followers.push({ "name": name });
core.gatherFollowers(); core.gatherFollowers();
core.clearMap('hero'); core.clearMap('hero');
core.drawHero(); core.drawHero();
@ -3045,9 +3051,9 @@ events.prototype.setEnemy = function (id, name, value, operator, prefix, norefre
var enemyInfo = core.getFlag('enemyInfo'); var enemyInfo = core.getFlag('enemyInfo');
if (!enemyInfo[id]) enemyInfo[id] = {}; if (!enemyInfo[id]) enemyInfo[id] = {};
if (typeof value === 'string' && name == 'name') value = value.replace(/\r/g, '\\r'); 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); value = this._updateValueByOperator(core.calValue(value, prefix), (core.material.enemys[id] || {})[name], operator);
enemyInfo[id][name] = value; enemyInfo[id][name] = value;
(core.material.enemys[id]||{})[name] = core.clone(value); (core.material.enemys[id] || {})[name] = core.clone(value);
if (!norefresh) core.updateStatusBar(); if (!norefresh) core.updateStatusBar();
} }
@ -3063,23 +3069,23 @@ events.prototype.setEnemyOnPoint = function (x, y, floorId, name, value, operato
value = this._updateValueByOperator(core.calValue(value, prefix), core.getEnemyValue(enemy, name, x, y, floorId), operator); value = this._updateValueByOperator(core.calValue(value, prefix), core.getEnemyValue(enemy, name, x, y, floorId), operator);
flags.enemyOnPoint = flags.enemyOnPoint || {}; flags.enemyOnPoint = flags.enemyOnPoint || {};
flags.enemyOnPoint[floorId] = flags.enemyOnPoint[floorId] || {}; flags.enemyOnPoint[floorId] = flags.enemyOnPoint[floorId] || {};
flags.enemyOnPoint[floorId][x+","+y] = flags.enemyOnPoint[floorId][x+","+y] || {}; flags.enemyOnPoint[floorId][x + "," + y] = flags.enemyOnPoint[floorId][x + "," + y] || {};
flags.enemyOnPoint[floorId][x+","+y][name] = value; flags.enemyOnPoint[floorId][x + "," + y][name] = value;
if (!norefresh) core.updateStatusBar(); if (!norefresh) core.updateStatusBar();
} }
////// 重置某个点上的怪物属性 ////// ////// 重置某个点上的怪物属性 //////
events.prototype.resetEnemyOnPoint = function (x, y, floorId, norefresh) { events.prototype.resetEnemyOnPoint = function (x, y, floorId, norefresh) {
delete ((flags.enemyOnPoint||{})[floorId||core.status.floorId]||{})[x+","+y]; delete ((flags.enemyOnPoint || {})[floorId || core.status.floorId] || {})[x + "," + y];
if (!norefresh) core.updateStatusBar(); if (!norefresh) core.updateStatusBar();
} }
////// 将某个点上已经设置的怪物属性移动到其他点 ////// ////// 将某个点上已经设置的怪物属性移动到其他点 //////
events.prototype.moveEnemyOnPoint = function (fromX, fromY, toX, toY, floorId, norefresh) { events.prototype.moveEnemyOnPoint = function (fromX, fromY, toX, toY, floorId, norefresh) {
floorId = floorId || core.status.floorId; floorId = floorId || core.status.floorId;
if (((flags.enemyOnPoint||{})[floorId]||{})[fromX+","+fromY]) { if (((flags.enemyOnPoint || {})[floorId] || {})[fromX + "," + fromY]) {
flags.enemyOnPoint[floorId][toX+","+toY] = flags.enemyOnPoint[floorId][fromX+","+fromY]; flags.enemyOnPoint[floorId][toX + "," + toY] = flags.enemyOnPoint[floorId][fromX + "," + fromY];
delete flags.enemyOnPoint[floorId][fromX+","+fromY]; delete flags.enemyOnPoint[floorId][fromX + "," + fromY];
if (!norefresh) core.updateStatusBar(); if (!norefresh) core.updateStatusBar();
} }
} }
@ -3115,7 +3121,7 @@ events.prototype.setGlobalFlag = function (name, value) {
var flags = core.getFlag("globalFlags", {}); var flags = core.getFlag("globalFlags", {});
if (name.startsWith('s:')) { if (name.startsWith('s:')) {
name = name.substring(2); name = name.substring(2);
var statusBarItems = core.flags.statusBarItems.filter(function (v) {return v!=name;}); var statusBarItems = core.flags.statusBarItems.filter(function (v) { return v != name; });
if (value) statusBarItems.push(name); if (value) statusBarItems.push(name);
core.flags.statusBarItems = statusBarItems; core.flags.statusBarItems = statusBarItems;
flags.statusBarItems = core.clone(statusBarItems); flags.statusBarItems = core.clone(statusBarItems);
@ -3234,7 +3240,7 @@ events.prototype.clearTextBox = function (code, callback) {
events.prototype.closeDoor = function (x, y, id, callback) { events.prototype.closeDoor = function (x, y, id, callback) {
id = id || ""; id = id || "";
if ((core.material.icons.animates[id] == null && core.material.icons.npc48[id] == null) if ((core.material.icons.animates[id] == null && core.material.icons.npc48[id] == null)
|| core.getBlock(x, y) != null) { || core.getBlock(x, y) != null) {
if (callback) callback(); if (callback) callback();
return; return;
} }
@ -3451,7 +3457,7 @@ events.prototype.scaleImage = function (code, center, scale, moveMode, time, cal
centerY = currTop + height * currScale / 2; centerY = currTop + height * currScale / 2;
} }
var scaleInfo = { var scaleInfo = {
x: (currLeft - centerX) / currScale, y: (currTop - centerY) / currScale, centerX: centerX, centerY: centerY, x: (currLeft - centerX) / currScale, y: (currTop - centerY) / currScale, centerX: centerX, centerY: centerY,
width: width, height: height, currScale: currScale, scale: scale, moveMode: moveMode, time: time width: width, height: height, currScale: currScale, scale: scale, moveMode: moveMode, time: time
} }
this._scaleImage_scale(ctx, scaleInfo, callback); this._scaleImage_scale(ctx, scaleInfo, callback);
@ -3547,7 +3553,7 @@ events.prototype.vibrate = function (direction, time, speed, power, callback) {
if (!time) time = 1000; if (!time) time = 1000;
speed = speed || 10; speed = speed || 10;
power = power || 10; power = power || 10;
var shakeInfo = {duration: parseInt(time / 10), speed: speed, power: power, direction: 1, shake: 0}; var shakeInfo = { duration: parseInt(time / 10), speed: speed, power: power, direction: 1, shake: 0 };
if (direction == 'random') { if (direction == 'random') {
direction = ['horizontal', 'vertical', 'diagonal1', 'diagonal2'][Math.floor(Math.random() * 4)]; direction = ['horizontal', 'vertical', 'diagonal1', 'diagonal2'][Math.floor(Math.random() * 4)];
} }
@ -3595,12 +3601,12 @@ events.prototype._vibrate_update = function (shakeInfo) {
} }
/////// 使用事件让勇士移动。这个函数将不会触发任何事件 ////// /////// 使用事件让勇士移动。这个函数将不会触发任何事件 //////
events.prototype.eventMoveHero = function(steps, time, callback) { events.prototype.eventMoveHero = function (steps, time, callback) {
time = time || core.values.moveSpeed; time = time || core.values.moveSpeed;
var step = 0, moveSteps = (steps||[]).map(function (t) { var step = 0, moveSteps = (steps || []).map(function (t) {
return [t.split(':')[0], parseInt(t.split(':')[1]||"1")]; return [t.split(':')[0], parseInt(t.split(':')[1] || "1")];
}).filter(function (t) { }).filter(function (t) {
return ['up','down','left','right','forward','backward','leftup','leftdown','rightup','rightdown','speed'].indexOf(t[0])>=0 return ['up', 'down', 'left', 'right', 'forward', 'backward', 'leftup', 'leftdown', 'rightup', 'rightdown', 'speed'].indexOf(t[0]) >= 0
&& !(t[0] == 'speed' && t[1] < 16); && !(t[0] == 'speed' && t[1] < 16);
}); });
core.status.heroMoving = -1; core.status.heroMoving = -1;
@ -3611,8 +3617,8 @@ events.prototype.eventMoveHero = function(steps, time, callback) {
if (callback) callback(); if (callback) callback();
} }
var animate=window.setInterval(function() { var animate = window.setInterval(function () {
if (moveSteps.length==0) { if (moveSteps.length == 0) {
delete core.animateFrame.asyncId[animate]; delete core.animateFrame.asyncId[animate];
clearInterval(animate); clearInterval(animate);
cb(); cb();
@ -3674,9 +3680,9 @@ events.prototype.jumpHero = function (ex, ey, time, callback) {
var sx = core.getHeroLoc('x'), sy = core.getHeroLoc('y'); var sx = core.getHeroLoc('x'), sy = core.getHeroLoc('y');
if (ex == null) ex = sx; if (ex == null) ex = sx;
if (ey == null) ey = sy; if (ey == null) ey = sy;
var sx=core.status.hero.loc.x, sy=core.status.hero.loc.y; var sx = core.status.hero.loc.x, sy = core.status.hero.loc.y;
if (!core.isset(ex)) ex=sx; if (!core.isset(ex)) ex = sx;
if (!core.isset(ey)) ey=sy; if (!core.isset(ey)) ey = sy;
var jumpInfo = core.maps.__generateJumpInfo(sx, sy, ex, ey, time || 500); var jumpInfo = core.maps.__generateJumpInfo(sx, sy, ex, ey, time || 500);
jumpInfo.icon = core.material.icons.hero[core.getHeroLoc('direction')]; jumpInfo.icon = core.material.icons.hero[core.getHeroLoc('direction')];
jumpInfo.width = core.material.icons.hero.width || 32; jumpInfo.width = core.material.icons.hero.width || 32;
@ -3723,7 +3729,7 @@ events.prototype.setHeroIcon = function (name, noDraw) {
name = core.getMappedName(name); name = core.getMappedName(name);
var img = core.material.images.images[name]; var img = core.material.images.images[name];
if (!img) { if (!img) {
console.error("找不到图片: "+img); console.error("找不到图片: " + img);
return; return;
} }
if (core.material.images.hero == img) return; if (core.material.images.hero == img) return;
@ -3747,7 +3753,7 @@ events.prototype.checkLvUp = function () {
} }
events.prototype._checkLvUp_check = function () { events.prototype._checkLvUp_check = function () {
if (core.flags.statusBarItems.indexOf('enableLevelUp')<0 || !core.firstData.levelUp if (core.flags.statusBarItems.indexOf('enableLevelUp') < 0 || !core.firstData.levelUp
|| core.status.hero.lv >= core.firstData.levelUp.length) return null; || core.status.hero.lv >= core.firstData.levelUp.length) return null;
// 计算下一个所需要的数值 // 计算下一个所需要的数值
var next = (core.firstData.levelUp[core.status.hero.lv] || {}); var next = (core.firstData.levelUp[core.status.hero.lv] || {});

View File

@ -2,7 +2,7 @@
"use strict"; "use strict";
function maps() { function maps () {
this._init(); this._init();
} }
@ -53,7 +53,7 @@ maps.prototype.loadFloor = function (floorId, map) {
var floor = core.floors[floorId]; var floor = core.floors[floorId];
if (!map) map = core.cloneArray(floor.map); if (!map) map = core.cloneArray(floor.map);
if (map instanceof Array) { if (map instanceof Array) {
map = {"map": map}; map = { "map": map };
} }
if (!map.map) map.map = core.cloneArray(floor.map); if (!map.map) map.map = core.cloneArray(floor.map);
var content = {}; var content = {};
@ -84,7 +84,7 @@ maps.prototype._loadFloor_doNotCopy = function () {
/// 根据需求解析出blocks /// 根据需求解析出blocks
maps.prototype.extractBlocks = function (map) { maps.prototype.extractBlocks = function (map) {
map = map || core.status.floorId; map = map || core.status.floorId;
if (typeof map == 'string') map = (core.status.maps||{})[map]; if (typeof map == 'string') map = (core.status.maps || {})[map];
if (!map) return; if (!map) return;
if (map.blocks) return; if (map.blocks) return;
if (map.deleted) { if (map.deleted) {
@ -104,7 +104,7 @@ maps.prototype._mapIntoBlocks = function (map, floor, floorId) {
var number = (map[i] || [])[j] || 0, block; var number = (map[i] || [])[j] || 0, block;
if (main.mode == 'editor') { if (main.mode == 'editor') {
if (!number) continue; if (!number) continue;
block = {x: j, y: i, id: number, event: this.getBlockByNumber(number).event}; block = { x: j, y: i, id: number, event: this.getBlockByNumber(number).event };
} else { } else {
block = this.initBlock(j, i, number, true, floor); block = this.initBlock(j, i, number, true, floor);
} }
@ -147,7 +147,7 @@ maps.prototype.extractBlocksForUI = function (map, flags) {
var event = (floor.events || {})[j + "," + i]; var event = (floor.events || {})[j + "," + i];
if (event != null && event.filter != null) filter = core.clone(event.filter); if (event != null && event.filter != null) filter = core.clone(event.filter);
} }
map.blocks.push(Object.assign({}, this.getBlockByNumber(number), {x: j, y: i, opacity: opacity, filter: filter})); map.blocks.push(Object.assign({}, this.getBlockByNumber(number), { x: j, y: i, opacity: opacity, filter: filter }));
} }
} }
} }
@ -202,15 +202,15 @@ maps.prototype.initBlock = function (x, y, id, addInfo, eventFloor) {
opacity = this._getBlockOpacityFromFlag(eventFloor.floorId, x, y); opacity = this._getBlockOpacityFromFlag(eventFloor.floorId, x, y);
filter = this._getBlockFilterFromFlag(eventFloor.floorId, x, y); filter = this._getBlockFilterFromFlag(eventFloor.floorId, x, y);
} }
var block = {'x': x, 'y': y, 'id': id}; var block = { 'x': x, 'y': y, 'id': id };
if (disable != null) block.disable = disable; if (disable != null) block.disable = disable;
if (opacity != null) block.opacity = opacity; if (opacity != null) block.opacity = opacity;
if (filter != null) block.filter = filter; if (filter != null) block.filter = filter;
if (id == 17) block.event = {"cls": "terrains", "id": "airwall", "cannotIn":["up", "down", "left", "right"]}; if (id == 17) block.event = { "cls": "terrains", "id": "airwall", "cannotIn": ["up", "down", "left", "right"] };
else if (id in this.blocksInfo) block.event = JSON.parse(JSON.stringify(this.blocksInfo[id])); else if (id in this.blocksInfo) block.event = JSON.parse(JSON.stringify(this.blocksInfo[id]));
else if (core.icons.getTilesetOffset(id)) block.event = {"cls": "tileset", "id": "X" + id}; else if (core.icons.getTilesetOffset(id)) block.event = { "cls": "tileset", "id": "X" + id };
else block.event = {'cls': 'terrains', 'id': 'none', 'noPass': false}; else block.event = { 'cls': 'terrains', 'id': 'none', 'noPass': false };
if (block.event.noPass == null) { if (block.event.noPass == null) {
if (block.event.canPass == null) { if (block.event.canPass == null) {
@ -222,7 +222,7 @@ maps.prototype.initBlock = function (x, y, id, addInfo, eventFloor) {
delete block.event.canPass; delete block.event.canPass;
// 增加怪物的faceIds // 增加怪物的faceIds
if (block.event.cls.indexOf("enemy") ==0 ) { if (block.event.cls.indexOf("enemy") == 0) {
var enemy = core.material.enemys[block.event.id]; var enemy = core.material.enemys[block.event.id];
if (enemy && enemy.faceIds) { if (enemy && enemy.faceIds) {
block.event.faceIds = enemy.faceIds; block.event.faceIds = enemy.faceIds;
@ -233,7 +233,7 @@ maps.prototype.initBlock = function (x, y, id, addInfo, eventFloor) {
if (eventFloor) { if (eventFloor) {
this._addEvent(block, x, y, (eventFloor.events || {})[x + "," + y]); this._addEvent(block, x, y, (eventFloor.events || {})[x + "," + y]);
var changeFloor = (eventFloor.changeFloor || {})[x + "," + y]; var changeFloor = (eventFloor.changeFloor || {})[x + "," + y];
if (changeFloor) this._addEvent(block, x, y, {"trigger": "changeFloor", "data": changeFloor}); if (changeFloor) this._addEvent(block, x, y, { "trigger": "changeFloor", "data": changeFloor });
} }
if (main.mode == 'editor') delete block.disable; if (main.mode == 'editor') delete block.disable;
return block; return block;
@ -260,10 +260,10 @@ maps.prototype._addEvent = function (block, x, y, event) {
if (!event) return; if (!event) return;
// event是字符串或数组 // event是字符串或数组
if (typeof event == "string") { if (typeof event == "string") {
event = {"data": [event]}; event = { "data": [event] };
} }
else if (event instanceof Array) { else if (event instanceof Array) {
event = {"data": event}; event = { "data": event };
} }
event.data = event.data || []; event.data = event.data || [];
@ -352,7 +352,7 @@ maps.prototype._getBlockOpacityFromFlag = function (floorId, x, y, flags) {
if (!floorId) return null; if (!floorId) return null;
if ((flags.__removed__ || []).indexOf(floorId) >= 0) return null; if ((flags.__removed__ || []).indexOf(floorId) >= 0) return null;
var index = x + y * core.floors[floorId].width; var index = x + y * core.floors[floorId].width;
return (__opacity__[floorId]||{})[index]; return (__opacity__[floorId] || {})[index];
} }
maps.prototype._getBlockFilterFromFlag = function (floorId, x, y, flags) { maps.prototype._getBlockFilterFromFlag = function (floorId, x, y, flags) {
@ -363,7 +363,7 @@ maps.prototype._getBlockFilterFromFlag = function (floorId, x, y, flags) {
if (!floorId) return null; if (!floorId) return null;
if ((flags.__removed__ || []).indexOf(floorId) >= 0) return null; if ((flags.__removed__ || []).indexOf(floorId) >= 0) return null;
var index = x + y * core.floors[floorId].width; var index = x + y * core.floors[floorId].width;
return core.clone((__filter__[floorId]||{})[index]); return core.clone((__filter__[floorId] || {})[index]);
} }
////// 设置某个点的不透明度 ////// ////// 设置某个点的不透明度 //////
@ -447,10 +447,10 @@ maps.prototype.setMapBlockDisabled = function (floorId, x, y, disabled) {
if (!window.flags.__disabled__) window.flags.__disabled__ = {}; if (!window.flags.__disabled__) window.flags.__disabled__ = {};
if ((window.flags.__removed__ || []).indexOf(floorId) >= 0) return; if ((window.flags.__removed__ || []).indexOf(floorId) >= 0) return;
var __disabled__ = window.flags.__disabled__ || {}; var __disabled__ = window.flags.__disabled__ || {};
if (!__disabled__[floorId]) __disabled__[floorId] = [[],[]]; if (!__disabled__[floorId]) __disabled__[floorId] = [[], []];
var index = x + y * core.floors[floorId].width; var index = x + y * core.floors[floorId].width;
__disabled__[floorId][0] = __disabled__[floorId][0].filter(function (x) {return x != index}); __disabled__[floorId][0] = __disabled__[floorId][0].filter(function (x) { return x != index });
__disabled__[floorId][1] = __disabled__[floorId][1].filter(function (x) {return x != index}); __disabled__[floorId][1] = __disabled__[floorId][1].filter(function (x) { return x != index });
if (disabled == null) return; if (disabled == null) return;
if (disabled) __disabled__[floorId][0].push(index); if (disabled) __disabled__[floorId][0].push(index);
else __disabled__[floorId][1].push(index); else __disabled__[floorId][1].push(index);
@ -525,7 +525,7 @@ maps.prototype.loadMap = function (data, floorId, flags) {
if (!floorId) { if (!floorId) {
var map = {}; var map = {};
core.floorIds.forEach(function (id) { core.floorIds.forEach(function (id) {
if (core.inArray((flags||{}).__removed__, id)) { if (core.inArray((flags || {}).__removed__, id)) {
data[id] = { deleted: true, canFlyTo: false, canFlyFrom: false, cannotViewMap: true }; data[id] = { deleted: true, canFlyTo: false, canFlyFrom: false, cannotViewMap: true };
} }
map[id] = core.maps.loadFloor(id, data[id]); map[id] = core.maps.loadFloor(id, data[id]);
@ -630,10 +630,10 @@ maps.prototype._getBgFgMapArray = function (name, floorId, noCache) {
for (var y = 0; y < height; ++y) { for (var y = 0; y < height; ++y) {
if (arr[y] == null) arr[y] = Array(width).fill(0); if (arr[y] == null) arr[y] = Array(width).fill(0);
} }
(core.getFlag('__'+name+'v__', {})[floorId] || []).forEach(function (one) { (core.getFlag('__' + name + 'v__', {})[floorId] || []).forEach(function (one) {
arr[one[1]][one[0]] = one[2] || 0; arr[one[1]][one[0]] = one[2] || 0;
}); });
(core.getFlag('__'+name+'d__', {})[floorId] || []).forEach(function (one) { (core.getFlag('__' + name + 'd__', {})[floorId] || []).forEach(function (one) {
arr[one[1]][one[0]] = 0; arr[one[1]][one[0]] = 0;
}); });
if (main.mode == 'editor') { if (main.mode == 'editor') {
@ -740,7 +740,7 @@ maps.prototype._canMoveHero_checkPoint = function (x, y, direction, floorId, arr
// 4. 检查是否能进将死的领域 // 4. 检查是否能进将死的领域
if (floorId == core.status.floorId && !core.flags.canGoDeadZone && !core.status.lockControl && if (floorId == core.status.floorId && !core.flags.canGoDeadZone && !core.status.lockControl &&
Math.max(core.status.hero.hp, 1) <= ((core.status.checkBlock.damage||{})[nx + "," + ny]||0) && arrays.eventArray[ny][nx] == 0) Math.max(core.status.hero.hp, 1) <= ((core.status.checkBlock.damage || {})[nx + "," + ny] || 0) && arrays.eventArray[ny][nx] == 0)
return false; return false;
return true; return true;
@ -760,7 +760,7 @@ maps.prototype._canMoveHero_checkCannotInOut = function (number, name, direction
////// 能否瞬间移动 ////// ////// 能否瞬间移动 //////
maps.prototype.canMoveDirectly = function (destX, destY) { maps.prototype.canMoveDirectly = function (destX, destY) {
return this.canMoveDirectlyArray([[destX,destY]])[0]; return this.canMoveDirectlyArray([[destX, destY]])[0];
} }
maps.prototype.canMoveDirectlyArray = function (locs, canMoveArray) { maps.prototype.canMoveDirectlyArray = function (locs, canMoveArray) {
@ -888,12 +888,12 @@ maps.prototype.automaticRoute = function (destX, destY) {
if (destX == startX && destY == startY) return []; if (destX == startX && destY == startY) return [];
// BFS找寻最短路径 // BFS找寻最短路径
var route = this._automaticRoute_bfs(startX, startY, destX, destY); var route = this._automaticRoute_bfs(startX, startY, destX, destY);
if (route[destX+","+destY] == null) return []; if (route[destX + "," + destY] == null) return [];
// 路径数组转换 // 路径数组转换
var ans = [], nowX = destX, nowY = destY; var ans = [], nowX = destX, nowY = destY;
while (nowX != startX || nowY != startY) { while (nowX != startX || nowY != startY) {
var dir = route[nowX + "," + nowY]; var dir = route[nowX + "," + nowY];
ans.push({'direction': dir, 'x': nowX, 'y': nowY}); ans.push({ 'direction': dir, 'x': nowX, 'y': nowY });
nowX -= core.utils.scan[dir].x; nowX -= core.utils.scan[dir].x;
nowY -= core.utils.scan[dir].y; nowY -= core.utils.scan[dir].y;
} }
@ -904,28 +904,28 @@ maps.prototype.automaticRoute = function (destX, destY) {
maps.prototype._automaticRoute_bfs = function (startX, startY, destX, destY) { maps.prototype._automaticRoute_bfs = function (startX, startY, destX, destY) {
var route = {}, canMoveArray = this.generateMovableArray(); var route = {}, canMoveArray = this.generateMovableArray();
// 使用优先队列 // 使用优先队列
var queue = new PriorityQueue({comparator: function (a,b) { return a.depth - b.depth; }}); var queue = new PriorityQueue({ comparator: function (a, b) { return a.depth - b.depth; } });
route[startX + "," + startY] = ''; route[startX + "," + startY] = '';
queue.queue({depth: 0, x: startX, y: startY}); queue.queue({ depth: 0, x: startX, y: startY });
var blocks = core.getMapBlocksObj(); var blocks = core.getMapBlocksObj();
while (queue.length!=0) { while (queue.length != 0) {
var curr = queue.dequeue(), deep = curr.depth, nowX = curr.x, nowY = curr.y; var curr = queue.dequeue(), deep = curr.depth, nowX = curr.x, nowY = curr.y;
for (var direction in core.utils.scan) { for (var direction in core.utils.scan) {
if (!core.inArray(canMoveArray[nowX][nowY], direction)) continue; if (!core.inArray(canMoveArray[nowX][nowY], direction)) continue;
var nx = nowX + core.utils.scan[direction].x; var nx = nowX + core.utils.scan[direction].x;
var ny = nowY + core.utils.scan[direction].y; var ny = nowY + core.utils.scan[direction].y;
if (nx<0 || nx>=core.bigmap.width || ny<0 || ny>=core.bigmap.height || route[nx+","+ny] != null) continue; if (nx < 0 || nx >= core.bigmap.width || ny < 0 || ny >= core.bigmap.height || route[nx + "," + ny] != null) continue;
// 重点 // 重点
if (nx == destX && ny == destY) { if (nx == destX && ny == destY) {
route[nx+","+ny] = direction; route[nx + "," + ny] = direction;
break; break;
} }
// 不可通行 // 不可通行
if (core.noPass(nx, ny)) continue; if (core.noPass(nx, ny)) continue;
route[nx+","+ny] = direction; route[nx + "," + ny] = direction;
queue.queue({depth: deep + this._automaticRoute_deepAdd(nx, ny, blocks), x: nx, y: ny}); queue.queue({ depth: deep + this._automaticRoute_deepAdd(nx, ny, blocks), x: nx, y: ny });
} }
if (route[destX+","+destY] != null) break; if (route[destX + "," + destY] != null) break;
} }
return route; return route;
} }
@ -933,7 +933,7 @@ maps.prototype._automaticRoute_bfs = function (startX, startY, destX, destY) {
maps.prototype._automaticRoute_deepAdd = function (x, y, blocks) { maps.prototype._automaticRoute_deepAdd = function (x, y, blocks) {
// 判定每个可通行点的损耗值,越高越应该绕路 // 判定每个可通行点的损耗值,越高越应该绕路
var deepAdd = 1; var deepAdd = 1;
var block = blocks[x+","+y]; var block = blocks[x + "," + y];
if (block && !block.disable) { if (block && !block.disable) {
var id = block.event.id; var id = block.event.id;
// 绕过亮灯 // 绕过亮灯
@ -946,9 +946,9 @@ maps.prototype._automaticRoute_deepAdd = function (x, y, blocks) {
// if (block.event.trigger == 'changeFloor') deepAdd+=10; // if (block.event.trigger == 'changeFloor') deepAdd+=10;
} }
// 绕过存在伤害的地方 // 绕过存在伤害的地方
deepAdd += (core.status.checkBlock.damage[x+","+y]||0) * 100; deepAdd += (core.status.checkBlock.damage[x + "," + y] || 0) * 100;
// 绕过捕捉 // 绕过捕捉
if (core.status.checkBlock.ambush[x+","+y]) deepAdd += 1000; if (core.status.checkBlock.ambush[x + "," + y]) deepAdd += 1000;
return deepAdd; return deepAdd;
} }
@ -973,7 +973,7 @@ maps.prototype._getBigImageInfo = function (bigImage, face, animate) {
// case "right": dx = 32 - per_width; dy = 32 - per_height; break; // case "right": dx = 32 - per_width; dy = 32 - per_height; break;
} }
return {sx: sx, sy: sy, per_width: per_width, per_height: per_height, face: face, dx: dx, dy: dy}; return { sx: sx, sy: sy, per_width: per_width, per_height: per_height, face: face, dx: dx, dy: dy };
} }
////// 绘制一个图块 ////// ////// 绘制一个图块 //////
@ -1172,7 +1172,7 @@ maps.prototype.redrawMap = function () {
core.bigmap.canvas.forEach(function (one) { core.bigmap.canvas.forEach(function (one) {
core.clearMap(one); core.clearMap(one);
}); });
this._drawMap_drawAll(null, {redraw: true}); this._drawMap_drawAll(null, { redraw: true });
core.drawDamage(); core.drawDamage();
} }
@ -1232,7 +1232,7 @@ maps.prototype._drawMap_drawBlockInfo = function (ctx, block, blockInfo, arr, co
maps.prototype.drawBg = function (floorId, config) { maps.prototype.drawBg = function (floorId, config) {
floorId = floorId || core.status.floorId; floorId = floorId || core.status.floorId;
if (config == null) config = {}; if (config == null) config = {};
if (typeof config == 'string' || config.canvas) config = {ctx: config}; if (typeof config == 'string' || config.canvas) config = { ctx: config };
config = Object.assign({}, config); config = Object.assign({}, config);
if (config.ctx == null) { if (config.ctx == null) {
config.onMap = true; config.onMap = true;
@ -1286,7 +1286,7 @@ maps.prototype._drawBg_drawBackground = function (floorId, config) {
maps.prototype.drawEvents = function (floorId, blocks, config) { maps.prototype.drawEvents = function (floorId, blocks, config) {
floorId = floorId || core.status.floorId; floorId = floorId || core.status.floorId;
if (config == null) config = {}; if (config == null) config = {};
if (typeof config == 'string' || config.canvas) config = {ctx: config}; if (typeof config == 'string' || config.canvas) config = { ctx: config };
config = Object.assign({}, config); config = Object.assign({}, config);
if (config.ctx == null) { if (config.ctx == null) {
config.onMap = true; config.onMap = true;
@ -1342,7 +1342,7 @@ maps.prototype.drawEvents = function (floorId, blocks, config) {
maps.prototype.drawFg = function (floorId, config) { maps.prototype.drawFg = function (floorId, config) {
floorId = floorId || core.status.floorId; floorId = floorId || core.status.floorId;
if (config == null) config = {}; if (config == null) config = {};
if (typeof config == 'string' || config.canvas) config = {ctx: config}; if (typeof config == 'string' || config.canvas) config = { ctx: config };
config = Object.assign({}, config); config = Object.assign({}, config);
if (config.ctx == null) { if (config.ctx == null) {
config.onMap = true; config.onMap = true;
@ -1444,7 +1444,7 @@ maps.prototype._drawFloorImages_gif = function (image, dx, dy) {
maps.prototype._drawFloorImage = function (ctx, name, one, image, currStatus, onMap) { maps.prototype._drawFloorImage = function (ctx, name, one, image, currStatus, onMap) {
var height = image.height; var height = image.height;
var imageName = one.name + (one.reverse||''); var imageName = one.name + (one.reverse || '');
var width = parseInt((one.w == null ? image.width : one.w) / (one.frame || 1)); var width = parseInt((one.w == null ? image.width : one.w) / (one.frame || 1));
var height = one.h == null ? image.height : one.h; var height = one.h == null ? image.height : one.h;
var sx = (one.sx || 0) + (currStatus || 0) % (one.frame || 1) * width; var sx = (one.sx || 0) + (currStatus || 0) % (one.frame || 1) * width;
@ -1483,111 +1483,112 @@ maps.prototype._drawAutotile = function (ctx, mapArr, block, size, left, top, st
status = status || 0; status = status || 0;
status %= parseInt(autotile.width / 96); status %= parseInt(autotile.width / 96);
var done = {}; var done = {};
var isGrass = function(x,y){ var isGrass = function (x, y) {
if(core.maps._drawAutotile_getAutotileAroundId(mapArr[yy][xx],x,y,mapArr)){ if (core.maps._drawAutotile_getAutotileAroundId(mapArr[yy][xx], x, y, mapArr)) {
return 1; return 1;
}else{ } else {
return 0; return 0;
} }
} }
var iG = []; var iG = [];
[-1,0,1].forEach(function(_x){ [-1, 0, 1].forEach(function (_x) {
iG[_x] = []; iG[_x] = [];
[-1,0,1].forEach(function(_y){ [-1, 0, 1].forEach(function (_y) {
iG[_x][_y] = isGrass(xx + _x, yy + _y); iG[_x][_y] = isGrass(xx + _x, yy + _y);
})}); })
if(iG[-1][-1] + iG[0][-1] + iG[0][0] + iG[-1][0] == 3 && !iG[-1][-1]){ });
if (iG[-1][-1] + iG[0][-1] + iG[0][0] + iG[-1][0] == 3 && !iG[-1][-1]) {
this._drawAutotile_render(ctx, xx * size + left, yy * size + top, size, autotile, status, 16, null, onMap); this._drawAutotile_render(ctx, xx * size + left, yy * size + top, size, autotile, status, 16, null, onMap);
done[0] = true; done[0] = true;
} }
if(iG[0][-1] + iG[1][-1] + iG[1][0] + iG[0][0] == 3 && !iG[1][-1]){ if (iG[0][-1] + iG[1][-1] + iG[1][0] + iG[0][0] == 3 && !iG[1][-1]) {
this._drawAutotile_render(ctx, xx * size + left + size/2, yy * size + top, size, autotile, status, 17, null, onMap); this._drawAutotile_render(ctx, xx * size + left + size / 2, yy * size + top, size, autotile, status, 17, null, onMap);
done[1] = true; done[1] = true;
} }
if(iG[0][0] + iG[1][0] + iG[1][1] + iG[0][1] == 3 && !iG[1][1]){ if (iG[0][0] + iG[1][0] + iG[1][1] + iG[0][1] == 3 && !iG[1][1]) {
this._drawAutotile_render(ctx, xx * size + left+size/2, yy * size + top + size/2, size, autotile, status, 18, null, onMap); this._drawAutotile_render(ctx, xx * size + left + size / 2, yy * size + top + size / 2, size, autotile, status, 18, null, onMap);
done[3] = true; done[3] = true;
} }
if(iG[0-1][0] + iG[0][0] + iG[0][1] + iG[-1][1] == 3 && !iG[-1][1]){ if (iG[0 - 1][0] + iG[0][0] + iG[0][1] + iG[-1][1] == 3 && !iG[-1][1]) {
this._drawAutotile_render(ctx, xx * size + left, yy * size + top + size/2, size, autotile, status, 19, null, onMap); this._drawAutotile_render(ctx, xx * size + left, yy * size + top + size / 2, size, autotile, status, 19, null, onMap);
done[2] = true; done[2] = true;
} }
var _id = iG[0][-1] + 2 * iG[-1][0] + 4 * iG[0][1] + 8 * iG[1][0]; var _id = iG[0][-1] + 2 * iG[-1][0] + 4 * iG[0][1] + 8 * iG[1][0];
this._drawAutotile_render(ctx, xx * size, yy * size, size, autotile, status, _id, done, onMap); this._drawAutotile_render(ctx, xx * size, yy * size, size, autotile, status, _id, done, onMap);
} }
maps.prototype._drawAutotile_render = function(canvas, x, y, size, autotile, status, index, done, onMap) { maps.prototype._drawAutotile_render = function (canvas, x, y, size, autotile, status, index, done, onMap) {
if (onMap) { if (onMap) {
x -= 32 * core.bigmap.posX; x -= 32 * core.bigmap.posX;
y -= 32 * core.bigmap.posY; y -= 32 * core.bigmap.posY;
} }
var indexData = [[[96 * status, 0, 32, 32, x, y, size, size],], var indexData = [[[96 * status, 0, 32, 32, x, y, size, size],],
[[96 * status, 3 * 32, 16, 32, x, y, size / 2, size],[96 * status + 2 * 32 + 16, 3 * 32, 16, 32, x + size / 2, y, size / 2, size],], [[96 * status, 3 * 32, 16, 32, x, y, size / 2, size], [96 * status + 2 * 32 + 16, 3 * 32, 16, 32, x + size / 2, y, size / 2, size],],
[[96 * status + 2 * 32, 32, 32, 16, x, y, size, size / 2],[96 * status + 2 * 32, 3 * 32 + 16, 32, 16, x, y + size / 2, size, size / 2],], [[96 * status + 2 * 32, 32, 32, 16, x, y, size, size / 2], [96 * status + 2 * 32, 3 * 32 + 16, 32, 16, x, y + size / 2, size, size / 2],],
[[96 * status + 2 * 32, 3 * 32, 32, 32, x, y, size, size],], [[96 * status + 2 * 32, 3 * 32, 32, 32, x, y, size, size],],
[[96 * status, 32, 16, 32, x, y, size / 2, size],[96 * status + 2 * 32 + 16, 32, 16, 32, x + size / 2, y, size / 2, size],], [[96 * status, 32, 16, 32, x, y, size / 2, size], [96 * status + 2 * 32 + 16, 32, 16, 32, x + size / 2, y, size / 2, size],],
[[96 * status, 2 * 32, 16, 32, x, y, size / 2, size],[96 * status + 2 * 32 + 16, 2 * 32, 16, 32, x + size / 2, y, size / 2, size],], [[96 * status, 2 * 32, 16, 32, x, y, size / 2, size], [96 * status + 2 * 32 + 16, 2 * 32, 16, 32, x + size / 2, y, size / 2, size],],
[[96 * status + 2 * 32, 32, 32, 32, x, y, size, size],], [[96 * status + 2 * 32, 32, 32, 32, x, y, size, size],],
[[96 * status + 2 * 32, 2 * 32, 32, 32, x, y, size, size],], [[96 * status + 2 * 32, 2 * 32, 32, 32, x, y, size, size],],
[[96 * status, 32, 32, 16, x, y, size, size / 2],[96 * status, 3 * 32 + 16, 32, 16, x, y + size / 2, size, size / 2],], [[96 * status, 32, 32, 16, x, y, size, size / 2], [96 * status, 3 * 32 + 16, 32, 16, x, y + size / 2, size, size / 2],],
[[96 * status, 3 * 32, 32, 32, x, y, size, size],], [[96 * status, 3 * 32, 32, 32, x, y, size, size],],
[[96 * status + 32, 32, 32, 16, x, y, size, size / 2],[96 * status + 32, 3 * 32 + 16, 32, 16, x, y + size / 2, size, size / 2],], [[96 * status + 32, 32, 32, 16, x, y, size, size / 2], [96 * status + 32, 3 * 32 + 16, 32, 16, x, y + size / 2, size, size / 2],],
[[96 * status + 32, 3 * 32, 32, 32, x, y, size, size],], [[96 * status + 32, 3 * 32, 32, 32, x, y, size, size],],
[[96 * status, 32, 32, 32, x, y, size, size],], [[96 * status, 32, 32, 32, x, y, size, size],],
[[96 * status, 2 * 32, 32, 32, x, y, size, size],], [[96 * status, 2 * 32, 32, 32, x, y, size, size],],
[[96 * status + 32, 32, 32, 32, x, y, size, size],], [[96 * status + 32, 32, 32, 32, x, y, size, size],],
[[96 * status + 32, 2 * 32, 32, 32, x, y, size, size],], [[96 * status + 32, 2 * 32, 32, 32, x, y, size, size],],
[[96 * status + 2 * 32, 0, 16, 16, x, y, size / 2, size / 2],], [[96 * status + 2 * 32, 0, 16, 16, x, y, size / 2, size / 2],],
[[96 * status + 2 * 32 + 16, 0, 16, 16, x, y, size / 2, size / 2],], [[96 * status + 2 * 32 + 16, 0, 16, 16, x, y, size / 2, size / 2],],
[[96 * status + 2 * 32 + 16, 16, 16, 16, x, y, size / 2, size / 2],], [[96 * status + 2 * 32 + 16, 16, 16, 16, x, y, size / 2, size / 2],],
[[96 * status + 2 * 32, 16, 16, 16, x, y, size / 2, size / 2],], [[96 * status + 2 * 32, 16, 16, 16, x, y, size / 2, size / 2],],
]; ];
var data = indexData[index]; var data = indexData[index];
if(index>=16){ // 拐角直接绘制 if (index >= 16) { // 拐角直接绘制
core.drawImage(canvas, autotile, data[0][0], data[0][1], data[0][2], data[0][3], data[0][4], data[0][5], size/2, size/2); core.drawImage(canvas, autotile, data[0][0], data[0][1], data[0][2], data[0][3], data[0][4], data[0][5], size / 2, size / 2);
}else{ // 非拐角要根据是否已经绘制进行切分后绘制 } else { // 非拐角要根据是否已经绘制进行切分后绘制
this._drawAutotile_renderCut(canvas, autotile, x, y, size, data, done); this._drawAutotile_renderCut(canvas, autotile, x, y, size, data, done);
} }
} }
maps.prototype._drawAutotile_renderCut = function(canvas, autotile, x, y, size, data, done){ maps.prototype._drawAutotile_renderCut = function (canvas, autotile, x, y, size, data, done) {
var drawData = []; var drawData = [];
done = done || {}; done = done || {};
if(data.length == 2){ if (data.length == 2) {
var idx = 0; var idx = 0;
var cut = 0; var cut = 0;
for(var i in data){ for (var i in data) {
if(data[i][2] % 32){ // 是否纵切 if (data[i][2] % 32) { // 是否纵切
cut = 0; cut = 0;
} }
else if(data[i][3] % 32){ // 是否横切 else if (data[i][3] % 32) { // 是否横切
cut = 1; cut = 1;
} }
if(data[i][0] % 32 || data[i][1] % 32){ // right down if (data[i][0] % 32 || data[i][1] % 32) { // right down
idx = 1; idx = 1;
}else{ // left top } else { // left top
idx = 0; idx = 0;
} }
if(cut){ if (cut) {
idx *= 2; idx *= 2;
if(!done[idx])drawData[idx] = [data[i][0], data[i][1]]; if (!done[idx]) drawData[idx] = [data[i][0], data[i][1]];
if(!done[idx + 1])drawData[idx + 1] = [parseInt(data[i][0]) + 16, data[i][1]]; if (!done[idx + 1]) drawData[idx + 1] = [parseInt(data[i][0]) + 16, data[i][1]];
}else{ } else {
if(!done[idx])drawData[idx] = [data[i][0], data[i][1]]; if (!done[idx]) drawData[idx] = [data[i][0], data[i][1]];
if(!done[idx + 2])drawData[idx + 2] = [data[i][0], parseInt(data[i][1]) + 16]; if (!done[idx + 2]) drawData[idx + 2] = [data[i][0], parseInt(data[i][1]) + 16];
} }
} }
}else{ } else {
if(!done[0])drawData[0] = [data[0][0], data[0][1]]; if (!done[0]) drawData[0] = [data[0][0], data[0][1]];
if(!done[1])drawData[1] = [data[0][0] + 16, data[0][1]]; if (!done[1]) drawData[1] = [data[0][0] + 16, data[0][1]];
if(!done[2])drawData[2] = [data[0][0], data[0][1] + 16]; if (!done[2]) drawData[2] = [data[0][0], data[0][1] + 16];
if(!done[3])drawData[3] = [data[0][0] + 16, data[0][1] + 16]; if (!done[3]) drawData[3] = [data[0][0] + 16, data[0][1] + 16];
} }
for(var i = 0; i<4; i++){ for (var i = 0; i < 4; i++) {
var dt = drawData[i];if(!dt)continue; var dt = drawData[i]; if (!dt) continue;
core.drawImage(canvas, autotile, dt[0], dt[1], 16, 16, x + (i % 2) * size / 2, y + parseInt(i / 2) * size / 2, size/2, size/2); core.drawImage(canvas, autotile, dt[0], dt[1], 16, 16, x + (i % 2) * size / 2, y + parseInt(i / 2) * size / 2, size / 2, size / 2);
}; };
} }
@ -1642,12 +1643,12 @@ maps.prototype._drawAutotileAnimate = function (block, animate) {
} }
} else { } else {
if (32 * x < core.bigmap.offsetX - 64 || 32 * x > core.bigmap.offsetX + core.__PIXELS__ + 32 if (32 * x < core.bigmap.offsetX - 64 || 32 * x > core.bigmap.offsetX + core.__PIXELS__ + 32
|| 32 * y < core.bigmap.offsetY - 64 || 32 * y > core.bigmap.offsetY + core.__PIXELS__ + 32 + 16) { || 32 * y < core.bigmap.offsetY - 64 || 32 * y > core.bigmap.offsetY + core.__PIXELS__ + 32 + 16) {
return; return;
} }
} }
var cv = block.name?core.canvas[block.name]:core.canvas.event; var cv = block.name ? core.canvas[block.name] : core.canvas.event;
cv.clearRect(32 * x - 32 * core.bigmap.posX, 32 * y - 32 * core.bigmap.posY, 32, 32); cv.clearRect(32 * x - 32 * core.bigmap.posX, 32 * y - 32 * core.bigmap.posY, 32, 32);
var alpha = null; var alpha = null;
if (block.opacity != null) alpha = core.setAlpha(cv, block.opacity); if (block.opacity != null) alpha = core.setAlpha(cv, block.opacity);
@ -1710,7 +1711,7 @@ maps.prototype.drawThumbnail = function (floorId, blocks, options) {
floorId = floorId || core.status.floorId; floorId = floorId || core.status.floorId;
if (!floorId) return; if (!floorId) return;
options = options || {}; options = options || {};
if (typeof options == 'string' || options.canvas) options = {ctx: options}; if (typeof options == 'string' || options.canvas) options = { ctx: options };
var ctx = options.ctx; var ctx = options.ctx;
// Step1绘制到tempCanvas上 // Step1绘制到tempCanvas上
this._drawThumbnail_drawTempCanvas(floorId, blocks, options); this._drawThumbnail_drawTempCanvas(floorId, blocks, options);
@ -1861,9 +1862,9 @@ maps.prototype.terrainExists = function (x, y, id, floorId) {
maps.prototype.stairExists = function (x, y, floorId) { maps.prototype.stairExists = function (x, y, floorId) {
var blockId = this.getBlockId(x, y, floorId); var blockId = this.getBlockId(x, y, floorId);
if (blockId == null) return false; if (blockId == null) return false;
var ids = ['upFloor','downFloor']; var ids = ['upFloor', 'downFloor'];
ids = ids.concat(['leftPortal','rightPortal','upPortal','downPortal','portal','starPortal']); ids = ids.concat(['leftPortal', 'rightPortal', 'upPortal', 'downPortal', 'portal', 'starPortal']);
return ids.indexOf(blockId)>=0; return ids.indexOf(blockId) >= 0;
} }
////// 当前位置是否在楼梯边 ////// ////// 当前位置是否在楼梯边 //////
@ -1920,7 +1921,7 @@ maps.prototype.getBlockOpacity = function (x, y, floorId, showDisable) {
maps.prototype.getBlockFilter = function (x, y, floorId, showDisable) { maps.prototype.getBlockFilter = function (x, y, floorId, showDisable) {
var block = core.getBlock(x, y, floorId, showDisable); var block = core.getBlock(x, y, floorId, showDisable);
if (block == null) return null; if (block == null) return null;
if (block.filter == null) return {blur: 0, hue: 0, grayscale: 0, invert: false, shadow: 0}; if (block.filter == null) return { blur: 0, hue: 0, grayscale: 0, invert: false, shadow: 0 };
return core.clone(block.filter); return core.clone(block.filter);
} }
@ -1975,8 +1976,10 @@ maps.prototype.getBlockInfo = function (block) {
if (!doorInfo && bigImage != null) animate = 4; if (!doorInfo && bigImage != null) animate = 4;
} }
return {number: number, id: id, cls: cls, name: name, image: image, posX: posX, doorInfo: doorInfo, return {
posY: posY, height: height, faceIds: faceIds, animate: animate, face: face, bigImage: bigImage}; number: number, id: id, cls: cls, name: name, image: image, posX: posX, doorInfo: doorInfo,
posY: posY, height: height, faceIds: faceIds, animate: animate, face: face, bigImage: bigImage
};
} }
////// 搜索某个图块出现的所有位置 ////// ////// 搜索某个图块出现的所有位置 //////
@ -1994,7 +1997,7 @@ maps.prototype.searchBlock = function (id, floorId, showDisable) {
for (var i = 0; i < core.status.maps[floorId].blocks.length; ++i) { for (var i = 0; i < core.status.maps[floorId].blocks.length; ++i) {
var block = core.status.maps[floorId].blocks[i]; var block = core.status.maps[floorId].blocks[i];
if ((showDisable || !block.disable) && (core.matchWildcard(id, block.event.id) || core.matchRegex(id, block.event.id))) { if ((showDisable || !block.disable) && (core.matchWildcard(id, block.event.id) || core.matchRegex(id, block.event.id))) {
result.push({floorId: floorId, x: block.x, y: block.y, block: block}); result.push({ floorId: floorId, x: block.x, y: block.y, block: block });
} }
} }
return result; return result;
@ -2014,7 +2017,7 @@ maps.prototype.searchBlockWithFilter = function (blockFilter, floorId, showDisab
for (var i = 0; i < core.status.maps[floorId].blocks.length; ++i) { for (var i = 0; i < core.status.maps[floorId].blocks.length; ++i) {
var block = core.status.maps[floorId].blocks[i]; var block = core.status.maps[floorId].blocks[i];
if ((showDisable || !block.disable) && blockFilter(block)) { if ((showDisable || !block.disable) && blockFilter(block)) {
result.push({floorId: floorId, x: block.x, y: block.y, block: block}); result.push({ floorId: floorId, x: block.x, y: block.y, block: block });
} }
} }
return result; return result;
@ -2141,7 +2144,7 @@ maps.prototype.removeBlockByIndex = function (index, floorId) {
var blocks = core.status.maps[floorId].blocks, block = blocks[index]; var blocks = core.status.maps[floorId].blocks, block = blocks[index];
blocks.splice(index, 1); blocks.splice(index, 1);
if (core.status.mapBlockObjs[floorId]) if (core.status.mapBlockObjs[floorId])
delete core.status.mapBlockObjs[floorId][block.x+","+block.y]; delete core.status.mapBlockObjs[floorId][block.x + "," + block.y];
core.setMapBlockDisabled(floorId, block.x, block.y, true); core.setMapBlockDisabled(floorId, block.x, block.y, true);
this._updateMapArray(floorId, block.x, block.y); this._updateMapArray(floorId, block.x, block.y);
} }
@ -2175,16 +2178,16 @@ maps.prototype._triggerBgFgMap = function (type, name, loc, floorId, callback) {
if (!floorId) return; if (!floorId) return;
if (loc.length == 0) return; if (loc.length == 0) return;
var disabled = core.getFlag('__'+name+'d__', {}); var disabled = core.getFlag('__' + name + 'd__', {});
disabled[floorId] = disabled[floorId] || []; disabled[floorId] = disabled[floorId] || [];
loc.forEach(function (t) { loc.forEach(function (t) {
if (type == 'hide') { if (type == 'hide') {
disabled[floorId].push([t[0], t[1]]); disabled[floorId].push([t[0], t[1]]);
} else { } else {
disabled[floorId] = disabled[floorId].filter(function (one) { return one[0] != t[0] || one[1] != t[1]}); disabled[floorId] = disabled[floorId].filter(function (one) { return one[0] != t[0] || one[1] != t[1] });
} }
}) })
core.setFlag('__'+name+'d__', disabled); core.setFlag('__' + name + 'd__', disabled);
core.status[name + "maps"][floorId] = null; core.status[name + "maps"][floorId] = null;
@ -2247,7 +2250,7 @@ maps.prototype.setBlock = function (number, x, y, floorId) {
if (originBlock == null) { if (originBlock == null) {
core.status.maps[floorId].blocks.push(block); core.status.maps[floorId].blocks.push(block);
if (core.status.mapBlockObjs[floorId]) if (core.status.mapBlockObjs[floorId])
core.status.mapBlockObjs[floorId][block.x+","+block.y] = block; core.status.mapBlockObjs[floorId][block.x + "," + block.y] = block;
core.setMapBlockDisabled(floorId, block.x, block.y, false); core.setMapBlockDisabled(floorId, block.x, block.y, false);
delete block.disable; delete block.disable;
} }
@ -2263,7 +2266,7 @@ maps.prototype.setBlock = function (number, x, y, floorId) {
core.redrawMap(); core.redrawMap();
} else { } else {
if (originEvent != null) { if (originEvent != null) {
this._removeBlockFromMap(floorId, {x: x, y: y, event: originEvent}); this._removeBlockFromMap(floorId, { x: x, y: y, event: originEvent });
} }
if (!block.disable) { if (!block.disable) {
core.drawBlock(block); core.drawBlock(block);
@ -2357,7 +2360,7 @@ maps.prototype.animateSetBlocks = function (number, locs, floorId, time, callbac
return; return;
} }
if (typeof locs[0] == 'number' && typeof locs[1] == 'number') if (typeof locs[0] == 'number' && typeof locs[1] == 'number')
locs = [locs]; locs = [locs];
var count = locs.length; var count = locs.length;
var _afterSet = function () { var _afterSet = function () {
@ -2426,14 +2429,16 @@ maps.prototype.setBgFgBlock = function (name, number, x, y, floorId) {
else number = core.getNumberById(number); else number = core.getNumberById(number);
} }
var values = core.getFlag('__'+name+'v__', {}); var values = core.getFlag('__' + name + 'v__', {});
values[floorId] = (values[floorId] || []).filter(function (one) { return one[0] != x || one[1] != y }); values[floorId] = (values[floorId] || []).filter(function (one) { return one[0] != x || one[1] != y });
values[floorId].push([x,y,number]); values[floorId].push([x, y, number]);
core.setFlag('__'+name+'v__', values); core.setFlag('__' + name + 'v__', values);
core.status[name + "maps"][floorId] = null; core.status[name + "maps"][floorId] = null;
if (floorId == core.status.floorId){ this._getBgFgMapArray(name, floorId, true);
if (floorId == core.status.floorId) {
core.clearMap(name); core.clearMap(name);
if (name.startsWith('bg')) core.drawBg(floorId); if (name.startsWith('bg')) core.drawBg(floorId);
else core.drawFg(floorId); else core.drawFg(floorId);
@ -2574,10 +2579,10 @@ maps.prototype.moveBlock = function (x, y, steps, time, keep, callback) {
return; return;
} }
var block = blockArr[0], blockInfo = blockArr[1]; var block = blockArr[0], blockInfo = blockArr[1];
var moveSteps = (steps||[]).map(function (t) { var moveSteps = (steps || []).map(function (t) {
return [t.split(':')[0], parseInt(t.split(':')[1]||"1")]; return [t.split(':')[0], parseInt(t.split(':')[1] || "1")];
}).filter(function (t) { }).filter(function (t) {
return ['up','down','left','right','forward','backward','leftup','leftdown','rightup','rightdown','speed'].indexOf(t[0])>=0 return ['up', 'down', 'left', 'right', 'forward', 'backward', 'leftup', 'leftdown', 'rightup', 'rightdown', 'speed'].indexOf(t[0]) >= 0
&& !(t[0] == 'speed' && t[1] < 16) && !(t[0] == 'speed' && t[1] < 16)
}); });
var canvases = this._initDetachedBlock(blockInfo, x, y, block.event.animate !== false); var canvases = this._initDetachedBlock(blockInfo, x, y, block.event.animate !== false);
@ -2706,7 +2711,7 @@ maps.prototype._moveBlock_moving = function (blockInfo, canvases, moveInfo) {
if (moveInfo.step == 16) { if (moveInfo.step == 16) {
moveInfo.step = 0; moveInfo.step = 0;
moveInfo.moveSteps[0][1]--; moveInfo.moveSteps[0][1]--;
if (moveInfo.moveSteps[0][1]<=0) { if (moveInfo.moveSteps[0][1] <= 0) {
moveInfo.moveSteps.shift(); moveInfo.moveSteps.shift();
} }
} }
@ -2977,7 +2982,7 @@ maps.prototype.drawAnimate = function (name, x, y, alignWindow, callback) {
centerY += core.bigmap.offsetY; centerY += core.bigmap.offsetY;
} }
animate.se = animate.se || {}; animate.se = animate.se || {};
if (typeof animate.se == 'string') animate.se = {1: animate.se}; if (typeof animate.se == 'string') animate.se = { 1: animate.se };
var id = setTimeout(null); var id = setTimeout(null);
core.status.animateObjs.push({ core.status.animateObjs.push({
@ -3006,7 +3011,7 @@ maps.prototype.drawHeroAnimate = function (name, callback) {
// 开始绘制 // 开始绘制
var animate = core.material.animates[name]; var animate = core.material.animates[name];
animate.se = animate.se || {}; animate.se = animate.se || {};
if (typeof animate.se == 'string') animate.se = {1: animate.se}; if (typeof animate.se == 'string') animate.se = { 1: animate.se };
var id = setTimeout(null); var id = setTimeout(null);
core.status.animateObjs.push({ core.status.animateObjs.push({
@ -3033,7 +3038,7 @@ maps.prototype._drawAnimateFrame = function (name, animate, centerX, centerY, in
var ctx = core.getContextByName(name); var ctx = core.getContextByName(name);
if (!ctx) return; if (!ctx) return;
var frame = animate.frames[index % animate.frame]; var frame = animate.frames[index % animate.frame];
core.playSound((animate.se||{})[index % animate.frame + 1], (animate.pitch||{})[index % animate.frame + 1]); core.playSound((animate.se || {})[index % animate.frame + 1], (animate.pitch || {})[index % animate.frame + 1]);
var ratio = animate.ratio; var ratio = animate.ratio;
frame.forEach(function (t) { frame.forEach(function (t) {
var image = animate.images[t.index]; var image = animate.images[t.index];

File diff suppressed because one or more lines are too long

View File

@ -7,23 +7,23 @@ utils.js 工具类
"use strict"; "use strict";
function utils() { function utils () {
this._init(); this._init();
this.scan = { this.scan = {
'up': {'x': 0, 'y': -1}, 'up': { 'x': 0, 'y': -1 },
'left': {'x': -1, 'y': 0}, 'left': { 'x': -1, 'y': 0 },
'down': {'x': 0, 'y': 1}, 'down': { 'x': 0, 'y': 1 },
'right': {'x': 1, 'y': 0} 'right': { 'x': 1, 'y': 0 }
}; };
this.scan2 = { this.scan2 = {
'up': {'x': 0, 'y': -1}, 'up': { 'x': 0, 'y': -1 },
'left': {'x': -1, 'y': 0}, 'left': { 'x': -1, 'y': 0 },
'down': {'x': 0, 'y': 1}, 'down': { 'x': 0, 'y': 1 },
'right': {'x': 1, 'y': 0}, 'right': { 'x': 1, 'y': 0 },
'leftup': {'x': -1, 'y': -1}, 'leftup': { 'x': -1, 'y': -1 },
'leftdown': {'x': -1, 'y': 1}, 'leftdown': { 'x': -1, 'y': 1 },
'rightup': {'x': 1, 'y': -1}, 'rightup': { 'x': 1, 'y': -1 },
'rightdown': {'x': 1, 'y': 1} 'rightdown': { 'x': 1, 'y': 1 }
}; };
} }
@ -105,7 +105,7 @@ utils.prototype.replaceText = function (text, prefix) {
if (cnt == 0) break; if (cnt == 0) break;
} }
if (cnt != 0) return text; if (cnt != 0) return text;
var value = core.calValue(text.substring(index+2, curr), prefix); var value = core.calValue(text.substring(index + 2, curr), prefix);
if (value == null) value = ""; if (value == null) value = "";
return text.substring(0, index) + value + core.replaceText(text.substring(curr + 1), prefix); return text.substring(0, index) + value + core.replaceText(text.substring(curr + 1), prefix);
} }
@ -124,17 +124,17 @@ utils.prototype.replaceValue = function (value) {
// value = value.replace(/switch:([a-zA-Z0-9_]+)/g, "core.getFlag('" + (prefix || ":f@x@y") + "@$1', 0)"); // value = value.replace(/switch:([a-zA-Z0-9_]+)/g, "core.getFlag('" + (prefix || ":f@x@y") + "@$1', 0)");
if (value.indexOf('global:') >= 0 || value.indexOf('global') >= 0) if (value.indexOf('global:') >= 0 || value.indexOf('global') >= 0)
value = value.replace(/global[:]([a-zA-Z0-9_\u4E00-\u9FCC\u3040-\u30FF\u2160-\u216B\u0391-\u03C9]+)/g, "core.getGlobal('$1', 0)"); value = value.replace(/global[:]([a-zA-Z0-9_\u4E00-\u9FCC\u3040-\u30FF\u2160-\u216B\u0391-\u03C9]+)/g, "core.getGlobal('$1', 0)");
if (value.indexOf('enemy:')>=0) if (value.indexOf('enemy:') >= 0)
value = value.replace(/enemy:([a-zA-Z0-9_]+)[\.:]([a-zA-Z0-9_]+)/g, "core.material.enemys['$1'].$2"); value = value.replace(/enemy:([a-zA-Z0-9_]+)[\.:]([a-zA-Z0-9_]+)/g, "core.material.enemys['$1'].$2");
if (value.indexOf('blockId:')>=0) if (value.indexOf('blockId:') >= 0)
value = value.replace(/blockId:(\d+),(\d+)/g, "core.getBlockId($1, $2)"); value = value.replace(/blockId:(\d+),(\d+)/g, "core.getBlockId($1, $2)");
if (value.indexOf('blockNumber:')>=0) if (value.indexOf('blockNumber:') >= 0)
value = value.replace(/blockNumber:(\d+),(\d+)/g, "core.getBlockNumber($1, $2)"); value = value.replace(/blockNumber:(\d+),(\d+)/g, "core.getBlockNumber($1, $2)");
if (value.indexOf('blockCls:')>=0) if (value.indexOf('blockCls:') >= 0)
value = value.replace(/blockCls:(\d+),(\d+)/g, "core.getBlockCls($1, $2)"); value = value.replace(/blockCls:(\d+),(\d+)/g, "core.getBlockCls($1, $2)");
if (value.indexOf('equip:')>=0) if (value.indexOf('equip:') >= 0)
value = value.replace(/equip:(\d)/g, "core.getEquip($1)"); value = value.replace(/equip:(\d)/g, "core.getEquip($1)");
if (value.indexOf('temp:')>=0) if (value.indexOf('temp:') >= 0)
value = value.replace(/temp:([a-zA-Z0-9_]+)/g, "core.getFlag('@temp@$1', 0)"); value = value.replace(/temp:([a-zA-Z0-9_]+)/g, "core.getFlag('@temp@$1', 0)");
} }
return value; return value;
@ -145,7 +145,7 @@ utils.prototype.calValue = function (value, prefix) {
if (!core.isset(value)) return null; if (!core.isset(value)) return null;
if (typeof value === 'string') { if (typeof value === 'string') {
if (value.indexOf(':') >= 0 || value.indexOf("flag") >= 0 || value.indexOf('global') >= 0) { if (value.indexOf(':') >= 0 || value.indexOf("flag") >= 0 || value.indexOf('global') >= 0) {
if (value.indexOf('switch:' >= 0)) if (value.indexOf('switch:') >= 0)
value = value.replace(/switch:([a-zA-Z0-9_]+)/g, "core.getFlag('" + (prefix || ":f@x@y") + "@$1', 0)"); value = value.replace(/switch:([a-zA-Z0-9_]+)/g, "core.getFlag('" + (prefix || ":f@x@y") + "@$1', 0)");
value = this.replaceValue(value); value = this.replaceValue(value);
} }
@ -426,7 +426,7 @@ utils.prototype.clone = function (data, filter, recursion) {
var copy = []; var copy = [];
for (var i in data) { for (var i in data) {
if (!filter || filter(i, data[i])) if (!filter || filter(i, data[i]))
copy[i] = core.clone(data[i], recursion?filter:null, recursion); copy[i] = core.clone(data[i], recursion ? filter : null, recursion);
} }
return copy; return copy;
} }
@ -439,7 +439,7 @@ utils.prototype.clone = function (data, filter, recursion) {
var copy = {}; var copy = {};
for (var i in data) { for (var i in data) {
if (data.hasOwnProperty(i) && (!filter || filter(i, data[i]))) if (data.hasOwnProperty(i) && (!filter || filter(i, data[i])))
copy[i] = core.clone(data[i], recursion?filter:null, recursion); copy[i] = core.clone(data[i], recursion ? filter : null, recursion);
} }
return copy; return copy;
} }
@ -496,9 +496,9 @@ utils.prototype.formatDate2 = function (date) {
} }
utils.prototype.formatTime = function (time) { utils.prototype.formatTime = function (time) {
return core.setTwoDigits(parseInt(time/3600000)) return core.setTwoDigits(parseInt(time / 3600000))
+":"+core.setTwoDigits(parseInt(time/60000)%60) + ":" + core.setTwoDigits(parseInt(time / 60000) % 60)
+":"+core.setTwoDigits(parseInt(time/1000)%60); + ":" + core.setTwoDigits(parseInt(time / 1000) % 60);
} }
////// 两位数显示 ////// ////// 两位数显示 //////
@ -508,27 +508,27 @@ utils.prototype.setTwoDigits = function (x) {
utils.prototype.formatSize = function (size) { utils.prototype.formatSize = function (size) {
if (size < 1024) return size + 'B'; if (size < 1024) return size + 'B';
else if (size < 1024 * 1024) return (size/1024).toFixed(2) + "KB"; else if (size < 1024 * 1024) return (size / 1024).toFixed(2) + "KB";
else return (size/1024/1024).toFixed(2) + "MB"; else return (size / 1024 / 1024).toFixed(2) + "MB";
} }
utils.prototype.formatBigNumber = function (x, digits) { utils.prototype.formatBigNumber = function (x, digits) {
if (digits === true) digits = 5; // 兼容旧版onMap参数 if (digits === true) digits = 5; // 兼容旧版onMap参数
if (!digits || digits < 5) digits = 6; // 连同负号、小数点和后缀字母在内的总位数至少需为5默认为6 if (!digits || digits < 5) digits = 6; // 连同负号、小数点和后缀字母在内的总位数至少需为5默认为6
x = Math.trunc(parseFloat(x)); // 尝试识别为小数然后向0取整 x = Math.trunc(parseFloat(x)); // 尝试识别为小数然后向0取整
if (x == null || !Number.isFinite(x)) return '???'; // 无法识别的数或正负无穷大,显示'???' if (x == null || !Number.isFinite(x)) return '???'; // 无法识别的数或正负无穷大,显示'???'
var units = [ // 单位及其后缀字母可自定义如改成千进制下的K、M、G、T、P var units = [ // 单位及其后缀字母可自定义如改成千进制下的K、M、G、T、P
{ "val": 1e4, "suffix": "w" }, { "val": 1e4, "suffix": "w" },
{ "val": 1e8, "suffix": "e" }, { "val": 1e8, "suffix": "e" },
{ "val": 1e12, "suffix": "z" }, { "val": 1e12, "suffix": "z" },
{ "val": 1e16, "suffix": "j" }, { "val": 1e16, "suffix": "j" },
{ "val": 1e20, "suffix": "g" }, { "val": 1e20, "suffix": "g" },
]; ];
if (Math.abs(x) > 1e20 * Math.pow(10, digits - 2)) if (Math.abs(x) > 1e20 * Math.pow(10, digits - 2))
return x.toExponential(0); // 绝对值过大以致于失去精度的数,直接使用科学记数法,系数只保留整数 return x.toExponential(0); // 绝对值过大以致于失去精度的数,直接使用科学记数法,系数只保留整数
var sign = x < 0 ? '-' : ''; var sign = x < 0 ? '-' : '';
if (sign) --digits; // 符号位单独处理,负号要占一位 if (sign) --digits; // 符号位单独处理,负号要占一位
x = Math.abs(x); x = Math.abs(x);
if (x < Math.pow(10, digits)) return sign + x; if (x < Math.pow(10, digits)) return sign + x;
@ -539,24 +539,24 @@ utils.prototype.formatBigNumber = function (x, digits) {
u = u.substring(0, u[u.length - 2] == '.' ? u.length - 2 : u.length - 1); u = u.substring(0, u[u.length - 2] == '.' ? u.length - 2 : u.length - 1);
return sign + u + each.suffix; return sign + u + each.suffix;
} }
return sign + x.toExponential(0); return sign + x.toExponential(0);
} }
////// 变速移动 ////// ////// 变速移动 //////
utils.prototype.applyEasing = function(name) { utils.prototype.applyEasing = function (name) {
var list = { var list = {
"easeIn": function(t) { "easeIn": function (t) {
return Math.pow(t, 3); return Math.pow(t, 3);
}, },
"easeOut": function(t) { "easeOut": function (t) {
return 1 - Math.pow(1 - t, 3); return 1 - Math.pow(1 - t, 3);
}, },
"easeInOut": function(t) { "easeInOut": function (t) {
// easeInOut试了一下感觉二次方效果明显点 // easeInOut试了一下感觉二次方效果明显点
if (t < 0.5) return Math.pow(t, 2) * 2; if (t < 0.5) return Math.pow(t, 2) * 2;
else return 1 - Math.pow(1 - t, 2) * 2; else return 1 - Math.pow(1 - t, 2) * 2;
}, },
"linear": function(t) { "linear": function (t) {
return t return t
} }
} }
@ -659,7 +659,7 @@ utils.prototype._encodeRoute_encodeOne = function (t) {
return 'k' + t.substring(6); return 'k' + t.substring(6);
else if (t.indexOf('random:') == 0) else if (t.indexOf('random:') == 0)
return 'X' + t.substring(7); return 'X' + t.substring(7);
return '('+t+')'; return '(' + t + ')';
} }
////// 解密路线 ////// ////// 解密路线 //////
@ -676,7 +676,7 @@ utils.prototype.decodeRoute = function (route) {
} catch (e) { } catch (e) {
} }
var decodeObj = {route: route, index: 0, ans: []}; var decodeObj = { route: route, index: 0, ans: [] };
while (decodeObj.index < decodeObj.route.length) { while (decodeObj.index < decodeObj.route.length) {
this._decodeRoute_decodeOne(decodeObj, decodeObj.route.charAt(decodeObj.index++)); this._decodeRoute_decodeOne(decodeObj, decodeObj.route.charAt(decodeObj.index++));
} }
@ -728,7 +728,7 @@ utils.prototype._decodeRoute_decodeOne = function (decodeObj, c) {
var nxt = (c == 'I' || c == 'e' || c == 'F' || c == 'S' || c == 'Q' || c == 't') ? var nxt = (c == 'I' || c == 'e' || c == 'F' || c == 'S' || c == 'Q' || c == 't') ?
this._decodeRoute_getString(decodeObj) : this._decodeRoute_getNumber(decodeObj); this._decodeRoute_getString(decodeObj) : this._decodeRoute_getNumber(decodeObj);
var mp = {"U": "up", "D": "down", "L": "left", "R": "right"}; var mp = { "U": "up", "D": "down", "L": "left", "R": "right" };
switch (c) { switch (c) {
case "U": case "U":
@ -797,7 +797,7 @@ utils.prototype._decodeRoute_decodeOne = function (decodeObj, c) {
var px = this._decodeRoute_getNumber(decodeObj); var px = this._decodeRoute_getNumber(decodeObj);
++decodeObj.index; ++decodeObj.index;
var py = this._decodeRoute_getNumber(decodeObj); var py = this._decodeRoute_getNumber(decodeObj);
decodeObj.ans.push("click:"+nxt+":"+px+":"+py); decodeObj.ans.push("click:" + nxt + ":" + px + ":" + py);
break; break;
case "X": case "X":
decodeObj.ans.push("random:" + nxt); decodeObj.ans.push("random:" + nxt);
@ -1030,7 +1030,7 @@ utils.prototype.readFileContent = function (content) {
// 检查base64 // 检查base64
try { try {
obj = JSON.parse(LZString.decompressFromBase64(content)); obj = JSON.parse(LZString.decompressFromBase64(content));
} catch (e) {} } catch (e) { }
if (!obj) { if (!obj) {
try { try {
obj = JSON.parse(content); obj = JSON.parse(content);
@ -1090,7 +1090,7 @@ utils.prototype.download = function (filename, content) {
// Step 3: 如果是Safari浏览器则提示并打开新窗口 // Step 3: 如果是Safari浏览器则提示并打开新窗口
if (core.platform.isSafari) { if (core.platform.isSafari) {
alert("你当前使用的是Safari浏览器不支持直接下载文件。\n即将打开一个新窗口为应下载内容请自行全选复制然后创建空白文件并粘贴。"); alert("你当前使用的是Safari浏览器不支持直接下载文件。\n即将打开一个新窗口为应下载内容请自行全选复制然后创建空白文件并粘贴。");
var blob = new Blob([content], {type: 'text/plain;charset=utf-8'}); var blob = new Blob([content], { type: 'text/plain;charset=utf-8' });
var href = window.URL.createObjectURL(blob); var href = window.URL.createObjectURL(blob);
var opened = window.open(href, "_blank"); var opened = window.open(href, "_blank");
window.URL.revokeObjectURL(href); window.URL.revokeObjectURL(href);
@ -1098,7 +1098,7 @@ utils.prototype.download = function (filename, content) {
} }
// Step 4: 下载 // Step 4: 下载
var blob = new Blob([content], {type: 'text/plain;charset=utf-8'}); var blob = new Blob([content], { type: 'text/plain;charset=utf-8' });
if (window.navigator.msSaveOrOpenBlob) { if (window.navigator.msSaveOrOpenBlob) {
window.navigator.msSaveBlob(blob, filename); window.navigator.msSaveBlob(blob, filename);
} }
@ -1168,7 +1168,7 @@ utils.prototype.myprompt = function (hint, value, callback) {
main.dom.inputDiv.style.display = 'block'; main.dom.inputDiv.style.display = 'block';
main.dom.inputMessage.innerHTML = hint.replace(/\n/g, '<br/>'); main.dom.inputMessage.innerHTML = hint.replace(/\n/g, '<br/>');
main.dom.inputBox.style.display = 'block'; main.dom.inputBox.style.display = 'block';
main.dom.inputBox.value = value==null?"":value; main.dom.inputBox.value = value == null ? "" : value;
main.dom.inputYes.blur(); main.dom.inputYes.blur();
main.dom.inputNo.blur(); main.dom.inputNo.blur();
setTimeout(function () { setTimeout(function () {
@ -1350,7 +1350,7 @@ utils.prototype.http = function (type, url, formData, success, error, mimeType,
// LZW-compress // LZW-compress
// https://gist.github.com/revolunet/843889 // https://gist.github.com/revolunet/843889
function lzw_encode(s) { function lzw_encode (s) {
var dict = {}; var dict = {};
var data = (s + "").split(""); var data = (s + "").split("");
var out = []; var out = [];
@ -1377,7 +1377,7 @@ function lzw_encode(s) {
} }
// Decompress an LZW-encoded string // Decompress an LZW-encoded string
function lzw_decode(s) { function lzw_decode (s) {
var dict = {}; var dict = {};
var data = (s + "").split(""); var data = (s + "").split("");
var currChar = data[0]; var currChar = data[0];