dsh-novel-game 0.3.1 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +23 -0
- package/README.md +3 -1
- package/client.js +410 -225
- package/index.js +0 -2
- package/lib/picker.mjs +71 -0
- package/lib/remote-contract.js +2 -0
- package/lib/remote.js +9 -0
- package/lib/store.mjs +9 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,28 @@
|
|
|
1
1
|
# CHANGELOG
|
|
2
2
|
|
|
3
|
+
## 0.4.0 — 2026-11-30
|
|
4
|
+
|
|
5
|
+
侧栏面板交互与视觉重做,新增原生选择器与底色主题。
|
|
6
|
+
|
|
7
|
+
### 新增
|
|
8
|
+
|
|
9
|
+
- **原生选择器**:面板「选择文件夹 / 选择文件」调用系统对话框(Windows PowerShell + WinForms,STA);选文件自动取其所在目录并触发探测;取消/超时不报错。
|
|
10
|
+
- **6 套底色**:纸白、夜行、苔原、雾港、晚樱、墨金;选择写入 `localStorage`,重开面板保留。
|
|
11
|
+
- **面板重做**:卡片化布局、粘性页签、进度条、状态胶囊、统计格、空态、Toast、引用块、头像圆点;场景筛选、剧透「设到这一幕」、摘录失效「改绑」、搜索结果高亮。
|
|
12
|
+
|
|
13
|
+
### 测试
|
|
14
|
+
|
|
15
|
+
- 34 项全过(新增 4 项选择器单测 + 2 项面板模拟:选目录→探测→导入→浏览→摘录→导出、remote 契约与 client 主题一致性)。
|
|
16
|
+
|
|
17
|
+
### 已知限制
|
|
18
|
+
|
|
19
|
+
- 原生选择器仅 Windows;其它平台提示手动粘贴路径。
|
|
20
|
+
- 效果图为静态稿(`docs/assets/game-panel-mock.html`),实际面板随 DSH 主题与侧栏宽度自适应。
|
|
21
|
+
|
|
22
|
+
## 0.3.2 — 2026-11-30
|
|
23
|
+
|
|
24
|
+
修复:`game_status` / `manifest` 里的 `toolVersion` 之前写死 `0.1.0`,现在从 `package.json` 读取,与发布版本一致。
|
|
25
|
+
|
|
3
26
|
## 0.3.1 — 2026-11-30
|
|
4
27
|
|
|
5
28
|
文档补丁:README 的「共同作者 / 喜欢它?/ 许可证」按插件市场统一格式重写(版本前缀、角色说明、GitHub ⭐/Issue/PR 入口、MIT License 链接)。无代码变更,测试仍 28/28。
|
package/README.md
CHANGED
|
@@ -10,6 +10,8 @@ DSH 插件:Host 工具 + 右侧栏六页面板。只处理你自己合法持
|
|
|
10
10
|
|
|
11
11
|
## 它能做什么
|
|
12
12
|
|
|
13
|
+
- **选目录**:原生「选择文件夹 / 选择文件」按钮,选完自动探测;也可以直接粘贴路径。
|
|
14
|
+
- **6 套底色**:纸白 / 夜行 / 苔原 / 雾港 / 晚樱 / 墨金,选择保存在本地,重开面板仍保留。
|
|
13
15
|
- **认引擎**:RPG Maker MV/MZ、Ren'Py(含 `.rpa` 归档)、以及任意目录的通用文本嗅探(JSON/CSV/PO/Yarn/Ink/TXT)。
|
|
14
16
|
- **读剧情**:按场景读对话、旁白、选项与跳转;每条文本带来源指针(文件 + 结构地址),能回查。
|
|
15
17
|
- **查设定**:人物卡草稿(出场、首现、代表台词)、物品/技能/敌人/UI 词条。
|
|
@@ -111,7 +113,7 @@ npm run check
|
|
|
111
113
|
|
|
112
114
|
## 共同作者
|
|
113
115
|
|
|
114
|
-
0.
|
|
116
|
+
0.4.0 共同作者:[MiyueWinter](https://github.com/MiyueWinter) —— 文案、测试、设计与开发。
|
|
115
117
|
|
|
116
118
|
## 喜欢它?
|
|
117
119
|
|
package/client.js
CHANGED
|
@@ -3,6 +3,7 @@ window.__ModuleLoader__.load({
|
|
|
3
3
|
factory(require) {
|
|
4
4
|
const React = require("react");
|
|
5
5
|
const h = React.createElement;
|
|
6
|
+
const { useState, useEffect, useRef } = React;
|
|
6
7
|
|
|
7
8
|
/* remote contract mirrors lib/remote-contract.js */
|
|
8
9
|
const scalar = (v) => ({
|
|
@@ -16,9 +17,7 @@ window.__ModuleLoader__.load({
|
|
|
16
17
|
const param = (n, s) => ({ name: n, wire: n, source: "json", codec: codec(n, s) });
|
|
17
18
|
const invoke = (m, ps) => ({
|
|
18
19
|
id: `dsh-novel-game#gamePanel/${m}`,
|
|
19
|
-
namespace: "gamePanel",
|
|
20
|
-
service: "gamePanel",
|
|
21
|
-
method: m,
|
|
20
|
+
namespace: "gamePanel", service: "gamePanel", method: m,
|
|
22
21
|
invocation: { kind: "direct" },
|
|
23
22
|
parameters: [param("sessionId", sid), ...ps],
|
|
24
23
|
result: codec("GameResult", res),
|
|
@@ -26,22 +25,15 @@ window.__ModuleLoader__.load({
|
|
|
26
25
|
const REMOTE = {
|
|
27
26
|
package: "dsh-novel-game",
|
|
28
27
|
descriptors: [
|
|
29
|
-
invoke("status", []),
|
|
30
|
-
invoke("
|
|
31
|
-
invoke("
|
|
32
|
-
invoke("
|
|
33
|
-
invoke("
|
|
34
|
-
invoke("
|
|
35
|
-
invoke("
|
|
36
|
-
invoke("
|
|
37
|
-
invoke("
|
|
38
|
-
invoke("routes", [param("options", obj)]),
|
|
39
|
-
invoke("characters", [param("options", obj)]),
|
|
40
|
-
invoke("glossary", [param("options", obj)]),
|
|
41
|
-
invoke("picks", [param("options", obj)]),
|
|
42
|
-
invoke("addPick", [param("options", obj)]),
|
|
43
|
-
invoke("export", [param("options", obj)]),
|
|
44
|
-
invoke("getSettings", []),
|
|
28
|
+
invoke("status", []), invoke("listGames", []),
|
|
29
|
+
invoke("detect", [param("options", obj)]), invoke("import", [param("options", obj)]),
|
|
30
|
+
invoke("jobStatus", [param("options", obj)]), invoke("cancelJob", [param("options", obj)]),
|
|
31
|
+
invoke("scenes", [param("options", obj)]), invoke("scene", [param("options", obj)]),
|
|
32
|
+
invoke("search", [param("options", obj)]), invoke("routes", [param("options", obj)]),
|
|
33
|
+
invoke("characters", [param("options", obj)]), invoke("glossary", [param("options", obj)]),
|
|
34
|
+
invoke("picks", [param("options", obj)]), invoke("addPick", [param("options", obj)]),
|
|
35
|
+
invoke("remapPick", [param("options", obj)]), invoke("pickPath", [param("options", obj)]),
|
|
36
|
+
invoke("export", [param("options", obj)]), invoke("getSettings", []),
|
|
45
37
|
invoke("saveSettings", [param("options", obj)]),
|
|
46
38
|
],
|
|
47
39
|
};
|
|
@@ -51,74 +43,173 @@ window.__ModuleLoader__.load({
|
|
|
51
43
|
return value;
|
|
52
44
|
};
|
|
53
45
|
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
accent: "
|
|
61
|
-
|
|
46
|
+
/* ---------- themes ---------- */
|
|
47
|
+
const THEMES = [
|
|
48
|
+
{ id: "paper", label: "纸白", bg: "#f4f1e9", panel: "#fffdf8", card: "#ffffff", border: "#e4ddcf", ink: "#2b2a26", sub: "#8a857a", accent: "#3f7a5a", soft: "#eef3ec" },
|
|
49
|
+
{ id: "night", label: "夜行", bg: "#13171c", panel: "#1b222a", card: "#232c36", border: "#33404d", ink: "#e9eff5", sub: "#93a2b1", accent: "#6fb1ff", soft: "#233140" },
|
|
50
|
+
{ id: "forest", label: "苔原", bg: "#eaeedd", panel: "#f8faf2", card: "#ffffff", border: "#d8e0ce", ink: "#26301f", sub: "#6f7d66", accent: "#4f7a3a", soft: "#e7efdc" },
|
|
51
|
+
{ id: "ocean", label: "雾港", bg: "#e6eff3", panel: "#f7fbfc", card: "#ffffff", border: "#d0dfe6", ink: "#1e2b31", sub: "#627780", accent: "#2f6f8f", soft: "#e3eef3" },
|
|
52
|
+
{ id: "rose", label: "晚樱", bg: "#f5eaee", panel: "#fff8fa", card: "#ffffff", border: "#ead2d9", ink: "#33242a", sub: "#8b6b75", accent: "#a8516d", soft: "#f6e4ea" },
|
|
53
|
+
{ id: "ink", label: "墨金", bg: "#191714", panel: "#23201b", card: "#2b2721", border: "#3d372f", ink: "#f0e9dc", sub: "#a79b87", accent: "#c9a35c", soft: "#312b23" },
|
|
54
|
+
];
|
|
55
|
+
const THEME_KEY = "dsh-novel-game-theme";
|
|
56
|
+
|
|
57
|
+
const CSS = `
|
|
58
|
+
[data-gpanel], [data-gpanel] * { box-sizing: border-box; }
|
|
59
|
+
[data-gpanel] {
|
|
60
|
+
display: flex; flex-direction: column; gap: 10px; padding: 10px 11px 12px;
|
|
61
|
+
border-radius: 14px; font-size: 12px; color: var(--g-ink);
|
|
62
|
+
background: linear-gradient(168deg, var(--g-bg), var(--g-panel) 55%);
|
|
63
|
+
min-height: 100%;
|
|
64
|
+
}
|
|
65
|
+
.g-head { display: flex; align-items: center; gap: 8px; }
|
|
66
|
+
.g-mark { width: 27px; height: 27px; border-radius: 9px; background: var(--g-accent); color: #fff;
|
|
67
|
+
display: flex; align-items: center; justify-content: center; font-weight: 700; font-size: 12px;
|
|
68
|
+
box-shadow: 0 4px 10px color-mix(in srgb, var(--g-accent) 30%, transparent); }
|
|
69
|
+
.g-title { font-size: 13px; font-weight: 700; letter-spacing: .4px; }
|
|
70
|
+
.g-sub { font-size: 10.5px; color: var(--g-sub); }
|
|
71
|
+
.g-row { display: flex; gap: 6px; align-items: center; flex-wrap: wrap; }
|
|
72
|
+
.g-grow { flex: 1; }
|
|
73
|
+
.g-iconbtn { border: 1px solid var(--g-border); background: var(--g-card); color: var(--g-ink);
|
|
74
|
+
border-radius: 8px; padding: 3px 8px; font-size: 11px; cursor: pointer; transition: .15s; }
|
|
75
|
+
.g-iconbtn:hover { border-color: var(--g-accent); color: var(--g-accent); }
|
|
76
|
+
.g-iconbtn:disabled { opacity: .45; cursor: default; }
|
|
77
|
+
.g-swatches { display: flex; gap: 7px; flex-wrap: wrap; padding: 7px 8px;
|
|
78
|
+
border: 1px dashed var(--g-border); border-radius: 10px; background: var(--g-card); }
|
|
79
|
+
.g-swatch { width: 22px; height: 22px; border-radius: 50%; border: 2px solid transparent; cursor: pointer;
|
|
80
|
+
transition: .15s; }
|
|
81
|
+
.g-swatch:hover { transform: scale(1.12); }
|
|
82
|
+
.g-swatch.on { border-color: var(--g-accent); box-shadow: 0 0 0 2px var(--g-panel) inset; }
|
|
83
|
+
.g-tabs { display: flex; gap: 4px; flex-wrap: wrap; position: sticky; top: 0; z-index: 3;
|
|
84
|
+
background: var(--g-panel); padding: 3px 0 7px; }
|
|
85
|
+
.g-tab { border: 1px solid var(--g-border); background: var(--g-card); color: var(--g-ink);
|
|
86
|
+
border-radius: 999px; padding: 3px 9px; font-size: 11px; cursor: pointer; transition: .15s;
|
|
87
|
+
display: inline-flex; gap: 4px; align-items: center; }
|
|
88
|
+
.g-tab:hover { border-color: var(--g-accent); color: var(--g-accent); }
|
|
89
|
+
.g-tab.on { background: var(--g-accent); border-color: var(--g-accent); color: #fff; }
|
|
90
|
+
.g-card { background: var(--g-card); border: 1px solid var(--g-border); border-radius: 12px; padding: 9px 10px; }
|
|
91
|
+
.g-card.click { cursor: pointer; transition: .15s; }
|
|
92
|
+
.g-card.click:hover { border-color: var(--g-accent); transform: translateY(-1px); box-shadow: 0 6px 16px rgba(0,0,0,.08); }
|
|
93
|
+
.g-input { flex: 1; min-width: 130px; border: 1px solid var(--g-border); background: var(--g-card);
|
|
94
|
+
color: var(--g-ink); border-radius: 9px; padding: 6px 8px; font-size: 11.5px; outline: none; transition: .15s; }
|
|
95
|
+
.g-input:focus { border-color: var(--g-accent); box-shadow: 0 0 0 3px color-mix(in srgb, var(--g-accent) 18%, transparent); }
|
|
96
|
+
.g-btn { border: 1px solid var(--g-border); background: var(--g-card); color: var(--g-ink);
|
|
97
|
+
border-radius: 9px; padding: 4px 10px; font-size: 11px; cursor: pointer; transition: .15s; }
|
|
98
|
+
.g-btn:hover { border-color: var(--g-accent); color: var(--g-accent); }
|
|
99
|
+
.g-btn:disabled { opacity: .45; cursor: default; }
|
|
100
|
+
.g-btn.primary { background: var(--g-accent); border-color: var(--g-accent); color: #fff; }
|
|
101
|
+
.g-btn.primary:hover { filter: brightness(1.08); color: #fff; }
|
|
102
|
+
.g-chip { font-size: 10px; padding: 1px 7px; border-radius: 999px; border: 1px solid var(--g-border);
|
|
103
|
+
color: var(--g-sub); background: var(--g-soft); white-space: nowrap; }
|
|
104
|
+
.g-chip.ok { color: #1f7a4d; border-color: #bfe3cf; background: #eaf7ef; }
|
|
105
|
+
.g-chip.warn { color: #a15c00; border-color: #f0d6ae; background: #fdf3e3; }
|
|
106
|
+
.g-chip.err { color: #b42318; border-color: #f3c2bd; background: #fdecea; }
|
|
107
|
+
.g-dot { width: 6px; height: 6px; border-radius: 50%; display: inline-block; margin-right: 4px; }
|
|
108
|
+
.g-bar { height: 6px; border-radius: 999px; background: var(--g-soft); overflow: hidden; }
|
|
109
|
+
.g-bar > i { display: block; height: 100%; background: var(--g-accent); border-radius: 999px; transition: width .35s; }
|
|
110
|
+
.g-list { display: flex; flex-direction: column; gap: 6px; max-height: 430px; overflow: auto; padding-right: 2px; }
|
|
111
|
+
.g-list::-webkit-scrollbar { width: 5px; }
|
|
112
|
+
.g-list::-webkit-scrollbar-thumb { background: var(--g-border); border-radius: 3px; }
|
|
113
|
+
.g-line { padding: 5px 0; border-bottom: 1px dashed var(--g-border); line-height: 1.6; }
|
|
114
|
+
.g-line:last-child { border-bottom: none; }
|
|
115
|
+
.g-avatar { width: 20px; height: 20px; border-radius: 50%; background: var(--g-soft); color: var(--g-accent);
|
|
116
|
+
display: inline-flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700;
|
|
117
|
+
margin-right: 5px; vertical-align: middle; }
|
|
118
|
+
.g-quote { padding: 6px 9px; border-left: 3px solid var(--g-accent); background: var(--g-soft);
|
|
119
|
+
border-radius: 0 8px 8px 0; margin: 4px 0; line-height: 1.55; }
|
|
120
|
+
.g-empty { padding: 18px 12px; text-align: center; color: var(--g-sub);
|
|
121
|
+
border: 1px dashed var(--g-border); border-radius: 12px; font-size: 11px; }
|
|
122
|
+
.g-drop { border: 1px dashed var(--g-border); border-radius: 12px; padding: 10px;
|
|
123
|
+
background: var(--g-card); display: flex; flex-direction: column; gap: 7px; }
|
|
124
|
+
.g-stat { flex: 1; min-width: 78px; background: var(--g-card); border: 1px solid var(--g-border);
|
|
125
|
+
border-radius: 10px; padding: 7px 8px; }
|
|
126
|
+
.g-stat b { font-size: 15px; }
|
|
127
|
+
.g-toast { position: sticky; bottom: 0; background: var(--g-accent); color: #fff; border-radius: 9px;
|
|
128
|
+
padding: 6px 9px; font-size: 11px; box-shadow: 0 6px 16px rgba(0,0,0,.16); z-index: 5; }
|
|
129
|
+
.g-mark { background: color-mix(in srgb, var(--g-accent) 26%, transparent); border-radius: 3px; padding: 0 1px; }
|
|
130
|
+
.g-switch { width: 30px; height: 17px; border-radius: 999px; background: var(--g-border); position: relative;
|
|
131
|
+
cursor: pointer; transition: .15s; border: none; }
|
|
132
|
+
.g-switch.on { background: var(--g-accent); }
|
|
133
|
+
.g-switch::after { content: ""; position: absolute; top: 2px; left: 2px; width: 13px; height: 13px;
|
|
134
|
+
border-radius: 50%; background: #fff; transition: .15s; }
|
|
135
|
+
.g-switch.on::after { left: 15px; }
|
|
136
|
+
.g-code { font-family: ui-monospace, Consolas, monospace; font-size: 10px; color: var(--g-sub);
|
|
137
|
+
word-break: break-all; }
|
|
138
|
+
`;
|
|
139
|
+
|
|
140
|
+
function ensureStyle() {
|
|
141
|
+
if (typeof document === "undefined") return;
|
|
142
|
+
if (document.getElementById("dsh-novel-game-style")) return;
|
|
143
|
+
const el = document.createElement("style");
|
|
144
|
+
el.id = "dsh-novel-game-style";
|
|
145
|
+
el.textContent = CSS;
|
|
146
|
+
document.head.appendChild(el);
|
|
147
|
+
}
|
|
62
148
|
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
tab: (on) => ({
|
|
70
|
-
border: `1px solid ${on ? C.accent : C.border}`,
|
|
71
|
-
background: on ? C.accent : C.bg,
|
|
72
|
-
color: on ? "#fff" : C.fg,
|
|
73
|
-
borderRadius: 6, padding: "3px 8px", cursor: "pointer", fontSize: 11,
|
|
74
|
-
}),
|
|
75
|
-
btn: (on) => ({
|
|
76
|
-
border: `1px solid ${on === false ? C.border : C.border}`,
|
|
77
|
-
background: on === false ? C.bg2 : C.bg,
|
|
78
|
-
color: C.fg, borderRadius: 6, padding: "3px 8px", cursor: "pointer", fontSize: 11,
|
|
79
|
-
}),
|
|
80
|
-
input: {
|
|
81
|
-
flex: 1, minWidth: 120, border: `1px solid ${C.border}`, borderRadius: 6,
|
|
82
|
-
padding: "4px 6px", fontSize: 11, background: C.bg, color: C.fg,
|
|
83
|
-
},
|
|
84
|
-
card: { border: `1px solid ${C.border}`, borderRadius: 8, padding: 8, background: C.bg },
|
|
85
|
-
card2: { border: `1px solid ${C.border}`, borderRadius: 8, padding: 8, background: C.bg2 },
|
|
86
|
-
sub: { color: C.sub, fontSize: 11 },
|
|
87
|
-
line: { padding: "3px 0", borderBottom: `1px dashed ${C.border}`, lineHeight: 1.5 },
|
|
88
|
-
speaker: { fontWeight: 600, marginRight: 4 },
|
|
89
|
-
choice: { margin: "6px 0", padding: 6, border: `1px solid ${C.border}`, borderRadius: 6, background: C.bg2 },
|
|
90
|
-
notice: { color: C.accent, fontSize: 11 },
|
|
91
|
-
error: { color: "#b42318", fontSize: 11, whiteSpace: "pre-wrap" },
|
|
92
|
-
list: { display: "flex", flexDirection: "column", gap: 4, maxHeight: 380, overflow: "auto" },
|
|
93
|
-
pill: { fontSize: 10, padding: "1px 6px", borderRadius: 999, border: `1px solid ${C.border}`, color: C.sub },
|
|
94
|
-
empty: { padding: 16, textAlign: "center", color: C.sub, fontSize: 11 },
|
|
149
|
+
const fmt = (n) => (typeof n === "number" ? n.toLocaleString() : String(n ?? 0));
|
|
150
|
+
const baseName = (p) => String(p || "").replace(/[\\/]+$/, "").split(/[\\/]/).pop() || p;
|
|
151
|
+
const dirName = (p) => {
|
|
152
|
+
const value = String(p || "").replace(/[\\/]+$/, "");
|
|
153
|
+
const index = Math.max(value.lastIndexOf("\\"), value.lastIndexOf("/"));
|
|
154
|
+
return index > 0 ? value.slice(0, index) : value;
|
|
95
155
|
};
|
|
156
|
+
const initial = (name) => (name ? String(name).trim().slice(0, 1) : "?");
|
|
157
|
+
|
|
158
|
+
function Highlight({ text, query, style }) {
|
|
159
|
+
if (!query) return h("span", { style }, text);
|
|
160
|
+
const source = String(text ?? "");
|
|
161
|
+
const lower = source.toLowerCase();
|
|
162
|
+
const needle = String(query).toLowerCase();
|
|
163
|
+
const parts = [];
|
|
164
|
+
let cursor = 0;
|
|
165
|
+
let index = lower.indexOf(needle);
|
|
166
|
+
let key = 0;
|
|
167
|
+
while (index >= 0) {
|
|
168
|
+
if (index > cursor) parts.push(h("span", { key: key++ }, source.slice(cursor, index)));
|
|
169
|
+
parts.push(h("mark", { key: key++, className: "g-mark" }, source.slice(index, index + needle.length)));
|
|
170
|
+
cursor = index + needle.length;
|
|
171
|
+
index = lower.indexOf(needle, cursor);
|
|
172
|
+
}
|
|
173
|
+
if (cursor < source.length) parts.push(h("span", { key: key++ }, source.slice(cursor)));
|
|
174
|
+
return h("span", { style }, parts);
|
|
175
|
+
}
|
|
96
176
|
|
|
97
|
-
function Btn({ children, onClick, disabled,
|
|
98
|
-
return h("button", { type: "button",
|
|
177
|
+
function Btn({ children, onClick, disabled, primary, title }) {
|
|
178
|
+
return h("button", { type: "button", className: `g-btn${primary ? " primary" : ""}`, onClick, disabled, title }, children);
|
|
99
179
|
}
|
|
100
180
|
|
|
101
181
|
function Panel({ sessionId, remote }) {
|
|
102
|
-
const [tab, setTab] =
|
|
103
|
-
const [
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
const [
|
|
107
|
-
const [
|
|
108
|
-
const [
|
|
109
|
-
const [
|
|
110
|
-
const [
|
|
111
|
-
const [
|
|
112
|
-
const [
|
|
113
|
-
const [
|
|
114
|
-
const [
|
|
115
|
-
const [
|
|
116
|
-
const [
|
|
117
|
-
const [
|
|
118
|
-
const [
|
|
119
|
-
const [
|
|
120
|
-
const [
|
|
121
|
-
const [
|
|
182
|
+
const [tab, setTab] = useState("library");
|
|
183
|
+
const [themeId, setThemeId] = useState(() => {
|
|
184
|
+
try { return localStorage.getItem(THEME_KEY) || "paper"; } catch { return "paper"; }
|
|
185
|
+
});
|
|
186
|
+
const [showThemes, setShowThemes] = useState(false);
|
|
187
|
+
const [status, setStatus] = useState(null);
|
|
188
|
+
const [gameId, setGameId] = useState("");
|
|
189
|
+
const [pathInput, setPathInput] = useState("");
|
|
190
|
+
const [consent, setConsent] = useState(false);
|
|
191
|
+
const [mode, setMode] = useState("incremental");
|
|
192
|
+
const [detected, setDetected] = useState(null);
|
|
193
|
+
const [job, setJob] = useState(null);
|
|
194
|
+
const [coverage, setCoverage] = useState(null);
|
|
195
|
+
const [scenes, setScenes] = useState(null);
|
|
196
|
+
const [sceneQuery, setSceneQuery] = useState("");
|
|
197
|
+
const [detail, setDetail] = useState(null);
|
|
198
|
+
const [routes, setRoutes] = useState(null);
|
|
199
|
+
const [query, setQuery] = useState("");
|
|
200
|
+
const [results, setResults] = useState(null);
|
|
201
|
+
const [cast, setCast] = useState(null);
|
|
202
|
+
const [terms, setTerms] = useState(null);
|
|
203
|
+
const [castView, setCastView] = useState("cast");
|
|
204
|
+
const [picks, setPicks] = useState(null);
|
|
205
|
+
const [exported, setExported] = useState(null);
|
|
206
|
+
const [notice, setNotice] = useState("");
|
|
207
|
+
const [error, setError] = useState("");
|
|
208
|
+
const [busy, setBusy] = useState(false);
|
|
209
|
+
const theme = THEMES.find((item) => item.id === themeId) ?? THEMES[0];
|
|
210
|
+
|
|
211
|
+
useEffect(() => { ensureStyle(); try { localStorage.setItem(THEME_KEY, themeId); } catch { /* ignore */ } }, [themeId]);
|
|
212
|
+
useEffect(() => { loadStatus(); }, []);
|
|
122
213
|
|
|
123
214
|
const flash = (message) => { setNotice(message); setTimeout(() => setNotice(""), 2600); };
|
|
124
215
|
|
|
@@ -155,9 +246,7 @@ window.__ModuleLoader__.load({
|
|
|
155
246
|
}
|
|
156
247
|
}
|
|
157
248
|
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
React.useEffect(() => {
|
|
249
|
+
useEffect(() => {
|
|
161
250
|
if (!job || job.status !== "running" || !remote) return undefined;
|
|
162
251
|
let timer = null;
|
|
163
252
|
let stopped = false;
|
|
@@ -186,32 +275,49 @@ window.__ModuleLoader__.load({
|
|
|
186
275
|
return () => { stopped = true; if (timer) clearTimeout(timer); };
|
|
187
276
|
}, [job?.jobId, job?.status]);
|
|
188
277
|
|
|
189
|
-
async function
|
|
190
|
-
const
|
|
191
|
-
if (
|
|
278
|
+
async function doDetect(target) {
|
|
279
|
+
const dir = (target ?? pathInput).trim();
|
|
280
|
+
if (!dir) { setError("先选一个游戏文件夹"); return; }
|
|
281
|
+
setPathInput(dir);
|
|
282
|
+
const value = await run(async () => unwrap(await remote.detect(sessionId, { path: dir })));
|
|
283
|
+
if (value) setDetected(value);
|
|
192
284
|
}
|
|
193
285
|
|
|
194
|
-
async function
|
|
195
|
-
const value = await run(async () => unwrap(await remote.
|
|
196
|
-
if (value
|
|
286
|
+
async function doPick(kind) {
|
|
287
|
+
const value = await run(async () => unwrap(await remote.pickPath(sessionId, { kind })));
|
|
288
|
+
if (!value || value.canceled) return;
|
|
289
|
+
const dir = kind === "file" ? dirName(value.path) : value.path;
|
|
290
|
+
setPathInput(dir);
|
|
291
|
+
flash(kind === "file" ? `已选文件 ${baseName(value.path)},将导入其所在目录` : `已选文件夹 ${baseName(dir)}`);
|
|
292
|
+
await doDetect(dir);
|
|
197
293
|
}
|
|
198
294
|
|
|
199
295
|
async function doImport() {
|
|
200
296
|
if (!consent) { setError("先勾选「我合法持有该游戏副本」"); return; }
|
|
201
|
-
const value = await run(async () => unwrap(await remote.import(sessionId, { path: pathInput.trim(), consent: true })));
|
|
297
|
+
const value = await run(async () => unwrap(await remote.import(sessionId, { path: pathInput.trim(), consent: true, mode })));
|
|
202
298
|
if (value) { setJob({ jobId: value.jobId, status: "running", progress: { phase: "queued" } }); setTab("extract"); }
|
|
203
299
|
}
|
|
204
300
|
|
|
301
|
+
async function openScene(sceneId) {
|
|
302
|
+
const value = await run(async () => unwrap(await remote.scene(sessionId, { gameId, sceneId })));
|
|
303
|
+
if (value) { setDetail(value); setTab("story"); }
|
|
304
|
+
}
|
|
305
|
+
|
|
205
306
|
async function doSearch() {
|
|
206
307
|
if (!query.trim()) return;
|
|
207
308
|
const value = await run(async () => unwrap(await remote.search(sessionId, { gameId, query: query.trim() })));
|
|
208
309
|
if (value) setResults(value);
|
|
209
310
|
}
|
|
210
311
|
|
|
312
|
+
async function loadRoutes() {
|
|
313
|
+
const value = await run(async () => unwrap(await remote.routes(sessionId, { gameId })));
|
|
314
|
+
if (value) setRoutes(value);
|
|
315
|
+
}
|
|
316
|
+
|
|
211
317
|
async function loadCast() {
|
|
212
318
|
const [people, glossary] = await Promise.all([
|
|
213
319
|
run(async () => unwrap(await remote.characters(sessionId, { gameId }))),
|
|
214
|
-
run(async () => unwrap(await remote.glossary(sessionId, { gameId, limit:
|
|
320
|
+
run(async () => unwrap(await remote.glossary(sessionId, { gameId, limit: 300 }))),
|
|
215
321
|
]);
|
|
216
322
|
if (people) setCast(people);
|
|
217
323
|
if (glossary) setTerms(glossary);
|
|
@@ -222,87 +328,133 @@ window.__ModuleLoader__.load({
|
|
|
222
328
|
if (value) setPicks(value);
|
|
223
329
|
}
|
|
224
330
|
|
|
225
|
-
async function loadRoutes() {
|
|
226
|
-
const value = await run(async () => unwrap(await remote.routes(sessionId, { gameId })));
|
|
227
|
-
if (value) setRoutes(value);
|
|
228
|
-
}
|
|
229
|
-
|
|
230
331
|
async function addPick(line) {
|
|
231
332
|
const value = await run(async () => unwrap(await remote.addPick(sessionId, { gameId, kind: "line", refId: line.lineId })));
|
|
232
333
|
if (value) flash("已收进同人准备篮");
|
|
233
334
|
}
|
|
234
335
|
|
|
336
|
+
async function remap(pickId) {
|
|
337
|
+
const value = await run(async () => unwrap(await remote.remapPick(sessionId, { gameId, pickId })));
|
|
338
|
+
if (value) { flash("已改绑到新位置"); await loadPicks(); }
|
|
339
|
+
}
|
|
340
|
+
|
|
235
341
|
async function doExport() {
|
|
236
342
|
const value = await run(async () => unwrap(await remote.export(sessionId, { gameId, formats: ["story", "canon", "brief"] })));
|
|
237
|
-
if (value) { setExported(value); flash("
|
|
343
|
+
if (value) { setExported(value); flash("已导出三件套"); }
|
|
344
|
+
}
|
|
345
|
+
|
|
346
|
+
async function spoilerToHere() {
|
|
347
|
+
if (!detail) return;
|
|
348
|
+
const max = detail.scene?.seq ?? 0;
|
|
349
|
+
const value = await run(async () => unwrap(await remote.saveSettings(sessionId, { spoiler: { mode: "scene", maxSceneOrder: max } })));
|
|
350
|
+
if (value) { flash(`剧透边界设为第 ${max + 1} 场`); await loadScenes(gameId, 0); }
|
|
238
351
|
}
|
|
239
352
|
|
|
240
353
|
const games = status?.list ?? [];
|
|
241
354
|
const current = games.find((item) => item.gameId === gameId) ?? null;
|
|
355
|
+
const sceneItems = (scenes?.items ?? []).filter((scene) => !sceneQuery.trim() || scene.title.toLowerCase().includes(sceneQuery.trim().toLowerCase()));
|
|
356
|
+
|
|
357
|
+
const themeBar = h("div", { className: "g-row" },
|
|
358
|
+
h("span", { className: "g-chip" }, current?.status === "partial" ? "部分成功" : (status ? "就绪" : "连接中")),
|
|
359
|
+
h("span", { className: "g-chip" }, `v${status?.toolVersion ?? "—"}`),
|
|
360
|
+
h("div", { className: "g-grow" }),
|
|
361
|
+
h("button", { type: "button", className: "g-iconbtn", onClick: () => setShowThemes((v) => !v) }, "底色"),
|
|
362
|
+
);
|
|
242
363
|
|
|
243
|
-
const
|
|
244
|
-
h("
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
}
|
|
364
|
+
const swatches = showThemes ? h("div", { className: "g-swatches" },
|
|
365
|
+
...THEMES.map((item) => h("button", {
|
|
366
|
+
key: item.id, type: "button", title: item.label,
|
|
367
|
+
className: `g-swatch${item.id === themeId ? " on" : ""}`,
|
|
368
|
+
style: { background: `linear-gradient(140deg, ${item.accent}, ${item.bg})` },
|
|
369
|
+
onClick: () => { setThemeId(item.id); flash(`底色:${item.label}`); },
|
|
370
|
+
})),
|
|
371
|
+
) : null;
|
|
372
|
+
|
|
373
|
+
const header = h("div", { className: "g-head" },
|
|
374
|
+
h("div", { className: "g-mark" }, "游"),
|
|
375
|
+
h("div", null,
|
|
376
|
+
h("div", { className: "g-title" }, "游戏剧情"),
|
|
377
|
+
h("div", { className: "g-sub" }, current ? `${current.title} · ${current.engine}` : "把本地游戏读成同人资料"),
|
|
378
|
+
),
|
|
379
|
+
h("div", { className: "g-grow" }),
|
|
380
|
+
h("button", { type: "button", className: "g-iconbtn", onClick: loadStatus, title: "刷新" }, "刷新"),
|
|
250
381
|
);
|
|
251
382
|
|
|
252
|
-
const tabs = h("div", {
|
|
253
|
-
[["library", "游戏库"], ["extract", "解包"], ["story", "剧情"], ["cast", "设定"], ["search", "检索"], ["prepare", "同人准备"]]
|
|
254
|
-
.map(([id, label]) => h("button", {
|
|
383
|
+
const tabs = h("div", { className: "g-tabs" },
|
|
384
|
+
[["library", "库", "游戏库"], ["extract", "包", "解包"], ["story", "剧", "剧情"], ["cast", "设", "设定"], ["search", "搜", "检索"], ["prepare", "备", "同人准备"]]
|
|
385
|
+
.map(([id, icon, label]) => h("button", {
|
|
386
|
+
key: id, type: "button", className: `g-tab${tab === id ? " on" : ""}`,
|
|
387
|
+
onClick: () => { setTab(id); if (id === "cast" && !cast) loadCast(); if (id === "prepare") loadPicks(); },
|
|
388
|
+
}, h("span", null, icon), h("span", null, label))),
|
|
255
389
|
);
|
|
256
390
|
|
|
257
391
|
function renderLibrary() {
|
|
258
392
|
return h("div", { style: { display: "flex", flexDirection: "column", gap: 8 } },
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
h("div", {
|
|
266
|
-
|
|
267
|
-
h("div", { style: { ...S.sub, wordBreak: "break-all" } }, item.root),
|
|
268
|
-
)),
|
|
269
|
-
h("div", { style: S.card2 },
|
|
270
|
-
h("div", { style: S.sub, marginBottom: 4 }, "导入本地游戏(只读;必须是你合法持有的副本)"),
|
|
271
|
-
h("div", { style: S.row },
|
|
272
|
-
h("input", { style: S.input, placeholder: "D:\\Games\\某游戏", value: pathInput, onChange: (e) => setPathInput(e.target.value) }),
|
|
273
|
-
h(Btn, { onClick: doDetect, disabled: busy || !pathInput.trim() }, "探测"),
|
|
274
|
-
h(Btn, { onClick: doImport, disabled: busy || !pathInput.trim() || !consent }, "导入"),
|
|
393
|
+
h("div", { className: "g-drop" },
|
|
394
|
+
h("div", { className: "g-row" }, h("b", null, "导入游戏"), h("span", { className: "g-chip" }, "只读 · 本地"), h("div", { className: "g-grow" }),
|
|
395
|
+
h("div", { className: "g-row" },
|
|
396
|
+
h("button", { type: "button", className: "g-chip", style: { cursor: "pointer" }, onClick: () => setMode("incremental") }, mode === "incremental" ? "增量 ●" : "增量"),
|
|
397
|
+
h("button", { type: "button", className: "g-chip", style: { cursor: "pointer" }, onClick: () => setMode("full") }, mode === "full" ? "全量 ●" : "全量"),
|
|
398
|
+
)),
|
|
399
|
+
h("div", { className: "g-row" },
|
|
400
|
+
h("input", { className: "g-input", placeholder: "D:\\Games\\某游戏", value: pathInput, onChange: (e) => setPathInput(e.target.value) }),
|
|
275
401
|
),
|
|
276
|
-
h("
|
|
277
|
-
h(
|
|
278
|
-
"
|
|
402
|
+
h("div", { className: "g-row" },
|
|
403
|
+
h(Btn, { onClick: () => doPick("folder"), disabled: busy }, "选择文件夹"),
|
|
404
|
+
h(Btn, { onClick: () => doPick("file"), disabled: busy }, "选择文件"),
|
|
405
|
+
h(Btn, { onClick: () => doDetect(), disabled: busy }, "探测"),
|
|
406
|
+
h(Btn, { onClick: doImport, disabled: busy || !consent, primary: true }, "导入"),
|
|
279
407
|
),
|
|
280
|
-
|
|
281
|
-
h("
|
|
282
|
-
h("
|
|
283
|
-
|
|
408
|
+
h("div", { className: "g-row" },
|
|
409
|
+
h("button", { type: "button", className: `g-switch${consent ? " on" : ""}`, onClick: () => setConsent((v) => !v), "aria-label": "合法持有确认" }),
|
|
410
|
+
h("span", { className: "g-sub" }, "我合法持有该游戏副本,仅用于个人同人创作参考"),
|
|
411
|
+
),
|
|
412
|
+
detected ? h("div", { style: { borderTop: `1px dashed ${theme.border}`, paddingTop: 7 } },
|
|
413
|
+
h("div", { className: "g-row" }, h("b", null, detected.chosen?.label ?? "未知"), h("span", { className: "g-chip ok" }, `置信 ${Math.round((detected.chosen?.confidence ?? 0) * 100)}%`), h("span", { className: "g-chip" }, detected.meta?.title ?? "")),
|
|
414
|
+
h("div", { className: "g-bar", style: { margin: "6px 0" } }, h("i", { style: { width: `${Math.round((detected.chosen?.confidence ?? 0) * 100)}%` } })),
|
|
415
|
+
h("div", { className: "g-sub" }, (detected.chosen?.evidence ?? []).join(" · ")),
|
|
416
|
+
h("div", { className: "g-sub" }, `文本容器 ${detected.containers?.filter((c) => c.textBearing).length ?? 0} 个`),
|
|
284
417
|
) : null,
|
|
285
418
|
),
|
|
419
|
+
games.length === 0 ? h("div", { className: "g-empty" }, "还没有导入游戏。选文件夹或选文件,探测后勾选确认再导入。") : null,
|
|
420
|
+
...games.map((item) => h("div", {
|
|
421
|
+
key: item.gameId, className: "g-card click", style: { borderColor: item.gameId === gameId ? theme.accent : theme.border },
|
|
422
|
+
onClick: () => { setGameId(item.gameId); setDetail(null); setScenes(null); setRoutes(null); loadScenes(item.gameId, 0); setCoverage(item); },
|
|
423
|
+
},
|
|
424
|
+
h("div", { className: "g-row" }, h("b", null, item.title), h("span", { className: "g-chip" }, item.engine), h("span", { className: `g-chip ${item.status === "partial" ? "warn" : "ok"}` }, item.status)),
|
|
425
|
+
h("div", { className: "g-row", style: { marginTop: 5 } },
|
|
426
|
+
h("span", { className: "g-sub" }, `场景 ${fmt(item.counts?.scenes)}`),
|
|
427
|
+
h("span", { className: "g-sub" }, `· 台词 ${fmt(item.counts?.lines)}`),
|
|
428
|
+
h("span", { className: "g-sub" }, `· 词条 ${fmt(item.counts?.glossary)}`),
|
|
429
|
+
),
|
|
430
|
+
h("div", { className: "g-bar", style: { marginTop: 6 } }, h("i", { style: { width: `${Math.min(100, Math.round(((item.coverage?.extracted ?? 0) / Math.max(1, item.coverage?.textBearing ?? 1)) * 100))}%` } })),
|
|
431
|
+
h("div", { className: "g-code", style: { marginTop: 4 } }, item.root),
|
|
432
|
+
)),
|
|
286
433
|
);
|
|
287
434
|
}
|
|
288
435
|
|
|
289
436
|
function renderExtract() {
|
|
290
437
|
const summary = coverage?.summary ?? current?.coverage ?? null;
|
|
291
438
|
const containers = coverage?.containers ?? [];
|
|
439
|
+
const progress = job?.progress ?? {};
|
|
440
|
+
const pct = progress.total > 0 ? Math.round((progress.done / progress.total) * 100) : (job?.status === "done" ? 100 : 8);
|
|
292
441
|
return h("div", { style: { display: "flex", flexDirection: "column", gap: 8 } },
|
|
293
|
-
job ? h("div", {
|
|
294
|
-
h("div", {
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
h("div", {
|
|
442
|
+
job ? h("div", { className: "g-card" },
|
|
443
|
+
h("div", { className: "g-row" }, h("b", null, "导入任务"), h("span", { className: `g-chip ${job.status === "failed" ? "err" : job.status === "done" ? "ok" : "warn"}` }, job.status), h("div", { className: "g-grow" }),
|
|
444
|
+
job.status === "running" ? h(Btn, { onClick: async () => { const v = await run(async () => unwrap(await remote.cancelJob(sessionId, { jobId: job.jobId }))); if (v) flash("已请求取消"); } }, "取消") : null),
|
|
445
|
+
h("div", { className: "g-bar", style: { margin: "7px 0 4px" } }, h("i", { style: { width: `${pct}%` } })),
|
|
446
|
+
h("div", { className: "g-row" }, h("span", { className: "g-sub" }, `${progress.phase ?? ""} ${progress.done ?? 0}/${progress.total ?? 0}`), h("span", { className: "g-grow" }), h("span", { className: "g-sub" }, `${pct}%`)),
|
|
447
|
+
) : h("div", { className: "g-empty" }, "没有进行中的任务。到「游戏库」选一个游戏导入。"),
|
|
448
|
+
summary ? h("div", { style: { display: "flex", gap: 6, flexWrap: "wrap" } },
|
|
449
|
+
h("div", { className: "g-stat" }, h("div", { className: "g-sub" }, "文本容器"), h("b", null, fmt(summary.textBearing))),
|
|
450
|
+
h("div", { className: "g-stat" }, h("div", { className: "g-sub" }, "已解"), h("b", null, fmt(summary.extracted))),
|
|
451
|
+
h("div", { className: "g-stat" }, h("div", { className: "g-sub" }, "复用"), h("b", null, fmt(summary.reused))),
|
|
452
|
+
h("div", { className: "g-stat" }, h("div", { className: "g-sub" }, "未解析单元"), h("b", null, fmt(summary.skippedUnits))),
|
|
301
453
|
) : null,
|
|
302
|
-
containers.length ? h("div", {
|
|
303
|
-
...containers.slice(0,
|
|
304
|
-
h("span", { style: {
|
|
305
|
-
h("span",
|
|
454
|
+
containers.length ? h("div", { className: "g-list" },
|
|
455
|
+
...containers.slice(0, 80).map((row) => h("div", { key: row.rel, style: { display: "flex", gap: 6, justifyContent: "space-between", alignItems: "center" } },
|
|
456
|
+
h("span", { className: "g-code", style: { flex: 1 } }, row.rel),
|
|
457
|
+
h("span", { className: `g-chip ${row.status === "error" ? "err" : row.status === "reused" ? "" : "ok"}` }, `${row.status}${row.units ? ` · ${row.units}` : ""}`),
|
|
306
458
|
)),
|
|
307
459
|
) : null,
|
|
308
460
|
);
|
|
@@ -311,128 +463,164 @@ window.__ModuleLoader__.load({
|
|
|
311
463
|
function renderStory() {
|
|
312
464
|
if (routes) {
|
|
313
465
|
const titleOf = (id) => routes.nodes.find((node) => node.sceneId === id)?.title ?? id;
|
|
466
|
+
const resolved = routes.edges.filter((edge) => edge.resolved);
|
|
314
467
|
return h("div", { style: { display: "flex", flexDirection: "column", gap: 6 } },
|
|
315
|
-
h("div", {
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
468
|
+
h("div", { className: "g-row" }, h(Btn, { onClick: () => setRoutes(null) }, "← 场景"), h("b", null, "路线图"), h("div", { className: "g-grow" }),
|
|
469
|
+
h("span", { className: "g-chip" }, `节点 ${routes.nodes.length}`), h("span", { className: "g-chip" }, `未解析 ${routes.unresolved}`)),
|
|
470
|
+
h("div", { className: "g-list" },
|
|
471
|
+
...resolved.slice(0, 120).map((edge, index) => h("div", { key: index, className: "g-card", style: { padding: "6px 8px" } },
|
|
472
|
+
h("div", { className: "g-sub" }, `${titleOf(edge.from)} → ${titleOf(edge.to)}`),
|
|
473
|
+
h("div", { className: "g-chip" }, `${edge.kind === "choice" ? "选项" : "跳转"}:${edge.label}`),
|
|
474
|
+
)),
|
|
475
|
+
),
|
|
476
|
+
h("div", { className: "g-row", style: { marginTop: 4 } }, h("b", null, "候选结局")),
|
|
477
|
+
...routes.endings.slice(0, 30).map((id) => h("div", { key: id, className: "g-sub" }, `· ${titleOf(id)}`)),
|
|
323
478
|
);
|
|
324
479
|
}
|
|
325
480
|
if (detail) {
|
|
326
481
|
return h("div", { style: { display: "flex", flexDirection: "column", gap: 6 } },
|
|
327
|
-
h("div", {
|
|
328
|
-
h(Btn, { onClick: () => setDetail(null) }, "←
|
|
482
|
+
h("div", { className: "g-row" },
|
|
483
|
+
h(Btn, { onClick: () => setDetail(null) }, "← 场景"),
|
|
329
484
|
h("b", null, detail.scene?.title ?? ""),
|
|
330
|
-
h("span", {
|
|
485
|
+
h("span", { className: "g-chip" }, `${detail.total} 句`),
|
|
486
|
+
h("div", { className: "g-grow" }),
|
|
487
|
+
h(Btn, { onClick: spoilerToHere, title: "把剧透边界设到这一幕" }, "剧透到此"),
|
|
331
488
|
),
|
|
332
|
-
h("div", {
|
|
333
|
-
...detail.lines.map((line) => h("div", { key: line.lineId,
|
|
489
|
+
h("div", { className: "g-list" },
|
|
490
|
+
...detail.lines.map((line) => h("div", { key: line.lineId, className: "g-line" },
|
|
334
491
|
h("div", null,
|
|
335
|
-
line.speakerName ? h("span", {
|
|
492
|
+
line.speakerName ? h("span", { className: "g-avatar" }, initial(line.speakerName)) : null,
|
|
493
|
+
line.speakerName ? h("b", { style: { marginRight: 4 } }, `${line.speakerName}:`) : null,
|
|
336
494
|
h("span", null, line.text),
|
|
337
|
-
h("button", { type: "button", style: {
|
|
495
|
+
h("button", { type: "button", className: "g-chip", style: { marginLeft: 6, cursor: "pointer" }, onClick: () => addPick(line) }, "收"),
|
|
338
496
|
),
|
|
339
|
-
line.refs?.voice || line.refs?.cg
|
|
497
|
+
line.refs?.voice || line.refs?.cg
|
|
498
|
+
? h("div", { className: "g-code" }, [line.refs?.voice ? `语音 ${line.refs.voice}` : "", line.refs?.cg ? `CG ${line.refs.cg}` : ""].filter(Boolean).join(" · "))
|
|
499
|
+
: null,
|
|
340
500
|
)),
|
|
341
|
-
...detail.choices.map((choice) => h("div", { key: choice.choiceId,
|
|
342
|
-
choice.prompt ? h("div", {
|
|
501
|
+
...detail.choices.map((choice) => h("div", { key: choice.choiceId, className: "g-quote" },
|
|
502
|
+
choice.prompt ? h("div", { className: "g-sub" }, choice.prompt) : null,
|
|
343
503
|
h("div", null, `[选项] ${choice.options.map((option) => option.text).join(" / ")}`),
|
|
344
504
|
)),
|
|
345
505
|
),
|
|
346
506
|
);
|
|
347
507
|
}
|
|
348
|
-
const items = scenes?.items ?? [];
|
|
349
508
|
return h("div", { style: { display: "flex", flexDirection: "column", gap: 6 } },
|
|
350
|
-
h("div", {
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
},
|
|
356
|
-
|
|
357
|
-
h("div", {
|
|
358
|
-
|
|
509
|
+
h("div", { className: "g-row" },
|
|
510
|
+
h("input", { className: "g-input", placeholder: "筛选场景…", value: sceneQuery, onChange: (e) => setSceneQuery(e.target.value) }),
|
|
511
|
+
h(Btn, { onClick: loadRoutes, disabled: busy || !gameId }, "路线图"),
|
|
512
|
+
),
|
|
513
|
+
h("div", { className: "g-row" }, h("span", { className: "g-sub" }, `共 ${scenes?.total ?? 0} 场`), h("span", { className: "g-chip" }, `已加载 ${sceneItems.length}`)),
|
|
514
|
+
scenes && scenes.items.length === 0 ? h("div", { className: "g-empty" }, "这个游戏还没有可浏览的场景。") : null,
|
|
515
|
+
h("div", { className: "g-list" },
|
|
516
|
+
...sceneItems.map((scene) => h("div", { key: scene.sceneId, className: "g-card click", onClick: () => openScene(scene.sceneId) },
|
|
517
|
+
h("div", { className: "g-row" }, h("span", { className: "g-chip" }, String((scene.seq ?? 0) + 1)), h("b", { className: "g-grow" }, scene.title)),
|
|
518
|
+
h("div", { className: "g-sub", style: { marginTop: 3 } }, `${scene.lineCount} 句${scene.choiceCount ? ` · ${scene.choiceCount} 个选项` : ""}${scene.lowConfidence ? " · 低置信" : ""}`),
|
|
519
|
+
)),
|
|
520
|
+
),
|
|
359
521
|
scenes && scenes.items.length < scenes.total ? h(Btn, { onClick: () => loadScenes(gameId, scenes.items.length) }, "加载更多") : null,
|
|
360
522
|
);
|
|
361
523
|
}
|
|
362
524
|
|
|
363
525
|
function renderCast() {
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
367
|
-
h("div", {
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
526
|
+
if (castView === "terms") {
|
|
527
|
+
const items = terms?.items ?? [];
|
|
528
|
+
return h("div", { style: { display: "flex", flexDirection: "column", gap: 6 } },
|
|
529
|
+
h("div", { className: "g-row" }, h(Btn, { onClick: () => setCastView("cast") }, "人物"), h(Btn, { primary: true }, "词条"), h("div", { className: "g-grow" }), h("span", { className: "g-chip" }, fmt(terms?.total ?? 0))),
|
|
530
|
+
h("div", { className: "g-list" },
|
|
531
|
+
...items.slice(0, 200).map((term) => h("div", { key: term.glossaryId, className: "g-card", style: { padding: "7px 9px" } },
|
|
532
|
+
h("div", { className: "g-row" }, h("span", { className: "g-chip" }, term.kind), h("b", null, term.name)),
|
|
533
|
+
term.description ? h("div", { className: "g-sub", style: { marginTop: 3 } }, term.description) : null,
|
|
534
|
+
)),
|
|
535
|
+
),
|
|
536
|
+
);
|
|
537
|
+
}
|
|
538
|
+
return h("div", { style: { display: "flex", flexDirection: "column", gap: 6 } },
|
|
539
|
+
h("div", { className: "g-row" }, h(Btn, { primary: true }, "人物"), h(Btn, { onClick: () => setCastView("terms") }, "词条"), h("div", { className: "g-grow" }), h("span", { className: "g-chip" }, fmt(cast?.total ?? 0))),
|
|
540
|
+
h("div", { className: "g-list" },
|
|
541
|
+
...(cast?.characters ?? []).slice(0, 60).map((character) => h("div", { key: character.characterId, className: "g-card" },
|
|
542
|
+
h("div", { className: "g-row" }, h("span", { className: "g-avatar" }, initial(character.name)), h("b", null, character.name), h("span", { className: "g-chip" }, `${character.lineCount} 句`), h("span", { className: "g-chip" }, `出场 ${character.sceneCount}`)),
|
|
543
|
+
character.aliases?.length ? h("div", { className: "g-sub", style: { marginTop: 3 } }, `别名:${character.aliases.join("、")}`) : null,
|
|
544
|
+
...character.quotes.slice(0, 2).map((quote, index) => h("div", { key: index, className: "g-quote" }, `「${quote.text}」`)),
|
|
545
|
+
)),
|
|
546
|
+
),
|
|
377
547
|
);
|
|
378
548
|
}
|
|
379
549
|
|
|
380
550
|
function renderSearch() {
|
|
381
551
|
return h("div", { style: { display: "flex", flexDirection: "column", gap: 8 } },
|
|
382
|
-
h("div", {
|
|
383
|
-
h("input", {
|
|
384
|
-
h(Btn, { onClick: doSearch, disabled: busy }, "搜索"),
|
|
552
|
+
h("div", { className: "g-row" },
|
|
553
|
+
h("input", { className: "g-input", placeholder: "搜台词 / 角色 / 词条,回车", value: query, onChange: (e) => setQuery(e.target.value), onKeyDown: (e) => { if (e.key === "Enter") doSearch(); } }),
|
|
554
|
+
h(Btn, { onClick: doSearch, disabled: busy, primary: true }, "搜索"),
|
|
555
|
+
),
|
|
556
|
+
results ? h("div", { className: "g-row" }, h("span", { className: "g-sub" }, `命中 ${results.total} 条`), h("span", { className: "g-chip" }, `“${results.query}”`)) : null,
|
|
557
|
+
h("div", { className: "g-list" },
|
|
558
|
+
...(results?.items ?? []).map((item) => h("div", {
|
|
559
|
+
key: item.lineId ?? item.glossaryId, className: `g-card${item.kind === "line" ? " click" : ""}`,
|
|
560
|
+
onClick: () => { if (item.kind === "line") openScene(item.sceneId); },
|
|
561
|
+
},
|
|
562
|
+
h("div", { className: "g-sub" }, `${item.sceneTitle ?? ""}${item.speakerName ? ` · ${item.speakerName}` : ""}`),
|
|
563
|
+
h("div", { style: { marginTop: 3 } }, h(Highlight, { text: item.text ?? `${item.term}:${item.description ?? ""}`, query: query.trim() })),
|
|
564
|
+
)),
|
|
385
565
|
),
|
|
386
|
-
results ? h("div", { style: S.sub }, `命中 ${results.total} 条`) : null,
|
|
387
|
-
...(results?.items ?? []).map((item) => h("div", {
|
|
388
|
-
key: item.lineId ?? item.glossaryId,
|
|
389
|
-
style: { ...S.card, cursor: item.kind === "line" ? "pointer" : "default" },
|
|
390
|
-
onClick: () => { if (item.kind === "line") openScene(item.sceneId); },
|
|
391
|
-
},
|
|
392
|
-
h("div", { style: S.sub }, `${item.sceneTitle ?? ""}${item.speakerName ? ` · ${item.speakerName}` : ""}`),
|
|
393
|
-
h("div", null, item.text ?? `${item.term}:${item.description ?? ""}`),
|
|
394
|
-
)),
|
|
395
566
|
);
|
|
396
567
|
}
|
|
397
568
|
|
|
398
569
|
function renderPrepare() {
|
|
570
|
+
const items = picks?.items ?? [];
|
|
399
571
|
return h("div", { style: { display: "flex", flexDirection: "column", gap: 8 } },
|
|
400
|
-
h("div", {
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
h("div", {
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
572
|
+
h("div", { className: "g-row" }, h("b", null, "同人准备篮"), h("span", { className: "g-chip" }, `${items.length}`), picks?.staleCount ? h("span", { className: "g-chip warn" }, `失效 ${picks.staleCount}`) : null, h("div", { className: "g-grow" }), h(Btn, { onClick: loadPicks }, "刷新")),
|
|
573
|
+
items.length === 0 ? h("div", { className: "g-empty" }, "在剧情里点「收」,把关键台词收进来。") : null,
|
|
574
|
+
h("div", { className: "g-list" },
|
|
575
|
+
...items.map((pick) => h("div", { key: pick.pickId, className: "g-card" },
|
|
576
|
+
h("div", { className: "g-row" }, h("span", { className: "g-chip" }, pick.kind), isPickStale(pick) ? h("span", { className: "g-chip warn" }, "失效") : null, h("div", { className: "g-grow" }),
|
|
577
|
+
pick.candidate ? h(Btn, { onClick: () => remap(pick.pickId) }, "改绑") : null),
|
|
578
|
+
pick.quote ? h("div", { className: "g-quote" }, `「${pick.quote}」`) : h("div", { className: "g-code" }, pick.refId),
|
|
579
|
+
pick.note ? h("div", { className: "g-sub", style: { marginTop: 3 } }, pick.note) : null,
|
|
580
|
+
)),
|
|
581
|
+
),
|
|
582
|
+
h("div", { className: "g-card" },
|
|
583
|
+
h("div", { className: "g-row" }, h("b", null, "导出"), h("span", { className: "g-chip" }, "只写 .dsh-novel-game/exports/")),
|
|
584
|
+
h("div", { className: "g-row", style: { marginTop: 6 } },
|
|
585
|
+
h(Btn, { onClick: doExport, disabled: busy || !gameId, primary: true }, "导出三件套"),
|
|
411
586
|
),
|
|
412
|
-
exported ? h("div", { style: {
|
|
413
|
-
`story
|
|
414
|
-
h("
|
|
415
|
-
h("
|
|
416
|
-
h("
|
|
587
|
+
exported ? h("div", { style: { marginTop: 7 } },
|
|
588
|
+
h("div", { className: "g-code" }, `story.md ${exported.files?.story ?? ""}`),
|
|
589
|
+
h("div", { className: "g-code" }, `canon.json ${exported.files?.canon ?? ""}`),
|
|
590
|
+
h("div", { className: "g-code" }, `brief.md ${exported.files?.brief ?? ""}`),
|
|
591
|
+
h("div", { className: "g-sub", style: { marginTop: 4 } }, "在 fanfic 里 /fic import 指到 story.md 即可建 canon。"),
|
|
417
592
|
) : null,
|
|
418
593
|
),
|
|
419
594
|
);
|
|
420
595
|
}
|
|
421
596
|
|
|
422
|
-
|
|
597
|
+
const body = tab === "library" ? renderLibrary()
|
|
598
|
+
: tab === "extract" ? renderExtract()
|
|
599
|
+
: tab === "story" ? renderStory()
|
|
600
|
+
: tab === "cast" ? renderCast()
|
|
601
|
+
: tab === "search" ? renderSearch()
|
|
602
|
+
: renderPrepare();
|
|
603
|
+
|
|
604
|
+
return h("div", {
|
|
605
|
+
"data-gpanel": "1",
|
|
606
|
+
style: {
|
|
607
|
+
"--g-bg": theme.bg, "--g-panel": theme.panel, "--g-card": theme.card,
|
|
608
|
+
"--g-border": theme.border, "--g-ink": theme.ink, "--g-sub": theme.sub,
|
|
609
|
+
"--g-accent": theme.accent, "--g-soft": theme.soft,
|
|
610
|
+
},
|
|
611
|
+
},
|
|
423
612
|
header,
|
|
613
|
+
themeBar,
|
|
614
|
+
swatches,
|
|
424
615
|
tabs,
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
tab === "cast" ? renderCast() : null,
|
|
429
|
-
tab === "search" ? renderSearch() : null,
|
|
430
|
-
tab === "prepare" ? renderPrepare() : null,
|
|
431
|
-
notice ? h("div", { style: S.notice }, notice) : null,
|
|
432
|
-
error ? h("div", { style: S.error }, error) : null,
|
|
616
|
+
body,
|
|
617
|
+
notice ? h("div", { className: "g-toast" }, notice) : null,
|
|
618
|
+
error ? h("div", { className: "g-chip err", style: { padding: "6px 8px", whiteSpace: "pre-wrap" } }, error) : null,
|
|
433
619
|
);
|
|
434
620
|
}
|
|
435
621
|
|
|
622
|
+
function isPickStale(pick) { return pick.stale === true; }
|
|
623
|
+
|
|
436
624
|
const TAB_ID = "dsh-novel-game";
|
|
437
625
|
const TAB_KIND = "novel-game";
|
|
438
626
|
|
|
@@ -466,10 +654,7 @@ window.__ModuleLoader__.load({
|
|
|
466
654
|
const right = scoped.get("sidebarRight");
|
|
467
655
|
if (!tabs || !right) return;
|
|
468
656
|
scoped.effect(() => tabs.register({
|
|
469
|
-
id: TAB_ID,
|
|
470
|
-
kind: TAB_KIND,
|
|
471
|
-
priority: "extension",
|
|
472
|
-
keepMounted: true,
|
|
657
|
+
id: TAB_ID, kind: TAB_KIND, priority: "extension", keepMounted: true,
|
|
473
658
|
title: () => "游戏",
|
|
474
659
|
guide: [{ id: TAB_ID, order: 27, title: () => "游戏", description: () => "本地游戏剧情/文本/设定的解包、浏览与同人准备" }],
|
|
475
660
|
}), "novel-game: tab type");
|
package/index.js
CHANGED
package/lib/picker.mjs
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import { execFile } from 'node:child_process';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { GameError, ErrorCode } from './core/errors.mjs';
|
|
4
|
+
|
|
5
|
+
const CANCEL = '__CANCEL__';
|
|
6
|
+
|
|
7
|
+
function folderScript() {
|
|
8
|
+
return [
|
|
9
|
+
'Add-Type -AssemblyName System.Windows.Forms | Out-Null',
|
|
10
|
+
'$owner = New-Object System.Windows.Forms.Form',
|
|
11
|
+
'$owner.TopMost = $true',
|
|
12
|
+
'$owner.ShowInTaskbar = $false',
|
|
13
|
+
'$owner.Visible = $false',
|
|
14
|
+
'$dialog = New-Object System.Windows.Forms.FolderBrowserDialog',
|
|
15
|
+
"$dialog.Description = '选择本地游戏文件夹'",
|
|
16
|
+
'$dialog.ShowNewFolderButton = $false',
|
|
17
|
+
'$result = $dialog.ShowDialog($owner)',
|
|
18
|
+
"if ($result -eq [System.Windows.Forms.DialogResult]::OK) { [Console]::Out.WriteLine($dialog.SelectedPath) } else { [Console]::Out.WriteLine('__CANCEL__') }",
|
|
19
|
+
].join('\n');
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
function fileScript() {
|
|
23
|
+
return [
|
|
24
|
+
'Add-Type -AssemblyName System.Windows.Forms | Out-Null',
|
|
25
|
+
'$owner = New-Object System.Windows.Forms.Form',
|
|
26
|
+
'$owner.TopMost = $true',
|
|
27
|
+
'$owner.ShowInTaskbar = $false',
|
|
28
|
+
'$owner.Visible = $false',
|
|
29
|
+
'$dialog = New-Object System.Windows.Forms.OpenFileDialog',
|
|
30
|
+
"$dialog.Title = '选择游戏文件'",
|
|
31
|
+
"$dialog.Filter = '游戏与脚本文件|*.exe;*.pck;*.rpa;*.xp3;*.dat;*.rpy;*.ks;*.json;*.csv;*.txt;*.po|所有文件|*.*'",
|
|
32
|
+
'$result = $dialog.ShowDialog($owner)',
|
|
33
|
+
"if ($result -eq [System.Windows.Forms.DialogResult]::OK) { [Console]::Out.WriteLine($dialog.FileName) } else { [Console]::Out.WriteLine('__CANCEL__') }",
|
|
34
|
+
].join('\n');
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
/** 默认执行器:Windows PowerShell(STA + WinForms)。测试可注入 runner。 */
|
|
38
|
+
export function defaultRunner(script, { timeoutMs = 180000 } = {}) {
|
|
39
|
+
return new Promise((resolve) => {
|
|
40
|
+
execFile(
|
|
41
|
+
process.env.DSH_POWERSHELL || 'powershell.exe',
|
|
42
|
+
['-NoProfile', '-STA', '-Command', script],
|
|
43
|
+
{ windowsHide: true, timeout: timeoutMs },
|
|
44
|
+
(error, stdout) => resolve({ error, stdout: String(stdout ?? '') }),
|
|
45
|
+
);
|
|
46
|
+
});
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/**
|
|
50
|
+
* 打开系统原生选择器,返回 { canceled } 或 { path }。
|
|
51
|
+
* 只在 Windows 上可用;其它平台给出明确错误,让作者手填路径。
|
|
52
|
+
*/
|
|
53
|
+
export async function pickPath({ kind = 'folder', timeoutMs = 180000, runner = defaultRunner } = {}) {
|
|
54
|
+
if (process.platform !== 'win32') {
|
|
55
|
+
throw new GameError(ErrorCode.UNSUPPORTED_ENGINE, '当前平台不支持原生选择器,请手动粘贴路径');
|
|
56
|
+
}
|
|
57
|
+
const script = kind === 'file' ? fileScript() : folderScript();
|
|
58
|
+
const { error, stdout } = await runner(script, { timeoutMs });
|
|
59
|
+
if (error?.killed) throw new GameError(ErrorCode.IO_ERROR, '选择器等待超时,请重试或手动粘贴路径');
|
|
60
|
+
|
|
61
|
+
const output = String(stdout || '').trim();
|
|
62
|
+
if (!output || output.includes(CANCEL)) return { kind, canceled: true };
|
|
63
|
+
|
|
64
|
+
const candidate = output.split(/\r?\n/).map((line) => line.trim()).filter(Boolean).pop();
|
|
65
|
+
if (!candidate || !path.isAbsolute(candidate)) {
|
|
66
|
+
throw new GameError(ErrorCode.IO_ERROR, `选择器返回的路径不可用:${candidate ?? '(空)'}`);
|
|
67
|
+
}
|
|
68
|
+
return { kind, canceled: false, path: candidate };
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export { CANCEL };
|
package/lib/remote-contract.js
CHANGED
|
@@ -54,6 +54,8 @@ export const DESCRIPTORS = [
|
|
|
54
54
|
invocation('glossary', [param('options', jsonObjectSchema)]),
|
|
55
55
|
invocation('picks', [param('options', jsonObjectSchema)]),
|
|
56
56
|
invocation('addPick', [param('options', jsonObjectSchema)]),
|
|
57
|
+
invocation('remapPick', [param('options', jsonObjectSchema)]),
|
|
58
|
+
invocation('pickPath', [param('options', jsonObjectSchema)]),
|
|
57
59
|
invocation('export', [param('options', jsonObjectSchema)]),
|
|
58
60
|
invocation('getSettings'),
|
|
59
61
|
invocation('saveSettings', [param('options', jsonObjectSchema)]),
|
package/lib/remote.js
CHANGED
|
@@ -10,6 +10,7 @@ import { DESCRIPTORS } from './remote-contract.js';
|
|
|
10
10
|
import { bindRemoteMethods, runRemoteInitializers } from './typert-bind.js';
|
|
11
11
|
import { GameStore } from './store.mjs';
|
|
12
12
|
import { GameService } from './service.mjs';
|
|
13
|
+
import { pickPath } from './picker.mjs';
|
|
13
14
|
import { REMOTE_INJECT } from './inject.mjs';
|
|
14
15
|
|
|
15
16
|
const fail = (message) => {
|
|
@@ -132,6 +133,14 @@ class GamePanelRemote extends TypertRemoteService {
|
|
|
132
133
|
});
|
|
133
134
|
}
|
|
134
135
|
|
|
136
|
+
async remapPick(id, options = {}) {
|
|
137
|
+
return (await this.service(id)).remapPick(String(options.gameId ?? ''), { pickId: String(options.pickId ?? '') });
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
async pickPath(id, options = {}) {
|
|
141
|
+
return pickPath({ kind: options.kind === 'file' ? 'file' : 'folder' });
|
|
142
|
+
}
|
|
143
|
+
|
|
135
144
|
async export(id, options = {}) {
|
|
136
145
|
const formats = Array.isArray(options.formats) && options.formats.length ? options.formats.map(String) : undefined;
|
|
137
146
|
return (await this.service(id)).export(String(options.gameId ?? ''), { formats });
|
package/lib/store.mjs
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import path from 'node:path';
|
|
2
|
+
import { readFileSync } from 'node:fs';
|
|
2
3
|
import { copyFile, readdir, readFile, rm } from 'node:fs/promises';
|
|
3
4
|
import { pluginRoot } from './core/paths.mjs';
|
|
4
5
|
import { GameError, ErrorCode } from './core/errors.mjs';
|
|
@@ -13,7 +14,14 @@ import {
|
|
|
13
14
|
import { shardKey } from './core/ids.mjs';
|
|
14
15
|
|
|
15
16
|
const SCHEMA_VERSION = 1;
|
|
16
|
-
|
|
17
|
+
// 版本从 package.json 读,避免代码里的常量与发布版本不一致。
|
|
18
|
+
const TOOL_VERSION = (() => {
|
|
19
|
+
try {
|
|
20
|
+
return JSON.parse(readFileSync(new URL('../package.json', import.meta.url), 'utf8')).version ?? '0.0.0';
|
|
21
|
+
} catch {
|
|
22
|
+
return '0.0.0';
|
|
23
|
+
}
|
|
24
|
+
})();
|
|
17
25
|
|
|
18
26
|
/**
|
|
19
27
|
* .dsh-novel-game/ 的唯一读写入口。
|