feat: 优化各种性能表现

This commit is contained in:
unanmed 2024-11-07 20:01:00 +08:00
parent 740dfdb6ce
commit 7e5b20d3ad
10 changed files with 75 additions and 480 deletions

View File

@ -2138,10 +2138,6 @@ var terndefs_f6783a0a_522d_417e_8407_94c67b692e50 = [
'!doc': '初始化core', '!doc': '初始化core',
'!type': 'fn(coreData: ?, callback: fn())' '!type': 'fn(coreData: ?, callback: fn())'
}, },
doFunc: {
'!doc': '执行一个函数;如果函数名是字符串则转发到插件中',
'!type': 'fn(func: name|fn(), _this?: ?)'
},
control: { control: {
'!doc': '负责整个游戏的核心控制系统,分为如下几个部分:<br/>- requestAnimationFrame相关<br/>- 标题界面,开始和重新开始游戏<br/>- 自动寻路和人物行走相关<br/>- 画布、位置、阻激夹域、显伤等相关<br/>- 录像的回放相关<br/>- 存读档,自动存档,同步存档等相关<br/>- 人物属性和状态、位置、变量等相关<br/>- 天气、色调、音乐和音效的播放<br/>- 状态栏和工具栏相关<br/>- 界面resize相关', '!doc': '负责整个游戏的核心控制系统,分为如下几个部分:<br/>- requestAnimationFrame相关<br/>- 标题界面,开始和重新开始游戏<br/>- 自动寻路和人物行走相关<br/>- 画布、位置、阻激夹域、显伤等相关<br/>- 录像的回放相关<br/>- 存读档,自动存档,同步存档等相关<br/>- 人物属性和状态、位置、变量等相关<br/>- 天气、色调、音乐和音效的播放<br/>- 状态栏和工具栏相关<br/>- 界面resize相关',
showStatusBar: { showStatusBar: {

View File

@ -166,20 +166,13 @@ actions.prototype.unregisterAction = function (action, name) {
}; };
////// 执行一个用户交互行为 ////// ////// 执行一个用户交互行为 //////
actions.prototype.doRegisteredAction = function (action) { actions.prototype.doRegisteredAction = function (action, ...params) {
var actions = this.actions[action]; var actions = this.actions[action];
if (!actions) return false; if (!actions) return false;
for (var i = 0; i < actions.length; ++i) { for (var i = 0; i < actions.length; ++i) {
try { try {
if ( const res = actions[i].func.apply(this, params);
core.doFunc.apply( if (res) return true;
core,
[actions[i].func, this].concat(
Array.prototype.slice.call(arguments, 1)
)
)
)
return true;
} catch (e) { } catch (e) {
console.error(e); console.error(e);
console.error('ERROR in actions[' + actions[i].name + '].'); console.error('ERROR in actions[' + actions[i].name + '].');

View File

@ -26,50 +26,12 @@ control.prototype._init = function () {
false, false,
this._animationFrame_totalTime this._animationFrame_totalTime
); );
this.registerAnimationFrame(
'autoSave',
true,
this._animationFrame_autoSave
);
this.registerAnimationFrame( this.registerAnimationFrame(
'globalAnimate', 'globalAnimate',
true, true,
this._animationFrame_globalAnimate this._animationFrame_globalAnimate
); );
this.registerAnimationFrame('animate', true, this._animationFrame_animate);
this.registerAnimationFrame(
'heroMoving',
true,
this._animationFrame_heroMoving
);
this.registerAnimationFrame('weather', true, this._animationFrame_weather);
this.registerAnimationFrame('tip', true, this._animateFrame_tip); this.registerAnimationFrame('tip', true, this._animateFrame_tip);
// --- 注册系统的天气
this.registerWeather(
'rain',
this._weather_rain,
this._animationFrame_weather_rain
);
this.registerWeather(
'snow',
this._weather_snow,
this._animationFrame_weather_snow
);
this.registerWeather(
'fog',
this._weather_fog,
this.__animateFrame_weather_image
);
this.registerWeather(
'cloud',
this._weather_cloud,
this.__animateFrame_weather_image
);
this.registerWeather(
'sun',
this._weather_sun,
this._animationFrame_weather_sun
);
// --- 注册系统的replay // --- 注册系统的replay
this.registerReplayAction('move', this._replayAction_move); this.registerReplayAction('move', this._replayAction_move);
this.registerReplayAction('item', this._replayAction_item); this.registerReplayAction('item', this._replayAction_item);
@ -122,7 +84,7 @@ control.prototype._setRequestAnimationFrame = function () {
if (b.func) { if (b.func) {
try { try {
if (core.isPlaying() || !b.needPlaying) if (core.isPlaying() || !b.needPlaying)
core.doFunc(b.func, core.control, timestamp); b.func.call(core.control, timestamp);
} catch (e) { } catch (e) {
console.error(e); console.error(e);
console.error( console.error(
@ -185,11 +147,7 @@ control.prototype._animationFrame_totalTime = function (timestamp) {
} }
}; };
control.prototype._animationFrame_autoSave = function (timestamp) { control.prototype._animationFrame_autoSave = function (timestamp) {};
// if (timestamp - core.saves.autosave.time <= 5000) return;
// core.control.checkAutosave();
// core.saves.autosave.time = timestamp;
};
control.prototype._animationFrame_globalAnimate = function (timestamp) { control.prototype._animationFrame_globalAnimate = function (timestamp) {
if (timestamp - core.animateFrame.globalTime <= core.values.animateSpeed) if (timestamp - core.animateFrame.globalTime <= core.values.animateSpeed)
@ -239,201 +197,19 @@ control.prototype._animationFrame_globalAnimate = function (timestamp) {
core.animateFrame.globalTime = timestamp; core.animateFrame.globalTime = timestamp;
}; };
control.prototype._animationFrame_animate = function (timestamp) { control.prototype._animationFrame_animate = function (timestamp) {};
if (
timestamp - core.animateFrame.animateTime < 50 ||
!core.status.animateObjs ||
core.status.animateObjs.length == 0
)
return;
core.clearMap('animate');
// 更新帧
for (var i = 0; i < core.status.animateObjs.length; i++) {
var obj = core.status.animateObjs[i];
if (obj.index == obj.animate.frames.length) {
(function (callback) {
setTimeout(function () {
if (callback) callback();
});
})(obj.callback);
}
}
core.status.animateObjs = core.status.animateObjs.filter(function (obj) {
return obj.index < obj.animate.frames.length;
});
core.status.animateObjs.forEach(function (obj) {
if (obj.hero) {
core.maps._drawAnimateFrame(
'animate',
obj.animate,
core.status.heroCenter.px,
core.status.heroCenter.py,
obj.index++
);
} else {
core.maps._drawAnimateFrame(
'animate',
obj.animate,
obj.centerX,
obj.centerY,
obj.index++
);
}
});
core.animateFrame.animateTime = timestamp;
};
control.prototype._animationFrame_heroMoving = function (timestamp) { control.prototype._animationFrame_heroMoving = function (timestamp) {};
// Deprecated. See src/plugin/game/heroFourFrames.js
};
control.prototype._animationFrame_weather = function (timestamp) { control.prototype._animationFrame_weather = function (timestamp) {};
var weather = core.animateFrame.weather,
type = weather.type;
if (
!core.dymCanvas.weather ||
!core.control.weathers[type] ||
!core.control.weathers[type].frameFunc
)
return;
try {
core.doFunc(
core.control.weathers[type].frameFunc,
core.control,
timestamp,
core.animateFrame.weather.level
);
} catch (e) {
console.error(e);
console.error('ERROR in weather[' + type + ']:已自动注销该项。');
core.unregisterWeather(type);
}
};
control.prototype._animationFrame_weather_rain = function (timestamp, level) { control.prototype._animationFrame_weather_rain = function (timestamp, level) {};
if (timestamp - core.animateFrame.weather.time < 30) return;
var ctx = core.dymCanvas.weather,
ox = core.bigmap.offsetX,
oy = core.bigmap.offsetY;
core.clearMap('weather');
ctx.strokeStyle = 'rgba(174,194,224,0.8)';
ctx.lineWidth = 1;
ctx.lineCap = 'round';
core.animateFrame.weather.nodes.forEach(function (p) { control.prototype._animationFrame_weather_snow = function (timestamp, level) {};
ctx.beginPath();
ctx.moveTo(p.x - ox, p.y - oy);
ctx.lineTo(p.x + p.l * p.xs - ox, p.y + p.l * p.ys - oy);
ctx.stroke();
p.x += p.xs; control.prototype.__animateFrame_weather_image = function (timestamp, level) {};
p.y += p.ys;
if (p.x > core.bigmap.width * 32 || p.y > core.bigmap.height * 32) {
p.x = Math.random() * core.bigmap.width * 32;
p.y = -10;
}
});
ctx.fill(); control.prototype._animationFrame_weather_sun = function (timestamp, level) {};
core.animateFrame.weather.time = timestamp;
};
control.prototype._animationFrame_weather_snow = function (timestamp, level) {
if (timestamp - core.animateFrame.weather.time < 30) return;
var ctx = core.dymCanvas.weather,
ox = core.bigmap.offsetX,
oy = core.bigmap.offsetY;
core.clearMap('weather');
ctx.fillStyle = 'rgba(255, 255, 255, 0.8)';
ctx.beginPath();
core.animateFrame.weather.data = core.animateFrame.weather.data || 0;
core.animateFrame.weather.data += 0.01;
var angle = core.animateFrame.weather.data;
core.animateFrame.weather.nodes.forEach(function (p) {
ctx.moveTo(p.x - ox, p.y - oy);
ctx.arc(p.x - ox, p.y - oy, p.r, 0, Math.PI * 2, true);
// update
p.x += Math.sin(angle) * core.animateFrame.weather.level;
p.y += Math.cos(angle + p.d) + 1 + p.r / 2;
if (
p.x > core.bigmap.width * 32 + 5 ||
p.x < -5 ||
p.y > core.bigmap.height * 32
) {
if (Math.random() > 1 / 3) {
p.x = Math.random() * core.bigmap.width * 32;
p.y = -10;
} else {
if (Math.sin(angle) > 0) p.x = -5;
else p.x = core.bigmap.width * 32 + 5;
p.y = Math.random() * core.bigmap.height * 32;
}
}
});
ctx.fill();
core.animateFrame.weather.time = timestamp;
};
control.prototype.__animateFrame_weather_image = function (timestamp, level) {
if (timestamp - core.animateFrame.weather.time < 30) return;
var node = core.animateFrame.weather.nodes[0];
var image = node.image;
if (!image) return;
core.clearMap('weather');
core.setAlpha('weather', node.level / 500);
var wind = 1.5;
var width = image.width,
height = image.height;
node.x += node.dx * wind;
node.y += (2 * node.dy - 1) * wind;
if (node.x + 3 * width <= core._PX_) {
node.x += 4 * width;
while (node.x > 0) node.x -= width;
}
node.dy += node.delta;
if (node.dy >= 1) {
node.delta = -0.001;
} else if (node.dy <= 0) {
node.delta = 0.001;
}
if (node.y + 3 * height <= core._PY_) {
node.y += 4 * height;
while (node.y > 0) node.y -= height;
} else if (node.y >= 0) {
node.y -= height;
}
for (var i = 0; i < 3; ++i) {
for (var j = 0; j < 3; ++j) {
if (
node.x + (i + 1) * width <= 0 ||
node.x + i * width >= core._PX_ ||
node.y + (j + 1) * height <= 0 ||
node.y + j * height >= core._PY_
)
continue;
core.drawImage(
'weather',
image,
node.x + i * width,
node.y + j * height
);
}
}
core.setAlpha('weather', 1);
core.animateFrame.weather.time = timestamp;
};
control.prototype._animationFrame_weather_sun = function (timestamp, level) {
if (timestamp - core.animateFrame.weather.time < 30) return;
var node = core.animateFrame.weather.nodes[0];
var opacity = node.opacity + node.delta;
if (opacity > level / 10 + 0.3 || opacity < level / 10 - 0.3)
node.delta = -node.delta;
node.opacity = opacity;
core.setOpacity('weather', core.clamp(opacity, 0, 1));
core.animateFrame.weather.time = timestamp;
};
control.prototype._animateFrame_tip = function (timestamp) { control.prototype._animateFrame_tip = function (timestamp) {
if (core.animateFrame.tip == null) return; if (core.animateFrame.tip == null) return;
@ -1859,8 +1635,7 @@ control.prototype.unregisterReplayAction = function (name) {
control.prototype._doReplayAction = function (action) { control.prototype._doReplayAction = function (action) {
for (var i in this.replayActions) { for (var i in this.replayActions) {
try { try {
if (core.doFunc(this.replayActions[i].func, this, action)) if (this.replayActions[i].func.call(this, action)) return true;
return true;
} catch (e) { } catch (e) {
console.error(e); console.error(e);
console.error( console.error(
@ -3118,138 +2893,27 @@ control.prototype.getMappedName = function (name) {
////// 更改天气效果 ////// ////// 更改天气效果 //////
control.prototype.setWeather = function (type, level) { control.prototype.setWeather = function (type, level) {
// 非雨雪 // Deprecated. Use WeatherController API instead.
if (type == null || !this.weathers[type]) {
core.deleteCanvas('weather');
core.animateFrame.weather.type = null;
core.animateFrame.weather.nodes = [];
return;
}
if (level == null) level = core.animateFrame.weather.level;
level = core.clamp(parseInt(level) || 5, 1, 10);
// 当前天气:则忽略
if (
type == core.animateFrame.weather.type &&
level == core.animateFrame.weather.level
)
return;
// 计算当前的宽高
core.createCanvas('weather', 0, 0, core._PX_, core._PY_, 80);
core.setOpacity('weather', 1.0);
core.animateFrame.weather.type = type;
core.animateFrame.weather.level = level;
core.animateFrame.weather.nodes = [];
try {
core.doFunc(this.weathers[type].initFunc, this, level);
} catch (e) {
console.error(e);
console.error('ERROR in weather[' + type + ']:已自动注销该项。');
core.unregisterWeather(type);
}
}; };
////// 注册一个天气 ////// ////// 注册一个天气 //////
// name为天气类型如 sun, rain, snow 等 // name为天气类型如 sun, rain, snow 等
// initFunc 为设置为此天气时的初始化接受level参数 // initFunc 为设置为此天气时的初始化接受level参数
// frameFunc 为该天气下每帧的效果接受和timestamp参数从页面加载完毕到当前经过的时间 // frameFunc 为该天气下每帧的效果接受和timestamp参数从页面加载完毕到当前经过的时间
control.prototype.registerWeather = function (name, initFunc, frameFunc) { control.prototype.registerWeather = function (name, initFunc, frameFunc) {};
this.unregisterWeather(name);
this.weathers[name] = { initFunc: initFunc, frameFunc: frameFunc };
};
////// 取消注册一个天气 ////// ////// 取消注册一个天气 //////
control.prototype.unregisterWeather = function (name) { control.prototype.unregisterWeather = function (name) {};
delete this.weathers[name];
if (core.animateFrame.weather.type == name) {
this.setWeather(null);
}
};
control.prototype._weather_rain = function (level) { control.prototype._weather_rain = function (level) {};
var number =
level *
parseInt(
(20 * core.bigmap.width * core.bigmap.height) /
(core._WIDTH_ * core._HEIGHT_)
);
for (var a = 0; a < number; a++) {
core.animateFrame.weather.nodes.push({
x: Math.random() * core.bigmap.width * 32,
y: Math.random() * core.bigmap.height * 32,
l: Math.random() * 2.5,
xs: -4 + Math.random() * 4 + 2,
ys: Math.random() * 10 + 10
});
}
};
control.prototype._weather_snow = function (level) { control.prototype._weather_snow = function (level) {};
var number =
level *
parseInt(
(20 * core.bigmap.width * core.bigmap.height) /
(core._WIDTH_ * core._HEIGHT_)
);
for (var a = 0; a < number; a++) {
core.animateFrame.weather.nodes.push({
x: Math.random() * core.bigmap.width * 32,
y: Math.random() * core.bigmap.height * 32,
r: Math.random() * 5 + 1,
d: Math.random() * Math.min(level, 200)
});
}
};
control.prototype._weather_fog = function (level) { control.prototype._weather_fog = function (level) {};
if (!core.animateFrame.weather.fog) return;
core.animateFrame.weather.nodes = [
{
image: core.animateFrame.weather.fog,
level: 40 * level,
x: 0,
y: -core._PY_ / 2,
dx: -Math.random() * 1.5,
dy: Math.random(),
delta: 0.001
}
];
};
control.prototype._weather_cloud = function (level) { control.prototype._weather_cloud = function (level) {};
if (!core.animateFrame.weather.cloud) return;
core.animateFrame.weather.nodes = [
{
image: core.animateFrame.weather.cloud,
level: 40 * level,
x: 0,
y: -core._PY_ / 2,
dx: -Math.random() * 1.5,
dy: Math.random(),
delta: 0.001
}
];
};
control.prototype._weather_sun = function (level) { control.prototype._weather_sun = function (level) {};
if (!core.animateFrame.weather.sun) return;
// 直接绘制
core.clearMap('weather');
core.drawImage(
'weather',
core.animateFrame.weather.sun,
0,
0,
core.animateFrame.weather.sun.width,
core.animateFrame.weather.sun.height,
0,
0,
core._PX_,
core._PY_
);
core.setOpacity('weather', level / 10);
core.animateFrame.weather.nodes = [{ opacity: level / 10, delta: 0.01 }];
};
////// 更改画面色调 ////// ////// 更改画面色调 //////
control.prototype.setCurtain = function (color, time, moveMode, callback) { control.prototype.setCurtain = function (color, time, moveMode, callback) {
@ -3466,46 +3130,7 @@ control.prototype.updateStatusBar_update = function () {
// see src/plugin/game/ui.js // see src/plugin/game/ui.js
}; };
control.prototype._updateStatusBar_setToolboxIcon = function () { control.prototype._updateStatusBar_setToolboxIcon = function () {};
if (core.isReplaying()) {
core.statusBar.image.book.src = core.status.replay.pausing
? core.statusBar.icons.play.src
: core.statusBar.icons.pause.src;
core.statusBar.image.book.style.opacity = 1;
core.statusBar.image.fly.src = core.statusBar.icons.stop.src;
core.statusBar.image.fly.style.opacity = 1;
core.statusBar.image.toolbox.src = core.statusBar.icons.rewind.src;
core.statusBar.image.keyboard.src = core.statusBar.icons.book.src;
core.statusBar.image.shop.src = core.statusBar.icons.floor.src;
core.statusBar.image.save.src = core.statusBar.icons.speedDown.src;
core.statusBar.image.save.style.opacity = 1;
core.statusBar.image.load.src = core.statusBar.icons.speedUp.src;
core.statusBar.image.settings.src = core.statusBar.icons.save.src;
} else {
core.statusBar.image.book.src = core.statusBar.icons.book.src;
core.statusBar.image.book.style.opacity = core.hasItem('book')
? 1
: 0.3;
if (!core.flags.equipboxButton) {
core.statusBar.image.fly.src = core.statusBar.icons.fly.src;
core.statusBar.image.fly.style.opacity = core.hasItem('fly')
? 1
: 0.3;
} else {
core.statusBar.image.fly.src = core.statusBar.icons.equipbox.src;
core.statusBar.image.fly.style.opacity = 1;
}
core.statusBar.image.toolbox.src = core.statusBar.icons.toolbox.src;
core.statusBar.image.keyboard.src = core.statusBar.icons.keyboard.src;
core.statusBar.image.shop.src = core.statusBar.icons.shop.src;
core.statusBar.image.save.src = core.statusBar.icons.save.src;
core.statusBar.image.save.style.opacity = core.hasFlag('__forbidSave__')
? 0.3
: 1;
core.statusBar.image.load.src = core.statusBar.icons.load.src;
core.statusBar.image.settings.src = core.statusBar.icons.settings.src;
}
};
control.prototype.showStatusBar = function () { control.prototype.showStatusBar = function () {
// see src/plugin/game/ui.js // see src/plugin/game/ui.js
@ -3540,7 +3165,7 @@ control.prototype.unregisterResize = function (name) {
control.prototype._doResize = function (obj) { control.prototype._doResize = function (obj) {
for (var i in this.resizes) { for (var i in this.resizes) {
try { try {
if (core.doFunc(this.resizes[i].func, this, obj)) return true; if (this.resizes[i].func.call(this, obj)) return true;
} catch (e) { } catch (e) {
console.error(e); console.error(e);
console.error( console.error(

View File

@ -697,13 +697,4 @@ core.prototype._forwardFunc = function (name, funcname) {
); );
}; };
core.prototype.doFunc = function (func, _this) {
if (typeof func == 'string') {
throw new Error('Parameter func must be a function.');
// func = core.plugin[func];
// _this = core.plugin;
}
return func.apply(_this, Array.prototype.slice.call(arguments, 2));
};
var core = new core(); var core = new core();

View File

@ -357,7 +357,7 @@ events.prototype.doSystemEvent = function (type, data, callback) {
core.clearRouteFolding(); core.clearRouteFolding();
if (this.systemEvents[type]) { if (this.systemEvents[type]) {
try { try {
return core.doFunc(this.systemEvents[type], this, data, callback); return this.systemEvents[type].call(this, data, callback);
} catch (e) { } catch (e) {
console.error(e); console.error(e);
console.error('ERROR in systemEvents[' + type + ']'); console.error('ERROR in systemEvents[' + type + ']');
@ -1035,7 +1035,7 @@ events.prototype.doEvent = function (data, x, y, prefix) {
var type = data.type; var type = data.type;
if (this.actions[type]) { if (this.actions[type]) {
try { try {
return core.doFunc(this.actions[type], this, data, x, y, prefix); return this.actions[type].call(this, data, x, y, prefix);
} catch (e) { } catch (e) {
console.error(e); console.error(e);
console.error('ERROR in actions[' + type + ']'); console.error('ERROR in actions[' + type + ']');

View File

@ -188,24 +188,24 @@ maps.prototype.extractBlocksForUI = function (map, flags) {
////// 从ID获得数字 ////// ////// 从ID获得数字 //////
maps.prototype.getNumberById = function (id) { maps.prototype.getNumberById = function (id) {
id = this.getIdOfThis(id); id = this.getIdOfThis(id);
core.status.id2number = core.status.id2number || {}; core.status.id2number ??= {};
if (core.status.id2number[id] != null) return core.status.id2number[id]; if (core.status.id2number[id] != null) return core.status.id2number[id];
return (core.status.id2number[id] = this._getNumberById(id)); return (core.status.id2number[id] = this._getNumberById(id));
}; };
maps.prototype._getNumberById = function (id) { maps.prototype._getNumberById = function (id) {
for (var number in this.blocksInfo) { for (var number in this.blocksInfo) {
if ((this.blocksInfo[number] || {}).id == id) if ((this.blocksInfo[number] || {}).id === id)
return parseInt(number) || 0; return Number(number) || 0;
} }
// tilesets // tilesets
if (/^X\d+$/.test(id)) { if (id[0] === 'X' && !isNaN(Number(id.slice(1)))) {
if (core.icons.getTilesetOffset(id)) return parseInt(id.substring(1)); if (core.icons.getTilesetOffset(id)) return Number(id.slice(1));
} }
// 特殊ID // 特殊ID
if (id == 'none') return 0; if (id === 'none') return 0;
if (id == 'airwall') return 17; else if (id === 'airwall') return 17;
return 0; else return 0;
}; };
maps.prototype.getBlockByNumber = function (number) { maps.prototype.getBlockByNumber = function (number) {

View File

@ -644,17 +644,23 @@ utils.prototype.encodeRoute = function (route, compress = true) {
cnt = 0; cnt = 0;
route.forEach(function (t) { route.forEach(function (t) {
if (t == 'up' || t == 'down' || t == 'left' || t == 'right') { if (t === 'up' || t === 'down' || t === 'left' || t === 'right') {
if (t != lastMove && cnt > 0) { if (t !== lastMove && cnt > 0) {
ans += lastMove.substring(0, 1).toUpperCase(); const char = lastMove[0];
if (char) {
ans += char.toUpperCase();
}
if (cnt > 1) ans += cnt; if (cnt > 1) ans += cnt;
cnt = 0; cnt = 0;
lastMove = t;
} }
lastMove = t;
cnt++; cnt++;
} else { } else {
if (cnt > 0) { if (cnt > 0) {
ans += lastMove.substring(0, 1).toUpperCase(); const char = lastMove[0];
if (char) {
ans += char.toUpperCase();
}
if (cnt > 1) ans += cnt; if (cnt > 1) ans += cnt;
cnt = 0; cnt = 0;
} }
@ -662,7 +668,7 @@ utils.prototype.encodeRoute = function (route, compress = true) {
} }
}); });
if (cnt > 0) { if (cnt > 0) {
ans += lastMove.substring(0, 1).toUpperCase(); ans += lastMove[0].toUpperCase();
if (cnt > 1) ans += cnt; if (cnt > 1) ans += cnt;
} }
if (!compress) { if (!compress) {
@ -674,33 +680,32 @@ utils.prototype.encodeRoute = function (route, compress = true) {
utils.prototype._encodeRoute_id2number = function (id) { utils.prototype._encodeRoute_id2number = function (id) {
var number = core.maps.getNumberById(id); var number = core.maps.getNumberById(id);
return number == 0 ? id : number; return number === 0 ? id : number;
}; };
utils.prototype._encodeRoute_encodeOne = function (t) { utils.prototype._encodeRoute_encodeOne = function (t) {
if (t.indexOf('item:') == 0) if (t.startsWith('item:'))
return 'I' + this._encodeRoute_id2number(t.substring(5)) + ':'; return 'I' + this._encodeRoute_id2number(t.slice(5)) + ':';
else if (t.indexOf('unEquip:') == 0) return 'u' + t.substring(8); else if (t.startsWith('unEquip:')) return 'u' + t.slice(8);
else if (t.indexOf('equip:') == 0) else if (t.startsWith('equip:'))
return 'e' + this._encodeRoute_id2number(t.substring(6)) + ':'; return 'e' + this._encodeRoute_id2number(t.slice(6)) + ':';
else if (t.indexOf('saveEquip:') == 0) return 's' + t.substring(10); else if (t.startsWith('saveEquip:')) return 's' + t.slice(10);
else if (t.indexOf('loadEquip:') == 0) return 'l' + t.substring(10); else if (t.startsWith('loadEquip:')) return 'l' + t.slice(10);
else if (t.indexOf('fly:') == 0) return 'F' + t.substring(4) + ':'; else if (t.startsWith('fly:')) return 'F' + t.slice(4) + ':';
else if (t == 'choices:none') return 'c'; else if (t === 'choices:none') return 'c';
else if (t.indexOf('choices:') == 0) return 'C' + t.substring(8); else if (t.startsWith('choices:')) return 'C' + t.slice(8);
else if (t.indexOf('shop:') == 0) return 'S' + t.substring(5) + ':'; else if (t.startsWith('shop:')) return 'S' + t.slice(5) + ':';
else if (t == 'turn') return 'T'; else if (t === 'turn') return 'T';
else if (t.indexOf('turn:') == 0) else if (t.startsWith('turn:')) return 't' + t[5].toUpperCase() + ':';
return 't' + t.substring(5).substring(0, 1).toUpperCase() + ':'; else if (t === 'getNext') return 'G';
else if (t == 'getNext') return 'G'; else if (t === 'input:none') return 'p';
else if (t == 'input:none') return 'p'; else if (t.startsWith('input:')) return 'P' + t.slice(6);
else if (t.indexOf('input:') == 0) return 'P' + t.substring(6); else if (t.startsWith('input2:')) return 'Q' + t.slice(7) + ':';
else if (t.indexOf('input2:') == 0) return 'Q' + t.substring(7) + ':'; else if (t === 'no') return 'N';
else if (t == 'no') return 'N'; else if (t.startsWith('move:')) return 'M' + t.slice(5);
else if (t.indexOf('move:') == 0) return 'M' + t.substring(5); else if (t.startsWith('key:')) return 'K' + t.slice(4);
else if (t.indexOf('key:') == 0) return 'K' + t.substring(4); else if (t.startsWith('click:')) return 'k' + t.slice(6);
else if (t.indexOf('click:') == 0) return 'k' + t.substring(6); else if (t.startsWith('random:')) return 'X' + t.slice(7);
else if (t.indexOf('random:') == 0) return 'X' + t.substring(7);
return '(' + t + ')'; return '(' + t + ')';
}; };
@ -1350,22 +1355,19 @@ utils.prototype.hashCode = function (obj) {
}; };
utils.prototype.same = function (a, b) { utils.prototype.same = function (a, b) {
if (a == null && b == null) return true;
if (a == null || b == null) return false;
if (a === b) return true; if (a === b) return true;
if (a == null || b == null) return false;
if (a instanceof Array && b instanceof Array) { if (a instanceof Array && b instanceof Array) {
if (a.length != b.length) return false; if (a.length !== b.length) return false;
for (var i = 0; i < a.length; i++) { for (var i = 0; i < a.length; i++) {
if (!this.same(a[i], b[i])) return false; if (!this.same(a[i], b[i])) return false;
} }
return true; return true;
} }
if (a instanceof Object && b instanceof Object) { if (a instanceof Object && b instanceof Object) {
var obj = {}; const toCompare = new Set([...Object.keys(a), ...Object.keys(b)]);
for (var i in a) obj[i] = true; for (const key of toCompare) {
for (var i in b) obj[i] = true; if (!this.same(a[key], b[key])) return false;
for (var i in obj) {
if (!this.same(a[i], b[i])) return false;
} }
return true; return true;
} }

View File

@ -85,7 +85,7 @@ export class SoundEffect extends AudioPlayer {
* @returns id * @returns id
*/ */
playSE() { playSE() {
if (SoundEffect.disable) return; if (SoundEffect.disable || this.volumn === 0) return;
const node = this.play(); const node = this.play();
if (!node) return; if (!node) return;
const index = SoundEffect.playIndex++; const index = SoundEffect.playIndex++;

View File

@ -159,6 +159,7 @@ export class Portal extends Sprite {
} }
private renderPortal(canvas: MotaOffscreenCanvas2D) { private renderPortal(canvas: MotaOffscreenCanvas2D) {
if (this.renderable.size === 0) return;
const { ctx } = canvas; const { ctx } = canvas;
const p = this.particleSetting.value; const p = this.particleSetting.value;

13
src/types/core.d.ts vendored
View File

@ -1075,19 +1075,6 @@ interface Core extends Pick<Main, CoreDataFromMain> {
*/ */
init(coreData: MainData, callback?: () => void): Promise<void>; init(coreData: MainData, callback?: () => void): Promise<void>;
/**
* @deprecated
* 西
* @param func
* @param _this
* @param params
*/
doFunc<F extends (...args: any) => any>(
func: F,
_this: any,
...params: Parameters<F>
): ReturnType<F>;
_afterLoadResources(callback?: () => void): void; _afterLoadResources(callback?: () => void): void;
} }