cortico-world-fun 0.1.0 → 0.1.1
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 +26 -0
- package/PUBLISHING.md +7 -5
- package/README.md +12 -0
- package/dist/webui.js +356 -0
- package/package.json +5 -4
- package/src/config.js +39 -0
- package/src/world.js +175 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,32 @@
|
|
|
2
2
|
|
|
3
3
|
市场按 `##` 标题里的版本号切段,显示在「历史版本」里。
|
|
4
4
|
|
|
5
|
+
## 0.1.1
|
|
6
|
+
|
|
7
|
+
**加了面板页**(0.1.0 只有世界卡片和配置页,点进去是空的)。
|
|
8
|
+
|
|
9
|
+
**「去哪儿」面板**:十二处地方这时候开没开、人多不多,一次看全。
|
|
10
|
+
|
|
11
|
+
- 开着的排前面、关着的单独一组,卡片左边一条色标(绿=开着、橙=快关了);点一张卡展开详情:能逛的项目、纪念品、拍照点、开放时段。
|
|
12
|
+
- 顶部一条**正在逛的那一趟**:几点进的、待了多久、逛了哪几处、买了什么、拍了哪些照、最近三条小事件。没在逛时显示「这会儿没在逛」和当前时间。
|
|
13
|
+
- 搜索按地方名、别名、标签都能筛(「同人展」「室内」「夜」)。
|
|
14
|
+
- **详情里会明说生图该填什么**:素材库里有的四处写「`scene` 填「漫展」」;另外八处写「`scene` 不用填」——不替她编库里没有的名字。
|
|
15
|
+
|
|
16
|
+
**「纪念册」面板**:去过的每一趟。
|
|
17
|
+
|
|
18
|
+
- 顶部四个数:多少趟、逛过多少处、买了多少件纪念品、拍了多少张照。
|
|
19
|
+
- 「常去的」按次数排出她最爱去的地方。
|
|
20
|
+
- 每一趟写:哪天、几点到几点、待了多久、逛了哪些、买了什么、生图用的 scene 和 outfits。
|
|
21
|
+
|
|
22
|
+
面板只读:打开面板不改动出游状态,有测试钉住这一点。状态会随时间变(几点、开没开),面板每分钟自己刷一次。
|
|
23
|
+
|
|
24
|
+
**其它**
|
|
25
|
+
|
|
26
|
+
- `describe.json` 已重新生成(加面板不影响工具,仍是 6 个工具、0 个事件)。
|
|
27
|
+
- 测试从 47 项加到 **59 项**(新增 `test/panels.test.mjs` 12 项,用 DOM 桩把两个面板真挂一遍:
|
|
28
|
+
面板 id 与服务端声明对得上、十二处都画出来、点卡展开/收起、搜索能筛、失败出错误卡、只读不写盘)。
|
|
29
|
+
- 包体:`dist/webui.js` 进包,`files` 白名单加了 `dist`。
|
|
30
|
+
|
|
5
31
|
## 0.1.0
|
|
6
32
|
|
|
7
33
|
首个版本。
|
package/PUBLISHING.md
CHANGED
|
@@ -27,8 +27,8 @@ node tools/publish-check.mjs --online # 市场收录口径 + npm 包名占用
|
|
|
27
27
|
|
|
28
28
|
`prepublishOnly` 已经把上面这一串(除 `--online` 外)都串起来了,`npm publish` 之前自动跑一遍,任何一处失败就发不出去。
|
|
29
29
|
|
|
30
|
-
当前状态(0.1.
|
|
31
|
-
(venues 10 · state 13 · world 24);打包 **
|
|
30
|
+
当前状态(0.1.1):**25 项通过、0 失败、1 警告**(没截 `screenshots`);**59 个单测全绿**
|
|
31
|
+
(venues 10 · state 13 · world 24 · panels 12);打包 **14 个文件**,解包 190KB。
|
|
32
32
|
|
|
33
33
|
---
|
|
34
34
|
|
|
@@ -77,15 +77,17 @@ npm config get registry # 应是 https://registry.npmjs.org/
|
|
|
77
77
|
npm pack --dry-run
|
|
78
78
|
```
|
|
79
79
|
|
|
80
|
-
0.1.
|
|
80
|
+
0.1.1 应该是 **14 个文件**、解包约 190KB:
|
|
81
81
|
|
|
82
82
|
```
|
|
83
83
|
package.json README.md CHANGELOG.md PUBLISHING.md describe.json
|
|
84
84
|
assets/icon.png
|
|
85
|
+
dist/webui.js # 面板(去哪儿 / 纪念册)
|
|
85
86
|
src/index.js src/definition.js src/config.js src/venues.js src/state.js src/world.js src/ENV_PROMPT.md
|
|
86
87
|
```
|
|
87
88
|
|
|
88
89
|
`test/`、`tools/`、`install.ps1` 都在 `files` 之外,不会发出去——测试、图标生成器、装机脚本是我们的工具,不是用户要的东西。
|
|
90
|
+
`dist/` 必须在 `files` 里:`cortico.webUiClient` 声明了它,漏了的话装到 Coo 里点面板是一片空白(`publish-check` 会拦)。
|
|
89
91
|
|
|
90
92
|
---
|
|
91
93
|
|
|
@@ -133,8 +135,8 @@ Action 平时每 30 分钟扫一次,GitHub 定时任务常推迟。想立刻
|
|
|
133
135
|
4. `package.json` 的 `cortico` 块里加 `"screenshots": ["assets/screenshot-1.png"]`
|
|
134
136
|
5. 截图改了就必须**发新版本**——市场按版本扫包
|
|
135
137
|
|
|
136
|
-
>
|
|
137
|
-
>
|
|
138
|
+
> 0.1.1 起**有面板页了**(`dist/webui.js`,两张:去哪儿 / 纪念册),所以现在能截:
|
|
139
|
+
> Coo 世界页的「娱乐时间」卡片、**「去哪儿」面板**(十二处 + 正在逛那条)、**「纪念册」面板**、配置页。
|
|
138
140
|
|
|
139
141
|
---
|
|
140
142
|
|
package/README.md
CHANGED
|
@@ -43,6 +43,18 @@ powershell -ExecutionPolicy Bypass -File .\install.ps1 -CooRoot "E:\Coopanion"
|
|
|
43
43
|
|
|
44
44
|
她**自己在同一回合里**把这些串起来,不是代码替她填参数。**没装生图工作室也照常能逛**——只是少了发图那一句。
|
|
45
45
|
|
|
46
|
+
## 面板
|
|
47
|
+
|
|
48
|
+
装好启用在 Coo 的世界页签里能看到两张面板(0.1.1 起):
|
|
49
|
+
|
|
50
|
+
- **去哪儿** —— 十二处地方这时候开没开、人多不多,一次看全。开着的排前面;点一张卡展开详情(能逛的项目、纪念品、拍照点、开放时段),详情里会明说生图该填什么 `scene`。顶部一条是**她正在逛的那一趟**:几点进的、待了多久、逛了哪几处、买了什么、拍了哪些照。搜索按地方名、别名、标签都能筛。
|
|
51
|
+
- **纪念册** —— 去过的每一趟:哪天、几点到几点、逛了哪些、买了什么、生图用的 `scene` / `outfits`。顶部四个数(多少趟、逛过多少处、多少件纪念品、多少张照)和「常去的」排行。
|
|
52
|
+
|
|
53
|
+
面板**只读**:打开面板不改动出游状态(有测试钉住)。状态会随时间变(几点、开没开),面板每分钟自己刷一次。
|
|
54
|
+
|
|
55
|
+
面板只提供「看」,不提供「点一下让她去这儿」——进门/逛/收摊是**她自己**的动作,
|
|
56
|
+
替她按下去就等于代码替她做决定,那和这个插件的立意相反(见下面「刻意没做的」)。
|
|
57
|
+
|
|
46
58
|
## 配置(`worlds.fun`,只有 3 项)
|
|
47
59
|
|
|
48
60
|
| 键 | 默认 | 管什么 |
|
package/dist/webui.js
ADDED
|
@@ -0,0 +1,356 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* 娱乐时间面板的浏览器端(Coo WebUI 扩展面板)。
|
|
3
|
+
*
|
|
4
|
+
* 约定(照 feed-world 的做法,见宿主 client-panel):
|
|
5
|
+
* · 默认导出 `{ panels: { <panelId>: { mount(ctx) } } }`
|
|
6
|
+
* · 只往 `ctx.root` 里写 DOM,不碰 document.body
|
|
7
|
+
* · 数据一律走 `ctx.invoke(method, args)`,**不读私有状态、不算时间**
|
|
8
|
+
* · 定时器只用 `ctx.interval` / `ctx.timeout`(宿主会在面板关掉时 dispose)
|
|
9
|
+
*
|
|
10
|
+
* 样式:注入一个 <style> 到 ctx.root 里。宿主可能是普通 DOM 也可能是 shadow root,
|
|
11
|
+
* 光靠外部 css 在 shadow root 里吃不到;注入 <style> 两边都成立。
|
|
12
|
+
* 颜色走宿主主题的自定义属性(--surface/--foreground/--border/--accent…),
|
|
13
|
+
* 自定义属性会继承进 shadow root,所以明暗两套主题都不用自己写。
|
|
14
|
+
*
|
|
15
|
+
* 两个面板:
|
|
16
|
+
* places —— 十二处地方此刻的状态,以及她正在逛的这一趟
|
|
17
|
+
* book —— 纪念册:去过的每一趟
|
|
18
|
+
*/
|
|
19
|
+
|
|
20
|
+
const CSS = `
|
|
21
|
+
.fun{--f-line:var(--border,#e3e4e3);--f-ink:var(--foreground,#1b1a1e);--f-dim:var(--muted-foreground,#5c5c60);--f-card:var(--surface,#fbfbfb);--f-soft:color-mix(in srgb,var(--surface,#fbfbfb) 92%,var(--foreground,#1b1a1e));--f-accent:var(--accent,#00a870);--f-warm:#e0862f;--f-mint:#00a870;font:13px/1.6 var(--sans,-apple-system,"Segoe UI","PingFang SC","Microsoft YaHei",sans-serif);color:var(--f-ink);padding:4px 2px 24px}
|
|
22
|
+
.fun *{box-sizing:border-box}
|
|
23
|
+
.fun-bar{display:flex;gap:8px;flex-wrap:wrap;align-items:center;margin-bottom:10px}
|
|
24
|
+
.fun input,.fun select,.fun button{font:inherit;color:inherit;background:var(--f-card);border:1px solid var(--f-line);border-radius:var(--radius-sm,6px);padding:5px 9px;outline:none}
|
|
25
|
+
.fun input:focus,.fun select:focus{border-color:var(--f-accent)}
|
|
26
|
+
.fun-search{flex:1;min-width:140px}
|
|
27
|
+
.fun button{cursor:pointer;transition:background .12s,border-color .12s}
|
|
28
|
+
.fun button:hover{border-color:var(--f-accent)}
|
|
29
|
+
.fun-btn-primary{background:var(--f-accent);border-color:var(--f-accent);color:#fff;font-weight:600}
|
|
30
|
+
.fun-btn-primary:hover{filter:brightness(1.06)}
|
|
31
|
+
.fun-btn-primary[disabled]{opacity:.55;cursor:default;filter:none}
|
|
32
|
+
.fun-dim{color:var(--f-dim)}
|
|
33
|
+
.fun-sec{font-weight:600;margin:14px 0 7px;font-size:12px;letter-spacing:.04em;color:var(--f-dim);text-transform:none}
|
|
34
|
+
.fun-sec:first-child{margin-top:2px}
|
|
35
|
+
|
|
36
|
+
/* 正在逛的那一趟 */
|
|
37
|
+
.fun-live{border:1px solid var(--f-line);border-left:3px solid var(--f-accent);border-radius:var(--radius-sm,6px);padding:9px 12px;margin-bottom:12px;background:var(--f-card)}
|
|
38
|
+
.fun-live-idle{border-left-color:var(--f-line)}
|
|
39
|
+
.fun-live h3{margin:0 0 3px;font-size:14px;font-weight:600}
|
|
40
|
+
.fun-live .fun-meta{font-size:12px;color:var(--f-dim);margin-bottom:6px}
|
|
41
|
+
.fun-chips{display:flex;gap:6px;flex-wrap:wrap;margin-top:6px}
|
|
42
|
+
.fun-chip{font-size:12px;padding:2px 8px;border-radius:999px;border:1px solid var(--f-line);background:var(--f-soft);color:var(--f-dim)}
|
|
43
|
+
.fun-chip-on{color:var(--f-ink);border-color:var(--f-accent);background:color-mix(in srgb,var(--f-accent) 14%,transparent)}
|
|
44
|
+
.fun-stale{color:var(--f-warm)}
|
|
45
|
+
|
|
46
|
+
/* 场所卡 */
|
|
47
|
+
.fun-grid{display:grid;grid-template-columns:repeat(auto-fill,minmax(232px,1fr));gap:9px}
|
|
48
|
+
.fun-card{border:1px solid var(--f-line);border-radius:var(--radius-sm,6px);padding:9px 11px;background:var(--f-card);cursor:pointer;transition:border-color .12s}
|
|
49
|
+
.fun-card:hover{border-color:var(--f-accent)}
|
|
50
|
+
.fun-card-closed{opacity:.62}
|
|
51
|
+
.fun-card-open{border-left:3px solid var(--f-mint)}
|
|
52
|
+
.fun-card-soon{border-left:3px solid var(--f-warm)}
|
|
53
|
+
.fun-card-head{display:flex;justify-content:space-between;gap:8px;align-items:baseline}
|
|
54
|
+
.fun-card-name{font-weight:600;font-size:13.5px}
|
|
55
|
+
.fun-card-state{font-size:11.5px;color:var(--f-dim);white-space:nowrap}
|
|
56
|
+
.fun-card-state-open{color:var(--f-mint)}
|
|
57
|
+
.fun-card-state-soon{color:var(--f-warm)}
|
|
58
|
+
.fun-card-desc{font-size:12px;color:var(--f-dim);margin-top:4px;display:-webkit-box;-webkit-line-clamp:3;-webkit-box-orient:vertical;overflow:hidden}
|
|
59
|
+
.fun-card-foot{display:flex;gap:6px;flex-wrap:wrap;margin-top:7px;font-size:11.5px;color:var(--f-dim)}
|
|
60
|
+
|
|
61
|
+
/* 详情展开 */
|
|
62
|
+
.fun-detail{border:1px solid var(--f-accent);border-radius:var(--radius-sm,6px);padding:11px 13px;margin-top:9px;background:var(--f-card)}
|
|
63
|
+
.fun-detail h4{margin:0 0 6px;font-size:14px}
|
|
64
|
+
.fun-detail p{margin:0 0 7px;font-size:12.5px}
|
|
65
|
+
.fun-list{margin:5px 0 0;padding-left:17px;font-size:12.5px}
|
|
66
|
+
.fun-list li{margin:2px 0}
|
|
67
|
+
.fun-scene{font-size:12px;padding:5px 9px;border-radius:var(--radius-sm,6px);background:var(--f-soft);border:1px solid var(--f-line);margin-top:8px}
|
|
68
|
+
.fun-scene b{font-weight:600}
|
|
69
|
+
|
|
70
|
+
/* 纪念册 */
|
|
71
|
+
.fun-trip{border:1px solid var(--f-line);border-radius:var(--radius-sm,6px);padding:9px 12px;margin-bottom:8px;background:var(--f-card)}
|
|
72
|
+
.fun-trip-head{display:flex;justify-content:space-between;gap:10px;align-items:baseline}
|
|
73
|
+
.fun-trip-name{font-weight:600}
|
|
74
|
+
.fun-trip-when{font-size:11.5px;color:var(--f-dim);white-space:nowrap}
|
|
75
|
+
.fun-trip-sum{margin-top:3px;font-size:12.5px}
|
|
76
|
+
.fun-trip-extras{margin-top:5px;font-size:12px;color:var(--f-dim)}
|
|
77
|
+
.fun-stats{display:flex;gap:16px;flex-wrap:wrap;margin-bottom:12px;padding:9px 12px;border:1px solid var(--f-line);border-radius:var(--radius-sm,6px);background:var(--f-card)}
|
|
78
|
+
.fun-stat b{display:block;font-size:17px;font-weight:600;line-height:1.25}
|
|
79
|
+
.fun-stat span{font-size:11.5px;color:var(--f-dim)}
|
|
80
|
+
.fun-empty{padding:22px 12px;text-align:center;color:var(--f-dim);font-size:12.5px}
|
|
81
|
+
.fun-err{border:1px solid #d9534f;border-radius:var(--radius-sm,6px);padding:10px 12px;color:#d9534f;background:color-mix(in srgb,#d9534f 10%,transparent);font-size:12.5px}
|
|
82
|
+
`;
|
|
83
|
+
|
|
84
|
+
/** 小工具:建元素 + 设属性,省掉一屏 createElement。 */
|
|
85
|
+
function el(tag, props, ...kids) {
|
|
86
|
+
const n = document.createElement(tag);
|
|
87
|
+
if (props) {
|
|
88
|
+
for (const [k, v] of Object.entries(props)) {
|
|
89
|
+
if (v === null || v === undefined || v === false) continue;
|
|
90
|
+
if (k === 'class') n.className = v;
|
|
91
|
+
else if (k === 'text') n.textContent = v;
|
|
92
|
+
else if (k === 'html') n.innerHTML = v;
|
|
93
|
+
else if (k.startsWith('on') && typeof v === 'function') n.addEventListener(k.slice(2), v);
|
|
94
|
+
else if (k === 'style') Object.assign(n.style, v);
|
|
95
|
+
else n.setAttribute(k, v);
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
for (const kid of kids.flat()) {
|
|
99
|
+
if (kid === null || kid === undefined || kid === false) continue;
|
|
100
|
+
n.appendChild(typeof kid === 'string' || typeof kid === 'number'
|
|
101
|
+
? document.createTextNode(String(kid)) : kid);
|
|
102
|
+
}
|
|
103
|
+
return n;
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
/** 只注入一次样式(同一 root 反复 mount 时别叠 <style>)。 */
|
|
107
|
+
function ensureStyle(root) {
|
|
108
|
+
if (root.querySelector('style.fun-style')) return;
|
|
109
|
+
root.appendChild(el('style', { class: 'fun-style', text: CSS }));
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** 顶层容器。 */
|
|
113
|
+
function shell(root) {
|
|
114
|
+
ensureStyle(root);
|
|
115
|
+
const box = el('div', { class: 'fun' });
|
|
116
|
+
root.appendChild(box);
|
|
117
|
+
return box;
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
function errorCard(err) {
|
|
121
|
+
return el('div', { class: 'fun-err', text: `面板加载失败:${err?.message ?? String(err)}` });
|
|
122
|
+
}
|
|
123
|
+
|
|
124
|
+
// ---------------------------------------------------------------------------
|
|
125
|
+
// places —— 去哪儿
|
|
126
|
+
// ---------------------------------------------------------------------------
|
|
127
|
+
|
|
128
|
+
function mountPlaces(ctx) {
|
|
129
|
+
const root = ctx.root;
|
|
130
|
+
root.replaceChildren();
|
|
131
|
+
const box = shell(root);
|
|
132
|
+
const body = el('div');
|
|
133
|
+
box.appendChild(body);
|
|
134
|
+
|
|
135
|
+
let keyword = '';
|
|
136
|
+
let expanded = null;
|
|
137
|
+
|
|
138
|
+
const render = (data) => {
|
|
139
|
+
body.replaceChildren();
|
|
140
|
+
|
|
141
|
+
// ---- 正在逛的那一趟 ----
|
|
142
|
+
if (data.session) {
|
|
143
|
+
const s = data.session;
|
|
144
|
+
const venue = data.places.find((p) => p.id === s.placeId);
|
|
145
|
+
const leftAreas = venue
|
|
146
|
+
? venue.areas.filter((a) => !s.visited.some((v) => v.area === a))
|
|
147
|
+
: [];
|
|
148
|
+
const leftText = leftAreas.length ? `还能逛:${leftAreas.slice(0, 5).join('、')}` : '都逛过了';
|
|
149
|
+
const progress = s.venueAreaCount ? `${s.visited.length}/${s.venueAreaCount}` : String(s.visited.length);
|
|
150
|
+
body.appendChild(el('div', { class: 'fun-live' },
|
|
151
|
+
el('h3', { text: `正在${s.placeName}逛` }),
|
|
152
|
+
el('div', { class: 'fun-meta' },
|
|
153
|
+
`${s.enteredHm} 进门 · 待了 ${s.stayedMin} 分钟 · 逛了 ${progress} 处`,
|
|
154
|
+
s.stale ? el('span', { class: 'fun-stale', text: ' · 这一趟挂得有点久了' }) : null),
|
|
155
|
+
el('div', { class: 'fun-meta', text: `逛过:${s.visited.length ? s.visited.map((v) => v.area).join('、') : '还没逛到哪儿'}` }),
|
|
156
|
+
s.souvenirs.length ? el('div', { class: 'fun-chips' }, s.souvenirs.map((x) => el('span', { class: 'fun-chip fun-chip-on', text: `买了 ${x}` }))) : null,
|
|
157
|
+
s.photos.length ? el('div', { class: 'fun-chips' }, s.photos.map((x) => el('span', { class: 'fun-chip', text: `📷 ${x}` }))) : null,
|
|
158
|
+
s.events.length ? el('ul', { class: 'fun-list' }, s.events.slice(-3).map((e) => el('li', { text: e }))) : null,
|
|
159
|
+
venue ? el('div', { class: 'fun-meta', text: leftText }) : null,
|
|
160
|
+
));
|
|
161
|
+
} else {
|
|
162
|
+
body.appendChild(el('div', { class: 'fun-live fun-live-idle' },
|
|
163
|
+
el('h3', { text: '这会儿没在逛' }),
|
|
164
|
+
el('div', { class: 'fun-meta', text: `现在 ${data.nowHm} · ${data.total} 处地方里 ${data.openCount} 处开着` }),
|
|
165
|
+
el('div', { class: 'fun-meta fun-dim', text: '她会自己挑一处进去;你在下面点一张卡也能看细节。' }),
|
|
166
|
+
));
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
// ---- 搜索条 ----
|
|
170
|
+
const input = el('input', {
|
|
171
|
+
class: 'fun-search',
|
|
172
|
+
type: 'search',
|
|
173
|
+
placeholder: '搜地方名、别名或标签(庙会 / 室内 / 夜…)',
|
|
174
|
+
value: keyword,
|
|
175
|
+
});
|
|
176
|
+
input.addEventListener('input', () => {
|
|
177
|
+
keyword = input.value;
|
|
178
|
+
// 只重画列表,不重画搜索框——否则每敲一个字就丢焦点(feast 踩过这条)。
|
|
179
|
+
renderList();
|
|
180
|
+
});
|
|
181
|
+
body.appendChild(el('div', { class: 'fun-bar' }, input));
|
|
182
|
+
|
|
183
|
+
const listBox = el('div');
|
|
184
|
+
body.appendChild(listBox);
|
|
185
|
+
|
|
186
|
+
function renderList() {
|
|
187
|
+
listBox.replaceChildren();
|
|
188
|
+
const kw = keyword.trim().toLowerCase();
|
|
189
|
+
const matched = kw
|
|
190
|
+
? data.places.filter((p) => p.name.toLowerCase().includes(kw)
|
|
191
|
+
|| p.aliases.some((a) => a.toLowerCase().includes(kw))
|
|
192
|
+
|| p.tags.some((t) => t.toLowerCase().includes(kw)))
|
|
193
|
+
: data.places;
|
|
194
|
+
|
|
195
|
+
const open = matched.filter((p) => p.state !== 'closed');
|
|
196
|
+
const closed = matched.filter((p) => p.state === 'closed');
|
|
197
|
+
|
|
198
|
+
const section = (title, items) => {
|
|
199
|
+
if (!items.length) return;
|
|
200
|
+
listBox.appendChild(el('div', { class: 'fun-sec', text: title }));
|
|
201
|
+
listBox.appendChild(el('div', { class: 'fun-grid' }, items.map(card)));
|
|
202
|
+
};
|
|
203
|
+
section(kw ? `匹配到 ${matched.length} 处` : `开着的(${open.length})`, open);
|
|
204
|
+
section('已经关了', closed);
|
|
205
|
+
if (!matched.length) {
|
|
206
|
+
listBox.appendChild(el('div', { class: 'fun-empty', text: `没有匹配「${keyword}」的地方。` }));
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
// 展开的详情画在列表后面
|
|
210
|
+
if (expanded) {
|
|
211
|
+
const p = data.places.find((x) => x.id === expanded);
|
|
212
|
+
if (p) listBox.appendChild(detail(p));
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const card = (p) => {
|
|
217
|
+
const cls = ['fun-card'];
|
|
218
|
+
if (p.state === 'closed') cls.push('fun-card-closed');
|
|
219
|
+
else if (p.state === 'closingSoon') cls.push('fun-card-soon');
|
|
220
|
+
else cls.push('fun-card-open');
|
|
221
|
+
const stateCls = p.state === 'open' ? 'fun-card-state-open'
|
|
222
|
+
: (p.state === 'closingSoon' ? 'fun-card-state-soon' : '');
|
|
223
|
+
const node = el('div', {
|
|
224
|
+
class: cls.join(' '),
|
|
225
|
+
onclick: () => { expanded = expanded === p.id ? null : p.id; renderList(); },
|
|
226
|
+
},
|
|
227
|
+
el('div', { class: 'fun-card-head' },
|
|
228
|
+
el('span', { class: 'fun-card-name', text: p.name }),
|
|
229
|
+
el('span', { class: `fun-card-state ${stateCls}`, text: p.stateLabel })),
|
|
230
|
+
el('div', { class: 'fun-card-desc', text: p.desc }),
|
|
231
|
+
el('div', { class: 'fun-card-foot' },
|
|
232
|
+
el('span', { text: `${p.hours.open}–${p.hours.close}` }),
|
|
233
|
+
el('span', { text: p.crowdLabel }),
|
|
234
|
+
el('span', { text: `${p.areaCount} 处可逛` }),
|
|
235
|
+
p.recent ? el('span', { class: 'fun-chip', text: '刚去过' }) : null));
|
|
236
|
+
return node;
|
|
237
|
+
};
|
|
238
|
+
|
|
239
|
+
const detail = (p) => {
|
|
240
|
+
const d = el('div', { class: 'fun-detail' },
|
|
241
|
+
el('h4', { text: p.name }),
|
|
242
|
+
el('p', { class: 'fun-dim', text: `${p.kindLabel} · ${p.crowdLabel} · ${p.hours.open}–${p.hours.close} · ${p.stateLabel}` }),
|
|
243
|
+
el('div', { class: 'fun-sec', text: '能逛的' }),
|
|
244
|
+
el('ul', { class: 'fun-list' }, p.areas.map((a) => el('li', { text: a }))),
|
|
245
|
+
el('div', { class: 'fun-sec', text: '纪念品' }),
|
|
246
|
+
el('div', { class: 'fun-chips' }, p.souvenirs.map((s) => el('span', { class: 'fun-chip', text: s }))),
|
|
247
|
+
el('div', { class: 'fun-sec', text: '拍照点' }),
|
|
248
|
+
el('div', { class: 'fun-chips' }, p.photoSpots.map((s) => el('span', { class: 'fun-chip', text: s }))),
|
|
249
|
+
el('div', { class: 'fun-scene' },
|
|
250
|
+
p.hasScene
|
|
251
|
+
? el('span', {}, '生图时 ', el('b', { text: `scene 填「${p.scene}」` }), `,outfits 建议「${p.outfit}」`)
|
|
252
|
+
: el('span', {}, '素材库里没有这处的场景,生图时 ', el('b', { text: 'scene 不用填' }), ',把地方写进 prompt 就行')));
|
|
253
|
+
|
|
254
|
+
// ---- 本地小工具:拆掉它自己的 onclick 监听没意义,直接按 id 查 ----
|
|
255
|
+
return d;
|
|
256
|
+
};
|
|
257
|
+
|
|
258
|
+
renderList();
|
|
259
|
+
};
|
|
260
|
+
|
|
261
|
+
const load = async () => {
|
|
262
|
+
try {
|
|
263
|
+
const data = await ctx.invoke('list');
|
|
264
|
+
if (!data?.ok) throw new Error(data?.error ?? '返回不正常');
|
|
265
|
+
render(data);
|
|
266
|
+
} catch (err) {
|
|
267
|
+
root.replaceChildren();
|
|
268
|
+
ensureStyle(root);
|
|
269
|
+
const box2 = shell(root);
|
|
270
|
+
box2.appendChild(errorCard(err));
|
|
271
|
+
}
|
|
272
|
+
};
|
|
273
|
+
|
|
274
|
+
void load();
|
|
275
|
+
// 状态会随时间变(几点、开没开):一分钟刷一次就够,不打断操作。
|
|
276
|
+
ctx.interval(() => { void load(); }, 60000);
|
|
277
|
+
return { refresh: load };
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
// ---------------------------------------------------------------------------
|
|
281
|
+
// book —— 纪念册
|
|
282
|
+
// ---------------------------------------------------------------------------
|
|
283
|
+
|
|
284
|
+
function mountBook(ctx) {
|
|
285
|
+
const root = ctx.root;
|
|
286
|
+
root.replaceChildren();
|
|
287
|
+
const box = shell(root);
|
|
288
|
+
const body = el('div');
|
|
289
|
+
box.appendChild(body);
|
|
290
|
+
|
|
291
|
+
const render = (data) => {
|
|
292
|
+
body.replaceChildren();
|
|
293
|
+
if (!data.total && !data.session) {
|
|
294
|
+
body.appendChild(el('div', { class: 'fun-empty', text: '纪念册还是空的——她收一次摊,这里就有一趟。' }));
|
|
295
|
+
return;
|
|
296
|
+
}
|
|
297
|
+
|
|
298
|
+
body.appendChild(el('div', { class: 'fun-stats' },
|
|
299
|
+
stat(data.total, '趟'),
|
|
300
|
+
stat(data.visitedAreaCount, '处逛过'),
|
|
301
|
+
stat(data.souvenirCount, '件纪念品'),
|
|
302
|
+
stat(data.photoCount, '张照片')));
|
|
303
|
+
|
|
304
|
+
if (data.mostVisited.length) {
|
|
305
|
+
body.appendChild(el('div', { class: 'fun-sec', text: '常去的' }));
|
|
306
|
+
body.appendChild(el('div', { class: 'fun-chips' },
|
|
307
|
+
data.mostVisited.slice(0, 8).map((m) => el('span', { class: 'fun-chip', text: `${m.name} ×${m.times}` }))));
|
|
308
|
+
}
|
|
309
|
+
|
|
310
|
+
if (data.session) {
|
|
311
|
+
body.appendChild(el('div', { class: 'fun-sec', text: '正在逛' }));
|
|
312
|
+
body.appendChild(el('div', { class: 'fun-trip' },
|
|
313
|
+
el('div', { class: 'fun-trip-sum', text: data.session.summary })));
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
body.appendChild(el('div', { class: 'fun-sec', text: `去过的 ${data.total} 趟` }));
|
|
317
|
+
for (const t of data.trips) {
|
|
318
|
+
body.appendChild(el('div', { class: 'fun-trip' },
|
|
319
|
+
el('div', { class: 'fun-trip-head' },
|
|
320
|
+
el('span', { class: 'fun-trip-name', text: t.placeName }),
|
|
321
|
+
el('span', { class: 'fun-trip-when', text: `${t.day} ${t.enteredHm}–${t.leftHm}${t.stayedMin ? ` · ${t.stayedMin} 分钟` : ''}` })),
|
|
322
|
+
el('div', { class: 'fun-trip-sum', text: t.summary }),
|
|
323
|
+
(t.events.length || t.scene)
|
|
324
|
+
? el('div', { class: 'fun-trip-extras' },
|
|
325
|
+
t.events.length ? el('div', { text: t.events.slice(0, 2).join(' / ') }) : null,
|
|
326
|
+
t.scene ? el('div', { text: `生图 scene:${t.scene}${t.outfit ? ` · outfits:${t.outfit}` : ''}` }) : null)
|
|
327
|
+
: null));
|
|
328
|
+
}
|
|
329
|
+
};
|
|
330
|
+
|
|
331
|
+
const stat = (n, label) => el('div', { class: 'fun-stat' },
|
|
332
|
+
el('b', { text: String(n) }), el('span', { text: label }));
|
|
333
|
+
|
|
334
|
+
const load = async () => {
|
|
335
|
+
try {
|
|
336
|
+
const data = await ctx.invoke('list');
|
|
337
|
+
if (!data?.ok) throw new Error(data?.error ?? '返回不正常');
|
|
338
|
+
render(data);
|
|
339
|
+
} catch (err) {
|
|
340
|
+
root.replaceChildren();
|
|
341
|
+
ensureStyle(root);
|
|
342
|
+
const box2 = shell(root);
|
|
343
|
+
box2.appendChild(errorCard(err));
|
|
344
|
+
}
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
void load();
|
|
348
|
+
return { refresh: load };
|
|
349
|
+
}
|
|
350
|
+
|
|
351
|
+
export default {
|
|
352
|
+
panels: {
|
|
353
|
+
places: { mount: mountPlaces },
|
|
354
|
+
book: { mount: mountBook },
|
|
355
|
+
},
|
|
356
|
+
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "cortico-world-fun",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.1",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "娱乐时间 —— 给 Coopanion 桌宠十二处真能去逛的地方:游乐场、海洋馆、庙会、漫展、电影院、动物园、公园、电玩城、KTV、博物馆、猫咖、爬山。进门、逛摊位、买纪念品、拍张照、收摊记一笔。",
|
|
6
6
|
"license": "MIT",
|
|
@@ -17,13 +17,13 @@
|
|
|
17
17
|
"engines": { "node": ">=22" },
|
|
18
18
|
"main": "./src/index.js",
|
|
19
19
|
"exports": { ".": "./src/index.js" },
|
|
20
|
-
"files": ["src", "assets", "describe.json", "CHANGELOG.md", "README.md", "PUBLISHING.md"],
|
|
20
|
+
"files": ["src", "dist", "assets", "describe.json", "CHANGELOG.md", "README.md", "PUBLISHING.md"],
|
|
21
21
|
"scripts": {
|
|
22
|
-
"test": "node test/venues.test.mjs && node test/state.test.mjs && node test/world.test.mjs",
|
|
22
|
+
"test": "node test/venues.test.mjs && node test/state.test.mjs && node test/world.test.mjs && node test/panels.test.mjs",
|
|
23
23
|
"verify": "node tools/fix-ps1-bom.mjs install.ps1 && node tools/check-prompt.mjs && node tools/smoke.mjs && node tools/make-describe.mjs --check",
|
|
24
24
|
"describe": "node tools/make-describe.mjs",
|
|
25
25
|
"check:publish": "node tools/publish-check.mjs --online",
|
|
26
|
-
"prepublishOnly": "node test/venues.test.mjs && node test/state.test.mjs && node test/world.test.mjs && node tools/check-prompt.mjs && node tools/smoke.mjs && node tools/make-describe.mjs --check && node tools/publish-check.mjs --online"
|
|
26
|
+
"prepublishOnly": "node test/venues.test.mjs && node test/state.test.mjs && node test/world.test.mjs && node test/panels.test.mjs && node tools/check-prompt.mjs && node tools/smoke.mjs && node tools/make-describe.mjs --check && node tools/publish-check.mjs --online"
|
|
27
27
|
},
|
|
28
28
|
"cortico": {
|
|
29
29
|
"kind": "world",
|
|
@@ -31,6 +31,7 @@
|
|
|
31
31
|
"displayName": "娱乐时间",
|
|
32
32
|
"icon": "assets/icon.png",
|
|
33
33
|
"describe": "describe.json",
|
|
34
|
+
"webUiClient": "dist/webui.js",
|
|
34
35
|
"tags": ["companion"],
|
|
35
36
|
"locales": {
|
|
36
37
|
"zh": {
|
package/src/config.js
CHANGED
|
@@ -43,6 +43,10 @@ const ZH = {
|
|
|
43
43
|
funAskReport: '收摊说一声',
|
|
44
44
|
funAskReportDesc: '开启时,收摊回执会提醒她把「今天逛了什么」用 feast_life_play 记进自己的日程,再跟主人说一句。关掉就只给这段文字,不提记账。',
|
|
45
45
|
},
|
|
46
|
+
storage: {
|
|
47
|
+
label: '出游记录',
|
|
48
|
+
note: '清掉之后,正在进行的那一趟和纪念册里的所有趟都会没(逛过哪些地方、买了什么、在哪儿拍过照)。场所库是内置的,不受影响;别的东西一概不动。',
|
|
49
|
+
},
|
|
46
50
|
};
|
|
47
51
|
|
|
48
52
|
const EN = {
|
|
@@ -61,12 +65,47 @@ const EN = {
|
|
|
61
65
|
funAskReport: 'Say something at the end',
|
|
62
66
|
funAskReportDesc: 'When on, the closing receipt reminds her to log the trip with feast_life_play and tell the owner one sentence.',
|
|
63
67
|
},
|
|
68
|
+
storage: {
|
|
69
|
+
label: 'Outing records',
|
|
70
|
+
note: 'Clearing this erases the trip in progress and every trip in the book (where she went, what she bought, where she took photos). The venue list is built in and unaffected; nothing else is touched.',
|
|
71
|
+
},
|
|
64
72
|
};
|
|
65
73
|
|
|
66
74
|
export function text(language = 'zh') {
|
|
67
75
|
return language === 'en' ? EN : ZH;
|
|
68
76
|
}
|
|
69
77
|
|
|
78
|
+
/**
|
|
79
|
+
* 面板自己的文案。
|
|
80
|
+
*
|
|
81
|
+
* 客户端产物(`dist/webui.js`)不 import 服务端模块,所以面板标题和说明
|
|
82
|
+
* 这里给一份、bundle 里另存一份——改文案时两处一起改(feast 也是这么做的)。
|
|
83
|
+
*/
|
|
84
|
+
export function panelText(language = 'zh') {
|
|
85
|
+
if (language === 'en') {
|
|
86
|
+
return {
|
|
87
|
+
places: {
|
|
88
|
+
title: 'Where to go',
|
|
89
|
+
description: 'The twelve places, whether each is open right now, and the trip she is on.',
|
|
90
|
+
},
|
|
91
|
+
book: {
|
|
92
|
+
title: 'Trip book',
|
|
93
|
+
description: 'Every trip she has taken: where she went, what she wandered and bought.',
|
|
94
|
+
},
|
|
95
|
+
};
|
|
96
|
+
}
|
|
97
|
+
return {
|
|
98
|
+
places: {
|
|
99
|
+
title: '去哪儿',
|
|
100
|
+
description: '十二处地方这会儿开没开、人多不多,以及她正在逛的那一趟。',
|
|
101
|
+
},
|
|
102
|
+
book: {
|
|
103
|
+
title: '纪念册',
|
|
104
|
+
description: '她去过的每一趟:逛了什么、买了什么、在哪儿拍了照。',
|
|
105
|
+
},
|
|
106
|
+
};
|
|
107
|
+
}
|
|
108
|
+
|
|
70
109
|
/** WebUI 的配置组;路径必须落在 `worlds.fun.` 段内。 */
|
|
71
110
|
export function configGroup(language = 'zh') {
|
|
72
111
|
const t = text(language).config;
|
package/src/world.js
CHANGED
|
@@ -23,7 +23,7 @@ import { mkdir, readFile, rename, writeFile } from 'node:fs/promises';
|
|
|
23
23
|
import { dirname, join } from 'node:path';
|
|
24
24
|
import { fileURLToPath } from 'node:url';
|
|
25
25
|
|
|
26
|
-
import { DEFAULTS, ID, configGroup, text } from './config.js';
|
|
26
|
+
import { DEFAULTS, ID, configGroup, panelText, text } from './config.js';
|
|
27
27
|
import {
|
|
28
28
|
CROWD_LABEL, KIND_LABEL, VENUES, allPlaces, findVenue, hasScene, hoursState, suggestPlaces,
|
|
29
29
|
} from './venues.js';
|
|
@@ -567,6 +567,7 @@ export class FunWorld {
|
|
|
567
567
|
webUi(language = 'zh') {
|
|
568
568
|
this.language = language === 'en' ? 'en' : 'zh';
|
|
569
569
|
const t = text(this.language);
|
|
570
|
+
const p = panelText(this.language);
|
|
570
571
|
const now = this.#now();
|
|
571
572
|
const state = this.#state ?? newState(dayIn(this.timezone, now));
|
|
572
573
|
const nowMin = minutesIn(this.timezone, now);
|
|
@@ -597,6 +598,11 @@ export class FunWorld {
|
|
|
597
598
|
: t.stopped,
|
|
598
599
|
}],
|
|
599
600
|
badges,
|
|
601
|
+
panels: [
|
|
602
|
+
{ id: 'places', title: p.places.title, description: p.places.description, getMethods: ['list'] },
|
|
603
|
+
{ id: 'book', title: p.book.title, description: p.book.description, getMethods: ['list'] },
|
|
604
|
+
],
|
|
605
|
+
invoke: (panel, method, args) => this.#invoke(panel, method, args ?? []),
|
|
600
606
|
config: [configGroup(this.language)],
|
|
601
607
|
promptDocs: [{
|
|
602
608
|
key: `worlds.${ID}.env`,
|
|
@@ -605,9 +611,177 @@ export class FunWorld {
|
|
|
605
611
|
path: ENV_PROMPT,
|
|
606
612
|
role: 'envPrompt',
|
|
607
613
|
}],
|
|
614
|
+
storage: [{
|
|
615
|
+
key: 'fun-state',
|
|
616
|
+
label: t.storage.label,
|
|
617
|
+
kind: 'disk',
|
|
618
|
+
location: this.stateFile(),
|
|
619
|
+
danger: true,
|
|
620
|
+
note: t.storage.note,
|
|
621
|
+
stat: () => {
|
|
622
|
+
const st = this.#state;
|
|
623
|
+
if (!st) return '还没启动';
|
|
624
|
+
const trips = st.trips?.length ?? 0;
|
|
625
|
+
return `${trips} 趟纪念册${st.session ? ` · 正在${st.session.placeName}逛` : ''}`;
|
|
626
|
+
},
|
|
627
|
+
clear: () => this.#clearState(),
|
|
628
|
+
}],
|
|
629
|
+
};
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
// -------------------------------------------------------------------------
|
|
633
|
+
// 面板数据面(客户端 bundle 只走这里,不读私有状态)
|
|
634
|
+
// -------------------------------------------------------------------------
|
|
635
|
+
|
|
636
|
+
/**
|
|
637
|
+
* 面板调用的唯一入口。
|
|
638
|
+
*
|
|
639
|
+
* 契约:**只读方法必须幂等、不写盘**;写方法(go/wander/home)走的是和工具同一个
|
|
640
|
+
* 实现,所以在面板上点一下和她自己调工具是一回事——不会有第二套逻辑。
|
|
641
|
+
* 任何异常都兜成 `{ ok: false, error }`,不让面板挂掉。
|
|
642
|
+
*/
|
|
643
|
+
async #invoke(panel, method, args) {
|
|
644
|
+
try {
|
|
645
|
+
this.#ensureStarted();
|
|
646
|
+
if (panel === 'places') {
|
|
647
|
+
switch (method) {
|
|
648
|
+
case 'list': return this.#placesData();
|
|
649
|
+
default: throw new Error(`places 没有 ${method} 这个方法`);
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
if (panel === 'book') {
|
|
653
|
+
switch (method) {
|
|
654
|
+
case 'list': return this.#bookData();
|
|
655
|
+
default: throw new Error(`book 没有 ${method} 这个方法`);
|
|
656
|
+
}
|
|
657
|
+
}
|
|
658
|
+
throw new Error(`不认识的面板:${panel}`);
|
|
659
|
+
} catch (err) {
|
|
660
|
+
return { ok: false, error: msg(err) };
|
|
661
|
+
}
|
|
662
|
+
}
|
|
663
|
+
|
|
664
|
+
/**
|
|
665
|
+
* 「去哪儿」面板:十二处场所 + 此刻的开放状态 + 正在逛的这一趟。
|
|
666
|
+
*
|
|
667
|
+
* 只读:不动状态、不写盘。`now` 由服务端给,别让面板自己算——
|
|
668
|
+
* 客户端的钟可能和她的时区不一致。
|
|
669
|
+
*/
|
|
670
|
+
#placesData() {
|
|
671
|
+
const now = this.#now();
|
|
672
|
+
const nowMin = minutesIn(this.timezone, now);
|
|
673
|
+
const tz = this.timezone;
|
|
674
|
+
const st = this.#state ?? newState(dayIn(tz, now));
|
|
675
|
+
const recent = recentPlaceIds(st, 3);
|
|
676
|
+
const places = VENUES.map((v) => {
|
|
677
|
+
const state = hoursState(v, nowMin);
|
|
678
|
+
return {
|
|
679
|
+
id: v.id,
|
|
680
|
+
name: v.name,
|
|
681
|
+
aliases: v.aliases,
|
|
682
|
+
tags: v.tags,
|
|
683
|
+
desc: v.desc,
|
|
684
|
+
scene: v.scene,
|
|
685
|
+
hasScene: hasScene(v),
|
|
686
|
+
outfit: v.recommendedOutfit,
|
|
687
|
+
crowd: v.crowd,
|
|
688
|
+
crowdLabel: CROWD_LABEL[v.crowd] ?? '',
|
|
689
|
+
kindLabel: KIND_LABEL[v.kind] ?? '',
|
|
690
|
+
hours: v.hours,
|
|
691
|
+
state,
|
|
692
|
+
stateLabel: STATE_LABEL[state],
|
|
693
|
+
areas: v.areas,
|
|
694
|
+
areaCount: v.areas.length,
|
|
695
|
+
souvenirs: v.souvenirs,
|
|
696
|
+
photoSpots: v.photoSpots,
|
|
697
|
+
recent: recent.includes(v.id),
|
|
698
|
+
};
|
|
699
|
+
});
|
|
700
|
+
// 开着的排前面;面板不截断,十二处都给它,前端自己分组。
|
|
701
|
+
places.sort((a, b) => rankOf(a.state) - rankOf(b.state));
|
|
702
|
+
|
|
703
|
+
return {
|
|
704
|
+
ok: true,
|
|
705
|
+
nowHm: hmIn(tz, now),
|
|
706
|
+
day: dayIn(tz, now),
|
|
707
|
+
ttlMin: this.#ttlMin(),
|
|
708
|
+
askReport: this.#askReport(),
|
|
709
|
+
on: this.#on(),
|
|
710
|
+
openCount: places.filter((x) => x.state !== 'closed').length,
|
|
711
|
+
total: places.length,
|
|
712
|
+
places,
|
|
713
|
+
session: st.session ? {
|
|
714
|
+
placeId: st.session.placeId,
|
|
715
|
+
placeName: st.session.placeName,
|
|
716
|
+
scene: st.session.scene,
|
|
717
|
+
outfit: st.session.outfit,
|
|
718
|
+
enteredHm: hmIn(tz, st.session.enteredAt),
|
|
719
|
+
lastHm: hmIn(tz, st.session.lastAt),
|
|
720
|
+
stayedMin: Math.max(0, Math.round((now - st.session.enteredAt) / 60000)),
|
|
721
|
+
stale: isStale(st.session, now, this.#ttlMin()),
|
|
722
|
+
visited: st.session.visited.map((v) => ({ area: v.area, note: v.note, hm: hmIn(tz, v.at) })),
|
|
723
|
+
souvenirs: st.session.souvenirs,
|
|
724
|
+
photos: st.session.photos,
|
|
725
|
+
events: st.session.events,
|
|
726
|
+
venueAreaCount: venueById(st.session.placeId)?.areas.length ?? null,
|
|
727
|
+
} : null,
|
|
728
|
+
};
|
|
729
|
+
}
|
|
730
|
+
|
|
731
|
+
/**
|
|
732
|
+
* 「纪念册」面板:去过的每一趟 + 汇总。
|
|
733
|
+
*
|
|
734
|
+
* 只读。`trips` 已经在 state 里裁到 MAX_TRIPS 条,这里不再二次截断,
|
|
735
|
+
* 否则面板上看到的总趟数和实际记得的对不上。
|
|
736
|
+
*/
|
|
737
|
+
#bookData() {
|
|
738
|
+
const tz = this.timezone;
|
|
739
|
+
const now = this.#now();
|
|
740
|
+
const st = this.#state ?? newState(dayIn(tz, now));
|
|
741
|
+
const trips = (st.trips ?? []).map((t) => ({
|
|
742
|
+
placeId: t.placeId,
|
|
743
|
+
placeName: t.placeName,
|
|
744
|
+
scene: t.scene,
|
|
745
|
+
outfit: t.outfit,
|
|
746
|
+
day: t.leftAt ? dayIn(tz, t.leftAt) : '',
|
|
747
|
+
enteredHm: t.enteredAt ? hmIn(tz, t.enteredAt) : '',
|
|
748
|
+
leftHm: t.leftAt ? hmIn(tz, t.leftAt) : '',
|
|
749
|
+
stayedMin: t.leftAt && t.enteredAt ? Math.max(0, Math.round((t.leftAt - t.enteredAt) / 60000)) : 0,
|
|
750
|
+
visited: t.visited.map((v) => v.area),
|
|
751
|
+
souvenirs: t.souvenirs,
|
|
752
|
+
photos: t.photos,
|
|
753
|
+
events: t.events,
|
|
754
|
+
summary: tripSummary(t),
|
|
755
|
+
}));
|
|
756
|
+
// 按地方汇总:哪几处去得最多(面板上的「常去」)。
|
|
757
|
+
const byPlace = new Map();
|
|
758
|
+
for (const t of trips) {
|
|
759
|
+
const cur = byPlace.get(t.placeName) ?? { name: t.placeName, times: 0, lastDay: '' };
|
|
760
|
+
cur.times += 1;
|
|
761
|
+
if (!cur.lastDay || t.day > cur.lastDay) cur.lastDay = t.day;
|
|
762
|
+
byPlace.set(t.placeName, cur);
|
|
763
|
+
}
|
|
764
|
+
const mostVisited = [...byPlace.values()].sort((a, b) => b.times - a.times || (a.lastDay < b.lastDay ? 1 : -1));
|
|
765
|
+
return {
|
|
766
|
+
ok: true,
|
|
767
|
+
total: trips.length,
|
|
768
|
+
souvenirCount: trips.reduce((n, t) => n + t.souvenirs.length, 0),
|
|
769
|
+
photoCount: trips.reduce((n, t) => n + t.photos.length, 0),
|
|
770
|
+
visitedAreaCount: trips.reduce((n, t) => n + t.visited.length, 0),
|
|
771
|
+
mostVisited,
|
|
772
|
+
trips,
|
|
773
|
+
session: st.session ? { placeName: st.session.placeName, summary: tripSummary(st.session) } : null,
|
|
608
774
|
};
|
|
609
775
|
}
|
|
610
776
|
|
|
777
|
+
/** 清空她的出游记录(存储页「清掉」)。只清 state 这一份,不碰别的 World。 */
|
|
778
|
+
async #clearState() {
|
|
779
|
+
this.#state = newState(dayIn(this.timezone, this.#now()));
|
|
780
|
+
await this.#save();
|
|
781
|
+
this.#host?.log?.info?.('娱乐时间:出游记录已清空');
|
|
782
|
+
return { ok: true };
|
|
783
|
+
}
|
|
784
|
+
|
|
611
785
|
// -------------------------------------------------------------------------
|
|
612
786
|
// 生命周期
|
|
613
787
|
// -------------------------------------------------------------------------
|