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/ENV_PROMPT.md
CHANGED
|
@@ -1,45 +1,13 @@
|
|
|
1
1
|
## 娱乐时间
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
不是想象,也不是刷视频:进门、逛摊位、买点东西、拍张照、吃点喝点、收摊回来。
|
|
3
|
+
出游流程:`fun_places` 查询地点 → `fun_go` 进门 → `fun_wander` 逐处游逛 → `fun_home` 收摊;现在出门可用 `fun_start`。地点、项目、纪念品和拍照点名称以工具回执为准;吃喝只填当前地点真实提供的品类。历史与收藏按需用 `fun_view`、`fun_shelf` 查询。
|
|
5
4
|
|
|
6
|
-
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
-
|
|
11
|
-
|
|
12
|
-
-
|
|
13
|
-
|
|
14
|
-
## 吃喝、发图、时段:细节都在回执里,三条红线别破
|
|
15
|
-
|
|
16
|
-
- **吃喝的味道不归本插件**:它只有品类名。想说九维口感、香气、余韵,就用 `feast_menu` → `feast_eat`
|
|
17
|
-
去「鱼的每一天」点一道真的;没装 / 关了开关就只说「我在这儿喝了什么」,**别形容味道**。
|
|
18
|
-
⚠️ **本插件不会探测别的扩展装没装**(World 契约不允许互相依赖),装没装都由主人拨配置里的开关。
|
|
19
|
-
- **发图(`imggen_draw`)**:`scene` 只在素材库里真有这处时才填,收摊回执会说明填哪个或「不用填」;
|
|
20
|
-
`outfits` 填这一趟穿的那身。**绝不替她编一个库里没有的场景名或衣服名字**——填了会「库里没找到」,等于白填。
|
|
21
|
-
- **时段**:有几处地方清早和夜里不是一副样子,进门回执会写此刻是哪一段、能逛的摊子也跟着变。
|
|
22
|
-
换个时间再去是合理的,不是重复。
|
|
23
|
-
- **去过的痕迹**:再来时 `fun_go` / `fun_wander` 会自己带来过几次、逛过什么、还没去过的几处。
|
|
24
|
-
这些是事实,顺着说或不说都行;第一次去就别假装熟。
|
|
25
|
-
|
|
26
|
-
## 主人加的地方、改过的预设
|
|
27
|
-
|
|
28
|
-
主人可以在面板上加自己的地方、改预设二十处(改的是覆盖层,预设本身不动,随时能恢复)。
|
|
29
|
-
加完跟别处一样能进能逛、会进纪念册;自己加的排在 `fun_places` 前面。**预设删不掉,只能恢复**。
|
|
30
|
-
自己加的地方没有素材库场景,回执会明说 `scene` 不用填,别替它编一个。
|
|
31
|
-
预设升级的新内容照常生效、主人改过的字段优先——别因为「这处被改过」就以为它是旧的。
|
|
5
|
+
- 遇到带 `choiceId` / `optionId` 的待选事件,必须照回执调用 `fun_choice` 完成选择后再继续,不猜 ID 或选项。
|
|
6
|
+
- 明确表达想去或想做时用 `fun_wish` 记录、`fun_wishes` 查询;不催促、不从旧行程推断完成。
|
|
7
|
+
- 发图用 `imggen_draw`:按 `fun_home` 回执填写 `scene` / `outfits` 正名,不编场景或衣服名字;库里没找到的不要填。
|
|
8
|
+
- 食物只记品类。开关联动允许且实际用「鱼的每一天」的 `feast_menu` → `feast_eat` 后才能描述口感;否则只说吃喝了什么,别形容味道。本插件不会探测别的扩展装没装,不依赖其他 World。
|
|
9
|
+
- 时段可能改变氛围和可逛项目;重复到访有效。历史只按需查询,不编造未发生的经历。
|
|
10
|
+
- 用户自填地点通常没有素材库场景;以回执为准。地点清单和动态详情通过 `fun_places` 查询。预设删不掉,只能恢复。
|
|
11
|
+
- 出门前可用 `feast_life_now` 对齐日程;收摊后按回执用 `feast_life_play` 记录实际经历。
|
|
32
12
|
|
|
33
13
|
{{fun_places_block}}
|
|
34
|
-
|
|
35
|
-
## 出门跟日程对齐
|
|
36
|
-
|
|
37
|
-
- **出门前**用 `feast_life_now` 看一眼你这会儿在干嘛:日程里写着「去海边」时,`fun_go` 去的地方要么对得上,
|
|
38
|
-
要么就直说是临时改主意,别装作日程里本来就有。
|
|
39
|
-
- **逛完**用 `feast_life_play` 记一笔(`activity` 写「去漫展逛」、`note` 写真逛到了什么);收摊回执会提醒这两步。
|
|
40
|
-
|
|
41
|
-
## 不用你操心的事
|
|
42
|
-
|
|
43
|
-
- 不必为了「有内容可发」才出门;逛完什么都不说也行。
|
|
44
|
-
- 逛到一半被叫走、或不想逛了,`fun_home` 收个摊就完了,不用把每个项目都走一遍。
|
|
45
|
-
- 一趟挂太久不算错,`fun_wander` 会提一句该收了,不会替你收;面板只给你看,进门/逛/收摊都是你自己的动作。
|
package/src/aquarium.js
ADDED
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
const DETAILS = {
|
|
2
|
+
'鲸豚湾': '玻璃幕墙映着幽蓝水光,宽阔水体在玻璃后铺开。',
|
|
3
|
+
'海底隧道': '蓝色玻璃拱过头顶,深灰地砖接住水面的晃光。',
|
|
4
|
+
'水母缸': '幽蓝水缸里浮着柔粉光点,缸前的光线比周围更柔和。',
|
|
5
|
+
'企鹅馆': '企鹅馆的玻璃隔开水面,层层手印叠在玻璃反光前。',
|
|
6
|
+
'触摸池': '触摸池水面近在眼前,海星的轮廓隔水可见。',
|
|
7
|
+
'纪念品店': '鲸鱼挂件、水母小夜灯和企鹅贴纸延续着馆里的海洋主题。',
|
|
8
|
+
};
|
|
9
|
+
|
|
10
|
+
const EVENT_DETAILS = {
|
|
11
|
+
'一条大鲸从头顶慢慢游过去,影子把整条隧道盖了一下': { area: '海底隧道', detail: '水面的亮纹随着影子从玻璃拱顶慢慢移开。' },
|
|
12
|
+
'海底隧道的传送带慢慢把人往前送': { area: '海底隧道', detail: '身边的水景一点点向后退,头顶的蓝色拱顶仍连成一整条。' },
|
|
13
|
+
'看到有人在水母缸前面站了十分钟一动不动': { area: '水母缸', detail: '周围的人流来去,粉色光点仍浮在缸里。' },
|
|
14
|
+
'水母缸前的灯一下调暗了': { area: '水母缸', detail: '暗下来的灯让水母轮廓显得更清楚。' },
|
|
15
|
+
'企鹅馆正好赶上喂食,一群企鹅扑通扑通全下了水': { area: '企鹅馆', detail: '几声接连的入水声从玻璃后传来。' },
|
|
16
|
+
'企鹅馆的玻璃上有一层手印': { area: '企鹅馆', detail: '隔着玻璃上的手印,水光在企鹅身后晃了一下。' },
|
|
17
|
+
'触摸池里摸到一下海星,凉凉的': { area: '触摸池', detail: '指尖只碰到一下,凉意很快散开。' },
|
|
18
|
+
'触摸池里有小孩不敢伸手': { area: '触摸池', detail: '小孩在池边停了一会儿,没有人催他。' },
|
|
19
|
+
'在纪念品店犹豫了很久,最后挑了那个鲸鱼挂件': { area: '纪念品店', detail: '货架上的水母小夜灯和企鹅贴纸还在旁边。' },
|
|
20
|
+
'纪念品店的店员在补货': { area: '纪念品店', detail: '店员把原有的纪念品一件件摆回货架。' },
|
|
21
|
+
};
|
|
22
|
+
|
|
23
|
+
export function aquariumDetail(area) { return DETAILS[area] ?? ''; }
|
|
24
|
+
export function aquariumEventDetail(event, area) {
|
|
25
|
+
const row = EVENT_DETAILS[event];
|
|
26
|
+
return row?.area === area ? row.detail : '';
|
|
27
|
+
}
|
package/src/choices.js
ADDED
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
const CHOICES = {
|
|
2
|
+
'看到有人在水母缸前面站了十分钟一动不动': {
|
|
3
|
+
prompt: '水母缸前的光点慢慢浮着,你想怎么做?',
|
|
4
|
+
options: [
|
|
5
|
+
{ id: 'stay', label: '也站一会儿', result: '在水母缸前多停了一会儿' },
|
|
6
|
+
{ id: 'move-on', label: '继续往前逛', result: '看了一会儿便继续往前逛' },
|
|
7
|
+
],
|
|
8
|
+
},
|
|
9
|
+
'企鹅馆正好赶上喂食,一群企鹅扑通扑通全下了水': {
|
|
10
|
+
prompt: '企鹅刚下水,接下来想怎么留住这一刻?',
|
|
11
|
+
options: [
|
|
12
|
+
{ id: 'watch', label: '再看一会儿', result: '在企鹅馆多看了一会儿' },
|
|
13
|
+
{ id: 'photo', label: '记下这个时间,继续逛', result: '记下了企鹅喂食的时间' },
|
|
14
|
+
],
|
|
15
|
+
},
|
|
16
|
+
'一条大鲸从头顶慢慢游过去,影子把整条隧道盖了一下': {
|
|
17
|
+
prompt: '鲸影从拱顶移过去了,你想怎么做?',
|
|
18
|
+
options: [
|
|
19
|
+
{ id: 'wait', label: '等它再游回来', result: '在海底隧道等了一会儿鲸影' },
|
|
20
|
+
{ id: 'walk', label: '沿隧道继续走', result: '沿着海底隧道继续往前走' },
|
|
21
|
+
],
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
const clean = (v, max = 160) => typeof v === 'string' ? v.replace(/\s+/g, ' ').trim().slice(0, max) : '';
|
|
26
|
+
|
|
27
|
+
export function choiceForEvent(event, context = {}) {
|
|
28
|
+
const base = CHOICES[clean(event, 200)];
|
|
29
|
+
if (!base) return null;
|
|
30
|
+
const area = clean(context.area, 60);
|
|
31
|
+
return {
|
|
32
|
+
id: `choice-${clean(event, 80)}`,
|
|
33
|
+
event: clean(event, 200),
|
|
34
|
+
area,
|
|
35
|
+
prompt: base.prompt,
|
|
36
|
+
options: base.options.map((x) => ({ id: x.id, label: x.label, result: x.result })),
|
|
37
|
+
};
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
export function normalizeChoice(raw) {
|
|
41
|
+
if (!raw || typeof raw !== 'object' || !clean(raw.id, 100) || !clean(raw.event, 200)) return null;
|
|
42
|
+
const options = Array.isArray(raw.options) ? raw.options.map((x) => ({ id: clean(x?.id, 50), label: clean(x?.label, 100), result: clean(x?.result, 160) })).filter((x) => x.id && x.label).slice(0, 4) : [];
|
|
43
|
+
if (!options.length) return null;
|
|
44
|
+
return { id: clean(raw.id, 100), event: clean(raw.event, 200), area: clean(raw.area, 60), prompt: clean(raw.prompt, 180), options };
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
export function applyChoice(pending, optionId) {
|
|
48
|
+
const choice = normalizeChoice(pending);
|
|
49
|
+
const id = clean(optionId, 50);
|
|
50
|
+
if (!choice) return { ok: false, error: '当前没有待选择的事件。' };
|
|
51
|
+
const option = choice.options.find((x) => x.id === id);
|
|
52
|
+
if (!option) return { ok: false, error: '没有这个选项,请按当前回执提供的选项选择。' };
|
|
53
|
+
return { ok: true, choice, option };
|
|
54
|
+
}
|
package/src/definition.js
CHANGED
|
@@ -8,32 +8,48 @@ import { FUN_TOOL_DECLS, FunWorld } from './world.js';
|
|
|
8
8
|
/** 自描述里每个工具配一句给人看的话,按工具名。 */
|
|
9
9
|
const TOOL_SUMMARIES = {
|
|
10
10
|
fun_places: {
|
|
11
|
-
zh: '
|
|
12
|
-
en: '
|
|
11
|
+
zh: '查询当前地点,按营业状态和拥挤度排序;可筛选或列出全部。',
|
|
12
|
+
en: 'Query available places ranked by opening hours and crowd; filter by kind or list all.',
|
|
13
13
|
},
|
|
14
14
|
fun_go: {
|
|
15
|
-
zh: '
|
|
16
|
-
en: '
|
|
15
|
+
zh: '进门开始行程,返回当前时段描写和可逛项目。',
|
|
16
|
+
en: 'Start a trip and return the current-time description and available areas.',
|
|
17
|
+
},
|
|
18
|
+
fun_choice: {
|
|
19
|
+
zh: '处理逛到的结构化事件选择,按回执中的 choiceId 和 optionId 选择。',
|
|
20
|
+
en: 'Resolve a structured event choice using the choiceId and optionId from the receipt.',
|
|
17
21
|
},
|
|
18
22
|
fun_wander: {
|
|
19
|
-
zh: '
|
|
20
|
-
en: 'Wander one spot
|
|
23
|
+
zh: '逛一个项目,可记录本次购买、拍照或吃喝;待选择事件按回执处理。',
|
|
24
|
+
en: 'Wander one spot and optionally record a purchase, photo or food; resolve pending choices from the receipt.',
|
|
21
25
|
},
|
|
22
26
|
fun_home: {
|
|
23
|
-
zh: '
|
|
24
|
-
en: '
|
|
27
|
+
zh: '结束行程并返回本次摘要与记录提示。',
|
|
28
|
+
en: 'End the trip and return its summary and logging prompt.',
|
|
25
29
|
},
|
|
26
30
|
fun_start: {
|
|
27
|
-
zh: '
|
|
28
|
-
en: '
|
|
31
|
+
zh: '查看当前推荐地点;详细筛选用 fun_places。',
|
|
32
|
+
en: 'Show current place recommendations; use fun_places for filters.',
|
|
29
33
|
},
|
|
30
34
|
fun_view: {
|
|
31
|
-
zh: '
|
|
32
|
-
en: '
|
|
35
|
+
zh: '按需查询近期或珍藏的行程记录。',
|
|
36
|
+
en: 'Query recent or kept trip records on demand.',
|
|
37
|
+
},
|
|
38
|
+
fun_wishes: {
|
|
39
|
+
zh: '查看明确记下的出游心愿和状态,不催促。',
|
|
40
|
+
en: 'View outing wishes and their status without reminders.',
|
|
41
|
+
},
|
|
42
|
+
fun_wish: {
|
|
43
|
+
zh: '记录、暂缓、恢复或取消一个出游心愿。',
|
|
44
|
+
en: 'Add, pause, resume or cancel an outing wish.',
|
|
45
|
+
},
|
|
46
|
+
fun_keepsake: {
|
|
47
|
+
zh: '珍藏或取消珍藏一趟行程,不影响纪念册近期列表和长期收藏。',
|
|
48
|
+
en: 'Keep or unkeep a trip without changing the recent trip book or permanent collection.',
|
|
33
49
|
},
|
|
34
50
|
fun_shelf: {
|
|
35
|
-
zh: '
|
|
36
|
-
en: '
|
|
51
|
+
zh: '按地点查询长期纪念品收藏和收集进度。',
|
|
52
|
+
en: 'Query long-term souvenirs and collection progress by place.',
|
|
37
53
|
},
|
|
38
54
|
};
|
|
39
55
|
|
package/src/events.js
ADDED
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/** 内置事件的明确前置条件;没有可靠来源的收获不自动补造。 */
|
|
2
|
+
export const EVENT_METADATA = {
|
|
3
|
+
'过山车冲下去那一下喊得嗓子发干,下来喝了半瓶水': { areas: ['过山车'] },
|
|
4
|
+
'在套圈摊套中了一个歪歪的小熊': { disabled: true },
|
|
5
|
+
'在纪念品店犹豫了很久,最后挑了那个鲸鱼挂件': { areas: ['纪念品店'], souvenir: '鲸鱼挂件' },
|
|
6
|
+
'抽了一支签,是「小吉」': { areas: ['抽签处'], souvenir: '一支签' },
|
|
7
|
+
'捞金鱼捞上来两条,纸破了第三条跑了': { disabled: true },
|
|
8
|
+
'苹果糖咬第一口把嘴唇粘住了': { souvenir: '苹果糖' },
|
|
9
|
+
'吧唧挑了半天,最后把一整组都买了': { disabled: true },
|
|
10
|
+
'买到最后一桶焦糖爆米花': { disabled: true },
|
|
11
|
+
'抓娃娃抓了七次才中': { areas: ['抓娃娃机'], souvenir: '抓到的娃娃' },
|
|
12
|
+
'文创店买到最后一个帆布袋': { areas: ['文创店'], souvenir: '文创帆布袋' },
|
|
13
|
+
'手冲等得有点久,但端上来的时候正好': { consume: '手冲' },
|
|
14
|
+
'拉花歪了一点,店员说要重做,你说不用': { consumeAny: true },
|
|
15
|
+
'犹豫很久,最后还是要了少糖': { consumeAny: true },
|
|
16
|
+
'封口机把杯子封歪了,店员重新封了一次': { consumeAny: true },
|
|
17
|
+
'拿到手的那一刻杯壁上全是水珠': { consumeAny: true },
|
|
18
|
+
'吸管戳下去的时候珍珠一下涌上来': { consume: '珍珠奶茶' },
|
|
19
|
+
'最后一道上得特别慢,但确实值得等': { consumeAny: true },
|
|
20
|
+
'点的那道菜比想象中辣': { disabled: true },
|
|
21
|
+
'等位等了二十分钟,服务员送了一小碟花生': { disabled: true },
|
|
22
|
+
'厨房多送了一碟小菜,说今天做多了': { disabled: true },
|
|
23
|
+
'最后一块点心被端到你面前,说是送的': { disabled: true },
|
|
24
|
+
'店员说新出了一款,今天试做,送一杯': { disabled: true },
|
|
25
|
+
'集点卡差最后一个印,店员说这次盖满': { disabled: true },
|
|
26
|
+
'老板多给了一串': { disabled: true },
|
|
27
|
+
'摊主认出你来过,多给了一串': { disabled: true },
|
|
28
|
+
'气球摊的老板认出了你,说上次那个没给你打折': { disabled: true },
|
|
29
|
+
'店员说你抓的次数够多了,多送了一次': { disabled: true },
|
|
30
|
+
'抽签的师傅说这支签今年只发出去几支': { areas: ['抽签处'], souvenir: '一支签' },
|
|
31
|
+
'常坐的那个位子今天正好空着': { disabled: true },
|
|
32
|
+
'小卖部的酸奶冰得正好': { areas: ['小卖部'], souvenir: '一瓶酸奶' },
|
|
33
|
+
};
|
|
34
|
+
|
|
35
|
+
// 完整项目名之外的内置简称,只做明确字面匹配,不猜测用户文本语义。
|
|
36
|
+
const AREA_TERMS = {
|
|
37
|
+
aquarium: { '隧道': ['海底隧道'] },
|
|
38
|
+
zoo: { '熊猫': ['熊猫馆'], '长颈鹿': ['长颈鹿区'], '猴子': ['猴山'], '小火车': ['园内小火车'] },
|
|
39
|
+
park: { '草坪': ['大草坪'], '长椅': ['湖边长椅'], '下棋': ['老树下的棋盘'], '棋局': ['老树下的棋盘'] },
|
|
40
|
+
arcade: { '抓娃娃': ['抓娃娃机'] },
|
|
41
|
+
ktv: { '唱到': ['包厢沙发', '点歌屏'], '唱完': ['包厢沙发', '点歌屏'], '点了一首': ['点歌屏'] },
|
|
42
|
+
cinema: { '前排': ['影厅', '最后一排'], '电影放到': ['影厅', '最后一排'], '片尾': ['影厅', '最后一排'], '爆米花': ['爆米花柜台'], '检票': ['取票厅'] },
|
|
43
|
+
museum: { '中庭': ['中庭长椅'] },
|
|
44
|
+
hiking: { '山顶': ['山顶的大石头'], '凉亭': ['半山腰的凉亭'], '半山腰': ['半山腰的凉亭'], '下山': ['下山的小路'], '山脚': ['山脚入口'] },
|
|
45
|
+
cafe: { '露天座': ['门口的露天座'], '窗边': ['靠窗的位子'] },
|
|
46
|
+
milktea: { '档口': ['点单的档口'], '台阶': ['门口的台阶'] },
|
|
47
|
+
market: { '套圈摊': ['套圈摊'], '烤串': ['烧烤摊'], '糖水': ['糖水铺'], '铁板': ['铁板鱿鱼摊'] },
|
|
48
|
+
bathhouse: { '休息区': ['休息区的躺椅'] },
|
|
49
|
+
thrift: { '旧书': ['旧书摊'], '磁带': ['磁带和唱片'], '旧钟表': ['旧钟表摊'], '旧衣服': ['旧衣服的架子'] },
|
|
50
|
+
riverside: { '台阶': ['下到水边的台阶'], '长椅': ['长椅上'], '栏杆': ['栏杆边'], '桥底': ['桥底下'] },
|
|
51
|
+
};
|
|
52
|
+
|
|
53
|
+
export function filterEventsForArea(events, area, venue, context = {}) {
|
|
54
|
+
const pool = Array.isArray(events) ? events : [];
|
|
55
|
+
const areas = Array.isArray(venue?.areas) ? venue.areas : [];
|
|
56
|
+
const terms = { ...Object.fromEntries(areas.map((a) => [a, [a]])), ...(AREA_TERMS[venue?.id] ?? {}) };
|
|
57
|
+
const ate = Array.isArray(context?.ate) ? context.ate : [];
|
|
58
|
+
return pool.filter((line) => {
|
|
59
|
+
if (typeof line !== 'string' || !line.trim()) return false;
|
|
60
|
+
const meta = EVENT_METADATA[line];
|
|
61
|
+
if (meta?.disabled) return false;
|
|
62
|
+
if (meta?.areas && !meta.areas.includes(area)) return false;
|
|
63
|
+
if (meta?.souvenir && !(context?.souvenirs ?? []).includes(meta.souvenir)) return false;
|
|
64
|
+
if (meta?.consume && !ate.some((x) => x?.item === meta.consume)) return false;
|
|
65
|
+
if (meta?.consumeAny && !ate.length) return false;
|
|
66
|
+
// 显式元数据的项目约束优先,否则按文本中明确提到的项目取并集。
|
|
67
|
+
if (meta?.areas) return true;
|
|
68
|
+
const mentioned = Object.entries(terms).filter(([term]) => line.includes(term)).flatMap(([, names]) => names);
|
|
69
|
+
return !mentioned.length || mentioned.includes(area);
|
|
70
|
+
});
|
|
71
|
+
}
|
package/src/keepsakes.js
CHANGED
|
@@ -1,200 +1,61 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* 纪念品架与场所完成度:让「去过」这件事在纪念册之外还留下点东西。
|
|
3
|
-
*
|
|
4
|
-
* ## 这一层解决什么问题
|
|
5
|
-
*
|
|
6
|
-
* 0.1.5 的纪念册是一串孤立的趟:`fun_go → fun_wander × N → fun_home`,
|
|
7
|
-
* 每一趟结束就结束了。纪念品在 `trip.souvenirs` 里只是几个字符串,
|
|
8
|
-
* **跨趟没有任何归集**——所以「这枚纪念币是第一次去游乐场那天买的」
|
|
9
|
-
* 这句话说不出来,面板上也看不出「我到底攒了多少东西」。
|
|
10
|
-
*
|
|
11
|
-
* 而这条数据其实一直都在 `state.trips` 里躺着,只是从来没人取。
|
|
12
|
-
*
|
|
13
|
-
* ## 设计
|
|
14
|
-
*
|
|
15
|
-
* - **纯函数、不碰文件**:输入是 `state.trips`(和场所表),输出是结构化归集。
|
|
16
|
-
* World 负责把它变成回执文字或面板 payload。
|
|
17
|
-
* - **不算新状态**:不落盘、不加字段、不改 state 形状。纪念品架是
|
|
18
|
-
* `trips` 的一个**视图**,随时可以从头算出来。这样老数据自动就有了,
|
|
19
|
-
* 也不需要迁移。
|
|
20
|
-
* - **永不抛错**:脏数据跳过那一条,绝不让纪念册打不开。
|
|
21
|
-
*
|
|
22
|
-
* ## 为什么不做「收藏值多少钱 / 稀有度」
|
|
23
|
-
*
|
|
24
|
-
* 那是给游戏做的。她真正会用到的是两句:这东西**在哪买的、哪天**,
|
|
25
|
-
* 以及**这儿我还差什么没玩**。所以这里只归集这两类。
|
|
26
|
-
*/
|
|
27
|
-
|
|
28
|
-
const norm = (v, max) => (typeof v === 'string' ? v.replace(/\s+/g, ' ').trim().slice(0, max) : '');
|
|
29
|
-
|
|
30
1
|
import { tripDay, tripSummary } from './state.js';
|
|
2
|
+
const norm = (v, max) => typeof v === 'string' ? v.replace(/\s+/g, ' ').trim().slice(0, max) : '';
|
|
31
3
|
|
|
32
|
-
/**
|
|
33
|
-
|
|
34
|
-
*
|
|
35
|
-
* 同名纪念品在不同地方买算**两件不同的东西**(游乐场的棉花糖 ≠ 公园的棉花糖),
|
|
36
|
-
* 所以 key 是 `placeId::名字`。同一处买过两次才算「买过几次」。
|
|
37
|
-
*
|
|
38
|
-
* @param {object[]} trips `state.trips`(最近的在前)
|
|
39
|
-
* @returns {{ items: object[], byPlace: object[], total: number, uniquePlaces: number }}
|
|
40
|
-
*/
|
|
41
|
-
export function collectSouvenirs(trips, timezone = 'Asia/Shanghai') {
|
|
4
|
+
/** 收藏可来自旧行程,或持久账本。详细回忆只关联仍保存的近期/珍藏行程。 */
|
|
5
|
+
export function collectSouvenirs(trips, timezone = 'Asia/Shanghai', collection = null) {
|
|
42
6
|
const list = Array.isArray(trips) ? trips : [];
|
|
43
7
|
const map = new Map();
|
|
44
|
-
|
|
45
8
|
for (const t of list) {
|
|
46
9
|
if (!t || typeof t !== 'object') continue;
|
|
47
|
-
const placeId = norm(t.placeId, 40);
|
|
10
|
+
const placeId = norm(t.placeId, 40); if (!placeId) continue;
|
|
48
11
|
const placeName = norm(t.placeName, 40) || placeId;
|
|
49
12
|
const day = tripDay(t, timezone);
|
|
50
|
-
const memory = {
|
|
51
|
-
|
|
52
|
-
leftAt: Number(t.leftAt) || 0,
|
|
53
|
-
company: norm(t.company, 40),
|
|
54
|
-
note: norm(t.note, 120),
|
|
55
|
-
summary: tripSummary({
|
|
56
|
-
placeName,
|
|
57
|
-
company: norm(t.company, 40),
|
|
58
|
-
visited: (Array.isArray(t.visited) ? t.visited : []).filter((v) => norm(v?.area, 40)).map((v) => ({ area: norm(v.area, 40) })),
|
|
59
|
-
}),
|
|
60
|
-
};
|
|
61
|
-
const souvenirs = Array.isArray(t.souvenirs) ? [...new Set(t.souvenirs.map((s) => norm(s, 40)).filter(Boolean))] : [];
|
|
62
|
-
for (const raw of souvenirs) {
|
|
63
|
-
const name = norm(raw, 40);
|
|
64
|
-
if (!name) continue;
|
|
13
|
+
const memory = { day, leftAt: Number(t.leftAt) || 0, company: norm(t.company, 40), note: norm(t.note, 120), summary: tripSummary({ ...t, placeName, visited: (Array.isArray(t.visited) ? t.visited : []).filter((v) => norm(v?.area, 40)) }) };
|
|
14
|
+
for (const name of new Set((Array.isArray(t.souvenirs) ? t.souvenirs : []).map((s) => norm(s, 40)).filter(Boolean))) {
|
|
65
15
|
const key = `${placeId}::${name}`;
|
|
66
16
|
const cur = map.get(key);
|
|
67
|
-
if (!cur) {
|
|
68
|
-
|
|
69
|
-
key,
|
|
70
|
-
name,
|
|
71
|
-
placeId,
|
|
72
|
-
placeName,
|
|
73
|
-
// 第一次买到它的那天:纪念册是最近的在前,所以先遇到的就是最近那次,
|
|
74
|
-
// 要一直往前覆盖到最后遇到的那条,才是真正的「第一次」。
|
|
75
|
-
firstDay: day,
|
|
76
|
-
lastDay: day,
|
|
77
|
-
times: 1,
|
|
78
|
-
memories: [memory],
|
|
79
|
-
});
|
|
80
|
-
continue;
|
|
81
|
-
}
|
|
82
|
-
cur.times += 1;
|
|
83
|
-
cur.memories.push(memory);
|
|
84
|
-
if (day && (!cur.firstDay || day < cur.firstDay)) cur.firstDay = day;
|
|
85
|
-
if (day && (!cur.lastDay || day > cur.lastDay)) cur.lastDay = day;
|
|
17
|
+
if (!cur) map.set(key, { key, name, placeId, placeName, firstDay: day, lastDay: day, times: 1, memories: [memory] });
|
|
18
|
+
else { cur.times += 1; cur.memories.push(memory); if (day && (!cur.firstDay || day < cur.firstDay)) cur.firstDay = day; if (day && (!cur.lastDay || day > cur.lastDay)) cur.lastDay = day; }
|
|
86
19
|
}
|
|
87
20
|
}
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
21
|
+
if (Array.isArray(collection)) {
|
|
22
|
+
const historical = new Map(map);
|
|
23
|
+
map.clear();
|
|
24
|
+
for (const x of collection) {
|
|
25
|
+
const placeId = norm(x?.placeId, 40); const name = norm(x?.name, 40); if (!placeId || !name) continue;
|
|
26
|
+
const key = `${placeId}::${name}`;
|
|
27
|
+
map.set(key, { key, placeId, placeName: norm(x.placeName, 40) || placeId, name, firstDay: norm(x.firstDay, 10), lastDay: norm(x.lastDay, 10), times: Math.max(1, Number(x.times) || 1), memories: historical.get(key)?.memories ?? (Array.isArray(x.tripIds) ? x.tripIds : []).map((id) => ({ tripId: id, archived: true })) });
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
const items = [...map.values()].sort((a, b) => b.lastDay.localeCompare(a.lastDay) || a.placeName.localeCompare(b.placeName) || a.name.localeCompare(b.name));
|
|
97
31
|
const places = new Map();
|
|
98
32
|
for (const it of items) {
|
|
99
|
-
const
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
if (it.lastDay && (!cur.lastDay || it.lastDay > cur.lastDay)) cur.lastDay = it.lastDay;
|
|
105
|
-
places.set(it.placeId, cur);
|
|
33
|
+
const group = places.get(it.placeId) ?? { placeId: it.placeId, placeName: it.placeName, items: [], firstDay: '', lastDay: '' };
|
|
34
|
+
group.items.push(it);
|
|
35
|
+
if (it.firstDay && (!group.firstDay || it.firstDay < group.firstDay)) group.firstDay = it.firstDay;
|
|
36
|
+
if (it.lastDay && (!group.lastDay || it.lastDay > group.lastDay)) group.lastDay = it.lastDay;
|
|
37
|
+
places.set(it.placeId, group);
|
|
106
38
|
}
|
|
107
|
-
|
|
108
|
-
return {
|
|
109
|
-
items,
|
|
110
|
-
byPlace: [...places.values()].sort((a, b) => b.items.length - a.items.length
|
|
111
|
-
|| a.placeName.localeCompare(b.placeName)),
|
|
112
|
-
total: items.reduce((n, it) => n + it.times, 0),
|
|
113
|
-
uniquePlaces: places.size,
|
|
114
|
-
};
|
|
39
|
+
return { items, byPlace: [...places.values()].sort((a, b) => b.items.length - a.items.length || a.placeName.localeCompare(b.placeName)), total: items.reduce((n, x) => n + x.times, 0), uniquePlaces: places.size };
|
|
115
40
|
}
|
|
116
41
|
|
|
117
|
-
|
|
118
|
-
* 一处地方的完成度:项目 / 纪念品 / 拍照点,各逛到(买到/拍到)多少。
|
|
119
|
-
*
|
|
120
|
-
* `place` 是合并后的场所(预设 + 用户改动),因为自填地点也该有进度。
|
|
121
|
-
* 传进来的 `trips` 只统计**这一处**的历史。
|
|
122
|
-
*
|
|
123
|
-
* 为什么三条分开算而不是一个总分:她缺的可能只是「鬼屋没去过」,
|
|
124
|
-
* 一个 62% 的总分说不出这件事。`fun_go` 回执要的正是一句具体的
|
|
125
|
-
* 「这儿你还差鬼屋和碰碰车」。
|
|
126
|
-
*
|
|
127
|
-
* @param {object} place 场所条目(含 areas / souvenirs / photoSpots)
|
|
128
|
-
* @param {object[]} trips 全部纪念册(内部按 placeId 过滤)
|
|
129
|
-
* @returns {{ areas: object, souvenirs: object, photos: object, percent: number, visits: number }}
|
|
130
|
-
*/
|
|
131
|
-
export function progressFor(place, trips) {
|
|
42
|
+
export function progressFor(place, trips, collection = null) {
|
|
132
43
|
const placeId = norm(place?.id, 40);
|
|
133
44
|
const mine = (Array.isArray(trips) ? trips : []).filter((t) => t && t.placeId === placeId);
|
|
134
|
-
|
|
135
|
-
const seenAreas = new Set();
|
|
136
|
-
const bought = new Set();
|
|
137
|
-
const shot = new Set();
|
|
45
|
+
const seenAreas = new Set(); const bought = new Set(); const shot = new Set();
|
|
138
46
|
for (const t of mine) {
|
|
139
|
-
for (const v of Array.isArray(t.visited) ? t.visited : []) {
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
for (const s of Array.isArray(t.souvenirs) ? t.souvenirs : []) {
|
|
144
|
-
const x = norm(s, 40);
|
|
145
|
-
if (x) bought.add(x);
|
|
146
|
-
}
|
|
147
|
-
for (const p of Array.isArray(t.photos) ? t.photos : []) {
|
|
148
|
-
const x = norm(p, 60);
|
|
149
|
-
if (x) shot.add(x);
|
|
150
|
-
}
|
|
47
|
+
for (const v of Array.isArray(t.visited) ? t.visited : []) { const a = norm(v?.area, 40); if (a) seenAreas.add(a); }
|
|
48
|
+
for (const s of Array.isArray(t.souvenirs) ? t.souvenirs : []) { const x = norm(s, 40); if (x) bought.add(x); }
|
|
49
|
+
for (const p of Array.isArray(t.photos) ? t.photos : []) { const x = norm(p, 60); if (x) shot.add(x); }
|
|
151
50
|
}
|
|
152
|
-
|
|
153
|
-
const
|
|
154
|
-
const
|
|
155
|
-
const
|
|
156
|
-
|
|
157
|
-
const part = (all, seen) => {
|
|
158
|
-
all = [...new Set(all)];
|
|
159
|
-
const got = all.filter((x) => seen.has(x));
|
|
160
|
-
const left = all.filter((x) => !seen.has(x));
|
|
161
|
-
return {
|
|
162
|
-
got, left, total: all.length, done: got.length,
|
|
163
|
-
complete: all.length > 0 && left.length === 0,
|
|
164
|
-
};
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
const areas = part(allAreas, seenAreas);
|
|
168
|
-
const souvenirs = part(allGoods, bought);
|
|
169
|
-
const photos = part(allShots, shot);
|
|
170
|
-
|
|
171
|
-
// 一个总百分比:只用来在面板上排「哪几处快集齐了」,不作为回执主句。
|
|
172
|
-
const denom = areas.total + souvenirs.total + photos.total;
|
|
173
|
-
const numer = areas.done + souvenirs.done + photos.done;
|
|
174
|
-
return {
|
|
175
|
-
areas,
|
|
176
|
-
souvenirs,
|
|
177
|
-
photos,
|
|
178
|
-
visits: mine.length,
|
|
179
|
-
percent: denom ? Math.round((numer / denom) * 100) : 0,
|
|
180
|
-
};
|
|
51
|
+
for (const x of Array.isArray(collection) ? collection : []) if (x?.placeId === placeId) bought.add(norm(x.name, 40));
|
|
52
|
+
const part = (all, seen) => { all = [...new Set((Array.isArray(all) ? all : []).map((x) => norm(x, 60)).filter(Boolean))]; const got = all.filter((x) => seen.has(x)); const left = all.filter((x) => !seen.has(x)); return { got, left, total: all.length, done: got.length, complete: all.length > 0 && !left.length }; };
|
|
53
|
+
const areas = part(place?.areas, seenAreas); const souvenirs = part(place?.souvenirs, bought); const photos = part(place?.photoSpots, shot);
|
|
54
|
+
const denom = areas.total + souvenirs.total + photos.total; const numer = areas.done + souvenirs.done + photos.done;
|
|
55
|
+
return { areas, souvenirs, photos, visits: mine.length, percent: denom ? Math.round(numer / denom * 100) : 0 };
|
|
181
56
|
}
|
|
182
|
-
|
|
183
|
-
/**
|
|
184
|
-
* 把完成度写成一句能放进回执的话。**只在有内容可说时返回字符串**,
|
|
185
|
-
* 没去过、或者全逛遍了,都返回空串(让调用方自己决定说什么)。
|
|
186
|
-
*
|
|
187
|
-
* 刻意写得具体:点出**还差什么**,而不是报个百分比。
|
|
188
|
-
* 「这儿你还差鬼屋和碰碰车」比「完成度 62%」有用得多。
|
|
189
|
-
*
|
|
190
|
-
* @param {object} progress `progressFor()` 的结果
|
|
191
|
-
* @param {number} max 最多点几处
|
|
192
|
-
*/
|
|
193
57
|
export function progressLine(progress, max = 3) {
|
|
194
|
-
const left = progress?.areas?.left ?? [];
|
|
195
|
-
|
|
196
|
-
const cap = Math.max(1, Math.round(Number(max) || 3));
|
|
197
|
-
const shown = left.slice(0, cap);
|
|
198
|
-
const more = left.length - shown.length;
|
|
58
|
+
const left = progress?.areas?.left ?? []; if (!left.length) return '';
|
|
59
|
+
const shown = left.slice(0, Math.max(1, Math.round(Number(max) || 3))); const more = left.length - shown.length;
|
|
199
60
|
return `这儿还差${shown.join('、')}${more > 0 ? ` 等 ${left.length} 处` : ''}没逛。`;
|
|
200
61
|
}
|
package/src/names.js
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
/** 名称解析只负责找候选:唯一命中后始终使用清单正名落盘。 */
|
|
2
|
+
export function resolveName(list, input) {
|
|
3
|
+
const wanted = typeof input === 'string' ? input.trim() : '';
|
|
4
|
+
const names = [...new Set((Array.isArray(list) ? list : []).filter((x) => typeof x === 'string' && x))];
|
|
5
|
+
if (!wanted) return { name: null, candidates: [] };
|
|
6
|
+
if (names.includes(wanted)) return { name: wanted, candidates: [wanted] };
|
|
7
|
+
const candidates = names.filter((x) => x.includes(wanted) || wanted.includes(x));
|
|
8
|
+
return { name: candidates.length === 1 ? candidates[0] : null, candidates };
|
|
9
|
+
}
|