chore: 同步 template 对 main.js 和 libs 的修改

This commit is contained in:
unanmed 2025-10-15 18:18:01 +08:00
parent ca7e1a3fce
commit 741ba164e9
7 changed files with 218 additions and 1513 deletions

File diff suppressed because it is too large Load Diff

View File

@ -1584,7 +1584,8 @@ control.prototype._replay_finished = function () {
core.status.replay.replaying = true; core.status.replay.replaying = true;
core.ui.closePanel(); core.ui.closePanel();
core.pauseReplay(); core.pauseReplay();
} },
true
); );
}; };
@ -1639,7 +1640,8 @@ control.prototype._replay_error = function (action, callback) {
core.ui.closePanel(); core.ui.closePanel();
core.stopReplay(true); core.stopReplay(true);
if (callback) callback(); if (callback) callback();
} },
true
); );
}; };
@ -2216,139 +2218,20 @@ control.prototype.syncSave = function (type) {
}; };
control.prototype._syncSave_http = function (type, saves) { control.prototype._syncSave_http = function (type, saves) {
if (!saves) return core.drawText('没有要同步的存档'); // Deprecated.
var formData = new FormData();
formData.append('type', 'save');
formData.append('name', core.firstData.name);
formData.append('data', LZString.compressToBase64(JSON.stringify(saves)));
formData.append('shorten', '1');
core.http(
'POST',
'/games/sync.php',
formData,
function (data) {
var response = JSON.parse(data);
if (response.code < 0) {
core.drawText(
'出错啦!\n无法同步存档到服务器。\n错误原因' +
response.msg
);
} else {
core.drawText(
(type == 'all'
? '所有存档'
: '存档' + core.saves.saveIndex) +
'同步成功!\n\n您的存档编号+密码: \r[yellow]' +
response.code +
response.msg +
'\r\n\n请牢记以上信息如截图等在从服务器\n同步存档时使用。\n\r[yellow]另外请注意,存档同步只会保存一个月的时间。\r'
);
}
},
function (e) {
core.drawText('出错啦!\n无法同步存档到服务器。\n错误原因' + e);
}
);
}; };
////// 从服务器加载存档 ////// ////// 从服务器加载存档 //////
control.prototype.syncLoad = function () { control.prototype.syncLoad = function () {
core.myprompt('请输入存档编号+密码', null, function (idpassword) { // Deprecated.
if (!idpassword) return core.ui._drawSyncSave();
if (
!/^\d{6}\w{4}$/.test(idpassword) &&
!/^\d{4}\w{3}$/.test(idpassword)
) {
core.drawText('不合法的存档编号+密码!');
return;
}
core.ui.drawWaiting('正在同步,请稍候...');
if (idpassword.length == 7) {
core.control._syncLoad_http(
idpassword.substring(0, 4),
idpassword.substring(4)
);
} else {
core.control._syncLoad_http(
idpassword.substring(0, 6),
idpassword.substring(6)
);
}
});
}; };
control.prototype._syncLoad_http = function (id, password) { control.prototype._syncLoad_http = function (id, password) {
var formData = new FormData(); // Deprecated.
formData.append('type', 'load');
formData.append('name', core.firstData.name);
formData.append('id', id);
formData.append('password', password);
core.http(
'POST',
'/games/sync.php',
formData,
function (data) {
var response = JSON.parse(data);
if (response.code == 0) {
var msg = null;
try {
msg = JSON.parse(
LZString.decompressFromBase64(response.msg)
);
} catch (e) {}
if (!msg) {
try {
msg = JSON.parse(response.msg);
} catch (e) {}
}
if (msg) {
core.control._syncLoad_write(msg);
} else {
core.drawText('出错啦!\n存档解析失败');
}
} else {
core.drawText(
'出错啦!\n无法从服务器同步存档。\n错误原因' +
response.msg
);
}
},
function (e) {
core.drawText('出错啦!\n无法从服务器同步存档。\n错误原因' + e);
}
);
}; };
control.prototype._syncLoad_write = function (data) { control.prototype._syncLoad_write = function (data) {
if (data instanceof Array) { // Deprecated.
core.status.event.selection = 1;
core.ui.drawConfirmBox(
'所有本地存档都将被覆盖,确认?',
function () {
for (var i = 1; i <= 5 * (main.savePages || 30); i++) {
if (i <= data.length)
core.setLocalForage('save' + i, data[i - 1]);
else if (core.saves.ids[i])
core.removeLocalForage('save' + i);
}
core.ui.closePanel();
core.drawText('同步成功!\n你的本地所有存档均已被覆盖。');
},
function () {
core.status.event.selection = 0;
core.ui._drawSyncSave();
}
);
} else {
// 只覆盖单存档
core.setLocalForage('save' + core.saves.saveIndex, data, function () {
core.drawText(
'同步成功!\n单存档已覆盖至存档' + core.saves.saveIndex
);
});
}
}; };
////// 存档到本地 ////// ////// 存档到本地 //////
@ -2745,9 +2628,7 @@ control.prototype.unlockControl = function () {
////// 开启debug模式 ////// ////// 开启debug模式 //////
control.prototype.debug = function () { control.prototype.debug = function () {
core.setFlag('debug', true); core.setFlag('debug', true);
core.drawText( core.drawTip('[调试模式开启]此模式下按住Ctrl键可以穿墙并忽略一切事件');
'\t[调试模式开启]此模式下按住Ctrl键或Ctrl+Shift键可以穿墙并忽略一切事件。\n此模式下将无法上传成绩。'
);
}; };
control.prototype._bindRoutePush = function () { control.prototype._bindRoutePush = function () {

View File

@ -320,6 +320,8 @@ core.prototype.initSync = function (coreData, callback) {
this._init_platform(); this._init_platform();
this._init_others(); this._init_others();
core.initStatus.maps = core.maps._initMaps();
core.loader._load(function () { core.loader._load(function () {
core._afterLoadResources(callback); core._afterLoadResources(callback);
}); });

View File

@ -43,7 +43,7 @@ events.prototype._startGame_start = function (hard, seed, route, callback) {
core.firstData.hero, core.firstData.hero,
hard, hard,
null, null,
core.cloneArray(core.initStatus.maps) core.clone(core.initStatus.maps)
); );
core.setHeroLoc('x', -1); core.setHeroLoc('x', -1);
core.setHeroLoc('y', -1); core.setHeroLoc('y', -1);
@ -121,7 +121,6 @@ events.prototype._startGame_upload = function () {
////// 游戏获胜事件 ////// ////// 游戏获胜事件 //////
events.prototype.win = function (reason, norank, noexit) { events.prototype.win = function (reason, norank, noexit) {
if (!noexit) core.status.gameOver = true;
return this.eventdata.win(reason, norank, noexit); return this.eventdata.win(reason, norank, noexit);
}; };
@ -131,7 +130,6 @@ events.prototype.lose = function (reason) {
return core.control._replay_error(reason, function () { return core.control._replay_error(reason, function () {
core.lose(reason); core.lose(reason);
}); });
core.status.gameOver = true;
return this.eventdata.lose(reason); return this.eventdata.lose(reason);
}; };
@ -188,7 +186,8 @@ events.prototype._gameOver_confirmUpload = function (ending, norank) {
if (main.isCompetition) if (main.isCompetition)
core.events._gameOver_confirmDownload(ending); core.events._gameOver_confirmDownload(ending);
else core.events._gameOver_doUpload(null, ending, norank); else core.events._gameOver_doUpload(null, ending, norank);
} },
true
); );
}; };
@ -252,7 +251,8 @@ events.prototype._gameOver_confirmDownload = function (ending) {
}, },
function () { function () {
core.events._gameOver_askRate(ending); core.events._gameOver_askRate(ending);
} },
true
); );
}; };
@ -285,7 +285,8 @@ events.prototype._gameOver_askRate = function (ending) {
function () { function () {
core.ui.closePanel(); core.ui.closePanel();
core.restart(); core.restart();
} },
true
); );
return; return;
} }
@ -302,7 +303,8 @@ events.prototype._gameOver_askRate = function (ending) {
}, },
function () { function () {
core.restart(); core.restart();
} },
true
); );
}; };
@ -328,7 +330,8 @@ events.prototype.confirmRestart = function () {
function () { function () {
core.playSound('取消'); core.playSound('取消');
core.ui.closePanel(); core.ui.closePanel();
} },
true
); );
}; };
@ -1564,6 +1567,10 @@ events.prototype.__action_doAsyncFunc = function (isAsync, func) {
}; };
events.prototype._action_text = function (data) { events.prototype._action_text = function (data) {
if (main.replayChecking) {
core.doAction();
return;
}
if (this.__action_checkReplaying()) return; if (this.__action_checkReplaying()) return;
const Store = Mota.require('@user/client-modules').TextboxStore; const Store = Mota.require('@user/client-modules').TextboxStore;
const { textbox = 'main-textbox', text, icon = 'none', title = '' } = data; const { textbox = 'main-textbox', text, icon = 'none', title = '' } = data;
@ -1593,6 +1600,10 @@ events.prototype._action_text = function (data) {
}; };
events.prototype._action_autoText = function (data) { events.prototype._action_autoText = function (data) {
if (main.replayChecking) {
core.doAction();
return;
}
if (this.__action_checkReplaying()) return; if (this.__action_checkReplaying()) return;
const Store = Mota.require('@user/client-modules').TextboxStore; const Store = Mota.require('@user/client-modules').TextboxStore;
const { textbox = 'main-textbox', text, icon = 'none', title = '' } = data; const { textbox = 'main-textbox', text, icon = 'none', title = '' } = data;
@ -1639,6 +1650,10 @@ events.prototype._action__label = function (data, x, y, prefix) {
}; };
events.prototype._action_setText = function (data) { events.prototype._action_setText = function (data) {
if (main.replayChecking) {
core.doAction();
return;
}
const isNil = value => value === null || value === void 0; const isNil = value => value === null || value === void 0;
const { textbox = 'main-textbox' } = data; const { textbox = 'main-textbox' } = data;
const Store = Mota.require('@user/client-modules').TextboxStore; const Store = Mota.require('@user/client-modules').TextboxStore;
@ -1741,7 +1756,7 @@ events.prototype._action_confirm = function (data, x, y, prefix) {
}; };
events.prototype._action_choices = function (data, x, y, prefix) { events.prototype._action_choices = function (data, x, y, prefix) {
core.ui.drawChoices( core.ui.drawChoices2(
core.replaceText(data.text, prefix), core.replaceText(data.text, prefix),
data.choices, data.choices,
data.width data.width
@ -2277,13 +2292,14 @@ events.prototype._action_unloadEquip = function (data, x, y, prefix) {
}; };
events.prototype._action_openShop = function (data, x, y, prefix) { events.prototype._action_openShop = function (data, x, y, prefix) {
Mota.require('@user/data-state').setShopVisited(data.id, true); Mota.require('@user/legacy-plugin-data').setShopVisited(data.id, true);
if (data.open) Mota.require('@user/data-state').openShop(data.id, true); if (data.open)
Mota.require('@user/legacy-plugin-data').openShop(data.id, true);
core.doAction(); core.doAction();
}; };
events.prototype._action_disableShop = function (data, x, y, prefix) { events.prototype._action_disableShop = function (data, x, y, prefix) {
Mota.require('@user/data-state').setShopVisited(data.id, false); Mota.require('@user/legacy-plugin-data').setShopVisited(data.id, false);
core.doAction(); core.doAction();
}; };

View File

@ -836,17 +836,17 @@ maps.prototype.generateMovableArray = function (floorId) {
for (var x = startX; x < endX; x++) { for (var x = startX; x < endX; x++) {
for (var y = startY; y < endY; y++) { for (var y = startY; y < endY; y++) {
array[x][y] = ['left', 'down', 'up', 'right'].filter(function ( array[x][y] = ['left', 'down', 'up', 'right'].filter(
direction function (direction) {
) { return core.maps._canMoveHero_checkPoint(
return core.maps._canMoveHero_checkPoint( x,
x, y,
y, direction,
direction, floorId,
floorId, arrays
arrays );
); }
}); );
} }
} }
return array; return array;
@ -2669,22 +2669,25 @@ maps.prototype._drawThumbnail_realDrawTempCanvas = function (
options.heroIcon = options.heroIcon =
options.heroIcon || core.status.hero.image || 'hero.png'; options.heroIcon || core.status.hero.image || 'hero.png';
options.heroIcon = core.getMappedName(options.heroIcon); options.heroIcon = core.getMappedName(options.heroIcon);
var icon = core.material.icons.hero[options.heroLoc.direction]; const image = core.material.images.images[options.heroIcon];
var height = core.material.images.images[options.heroIcon].height / 4; if (image) {
var width = var icon = core.material.icons.hero[options.heroLoc.direction];
(core.material.images.images[options.heroIcon].width || 128) / 4; var height =
core.drawImage( core.material.images.images[options.heroIcon].height / 4;
options.ctx, var width = (image.width || 128) / 4;
core.material.images.images[options.heroIcon], core.drawImage(
icon.stop * width, options.ctx,
icon.loc * height, core.material.images.images[options.heroIcon],
width, icon.stop * width,
height, icon.loc * height,
32 * options.heroLoc.x + 32 - width, width,
32 * options.heroLoc.y + 32 - height, height,
width, 32 * options.heroLoc.x + 32 - width,
height 32 * options.heroLoc.y + 32 - height,
); width,
height
);
}
} }
// 缩略图:前景 // 缩略图:前景
this.drawFg(floorId, options); this.drawFg(floorId, options);
@ -3127,6 +3130,14 @@ maps.prototype.showBlock = function (x, y, floorId) {
block.disable = false; block.disable = false;
core.setMapBlockDisabled(floorId, x, y, false); core.setMapBlockDisabled(floorId, x, y, false);
this._updateMapArray(floorId, block.x, block.y); this._updateMapArray(floorId, block.x, block.y);
Mota.require('@user/data-base').hook.emit(
'setBlock',
x,
y,
floorId,
block?.id ?? 0,
0
);
// 在本层,添加动画 // 在本层,添加动画
if (floorId == core.status.floorId) { if (floorId == core.status.floorId) {
if (block.event.cls == 'autotile') { if (block.event.cls == 'autotile') {
@ -3151,6 +3162,14 @@ maps.prototype.hideBlock = function (x, y, floorId) {
block.disable = true; block.disable = true;
core.setMapBlockDisabled(floorId, block.x, block.y, true); core.setMapBlockDisabled(floorId, block.x, block.y, true);
this._updateMapArray(floorId, block.x, block.y); this._updateMapArray(floorId, block.x, block.y);
Mota.require('@user/data-base').hook.emit(
'setBlock',
x,
y,
floorId,
0,
block?.id ?? 0
);
// 删除动画,清除地图 // 删除动画,清除地图
this._removeBlockFromMap(floorId, block); this._removeBlockFromMap(floorId, block);
@ -3166,6 +3185,14 @@ maps.prototype.hideBlockByIndex = function (index, floorId) {
block.disable = true; block.disable = true;
core.setMapBlockDisabled(floorId, block.x, block.y, true); core.setMapBlockDisabled(floorId, block.x, block.y, true);
this._updateMapArray(floorId, block.x, block.y); this._updateMapArray(floorId, block.x, block.y);
Mota.require('@user/data-base').hook.emit(
'setBlock',
x,
y,
floorId,
0,
block?.id ?? 0
);
}; };
////// 一次性隐藏多个block ////// ////// 一次性隐藏多个block //////
@ -3585,6 +3612,14 @@ maps.prototype.replaceBlock = function (fromNumber, toNumber, floorId) {
block.event[one] = core.clone(toBlock.event[one]); block.event[one] = core.clone(toBlock.event[one]);
} }
this._updateMapArray(floorId, block.x, block.y); this._updateMapArray(floorId, block.x, block.y);
Mota.require('@user/data-base').hook.emit(
'setBlock',
x,
y,
floorId,
fromNumber,
toNumber
);
} }
}, this); }, this);
if (floorId == core.status.floorId) core.redrawMap(); if (floorId == core.status.floorId) core.redrawMap();
@ -3673,112 +3708,12 @@ maps.prototype._moveDetachedBlock = function (
opacity, opacity,
canvases canvases
) { ) {
var height = blockInfo.height, // Deprecated.
posX = blockInfo.posX,
posY = blockInfo.posY,
image = blockInfo.image;
var headCanvas = canvases.headCanvas,
bodyCanvas = canvases.bodyCanvas,
damageCanvas = canvases.damageCanvas;
if (headCanvas) {
core.dymCanvas[headCanvas].clearRect(0, 0, 32, height);
core.dymCanvas[headCanvas].drawImage(
image,
posX * 32,
posY * height,
32,
height - 32,
0,
0,
32,
height - 32
);
core.relocateCanvas(
headCanvas,
nowX - core.bigmap.offsetX,
nowY + 32 - height - core.bigmap.offsetY
);
core.setOpacity(headCanvas, opacity);
}
if (bodyCanvas) {
if (blockInfo.bigImage) {
var face = blockInfo.face;
if (!blockInfo.faceIds) face = 'down';
else if (!blockInfo.faceIds[face]) {
// 维持此时朝向
face = 'down';
for (var f in blockInfo.faceIds) {
if (blockInfo.faceIds[f] == blockInfo.id) {
face = f;
}
}
}
var bigImageInfo = this._getBigImageInfo(
blockInfo.bigImage,
face,
blockInfo.posX
);
var per_width = bigImageInfo.per_width,
per_height = bigImageInfo.per_height;
core.dymCanvas[bodyCanvas].clearRect(
0,
0,
bigImageInfo.per_width,
bigImageInfo.per_height
);
core.dymCanvas[bodyCanvas].drawImage(
blockInfo.bigImage,
bigImageInfo.sx,
bigImageInfo.sy,
per_width,
per_height,
0,
0,
per_width,
per_height
);
core.relocateCanvas(
bodyCanvas,
nowX - core.bigmap.offsetX + bigImageInfo.dx,
nowY - core.bigmap.offsetY + bigImageInfo.dy
);
core.setOpacity(bodyCanvas, opacity);
} else {
core.dymCanvas[bodyCanvas].clearRect(0, 0, 32, 32);
core.dymCanvas[bodyCanvas].drawImage(
image,
posX * 32,
posY * height + height - 32,
32,
32,
0,
0,
32,
32
);
core.relocateCanvas(
bodyCanvas,
nowX - core.bigmap.offsetX,
nowY - core.bigmap.offsetY
);
core.setOpacity(bodyCanvas, opacity);
}
}
if (damageCanvas) {
core.relocateCanvas(
damageCanvas,
nowX - core.bigmap.offsetX,
nowY - core.bigmap.offsetY
);
core.setOpacity(damageCanvas, opacity);
}
}; };
////// 删除独立的block canvas ////// ////// 删除独立的block canvas //////
maps.prototype._deleteDetachedBlock = function (canvases) { maps.prototype._deleteDetachedBlock = function (canvases) {
core.deleteCanvas(canvases.headCanvas); // Deprecated.
core.deleteCanvas(canvases.bodyCanvas);
core.deleteCanvas(canvases.damageCanvas);
}; };
maps.prototype._getAndRemoveBlock = function (x, y) { maps.prototype._getAndRemoveBlock = function (x, y) {
@ -3891,7 +3826,14 @@ maps.prototype._moveBlock_doMove = function (
_run(); _run();
} else } else
core.maps._moveBlock_moving(blockInfo, canvases, moveInfo); core.maps._moveBlock_moving(blockInfo, canvases, moveInfo);
} else core.maps._moveJumpBlock_finished(blockInfo, canvases, moveInfo, animate, cb); } else
core.maps._moveJumpBlock_finished(
blockInfo,
canvases,
moveInfo,
animate,
cb
);
}, moveInfo.per_time); }, moveInfo.per_time);
core.animateFrame.lastAsyncId = animate; core.animateFrame.lastAsyncId = animate;

View File

@ -2228,7 +2228,7 @@ ui.prototype.textImage = function (content, lineHeight) {
}; };
////// 绘制一个选项界面 ////// ////// 绘制一个选项界面 //////
ui.prototype.drawChoices = async function (content, choices, width) { ui.prototype.drawChoices2 = async function (content, choices, width, noRoute) {
if (main.replayChecking) { if (main.replayChecking) {
const selected = (() => { const selected = (() => {
const route = core.status.replay.toReplay[0]; const route = core.status.replay.toReplay[0];
@ -2238,19 +2238,26 @@ ui.prototype.drawChoices = async function (content, choices, width) {
return Number(route.slice(8)); return Number(route.slice(8));
} }
})(); })();
core.status.replay.toReplay.shift();
core.insertAction(choices[selected].action); core.insertAction(choices[selected].action);
core.doAction(); core.doAction();
} else { } else {
const { routedChoices, mainUIController } = Mota.require( const {
'@user/client-modules' routedChoices,
); getChoices,
mainUIController,
HALF_WIDTH,
HALF_HEIGHT,
POP_BOX_WIDTH
} = Mota.require('@user/client-modules');
const choice = choices.map((v, i) => [i, v.text]); const choice = choices.map((v, i) => [i, v.text]);
const selected = await routedChoices( const fn = noRoute ? getChoices : routedChoices;
const selected = await fn(
mainUIController, mainUIController,
choice, choice,
[420, 240, void 0, void 0, 0.5, 0.5], [HALF_WIDTH, HALF_HEIGHT, void 0, void 0, 0.5, 0.5],
width, width ?? POP_BOX_WIDTH,
{ title: content ?? '' } { text: content ?? '' }
); );
core.insertAction(choices[selected].action); core.insertAction(choices[selected].action);
core.doAction(); core.doAction();
@ -2278,7 +2285,7 @@ ui.prototype.drawConfirmBox = async function (
text, text,
yesCallback, yesCallback,
noCallback, noCallback,
ctx noRoute
) { ) {
if (main.replayChecking) { if (main.replayChecking) {
const confirm = (() => { const confirm = (() => {
@ -2289,20 +2296,27 @@ ui.prototype.drawConfirmBox = async function (
return Number(route.slice(8)) === 1; return Number(route.slice(8)) === 1;
} }
})(); })();
core.status.replay.toReplay.shift();
if (confirm) { if (confirm) {
yesCallback?.(); yesCallback?.();
} else { } else {
noCallback?.(); noCallback?.();
} }
} else { } else {
const { routedConfirm, mainUIController } = Mota.require( const {
'@user/client-modules' routedConfirm,
); getConfirm,
const confirm = await routedConfirm( mainUIController,
HALF_WIDTH,
HALF_HEIGHT,
POP_BOX_WIDTH
} = Mota.require('@user/client-modules');
const fn = noRoute ? getConfirm : routedConfirm;
const confirm = await fn(
mainUIController, mainUIController,
text, text,
[420, 240, void 0, void 0, 0.5, 0.5], [HALF_WIDTH, HALF_HEIGHT, void 0, void 0, 0.5, 0.5],
240 POP_BOX_WIDTH
); );
if (confirm) { if (confirm) {
yesCallback?.(); yesCallback?.();
@ -2361,7 +2375,7 @@ ui.prototype._drawQuickShop = function () {
}; };
}); });
choices.push('返回游戏'); choices.push('返回游戏');
this.drawChoices(null, choices); this.drawChoices(null, choices, void 0, true);
}; };
ui.prototype._drawSyncSave = function () { ui.prototype._drawSyncSave = function () {

View File

@ -109,7 +109,7 @@ function main() {
this.canvas = {}; this.canvas = {};
this.__VERSION__ = '2.10.0'; this.__VERSION__ = '2.10.0';
this.__VERSION_CODE__ = 510; this.__VERSION_CODE__ = 610;
} }
// >>>> body end // >>>> body end
@ -183,15 +183,12 @@ main.prototype.loadSync = function (mode, callback) {
coreData[t] = main[t]; coreData[t] = main[t];
}); });
core.initSync(coreData, callback); core.initSync(coreData, () => {});
main.loading.emit('coreInit'); main.loading.emit('coreInit');
core.initStatus.maps = core.maps._initMaps();
core.resize(); core.resize();
main.core = core; main.core = core;
core.completeAchievement = () => 0; callback?.();
core.plugin = { drawLight: 0 };
}; };
main.prototype.loadAsync = async function (mode, callback) { main.prototype.loadAsync = async function (mode, callback) {