polyfill & kill bug
This commit is contained in:
parent
01fbd7647c
commit
4a801cbc85
@ -189,6 +189,7 @@
|
||||
</div>
|
||||
</div>
|
||||
<!-- injection -->
|
||||
<script src='libs/thirdparty/browser-polyfill.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/localforage.min.js'></script>
|
||||
|
||||
278
libs/events.js
278
libs/events.js
@ -2,7 +2,7 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
function events() {
|
||||
function events () {
|
||||
this._init();
|
||||
}
|
||||
|
||||
@ -61,7 +61,7 @@ events.prototype._startGame_start = function (hard, seed, route, callback) {
|
||||
core.dom.enlargeBtn.style.display = 'block';
|
||||
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);
|
||||
this.insertAction(todo, null, null, function () {
|
||||
core.events._startGame_afterStart(callback);
|
||||
@ -78,7 +78,7 @@ events.prototype._startGame_setHard = function () {
|
||||
main.levelChoose.forEach(function (one) {
|
||||
if (one.name == core.status.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);
|
||||
}
|
||||
});
|
||||
@ -162,8 +162,8 @@ events.prototype._gameOver_confirmUpload = function (ending, norank) {
|
||||
else {
|
||||
var id = core.getCookie('id') || "";
|
||||
var hint = "请输入你的ID:\n(登录状态下输入数字用户编号可成为蓝名成绩并计入用户通关数)";
|
||||
if (id) hint = "请输入你的ID:\n(输入数字用户编号"+id+ "可成为蓝名成绩并计入用户通关数)";
|
||||
core.myprompt(hint, id, function (username) {
|
||||
if (id) hint = "请输入你的ID:\n(输入数字用户编号" + id + "可成为蓝名成绩并计入用户通关数)";
|
||||
core.myprompt(hint, id, function (username) {
|
||||
core.events._gameOver_doUpload(username, ending, norank);
|
||||
});
|
||||
}
|
||||
@ -220,7 +220,7 @@ events.prototype._gameOver_confirmDownload = function (ending) {
|
||||
'seed': core.getFlag('__seed__'),
|
||||
'route': core.encodeRoute(core.status.route)
|
||||
}
|
||||
core.download(core.firstData.name + "_" + core.formatDate2(new Date()) + ".h5route",
|
||||
core.download(core.firstData.name + "_" + core.formatDate2(new Date()) + ".h5route",
|
||||
LZString.compressToBase64(JSON.stringify(obj)));
|
||||
core.events._gameOver_askRate(ending);
|
||||
}, function () {
|
||||
@ -272,7 +272,7 @@ events.prototype._gameOver_askRate = function (ending) {
|
||||
}
|
||||
|
||||
////// 重新开始游戏;此函数将回到标题页面 //////
|
||||
events.prototype.restart = function() {
|
||||
events.prototype.restart = function () {
|
||||
core.showStartAnimate();
|
||||
core.playBgm(main.startBgm);
|
||||
}
|
||||
@ -313,7 +313,7 @@ events.prototype.doSystemEvent = function (type, data, callback) {
|
||||
}
|
||||
catch (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);
|
||||
@ -333,7 +333,7 @@ events.prototype.trigger = function (x, y, callback) {
|
||||
}
|
||||
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},
|
||||
core.insertAction({ "type": "function", "function": "function () { core.events._trigger_inAction(" + x + "," + y + "); }", "async": true },
|
||||
null, null, null, true);
|
||||
return _executeCallback();
|
||||
}
|
||||
@ -373,7 +373,7 @@ events.prototype.trigger = function (x, y, callback) {
|
||||
|
||||
events.prototype._trigger_inAction = function (x, y) {
|
||||
if (core.status.gameOver || core.status.event.id != 'action') return;
|
||||
|
||||
|
||||
var block = core.getBlock(x, y);
|
||||
if (block == null) return core.doAction();
|
||||
|
||||
@ -439,9 +439,9 @@ 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);
|
||||
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.push(beforeBattle, [{ "type": "battle", "x": data.x, "y": data.y }]);
|
||||
core.clearContinueAutomaticRoute();
|
||||
|
||||
// 自动存档
|
||||
@ -545,7 +545,7 @@ events.prototype._openDoor_check = function (block, x, y, needKey) {
|
||||
if (needKey) {
|
||||
for (var keyName in keyInfo) {
|
||||
var keyValue = keyInfo[keyName];
|
||||
if (keyName.endsWith(':o')) keyName = keyName.substring(0, keyName.length - 2);
|
||||
if (keyName.endsWith(':o')) keyName = keyName.substring(0, keyName.length - 2);
|
||||
|
||||
// --- 如果是一个不存在的道具,则直接认为无法开启
|
||||
if (!core.material.items[keyName]) {
|
||||
@ -562,7 +562,7 @@ events.prototype._openDoor_check = function (block, x, y, needKey) {
|
||||
}
|
||||
}
|
||||
if (!core.status.event.id) core.autosave(true);
|
||||
for (var keyName in keyInfo) {
|
||||
for (var keyName in keyInfo) {
|
||||
if (!keyName.endsWith(':o')) core.removeItem(keyName, keyInfo[keyName]);
|
||||
}
|
||||
}
|
||||
@ -593,7 +593,7 @@ events.prototype._openDoor_animate = function (block, x, y, callback) {
|
||||
if (callback) callback();
|
||||
}
|
||||
|
||||
var animate = window.setInterval(function() {
|
||||
var animate = window.setInterval(function () {
|
||||
blockInfo.posX++;
|
||||
if (blockInfo.posX == 4) {
|
||||
clearInterval(animate);
|
||||
@ -601,9 +601,9 @@ events.prototype._openDoor_animate = function (block, x, y, callback) {
|
||||
cb();
|
||||
return;
|
||||
}
|
||||
core.maps._drawBlockInfo(blockInfo, x, y);
|
||||
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;
|
||||
}
|
||||
@ -635,13 +635,13 @@ events.prototype.getItem = function (id, num, x, y, isGentleClick, callback) {
|
||||
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"
|
||||
} 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在装备栏进行装备)" : ""));
|
||||
: itemCls == 'constants' ? "(永久类道具,请按T在道具栏使用)"
|
||||
: itemCls == 'equips' ? "(装备类道具,请按Q在装备栏进行装备)" : ""));
|
||||
}
|
||||
itemHint.push(id);
|
||||
}
|
||||
@ -686,7 +686,7 @@ events.prototype._getNextItem = function (direction, noRoute) {
|
||||
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.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 () {
|
||||
@ -799,13 +799,13 @@ events.prototype._changeFloor_beforeChange = function (info, callback) {
|
||||
}
|
||||
|
||||
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) {
|
||||
@ -814,7 +814,7 @@ events.prototype._changeFloor_changing = function (info, callback) {
|
||||
var __lockViewport__ = flags.__lockViewport__;
|
||||
core.setFlag('__lockViewport__', null);
|
||||
core.drawHero();
|
||||
core.setFlag('__lockViewport__', __lockViewport__);
|
||||
core.setFlag('__lockViewport__', __lockViewport__);
|
||||
|
||||
if (info.time == 0)
|
||||
this._changeFloor_afterChange(info, callback);
|
||||
@ -888,8 +888,8 @@ events.prototype.pushBox = function (data) {
|
||||
core.setBlock('flower', data.x, data.y);
|
||||
// 勇士前进一格,然后触发推箱子后事件
|
||||
core.insertAction([
|
||||
{"type": "moveAction"},
|
||||
{"type": "function", "function": "function() { core.afterPushBox(); }"}
|
||||
{ "type": "moveAction" },
|
||||
{ "type": "function", "function": "function() { core.afterPushBox(); }" }
|
||||
]);
|
||||
}
|
||||
|
||||
@ -953,7 +953,7 @@ events.prototype.doEvent = function (data, x, y, prefix) {
|
||||
}
|
||||
catch (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);
|
||||
@ -966,8 +966,8 @@ events.prototype.setEvents = function (list, x, y, callback) {
|
||||
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"}];
|
||||
l.push({ "type": "_label" });
|
||||
data.list = [{ todo: l, total: core.clone(l), condition: "false" }];
|
||||
// 结束所有正在执行的自动事件
|
||||
if (list.length == 0) {
|
||||
core.status.autoEvents.forEach(function (autoEvent) {
|
||||
@ -1020,7 +1020,7 @@ events.prototype.doAction = function () {
|
||||
var data = current.todo.shift();
|
||||
core.status.event.data.current = data;
|
||||
if (typeof data == "string")
|
||||
data = {"type": "text", "text": data};
|
||||
data = { "type": "text", "text": data };
|
||||
// 该事件块已经被禁用
|
||||
if (data._disabled) return core.doAction();
|
||||
data.floorId = data.floorId || floorId;
|
||||
@ -1082,7 +1082,7 @@ events.prototype.insertAction = function (action, x, y, callback, addToLast) {
|
||||
list.splice(index, 0, action);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else core.unshift(core.status.event.data.list[0].todo, action);
|
||||
this.setEvents(null, x, y, callback);
|
||||
@ -1103,12 +1103,12 @@ events.prototype.insertCommonEvent = function (name, args, x, y, callback, addTo
|
||||
for (var i = 0; i < args.length; ++i) {
|
||||
try {
|
||||
if (args[i] != null)
|
||||
core.setFlag('arg'+(i+1), args[i]);
|
||||
core.setFlag('arg' + (i + 1), args[i]);
|
||||
} 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 正在执行中
|
||||
if (autoEvent.currentFloor && floorId != core.status.floorId) 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;
|
||||
var prefix = floorId + "@" + x + "@" + y;
|
||||
try {
|
||||
@ -1154,23 +1154,29 @@ events.prototype.checkAutoEvents = function () {
|
||||
|
||||
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); }"}
|
||||
{ "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 + "' ); }"},
|
||||
{
|
||||
"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); }"}
|
||||
{ "type": "dowhile", "condition": "false", "data": autoEvent.data },
|
||||
{
|
||||
"type": "function", "function":
|
||||
"function() { core.popEventLoc(); core.autoEventExecuting('" + symbol + "', false); }"
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
@ -1397,7 +1403,7 @@ events.prototype._action_text = function (data, x, y, prefix) {
|
||||
|
||||
events.prototype._action_moveTextBox = function (data, x, y, prefix) {
|
||||
if (this.__action_checkReplaying()) return;
|
||||
this.__action_doAsyncFunc(data.async, core.moveTextBox,
|
||||
this.__action_doAsyncFunc(data.async, core.moveTextBox,
|
||||
data.code, this.__action_getLoc(data.loc, x, y, prefix), data.relative, data.moveMode, data.time);
|
||||
}
|
||||
|
||||
@ -1439,7 +1445,7 @@ events.prototype._action_tip = function (data, x, y, prefix) {
|
||||
|
||||
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) {
|
||||
if (data.time > 0 && data.floorId == core.status.floorId) {
|
||||
this.__action_doAsyncFunc(data.async, core.animateBlock, data.loc, 'show', data.time);
|
||||
}
|
||||
else {
|
||||
@ -1583,14 +1589,14 @@ events.prototype._action_moveAction = function (data, x, y, prefix) {
|
||||
// 检查noPass决定是撞击还是移动
|
||||
if (core.noPass(nx, ny)) {
|
||||
core.insertAction([
|
||||
{"type": "trigger", "loc": [nx, ny]}
|
||||
{ "type": "trigger", "loc": [nx, ny] }
|
||||
]);
|
||||
} else {
|
||||
// 先移动一格,然后尝试触发事件
|
||||
core.insertAction([
|
||||
{"type": "moveHero", "steps": ["forward"]},
|
||||
{"type": "function", "function": "function() { core.moveOneStep(core.doAction); }", "async": true},
|
||||
{"type": "_label"},
|
||||
{ "type": "moveHero", "steps": ["forward"] },
|
||||
{ "type": "function", "function": "function() { core.moveOneStep(core.doAction); }", "async": true },
|
||||
{ "type": "_label" },
|
||||
]);
|
||||
}
|
||||
}
|
||||
@ -1630,7 +1636,7 @@ events.prototype._action_jumpHero = function (data, x, y, prefix) {
|
||||
|
||||
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};
|
||||
var heroLoc = { x: loc[0], y: loc[1], direction: data.direction };
|
||||
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);
|
||||
if (core.isReplaying()) data.time = 0;
|
||||
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);
|
||||
this.__action_doAsyncFunc(data.async || data.time == 0, core.showImage,
|
||||
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 {
|
||||
// 设置参数
|
||||
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 (e) { main.log(e); }
|
||||
}
|
||||
for (var i = 0; i < data.args.length; ++i) {
|
||||
try {
|
||||
if (data.args[i] != null)
|
||||
core.setFlag('arg' + (i + 1), data.args[i]);
|
||||
} catch (e) { main.log(e); }
|
||||
}
|
||||
}
|
||||
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]];
|
||||
var event = (core.floors[floorId][which] || [])[loc[0] + "," + loc[1]];
|
||||
if (event) this.insertAction(event.data || event);
|
||||
}
|
||||
core.doAction();
|
||||
@ -2099,13 +2105,13 @@ events.prototype._action_choices = function (data, x, y, prefix) {
|
||||
core.status.route.push("choices:none");
|
||||
core.setFlag('timeout', 0);
|
||||
core.doAction();
|
||||
}, data.timeout);
|
||||
}, 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": 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);
|
||||
@ -2126,13 +2132,13 @@ events.prototype.__action_choices_replaying = function (data, index) {
|
||||
} else core.setFlag('timeout', 0);
|
||||
core.status.event.selection = selection;
|
||||
setTimeout(function () {
|
||||
core.status.route.push("choices:"+index);
|
||||
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);
|
||||
core.control._replay_error("无法选择项:" + index);
|
||||
return;
|
||||
} else {
|
||||
core.insertAction(choice.action);
|
||||
@ -2155,7 +2161,7 @@ events.prototype._precompile_choices = function (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};
|
||||
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)) {
|
||||
@ -2194,7 +2200,7 @@ events.prototype.__action_confirm_replaying = function (data, index) {
|
||||
} else core.setFlag('timeout', 0);
|
||||
core.status.event.selection = index;
|
||||
setTimeout(function () {
|
||||
core.status.route.push("choices:"+index);
|
||||
core.status.route.push("choices:" + index);
|
||||
if (index != 'none') {
|
||||
if (index == 0) core.insertAction(data.yes);
|
||||
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 to = core.calValue(data.to);
|
||||
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('循环遍历事件要求【起始点】【终止点】【每步】仅能是数字!');
|
||||
return core.doAction();
|
||||
}
|
||||
@ -2234,18 +2240,18 @@ events.prototype._action_for = function (data, x, y, prefix) {
|
||||
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; }"+
|
||||
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);
|
||||
return this._action_dowhile({ "condition": condition, "data": data.data }, x, y, prefix);
|
||||
}
|
||||
|
||||
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);
|
||||
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;"+
|
||||
"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);
|
||||
return this._action_while({ "condition": condition, "data": data.data }, x, y, prefix);
|
||||
}
|
||||
|
||||
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)) {
|
||||
var list = core.clone(data.data);
|
||||
if (!(list instanceof Array)) list = [list];
|
||||
list.push({"type": "_label"});
|
||||
list.push({ "type": "_label" });
|
||||
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();
|
||||
@ -2299,9 +2305,9 @@ events.prototype._precompile_while = function (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"});
|
||||
list.push({ "type": "_label" });
|
||||
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();
|
||||
}
|
||||
@ -2431,7 +2437,7 @@ events.prototype._action_wait = function (data, x, y, prefix) {
|
||||
core.control._replay_error(code);
|
||||
return;
|
||||
} else if (data.timeout) {
|
||||
core.status.event.interval = setTimeout(function() {
|
||||
core.status.event.interval = setTimeout(function () {
|
||||
core.status.route.push("input:none");
|
||||
core.setFlag("type", -1);
|
||||
core.setFlag("timeout", 0);
|
||||
@ -2498,7 +2504,7 @@ events.prototype.__action_wait_afterGet = function (data) {
|
||||
}
|
||||
if (one["case"] == "condition") {
|
||||
var condition = false;
|
||||
try { condition = core.calValue(one.condition); } catch (e) {}
|
||||
try { condition = core.calValue(one.condition); } catch (e) { }
|
||||
if (condition) {
|
||||
found = true;
|
||||
core.push(todo, one.action);
|
||||
@ -2532,9 +2538,9 @@ events.prototype._precompile_wait = function (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)) {
|
||||
if (!core.hasAsync()
|
||||
&& (data.excludeAnimates || core.isReplaying() || core.getPlayingAnimates().length == 0)
|
||||
&& (!data.includeSounds || core.isReplaying() || core.getPlayingSounds().length == 0)) {
|
||||
clearInterval(test);
|
||||
core.doAction();
|
||||
}
|
||||
@ -2778,7 +2784,7 @@ events.prototype.useFly = function (fromUserAction) {
|
||||
if (!core.hasItem('fly')) {
|
||||
core.playSound('操作失败');
|
||||
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.drawTip('无法传送到当前层', 'fly');
|
||||
} else {
|
||||
@ -2880,32 +2886,32 @@ events.prototype.save = function (fromUserAction) {
|
||||
return;
|
||||
if (!this._checkStatus('save', fromUserAction)) return;
|
||||
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.ui._drawSLPanel(10*page+offset);
|
||||
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;
|
||||
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.event = { 'id': 'load', 'data': null };
|
||||
core.status.lockControl = true;
|
||||
core.playSound('打开界面');
|
||||
core.ui._drawSLPanel(10*page+offset);
|
||||
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);
|
||||
core.ui._drawSLPanel(10 * page + offset);
|
||||
}
|
||||
|
||||
////// 点击设置按钮时的操作 //////
|
||||
@ -2944,7 +2950,7 @@ events.prototype.hasAsyncAnimate = function () {
|
||||
events.prototype.follow = function (name) {
|
||||
name = core.getMappedName(name);
|
||||
if (core.material.images.images[name]) {
|
||||
core.status.hero.followers.push({"name": name});
|
||||
core.status.hero.followers.push({ "name": name });
|
||||
core.gatherFollowers();
|
||||
core.clearMap('hero');
|
||||
core.drawHero();
|
||||
@ -3045,9 +3051,9 @@ events.prototype.setEnemy = function (id, name, value, operator, prefix, norefre
|
||||
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);
|
||||
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);
|
||||
(core.material.enemys[id] || {})[name] = core.clone(value);
|
||||
if (!norefresh) core.updateStatusBar();
|
||||
}
|
||||
|
||||
@ -3062,24 +3068,24 @@ events.prototype.setEnemyOnPoint = function (x, y, floorId, name, value, operato
|
||||
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;
|
||||
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];
|
||||
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 (((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();
|
||||
}
|
||||
}
|
||||
@ -3115,7 +3121,7 @@ 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;});
|
||||
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);
|
||||
@ -3201,7 +3207,7 @@ events.prototype._moveTextBox_moving = function (ctx, moveInfo, callback) {
|
||||
if (callback) callback();
|
||||
}
|
||||
}, 10);
|
||||
|
||||
|
||||
core.animateFrame.lastAsyncId = animate;
|
||||
core.animateFrame.asyncId[animate] = callback;
|
||||
}
|
||||
@ -3234,7 +3240,7 @@ events.prototype.clearTextBox = function (code, callback) {
|
||||
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) {
|
||||
|| core.getBlock(x, y) != null) {
|
||||
if (callback) callback();
|
||||
return;
|
||||
}
|
||||
@ -3267,7 +3273,7 @@ events.prototype.closeDoor = function (x, y, id, callback) {
|
||||
}
|
||||
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;
|
||||
}
|
||||
@ -3378,7 +3384,7 @@ events.prototype._moveImage_moving = function (name, moveInfo, callback) {
|
||||
if (callback) callback();
|
||||
}
|
||||
}, per_time);
|
||||
|
||||
|
||||
core.animateFrame.lastAsyncId = animate;
|
||||
core.animateFrame.asyncId[animate] = callback;
|
||||
}
|
||||
@ -3423,7 +3429,7 @@ events.prototype._rotateImage_rotating = function (name, rotateInfo, callback) {
|
||||
if (callback) callback();
|
||||
}
|
||||
}, per_time);
|
||||
|
||||
|
||||
core.animateFrame.lastAsyncId = animate;
|
||||
core.animateFrame.asyncId[animate] = callback;
|
||||
}
|
||||
@ -3451,7 +3457,7 @@ events.prototype.scaleImage = function (code, center, scale, moveMode, time, cal
|
||||
centerY = currTop + height * currScale / 2;
|
||||
}
|
||||
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
|
||||
}
|
||||
this._scaleImage_scale(ctx, scaleInfo, callback);
|
||||
@ -3484,7 +3490,7 @@ events.prototype._scaleImage_scale = function (ctx, scaleInfo, callback) {
|
||||
if (callback) callback();
|
||||
}
|
||||
}, per_time);
|
||||
|
||||
|
||||
core.animateFrame.lastAsyncId = animate;
|
||||
core.animateFrame.asyncId[animate] = callback;
|
||||
}
|
||||
@ -3533,7 +3539,7 @@ events.prototype.setVolume = function (value, time, callback) {
|
||||
if (callback) callback();
|
||||
}
|
||||
}, per_time);
|
||||
|
||||
|
||||
core.animateFrame.lastAsyncId = animate;
|
||||
core.animateFrame.asyncId[animate] = callback;
|
||||
}
|
||||
@ -3547,7 +3553,7 @@ events.prototype.vibrate = function (direction, time, speed, power, callback) {
|
||||
if (!time) time = 1000;
|
||||
speed = speed || 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') {
|
||||
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;
|
||||
var step = 0, moveSteps = (steps||[]).map(function (t) {
|
||||
return [t.split(':')[0], parseInt(t.split(':')[1]||"1")];
|
||||
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
|
||||
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;
|
||||
@ -3611,8 +3617,8 @@ events.prototype.eventMoveHero = function(steps, time, callback) {
|
||||
if (callback) callback();
|
||||
}
|
||||
|
||||
var animate=window.setInterval(function() {
|
||||
if (moveSteps.length==0) {
|
||||
var animate = window.setInterval(function () {
|
||||
if (moveSteps.length == 0) {
|
||||
delete core.animateFrame.asyncId[animate];
|
||||
clearInterval(animate);
|
||||
cb();
|
||||
@ -3629,7 +3635,7 @@ events.prototype.eventMoveHero = function(steps, time, callback) {
|
||||
step = 0;
|
||||
}
|
||||
}, core.status.replay.speed == 24 ? 1 : time / 8 / core.status.replay.speed);
|
||||
|
||||
|
||||
core.animateFrame.lastAsyncId = animate;
|
||||
core.animateFrame.asyncId[animate] = cb;
|
||||
}
|
||||
@ -3674,9 +3680,9 @@ 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 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;
|
||||
@ -3723,7 +3729,7 @@ events.prototype.setHeroIcon = function (name, noDraw) {
|
||||
name = core.getMappedName(name);
|
||||
var img = core.material.images.images[name];
|
||||
if (!img) {
|
||||
console.error("找不到图片: "+img);
|
||||
console.error("找不到图片: " + img);
|
||||
return;
|
||||
}
|
||||
if (core.material.images.hero == img) return;
|
||||
@ -3747,7 +3753,7 @@ events.prototype.checkLvUp = 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;
|
||||
// 计算下一个所需要的数值
|
||||
var next = (core.firstData.levelUp[core.status.hero.lv] || {});
|
||||
|
||||
291
libs/maps.js
291
libs/maps.js
@ -2,7 +2,7 @@
|
||||
|
||||
"use strict";
|
||||
|
||||
function maps() {
|
||||
function maps () {
|
||||
this._init();
|
||||
}
|
||||
|
||||
@ -53,7 +53,7 @@ maps.prototype.loadFloor = function (floorId, map) {
|
||||
var floor = core.floors[floorId];
|
||||
if (!map) map = core.cloneArray(floor.map);
|
||||
if (map instanceof Array) {
|
||||
map = {"map": map};
|
||||
map = { "map": map };
|
||||
}
|
||||
if (!map.map) map.map = core.cloneArray(floor.map);
|
||||
var content = {};
|
||||
@ -76,7 +76,7 @@ maps.prototype.loadFloor = function (floorId, map) {
|
||||
maps.prototype._loadFloor_doNotCopy = function () {
|
||||
return [
|
||||
"firstArrive", "eachArrive", "blocks", "parallelDo", "map", "bgmap", "fgmap",
|
||||
"events", "changeFloor", "beforeBattle", "afterBattle", "afterGetItem", "afterOpenDoor",
|
||||
"events", "changeFloor", "beforeBattle", "afterBattle", "afterGetItem", "afterOpenDoor",
|
||||
"cannotMove", "cannotMoveIn"
|
||||
];
|
||||
}
|
||||
@ -84,7 +84,7 @@ maps.prototype._loadFloor_doNotCopy = function () {
|
||||
/// 根据需求解析出blocks
|
||||
maps.prototype.extractBlocks = function (map) {
|
||||
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.blocks) return;
|
||||
if (map.deleted) {
|
||||
@ -104,7 +104,7 @@ maps.prototype._mapIntoBlocks = function (map, floor, floorId) {
|
||||
var number = (map[i] || [])[j] || 0, block;
|
||||
if (main.mode == 'editor') {
|
||||
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 {
|
||||
block = this.initBlock(j, i, number, true, floor);
|
||||
}
|
||||
@ -147,7 +147,7 @@ maps.prototype.extractBlocksForUI = function (map, flags) {
|
||||
var event = (floor.events || {})[j + "," + i];
|
||||
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);
|
||||
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 (opacity != null) block.opacity = opacity;
|
||||
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 (core.icons.getTilesetOffset(id)) block.event = {"cls": "tileset", "id": "X" + id};
|
||||
else block.event = {'cls': 'terrains', 'id': 'none', 'noPass': false};
|
||||
else if (core.icons.getTilesetOffset(id)) block.event = { "cls": "tileset", "id": "X" + id };
|
||||
else block.event = { 'cls': 'terrains', 'id': 'none', 'noPass': false };
|
||||
|
||||
if (block.event.noPass == null) {
|
||||
if (block.event.canPass == null) {
|
||||
@ -222,7 +222,7 @@ maps.prototype.initBlock = function (x, y, id, addInfo, eventFloor) {
|
||||
delete block.event.canPass;
|
||||
|
||||
// 增加怪物的faceIds
|
||||
if (block.event.cls.indexOf("enemy") ==0 ) {
|
||||
if (block.event.cls.indexOf("enemy") == 0) {
|
||||
var enemy = core.material.enemys[block.event.id];
|
||||
if (enemy && enemy.faceIds) {
|
||||
block.event.faceIds = enemy.faceIds;
|
||||
@ -233,7 +233,7 @@ maps.prototype.initBlock = function (x, y, id, addInfo, eventFloor) {
|
||||
if (eventFloor) {
|
||||
this._addEvent(block, x, y, (eventFloor.events || {})[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;
|
||||
return block;
|
||||
@ -260,10 +260,10 @@ maps.prototype._addEvent = function (block, x, y, event) {
|
||||
if (!event) return;
|
||||
// event是字符串或数组?
|
||||
if (typeof event == "string") {
|
||||
event = {"data": [event]};
|
||||
event = { "data": [event] };
|
||||
}
|
||||
else if (event instanceof Array) {
|
||||
event = {"data": event};
|
||||
event = { "data": event };
|
||||
}
|
||||
event.data = event.data || [];
|
||||
|
||||
@ -337,7 +337,7 @@ maps.prototype._processInvalidMap = function (mapArr, width, height) {
|
||||
}
|
||||
for (var j = 0; j < height; ++j) {
|
||||
for (var i = 0; i < width; ++i) {
|
||||
if (j < mapArr.length && i < mapArr[j].length)
|
||||
if (j < mapArr.length && i < mapArr[j].length)
|
||||
map[j][i] = mapArr[j][i];
|
||||
}
|
||||
}
|
||||
@ -352,7 +352,7 @@ maps.prototype._getBlockOpacityFromFlag = function (floorId, x, y, flags) {
|
||||
if (!floorId) return null;
|
||||
if ((flags.__removed__ || []).indexOf(floorId) >= 0) return null;
|
||||
var index = x + y * core.floors[floorId].width;
|
||||
return (__opacity__[floorId]||{})[index];
|
||||
return (__opacity__[floorId] || {})[index];
|
||||
}
|
||||
|
||||
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 ((flags.__removed__ || []).indexOf(floorId) >= 0) return null;
|
||||
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.__removed__ || []).indexOf(floorId) >= 0) return;
|
||||
var __disabled__ = window.flags.__disabled__ || {};
|
||||
if (!__disabled__[floorId]) __disabled__[floorId] = [[],[]];
|
||||
if (!__disabled__[floorId]) __disabled__[floorId] = [[], []];
|
||||
var index = x + y * core.floors[floorId].width;
|
||||
__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][0] = __disabled__[floorId][0].filter(function (x) { return x != index });
|
||||
__disabled__[floorId][1] = __disabled__[floorId][1].filter(function (x) { return x != index });
|
||||
if (disabled == null) return;
|
||||
if (disabled) __disabled__[floorId][0].push(index);
|
||||
else __disabled__[floorId][1].push(index);
|
||||
@ -525,7 +525,7 @@ maps.prototype.loadMap = function (data, floorId, flags) {
|
||||
if (!floorId) {
|
||||
var map = {};
|
||||
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 };
|
||||
}
|
||||
map[id] = core.maps.loadFloor(id, data[id]);
|
||||
@ -601,7 +601,7 @@ maps.prototype._getMapArrayFromBlocks = function (blockArray, width, height, sho
|
||||
////// 以x,y的形式返回每个点的事件 //////
|
||||
maps.prototype.getMapBlocksObj = function (floorId, noCache) {
|
||||
floorId = floorId || core.status.floorId;
|
||||
if (core.status.mapBlockObjs[floorId] && !noCache)
|
||||
if (core.status.mapBlockObjs[floorId] && !noCache)
|
||||
return core.status.mapBlockObjs[floorId];
|
||||
|
||||
var obj = {};
|
||||
@ -630,10 +630,10 @@ maps.prototype._getBgFgMapArray = function (name, floorId, noCache) {
|
||||
for (var y = 0; y < height; ++y) {
|
||||
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;
|
||||
});
|
||||
(core.getFlag('__'+name+'d__', {})[floorId] || []).forEach(function (one) {
|
||||
(core.getFlag('__' + name + 'd__', {})[floorId] || []).forEach(function (one) {
|
||||
arr[one[1]][one[0]] = 0;
|
||||
});
|
||||
if (main.mode == 'editor') {
|
||||
@ -701,7 +701,7 @@ maps.prototype.generateMovableArray = function (floorId) {
|
||||
|
||||
maps.prototype._generateMovableArray_arrays = function (floorId) {
|
||||
return {
|
||||
bgArray: this.getBgMapArray(floorId),
|
||||
bgArray: this.getBgMapArray(floorId),
|
||||
fgArray: this.getFgMapArray(floorId),
|
||||
eventArray: this.getMapArray(floorId)
|
||||
};
|
||||
@ -740,7 +740,7 @@ maps.prototype._canMoveHero_checkPoint = function (x, y, direction, floorId, arr
|
||||
|
||||
// 4. 检查是否能进将死的领域
|
||||
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 true;
|
||||
@ -760,7 +760,7 @@ maps.prototype._canMoveHero_checkCannotInOut = function (number, name, direction
|
||||
|
||||
////// 能否瞬间移动 //////
|
||||
maps.prototype.canMoveDirectly = function (destX, destY) {
|
||||
return this.canMoveDirectlyArray([[destX,destY]])[0];
|
||||
return this.canMoveDirectlyArray([[destX, destY]])[0];
|
||||
}
|
||||
|
||||
maps.prototype.canMoveDirectlyArray = function (locs, canMoveArray) {
|
||||
@ -888,12 +888,12 @@ maps.prototype.automaticRoute = function (destX, destY) {
|
||||
if (destX == startX && destY == startY) return [];
|
||||
// BFS找寻最短路径
|
||||
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;
|
||||
while (nowX != startX || nowY != startY) {
|
||||
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;
|
||||
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) {
|
||||
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] = '';
|
||||
queue.queue({depth: 0, x: startX, y: startY});
|
||||
queue.queue({ depth: 0, x: startX, y: startY });
|
||||
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;
|
||||
for (var direction in core.utils.scan) {
|
||||
if (!core.inArray(canMoveArray[nowX][nowY], direction)) continue;
|
||||
var nx = nowX + core.utils.scan[direction].x;
|
||||
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) {
|
||||
route[nx+","+ny] = direction;
|
||||
route[nx + "," + ny] = direction;
|
||||
break;
|
||||
}
|
||||
// 不可通行
|
||||
if (core.noPass(nx, ny)) continue;
|
||||
route[nx+","+ny] = direction;
|
||||
queue.queue({depth: deep + this._automaticRoute_deepAdd(nx, ny, blocks), x: nx, y: ny});
|
||||
route[nx + "," + ny] = direction;
|
||||
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;
|
||||
}
|
||||
@ -933,7 +933,7 @@ maps.prototype._automaticRoute_bfs = function (startX, startY, destX, destY) {
|
||||
maps.prototype._automaticRoute_deepAdd = function (x, y, blocks) {
|
||||
// 判定每个可通行点的损耗值,越高越应该绕路
|
||||
var deepAdd = 1;
|
||||
var block = blocks[x+","+y];
|
||||
var block = blocks[x + "," + y];
|
||||
if (block && !block.disable) {
|
||||
var id = block.event.id;
|
||||
// 绕过亮灯
|
||||
@ -946,9 +946,9 @@ maps.prototype._automaticRoute_deepAdd = function (x, y, blocks) {
|
||||
// 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;
|
||||
}
|
||||
|
||||
@ -973,7 +973,7 @@ maps.prototype._getBigImageInfo = function (bigImage, face, animate) {
|
||||
// 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 };
|
||||
}
|
||||
|
||||
////// 绘制一个图块 //////
|
||||
@ -1025,7 +1025,7 @@ maps.prototype._drawBlockInfo_bigImage = function (blockInfo, x, y, ctx) {
|
||||
|
||||
var px = 32 * x - core.bigmap.offsetX;
|
||||
var py = 32 * y - core.bigmap.offsetY;
|
||||
|
||||
|
||||
// 上半部分 - 会遮挡勇士;z值高于event2,为51
|
||||
var header = "_bigImage_header_" + x + "_" + y;
|
||||
// 下半部分 - 会被勇士遮挡;z值高于event,为31
|
||||
@ -1172,7 +1172,7 @@ maps.prototype.redrawMap = function () {
|
||||
core.bigmap.canvas.forEach(function (one) {
|
||||
core.clearMap(one);
|
||||
});
|
||||
this._drawMap_drawAll(null, {redraw: true});
|
||||
this._drawMap_drawAll(null, { redraw: true });
|
||||
core.drawDamage();
|
||||
}
|
||||
|
||||
@ -1211,7 +1211,7 @@ maps.prototype._drawMap_drawBlockInfo = function (ctx, block, blockInfo, arr, co
|
||||
var bigImageInfo = core.maps._getBigImageInfo(blockInfo.bigImage, blockInfo.face, 0);
|
||||
var per_width = bigImageInfo.per_width, per_height = bigImageInfo.per_height;
|
||||
core.maps._drawBlockInfo_drawWithFilter(block, ctx, function () {
|
||||
core.drawImage(ctx, blockInfo.bigImage, bigImageInfo.sx, bigImageInfo.sy, per_width, per_height,
|
||||
core.drawImage(ctx, blockInfo.bigImage, bigImageInfo.sx, bigImageInfo.sy, per_width, per_height,
|
||||
32 * block.x + bigImageInfo.dx, 32 * block.y + bigImageInfo.dy, per_width, per_height);
|
||||
});
|
||||
});
|
||||
@ -1232,7 +1232,7 @@ maps.prototype._drawMap_drawBlockInfo = function (ctx, block, blockInfo, arr, co
|
||||
maps.prototype.drawBg = function (floorId, config) {
|
||||
floorId = floorId || core.status.floorId;
|
||||
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);
|
||||
if (config.ctx == null) {
|
||||
config.onMap = true;
|
||||
@ -1286,7 +1286,7 @@ maps.prototype._drawBg_drawBackground = function (floorId, config) {
|
||||
maps.prototype.drawEvents = function (floorId, blocks, config) {
|
||||
floorId = floorId || core.status.floorId;
|
||||
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);
|
||||
if (config.ctx == null) {
|
||||
config.onMap = true;
|
||||
@ -1342,7 +1342,7 @@ maps.prototype.drawEvents = function (floorId, blocks, config) {
|
||||
maps.prototype.drawFg = function (floorId, config) {
|
||||
floorId = floorId || core.status.floorId;
|
||||
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);
|
||||
if (config.ctx == null) {
|
||||
config.onMap = true;
|
||||
@ -1444,14 +1444,14 @@ maps.prototype._drawFloorImages_gif = function (image, dx, dy) {
|
||||
|
||||
maps.prototype._drawFloorImage = function (ctx, name, one, image, currStatus, onMap) {
|
||||
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 height = one.h == null ? image.height : one.h;
|
||||
var sx = (one.sx || 0) + (currStatus || 0) % (one.frame || 1) * width;
|
||||
var sy = one.sy || 0;
|
||||
var x = one.x || 0, y = one.y || 0;
|
||||
if (onMap && core.bigmap.v2) {
|
||||
if (x > 32 * core.bigmap.posX + core.__PIXELS__ + 32 || x + width < 32 * core.bigmap.posX - 32
|
||||
if (x > 32 * core.bigmap.posX + core.__PIXELS__ + 32 || x + width < 32 * core.bigmap.posX - 32
|
||||
|| y > 32 * core.bigmap.posX + core.__PIXELS__ + 32 || y + height < 32 * core.bigmap.posY - 32) {
|
||||
return;
|
||||
}
|
||||
@ -1483,111 +1483,112 @@ maps.prototype._drawAutotile = function (ctx, mapArr, block, size, left, top, st
|
||||
status = status || 0;
|
||||
status %= parseInt(autotile.width / 96);
|
||||
var done = {};
|
||||
var isGrass = function(x,y){
|
||||
if(core.maps._drawAutotile_getAutotileAroundId(mapArr[yy][xx],x,y,mapArr)){
|
||||
var isGrass = function (x, y) {
|
||||
if (core.maps._drawAutotile_getAutotileAroundId(mapArr[yy][xx], x, y, mapArr)) {
|
||||
return 1;
|
||||
}else{
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
var iG = [];
|
||||
[-1,0,1].forEach(function(_x){
|
||||
iG[_x] = [];
|
||||
[-1,0,1].forEach(function(_y){
|
||||
[-1, 0, 1].forEach(function (_x) {
|
||||
iG[_x] = [];
|
||||
[-1, 0, 1].forEach(function (_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);
|
||||
done[0] = true;
|
||||
}
|
||||
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);
|
||||
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);
|
||||
done[1] = true;
|
||||
}
|
||||
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);
|
||||
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);
|
||||
done[3] = true;
|
||||
}
|
||||
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);
|
||||
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);
|
||||
done[2] = true;
|
||||
}
|
||||
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) {
|
||||
x -= 32 * core.bigmap.posX;
|
||||
y -= 32 * core.bigmap.posY;
|
||||
}
|
||||
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 + 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, 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, 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, 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, 3 * 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 + 32, 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 + 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, x, y, size / 2, size / 2],],
|
||||
[[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, 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, 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, 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, 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, 3 * 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 + 32, 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 + 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, x, y, size / 2, size / 2],],
|
||||
];
|
||||
var data = indexData[index];
|
||||
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);
|
||||
}else{ // 非拐角要根据是否已经绘制进行切分后绘制
|
||||
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);
|
||||
} else { // 非拐角要根据是否已经绘制进行切分后绘制
|
||||
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 = [];
|
||||
done = done || {};
|
||||
if(data.length == 2){
|
||||
if (data.length == 2) {
|
||||
var idx = 0;
|
||||
var cut = 0;
|
||||
for(var i in data){
|
||||
if(data[i][2] % 32){ // 是否纵切
|
||||
for (var i in data) {
|
||||
if (data[i][2] % 32) { // 是否纵切
|
||||
cut = 0;
|
||||
}
|
||||
else if(data[i][3] % 32){ // 是否横切
|
||||
else if (data[i][3] % 32) { // 是否横切
|
||||
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;
|
||||
}else{ // left top
|
||||
} else { // left top
|
||||
idx = 0;
|
||||
}
|
||||
if(cut){
|
||||
if (cut) {
|
||||
idx *= 2;
|
||||
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]];
|
||||
}else{
|
||||
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]) drawData[idx] = [data[i][0], data[i][1]];
|
||||
if (!done[idx + 1]) drawData[idx + 1] = [parseInt(data[i][0]) + 16, data[i][1]];
|
||||
} else {
|
||||
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];
|
||||
}
|
||||
}
|
||||
}else{
|
||||
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[2])drawData[2] = [data[0][0], data[0][1] + 16];
|
||||
if(!done[3])drawData[3] = [data[0][0] + 16, data[0][1] + 16];
|
||||
} else {
|
||||
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[2]) drawData[2] = [data[0][0], data[0][1] + 16];
|
||||
if (!done[3]) drawData[3] = [data[0][0] + 16, data[0][1] + 16];
|
||||
}
|
||||
for(var i = 0; i<4; i++){
|
||||
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);
|
||||
for (var i = 0; i < 4; i++) {
|
||||
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);
|
||||
};
|
||||
}
|
||||
|
||||
@ -1642,12 +1643,12 @@ maps.prototype._drawAutotileAnimate = function (block, animate) {
|
||||
}
|
||||
} else {
|
||||
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;
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
var alpha = null;
|
||||
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;
|
||||
if (!floorId) return;
|
||||
options = options || {};
|
||||
if (typeof options == 'string' || options.canvas) options = {ctx: options};
|
||||
if (typeof options == 'string' || options.canvas) options = { ctx: options };
|
||||
var ctx = options.ctx;
|
||||
// Step1:绘制到tempCanvas上
|
||||
this._drawThumbnail_drawTempCanvas(floorId, blocks, options);
|
||||
@ -1748,7 +1749,7 @@ maps.prototype._drawThumbnail_drawTempCanvas = function (floorId, blocks, option
|
||||
tempCanvas.canvas.height = height * 32;
|
||||
}
|
||||
options.ctx = tempCanvas;
|
||||
|
||||
|
||||
// 地图过大的缩略图不绘制显伤
|
||||
if (width * height > core.bigmap.threshold)
|
||||
options.damage = false;
|
||||
@ -1801,7 +1802,7 @@ maps.prototype._drawThumbnail_drawToTarget = function (floorId, options) {
|
||||
var centerX = options.centerX, centerY = options.centerY;
|
||||
if (centerX == null) centerX = Math.floor(width / 2);
|
||||
if (centerY == null) centerY = Math.floor(height / 2);
|
||||
var tempCanvas = core.bigmap.tempCanvas;
|
||||
var tempCanvas = core.bigmap.tempCanvas;
|
||||
|
||||
if (options.all) {
|
||||
var tempWidth = tempCanvas.canvas.width, tempHeight = tempCanvas.canvas.height;
|
||||
@ -1861,9 +1862,9 @@ maps.prototype.terrainExists = function (x, y, id, floorId) {
|
||||
maps.prototype.stairExists = function (x, y, floorId) {
|
||||
var blockId = this.getBlockId(x, y, floorId);
|
||||
if (blockId == null) return false;
|
||||
var ids = ['upFloor','downFloor'];
|
||||
ids = ids.concat(['leftPortal','rightPortal','upPortal','downPortal','portal','starPortal']);
|
||||
return ids.indexOf(blockId)>=0;
|
||||
var ids = ['upFloor', 'downFloor'];
|
||||
ids = ids.concat(['leftPortal', 'rightPortal', 'upPortal', 'downPortal', 'portal', 'starPortal']);
|
||||
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) {
|
||||
var block = core.getBlock(x, y, floorId, showDisable);
|
||||
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);
|
||||
}
|
||||
|
||||
@ -1975,8 +1976,10 @@ maps.prototype.getBlockInfo = function (block) {
|
||||
if (!doorInfo && bigImage != null) animate = 4;
|
||||
}
|
||||
|
||||
return {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};
|
||||
return {
|
||||
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) {
|
||||
var block = core.status.maps[floorId].blocks[i];
|
||||
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;
|
||||
@ -2014,7 +2017,7 @@ maps.prototype.searchBlockWithFilter = function (blockFilter, floorId, showDisab
|
||||
for (var i = 0; i < core.status.maps[floorId].blocks.length; ++i) {
|
||||
var block = core.status.maps[floorId].blocks[i];
|
||||
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;
|
||||
@ -2141,7 +2144,7 @@ maps.prototype.removeBlockByIndex = function (index, floorId) {
|
||||
var blocks = core.status.maps[floorId].blocks, block = blocks[index];
|
||||
blocks.splice(index, 1);
|
||||
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);
|
||||
this._updateMapArray(floorId, block.x, block.y);
|
||||
}
|
||||
@ -2175,17 +2178,17 @@ maps.prototype._triggerBgFgMap = function (type, name, loc, floorId, callback) {
|
||||
if (!floorId) return;
|
||||
|
||||
if (loc.length == 0) return;
|
||||
var disabled = core.getFlag('__'+name+'d__', {});
|
||||
var disabled = core.getFlag('__' + name + 'd__', {});
|
||||
disabled[floorId] = disabled[floorId] || [];
|
||||
loc.forEach(function (t) {
|
||||
if (type == 'hide') {
|
||||
disabled[floorId].push([t[0], t[1]]);
|
||||
} 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;
|
||||
|
||||
if (floorId == core.status.floorId) {
|
||||
@ -2247,7 +2250,7 @@ maps.prototype.setBlock = function (number, x, y, floorId) {
|
||||
if (originBlock == null) {
|
||||
core.status.maps[floorId].blocks.push(block);
|
||||
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);
|
||||
delete block.disable;
|
||||
}
|
||||
@ -2263,7 +2266,7 @@ maps.prototype.setBlock = function (number, x, y, floorId) {
|
||||
core.redrawMap();
|
||||
} else {
|
||||
if (originEvent != null) {
|
||||
this._removeBlockFromMap(floorId, {x: x, y: y, event: originEvent});
|
||||
this._removeBlockFromMap(floorId, { x: x, y: y, event: originEvent });
|
||||
}
|
||||
if (!block.disable) {
|
||||
core.drawBlock(block);
|
||||
@ -2357,7 +2360,7 @@ maps.prototype.animateSetBlocks = function (number, locs, floorId, time, callbac
|
||||
return;
|
||||
}
|
||||
if (typeof locs[0] == 'number' && typeof locs[1] == 'number')
|
||||
locs = [locs];
|
||||
locs = [locs];
|
||||
|
||||
var count = locs.length;
|
||||
var _afterSet = function () {
|
||||
@ -2426,14 +2429,16 @@ maps.prototype.setBgFgBlock = function (name, number, x, y, floorId) {
|
||||
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].push([x,y,number]);
|
||||
core.setFlag('__'+name+'v__', values);
|
||||
values[floorId].push([x, y, number]);
|
||||
core.setFlag('__' + name + 'v__', values);
|
||||
|
||||
core.status[name + "maps"][floorId] = null;
|
||||
|
||||
if (floorId == core.status.floorId){
|
||||
this._getBgFgMapArray(name, floorId, true);
|
||||
|
||||
if (floorId == core.status.floorId) {
|
||||
core.clearMap(name);
|
||||
if (name.startsWith('bg')) core.drawBg(floorId);
|
||||
else core.drawFg(floorId);
|
||||
@ -2574,10 +2579,10 @@ maps.prototype.moveBlock = function (x, y, steps, time, keep, callback) {
|
||||
return;
|
||||
}
|
||||
var block = blockArr[0], blockInfo = blockArr[1];
|
||||
var moveSteps = (steps||[]).map(function (t) {
|
||||
return [t.split(':')[0], parseInt(t.split(':')[1]||"1")];
|
||||
var 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
|
||||
return ['up', 'down', 'left', 'right', 'forward', 'backward', 'leftup', 'leftdown', 'rightup', 'rightdown', 'speed'].indexOf(t[0]) >= 0
|
||||
&& !(t[0] == 'speed' && t[1] < 16)
|
||||
});
|
||||
var canvases = this._initDetachedBlock(blockInfo, x, y, block.event.animate !== false);
|
||||
@ -2625,7 +2630,7 @@ maps.prototype._moveBlock_doMove = function (blockInfo, canvases, moveInfo, call
|
||||
else
|
||||
core.maps._moveJumpBlock_finished(blockInfo, canvases, moveInfo, animate, cb);
|
||||
}, moveInfo.per_time);
|
||||
|
||||
|
||||
core.animateFrame.lastAsyncId = animate;
|
||||
core.animateFrame.asyncId[animate] = cb;
|
||||
}
|
||||
@ -2706,7 +2711,7 @@ maps.prototype._moveBlock_moving = function (blockInfo, canvases, moveInfo) {
|
||||
if (moveInfo.step == 16) {
|
||||
moveInfo.step = 0;
|
||||
moveInfo.moveSteps[0][1]--;
|
||||
if (moveInfo.moveSteps[0][1]<=0) {
|
||||
if (moveInfo.moveSteps[0][1] <= 0) {
|
||||
moveInfo.moveSteps.shift();
|
||||
}
|
||||
}
|
||||
@ -2947,7 +2952,7 @@ maps.prototype.drawBoxAnimate = function () {
|
||||
var bigImageInfo = core.maps._getBigImageInfo(obj.bigImage, obj.face, core.status.globalAnimateStatus % 4);
|
||||
var sx = bigImageInfo.sx, sy = bigImageInfo.sy, per_width = bigImageInfo.per_width, per_height = bigImageInfo.per_height;
|
||||
var actual_width = Math.min(per_width, obj.max_width || per_width), actual_height = per_height * actual_width / per_width;
|
||||
core.drawImage(ctx, obj.bigImage, sx, sy, per_width, per_height,
|
||||
core.drawImage(ctx, obj.bigImage, sx, sy, per_width, per_height,
|
||||
obj.centerX - actual_width / 2, obj.centerY - actual_height / 2, actual_width, actual_height);
|
||||
} else {
|
||||
var ctx = obj.ctx || 'ui';
|
||||
@ -2977,7 +2982,7 @@ maps.prototype.drawAnimate = function (name, x, y, alignWindow, callback) {
|
||||
centerY += core.bigmap.offsetY;
|
||||
}
|
||||
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);
|
||||
core.status.animateObjs.push({
|
||||
@ -3006,7 +3011,7 @@ maps.prototype.drawHeroAnimate = function (name, callback) {
|
||||
// 开始绘制
|
||||
var animate = core.material.animates[name];
|
||||
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);
|
||||
core.status.animateObjs.push({
|
||||
@ -3033,7 +3038,7 @@ maps.prototype._drawAnimateFrame = function (name, animate, centerX, centerY, in
|
||||
var ctx = core.getContextByName(name);
|
||||
if (!ctx) return;
|
||||
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;
|
||||
frame.forEach(function (t) {
|
||||
var image = animate.images[t.index];
|
||||
@ -3051,7 +3056,7 @@ maps.prototype._drawAnimateFrame = function (name, animate, centerX, centerY, in
|
||||
var mirror = t.mirror ? 'x' : null;
|
||||
var angle = t.angle ? -t.angle * Math.PI / 180 : null;
|
||||
core.drawImage(ctx, image, ix, iy, realWidth, realHeight, null, null, null, null, angle, mirror);
|
||||
|
||||
|
||||
core.setAlpha(ctx, 1);
|
||||
})
|
||||
}
|
||||
|
||||
2
libs/thirdparty/browser-polyfill.min.js
vendored
Normal file
2
libs/thirdparty/browser-polyfill.min.js
vendored
Normal file
File diff suppressed because one or more lines are too long
122
libs/utils.js
122
libs/utils.js
@ -7,23 +7,23 @@ utils.js 工具类
|
||||
|
||||
"use strict";
|
||||
|
||||
function utils() {
|
||||
function utils () {
|
||||
this._init();
|
||||
this.scan = {
|
||||
'up': {'x': 0, 'y': -1},
|
||||
'left': {'x': -1, 'y': 0},
|
||||
'down': {'x': 0, 'y': 1},
|
||||
'right': {'x': 1, 'y': 0}
|
||||
'up': { 'x': 0, 'y': -1 },
|
||||
'left': { 'x': -1, 'y': 0 },
|
||||
'down': { 'x': 0, 'y': 1 },
|
||||
'right': { 'x': 1, 'y': 0 }
|
||||
};
|
||||
this.scan2 = {
|
||||
'up': {'x': 0, 'y': -1},
|
||||
'left': {'x': -1, 'y': 0},
|
||||
'down': {'x': 0, 'y': 1},
|
||||
'right': {'x': 1, 'y': 0},
|
||||
'leftup': {'x': -1, 'y': -1},
|
||||
'leftdown': {'x': -1, 'y': 1},
|
||||
'rightup': {'x': 1, 'y': -1},
|
||||
'rightdown': {'x': 1, 'y': 1}
|
||||
'up': { 'x': 0, 'y': -1 },
|
||||
'left': { 'x': -1, 'y': 0 },
|
||||
'down': { 'x': 0, 'y': 1 },
|
||||
'right': { 'x': 1, 'y': 0 },
|
||||
'leftup': { 'x': -1, 'y': -1 },
|
||||
'leftdown': { 'x': -1, 'y': 1 },
|
||||
'rightup': { 'x': 1, 'y': -1 },
|
||||
'rightdown': { 'x': 1, 'y': 1 }
|
||||
};
|
||||
}
|
||||
|
||||
@ -105,7 +105,7 @@ utils.prototype.replaceText = function (text, prefix) {
|
||||
if (cnt == 0) break;
|
||||
}
|
||||
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 = "";
|
||||
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)");
|
||||
if (value.indexOf('global:') >= 0 || value.indexOf('global:') >= 0)
|
||||
value = value.replace(/global[::]([a-zA-Z0-9_\u4E00-\u9FCC\u3040-\u30FF\u2160-\u216B\u0391-\u03C9]+)/g, "core.getGlobal('$1', 0)");
|
||||
if (value.indexOf('enemy:')>=0)
|
||||
if (value.indexOf('enemy:') >= 0)
|
||||
value = value.replace(/enemy:([a-zA-Z0-9_]+)[\.:]([a-zA-Z0-9_]+)/g, "core.material.enemys['$1'].$2");
|
||||
if (value.indexOf('blockId:')>=0)
|
||||
if (value.indexOf('blockId:') >= 0)
|
||||
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)");
|
||||
if (value.indexOf('blockCls:')>=0)
|
||||
if (value.indexOf('blockCls:') >= 0)
|
||||
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)");
|
||||
if (value.indexOf('temp:')>=0)
|
||||
if (value.indexOf('temp:') >= 0)
|
||||
value = value.replace(/temp:([a-zA-Z0-9_]+)/g, "core.getFlag('@temp@$1', 0)");
|
||||
}
|
||||
return value;
|
||||
@ -145,7 +145,7 @@ utils.prototype.calValue = function (value, prefix) {
|
||||
if (!core.isset(value)) return null;
|
||||
if (typeof value === 'string') {
|
||||
if (value.indexOf(':') >= 0 || value.indexOf("flag:") >= 0 || value.indexOf('global:') >= 0) {
|
||||
if (value.indexOf('switch:' >= 0))
|
||||
if (value.indexOf('switch:') >= 0)
|
||||
value = value.replace(/switch:([a-zA-Z0-9_]+)/g, "core.getFlag('" + (prefix || ":f@x@y") + "@$1', 0)");
|
||||
value = this.replaceValue(value);
|
||||
}
|
||||
@ -426,7 +426,7 @@ utils.prototype.clone = function (data, filter, recursion) {
|
||||
var copy = [];
|
||||
for (var i in data) {
|
||||
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;
|
||||
}
|
||||
@ -439,7 +439,7 @@ utils.prototype.clone = function (data, filter, recursion) {
|
||||
var copy = {};
|
||||
for (var i in data) {
|
||||
if (data.hasOwnProperty(i) && (!filter || filter(i, data[i])))
|
||||
copy[i] = core.clone(data[i], recursion?filter:null, recursion);
|
||||
copy[i] = core.clone(data[i], recursion ? filter : null, recursion);
|
||||
}
|
||||
return copy;
|
||||
}
|
||||
@ -496,9 +496,9 @@ utils.prototype.formatDate2 = function (date) {
|
||||
}
|
||||
|
||||
utils.prototype.formatTime = function (time) {
|
||||
return core.setTwoDigits(parseInt(time/3600000))
|
||||
+":"+core.setTwoDigits(parseInt(time/60000)%60)
|
||||
+":"+core.setTwoDigits(parseInt(time/1000)%60);
|
||||
return core.setTwoDigits(parseInt(time / 3600000))
|
||||
+ ":" + core.setTwoDigits(parseInt(time / 60000) % 60)
|
||||
+ ":" + core.setTwoDigits(parseInt(time / 1000) % 60);
|
||||
}
|
||||
|
||||
////// 两位数显示 //////
|
||||
@ -508,27 +508,27 @@ utils.prototype.setTwoDigits = function (x) {
|
||||
|
||||
utils.prototype.formatSize = function (size) {
|
||||
if (size < 1024) return size + 'B';
|
||||
else if (size < 1024 * 1024) return (size/1024).toFixed(2) + "KB";
|
||||
else return (size/1024/1024).toFixed(2) + "MB";
|
||||
else if (size < 1024 * 1024) return (size / 1024).toFixed(2) + "KB";
|
||||
else return (size / 1024 / 1024).toFixed(2) + "MB";
|
||||
}
|
||||
|
||||
utils.prototype.formatBigNumber = function (x, digits) {
|
||||
if (digits === true) digits = 5; // 兼容旧版onMap参数
|
||||
if (!digits || digits < 5) digits = 6; // 连同负号、小数点和后缀字母在内的总位数,至少需为5,默认为6
|
||||
x = Math.trunc(parseFloat(x)); // 尝试识别为小数,然后向0取整
|
||||
if (x == null || !Number.isFinite(x)) return '???'; // 无法识别的数或正负无穷大,显示'???'
|
||||
var units = [ // 单位及其后缀字母,可自定义,如改成千进制下的K、M、G、T、P
|
||||
{ "val": 1e4, "suffix": "w" },
|
||||
{ "val": 1e8, "suffix": "e" },
|
||||
{ "val": 1e12, "suffix": "z" },
|
||||
{ "val": 1e16, "suffix": "j" },
|
||||
{ "val": 1e20, "suffix": "g" },
|
||||
];
|
||||
if (Math.abs(x) > 1e20 * Math.pow(10, digits - 2))
|
||||
return x.toExponential(0); // 绝对值过大以致于失去精度的数,直接使用科学记数法,系数只保留整数
|
||||
var sign = x < 0 ? '-' : '';
|
||||
if (sign) --digits; // 符号位单独处理,负号要占一位
|
||||
x = Math.abs(x);
|
||||
if (digits === true) digits = 5; // 兼容旧版onMap参数
|
||||
if (!digits || digits < 5) digits = 6; // 连同负号、小数点和后缀字母在内的总位数,至少需为5,默认为6
|
||||
x = Math.trunc(parseFloat(x)); // 尝试识别为小数,然后向0取整
|
||||
if (x == null || !Number.isFinite(x)) return '???'; // 无法识别的数或正负无穷大,显示'???'
|
||||
var units = [ // 单位及其后缀字母,可自定义,如改成千进制下的K、M、G、T、P
|
||||
{ "val": 1e4, "suffix": "w" },
|
||||
{ "val": 1e8, "suffix": "e" },
|
||||
{ "val": 1e12, "suffix": "z" },
|
||||
{ "val": 1e16, "suffix": "j" },
|
||||
{ "val": 1e20, "suffix": "g" },
|
||||
];
|
||||
if (Math.abs(x) > 1e20 * Math.pow(10, digits - 2))
|
||||
return x.toExponential(0); // 绝对值过大以致于失去精度的数,直接使用科学记数法,系数只保留整数
|
||||
var sign = x < 0 ? '-' : '';
|
||||
if (sign) --digits; // 符号位单独处理,负号要占一位
|
||||
x = Math.abs(x);
|
||||
|
||||
if (x < Math.pow(10, digits)) return sign + x;
|
||||
|
||||
@ -539,24 +539,24 @@ utils.prototype.formatBigNumber = function (x, digits) {
|
||||
u = u.substring(0, u[u.length - 2] == '.' ? u.length - 2 : u.length - 1);
|
||||
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 = {
|
||||
"easeIn": function(t) {
|
||||
"easeIn": function (t) {
|
||||
return Math.pow(t, 3);
|
||||
},
|
||||
"easeOut": function(t) {
|
||||
"easeOut": function (t) {
|
||||
return 1 - Math.pow(1 - t, 3);
|
||||
},
|
||||
"easeInOut": function(t) {
|
||||
"easeInOut": function (t) {
|
||||
// easeInOut试了一下感觉二次方效果明显点
|
||||
if (t < 0.5) return Math.pow(t, 2) * 2;
|
||||
else return 1 - Math.pow(1 - t, 2) * 2;
|
||||
},
|
||||
"linear": function(t) {
|
||||
"linear": function (t) {
|
||||
return t
|
||||
}
|
||||
}
|
||||
@ -659,7 +659,7 @@ utils.prototype._encodeRoute_encodeOne = function (t) {
|
||||
return 'k' + t.substring(6);
|
||||
else if (t.indexOf('random:') == 0)
|
||||
return 'X' + t.substring(7);
|
||||
return '('+t+')';
|
||||
return '(' + t + ')';
|
||||
}
|
||||
|
||||
////// 解密路线 //////
|
||||
@ -676,7 +676,7 @@ utils.prototype.decodeRoute = function (route) {
|
||||
} catch (e) {
|
||||
}
|
||||
|
||||
var decodeObj = {route: route, index: 0, ans: []};
|
||||
var decodeObj = { route: route, index: 0, ans: [] };
|
||||
while (decodeObj.index < decodeObj.route.length) {
|
||||
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') ?
|
||||
this._decodeRoute_getString(decodeObj) : this._decodeRoute_getNumber(decodeObj);
|
||||
|
||||
var mp = {"U": "up", "D": "down", "L": "left", "R": "right"};
|
||||
var mp = { "U": "up", "D": "down", "L": "left", "R": "right" };
|
||||
|
||||
switch (c) {
|
||||
case "U":
|
||||
@ -797,7 +797,7 @@ utils.prototype._decodeRoute_decodeOne = function (decodeObj, c) {
|
||||
var px = this._decodeRoute_getNumber(decodeObj);
|
||||
++decodeObj.index;
|
||||
var py = this._decodeRoute_getNumber(decodeObj);
|
||||
decodeObj.ans.push("click:"+nxt+":"+px+":"+py);
|
||||
decodeObj.ans.push("click:" + nxt + ":" + px + ":" + py);
|
||||
break;
|
||||
case "X":
|
||||
decodeObj.ans.push("random:" + nxt);
|
||||
@ -870,7 +870,7 @@ utils.prototype.turnDirection = function (turn, direction) {
|
||||
direction = direction || core.getHeroLoc('direction');
|
||||
var directionList = ["left", "leftup", "up", "rightup", "right", "rightdown", "down", "leftdown"];
|
||||
if (directionList.indexOf(turn) >= 0) return turn;
|
||||
if (turn == ':hero') return core.getHeroLoc('direction');
|
||||
if (turn == ':hero') return core.getHeroLoc('direction');
|
||||
if (turn == ':backhero') return this.turnDirection(':back', core.getHeroLoc('direction'));
|
||||
if (typeof turn === 'number' && turn % 45 == 0) turn /= 45;
|
||||
else {
|
||||
@ -1030,7 +1030,7 @@ utils.prototype.readFileContent = function (content) {
|
||||
// 检查base64
|
||||
try {
|
||||
obj = JSON.parse(LZString.decompressFromBase64(content));
|
||||
} catch (e) {}
|
||||
} catch (e) { }
|
||||
if (!obj) {
|
||||
try {
|
||||
obj = JSON.parse(content);
|
||||
@ -1090,7 +1090,7 @@ utils.prototype.download = function (filename, content) {
|
||||
// Step 3: 如果是Safari浏览器,则提示并打开新窗口
|
||||
if (core.platform.isSafari) {
|
||||
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 opened = window.open(href, "_blank");
|
||||
window.URL.revokeObjectURL(href);
|
||||
@ -1098,7 +1098,7 @@ utils.prototype.download = function (filename, content) {
|
||||
}
|
||||
|
||||
// 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) {
|
||||
window.navigator.msSaveBlob(blob, filename);
|
||||
}
|
||||
@ -1168,7 +1168,7 @@ utils.prototype.myprompt = function (hint, value, callback) {
|
||||
main.dom.inputDiv.style.display = 'block';
|
||||
main.dom.inputMessage.innerHTML = hint.replace(/\n/g, '<br/>');
|
||||
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.inputNo.blur();
|
||||
setTimeout(function () {
|
||||
@ -1350,7 +1350,7 @@ utils.prototype.http = function (type, url, formData, success, error, mimeType,
|
||||
|
||||
// LZW-compress
|
||||
// https://gist.github.com/revolunet/843889
|
||||
function lzw_encode(s) {
|
||||
function lzw_encode (s) {
|
||||
var dict = {};
|
||||
var data = (s + "").split("");
|
||||
var out = [];
|
||||
@ -1377,7 +1377,7 @@ function lzw_encode(s) {
|
||||
}
|
||||
|
||||
// Decompress an LZW-encoded string
|
||||
function lzw_decode(s) {
|
||||
function lzw_decode (s) {
|
||||
var dict = {};
|
||||
var data = (s + "").split("");
|
||||
var currChar = data[0];
|
||||
|
||||
Loading…
Reference in New Issue
Block a user