cortico-world-fun 0.1.6 → 0.2.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 +28 -1
- package/PUBLISHING.md +30 -1
- package/README.md +34 -3
- package/describe.json +150 -22
- package/dist/webui.js +329 -67
- package/package.json +3 -3
- package/src/ENV_PROMPT.md +8 -40
- package/src/aquarium.js +27 -0
- package/src/choices.js +54 -0
- package/src/definition.js +30 -14
- package/src/events.js +71 -0
- package/src/keepsakes.js +36 -175
- package/src/names.js +9 -0
- package/src/state.js +115 -5
- package/src/venues.js +2 -3
- package/src/wishes.js +114 -0
- package/src/world.js +287 -115
package/src/world.js
CHANGED
|
@@ -14,7 +14,7 @@
|
|
|
14
14
|
* `lifeFreeMenu` 那一行顺手一提,或者她自己 `fun_start`。
|
|
15
15
|
* 这是刻意的——两套叫醒会互相抢时间轴,而联动本来靠的就是提示词。
|
|
16
16
|
*
|
|
17
|
-
* 状态是纯 JSON,落在 `<dataDir>/fun/state.json
|
|
17
|
+
* 状态是纯 JSON,落在 `<dataDir>/fun/state.json`;历史保留,跨天仅清理过期行程。
|
|
18
18
|
*
|
|
19
19
|
* 红线(World 契约):不调别的 World 的工具、不读别人的状态或日程文件、
|
|
20
20
|
* `envPromptVars()` 永不抛错、`create()` 保持纯。
|
|
@@ -39,10 +39,15 @@ import {
|
|
|
39
39
|
mergeVenues, parseVenueFile, stringifyVenueFile,
|
|
40
40
|
} from './user-venues.js';
|
|
41
41
|
import { collectSouvenirs, progressFor, progressLine } from './keepsakes.js';
|
|
42
|
+
import { resolveName } from './names.js';
|
|
43
|
+
import { filterEventsForArea } from './events.js';
|
|
44
|
+
import { aquariumDetail, aquariumEventDetail } from './aquarium.js';
|
|
45
|
+
import { applyChoice, choiceForEvent } from './choices.js';
|
|
46
|
+
import { addWish, changeWish, fulfillWishes } from './wishes.js';
|
|
42
47
|
import {
|
|
43
|
-
buySouvenir, closeSession, dayIn, enterVenue, hmIn, isStale, minutesIn,
|
|
44
|
-
newState, normalizeState,
|
|
45
|
-
|
|
48
|
+
buySouvenir, closeSession, dayIn, enterVenue, favoriteTrip, hmIn, isStale, minutesIn,
|
|
49
|
+
newState, normalizeState, recentPlaceIds, recordConsume,
|
|
50
|
+
takePhoto, tripDay, tripSummary, visitedText, wanderOnce,
|
|
46
51
|
} from './state.js';
|
|
47
52
|
|
|
48
53
|
const ENV_PROMPT = fileURLToPath(new URL('./ENV_PROMPT.md', import.meta.url));
|
|
@@ -68,7 +73,7 @@ export const FUN_TOOL_DECLS = [
|
|
|
68
73
|
{
|
|
69
74
|
name: 'fun_places',
|
|
70
75
|
tags: ['read', 'snapshot'],
|
|
71
|
-
description: '
|
|
76
|
+
description: '查询当前可去地点,默认按营业状态和拥挤度排序;all 列出全部,kind 筛选类别。地点名以此工具返回为准。',
|
|
72
77
|
parameters: {
|
|
73
78
|
type: 'object',
|
|
74
79
|
properties: {
|
|
@@ -85,7 +90,7 @@ export const FUN_TOOL_DECLS = [
|
|
|
85
90
|
{
|
|
86
91
|
name: 'fun_go',
|
|
87
92
|
tags: ['write'],
|
|
88
|
-
description: '
|
|
93
|
+
description: '开始一趟出游并返回当前时段的地点描写与可逛项目。place 必填,使用 fun_places 返回的地点名或别名。',
|
|
89
94
|
parameters: {
|
|
90
95
|
type: 'object',
|
|
91
96
|
properties: {
|
|
@@ -99,7 +104,7 @@ export const FUN_TOOL_DECLS = [
|
|
|
99
104
|
{
|
|
100
105
|
name: 'fun_wander',
|
|
101
106
|
tags: ['write'],
|
|
102
|
-
description: '
|
|
107
|
+
description: '在当前地点逛一个项目;可选 buy/photo/consume 记录本次真实收获。若回执含 choiceId/optionId,先用 fun_choice 处理再继续。',
|
|
103
108
|
parameters: {
|
|
104
109
|
type: 'object',
|
|
105
110
|
properties: {
|
|
@@ -116,10 +121,24 @@ export const FUN_TOOL_DECLS = [
|
|
|
116
121
|
additionalProperties: false,
|
|
117
122
|
},
|
|
118
123
|
},
|
|
124
|
+
{
|
|
125
|
+
name: 'fun_choice',
|
|
126
|
+
tags: ['write'],
|
|
127
|
+
description: '处理 fun_wander 回执中出现的待选择事件。按回执提供的 choiceId 和 optionId 选一个,不会凭空添加收获。',
|
|
128
|
+
parameters: {
|
|
129
|
+
type: 'object',
|
|
130
|
+
properties: {
|
|
131
|
+
choiceId: { type: 'string', description: '待选择事件回执给出的 choiceId。' },
|
|
132
|
+
optionId: { type: 'string', description: '待选择事件回执给出的 optionId。' },
|
|
133
|
+
},
|
|
134
|
+
required: ['choiceId', 'optionId'],
|
|
135
|
+
additionalProperties: false,
|
|
136
|
+
},
|
|
137
|
+
},
|
|
119
138
|
{
|
|
120
139
|
name: 'fun_home',
|
|
121
140
|
tags: ['write'],
|
|
122
|
-
description: '
|
|
141
|
+
description: '结束当前行程并返回摘要及记录提示。note 可选,记录一句本趟感受。',
|
|
123
142
|
parameters: {
|
|
124
143
|
type: 'object',
|
|
125
144
|
properties: {
|
|
@@ -131,7 +150,7 @@ export const FUN_TOOL_DECLS = [
|
|
|
131
150
|
{
|
|
132
151
|
name: 'fun_start',
|
|
133
152
|
tags: ['read'],
|
|
134
|
-
description: '
|
|
153
|
+
description: '查看当前推荐地点;详细筛选用 fun_places。',
|
|
135
154
|
parameters: {
|
|
136
155
|
type: 'object',
|
|
137
156
|
properties: {},
|
|
@@ -140,7 +159,7 @@ export const FUN_TOOL_DECLS = [
|
|
|
140
159
|
{
|
|
141
160
|
name: 'fun_view',
|
|
142
161
|
tags: ['read', 'snapshot'],
|
|
143
|
-
description: '
|
|
162
|
+
description: '按需查询近期或珍藏的行程记录。',
|
|
144
163
|
parameters: {
|
|
145
164
|
type: 'object',
|
|
146
165
|
properties: {
|
|
@@ -149,10 +168,47 @@ export const FUN_TOOL_DECLS = [
|
|
|
149
168
|
additionalProperties: false,
|
|
150
169
|
},
|
|
151
170
|
},
|
|
171
|
+
{
|
|
172
|
+
name: 'fun_wishes',
|
|
173
|
+
tags: ['read', 'snapshot'],
|
|
174
|
+
description: '查看出游心愿及状态;只有明确说过想去、想做的事才会记录,不会催促。',
|
|
175
|
+
parameters: { type: 'object', properties: {}, additionalProperties: false },
|
|
176
|
+
},
|
|
177
|
+
{
|
|
178
|
+
name: 'fun_wish',
|
|
179
|
+
tags: ['write'],
|
|
180
|
+
description: '记录明确表达的出游心愿,或暂缓、恢复、取消。先选地点;项目、时段、纪念品须填真实清单正名。不会替你出游,也不按旧行程补完成。',
|
|
181
|
+
parameters: {
|
|
182
|
+
type: 'object',
|
|
183
|
+
properties: {
|
|
184
|
+
action: { type: 'string', enum: ['add', 'pause', 'resume', 'cancel'] },
|
|
185
|
+
id: { type: 'string', description: '管理现有心愿时填 fun_wishes 给出的 ID。' },
|
|
186
|
+
place: { type: 'string', description: '新增心愿的地点名,别名也认。' },
|
|
187
|
+
type: { type: 'string', enum: ['visit', 'area', 'phase', 'souvenir'] },
|
|
188
|
+
target: { type: 'string', description: '项目/时段/纪念品正名;visit 不填。' },
|
|
189
|
+
reason: { type: 'string', description: '你明确表达的缘由,可选,不凭空猜测偏好。' },
|
|
190
|
+
},
|
|
191
|
+
required: ['action'], additionalProperties: false,
|
|
192
|
+
},
|
|
193
|
+
},
|
|
194
|
+
{
|
|
195
|
+
name: 'fun_keepsake',
|
|
196
|
+
tags: ['write'],
|
|
197
|
+
description: '用 fun_view 的行程 ID 珍藏或取消珍藏一趟已收摊的行程。珍藏独立保留,不影响收藏账本。',
|
|
198
|
+
parameters: {
|
|
199
|
+
type: 'object',
|
|
200
|
+
properties: {
|
|
201
|
+
id: { type: 'string', description: '行程 ID,来自纪念册(fun_view)。' },
|
|
202
|
+
keep: { type: 'boolean', description: 'true 珍藏,false 取消珍藏。' },
|
|
203
|
+
},
|
|
204
|
+
required: ['id'],
|
|
205
|
+
additionalProperties: false,
|
|
206
|
+
},
|
|
207
|
+
},
|
|
152
208
|
{
|
|
153
209
|
name: 'fun_shelf',
|
|
154
210
|
tags: ['read', 'snapshot'],
|
|
155
|
-
description: '
|
|
211
|
+
description: '按地点查询长期纪念品收藏和收集进度。',
|
|
156
212
|
parameters: {
|
|
157
213
|
type: 'object',
|
|
158
214
|
properties: {
|
|
@@ -305,30 +361,9 @@ export class FunWorld {
|
|
|
305
361
|
// 提示词
|
|
306
362
|
// -------------------------------------------------------------------------
|
|
307
363
|
|
|
308
|
-
/**
|
|
309
|
-
* 只放**一天变不了几次**的东西:二十处场所的正名与别名。
|
|
310
|
-
*
|
|
311
|
-
* 二十处全列细节会顶掉几百 token 的常驻前缀,所以这里**只列名字和别名**,
|
|
312
|
-
* 细节留给 `fun_places` / `fun_go` 按需给。生图素材库里有的那几处后面带一句
|
|
313
|
-
* 「scene 填「X」」;没有的不带——**不能让她以为每处都有 scene 可填**。
|
|
314
|
-
*
|
|
315
|
-
* 「此刻在逛哪儿」不进前缀——那是 `fun_wander` 和收摊回执的事。
|
|
316
|
-
* 这个方法绝不能抛错:契约里抛错会把整个 World 卸载掉。
|
|
317
|
-
*/
|
|
364
|
+
/** This World adds no dynamic venue list to the always-present prompt. */
|
|
318
365
|
envPromptVars() {
|
|
319
|
-
|
|
320
|
-
if (!this.#on()) return { fun_places_block: '' };
|
|
321
|
-
const lines = ['(能去逛的地方:)'];
|
|
322
|
-
for (const v of this.#places()) {
|
|
323
|
-
const alias = v.aliases.length ? `(也叫 ${v.aliases.slice(0, 3).join('、')})` : '';
|
|
324
|
-
const scene = hasScene(v) ? ` 生图 scene 填「${v.scene}」` : '';
|
|
325
|
-
lines.push(`- ${v.name}${alias}${scene}`);
|
|
326
|
-
}
|
|
327
|
-
return { fun_places_block: lines.join('\n') };
|
|
328
|
-
} catch (err) {
|
|
329
|
-
this.#host?.log?.warn?.('娱乐时间:场所清单算不出来', { err: msg(err) });
|
|
330
|
-
return { fun_places_block: '' };
|
|
331
|
-
}
|
|
366
|
+
return { fun_places_block: '' };
|
|
332
367
|
}
|
|
333
368
|
|
|
334
369
|
// -------------------------------------------------------------------------
|
|
@@ -358,14 +393,85 @@ export class FunWorld {
|
|
|
358
393
|
case 'fun_places': return this.#placesTool(args);
|
|
359
394
|
case 'fun_go': return await this.#goTool(args);
|
|
360
395
|
case 'fun_wander': return await this.#wanderTool(args);
|
|
396
|
+
case 'fun_choice': return await this.#choiceTool(args);
|
|
361
397
|
case 'fun_home': return await this.#homeTool(args);
|
|
362
398
|
case 'fun_start': return this.#startTool();
|
|
363
399
|
case 'fun_view': return this.#viewTool(args);
|
|
400
|
+
case 'fun_wishes': { this.#state = this.#normalizeState(); return { text: this.#wishesText() }; }
|
|
401
|
+
case 'fun_wish': {
|
|
402
|
+
const result = await this.#manageWish(args);
|
|
403
|
+
return { text: result.ok ? this.#wishesText() : result.error, ...(result.ok ? {} : { failed: true }) };
|
|
404
|
+
}
|
|
405
|
+
case 'fun_keepsake': return await this.#keepsakeTool(args);
|
|
364
406
|
case 'fun_shelf': return this.#shelfTool(args);
|
|
365
407
|
default: return { text: `[${name} 失败] 不认识这个工具。`, failed: true };
|
|
366
408
|
}
|
|
367
409
|
}
|
|
368
410
|
|
|
411
|
+
#wishesText() {
|
|
412
|
+
const labels = { active: '想去', paused: '暂缓', completed: '已完成', cancelled: '已取消' };
|
|
413
|
+
const wishes = this.#state.wishes ?? [];
|
|
414
|
+
if (!wishes.length) return '还没有出游心愿。只有明确想去或想做时才记录,不需要凑任务。';
|
|
415
|
+
return ['出游心愿(不会催促):', ...wishes.map((w) => `- [${labels[w.status]}] ${w.placeName}${w.target ? ` · ${w.target}` : ''}${w.reason ? `:${w.reason}` : ''}(ID:${w.id})`)].join('\n');
|
|
416
|
+
}
|
|
417
|
+
|
|
418
|
+
async #choiceTool(args) {
|
|
419
|
+
const session = this.#state.session;
|
|
420
|
+
if (!session?.pendingChoice) return { text: '现在没有待选择的事件。', failed: true };
|
|
421
|
+
if (args?.choiceId !== session.pendingChoice.id) return { text: '这不是当前这条待选择事件,请按最新回执里的 choiceId 选择。', failed: true };
|
|
422
|
+
const result = applyChoice(session.pendingChoice, args?.optionId);
|
|
423
|
+
if (!result.ok) return { text: result.error, failed: true };
|
|
424
|
+
session.choices = Array.isArray(session.choices) ? session.choices : [];
|
|
425
|
+
session.choices.push({ event: result.choice.event, option: result.option.id, result: result.option.result, at: this.#now() });
|
|
426
|
+
session.pendingChoice = null;
|
|
427
|
+
session.lastAt = this.#now();
|
|
428
|
+
await this.#save();
|
|
429
|
+
return { text: `你选择了「${result.option.label}」。${result.option.result}。` };
|
|
430
|
+
}
|
|
431
|
+
|
|
432
|
+
async #manageWish(args) {
|
|
433
|
+
const action = args?.action;
|
|
434
|
+
const now = this.#now();
|
|
435
|
+
let result;
|
|
436
|
+
if (action === 'add') {
|
|
437
|
+
const venue = this.#places().find((v) => v.id === args?.placeId) ?? findVenue(this.#places(), args?.place);
|
|
438
|
+
if (!venue) return { ok: false, error: '请先选择一个现有地点;fun_places 可以查看地点清单。' };
|
|
439
|
+
const type = args?.type;
|
|
440
|
+
const rawTarget = typeof args?.target === 'string' ? args.target.trim() : '';
|
|
441
|
+
const lists = { area: venue.areas, phase: (venue.phases ?? []).map((p) => p.label), souvenir: venue.souvenirs };
|
|
442
|
+
if (!['visit', 'area', 'phase', 'souvenir'].includes(type)) return { ok: false, error: '心愿类型请选择 visit、area、phase 或 souvenir。' };
|
|
443
|
+
if (type !== 'visit' && !lists[type]?.includes(rawTarget)) return { ok: false, error: `这处没有这个目标;可填:${(lists[type] ?? []).join('、') || '暂无此类目标'}。` };
|
|
444
|
+
result = addWish(this.#state.wishes, { placeId: venue.id, placeName: venue.name, type, target: type === 'visit' ? '' : rawTarget, reason: args.reason }, now);
|
|
445
|
+
} else {
|
|
446
|
+
result = changeWish(this.#state.wishes, args?.id, action, now);
|
|
447
|
+
}
|
|
448
|
+
if (result.error) return { ok: false, error: result.error };
|
|
449
|
+
const previous = this.#state.wishes;
|
|
450
|
+
this.#state.wishes = result.wishes;
|
|
451
|
+
try { await this.#save(); } catch (err) { this.#state.wishes = previous; throw err; }
|
|
452
|
+
return { ok: true, wish: result.wish, duplicate: result.duplicate ?? false };
|
|
453
|
+
}
|
|
454
|
+
|
|
455
|
+
#completeWishes(facts) {
|
|
456
|
+
const result = fulfillWishes(this.#state.wishes, facts, this.#now());
|
|
457
|
+
this.#state.wishes = result.wishes;
|
|
458
|
+
return result.completed;
|
|
459
|
+
}
|
|
460
|
+
|
|
461
|
+
#wishRecommendation(venue, nowMin) {
|
|
462
|
+
if (hoursState(venue, nowMin) === 'closed') return '';
|
|
463
|
+
const wish = (this.#state.wishes ?? []).find((w) => w.status === 'active' && w.placeId === venue.id
|
|
464
|
+
&& (w.type !== 'phase' || phaseLabelAt(venue, nowMin) === w.target)
|
|
465
|
+
&& (w.type !== 'area' || areasNow(venue, nowMin).includes(w.target))
|
|
466
|
+
&& (w.type !== 'souvenir' || venue.souvenirs.includes(w.target)));
|
|
467
|
+
return wish ? `有个心愿:${wish.type === 'visit' ? `想去${venue.name}` : `想${wish.type === 'souvenir' ? '拿到' : '看看'}${wish.target}`}${wish.reason ? `(${wish.reason})` : ''}` : '';
|
|
468
|
+
}
|
|
469
|
+
|
|
470
|
+
#wishRank(picks, nowMin) {
|
|
471
|
+
return picks.map((p, i) => ({ ...p, i, wishReason: this.#wishRecommendation(p.venue, nowMin) }))
|
|
472
|
+
.sort((a, b) => rankOf(a.state) - rankOf(b.state) || Number(Boolean(b.wishReason)) - Number(Boolean(a.wishReason)) || a.i - b.i);
|
|
473
|
+
}
|
|
474
|
+
|
|
369
475
|
#placesTool(args) {
|
|
370
476
|
const now = this.#now();
|
|
371
477
|
const nowMin = minutesIn(this.timezone, now);
|
|
@@ -399,14 +505,17 @@ export class FunWorld {
|
|
|
399
505
|
.map((venue) => ({ venue, state: hoursState(venue, nowMin) }))
|
|
400
506
|
.sort((a, b) => rankOf(a.state) - rankOf(b.state));
|
|
401
507
|
} else {
|
|
402
|
-
picks =
|
|
508
|
+
picks = allPlaces(nowMin, avoid, places);
|
|
403
509
|
}
|
|
510
|
+
picks = this.#wishRank(picks, nowMin);
|
|
511
|
+
if (!all && !kindFilter) picks = picks.slice(0, count);
|
|
404
512
|
|
|
405
513
|
const lines = [`这会儿 ${hmIn(this.timezone, now)},能去逛的:`];
|
|
406
|
-
for (const { venue, state } of picks) {
|
|
514
|
+
for (const { venue, state, wishReason } of picks) {
|
|
407
515
|
const bits = [`${venue.name}(${STATE_LABEL[state]},${CROWD_LABEL[venue.crowd] || '人不少'})`];
|
|
408
516
|
bits.push(`${venue.hours.open}–${venue.hours.close}`);
|
|
409
517
|
bits.push(`能逛:${venue.areas.slice(0, 5).join('、')}`);
|
|
518
|
+
if (wishReason) bits.push(wishReason);
|
|
410
519
|
lines.push(`- ${bits.join(';')}`);
|
|
411
520
|
}
|
|
412
521
|
if (this.#state.session) {
|
|
@@ -439,6 +548,7 @@ export class FunWorld {
|
|
|
439
548
|
text: `你已经在「${this.#state.session.placeName}」逛着了(${visitedText(this.#state.session)})。\n要么接着 fun_wander,要么 fun_home 收了再换地方。`,
|
|
440
549
|
};
|
|
441
550
|
}
|
|
551
|
+
const completedWishes = this.#completeWishes({ placeId: venue.id, phase: phaseLabelAt(venue, minutesIn(this.timezone, now)) });
|
|
442
552
|
await this.#save();
|
|
443
553
|
|
|
444
554
|
// 时段气氛:江边清早和夜里不是一回事,所以描写和可逛的项目都按此刻取。
|
|
@@ -446,13 +556,14 @@ export class FunWorld {
|
|
|
446
556
|
const label = phaseLabelAt(venue, nowMin);
|
|
447
557
|
|
|
448
558
|
const lines = [`进了${venue.name}${label ? `(${label})` : ''}。`, descNow(venue, nowMin)];
|
|
559
|
+
if (completedWishes.length) lines.push(`完成了心愿:${completedWishes.map((w) => w.target || `去${w.placeName}`).join('、')}。`);
|
|
449
560
|
if (args?.company) lines.push(`跟${String(args.company).slice(0, 40)}一起。`);
|
|
450
561
|
if (state === 'closingSoon') lines.push(`(快到打烊时间了,${venue.hours.close} 就关,别排太长的队。)`);
|
|
451
562
|
if (state === 'closed') lines.push(`(其实这会儿已经过了开放时段(${venue.hours.open}–${venue.hours.close}),当它开着逛也行,只是别写外头太亮。)`);
|
|
452
563
|
lines.push(`能逛的:${areasNow(venue, nowMin).join('、')}。`);
|
|
453
|
-
if (
|
|
454
|
-
|
|
455
|
-
}
|
|
564
|
+
if (venue.souvenirs?.length) lines.push(`纪念品:${venue.souvenirs.join('、')}。`);
|
|
565
|
+
if (venue.photoSpots?.length) lines.push(`拍照点:${venue.photoSpots.join('、')}。`);
|
|
566
|
+
if (hasFood(venue)) lines.push(`可${venue.food.verb}:${venue.food.items.join('、')}。`);
|
|
456
567
|
// 有分时段的场所,提醒一句「换个时间来是另一副样子」——这是这个世界最耐玩的地方。
|
|
457
568
|
const phaseCount = Array.isArray(venue.phases) ? venue.phases.length : 0;
|
|
458
569
|
if (phaseCount > 1) {
|
|
@@ -473,22 +584,14 @@ export class FunWorld {
|
|
|
473
584
|
// 只在够格时出现(5 趟起),且和上面那句分开放,免得事实和关系糊成一团。
|
|
474
585
|
const regular = regularLine(history, venue.name);
|
|
475
586
|
if (regular) lines.push(regular);
|
|
476
|
-
|
|
477
|
-
// 还差哪几处:用**这一处自己的完整清单**(不是此刻被时段收窄的那份),
|
|
478
|
-
// 和集齐进度共用一份数据,别让两句话各算各的又各说一遍。
|
|
479
587
|
const prog = progressFor(venue, this.#state.trips);
|
|
480
588
|
if (prog.areas.left.length) {
|
|
481
|
-
|
|
482
|
-
const more = prog.areas.left.length - shown.length;
|
|
483
|
-
lines.push(`还没去过:${shown.join('、')}${more > 0 ? ` 等 ${prog.areas.left.length} 处` : ''}。`);
|
|
484
|
-
}
|
|
485
|
-
// 纪念品集齐了值得说一句;没集齐不报数(「还差两件纪念品」是清单口气)。
|
|
486
|
-
if (prog.souvenirs.complete && prog.souvenirs.total) {
|
|
487
|
-
lines.push(`(这儿的纪念品你集齐了:${prog.souvenirs.got.join('、')}。)`);
|
|
589
|
+
lines.push(`还没去过:${prog.areas.left.slice(0, 4).join('、')}${prog.areas.left.length > 4 ? ` 等 ${prog.areas.left.length} 处` : ''}。`);
|
|
488
590
|
}
|
|
591
|
+
|
|
489
592
|
}
|
|
490
593
|
|
|
491
|
-
lines.push('一处一处来:fun_wander 逛一处(不填 area
|
|
594
|
+
lines.push('一处一处来:fun_wander 逛一处(不填 area 就自动挑一个没逛过的),看到纪念品/拍照点会用得了;遇到需要决定的事件,先用 fun_choice 选完再继续。');
|
|
492
595
|
return { text: lines.join('\n') };
|
|
493
596
|
}
|
|
494
597
|
|
|
@@ -497,8 +600,11 @@ export class FunWorld {
|
|
|
497
600
|
const day = dayIn(this.timezone, now);
|
|
498
601
|
this.#state = this.#normalizeState();
|
|
499
602
|
const session = this.#state.session;
|
|
603
|
+
if (session?.pendingChoice) {
|
|
604
|
+
return { text: `上一处还有待选择事件(choiceId:${session.pendingChoice.id}),请先用 fun_choice 选择后再继续。` };
|
|
605
|
+
}
|
|
500
606
|
if (!session) {
|
|
501
|
-
return { text:
|
|
607
|
+
return { text: '你还没进门呢。先用 fun_places 选地点,再用 fun_go 进门。' };
|
|
502
608
|
}
|
|
503
609
|
const places = this.#places();
|
|
504
610
|
// venueById 只认预设;自填地点要在这份合并表里按 id 查,否则用户加的地方
|
|
@@ -527,7 +633,6 @@ export class FunWorld {
|
|
|
527
633
|
// 两池都先滤掉碰过的,再按 `eventPool` 决定这次从哪个池子里抽。
|
|
528
634
|
const rarePool = filterRepeatedEvents(rareEventsNow(venue, nowMin), pastHistory);
|
|
529
635
|
const visitsBefore = pastHistory?.visitCount ?? 0;
|
|
530
|
-
const chosenPool = eventPool(liveEvents, rarePool, visitsBefore, this.#random);
|
|
531
636
|
|
|
532
637
|
// 指定了没逛过的项目就用它,否则自动挑。
|
|
533
638
|
//
|
|
@@ -546,16 +651,14 @@ export class FunWorld {
|
|
|
546
651
|
const allHere = (venue.areas || []).includes(wanted) ? '(这会儿还没开)' : '';
|
|
547
652
|
areaMiss = `${venue.name}没有「${wanted}」这处${allHere}。这会儿能逛的是:${liveAreas.join('、')}。`;
|
|
548
653
|
} else {
|
|
549
|
-
const ev = pickEvent(chosenPool, session.events, this.#random);
|
|
550
654
|
if (!session.visited.some((v) => v.area === hit)) {
|
|
551
655
|
session.visited.push({ area: hit, note: String(args?.note ?? '').slice(0, 120), at: now });
|
|
552
656
|
}
|
|
553
657
|
session.lastAt = now;
|
|
554
|
-
|
|
555
|
-
picked = { area: hit, event: ev };
|
|
658
|
+
picked = { area: hit, event: null };
|
|
556
659
|
}
|
|
557
660
|
} else {
|
|
558
|
-
picked = wanderOnce(this.#state, venue, now, this.#random, liveAreas,
|
|
661
|
+
picked = wanderOnce(this.#state, venue, now, this.#random, liveAreas, []);
|
|
559
662
|
if (!picked) {
|
|
560
663
|
return { text: `${venue.name}这几处你都逛过了。${this.#homeHint()}` };
|
|
561
664
|
}
|
|
@@ -572,32 +675,55 @@ export class FunWorld {
|
|
|
572
675
|
const buyName = typeof args?.buy === 'string' ? args.buy.trim() : '';
|
|
573
676
|
const photoName = typeof args?.photo === 'string' ? args.photo.trim() : '';
|
|
574
677
|
const eatName = typeof args?.consume === 'string' ? args.consume.trim() : '';
|
|
575
|
-
const belongs = (list, name) => (list || []).some((x) => x.includes(name) || name.includes(x));
|
|
576
|
-
|
|
577
678
|
const misfit = [];
|
|
679
|
+
const resolve = (list, name, missing) => {
|
|
680
|
+
const match = resolveName(list, name);
|
|
681
|
+
if (match.name) return match.name;
|
|
682
|
+
misfit.push(match.candidates.length > 1
|
|
683
|
+
? `「${name}」能对应多样:${match.candidates.join('、')},请填完整名字,这次没记`
|
|
684
|
+
: missing);
|
|
685
|
+
return null;
|
|
686
|
+
};
|
|
687
|
+
|
|
578
688
|
let bought = null;
|
|
579
689
|
if (buyName) {
|
|
580
|
-
|
|
581
|
-
|
|
690
|
+
const name = resolve(venue.souvenirs, buyName, `「${buyName}」不是${venue.name}的东西,没记`);
|
|
691
|
+
if (name) bought = buySouvenir(this.#state, name, now);
|
|
582
692
|
}
|
|
583
693
|
let shot = null;
|
|
584
694
|
if (photoName) {
|
|
585
|
-
|
|
586
|
-
|
|
695
|
+
const name = resolve(venue.photoSpots, photoName, `「${photoName}」不是${venue.name}的拍照点,没记`);
|
|
696
|
+
if (name) shot = takePhoto(this.#state, name, now);
|
|
587
697
|
}
|
|
588
698
|
// 吃了/喝了什么:只记「这处地方供得出来」的品类,且**只记名字不记味道**。
|
|
589
699
|
let ate = null;
|
|
590
700
|
if (eatName) {
|
|
591
701
|
if (!hasFood(venue)) misfit.push(`${venue.name}没有能吃能喝的,没记`);
|
|
592
|
-
else
|
|
593
|
-
|
|
702
|
+
else {
|
|
703
|
+
const name = resolve(venue.food.items, eatName, `「${eatName}」不是${venue.name}有的,没记`);
|
|
704
|
+
if (name) ate = recordConsume(this.#state, venue, name, now);
|
|
705
|
+
}
|
|
706
|
+
}
|
|
707
|
+
// 项目和已验证的收获确定后才抽事件,避免串项目或凭空获得东西。
|
|
708
|
+
if (picked) {
|
|
709
|
+
const common = filterEventsForArea(liveEvents, picked.area, venue, session);
|
|
710
|
+
const rare = filterEventsForArea(rarePool, picked.area, venue, session);
|
|
711
|
+
const chosenPool = eventPool(common, rare, visitsBefore, this.#random);
|
|
712
|
+
picked.event = pickEvent(chosenPool, session.events, this.#random);
|
|
713
|
+
if (picked.event) {
|
|
714
|
+
session.events.push(picked.event);
|
|
715
|
+
const choice = choiceForEvent(picked.event, { area: picked.area });
|
|
716
|
+
if (choice && !session.pendingChoice) session.pendingChoice = choice;
|
|
717
|
+
}
|
|
594
718
|
}
|
|
719
|
+
const completedWishes = this.#completeWishes({ placeId: venue.id, area: picked?.area ?? '', phase: phaseName, souvenirs: bought && !bought.duplicate ? [bought.item] : [] });
|
|
595
720
|
await this.#save();
|
|
596
721
|
|
|
597
722
|
// 点的那处不存在:不编一个「逛了」,把能逛的如实递给她,买/拍照/吃喝照常结算
|
|
598
723
|
// (她可能就是想在那儿买点东西,没必要连这个也拦掉)。
|
|
599
724
|
if (areaMiss) {
|
|
600
725
|
const lines = [`(${areaMiss})`];
|
|
726
|
+
if (completedWishes.length) lines.push(`完成了心愿:${completedWishes.map((w) => w.target || `去${w.placeName}`).join('、')}。`);
|
|
601
727
|
if (bought) lines.push(bought.duplicate ? `(${bought.item} 你之前已经买过了。)` : `买了:${bought.item}。`);
|
|
602
728
|
if (shot) lines.push(shot.duplicate ? `(${shot.spot} 已经拍过了。)` : `拍了张照:${shot.spot}。`);
|
|
603
729
|
if (ate) lines.push(ate.duplicate ? `(${ate.item} 你这一趟已经${ate.verb}过了。)` : `${ate.verb}了:${ate.item}。`);
|
|
@@ -607,46 +733,31 @@ export class FunWorld {
|
|
|
607
733
|
}
|
|
608
734
|
|
|
609
735
|
const lines = [`${venue.name}${phaseName ? `(${phaseName})` : ''} · ${picked.area}`, this.#areaLine(venue, picked.area, nowMin)];
|
|
610
|
-
if (
|
|
611
|
-
|
|
612
|
-
|
|
613
|
-
|
|
614
|
-
|
|
615
|
-
|
|
616
|
-
|
|
617
|
-
|
|
618
|
-
lines.push(
|
|
736
|
+
if (completedWishes.length) lines.push(`完成了心愿:${completedWishes.map((w) => w.target || `去${w.placeName}`).join('、')}。`);
|
|
737
|
+
if (picked.event) {
|
|
738
|
+
lines.push(`——${picked.event}`);
|
|
739
|
+
const detail = aquariumEventDetail(picked.event, picked.area);
|
|
740
|
+
if (detail) lines.push(detail);
|
|
741
|
+
if (session.pendingChoice?.event === picked.event) {
|
|
742
|
+
const c = session.pendingChoice;
|
|
743
|
+
lines.push(`需要你选一下(choiceId:${c.id}):${c.prompt}`);
|
|
744
|
+
lines.push(c.options.map((o) => `${o.id}:${o.label}`).join(' / '));
|
|
745
|
+
lines.push('请用 fun_choice 填 choiceId 和 optionId;选完再继续下一处。');
|
|
619
746
|
}
|
|
620
747
|
}
|
|
621
748
|
const last = session.visited[session.visited.length - 1];
|
|
622
749
|
if (last?.note) lines.push(`(你记的:${last.note})`);
|
|
623
750
|
|
|
624
|
-
const spots = photoSpotsFor(session, venue);
|
|
625
|
-
const goods = souvenirsFor(session, venue);
|
|
626
751
|
if (bought) lines.push(bought.duplicate ? `(${bought.item} 你之前已经买过了。)` : `买了:${bought.item}。`);
|
|
627
752
|
if (shot) lines.push(shot.duplicate ? `(${shot.spot} 已经拍过了。)` : `拍了张照:${shot.spot}。`);
|
|
628
753
|
if (ate) lines.push(ate.duplicate ? `(${ate.item} 你这一趟已经${ate.verb}过了。)` : `${ate.verb}了:${ate.item}。`);
|
|
629
754
|
for (const m of misfit) lines.push(`(${m}。)`);
|
|
630
|
-
|
|
631
|
-
if (spots.length) lines.push(`还能拍的:${spots.slice(0, 3).join('、')}。`);
|
|
632
|
-
if (goods.length) lines.push(`还能买的:${goods.slice(0, 4).join('、')}。`);
|
|
633
|
-
|
|
634
|
-
// ---- 吃 / 喝:本插件只说「这儿有得吃」,味道交给鱼的每一天 ----
|
|
635
|
-
if (hasFood(venue)) {
|
|
636
|
-
const f = venue.food;
|
|
637
|
-
lines.push(`这儿能${f.verb}:${f.items.join('、')}。`);
|
|
638
|
-
lines.push(this.#foodHint(venue));
|
|
639
|
-
}
|
|
755
|
+
if (hasFood(venue) && ate) lines.push(this.#foodHint(venue));
|
|
640
756
|
|
|
641
|
-
const total = venue.areas.length;
|
|
642
|
-
const got = session.visited.length;
|
|
643
|
-
lines.push(`这一趟逛了 ${got} 处(${visitedText(session)})。`);
|
|
644
757
|
if (staleBefore) {
|
|
645
758
|
lines.push(`(这一趟挂得有点久了,上一次动是 ${hmIn(this.timezone, idleSince)}。想收就用 fun_home。)`);
|
|
646
|
-
} else if (
|
|
759
|
+
} else if (session.visited.length >= venue.areas.length) {
|
|
647
760
|
lines.push('这儿差不多逛遍了。');
|
|
648
|
-
} else {
|
|
649
|
-
lines.push('还想逛就接着 fun_wander;逛够了就 fun_home 收摊。');
|
|
650
761
|
}
|
|
651
762
|
return { text: lines.join('\n') };
|
|
652
763
|
}
|
|
@@ -697,20 +808,33 @@ export class FunWorld {
|
|
|
697
808
|
const now = this.#now();
|
|
698
809
|
const nowMin = minutesIn(this.timezone, now);
|
|
699
810
|
const places = this.#places();
|
|
700
|
-
const picks =
|
|
811
|
+
const picks = this.#wishRank(allPlaces(nowMin, recentPlaceIds(this.#state, 2), places), nowMin).slice(0, 5);
|
|
701
812
|
const lines = [`这会儿 ${hmIn(this.timezone, now)}。想现在就出门的话,能去:`];
|
|
702
|
-
for (const { venue, state } of picks) {
|
|
703
|
-
lines.push(`- ${venue.name}(${STATE_LABEL[state]},${CROWD_LABEL[venue.crowd] || '人不少'}
|
|
813
|
+
for (const { venue, state, wishReason } of picks) {
|
|
814
|
+
lines.push(`- ${venue.name}(${STATE_LABEL[state]},${CROWD_LABEL[venue.crowd] || '人不少'})${wishReason ? `;${wishReason}` : ''}`);
|
|
704
815
|
}
|
|
705
816
|
lines.push(`(一共 ${places.length} 处,fun_places all 填 true 能看全,kind 填「室内」「户外」「夜」能只看一类。)`);
|
|
706
|
-
lines.push('
|
|
707
|
-
lines.push('收摊回执会把这一趟收成一句话,你照着 feast_life_play 记一笔就行。');
|
|
817
|
+
lines.push('选好后用 fun_go 进门;逛完用 fun_home 收摊。');
|
|
708
818
|
return { text: lines.join('\n') };
|
|
709
819
|
}
|
|
710
820
|
|
|
821
|
+
#savedTrips() {
|
|
822
|
+
const kept = new Map((this.#state?.keepsakeTrips ?? []).map((t) => [t.id, t]));
|
|
823
|
+
const all = [...(this.#state?.trips ?? []), ...kept.values()];
|
|
824
|
+
return [...new Map(all.map((t) => [t.id, kept.get(t.id) ?? t])).values()].sort((a, b) => b.leftAt - a.leftAt);
|
|
825
|
+
}
|
|
826
|
+
|
|
827
|
+
async #favorite(id, keep = true) {
|
|
828
|
+
return this.#serial(async () => {
|
|
829
|
+
const result = favoriteTrip(this.#state, id, keep);
|
|
830
|
+
if (result.ok) await this.#save();
|
|
831
|
+
return result;
|
|
832
|
+
});
|
|
833
|
+
}
|
|
834
|
+
|
|
711
835
|
#viewTool(args) {
|
|
712
836
|
const count = clampInt(args?.count, 1, 20, 5);
|
|
713
|
-
const trips = (this.#state.
|
|
837
|
+
const trips = this.#savedTrips().filter((t) => !args?.kept || (this.#state.keepsakeTrips ?? []).some((k) => k.id === t.id)).slice(0, count);
|
|
714
838
|
if (!trips.length && !this.#state.session) {
|
|
715
839
|
return { text: '纪念册还是空的——还没收过摊。想出门就 fun_start 或 fun_places 看看。' };
|
|
716
840
|
}
|
|
@@ -722,8 +846,10 @@ export class FunWorld {
|
|
|
722
846
|
lines.push('去过的地方:');
|
|
723
847
|
for (const t of trips) {
|
|
724
848
|
const when = tripDay(t, this.timezone);
|
|
725
|
-
|
|
726
|
-
|
|
849
|
+
const kept = (this.#state.keepsakeTrips ?? []).some((k) => k.id === t.id);
|
|
850
|
+
const archived = !(this.#state.trips ?? []).some((x) => x.id === t.id);
|
|
851
|
+
lines.push(`- ${when} ${tripSummary(t)}${kept ? '(已珍藏)' : ''}${archived && !kept ? '(近期行程已归档)' : ''}`);
|
|
852
|
+
lines.push(` 行程 ID:${t.id}`);
|
|
727
853
|
if (t.note) lines.push(` (你记的:${t.note})`);
|
|
728
854
|
}
|
|
729
855
|
}
|
|
@@ -739,6 +865,16 @@ export class FunWorld {
|
|
|
739
865
|
*
|
|
740
866
|
* 只读工具:不写盘、不改状态。
|
|
741
867
|
*/
|
|
868
|
+
async #keepsakeTool(args) {
|
|
869
|
+
this.#state = this.#normalizeState();
|
|
870
|
+
const id = typeof args?.id === 'string' ? args.id.trim() : '';
|
|
871
|
+
if (!id) return { text: '要珍藏哪一趟?用 fun_view 找行程 ID。', failed: true };
|
|
872
|
+
const result = favoriteTrip(this.#state, id, args?.keep !== false);
|
|
873
|
+
if (!result.ok) return { text: result.error, failed: true };
|
|
874
|
+
await this.#save();
|
|
875
|
+
return { text: result.kept ? `已珍藏「${result.trip.placeName}」这一趟,之后仍可在纪念册查看。` : `已取消珍藏「${result.trip.placeName}」这一趟;近期纪念册中的记录不受影响。` };
|
|
876
|
+
}
|
|
877
|
+
|
|
742
878
|
#shelfTool(args) {
|
|
743
879
|
const places = this.#places();
|
|
744
880
|
const want = typeof args?.place === 'string' ? args.place.trim() : '';
|
|
@@ -754,13 +890,14 @@ export class FunWorld {
|
|
|
754
890
|
}
|
|
755
891
|
}
|
|
756
892
|
|
|
757
|
-
const
|
|
758
|
-
const
|
|
893
|
+
const trips = this.#savedTrips();
|
|
894
|
+
const allMemories = [...trips, ...(this.#state.keepsakeTrips ?? [])];
|
|
895
|
+
const rack = collectSouvenirs(allMemories, this.timezone, this.#state.collection);
|
|
759
896
|
const target = only ? rack.byPlace.find((p) => p.placeId === only.id) : null;
|
|
760
897
|
|
|
761
898
|
const lines = [];
|
|
762
899
|
if (only) {
|
|
763
|
-
const prog = progressFor(only,
|
|
900
|
+
const prog = progressFor(only, allMemories, this.#state.collection);
|
|
764
901
|
lines.push('进度按当前场所清单统计;移除或改名的旧项目仍保留在回忆中。');
|
|
765
902
|
const group = target;
|
|
766
903
|
lines.push(`${only.name}的架子(去过 ${prog.visits} 次):`);
|
|
@@ -772,6 +909,9 @@ export class FunWorld {
|
|
|
772
909
|
for (const m of it.memories) {
|
|
773
910
|
lines.push(` ${m.day || '日期不详'}:${m.summary}${m.note ? `;你记的:${m.note}` : ''}`);
|
|
774
911
|
}
|
|
912
|
+
if (it.archivedCount) {
|
|
913
|
+
lines.push(` 另有 ${it.archivedCount} 次更早获得记录已归档;累计数量仍保留。`);
|
|
914
|
+
}
|
|
775
915
|
}
|
|
776
916
|
} else {
|
|
777
917
|
lines.push('(这处还什么都没买过。)');
|
|
@@ -791,7 +931,7 @@ export class FunWorld {
|
|
|
791
931
|
return { text: '架子上还什么都没有——还没买过纪念品。想逛就 fun_start 或 fun_places 看看。' };
|
|
792
932
|
}
|
|
793
933
|
|
|
794
|
-
lines.push(
|
|
934
|
+
lines.push(`长期收藏账本里一共 ${rack.items.length} 样东西(${rack.total} 件),来自 ${rack.uniquePlaces} 处地方;详细行程保留最近 40 趟及已珍藏的行程:`);
|
|
795
935
|
for (const group of rack.byPlace) {
|
|
796
936
|
const bits = group.items.map((it) => (it.times > 1 ? `${it.name}×${it.times}` : it.name));
|
|
797
937
|
const when = group.firstDay ? `(最早 ${group.firstDay})` : '';
|
|
@@ -799,7 +939,7 @@ export class FunWorld {
|
|
|
799
939
|
}
|
|
800
940
|
// 哪几处快集齐了:这是「再去一次把它补完」的钩子,比总数有用。
|
|
801
941
|
const close = places
|
|
802
|
-
.map((v) => ({ v, p: progressFor(v, trips) }))
|
|
942
|
+
.map((v) => ({ v, p: progressFor(v, trips, this.#state.collection) }))
|
|
803
943
|
.filter((x) => x.p.visits > 0 && x.p.areas.total > 0)
|
|
804
944
|
.sort((a, b) => b.p.percent - a.p.percent || b.p.visits - a.p.visits)
|
|
805
945
|
.slice(0, 3);
|
|
@@ -828,7 +968,8 @@ export class FunWorld {
|
|
|
828
968
|
const idx = (venue.areas || []).indexOf(area);
|
|
829
969
|
const n = idx >= 0 ? idx + 1 : null;
|
|
830
970
|
// desc 的第一段(到第一个分号)通常就是空间本身,够用且不啰嗦。
|
|
831
|
-
let scenery =
|
|
971
|
+
let scenery = venue.id === 'aquarium' ? aquariumDetail(area) : '';
|
|
972
|
+
if (!scenery) scenery = descNow(venue, nowMin).split(';')[0].replace(/^[^:]*:/, '');
|
|
832
973
|
// 自填地点的描述是用户手写的,可能本来就有句号;别再补一个变成「。。」。
|
|
833
974
|
scenery = scenery.replace(/[。!?.!?]+$/, '');
|
|
834
975
|
const where = n ? `(第 ${n} 处,共 ${venue.areas.length} 处)` : '';
|
|
@@ -872,7 +1013,7 @@ export class FunWorld {
|
|
|
872
1013
|
const day = dayIn(this.timezone, this.#now());
|
|
873
1014
|
try {
|
|
874
1015
|
const raw = JSON.parse(await readFile(this.stateFile(), 'utf8'));
|
|
875
|
-
return normalizeState(raw, day, this.#now(), this.#ttlMin());
|
|
1016
|
+
return normalizeState(raw, day, this.#now(), this.#ttlMin(), this.timezone);
|
|
876
1017
|
} catch {
|
|
877
1018
|
return newState(day);
|
|
878
1019
|
}
|
|
@@ -887,7 +1028,7 @@ export class FunWorld {
|
|
|
887
1028
|
*/
|
|
888
1029
|
#normalizeState() {
|
|
889
1030
|
const now = this.#now();
|
|
890
|
-
return normalizeState(this.#state, dayIn(this.timezone, now), now, this.#ttlMin());
|
|
1031
|
+
return normalizeState(this.#state, dayIn(this.timezone, now), now, this.#ttlMin(), this.timezone);
|
|
891
1032
|
}
|
|
892
1033
|
|
|
893
1034
|
async #save() {
|
|
@@ -959,7 +1100,7 @@ export class FunWorld {
|
|
|
959
1100
|
getMethods: ['list', 'blank'],
|
|
960
1101
|
methods: ['save', 'remove', 'reset', 'resetAll'],
|
|
961
1102
|
},
|
|
962
|
-
{ id: 'book', title: p.book.title, description: p.book.description, getMethods: ['list'] },
|
|
1103
|
+
{ id: 'book', title: p.book.title, description: p.book.description, getMethods: ['list'], methods: ['favorite', 'wish'] },
|
|
963
1104
|
{ id: 'shelf', title: p.shelf.title, description: p.shelf.description, getMethods: ['list'] },
|
|
964
1105
|
],
|
|
965
1106
|
invoke: (panel, method, args) => this.#invoke(panel, method, args ?? []),
|
|
@@ -1018,7 +1159,9 @@ export class FunWorld {
|
|
|
1018
1159
|
}
|
|
1019
1160
|
if (panel === 'book') {
|
|
1020
1161
|
switch (method) {
|
|
1021
|
-
case 'list': return this.#bookData();
|
|
1162
|
+
case 'list': this.#state = this.#normalizeState(); return this.#bookData();
|
|
1163
|
+
case 'favorite': return await this.#favorite(args?.[0]?.id, args?.[0]?.keep !== false);
|
|
1164
|
+
case 'wish': return await this.#serial(() => this.#manageWish(args?.[0] ?? {}));
|
|
1022
1165
|
default: throw new Error(`book 没有 ${method} 这个方法`);
|
|
1023
1166
|
}
|
|
1024
1167
|
}
|
|
@@ -1186,7 +1329,11 @@ export class FunWorld {
|
|
|
1186
1329
|
visitCount: historyFor(st.trips, v.id, dayIn(tz, now), tz)?.visitCount ?? 0,
|
|
1187
1330
|
// 时段:现在处于哪一段、这一处共有哪几段(面板上做「换时间来是另一副样子」的提示)
|
|
1188
1331
|
phase: phaseLabelAt(v, nowMin) || null,
|
|
1189
|
-
phases: Array.isArray(v.phases) ? v.phases.map((x) => ({
|
|
1332
|
+
phases: Array.isArray(v.phases) ? v.phases.map((x) => ({
|
|
1333
|
+
key: x.key, label: x.label, from: x.from, to: x.to,
|
|
1334
|
+
overridesDesc: typeof x.desc === 'string' && Boolean(x.desc.trim()),
|
|
1335
|
+
overridesAreas: Array.isArray(x.areas) && x.areas.length > 0,
|
|
1336
|
+
})) : [],
|
|
1190
1337
|
// 有吃有喝的地方:只给品类名和动词,**不给味道**(味道在鱼的每一天里)。
|
|
1191
1338
|
food: hasFood(v) ? { label: v.food.label, items: v.food.items, verb: v.food.verb } : null,
|
|
1192
1339
|
};
|
|
@@ -1223,6 +1370,8 @@ export class FunWorld {
|
|
|
1223
1370
|
photos: st.session.photos,
|
|
1224
1371
|
ate: (st.session.ate ?? []).map((x) => ({ item: x.item, verb: x.verb, hm: hmIn(tz, x.at) })),
|
|
1225
1372
|
events: st.session.events,
|
|
1373
|
+
pendingChoice: st.session.pendingChoice ?? null,
|
|
1374
|
+
choices: st.session.choices ?? [],
|
|
1226
1375
|
venueAreaCount: places.find((v) => v.id === st.session.placeId)?.areas.length ?? null,
|
|
1227
1376
|
} : null,
|
|
1228
1377
|
};
|
|
@@ -1238,7 +1387,17 @@ export class FunWorld {
|
|
|
1238
1387
|
const tz = this.timezone;
|
|
1239
1388
|
const now = this.#now();
|
|
1240
1389
|
const st = this.#state ?? newState(dayIn(tz, now));
|
|
1241
|
-
const
|
|
1390
|
+
const recentIds = new Set((st.trips ?? []).map((t) => t.id));
|
|
1391
|
+
const keptIds = new Set((st.keepsakeTrips ?? []).map((t) => t.id));
|
|
1392
|
+
const keptTrips = new Map((st.keepsakeTrips ?? []).map((t) => [t.id, t]));
|
|
1393
|
+
const trips = [...(st.keepsakeTrips ?? []), ...(st.trips ?? [])]
|
|
1394
|
+
.map((t) => keptTrips.get(t.id) ?? t)
|
|
1395
|
+
.filter((t, i, all) => all.findIndex((x) => x.id === t.id) === i)
|
|
1396
|
+
.sort((a, b) => b.leftAt - a.leftAt)
|
|
1397
|
+
.map((t) => ({
|
|
1398
|
+
id: t.id,
|
|
1399
|
+
kept: keptIds.has(t.id) || t.favorite === true,
|
|
1400
|
+
archived: !recentIds.has(t.id),
|
|
1242
1401
|
placeId: t.placeId,
|
|
1243
1402
|
placeName: t.placeName,
|
|
1244
1403
|
scene: t.scene,
|
|
@@ -1255,6 +1414,7 @@ export class FunWorld {
|
|
|
1255
1414
|
photos: t.photos,
|
|
1256
1415
|
ate: (t.ate ?? []).map((x) => ({ item: x.item, verb: x.verb })),
|
|
1257
1416
|
events: t.events,
|
|
1417
|
+
choices: t.choices ?? [],
|
|
1258
1418
|
summary: tripSummary(t),
|
|
1259
1419
|
}));
|
|
1260
1420
|
// 按地方汇总:哪几处去得最多(面板上的「常去」)。
|
|
@@ -1269,7 +1429,12 @@ export class FunWorld {
|
|
|
1269
1429
|
return {
|
|
1270
1430
|
ok: true,
|
|
1271
1431
|
total: trips.length,
|
|
1272
|
-
|
|
1432
|
+
wishes: structuredClone(st.wishes ?? []),
|
|
1433
|
+
places: this.#places().map((v) => ({ id: v.id, name: v.name, areas: v.areas, souvenirs: v.souvenirs, phaseNames: (v.phases ?? []).map((p) => p.label) })),
|
|
1434
|
+
totalRecent: st.trips?.length ?? 0,
|
|
1435
|
+
totalKept: keptIds.size,
|
|
1436
|
+
keepsakeCount: keptIds.size,
|
|
1437
|
+
souvenirCount: st.collection?.reduce((n, x) => n + (Number(x.times) || 0), 0) ?? trips.reduce((n, t) => n + t.souvenirs.length, 0),
|
|
1273
1438
|
photoCount: trips.reduce((n, t) => n + t.photos.length, 0),
|
|
1274
1439
|
visitedAreaCount: trips.reduce((n, t) => n + t.visited.length, 0),
|
|
1275
1440
|
mostVisited,
|
|
@@ -1287,13 +1452,20 @@ export class FunWorld {
|
|
|
1287
1452
|
#shelfData() {
|
|
1288
1453
|
const now = this.#now();
|
|
1289
1454
|
const st = this.#state ?? newState(dayIn(this.timezone, now));
|
|
1290
|
-
const trips =
|
|
1291
|
-
const
|
|
1455
|
+
const trips = this.#savedTrips();
|
|
1456
|
+
const allMemories = [...trips, ...(st.keepsakeTrips ?? [])];
|
|
1457
|
+
const rack = collectSouvenirs(allMemories, this.timezone, st.collection);
|
|
1458
|
+
const detailMemories = new Map(allMemories.map((t) => [t.id, t]));
|
|
1459
|
+
for (const item of rack.items) {
|
|
1460
|
+
item.memories = (st.collection ?? []).find((x) => x.key === item.key)?.tripIds
|
|
1461
|
+
?.map((id) => detailMemories.get(id)).filter(Boolean).map((t) => ({ day: tripDay(t, this.timezone), summary: tripSummary(t), note: t.note, company: t.company })) ?? item.memories;
|
|
1462
|
+
if (item.memories.length < item.times) item.archivedCount = item.times - item.memories.length;
|
|
1463
|
+
}
|
|
1292
1464
|
const places = this.#places();
|
|
1293
1465
|
|
|
1294
1466
|
// 每一处都给进度:面板上按「去过但没逛遍」排前面,没去过的排最后。
|
|
1295
1467
|
const progress = places.map((v) => {
|
|
1296
|
-
const p = progressFor(v, trips);
|
|
1468
|
+
const p = progressFor(v, trips, st.collection);
|
|
1297
1469
|
return {
|
|
1298
1470
|
placeId: v.id,
|
|
1299
1471
|
placeName: v.name,
|