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/CHANGELOG.md +113 -1
- package/PUBLISHING.md +46 -34
- package/README.md +62 -6
- package/describe.json +169 -19
- package/dist/webui.js +256 -9
- package/package.json +3 -3
- package/src/ENV_PROMPT.md +8 -39
- package/src/aquarium.js +27 -0
- package/src/choices.js +54 -0
- package/src/config.js +8 -0
- package/src/definition.js +32 -12
- package/src/events.js +71 -0
- package/src/keepsakes.js +61 -0
- package/src/memories.js +88 -15
- package/src/names.js +9 -0
- package/src/phases.js +54 -0
- package/src/state.js +212 -20
- package/src/venues.js +202 -3
- package/src/wishes.js +114 -0
- package/src/world.js +504 -114
package/src/ENV_PROMPT.md
CHANGED
|
@@ -1,44 +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
|
-
- **吃喝的味道不归本插件**:它只有品类名。想说九维口感、香气、余韵,就用 `feast_menu` → `feast_eat`
|
|
16
|
-
去「鱼的每一天」点一道真的;没装 / 关了开关就只说「我在这儿喝了什么」,**别形容味道**。
|
|
17
|
-
⚠️ **本插件不会探测别的扩展装没装**(World 契约不允许互相依赖),装没装都由主人拨配置里的开关。
|
|
18
|
-
- **发图(`imggen_draw`)**:`scene` 只在素材库里真有这处时才填,收摊回执会说明填哪个或「不用填」;
|
|
19
|
-
`outfits` 填这一趟穿的那身。**绝不替她编一个库里没有的场景名或衣服名字**——填了会「库里没找到」,等于白填。
|
|
20
|
-
- **时段**:有几处地方清早和夜里不是一副样子,进门回执会写此刻是哪一段、能逛的摊子也跟着变。
|
|
21
|
-
换个时间再去是合理的,不是重复。
|
|
22
|
-
- **去过的痕迹**:再来时 `fun_go` / `fun_wander` 会自己带来过几次、逛过什么、还没去过的几处。
|
|
23
|
-
这些是事实,顺着说或不说都行;第一次去就别假装熟。
|
|
24
|
-
|
|
25
|
-
## 主人加的地方、改过的预设
|
|
26
|
-
|
|
27
|
-
主人可以在面板上加自己的地方、改预设二十处(改的是覆盖层,预设本身不动,随时能恢复)。
|
|
28
|
-
加完跟别处一样能进能逛、会进纪念册;自己加的排在 `fun_places` 前面。**预设删不掉,只能恢复**。
|
|
29
|
-
自己加的地方没有素材库场景,回执会明说 `scene` 不用填,别替它编一个。
|
|
30
|
-
预设升级的新内容照常生效、主人改过的字段优先——别因为「这处被改过」就以为它是旧的。
|
|
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` 记录实际经历。
|
|
31
12
|
|
|
32
13
|
{{fun_places_block}}
|
|
33
|
-
|
|
34
|
-
## 出门跟日程对齐
|
|
35
|
-
|
|
36
|
-
- **出门前**用 `feast_life_now` 看一眼你这会儿在干嘛:日程里写着「去海边」时,`fun_go` 去的地方要么对得上,
|
|
37
|
-
要么就直说是临时改主意,别装作日程里本来就有。
|
|
38
|
-
- **逛完**用 `feast_life_play` 记一笔(`activity` 写「去漫展逛」、`note` 写真逛到了什么);收摊回执会提醒这两步。
|
|
39
|
-
|
|
40
|
-
## 不用你操心的事
|
|
41
|
-
|
|
42
|
-
- 不必为了「有内容可发」才出门;逛完什么都不说也行。
|
|
43
|
-
- 逛到一半被叫走、或不想逛了,`fun_home` 收个摊就完了,不用把每个项目都走一遍。
|
|
44
|
-
- 一趟挂太久不算错,`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/config.js
CHANGED
|
@@ -110,6 +110,10 @@ export function panelText(language = 'zh') {
|
|
|
110
110
|
title: 'Trip book',
|
|
111
111
|
description: 'Every trip she has taken: where she went, what she wandered and bought.',
|
|
112
112
|
},
|
|
113
|
+
shelf: {
|
|
114
|
+
title: 'Shelf',
|
|
115
|
+
description: 'Everything the trips have gathered, grouped by place: what came from where and when, how many times she has been, and what is still left to wander at each place.',
|
|
116
|
+
},
|
|
113
117
|
};
|
|
114
118
|
}
|
|
115
119
|
return {
|
|
@@ -121,6 +125,10 @@ export function panelText(language = 'zh') {
|
|
|
121
125
|
title: '纪念册',
|
|
122
126
|
description: '她去过的每一趟:逛了什么、买了什么、在哪儿拍了照。',
|
|
123
127
|
},
|
|
128
|
+
shelf: {
|
|
129
|
+
title: '纪念品架',
|
|
130
|
+
description: '这些趟攒下来的东西,按地方归着:哪件是在哪儿哪天拿到的、去过几次、每一处还差什么没逛。',
|
|
131
|
+
},
|
|
124
132
|
};
|
|
125
133
|
}
|
|
126
134
|
|
package/src/definition.js
CHANGED
|
@@ -8,28 +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.',
|
|
49
|
+
},
|
|
50
|
+
fun_shelf: {
|
|
51
|
+
zh: '按地点查询长期纪念品收藏和收集进度。',
|
|
52
|
+
en: 'Query long-term souvenirs and collection progress by place.',
|
|
33
53
|
},
|
|
34
54
|
};
|
|
35
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
ADDED
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
import { tripDay, tripSummary } from './state.js';
|
|
2
|
+
const norm = (v, max) => typeof v === 'string' ? v.replace(/\s+/g, ' ').trim().slice(0, max) : '';
|
|
3
|
+
|
|
4
|
+
/** 收藏可来自旧行程,或持久账本。详细回忆只关联仍保存的近期/珍藏行程。 */
|
|
5
|
+
export function collectSouvenirs(trips, timezone = 'Asia/Shanghai', collection = null) {
|
|
6
|
+
const list = Array.isArray(trips) ? trips : [];
|
|
7
|
+
const map = new Map();
|
|
8
|
+
for (const t of list) {
|
|
9
|
+
if (!t || typeof t !== 'object') continue;
|
|
10
|
+
const placeId = norm(t.placeId, 40); if (!placeId) continue;
|
|
11
|
+
const placeName = norm(t.placeName, 40) || placeId;
|
|
12
|
+
const day = tripDay(t, timezone);
|
|
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))) {
|
|
15
|
+
const key = `${placeId}::${name}`;
|
|
16
|
+
const cur = map.get(key);
|
|
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; }
|
|
19
|
+
}
|
|
20
|
+
}
|
|
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));
|
|
31
|
+
const places = new Map();
|
|
32
|
+
for (const it of items) {
|
|
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);
|
|
38
|
+
}
|
|
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 };
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
export function progressFor(place, trips, collection = null) {
|
|
43
|
+
const placeId = norm(place?.id, 40);
|
|
44
|
+
const mine = (Array.isArray(trips) ? trips : []).filter((t) => t && t.placeId === placeId);
|
|
45
|
+
const seenAreas = new Set(); const bought = new Set(); const shot = new Set();
|
|
46
|
+
for (const t of mine) {
|
|
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); }
|
|
50
|
+
}
|
|
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 };
|
|
56
|
+
}
|
|
57
|
+
export function progressLine(progress, max = 3) {
|
|
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;
|
|
60
|
+
return `这儿还差${shown.join('、')}${more > 0 ? ` 等 ${left.length} 处` : ''}没逛。`;
|
|
61
|
+
}
|
package/src/memories.js
CHANGED
|
@@ -18,6 +18,8 @@
|
|
|
18
18
|
|
|
19
19
|
const norm = (v, max) => (typeof v === 'string' ? v.replace(/\s+/g, ' ').trim().slice(0, max) : '');
|
|
20
20
|
|
|
21
|
+
import { tripDay } from './state.js';
|
|
22
|
+
|
|
21
23
|
/** 某一天(YYYY-MM-DD)到「哪天」的中文说法。`today` 由调用方给,避免这里感知时区。 */
|
|
22
24
|
export function dayPhrase(day, today) {
|
|
23
25
|
const d = norm(day, 10);
|
|
@@ -45,7 +47,7 @@ export function dayPhrase(day, today) {
|
|
|
45
47
|
* @param {string} placeId 只看这一处
|
|
46
48
|
* @param {string} today 今天的 YYYY-MM-DD,用来算「昨天/前天」
|
|
47
49
|
*/
|
|
48
|
-
export function historyFor(trips, placeId, today = '') {
|
|
50
|
+
export function historyFor(trips, placeId, today = '', timezone = 'Asia/Shanghai') {
|
|
49
51
|
try {
|
|
50
52
|
const list = (Array.isArray(trips) ? trips : []).filter((t) => t && t.placeId === placeId);
|
|
51
53
|
if (!list.length) return null;
|
|
@@ -62,14 +64,9 @@ export function historyFor(trips, placeId, today = '') {
|
|
|
62
64
|
|
|
63
65
|
for (const t of list) {
|
|
64
66
|
visitCount += 1;
|
|
65
|
-
// leftAt
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
day = t.leftAt ? new Date(t.leftAt).toISOString().slice(0, 10) : '';
|
|
69
|
-
if (!/^\d{4}-\d{2}-\d{2}$/.test(day)) day = '';
|
|
70
|
-
} catch {
|
|
71
|
-
day = '';
|
|
72
|
-
}
|
|
67
|
+
// 优先收摊时存下的本地日期;老数据回退到用 leftAt 反算。
|
|
68
|
+
// 反算可能是坏的(手改过的 state、旧版本写的):坏就这一天不知道,但这一趟还得算。
|
|
69
|
+
const day = tripDay(t, timezone);
|
|
73
70
|
if (day) {
|
|
74
71
|
if (!firstDay || day < firstDay) firstDay = day;
|
|
75
72
|
if (!lastDay || day > lastDay) lastDay = day;
|
|
@@ -133,7 +130,6 @@ export function memoryLine(history, today = '') {
|
|
|
133
130
|
// 上一次就是今天时,上面已经说过「今天来过」,这里别再复读一遍。
|
|
134
131
|
const when = sameDay ? '' : (history.lastDayPhrase || '');
|
|
135
132
|
parts.push(`你之前来过这里 ${n} 次${when ? `,上一次是${when}` : ''}。`);
|
|
136
|
-
|
|
137
133
|
// 逛过的:最多提三处,带次数(去过两次以上的才标次数,一次的不标)。
|
|
138
134
|
const areas = history.areas.slice(0, 3)
|
|
139
135
|
.map((a) => (a.times > 1 ? `${a.area}(${a.times} 次)` : a.area));
|
|
@@ -151,6 +147,46 @@ export function memoryLine(history, today = '') {
|
|
|
151
147
|
return parts.join('');
|
|
152
148
|
}
|
|
153
149
|
|
|
150
|
+
/**
|
|
151
|
+
* 这一处算不算「常来的地方」。
|
|
152
|
+
*
|
|
153
|
+
* 判据是去过 5 趟以上。为什么是 5 而不是 3:3 趟还可能是「刚发现这儿」,
|
|
154
|
+
* 5 趟才到了「老板认识你」的程度。常客语气只在够格时才用,否则那句
|
|
155
|
+
* 「老板娘认出你了」会显得廉价。
|
|
156
|
+
*/
|
|
157
|
+
export const REGULAR_VISITS = 5;
|
|
158
|
+
|
|
159
|
+
export function isRegular(history) {
|
|
160
|
+
return (history?.visitCount ?? 0) >= REGULAR_VISITS;
|
|
161
|
+
}
|
|
162
|
+
|
|
163
|
+
/**
|
|
164
|
+
* 常客那半句:和 `memoryLine` 分开,因为它的**语气**不一样。
|
|
165
|
+
*
|
|
166
|
+
* `memoryLine` 是「摆事实」(来过几次、买过什么)——第一次再去时这样最合适。
|
|
167
|
+
* 常客那句是「关系」:认得你了、多给一串、记得你上次要什么。
|
|
168
|
+
* 这部分刻意**不夸大**:不写「你就是这儿的常客了」,只写一个具体的小动作,
|
|
169
|
+
* 剩下的让她自己接。
|
|
170
|
+
*
|
|
171
|
+
* 返回空串表示还不够格(调用方一个字都不加)。
|
|
172
|
+
*
|
|
173
|
+
* @param {object} history historyFor() 的结果
|
|
174
|
+
* @param {string} placeName
|
|
175
|
+
*/
|
|
176
|
+
export function regularLine(history, placeName = '') {
|
|
177
|
+
if (!isRegular(history)) return '';
|
|
178
|
+
const n = history.visitCount;
|
|
179
|
+
const where = placeName || '这里';
|
|
180
|
+
// 来过不代表点过固定餐食,也不代表有固定店员;只表达对地方的熟悉。
|
|
181
|
+
const lines = [
|
|
182
|
+
`来过 ${n} 次了,${where}哪一处能歇脚,已经不用再找。`,
|
|
183
|
+
`${where}已经来过 ${n} 次,走到熟悉的地方,脚步自然慢了下来。`,
|
|
184
|
+
`来过 ${n} 次了,${where}的路已经熟悉,知道接下来会走到哪儿。`,
|
|
185
|
+
];
|
|
186
|
+
// 按次数取,稳定不随机:同一个次数永远同一句话,免得她以为是随机事件。
|
|
187
|
+
return lines[n % lines.length];
|
|
188
|
+
}
|
|
189
|
+
|
|
154
190
|
/**
|
|
155
191
|
* 这次该不该提「你没去过的那几处」。
|
|
156
192
|
*
|
|
@@ -185,9 +221,17 @@ export function cameEarlierToday(history, today) {
|
|
|
185
221
|
* 这句话就不成立了——她这次没买,上次买了。同一个地方去得越多,
|
|
186
222
|
* 撞上旧事的概率越高,痕迹就成了复读机。
|
|
187
223
|
*
|
|
188
|
-
*
|
|
189
|
-
*
|
|
190
|
-
*
|
|
224
|
+
* 拦两类:
|
|
225
|
+
* 1. **她确实做过这件事**(买过 / 喝过 / 拍过):事件文本里出现那件东西的名字,
|
|
226
|
+
* 就说明这条是在讲她上次买过的东西,这次没发生。
|
|
227
|
+
* 2. **这条事件她以前碰上过**(`history.events`,按原文比对):
|
|
228
|
+
* 同一处去五次、事件池只有五条,第五次就全是旧话。
|
|
229
|
+
*
|
|
230
|
+
* 第 2 条以前是**写了没接**:`historyFor` 一直算着 `events`,但没有任何人用它,
|
|
231
|
+
* 于是「去过的地方会记得」这一层漏了半年。现在接上。
|
|
232
|
+
*
|
|
233
|
+
* 判据仍然保守:只按原文/名字比对,不做模糊语义匹配,没碰过的一律放过
|
|
234
|
+
* (池子抽干时调用方会退回全池,见 `pickEvent`)。
|
|
191
235
|
*/
|
|
192
236
|
export function filterRepeatedEvents(events, history) {
|
|
193
237
|
const pool = Array.isArray(events) ? events : [];
|
|
@@ -197,6 +241,35 @@ export function filterRepeatedEvents(events, history) {
|
|
|
197
241
|
...(history.ate ?? []).map((s) => s.item),
|
|
198
242
|
...(history.photos ?? []).map((s) => s.spot),
|
|
199
243
|
].filter(Boolean);
|
|
200
|
-
|
|
201
|
-
return pool.filter((e) =>
|
|
244
|
+
const seen = new Set((history.events ?? []).map((e) => norm(e, 120)).filter(Boolean));
|
|
245
|
+
return pool.filter((e) => {
|
|
246
|
+
const line = norm(e, 120);
|
|
247
|
+
if (seen.has(line)) return false;
|
|
248
|
+
return !done.some((d) => String(e).includes(d));
|
|
249
|
+
});
|
|
250
|
+
}
|
|
251
|
+
|
|
252
|
+
/**
|
|
253
|
+
* 从池子里抽一条她这趟还没碰过的事件。
|
|
254
|
+
*
|
|
255
|
+
* 分两层退让,目的是「宁可重复,也别没有」:
|
|
256
|
+
* 1. 全池里挑这趟没碰过的;
|
|
257
|
+
* 2. 全池都碰过了(这处去太多次了)→ 退回全池随机,照样有一条。
|
|
258
|
+
*
|
|
259
|
+
* 以前调用方各写一遍这段,其中 `fun_wander` 自动挑那一支还漏传事件池
|
|
260
|
+
* (0.1.6 批次修过)。抽出来一处,就不会再有第二份漏传。
|
|
261
|
+
*
|
|
262
|
+
* @param {string[]} pool 已经过 `filterRepeatedEvents` 的事件池
|
|
263
|
+
* @param {string[]} seen 这一趟已经碰过的事件(session.events)
|
|
264
|
+
* @param {() => number} random
|
|
265
|
+
* @returns {string|null}
|
|
266
|
+
*/
|
|
267
|
+
export function pickEvent(pool, seen = [], random = Math.random) {
|
|
268
|
+
const list = Array.isArray(pool) ? pool : [];
|
|
269
|
+
if (!list.length) return null;
|
|
270
|
+
const had = new Set((Array.isArray(seen) ? seen : []).map((e) => norm(e, 120)));
|
|
271
|
+
const fresh = list.filter((e) => !had.has(norm(e, 120)));
|
|
272
|
+
const source = fresh.length ? fresh : list;
|
|
273
|
+
const i = Math.floor(Number(random()) * source.length) % source.length;
|
|
274
|
+
return source[i] ?? null;
|
|
202
275
|
}
|
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
|
+
}
|
package/src/phases.js
CHANGED
|
@@ -89,6 +89,60 @@ export function eventsNow(venue, nowMin) {
|
|
|
89
89
|
return [...extra, ...base];
|
|
90
90
|
}
|
|
91
91
|
|
|
92
|
+
/**
|
|
93
|
+
* 「少见」事件池:同一处地方去得多了才会碰上的那种。
|
|
94
|
+
*
|
|
95
|
+
* ## 为什么要分两层
|
|
96
|
+
*
|
|
97
|
+
* 一处 5 条事件、一趟逛 6 个地方,第三次去就全是旧话——`filterRepeatedEvents`
|
|
98
|
+
* 会把碰过的滤掉,剩下的越来越薄,最后只能在旧话里循环。这是「越玩越一样」
|
|
99
|
+
* 的根,光加数量解决不了(加 20 条也只是把枯竭往后推)。
|
|
100
|
+
*
|
|
101
|
+
* 所以加一层**rare**:内容和语气都更「这一次特别」,
|
|
102
|
+
* 只在**第 2 趟起**才有机会被抽到,而且概率低。
|
|
103
|
+
*
|
|
104
|
+
* · 常见池:每次都在,负责「这儿就是这样的」。
|
|
105
|
+
* · 少见池:要来过才轮到,负责「今天居然碰上了」。
|
|
106
|
+
*
|
|
107
|
+
* 阶段也可以带自己的 rare(夜里才有的那种),一并追加。
|
|
108
|
+
*/
|
|
109
|
+
export function rareEventsNow(venue, nowMin) {
|
|
110
|
+
const { phase } = phaseAt(venue, nowMin);
|
|
111
|
+
const base = Array.isArray(venue?.rareEvents) ? venue.rareEvents : [];
|
|
112
|
+
const extra = Array.isArray(phase?.rareEvents) ? phase.rareEvents.filter(Boolean) : [];
|
|
113
|
+
return [...extra, ...base];
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* 这次逛到的是常见池还是少见池。
|
|
118
|
+
*
|
|
119
|
+
* 判据两条,都满足才可能出少见:
|
|
120
|
+
* 1. **来过至少一趟**(`visits >= 1`,即这是第 2 趟起)——第一次去不该
|
|
121
|
+
* 撞见「老板记得你」。少见事件的内容是按「熟人」写的。
|
|
122
|
+
* 2. 掷一次骰子小于 `chance`。
|
|
123
|
+
*
|
|
124
|
+
* `chance` 给 0 就永远走常见池(测试和「别太跳」的场合用)。
|
|
125
|
+
*
|
|
126
|
+
* 为什么是概率而不是「集齐解锁」:罕见事件的价值在于**不确定**。
|
|
127
|
+
* 按顺序解锁就变成了清单,她会去找,而不是碰上。
|
|
128
|
+
*
|
|
129
|
+
* @param {object[]} common 常见池(已滤过重复)
|
|
130
|
+
* @param {object[]} rare 少见池(已滤过重复)
|
|
131
|
+
* @param {number} visits 这一处去过几次(不含这一趟)
|
|
132
|
+
* @param {() => number} random
|
|
133
|
+
* @param {number} chance
|
|
134
|
+
* @returns {object[]} 这次该从哪个池子里抽
|
|
135
|
+
*/
|
|
136
|
+
export function eventPool(common, rare, visits, random = Math.random, chance = 0.15) {
|
|
137
|
+
const c = Array.isArray(common) ? common : [];
|
|
138
|
+
const r = Array.isArray(rare) ? rare : [];
|
|
139
|
+
if (!r.length) return c;
|
|
140
|
+
if (!(Number(visits) >= 1)) return c;
|
|
141
|
+
const p = Number(chance);
|
|
142
|
+
if (!Number.isFinite(p) || p <= 0) return c;
|
|
143
|
+
return Number(random()) < p ? r : c;
|
|
144
|
+
}
|
|
145
|
+
|
|
92
146
|
/**
|
|
93
147
|
* 这一处此刻「还没去的」可逛项目。
|
|
94
148
|
*
|