fixed # 更新文档内容

This commit is contained in:
2026-11-24 00:47:30 +08:00
parent 676977c12a
commit 884d694d22
18 changed files with 161 additions and 60 deletions
+5 -1
View File
@@ -1,5 +1,5 @@
import { openCardLibrary } from "../card-library.js";
import { askMenu, openModeSelection, openNonameMenu } from "../navigation.js";
import { askMenu, confirmRestartJourney, openModeSelection, openNonameMenu } from "../navigation.js";
import { ui, get } from "../../../../../noname.js";
import config from "../../config.js";
import { getRelic } from "../../relics/definitions.js";
@@ -28,6 +28,7 @@ const controlIconPaths = {
book: "M5 5h9a5 5 0 015 5v17a5 5 0 00-5-5H5zM27 5h-9a5 5 0 00-5 5v17a5 5 0 015-5h9z",
record: "M8 4h16v24H8zM12 10h8M12 16h8M12 22h5",
settings: "M16 11a5 5 0 100 10 5 5 0 000-10zM16 3v4M16 25v4M3 16h4M25 16h4M7 7l3 3M22 22l3 3M25 7l-3 3M10 22l-3 3",
restart: "M5 15a11 11 0 111 7M5 6v9h9",
exit: "M13 5H6v22h7M20 10l6 6-6 6M26 16H11",
back: "M20 7l-9 9 9 9M11 16h16",
close: "M8 8l16 16M24 8L8 24",
@@ -343,6 +344,9 @@ export const showMap = (run, { saveRun } = {}) => new Promise(resolve => {
}
},
}).setAttribute("aria-haspopup", "dialog");
createMenuAction({ icon: "restart", name: "重新开始", description: "结束本次征程,返回角色选择",
danger: true, onClick: confirmRestartJourney,
}).setAttribute("aria-haspopup", "dialog");
}
function handleEscape(event) {
+64 -2
View File
@@ -1,9 +1,21 @@
import { lib, game, ui, _status } from "../../../../noname.js";
import { save } from "../../../../noname/util/config.js";
import { getDiagnostics } from "../../diagnostics/index.js";
import config from "../config.js";
let selectingMode = false;
let nonameMenuTask = null;
let restartingJourney = false;
const journeyRestartKey = () => `${lib.configprefix}${config.modeId}:restart`;
const canRestartJourney = () => lib.storage?.[config.saveKey]?.status === "running";
export const consumeJourneyRestart = () => {
const key = journeyRestartKey();
if (sessionStorage.getItem(key) !== "true") return false;
sessionStorage.removeItem(key);
return true;
};
// Open the engine's real settings menu without ending the current expedition flow.
export const openNonameMenu = async () => {
@@ -138,6 +150,53 @@ export const askMenu = (title, description, choices) => new Promise(resolve => {
dialog.querySelector("button")?.focus();
});
export const confirmRestartJourney = async () => {
if (restartingJourney || !canRestartJourney()) return;
restartingJourney = true;
let cleared = false;
try {
const confirmed = await askMenu("重新开始?", "当前征程的存档将被清除。确认后返回角色选择。", [
{ id: "cancel", name: "取消" },
{ id: "confirm", name: "确认重新开始", danger: true },
]);
if (confirmed !== "confirm") return;
const restartKey = journeyRestartKey();
const directStartKey = `${lib.configprefix}directstart`;
const previousDirectStart = localStorage.getItem(directStartKey);
const previousInert = ui.window.inert;
const wasPaused = _status.paused2;
ui.window.inert = true;
game.pause2();
try {
sessionStorage.setItem(restartKey, "true");
localStorage.setItem(directStartKey, "true");
await game.mengsanClearRun_shuying();
} catch (error) {
ui.window.inert = previousInert;
if (!wasPaused) game.resume2();
sessionStorage.removeItem(restartKey);
if (previousDirectStart === null) localStorage.removeItem(directStartKey);
else localStorage.setItem(directStartKey, previousDirectStart);
throw error;
}
cleared = true;
// Reload through the engine so the old flow stops and pending DB writes can finish.
game.reload();
await new Promise(() => {});
} catch (error) {
console.error("梦三重新开始失败:", error);
getDiagnostics().scope("mengsan.navigation").error("restart.failed", error);
const message = cleared ? "本局存档已清除,请重新进入梦三选择角色。" : "请关闭提示后重试。";
await askMenu("暂时无法重新开始", message, [
{ id: "close", name: "关闭提示" },
]);
} finally {
restartingJourney = false;
}
};
export const mountMenu = (overlay, options = {}) => {
const button = document.createElement("button");
button.type = "button";
@@ -160,12 +219,15 @@ export const mountMenu = (overlay, options = {}) => {
options.onOpen?.();
let action = null;
try {
action = await askMenu("征程菜单", "退出不删除存档。未完成的节点与对话将在下次进入时重新开始。", [
const choices = [
{ id: "resume", name: "继续当前界面" },
{ id: "noname", name: "显示 Noname 菜单" },
{ id: "exit", name: "返回模式选择" },
]);
];
if (canRestartJourney()) choices.push({ id: "restart", name: "重新开始", danger: true });
action = await askMenu("征程菜单", "返回模式选择会保留存档。未完成的节点与对话将在下次进入时重新开始。", choices);
if (action === "noname") { await openNonameMenu(); return; }
if (action === "restart") { await confirmRestartJourney(); return; }
if (action !== "exit") return;
const confirmed = await askMenu("返回模式选择?", "保留上次已完成节点的存档。本次尚未完成的内容不会提交。", [
{ id: "cancel", name: "留在梦三" },