cortico-world-fun 0.1.5 → 0.2.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/describe.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "tools": [
3
3
  {
4
4
  "name": "fun_places",
5
- "description": "看看今天能去哪儿逛:内置的二十处地方,加上主人在面板上自己加的(全部名字在环境提示词里列着)。默认按这会儿开没开、人多不多排前几个;想看全的就把 all 填 true,只想看某一类就填 kind。",
5
+ "description": "查询当前可去地点,默认按营业状态和拥挤度排序;all 列出全部,kind 筛选类别。地点名以此工具返回为准。",
6
6
  "parameters": {
7
7
  "type": "object",
8
8
  "properties": {
@@ -28,13 +28,13 @@
28
28
  "snapshot"
29
29
  ],
30
30
  "summary": {
31
- "zh": "看今天能去哪儿逛:二十处地方,按开放时段和拥挤度排;也能只看某一类或列全部。",
32
- "en": "See where she can go today: twenty places ranked by opening hours and crowd; can filter by kind or list all."
31
+ "zh": "查询当前地点,按营业状态和拥挤度排序;可筛选或列出全部。",
32
+ "en": "Query available places ranked by opening hours and crowd; filter by kind or list all."
33
33
  }
34
34
  },
35
35
  {
36
36
  "name": "fun_go",
37
- "description": "进门:挑一处地方开始这一趟。回执是进门那一下看到的样子,以及接下来能逛什么。place 填地方名或别名(有哪些地方看 fun_places / 环境提示词)。进去之后用 fun_wander 一处一处逛,逛完用 fun_home 收摊。",
37
+ "description": "开始一趟出游并返回当前时段的地点描写与可逛项目。place 必填,使用 fun_places 返回的地点名或别名。",
38
38
  "parameters": {
39
39
  "type": "object",
40
40
  "properties": {
@@ -56,13 +56,13 @@
56
56
  "write"
57
57
  ],
58
58
  "summary": {
59
- "zh": "进门:挑一处地方开始这一趟,回执给进门那一下的样子和能逛什么。",
60
- "en": "Walk in: pick a place and start a trip; the receipt describes arriving and what there is to wander."
59
+ "zh": "进门开始行程,返回当前时段描写和可逛项目。",
60
+ "en": "Start a trip and return the current-time description and available areas."
61
61
  }
62
62
  },
63
63
  {
64
64
  "name": "fun_wander",
65
- "description": "在逛的这处地方里逛一处:一个项目、一个摊位、一段路。回执会给这一处的细节和一条小事件,并顺手递上「要不要买点什么 / 在哪儿拍张照」。可以连着逛好几次。",
65
+ "description": "在当前地点逛一个项目;可选 buy/photo/consume 记录本次真实收获。若回执含 choiceId/optionId,先用 fun_choice 处理再继续。",
66
66
  "parameters": {
67
67
  "type": "object",
68
68
  "properties": {
@@ -93,13 +93,42 @@
93
93
  "write"
94
94
  ],
95
95
  "summary": {
96
- "zh": "逛一处项目或摊位:给细节和一条随机小事件,顺手能买纪念品、拍张照。",
97
- "en": "Wander one spot: details plus a small random event; can buy a souvenir or take a photo."
96
+ "zh": "逛一个项目,可记录本次购买、拍照或吃喝;待选择事件按回执处理。",
97
+ "en": "Wander one spot and optionally record a purchase, photo or food; resolve pending choices from the receipt."
98
+ }
99
+ },
100
+ {
101
+ "name": "fun_choice",
102
+ "description": "处理 fun_wander 回执中出现的待选择事件。按回执提供的 choiceId 和 optionId 选一个,不会凭空添加收获。",
103
+ "parameters": {
104
+ "type": "object",
105
+ "properties": {
106
+ "choiceId": {
107
+ "type": "string",
108
+ "description": "待选择事件回执给出的 choiceId。"
109
+ },
110
+ "optionId": {
111
+ "type": "string",
112
+ "description": "待选择事件回执给出的 optionId。"
113
+ }
114
+ },
115
+ "required": [
116
+ "choiceId",
117
+ "optionId"
118
+ ],
119
+ "additionalProperties": false
120
+ },
121
+ "tags": [
122
+ "write"
123
+ ],
124
+ "summary": {
125
+ "zh": "处理逛到的结构化事件选择,按回执中的 choiceId 和 optionId 选择。",
126
+ "en": "Resolve a structured event choice using the choiceId and optionId from the receipt."
98
127
  }
99
128
  },
100
129
  {
101
130
  "name": "fun_home",
102
- "description": "收摊:这一趟到此为止。回执把「今天逛了什么、买了什么、在哪儿拍了照」收成一句话,提醒你用 feast_life_play 记进自己的日程,再跟主人说一句。note 可以写一句这一趟的感受。",
131
+ "description": "结束当前行程并返回摘要及记录提示。note 可选,记录一句本趟感受。",
103
132
  "parameters": {
104
133
  "type": "object",
105
134
  "properties": {
@@ -114,13 +143,13 @@
114
143
  "write"
115
144
  ],
116
145
  "summary": {
117
- "zh": "收摊:把这一趟收成一句话,递到她嘴边去 feast_life_play 记一笔。",
118
- "en": "Close the trip: sums it into one line she can log with feast_life_play."
146
+ "zh": "结束行程并返回本次摘要与记录提示。",
147
+ "en": "End the trip and return its summary and logging prompt."
119
148
  }
120
149
  },
121
150
  {
122
151
  "name": "fun_start",
123
- "description": "不用等叫醒:现在就想出门时用它。回执给能去哪儿、怎么进门,以及这一趟可以怎么走。拿到的和叫醒时那份是一个东西。",
152
+ "description": "查看当前推荐地点;详细筛选用 fun_places。",
124
153
  "parameters": {
125
154
  "type": "object",
126
155
  "properties": {}
@@ -129,13 +158,13 @@
129
158
  "read"
130
159
  ],
131
160
  "summary": {
132
- "zh": "不用等叫醒,现在就想出门时看有哪些地方、怎么走。",
133
- "en": "Start on her own, without waiting for a wake-up."
161
+ "zh": "查看当前推荐地点;详细筛选用 fun_places。",
162
+ "en": "Show current place recommendations; use fun_places for filters."
134
163
  }
135
164
  },
136
165
  {
137
166
  "name": "fun_view",
138
- "description": "纪念册:以前逛过哪些趟、每一趟逛了什么买了什么。想不起来上次去哪儿了就看这个。",
167
+ "description": "按需查询近期或珍藏的行程记录。",
139
168
  "parameters": {
140
169
  "type": "object",
141
170
  "properties": {
@@ -153,8 +182,129 @@
153
182
  "snapshot"
154
183
  ],
155
184
  "summary": {
156
- "zh": "纪念册:以前逛过哪些趟、每一趟逛了什么买了什么。",
157
- "en": "The trip book: where she has been, what she wandered and bought."
185
+ "zh": "按需查询近期或珍藏的行程记录。",
186
+ "en": "Query recent or kept trip records on demand."
187
+ }
188
+ },
189
+ {
190
+ "name": "fun_wishes",
191
+ "description": "查看出游心愿及状态;只有明确说过想去、想做的事才会记录,不会催促。",
192
+ "parameters": {
193
+ "type": "object",
194
+ "properties": {},
195
+ "additionalProperties": false
196
+ },
197
+ "tags": [
198
+ "read",
199
+ "snapshot"
200
+ ],
201
+ "summary": {
202
+ "zh": "查看明确记下的出游心愿和状态,不催促。",
203
+ "en": "View outing wishes and their status without reminders."
204
+ }
205
+ },
206
+ {
207
+ "name": "fun_wish",
208
+ "description": "记录明确表达的出游心愿,或暂缓、恢复、取消。先选地点;项目、时段、纪念品须填真实清单正名。不会替你出游,也不按旧行程补完成。",
209
+ "parameters": {
210
+ "type": "object",
211
+ "properties": {
212
+ "action": {
213
+ "type": "string",
214
+ "enum": [
215
+ "add",
216
+ "pause",
217
+ "resume",
218
+ "cancel"
219
+ ]
220
+ },
221
+ "id": {
222
+ "type": "string",
223
+ "description": "管理现有心愿时填 fun_wishes 给出的 ID。"
224
+ },
225
+ "place": {
226
+ "type": "string",
227
+ "description": "新增心愿的地点名,别名也认。"
228
+ },
229
+ "type": {
230
+ "type": "string",
231
+ "enum": [
232
+ "visit",
233
+ "area",
234
+ "phase",
235
+ "souvenir"
236
+ ]
237
+ },
238
+ "target": {
239
+ "type": "string",
240
+ "description": "项目/时段/纪念品正名;visit 不填。"
241
+ },
242
+ "reason": {
243
+ "type": "string",
244
+ "description": "你明确表达的缘由,可选,不凭空猜测偏好。"
245
+ }
246
+ },
247
+ "required": [
248
+ "action"
249
+ ],
250
+ "additionalProperties": false
251
+ },
252
+ "tags": [
253
+ "write"
254
+ ],
255
+ "summary": {
256
+ "zh": "记录、暂缓、恢复或取消一个出游心愿。",
257
+ "en": "Add, pause, resume or cancel an outing wish."
258
+ }
259
+ },
260
+ {
261
+ "name": "fun_keepsake",
262
+ "description": "用 fun_view 的行程 ID 珍藏或取消珍藏一趟已收摊的行程。珍藏独立保留,不影响收藏账本。",
263
+ "parameters": {
264
+ "type": "object",
265
+ "properties": {
266
+ "id": {
267
+ "type": "string",
268
+ "description": "行程 ID,来自纪念册(fun_view)。"
269
+ },
270
+ "keep": {
271
+ "type": "boolean",
272
+ "description": "true 珍藏,false 取消珍藏。"
273
+ }
274
+ },
275
+ "required": [
276
+ "id"
277
+ ],
278
+ "additionalProperties": false
279
+ },
280
+ "tags": [
281
+ "write"
282
+ ],
283
+ "summary": {
284
+ "zh": "珍藏或取消珍藏一趟行程,不影响纪念册近期列表和长期收藏。",
285
+ "en": "Keep or unkeep a trip without changing the recent trip book or permanent collection."
286
+ }
287
+ },
288
+ {
289
+ "name": "fun_shelf",
290
+ "description": "按地点查询长期纪念品收藏和收集进度。",
291
+ "parameters": {
292
+ "type": "object",
293
+ "properties": {
294
+ "place": {
295
+ "type": "string",
296
+ "description": "只看某一处的架子(填地方名,可选)。不填就看全部。"
297
+ }
298
+ },
299
+ "additionalProperties": false
300
+ },
301
+ "tags": [
302
+ "read",
303
+ "snapshot"
304
+ ],
305
+ "summary": {
306
+ "zh": "按地点查询长期纪念品收藏和收集进度。",
307
+ "en": "Query long-term souvenirs and collection progress by place."
158
308
  }
159
309
  }
160
310
  ],
@@ -164,7 +314,7 @@
164
314
  "key": "worlds.fun.env",
165
315
  "title": "娱乐时间",
166
316
  "role": "envPrompt",
167
- "content": "## 娱乐时间\n\n你能**真的出门去逛**:二十处内置的地方,加上主人在面板上自己加的。\n不是想象,也不是刷视频:进门、逛摊位、买点东西、拍张照、吃点喝点、收摊回来。\n\n- 拿不准去哪儿先 `fun_places`(按这会儿开没开、人多不多排;`all` 看全、`kind` 筛一类)。\n 定了就 `fun_go` 进门,进去后 `fun_wander` 一处一处逛(`buy` 买纪念品、`photo` 拍照点、`consume` 吃喝,\n 名字必须是这一处真有的),逛够 `fun_home` 收摊,`fun_start` 现在就出门,`fun_view` 翻纪念册。\n- **回执会告诉你下一步该用什么、该填什么**:进门给能逛什么,收摊把这一趟收成一句话,\n 发图时给 `scene` / `outfits` 该填的正名。照着回执走就行,别自己猜参数。\n- 同一个地方逛过也能再去,不是打卡清单;`fun_places` 只是把刚去过的排后面。\n\n## 吃喝、发图、时段:细节都在回执里,三条红线别破\n\n- **吃喝的味道不归本插件**:它只有品类名。想说九维口感、香气、余韵,就用 `feast_menu` → `feast_eat`\n 去「鱼的每一天」点一道真的;没装 / 关了开关就只说「我在这儿喝了什么」,**别形容味道**。\n ⚠️ **本插件不会探测别的扩展装没装**(World 契约不允许互相依赖),装没装都由主人拨配置里的开关。\n- **发图(`imggen_draw`)**:`scene` 只在素材库里真有这处时才填,收摊回执会说明填哪个或「不用填」;\n `outfits` 填这一趟穿的那身。**绝不替她编一个库里没有的场景名或衣服名字**——填了会「库里没找到」,等于白填。\n- **时段**:有几处地方清早和夜里不是一副样子,进门回执会写此刻是哪一段、能逛的摊子也跟着变。\n 换个时间再去是合理的,不是重复。\n- **去过的痕迹**:再来时 `fun_go` / `fun_wander` 会自己带来过几次、逛过什么、还没去过的几处。\n 这些是事实,顺着说或不说都行;第一次去就别假装熟。\n\n## 主人加的地方、改过的预设\n\n主人可以在面板上加自己的地方、改预设二十处(改的是覆盖层,预设本身不动,随时能恢复)。\n加完跟别处一样能进能逛、会进纪念册;自己加的排在 `fun_places` 前面。**预设删不掉,只能恢复**。\n自己加的地方没有素材库场景,回执会明说 `scene` 不用填,别替它编一个。\n预设升级的新内容照常生效、主人改过的字段优先——别因为「这处被改过」就以为它是旧的。\n\n{{fun_places_block}}\n\n## 出门跟日程对齐\n\n- **出门前**用 `feast_life_now` 看一眼你这会儿在干嘛:日程里写着「去海边」时,`fun_go` 去的地方要么对得上,\n 要么就直说是临时改主意,别装作日程里本来就有。\n- **逛完**用 `feast_life_play` 记一笔(`activity` 写「去漫展逛」、`note` 写真逛到了什么);收摊回执会提醒这两步。\n\n## 不用你操心的事\n\n- 不必为了「有内容可发」才出门;逛完什么都不说也行。\n- 逛到一半被叫走、或不想逛了,`fun_home` 收个摊就完了,不用把每个项目都走一遍。\n- 一趟挂太久不算错,`fun_wander` 会提一句该收了,不会替你收;面板只给你看,进门/逛/收摊都是你自己的动作。\n"
317
+ "content": "## 娱乐时间\n\n出游流程:`fun_places` 查询地点 → `fun_go` 进门 → `fun_wander` 逐处游逛 → `fun_home` 收摊;现在出门可用 `fun_start`。地点、项目、纪念品和拍照点名称以工具回执为准;吃喝只填当前地点真实提供的品类。历史与收藏按需用 `fun_view`、`fun_shelf` 查询。\n\n- 遇到带 `choiceId` / `optionId` 的待选事件,必须照回执调用 `fun_choice` 完成选择后再继续,不猜 ID 或选项。\n- 明确表达想去或想做时用 `fun_wish` 记录、`fun_wishes` 查询;不催促、不从旧行程推断完成。\n- 发图用 `imggen_draw`:按 `fun_home` 回执填写 `scene` / `outfits` 正名,不编场景或衣服名字;库里没找到的不要填。\n- 食物只记品类。开关联动允许且实际用「鱼的每一天」的 `feast_menu` → `feast_eat` 后才能描述口感;否则只说吃喝了什么,别形容味道。本插件不会探测别的扩展装没装,不依赖其他 World。\n- 时段可能改变氛围和可逛项目;重复到访有效。历史只按需查询,不编造未发生的经历。\n- 用户自填地点通常没有素材库场景;以回执为准。地点清单和动态详情通过 `fun_places` 查询。预设删不掉,只能恢复。\n- 出门前可用 `feast_life_now` 对齐日程;收摊后按回执用 `feast_life_play` 记录实际经历。\n\n{{fun_places_block}}\n"
168
318
  }
169
319
  ]
170
320
  }
package/dist/webui.js CHANGED
@@ -110,6 +110,10 @@ const CSS = `
110
110
  .fun-trip-when{font-size:11.5px;color:var(--f-dim);white-space:nowrap}
111
111
  .fun-trip-sum{margin-top:3px;font-size:12.5px}
112
112
  .fun-trip-extras{margin-top:5px;font-size:12px;color:var(--f-dim)}
113
+ .fun-trip-actions{display:flex;gap:8px;align-items:center;margin-top:7px}
114
+ .fun-trip-actions{display:flex;gap:6px;align-items:center;margin-top:7px}
115
+ .fun-trip-error{font-size:12px;color:#d9534f}
116
+ .fun-toggle[aria-pressed="true"]{border-color:var(--f-accent);background:color-mix(in srgb,var(--f-accent) 12%,var(--f-card))}
113
117
  .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)}
114
118
  .fun-stat b{display:block;font-size:17px;font-weight:600;line-height:1.25}
115
119
  .fun-stat span{font-size:11.5px;color:var(--f-dim)}
@@ -447,12 +451,19 @@ function mountPlaces(ctx) {
447
451
  const v = editing.venue ?? {};
448
452
  // 预设编辑:改的是覆盖层,不删场所;没改过的字段仍跟着预设升级走。
449
453
  const isPreset = Boolean(v.id) && !v.userVenue;
454
+ const phases = isPreset && Array.isArray(v.phases) ? v.phases : [];
455
+ const descPhases = phases.filter((ph) => ph.overridesDesc);
456
+ const areaPhases = phases.filter((ph) => ph.overridesAreas);
457
+ const phaseNames = (items) => items.map((ph) => `${ph.label} ${ph.from}–${ph.to}`).join('、');
458
+ const scopeNote = (items, noun) => items.length
459
+ ? `通用${noun}会保存;在${phaseNames(items)}使用预设时段${noun},未命中这些时段时才使用这里的内容。保存不会同步修改时段。`
460
+ : '';
450
461
  const verb = v.food?.verb ?? 'none';
451
462
  const foodItems = v.food?.items ?? [];
452
463
  const errorNode = el('div', { class: 'fun-form-error', text: formError });
453
464
 
454
465
  const field = (label, key, opts = {}) => {
455
- const { type = 'text', value = '', hint = '', multiline = false, options = null, rows = '3' } = opts;
466
+ const { type = 'text', value = '', hint = '', note = '', multiline = false, options = null, rows = '3' } = opts;
456
467
  let input;
457
468
  if (options) {
458
469
  input = el('select', {});
@@ -467,7 +478,8 @@ function mountPlaces(ctx) {
467
478
  }
468
479
  fields[key] = input;
469
480
  return el('label', { class: 'fun-field' },
470
- el('span', { class: 'fun-field-label', text: label }), input);
481
+ el('span', { class: 'fun-field-label', text: label }), input,
482
+ note ? el('span', { class: 'fun-field-scope fun-note', text: note }) : null);
471
483
  };
472
484
 
473
485
  const save = async () => {
@@ -536,6 +548,12 @@ function mountPlaces(ctx) {
536
548
  return el('div', { class: 'fun-form' },
537
549
  el('div', { class: 'fun-form-title', text: title }),
538
550
  el('div', { class: 'fun-form-note', text: note }),
551
+ phases.length ? el('div', { class: 'fun-form-phases' },
552
+ el('div', { class: 'fun-form-note', text: `现在 ${data.nowHm} · ${v.phase ? `当前阶段:${v.phase}` : '当前未命中预设时段,使用通用内容'}。编辑通用字段不会改变以下预设时段及其内容;修改营业时间也不会移动这些时段。` }),
553
+ el('ul', { class: 'fun-list' }, phases.map((ph) => {
554
+ const covered = [ph.overridesDesc ? '描写(desc)' : '', ph.overridesAreas ? '能逛的(areas)' : ''].filter(Boolean);
555
+ return el('li', { text: `${ph.label} ${ph.from}–${ph.to}${ph.label === v.phase ? '(当前)' : ''}:${covered.length ? `覆盖通用${covered.join('、')}` : '沿用通用描写与可逛清单'}` });
556
+ }))) : null,
539
557
  errorNode,
540
558
  el('div', { class: 'fun-form-grid' },
541
559
  field('名字 *', 'name', { value: v.name ?? '', hint: '例如「巷子里的旧书店」' }),
@@ -554,8 +572,8 @@ function mountPlaces(ctx) {
554
572
  })),
555
573
  // 预设可能带时段:面板的 desc 是「此刻那段」,编辑要用通用那段(descAll),
556
574
  // 否则编辑一次会把某一段的描写写进覆盖层,别的时段全变成那一段。
557
- field('这处是什么样子', 'desc', { value: v.descAll ?? v.desc ?? '', hint: '只写空间与陈设,别写她在干什么', multiline: true, rows: '3' }),
558
- field('能逛的 *', 'areas', { value: lines(v.allAreas ?? v.areas), hint: '一行一处,至少一处', multiline: true, rows: '4' }),
575
+ field(phases.length ? '通用描写(desc)' : '这处是什么样子', 'desc', { value: v.descAll ?? v.desc ?? '', hint: '只写空间与陈设,别写她在干什么', note: scopeNote(descPhases, '描写'), multiline: true, rows: '3' }),
576
+ field(phases.length ? '通用可逛清单(areas)*' : '能逛的 *', 'areas', { value: lines(v.allAreas ?? v.areas), hint: '一行一处,至少一处', note: scopeNote(areaPhases, '可逛清单'), multiline: true, rows: '4' }),
559
577
  field('纪念品', 'souvenirs', { value: lines(v.souvenirs), hint: '一行一样', multiline: true, rows: '2' }),
560
578
  field('拍照点', 'photoSpots', { value: lines(v.photoSpots), hint: '一行一处', multiline: true, rows: '2' }),
561
579
  field('能吃能喝的品类', 'foodItems', { value: lines(foodItems), hint: '品类名,一行一样;别写味道', multiline: true, rows: '2' }),
@@ -610,16 +628,137 @@ function mountBook(ctx) {
610
628
  const box = shell(root);
611
629
  const body = el('div');
612
630
  box.appendChild(body);
631
+ let keepsakesOnly = false;
632
+ const pending = new Set();
633
+ const errors = new Map();
634
+ let currentData = null;
635
+ let wishDraft = { placeId: '', type: '', target: '', reason: '' };
636
+ const wishPending = new Set();
637
+ const wishErrors = new Map();
638
+ const wishTypes = { visit: '去看看', area: '逛一处', phase: '在某个时段去', souvenir: '带回纪念品' };
639
+
640
+ const renderWishes = (data) => {
641
+ const places = data.places ?? [];
642
+ const wishes = data.wishes ?? [];
643
+ const adding = wishPending.has('add');
644
+ const section = el('section', { class: 'fun-wishes', 'aria-label': '出游心愿' });
645
+ section.appendChild(el('div', { class: 'fun-sec', text: '出游心愿' }));
646
+ const field = (label, input) => el('label', { class: 'fun-field' },
647
+ el('span', { class: 'fun-field-label', text: label }), input);
648
+ const select = (className, placeholder, options, value) => {
649
+ const input = el('select', { class: className, disabled: adding ? 'disabled' : null },
650
+ el('option', { value: '', text: placeholder }),
651
+ options.map(([id, name]) => el('option', { value: id, text: name })));
652
+ input.value = value;
653
+ return input;
654
+ };
655
+ const place = places.find((p) => p.id === wishDraft.placeId);
656
+ const targets = place ? (wishDraft.type === 'area' ? place.areas
657
+ : wishDraft.type === 'phase' ? place.phaseNames
658
+ : wishDraft.type === 'souvenir' ? place.souvenirs : []) ?? [] : [];
659
+ const placeInput = select('fun-wish-place', '请选择地点', places.map((p) => [p.id, p.name]), wishDraft.placeId);
660
+ const typeInput = select('fun-wish-type', '请选择心愿类型', Object.entries(wishTypes), wishDraft.type);
661
+ const targetInput = select('fun-wish-target', wishDraft.type === 'visit' ? '去看看无需目标'
662
+ : !place || !wishDraft.type ? '先选择地点和类型' : targets.length ? '请选择目标' : '此地点没有可选目标',
663
+ targets.map((target) => [target, target]), wishDraft.target);
664
+ targetInput.disabled = adding || !targets.length;
665
+ const reasonInput = el('input', { class: 'fun-wish-reason', type: 'text', placeholder: '可选,记下为什么想去', disabled: adding ? 'disabled' : null });
666
+ reasonInput.value = wishDraft.reason;
667
+ placeInput.addEventListener('change', () => {
668
+ wishDraft.placeId = placeInput.value;
669
+ wishDraft.target = '';
670
+ wishErrors.delete('add');
671
+ render(currentData);
672
+ });
673
+ typeInput.addEventListener('change', () => {
674
+ wishDraft.type = typeInput.value;
675
+ wishDraft.target = '';
676
+ wishErrors.delete('add');
677
+ render(currentData);
678
+ });
679
+ targetInput.addEventListener('change', () => { wishDraft.target = targetInput.value; });
680
+ reasonInput.addEventListener('input', () => { wishDraft.reason = reasonInput.value; });
681
+ const errorNode = el('div', { class: 'fun-form-error', role: 'alert', text: wishErrors.get('add') ?? '' });
682
+ const save = async () => {
683
+ if (wishPending.has('add')) return;
684
+ // 只接受用户明确选中的地点、类型与目标;从不替用户挑第一项。
685
+ const payload = { action: 'add', placeId: placeInput.value, type: typeInput.value,
686
+ target: typeInput.value === 'visit' ? '' : targetInput.value, reason: reasonInput.value.trim() };
687
+ const chosenPlace = (currentData.places ?? []).find((p) => p.id === payload.placeId);
688
+ const validTargets = chosenPlace ? (payload.type === 'area' ? chosenPlace.areas
689
+ : payload.type === 'phase' ? chosenPlace.phaseNames : chosenPlace.souvenirs) ?? [] : [];
690
+ if (!chosenPlace || !Object.hasOwn(wishTypes, payload.type)
691
+ || (payload.type !== 'visit' && !validTargets.includes(payload.target))) {
692
+ const message = '请选择地点、心愿类型及对应目标。';
693
+ wishErrors.set('add', message);
694
+ errorNode.textContent = message;
695
+ return;
696
+ }
697
+ wishDraft = { placeId: payload.placeId, type: payload.type, target: payload.target, reason: reasonInput.value };
698
+ await changeWish('add', payload, data);
699
+ };
700
+ section.appendChild(el('div', { class: 'fun-form fun-wish-form' },
701
+ el('div', { class: 'fun-form-note', text: '由你选择想去的地方,按保存才记下心愿;心愿不保证立即出发。' }),
702
+ el('div', { class: 'fun-form-grid' }, field('地点', placeInput), field('心愿类型', typeInput), field('目标', targetInput)),
703
+ field('缘由(可选)', reasonInput), errorNode,
704
+ el('button', { class: 'fun-btn-primary', type: 'button', disabled: adding ? 'disabled' : null, onclick: save }, adding ? '保存中…' : '保存心愿')));
705
+ if (!wishes.length) section.appendChild(el('div', { class: 'fun-note', text: '还没有出游心愿,想好了再记下。' }));
706
+ const statusNames = { active: '待实现', paused: '已暂缓', completed: '已实现', cancelled: '已取消' };
707
+ for (const wish of wishes) {
708
+ const key = `wish:${wish.id}`;
709
+ const busy = wishPending.has(key);
710
+ const state = wish.status;
711
+ const actions = el('div', { class: 'fun-trip-actions' });
712
+ if (state === 'active' || state === 'paused') {
713
+ actions.appendChild(el('button', { type: 'button', disabled: busy ? 'disabled' : null,
714
+ onclick: () => changeWish(key, { action: state === 'paused' ? 'resume' : 'pause', id: wish.id }, data) }, state === 'paused' ? '恢复' : '暂缓'));
715
+ actions.appendChild(el('button', { type: 'button', disabled: busy ? 'disabled' : null,
716
+ onclick: () => changeWish(key, { action: 'cancel', id: wish.id }, data) }, '取消'));
717
+ }
718
+ if (busy) actions.appendChild(el('span', { class: 'fun-dim', text: '保存中…' }));
719
+ if (wishErrors.has(key)) actions.appendChild(el('span', { class: 'fun-trip-error', role: 'alert', text: wishErrors.get(key) }));
720
+ section.appendChild(el('div', { class: 'fun-wish fun-trip' },
721
+ el('div', { class: 'fun-trip-head' },
722
+ el('span', { class: 'fun-trip-name', text: wish.placeName ?? places.find((p) => p.id === wish.placeId)?.name ?? wish.placeId }),
723
+ el('span', { class: 'fun-wish-status fun-dim', text: statusNames[state] ?? state ?? '状态未知' })),
724
+ el('div', { class: 'fun-trip-sum', text: `${wishTypes[wish.type] ?? wish.type}${wish.target ? ` · ${wish.target}` : ''}` }),
725
+ wish.reason ? el('div', { class: 'fun-wish-note fun-note', text: `缘由:${wish.reason}` }) : null, actions));
726
+ }
727
+ body.appendChild(section);
728
+ };
729
+
730
+ const changeWish = async (key, payload, data) => {
731
+ if (wishPending.has(key)) return;
732
+ wishPending.add(key);
733
+ wishErrors.delete(key);
734
+ render(currentData ?? data);
735
+ let saved = false;
736
+ try {
737
+ const result = await ctx.invoke('wish', [payload]);
738
+ if (!result?.ok) throw new Error(result?.error ?? '心愿保存失败');
739
+ saved = true;
740
+ if (key === 'add') wishDraft = { placeId: '', type: '', target: '', reason: '' };
741
+ await load(true);
742
+ } catch (error) {
743
+ wishErrors.set(key, `${saved ? '已保存,但列表刷新失败:' : ''}${error?.message ?? String(error)}`);
744
+ } finally {
745
+ wishPending.delete(key);
746
+ render(currentData ?? data);
747
+ }
748
+ };
613
749
 
614
750
  const render = (data) => {
751
+ currentData = data;
615
752
  body.replaceChildren();
616
- if (!data.total && !data.session) {
753
+ renderWishes(data);
754
+ if (!data.total && !data.session && !(data.keepsakeCount > 0)) {
617
755
  body.appendChild(el('div', { class: 'fun-empty', text: '纪念册还是空的——她收一次摊,这里就有一趟。' }));
618
756
  return;
619
757
  }
620
758
 
621
759
  body.appendChild(el('div', { class: 'fun-stats' },
622
- stat(data.total, '趟'),
760
+ stat(data.totalRecent ?? data.total, '近期行程'),
761
+ stat(data.keepsakeCount ?? 0, '珍藏'),
623
762
  stat(data.visitedAreaCount, '处逛过'),
624
763
  stat(data.souvenirCount, '件纪念品'),
625
764
  stat(data.photoCount, '张照片')));
@@ -636,8 +775,29 @@ function mountBook(ctx) {
636
775
  el('div', { class: 'fun-trip-sum', text: data.session.summary })));
637
776
  }
638
777
 
639
- body.appendChild(el('div', { class: 'fun-sec', text: `去过的 ${data.total} 趟` }));
640
- for (const t of data.trips) {
778
+ body.appendChild(el('div', { class: 'fun-bar' },
779
+ el('button', { class: 'fun-toggle', type: 'button', 'aria-pressed': keepsakesOnly ? 'true' : 'false', onclick: () => { keepsakesOnly = !keepsakesOnly; render(data); } }, keepsakesOnly ? '全部行程' : '仅看珍藏')));
780
+ const trips = keepsakesOnly ? data.trips.filter((t) => t.kept) : data.trips;
781
+ body.appendChild(el('div', { class: 'fun-sec', text: keepsakesOnly ? `珍藏行程(${trips.length})` : `近期与珍藏行程(${data.totalRecent ?? data.total})` }));
782
+ for (const t of trips) {
783
+ const err = errors.get(t.id);
784
+ const toggleKeep = async () => {
785
+ if (pending.has(t.id)) return;
786
+ pending.add(t.id);
787
+ errors.delete(t.id);
788
+ render(data);
789
+ try {
790
+ const result = await ctx.invoke('favorite', [{ id: t.id, keep: !t.kept }]);
791
+ if (!result?.ok) throw new Error(result?.error ?? '珍藏状态保存失败');
792
+ await load();
793
+ } catch (error) {
794
+ errors.set(t.id, error?.message ?? String(error));
795
+ render(data);
796
+ } finally {
797
+ pending.delete(t.id);
798
+ render(currentData ?? data);
799
+ }
800
+ };
641
801
  body.appendChild(el('div', { class: 'fun-trip' },
642
802
  el('div', { class: 'fun-trip-head' },
643
803
  el('span', { class: 'fun-trip-name', text: t.placeName }),
@@ -647,13 +807,99 @@ function mountBook(ctx) {
647
807
  ? el('div', { class: 'fun-trip-extras' },
648
808
  t.events.length ? el('div', { text: t.events.slice(0, 2).join(' / ') }) : null,
649
809
  t.scene ? el('div', { text: `生图 scene:${t.scene}${t.outfit ? ` · outfits:${t.outfit}` : ''}` }) : null)
650
- : null));
810
+ : null,
811
+ el('div', { class: 'fun-trip-actions' },
812
+ el('button', { type: 'button', disabled: pending.has(t.id) ? 'disabled' : null, onclick: toggleKeep }, pending.has(t.id) ? '保存中…' : (t.kept ? '取消珍藏' : '珍藏')),
813
+ err ? el('span', { class: 'fun-trip-error', role: 'alert', text: err }) : null)));
651
814
  }
815
+ if (keepsakesOnly && !trips.length) body.appendChild(el('div', { class: 'fun-empty', text: '还没有珍藏的行程。' }));
652
816
  };
653
817
 
654
818
  const stat = (n, label) => el('div', { class: 'fun-stat' },
655
819
  el('b', { text: String(n) }), el('span', { text: label }));
656
820
 
821
+ const load = async (propagate = false) => {
822
+ try {
823
+ const data = await ctx.invoke('list');
824
+ if (!data?.ok) throw new Error(data?.error ?? '返回不正常');
825
+ render(data);
826
+ } catch (err) {
827
+ if (propagate) throw err;
828
+ body.replaceChildren(errorCard(err));
829
+ }
830
+ };
831
+
832
+ void load();
833
+ return { refresh: load };
834
+ }
835
+
836
+ /**
837
+ * 纪念品架:跨趟归集的收藏 + 每处的集齐进度。
838
+ *
839
+ * 数据全部由服务端的 `shelf/list` 算好(`keepsakes.js` 是纯函数),
840
+ * 这里只负责画。**不自己聚合、不自己算日期**——两边各算一遍必然会不一致。
841
+ */
842
+ function mountShelf(ctx) {
843
+ const root = ctx.root;
844
+ root.replaceChildren();
845
+ const box = shell(root);
846
+ const body = el('div');
847
+ box.appendChild(body);
848
+
849
+ const stat = (n, label) => el('div', { class: 'fun-stat' },
850
+ el('b', { text: String(n) }), el('span', { text: label }));
851
+
852
+ const pct = (part) => `${part.done}/${part.total}`;
853
+
854
+ const render = (data) => {
855
+ body.replaceChildren();
856
+ if (!data.total) {
857
+ body.appendChild(el('div', { class: 'fun-empty', text: '架子上还什么都没有——她买过纪念品,这里就有了。' }));
858
+ return;
859
+ }
860
+
861
+ body.appendChild(el('div', { class: 'fun-stats' },
862
+ stat(data.total, '样东西'),
863
+ stat(data.pieces, '件'),
864
+ stat(data.places, '处地方'),
865
+ stat(data.completePlaces, '处逛遍')));
866
+
867
+ body.appendChild(el('div', { class: 'fun-meta', text: '收藏账本长期保留;详细行程可查看最近 40 趟与珍藏行程。进度按当前场所清单统计,移除或改名不删除旧回忆。' }));
868
+
869
+ body.appendChild(el('div', { class: 'fun-meta', text: '收藏账本长期保留;详细行程可查看最近 40 趟与珍藏行程。进度按当前场所清单统计,移除或改名不删除旧回忆。' }));
870
+
871
+ // 每一处的架子:只列真有东西的,空的不用占版面。
872
+ body.appendChild(el('div', { class: 'fun-sec', text: '按地方归着' }));
873
+ for (const g of data.byPlace) {
874
+ body.appendChild(el('div', { class: 'fun-trip' },
875
+ el('div', { class: 'fun-trip-head' },
876
+ el('span', { class: 'fun-trip-name', text: g.placeName }),
877
+ el('span', { class: 'fun-trip-when', text: `${g.items.length} 样 · 最早 ${g.firstDay || '—'}` })),
878
+ ...g.items.map((it) => el('details', { class: 'fun-meta' },
879
+ el('summary', { text: `${it.name}${it.times > 1 ? ` ×${it.times}` : ''} · 记录中最早 ${it.firstDay || '日期不详'}` }),
880
+ ...(it.memories ?? []).map((m) => el('div', { class: 'fun-trip-sum' },
881
+ el('div', { text: `${m.day || '日期不详'} · ${m.summary}` }),
882
+ m.note ? el('div', { text: `你记的:${m.note}` }) : null))))));
883
+ }
884
+
885
+ // 进度:只列去过的。服务端已按「快逛遍的」排好,这里照顺序画。
886
+ const visited = data.progress.filter((p) => p.visits > 0);
887
+ if (visited.length) {
888
+ body.appendChild(el('div', { class: 'fun-sec', text: `逛过的 ${visited.length} 处` }));
889
+ for (const p of visited) {
890
+ const left = p.areas.left.length;
891
+ body.appendChild(el('div', { class: 'fun-trip' },
892
+ el('div', { class: 'fun-trip-head' },
893
+ el('span', { class: 'fun-trip-name', text: p.placeName }),
894
+ el('span', { class: 'fun-trip-when', text: `去过 ${p.visits} 次 · ${p.percent}%` })),
895
+ el('div', { class: 'fun-meta', text: `逛过 ${pct(p.areas)}${p.souvenirs.total ? ` · 纪念品 ${pct(p.souvenirs)}` : ''}${p.photos.total ? ` · 拍过 ${pct(p.photos)}` : ''}` }),
896
+ left
897
+ ? el('div', { class: 'fun-trip-sum', text: `还差:${p.areas.left.slice(0, 6).join('、')}${left > 6 ? ` 等 ${left} 处` : ''}` })
898
+ : el('div', { class: 'fun-trip-sum', text: '这一处已经逛遍了。' })));
899
+ }
900
+ }
901
+ };
902
+
657
903
  const load = async () => {
658
904
  try {
659
905
  const data = await ctx.invoke('list');
@@ -675,5 +921,6 @@ export default {
675
921
  panels: {
676
922
  places: { mount: mountPlaces },
677
923
  book: { mount: mountBook },
924
+ shelf: { mount: mountShelf },
678
925
  },
679
926
  };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "cortico-world-fun",
3
- "version": "0.1.5",
3
+ "version": "0.2.0",
4
4
  "type": "module",
5
5
  "description": "娱乐时间 —— 给 Coopanion 桌宠二十处真能去逛的地方:游乐场、海洋馆、庙会、漫展、电影院、动物园、公园、电玩城、KTV、博物馆、猫咖、爬山、咖啡店、奶茶店、餐厅、图书馆、夜市、澡堂、旧货市场、江边。进门、逛摊位、买纪念品、拍张照、吃喝点什么,收摊记一笔。能和「鱼的每一天」「生图工作室」联动,但都不依赖。",
6
6
  "license": "MIT",
@@ -39,13 +39,13 @@
39
39
  "PUBLISHING.md"
40
40
  ],
41
41
  "scripts": {
42
- "test": "node test/venues.test.mjs && node test/state.test.mjs && node test/memories.test.mjs && node test/phases.test.mjs && node test/user-venues.test.mjs && node test/world.test.mjs && node test/panels.test.mjs",
42
+ "test": "node test/venues.test.mjs && node test/state.test.mjs && node test/events.test.mjs && node test/memories.test.mjs && node test/phases.test.mjs && node test/keepsakes.test.mjs && node test/user-venues.test.mjs && node test/aquarium.test.mjs && node test/wishes.test.mjs && node test/choices.test.mjs && node test/world.test.mjs && node test/panels.test.mjs",
43
43
  "verify": "node tools/fix-ps1-bom.mjs install.ps1 && node tools/check-prompt.mjs && node tools/check-isolation.mjs && node tools/smoke.mjs && node tools/make-describe.mjs --check",
44
44
  "describe": "node tools/make-describe.mjs",
45
45
  "check:publish": "node tools/publish-check.mjs --online",
46
46
  "check:isolation": "node tools/check-isolation.mjs",
47
47
  "verify:published": "node tools/verify-published.mjs",
48
- "prepublishOnly": "node test/venues.test.mjs && node test/state.test.mjs && node test/memories.test.mjs && node test/phases.test.mjs && node test/user-venues.test.mjs && node test/world.test.mjs && node test/panels.test.mjs && node tools/check-prompt.mjs && node tools/check-isolation.mjs && node tools/smoke.mjs && node tools/make-describe.mjs --check && node tools/publish-check.mjs --online"
48
+ "prepublishOnly": "node test/venues.test.mjs && node test/state.test.mjs && node test/events.test.mjs && node test/memories.test.mjs && node test/phases.test.mjs && node test/keepsakes.test.mjs && node test/user-venues.test.mjs && node test/aquarium.test.mjs && node test/wishes.test.mjs && node test/choices.test.mjs && node test/world.test.mjs && node test/panels.test.mjs && node tools/check-prompt.mjs && node tools/check-isolation.mjs && node tools/smoke.mjs && node tools/make-describe.mjs --check && node tools/publish-check.mjs --online"
49
49
  },
50
50
  "cortico": {
51
51
  "kind": "world",