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.ui.closePanel();
core.pauseReplay();
}
},
true
);
};
@ -1639,7 +1640,8 @@ control.prototype._replay_error = function (action, callback) {
core.ui.closePanel();
core.stopReplay(true);
if (callback) callback();
}
},
true
);
};
@ -2216,139 +2218,20 @@ control.prototype.syncSave = function (type) {
};
control.prototype._syncSave_http = function (type, saves) {
if (!saves) return core.drawText('没有要同步的存档');
var formData = new FormData();
formData.append('type', 'save');
formData.append('name', core.firstData.name);
formData.append('data', LZString.compressToBase64(JSON.stringify(saves)));
formData.append('shorten', '1');
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);
}
);
// Deprecated.
};
////// 从服务器加载存档 //////
control.prototype.syncLoad = function () {
core.myprompt('请输入存档编号+密码', null, function (idpassword) {
if (!idpassword) return core.ui._drawSyncSave();
if (
!/^\d{6}\w{4}$/.test(idpassword) &&
!/^\d{4}\w{3}$/.test(idpassword)
) {
core.drawText('不合法的存档编号+密码!');
return;
}
core.ui.drawWaiting('正在同步,请稍候...');
if (idpassword.length == 7) {
core.control._syncLoad_http(
idpassword.substring(0, 4),
idpassword.substring(4)
);
} else {
core.control._syncLoad_http(
idpassword.substring(0, 6),
idpassword.substring(6)
);
}
});
// Deprecated.
};
control.prototype._syncLoad_http = function (id, password) {
var formData = new FormData();
formData.append('type', 'load');
formData.append('name', core.firstData.name);
formData.append('id', id);
formData.append('password', password);
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);
}
);
// Deprecated.
};
control.prototype._syncLoad_write = function (data) {
if (data instanceof Array) {
core.status.event.selection = 1;
core.ui.drawConfirmBox(
'所有本地存档都将被覆盖,确认?',
function () {
for (var i = 1; i <= 5 * (main.savePages || 30); i++) {
if (i <= data.length)
core.setLocalForage('save' + i, data[i - 1]);
else if (core.saves.ids[i])
core.removeLocalForage('save' + i);
}
core.ui.closePanel();
core.drawText('同步成功!\n你的本地所有存档均已被覆盖。');
},
function () {
core.status.event.selection = 0;
core.ui._drawSyncSave();
}
);
} else {
// 只覆盖单存档
core.setLocalForage('save' + core.saves.saveIndex, data, function () {
core.drawText(
'同步成功!\n单存档已覆盖至存档' + core.saves.saveIndex
);
});
}
// Deprecated.
};
////// 存档到本地 //////
@ -2745,9 +2628,7 @@ control.prototype.unlockControl = function () {
////// 开启debug模式 //////
control.prototype.debug = function () {
core.setFlag('debug', true);
core.drawText(
'\t[调试模式开启]此模式下按住Ctrl键或Ctrl+Shift键可以穿墙并忽略一切事件。\n此模式下将无法上传成绩。'
);
core.drawTip('[调试模式开启]此模式下按住Ctrl键可以穿墙并忽略一切事件');
};
control.prototype._bindRoutePush = function () {

View File

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

View File

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

View File

@ -836,17 +836,17 @@ maps.prototype.generateMovableArray = function (floorId) {
for (var x = startX; x < endX; x++) {
for (var y = startY; y < endY; y++) {
array[x][y] = ['left', 'down', 'up', 'right'].filter(function (
direction
) {
return core.maps._canMoveHero_checkPoint(
x,
y,
direction,
floorId,
arrays
);
});
array[x][y] = ['left', 'down', 'up', 'right'].filter(
function (direction) {
return core.maps._canMoveHero_checkPoint(
x,
y,
direction,
floorId,
arrays
);
}
);
}
}
return array;
@ -2669,22 +2669,25 @@ maps.prototype._drawThumbnail_realDrawTempCanvas = function (
options.heroIcon =
options.heroIcon || core.status.hero.image || 'hero.png';
options.heroIcon = core.getMappedName(options.heroIcon);
var icon = core.material.icons.hero[options.heroLoc.direction];
var height = core.material.images.images[options.heroIcon].height / 4;
var width =
(core.material.images.images[options.heroIcon].width || 128) / 4;
core.drawImage(
options.ctx,
core.material.images.images[options.heroIcon],
icon.stop * width,
icon.loc * height,
width,
height,
32 * options.heroLoc.x + 32 - width,
32 * options.heroLoc.y + 32 - height,
width,
height
);
const image = core.material.images.images[options.heroIcon];
if (image) {
var icon = core.material.icons.hero[options.heroLoc.direction];
var height =
core.material.images.images[options.heroIcon].height / 4;
var width = (image.width || 128) / 4;
core.drawImage(
options.ctx,
core.material.images.images[options.heroIcon],
icon.stop * width,
icon.loc * height,
width,
height,
32 * options.heroLoc.x + 32 - width,
32 * options.heroLoc.y + 32 - height,
width,
height
);
}
}
// 缩略图:前景
this.drawFg(floorId, options);
@ -3127,6 +3130,14 @@ maps.prototype.showBlock = function (x, y, floorId) {
block.disable = false;
core.setMapBlockDisabled(floorId, x, y, false);
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 (block.event.cls == 'autotile') {
@ -3151,6 +3162,14 @@ maps.prototype.hideBlock = function (x, y, floorId) {
block.disable = true;
core.setMapBlockDisabled(floorId, block.x, block.y, true);
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);
@ -3166,6 +3185,14 @@ maps.prototype.hideBlockByIndex = function (index, floorId) {
block.disable = true;
core.setMapBlockDisabled(floorId, block.x, block.y, true);
this._updateMapArray(floorId, block.x, block.y);
Mota.require('@user/data-base').hook.emit(
'setBlock',
x,
y,
floorId,
0,
block?.id ?? 0
);
};
////// 一次性隐藏多个block //////
@ -3585,6 +3612,14 @@ maps.prototype.replaceBlock = function (fromNumber, toNumber, floorId) {
block.event[one] = core.clone(toBlock.event[one]);
}
this._updateMapArray(floorId, block.x, block.y);
Mota.require('@user/data-base').hook.emit(
'setBlock',
x,
y,
floorId,
fromNumber,
toNumber
);
}
}, this);
if (floorId == core.status.floorId) core.redrawMap();
@ -3673,112 +3708,12 @@ maps.prototype._moveDetachedBlock = function (
opacity,
canvases
) {
var height = blockInfo.height,
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);
}
// Deprecated.
};
////// 删除独立的block canvas //////
maps.prototype._deleteDetachedBlock = function (canvases) {
core.deleteCanvas(canvases.headCanvas);
core.deleteCanvas(canvases.bodyCanvas);
core.deleteCanvas(canvases.damageCanvas);
// Deprecated.
};
maps.prototype._getAndRemoveBlock = function (x, y) {
@ -3891,7 +3826,14 @@ maps.prototype._moveBlock_doMove = function (
_run();
} else
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);
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) {
const selected = (() => {
const route = core.status.replay.toReplay[0];
@ -2238,19 +2238,26 @@ ui.prototype.drawChoices = async function (content, choices, width) {
return Number(route.slice(8));
}
})();
core.status.replay.toReplay.shift();
core.insertAction(choices[selected].action);
core.doAction();
} else {
const { routedChoices, mainUIController } = Mota.require(
'@user/client-modules'
);
const {
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 selected = await routedChoices(
const fn = noRoute ? getChoices : routedChoices;
const selected = await fn(
mainUIController,
choice,
[420, 240, void 0, void 0, 0.5, 0.5],
width,
{ title: content ?? '' }
[HALF_WIDTH, HALF_HEIGHT, void 0, void 0, 0.5, 0.5],
width ?? POP_BOX_WIDTH,
{ text: content ?? '' }
);
core.insertAction(choices[selected].action);
core.doAction();
@ -2278,7 +2285,7 @@ ui.prototype.drawConfirmBox = async function (
text,
yesCallback,
noCallback,
ctx
noRoute
) {
if (main.replayChecking) {
const confirm = (() => {
@ -2289,20 +2296,27 @@ ui.prototype.drawConfirmBox = async function (
return Number(route.slice(8)) === 1;
}
})();
core.status.replay.toReplay.shift();
if (confirm) {
yesCallback?.();
} else {
noCallback?.();
}
} else {
const { routedConfirm, mainUIController } = Mota.require(
'@user/client-modules'
);
const confirm = await routedConfirm(
const {
routedConfirm,
getConfirm,
mainUIController,
HALF_WIDTH,
HALF_HEIGHT,
POP_BOX_WIDTH
} = Mota.require('@user/client-modules');
const fn = noRoute ? getConfirm : routedConfirm;
const confirm = await fn(
mainUIController,
text,
[420, 240, void 0, void 0, 0.5, 0.5],
240
[HALF_WIDTH, HALF_HEIGHT, void 0, void 0, 0.5, 0.5],
POP_BOX_WIDTH
);
if (confirm) {
yesCallback?.();
@ -2361,7 +2375,7 @@ ui.prototype._drawQuickShop = function () {
};
});
choices.push('返回游戏');
this.drawChoices(null, choices);
this.drawChoices(null, choices, void 0, true);
};
ui.prototype._drawSyncSave = function () {

View File

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