cortico-world-genesis 2.2.7 → 2.6.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/src/index.ts CHANGED
@@ -202,6 +202,7 @@ export {
202
202
  type AtmosphereReading,
203
203
  } from './life.ts';
204
204
  export { HABITAT_COMFORT_C, HABITAT_CLIMATE_PULL_C, habitatInteriorC, habitatComfortIssue } from './game.ts';
205
+ export { structureInteriorC, interiorComfortable, STAFF_COMFORT_C, LODGE_COMFORT_C, S2_ENGINE_MAX, S2_COMPUTE_PER_HOUR, S2_KJ_PER_COMPUTE } from './game.ts';
205
206
  export { ordersForDay, GENE_LABELS, type Order } from './orders.ts';
206
207
  export { PROTOCOL_TASKS, CHAPTER_TITLES, protocolStatus, protocolDone, protocolComplete } from './protocol.ts';
207
208
 
@@ -34,6 +34,8 @@ export interface GenesisPanelPower {
34
34
  tungsten: number;
35
35
  /** 着陆舱:开局的口粮/水/氧气和还能撑多久。 */
36
36
  ship: GenesisPanelShip;
37
+ /** 执照与两条线的存量。 */
38
+ charter: GenesisPanelCharter;
37
39
  /** 本地行星电网:有没有整流电塔、离多远、存了多少。 */
38
40
  grid: GenesisPanelGrid;
39
41
  sails: number;
@@ -167,6 +169,42 @@ export interface GenesisPanelBuild {
167
169
  leftHomeHours: number;
168
170
  }
169
171
 
172
+ /** 执照与两条线的存量(2.4.0)。 */
173
+ export interface GenesisPanelCharter {
174
+ /** 还没选就是 null。 */
175
+ charter: 'tourism' | 'tech' | null;
176
+ /** 0–100,只有旅游线会长。 */
177
+ reputation: number;
178
+ /** 只有科技线会长。 */
179
+ compute: number;
180
+ /** 科技线的员工数与上限。 */
181
+ staff: number;
182
+ staffCap: number;
183
+ /** 昨日到港游客(旅游线)。 */
184
+ visitors: number;
185
+ /** 时间倍速(1–200)。 */
186
+ speed: number;
187
+ /** 1 倍速下「一个母星时 = 多少现实分钟」。 */
188
+ baseMinutesPerHomeHour: number;
189
+ /** 住得下(温度合适、通电)的访客床位。 */
190
+ lodgeBeds: number;
191
+ /** 住得下的员工床位。 */
192
+ housingBeds: number;
193
+ /** 因为太热/太冷而白建的住所。 */
194
+ tempBlocked: string[];
195
+ /** 当前倍速下同一件事。 */
196
+ minutesPerHomeHour: number;
197
+ /** 停泊位 / 床位 / 招募站 / 晶圆厂数量,面板直接拿去说人话。 */
198
+ docks: number;
199
+ lodges: number;
200
+ offices: number;
201
+ fabs: number;
202
+ /** 正在建的奇观(一次只有一座)。 */
203
+ wonder: { id: string; label: string; progress: number } | null;
204
+ /** 已经落成的奇观。 */
205
+ wonders: string[];
206
+ }
207
+
170
208
  /** 面板一次拿到的全部数据;`locked` 为真时说明已经创世,界面不再给表单。 */
171
209
  export interface GenesisPanelState {
172
210
  locked: boolean;
@@ -350,3 +388,43 @@ export interface GenesisUpgradeState {
350
388
  energyKj: number;
351
389
  cards: GenesisUpgradeCard[];
352
390
  }
391
+
392
+ /** 商店页签的一行货(买或卖)。 */
393
+ export interface GenesisShopRow {
394
+ id: string;
395
+ name: string;
396
+ /** 已格式化好的一行价格,比如「1,200 kJ」「30 信用点/kg」。 */
397
+ priceLabel: string;
398
+ /** 今天还能买卖多少。 */
399
+ limitLabel: string;
400
+ note?: string;
401
+ /** 卖出时:我手里有多少(kg 或份)。 */
402
+ held?: number;
403
+ /** 这一行今天卖的具体物种(种子行才有)。 */
404
+ species?: string;
405
+ }
406
+
407
+ /** 商店页签的一张基因订单。 */
408
+ export interface GenesisShopOrder {
409
+ id: string;
410
+ label: string;
411
+ note: string;
412
+ }
413
+
414
+ /** 「商店」页签:开没开张、货架、收购价、订单。 */
415
+ export interface GenesisShopPanel {
416
+ open: boolean;
417
+ /** 「12:00–23:00 营业」这类说明;关张时说明为什么。 */
418
+ window: string;
419
+ /** 离下次开张还有几个母星时(开张时为 0)。 */
420
+ nextOpenHours: number;
421
+ level: number;
422
+ credits: number;
423
+ energyKj: number;
424
+ tungsten: number;
425
+ buyables: GenesisShopRow[];
426
+ sellables: GenesisShopRow[];
427
+ orders: GenesisShopOrder[];
428
+ /** 关张时给一句总说明。 */
429
+ closedNote?: string;
430
+ }
@@ -0,0 +1,2 @@
1
+ // 由 scripts/build-guide-content.mjs 从 src/TOOLS.md 生成,别手改。
2
+ export const TOOLS_SNAPSHOT: string = "# 工具总表\n\n每个工具一行:**做什么 · 关键参数 · 一句提醒**。\n价格、材料、当前等级一律现查(`genesis_info` / `genesis_recipes`),别凭记忆报价。\n\n## 一、创世与档案\n\n| 工具 | 说明 |\n| --- | --- |\n| `genesis_menu` | 创世菜单:四个输入的含义、行星数与卫星上限由种子决定。 | \n| `genesis_create` | 建世:`seed`(数字或一句话)、`starMass`(0.15–2.0)、`starName`、`homeName`。只能成功一次;重复调用只回「已经创世过了」,不返回星卡。 |\n| `genesis_reset` | 删档重来:**必须** `confirm: \"DELETE\"`,且对方明确同意。 |\n| `genesis_card` | 星卡:恒星与**已装监测器**的天体属性。没监测器的天体只会写「尚未观测」。 |\n| `genesis_info` | 查单件东西:建筑、资源、作物、升级、机制。`query` 可写 id 或中文名,模糊搜,回 3 条。 |\n\n## 二、时间、天象与观测\n\n| 工具 | 说明 |\n| --- | --- |\n| `genesis_time` | 现在几点、在哪、是否在移动、电量与着陆舱补给。时间格式「13曙光年-42曙光日-7.5曙光时」。 |\n| `genesis_sun` | 太阳高度角/方位角;高度角 > 0 是白天。换过经纬度后只能靠它判昼夜。 |\n| `genesis_stargaze` | 观星:可见度 > 0.5 才可用,列出够亮的天体,开 1 母星时的航行窗口。望远镜 lv2 起可见度 +0.15。 |\n| `genesis_transit` | 我在第几颗行星/卫星:需要所在天体装了【凌日计数器】。 |\n| `genesis_veins` | 扫矿:脚下 5×5 格剩余钨含量 + 最富格的方位距离;需要【质谱仪】,每 6 母星时一次。 |\n\n## 三、看与走\n\n| 工具 | 说明 |\n| --- | --- |\n| `genesis_look` | 此刻这里:脚下、太阳、近处 5×5 地形、200 km 内站点与建筑、天上可见天体。 |\n| `genesis_terrain` | 看某片地形:`lat`/`lon` 必填,`planetIndex`/`moonIndex` 可指别处;不指就是脚下。岩石行星给群系/海拔/均温,气态给风暴带。 |\n| `genesis_move` | `kind: \"surface\"` 带 `lat`/`lon` 走过去;`\"interstellar\"` 带 `target`(`p2`、`p2-m1` 或【未抵星体-xxxx】);`\"home\"` 回母星。都要时间,路上不能观星/起名。 |\n| `genesis_wait` | 原地等:`hours`(≤7 母星日)或 `until: dawn\\|dusk\\|noon\\|open\\|ripe\\|built\\|arrive`。按 1 母星时步进并汇报。 |\n| `genesis_name` | 给脚下天体起名(≤12 字,不重名);恒星与已命名天体不能再改。 |\n\n## 四、建造与安装\n\n| 工具 | 说明 |\n| --- | --- |\n| `genesis_install` | 唯一的建造入口。`id` 取:`greenhouse` `pump` `warehouse` `cold_store` `inert_room` `drone_cluster` `rocket` `biome_changer` `monitor` `counter` `sail` `rectifier` `miner` `kiln` `purifier` `sealer` `atmo_extractor` `mutator` `habitat` `arm` `terminal` `storage_terminal` `duty` `carrier` `wind` `fire` `converter` `planter`,以及配件 `cooler` `heater` `realism`(配件不进队列)。气态/冰巨星的子建筑把 `site` 写成 `carrier:<母舰id>`。 |\n| `genesis_upgrade` | 船上升级:`mobility_core` `telescope` `spark_plug` `battery` `subagent` `blueprints` `spectrometer`。不带 `id` 只列清单。 |\n| `genesis_recipes` | 升级与维修总表:等级、造价、材料(需要 vs 现有)、还差什么、下一级效果。 |\n| `genesis_store` | 容器与背包:`list`、`deposit`、`withdraw`、`demolish`、`bags`、`take`、`use`(罐装液氨)、`grid`/`grid_in`/`grid_out`(电网)、`fertilize`(撒复合肥)。着陆舱用 `building: \"pod\"`。 |\n\n## 五、农业\n\n| 工具 | 说明 |\n| --- | --- |\n| `genesis_site` | 在脚下建 1 km² 站点(一格最多 3 个;水面不行,冰盖可以,会自带 100 L 冰窖)。`kind` 自动判湿地/旱地。 |\n| `genesis_plant` | 播种:`site`(或 `planter:<建筑id>`)+ 种子袋 id,`count` 可一次多种。 |\n| `genesis_flora` | 农场总览:站点气候、作物阶段/进度/健康、温室与种植盆状态;也用来建/收/施肥。 |\n| `genesis_harvest` | 收一株或一片:大型作物一次收完,群落留接种量;收成进站点或值班仓库。 |\n| `genesis_inspect` | 一株作物的全部细节:基因、有效温区、温湿肥、四维养分当前/阈值、生长因子拆解、剩余母星时、预计收成。 |\n| `genesis_transplant` | 移栽:把进度 ≥15% 的作物挖回种子袋(基因不变,这株就没了)。 |\n| `genesis_breed` | 留种:`mode: \"self\"`(300 kJ、0.2 时、3 粒,产量每代 −4%)/ `\"cross\"`(800 kJ、0.5 时、4 粒,需同物种另一株)。 |\n| `genesis_algae` | 藻肥:3 kg 蓝藻 → 目标旱地 +0.02 氮 +0.005 钾,200 kJ。 |\n| `genesis_remove` | 拔掉枯死/应激到 20% 以下的作物,腾出位置。 |\n\n## 六、贸易与信用点\n\n| 工具 | 说明 |\n| --- | --- |\n| `genesis_shop` | 商店:货架、当日价、限额、营业窗口;带 `sell` + `amount` 可卖货。商人不在就什么都不行。 |\n| `genesis_buy` | 买:`kind` 取 `random_seed` `premium_seed` `cylinder` `chart` `tungsten` `energy_block` `fertilizer`(`kg`)。种子用 kJ,其余多用信用点。 |\n| `genesis_survey` | 测绘:每颗行星的每个群系只认第一次,普通 1 份、难去的地方 2 份,50 信用点/份。 |\n| `genesis_orders` | 商人的基因订单:接单、交货;只在开张时能做。 |\n\n## 七、物流与自动化\n\n| 工具 | 说明 |\n| --- | --- |\n| `genesis_route` | 仓储终端编排表:给容器(按槽位或 id)设优先级,数字越大越先被取,0 最低;不写进去的不动。 |\n| `genesis_link` | 改机械臂线路:`inputs`(多个)/ `output`(一个)/ `items`(白名单,不传全搬)。臂展 5 km,每行星 20 座,成环只提醒不拦。 |\n| `genesis_duty` | 改值班终端绑定:`habitat` / `store` / `sites`(≤6)。没有值班终端,人只吃饭不干活。 |\n\n## 八、生命、协议与手册\n\n| 工具 | 说明 |\n| --- | --- |\n| `genesis_protocol` | 唤醒清单:12 条三章;门槛只数前 11 条,第 12 条是结果。 |\n| `genesis_wake` | 叫醒人类:`habitat` 或 `carrier` 可指定;室内 5–32℃ 才肯住,休眠舱没人了会报错。 |\n| `genesis_mutate` | 诱变:一袋种子 → 3–5 颗基因抖动的种子,需站在诱变室站点。 |\n| `genesis_guide` | 教程:不带 `topic` 给目录;`start` `plan` `time` `power` `mine` `farm` `logistics` `trade` `upgrade` `life` `trouble`。 |\n| `genesis_tools` | 这张表。`query` 可搜工具名或关键词。 |\n| `genesis_burn` | **已停用**:燃料只能进【火力发电站】。 |\n";
@@ -0,0 +1,46 @@
1
+ import { readFileSync } from 'node:fs';
2
+ import { fileURLToPath } from 'node:url';
3
+
4
+ import { TOOLS_SNAPSHOT } from './tools-content.ts';
5
+
6
+ const cache = new Map<string, string>();
7
+
8
+ function toolsBody(): string {
9
+ const hit = cache.get('all');
10
+ if (hit !== undefined) return hit;
11
+ let text: string;
12
+ try {
13
+ text = readFileSync(fileURLToPath(new URL('./TOOLS.md', import.meta.url)), 'utf8');
14
+ } catch {
15
+ text = TOOLS_SNAPSHOT;
16
+ }
17
+ if (!text) {
18
+ throw new Error('工具表丢了:src/TOOLS.md(跑 node scripts/build-guide-content.mjs 重新生成快照)。');
19
+ }
20
+ cache.set('all', text);
21
+ return text;
22
+ }
23
+
24
+ /** 整张工具表。 */
25
+ export function toolsText(): string {
26
+ return toolsBody();
27
+ }
28
+
29
+ /** 按关键词过滤工具表:命中行 + 表格里它所在的那几行。 */
30
+ export function toolsSearch(query: string | undefined): string {
31
+ const text = toolsBody();
32
+ const q = (query ?? '').trim().toLowerCase();
33
+ if (!q) return text;
34
+ const lines = text.split('\n');
35
+ const keep = new Set<number>();
36
+ for (let i = 0; i < lines.length; i += 1) {
37
+ if (lines[i]!.toLowerCase().includes(q)) {
38
+ for (let k = Math.max(0, i - 1); k <= Math.min(lines.length - 1, i + 2); k += 1) keep.add(k);
39
+ }
40
+ }
41
+ if (keep.size === 0) {
42
+ return `工具表里没有「${query}」。不带参数可以看全表。`;
43
+ }
44
+ const picked = [...keep].sort((a, b) => a - b).map((i) => lines[i]!);
45
+ return picked.join('\n').trim();
46
+ }
@@ -1,5 +1,5 @@
1
1
  import type { WebUiClientBundle, WebUiPanel, WebUiPanelContext } from 'cortico/web/shared/client-panel.ts';
2
- import type { GenesisPanelState, GenesisProtocolPanel, GenesisSurfaceMap, GenesisUpgradeState } from '../panel-types.ts';
2
+ import type { GenesisPanelState, GenesisProtocolPanel, GenesisShopPanel, GenesisSurfaceMap, GenesisUpgradeState } from '../panel-types.ts';
3
3
 
4
4
  interface Text {
5
5
  title: string;
@@ -42,6 +42,15 @@ interface Text {
42
42
  gridIn: string;
43
43
  gridOut: string;
44
44
  gridStored: string;
45
+ speedTitle: string;
46
+ speedHint: (speed: number, realMinutes: number) => string;
47
+ charterNone: string;
48
+ charterTourism: (reputation: number, visitors: number, docks: number, lodges: number) => string;
49
+ charterTech: (compute: number, staff: number, cap: number, fabs: number) => string;
50
+ wonderLine: (label: string, percent: number) => string;
51
+ bedsInfo: (lodge: number, housing: number) => string;
52
+ tempWarning: (list: string) => string;
53
+ wondersDone: (count: number) => string;
45
54
  gridReach: string;
46
55
  gridFar: string;
47
56
  gridTowerAt: string;
@@ -178,6 +187,24 @@ interface Text {
178
187
  guideEmpty: string;
179
188
  guideSearch: string;
180
189
  guideSearchHint: string;
190
+ guideTools: string;
191
+ shopTitle: string;
192
+ shopDesc: string;
193
+ shopOpenNow: string;
194
+ shopClosedNow: string;
195
+ shopWindowLabel: string;
196
+ shopNextOpen: (hours: number) => string;
197
+ shopCredits: string;
198
+ shopEnergy: string;
199
+ shopTungsten: string;
200
+ shopSellHeader: string;
201
+ shopBuyHeader: string;
202
+ shopOrdersHeader: string;
203
+ shopHeld: (amount: string) => string;
204
+ shopSell: (name: string, unit: string) => string;
205
+ shopBuy: (name: string) => string;
206
+ shopDeliver: string;
207
+ shopNoOrders: string;
181
208
  protoClear: string;
182
209
  }
183
210
 
@@ -222,7 +249,18 @@ const ZH: Text = {
222
249
  generatorBusy: '动能发电机(冷却中…)',
223
250
  generatorHint: '只有你能按;Agent 不会自己发电,缺电时会来求你。现在一次 {kj} kJ,0.5 秒冷却。修【火花塞】能让它更省力。',
224
251
  gridIn: '从电网搬电(-10%)',
252
+ speedTitle: '时间倍速',
253
+ speedHint: (x: number, realMin: number) => `${x} 倍:一个母星时 ${realMin.toFixed(2)} 分钟现实时间。`,
254
+ charterNone: '还没选执照:去商店买【星际广播 · 旅游星系】或【星际广播 · 技术星系】(一局只能选一张)。',
255
+ charterTourism: (rep: number, visitors: number, docks: number, lodges: number) =>
256
+ `旅游星系 · 知名度 ${rep.toFixed(1)}/100 · 昨日到港 ${visitors} 位 · ${docks} 个停泊位 / ${lodges} 床`,
257
+ charterTech: (compute: number, staff: number, cap: number, fabs: number) =>
258
+ `技术星系 · 计算力 ${compute.toFixed(1)} · 员工 ${staff}/${cap} · ${fabs} 座晶圆厂`,
225
259
  gridOut: '把电送进电网(-10%)',
260
+ bedsInfo: (lodge, housing) => `床位:访客 ${lodge} · 员工 ${housing}(太热太冷的不算)`,
261
+ tempWarning: (list) => `⚠ 住不下:${list}`,
262
+ wonderLine: (label, percent) => `奇观:${label} · ${percent}%`,
263
+ wondersDone: (count) => `已落成奇观 ${count} 座`,
226
264
  gridStored: '本地电网:',
227
265
  gridReach: '电塔就在',
228
266
  gridFar: '离电塔',
@@ -356,6 +394,24 @@ const ZH: Text = {
356
394
  guideEmpty: '挑一篇。不确定从哪看,先看「醒来」,再看「路线图」。',
357
395
  guideSearch: '查东西',
358
396
  guideSearchHint: '查一件东西:温室、钨、腐烂、duty…',
397
+ guideTools: '工具表',
398
+ shopTitle: '商店',
399
+ shopDesc: '商人只在一定的时间来:卖货、买种子与设备、交订单都在这里。关张时按钮是灰的,价目照看。',
400
+ shopOpenNow: '开张中',
401
+ shopClosedNow: '关张',
402
+ shopWindowLabel: '营业时间',
403
+ shopNextOpen: (hours) => '还有 ' + hours + ' 母星时开张',
404
+ shopCredits: '信用点',
405
+ shopEnergy: '能量',
406
+ shopTungsten: '钨',
407
+ shopSellHeader: '卖给他',
408
+ shopBuyHeader: '从他这买',
409
+ shopOrdersHeader: '他带来的订单',
410
+ shopHeld: (amount) => '手里 ' + amount,
411
+ shopSell: (name, unit) => '卖 ' + unit + ' ' + name,
412
+ shopBuy: (name) => '买 ' + name,
413
+ shopDeliver: '交货',
414
+ shopNoOrders: '这一会儿没有订单。',
359
415
  protoClear: '全部完成。',
360
416
  };
361
417
 
@@ -400,7 +456,18 @@ const EN: Text = {
400
456
  generatorBusy: 'Kinetic generator (cooling…)',
401
457
  generatorHint: 'Only you can press it; the agent never generates power and will ask you when it needs some. Now {kj} kJ per press, 0.5 s cooldown. Repairing the spark plug makes it go further.',
402
458
  gridIn: 'Tap the grid (−10%)',
459
+ speedTitle: 'Time speed',
460
+ speedHint: (x: number, realMin: number) => `${x}× — one home hour is ${realMin.toFixed(2)} real minutes.`,
461
+ charterNone: 'No charter yet: buy a broadcast licence (tourism or tech) at the shop — one per run.',
462
+ charterTourism: (rep: number, visitors: number, docks: number, lodges: number) =>
463
+ `Tourism · fame ${rep.toFixed(1)}/100 · ${visitors} visitors yesterday · ${docks} docks / ${lodges} beds`,
464
+ charterTech: (compute: number, staff: number, cap: number, fabs: number) =>
465
+ `Tech · compute ${compute.toFixed(1)} · staff ${staff}/${cap} · ${fabs} fabs`,
403
466
  gridOut: 'Feed the grid (−10%)',
467
+ bedsInfo: (lodge, housing) => `Beds: guests ${lodge} · staff ${housing} (hot/cold ones don’t count)`,
468
+ tempWarning: (list) => `⚠ Unlivable: ${list}`,
469
+ wonderLine: (label, percent) => `Wonder: ${label} · ${percent}%`,
470
+ wondersDone: (count) => `${count} wonder(s) standing`,
404
471
  gridStored: 'Local grid: ',
405
472
  gridReach: 'tower is',
406
473
  gridFar: 'tower is',
@@ -534,6 +601,24 @@ const EN: Text = {
534
601
  guideEmpty: 'Pick a chapter. If you are not sure, start with "Waking up", then "Roadmap".',
535
602
  guideSearch: 'Look up',
536
603
  guideSearchHint: 'Look up one thing: greenhouse, tungsten, rot, duty…',
604
+ guideTools: 'All tools',
605
+ shopTitle: 'Shop',
606
+ shopDesc: 'The merchant only comes around at certain hours: selling, buying seeds and gear, handing in orders — all here. Buttons grey out when he is away; prices stay visible.',
607
+ shopOpenNow: 'Open',
608
+ shopClosedNow: 'Closed',
609
+ shopWindowLabel: 'Hours',
610
+ shopNextOpen: (hours) => 'Opens in ' + hours + ' home hours',
611
+ shopCredits: 'Credits',
612
+ shopEnergy: 'Energy',
613
+ shopTungsten: 'Tungsten',
614
+ shopSellHeader: 'Sell',
615
+ shopBuyHeader: 'Buy',
616
+ shopOrdersHeader: 'His orders',
617
+ shopHeld: (amount) => 'You hold ' + amount,
618
+ shopSell: (name, unit) => 'Sell ' + unit + ' ' + name,
619
+ shopBuy: (name) => 'Buy ' + name,
620
+ shopDeliver: 'Deliver',
621
+ shopNoOrders: 'No orders right now.',
537
622
  protoClear: 'All done.',
538
623
  };
539
624
 
@@ -798,6 +883,19 @@ const panel: WebUiPanel = {
798
883
  const energyLine = ctx.ui.h('div', 'mono');
799
884
  const shipLineEl = ctx.ui.h('div', 'mono');
800
885
  shipLineEl.style.fontSize = '12px';
886
+ async function setSpeed(): Promise<void> {
887
+ try {
888
+ const payload = await ctx.invoke<{ text: string; state: GenesisPanelState }>('speed', [Number(speedInput.value)]);
889
+ if (payload?.state) {
890
+ state = payload.state;
891
+ render();
892
+ }
893
+ ctx.ui.toast(payload?.text ?? t.speedTitle, 'ok');
894
+ } catch (error) {
895
+ ctx.ui.toast(errorText(error), 'bad');
896
+ }
897
+ }
898
+
801
899
  const genButton = ctx.ui.button(t.generator, { size: 'sm', variant: 'primary', onClick: () => void press() });
802
900
  const genHint = ctx.ui.h('div', 'muted', t.generatorHint);
803
901
  genHint.style.fontSize = '12px';
@@ -809,7 +907,31 @@ const panel: WebUiPanel = {
809
907
  const gridInButton = ctx.ui.button(t.gridIn, { size: 'sm', onClick: () => void gridMove('grid_in') });
810
908
  const gridOutButton = ctx.ui.button(t.gridOut, { size: 'sm', onClick: () => void gridMove('grid_out') });
811
909
  gridRow.append(gridInButton, gridOutButton);
812
- powerBox.append(ctx.ui.h('h3', undefined, t.powerTitle), energyLine, shipLineEl, genButton, genHint, gridLineEl, gridRow);
910
+ const speedRow = ctx.ui.h('div');
911
+ speedRow.style.display = 'flex';
912
+ speedRow.style.gap = '6px';
913
+ speedRow.style.alignItems = 'center';
914
+ function baseMinutesNow(): number {
915
+ const snapshot = state as GenesisPanelState | null;
916
+ return snapshot?.power?.charter?.baseMinutesPerHomeHour ?? 60;
917
+ }
918
+ const speedInput = doc.createElement('input');
919
+ speedInput.type = 'range';
920
+ speedInput.value = '1';
921
+ speedInput.min = '1';
922
+ speedInput.max = '200';
923
+ speedInput.step = '1';
924
+ speedInput.style.flex = '1';
925
+ const speedLabel = ctx.ui.h('div', 'muted', t.speedHint(1, baseMinutesNow()));
926
+ speedLabel.style.fontSize = '12px';
927
+ speedRow.append(ctx.ui.h('span', 'muted', t.speedTitle), speedInput);
928
+ speedInput.addEventListener('input', () => {
929
+ speedLabel.textContent = t.speedHint(Number(speedInput.value), baseMinutesNow() / Number(speedInput.value));
930
+ });
931
+ speedInput.addEventListener('change', () => void setSpeed());
932
+ const charterLine = ctx.ui.h('div', 'muted');
933
+ charterLine.style.fontSize = '12px';
934
+ powerBox.append(ctx.ui.h('h3', undefined, t.powerTitle), energyLine, shipLineEl, genButton, genHint, gridLineEl, gridRow, speedRow, speedLabel, charterLine);
813
935
 
814
936
  const monitorBox = ctx.ui.h('div');
815
937
  monitorBox.style.display = 'grid';
@@ -959,6 +1081,16 @@ const panel: WebUiPanel = {
959
1081
  { value: 'wind', label: '风力发电站' },
960
1082
  { value: 'fire', label: '火力发电站' },
961
1083
  { value: 'converter', label: '气液转换机' },
1084
+ { value: 'tourism_dock', label: '观光塔台(需旅游执照)' },
1085
+ { value: 'visitor_lodge', label: '访客驿站(需旅游执照)' },
1086
+ { value: 'recruit_office', label: '招募站(需技术执照)' },
1087
+ { value: 'staff_housing', label: '员工公寓(需技术执照)' },
1088
+ { value: 'fab', label: '晶圆厂(需技术执照)' },
1089
+ { value: 'tour_line', label: '观光线路站(需旅游执照)' },
1090
+ { value: 'souvenir', label: '纪念品店(需旅游执照)' },
1091
+ { value: 'compute_array', label: '计算阵列(需技术执照)' },
1092
+ { value: 'heavy_water', label: '重水提取器(需技术执照)' },
1093
+ { value: 'enrichment', label: '富集塔(需技术执照)' },
962
1094
  ],
963
1095
  }) as HTMLSelectElement;
964
1096
  const buildButton = ctx.ui.button(t.buildHere, { size: 'sm', variant: 'primary', onClick: () => void buildHere() });
@@ -1214,6 +1346,24 @@ const panel: WebUiPanel = {
1214
1346
  ? `${t.generatorBusy} ${(cooldownMs / 1000).toFixed(1)}s`
1215
1347
  : t.generator.replace('{kj}', String(kj));
1216
1348
  genHint.textContent = t.generatorHint.replace('{kj}', String(kj));
1349
+ const charter = power.charter;
1350
+ speedInput.value = String(charter.speed ?? 1);
1351
+ speedLabel.textContent = t.speedHint(
1352
+ charter.speed ?? 1,
1353
+ (charter.baseMinutesPerHomeHour ?? 60) / (charter.speed ?? 1),
1354
+ );
1355
+ charterLine.textContent = !charter.charter
1356
+ ? t.charterNone
1357
+ : charter.charter === 'tourism'
1358
+ ? t.charterTourism(charter.reputation, charter.visitors, charter.docks, charter.lodges)
1359
+ : t.charterTech(charter.compute, charter.staff, charter.staffCap, charter.fabs);
1360
+ charterLine.textContent += `\n${t.bedsInfo(charter.lodgeBeds ?? 0, charter.housingBeds ?? 0)}`;
1361
+ if ((charter.tempBlocked ?? []).length > 0) charterLine.textContent += `\n${t.tempWarning(charter.tempBlocked.join('、'))}`;
1362
+ if (charter.wonder) {
1363
+ charterLine.textContent += `\n${t.wonderLine(charter.wonder.label, Math.round(charter.wonder.progress * 100))}`;
1364
+ } else if (charter.wonders.length > 0) {
1365
+ charterLine.textContent += `\n${t.wondersDone(charter.wonders.length)}`;
1366
+ }
1217
1367
  const grid = power.grid;
1218
1368
  gridLineEl.textContent = grid
1219
1369
  ? grid.hasTower
@@ -1333,27 +1483,11 @@ const panel: WebUiPanel = {
1333
1483
  const sellButton = ctx.ui.button(`卖 1 ${item.name}`, { size: 'sm', onClick: () => void floraDo('sell', [item.id, 1]) });
1334
1484
  floraInv.append(sellButton);
1335
1485
  }
1336
- // 商人不在就整块藏起来:基因订单与钢瓶都是跟他做的买卖。
1486
+ // 买卖搬去「商店」页签了;这里只留对地块的动作。
1337
1487
  floraTrade.replaceChildren();
1338
- floraTrade.hidden = !flora.shopOpen;
1339
- if (flora.shopOpen) {
1340
- for (const order of state?.orders ?? []) {
1341
- floraTrade.append(
1342
- ctx.ui.button(`${t.lifeOrder}:${order.species} · ${order.gene} ≥ ${order.min} · ${order.kg}kg → ${order.reward}`, {
1343
- size: 'sm',
1344
- onClick: () => void lifeDo('order', [order.id]),
1345
- }),
1346
- );
1347
- }
1348
- floraTrade.append(
1349
- ctx.ui.button(t.lifeCylinder, { size: 'sm', onClick: () => void lifeDo('cylinder', [10]) }),
1350
- );
1351
- floraTrade.append(
1352
- ctx.ui.button(t.buyChart, { size: 'sm', variant: 'primary', onClick: () => void lifeDo('chart', []) }),
1353
- );
1354
- floraTrade.append(
1355
- ctx.ui.button(t.buyFertilizer, { size: 'sm', onClick: () => void lifeDo('fertilizer', [5]) }),
1356
- );
1488
+ const bagFertilizer = flora.inventory.find((item) => item.id === 'fertilizer')?.amount ?? 0;
1489
+ floraTrade.hidden = bagFertilizer <= 0;
1490
+ if (bagFertilizer > 0) {
1357
1491
  if ((flora.inventory.find((item) => item.id === 'fertilizer')?.amount ?? 0) > 0) {
1358
1492
  floraTrade.append(
1359
1493
  ctx.ui.button(t.spreadFertilizer, { size: 'sm', onClick: () => void lifeDo('fertilize', [1]) }),
@@ -2087,7 +2221,8 @@ const guidePanel: WebUiPanel = {
2087
2221
  const searchInput = ctx.ui.input({ placeholder: t.guideSearchHint });
2088
2222
  searchInput.type = 'text';
2089
2223
  const searchButton = ctx.ui.button(t.guideSearch, { size: 'sm' });
2090
- searchRow.append(searchInput, searchButton);
2224
+ const toolsButton = ctx.ui.button(t.guideTools, { size: 'sm' });
2225
+ searchRow.append(searchInput, searchButton, toolsButton);
2091
2226
  const chips = ctx.ui.h('div', 'rows');
2092
2227
  const article = ctx.ui.h('div', 'cols');
2093
2228
  const hint = ctx.ui.h('p', 'muted', t.guideEmpty);
@@ -2138,6 +2273,18 @@ const guidePanel: WebUiPanel = {
2138
2273
  };
2139
2274
 
2140
2275
  searchButton.addEventListener('click', () => void search());
2276
+ toolsButton.addEventListener('click', () => {
2277
+ void (async () => {
2278
+ try {
2279
+ const payload = await ctx.invoke<{ text: string }>('tools', []);
2280
+ const card = renderMarkdown(document, payload.text);
2281
+ card.classList.add('mono');
2282
+ article.replaceChildren(card);
2283
+ } catch (error) {
2284
+ article.replaceChildren(ctx.ui.h('p', 'muted', errorText(error)));
2285
+ }
2286
+ })();
2287
+ });
2141
2288
  searchInput.addEventListener('keydown', (event) => {
2142
2289
  if (event.key === 'Enter') void search();
2143
2290
  });
@@ -2232,7 +2379,130 @@ function inlineNodes(owner: Document, text: string): Node[] {
2232
2379
  return nodes;
2233
2380
  }
2234
2381
 
2235
- const bundle: WebUiClientBundle = { panels: { system: panel, upgrade: upgradePanel, protocol: protocolPanel, guide: guidePanel } };
2382
+
2383
+ /** 「商店」页签:买卖、订单,都在商人开张时。 */
2384
+ const shopPanel: WebUiPanel = {
2385
+ mount(ctx) {
2386
+ const t = text(ctx.language);
2387
+ const sheet = ctx.ui.sheet({ title: t.shopTitle, desc: t.shopDesc });
2388
+ const head = ctx.ui.rowbar();
2389
+ const statusLine = ctx.ui.msgline();
2390
+ const wallet = ctx.ui.h('span', 'mono', '');
2391
+ const refreshButton = ctx.ui.button('刷新', { size: 'sm' });
2392
+ head.append(refreshButton, statusLine, wallet);
2393
+
2394
+ const sellBox = ctx.ui.h('div');
2395
+ const buyBox = ctx.ui.h('div');
2396
+ const orderBox = ctx.ui.h('div');
2397
+
2398
+ sheet.body.append(head, sellBox, buyBox, orderBox);
2399
+ ctx.root.append(sheet.el);
2400
+
2401
+ const fmt = (value: number): string => value.toLocaleString('en-US');
2402
+
2403
+ async function act(method: string, args: unknown[]): Promise<void> {
2404
+ try {
2405
+ const result = await ctx.invoke<{ text?: string; state?: GenesisShopPanel }>(method, args);
2406
+ if (result?.text) ctx.ui.toast(result.text, 'ok');
2407
+ if (result?.state) render(result.state);
2408
+ else await load();
2409
+ void ctx.refresh();
2410
+ } catch (error) {
2411
+ ctx.ui.toast(error instanceof Error ? error.message : String(error), 'bad');
2412
+ }
2413
+ }
2414
+
2415
+ function buyArgs(row: { id: string; species?: string }): Record<string, unknown> {
2416
+ if (row.id === 'random_seed' || row.id === 'premium_seed') {
2417
+ return { kind: row.id, ...(row.species ? { species: row.species } : {}) };
2418
+ }
2419
+ if (row.id === 'fertilizer') return { kind: 'fertilizer', kg: 5 };
2420
+ if (row.id === 'cylinder') return { kind: 'cylinder', count: 10 };
2421
+ return { kind: row.id };
2422
+ }
2423
+
2424
+ function render(panel: GenesisShopPanel): void {
2425
+ const open = panel.open;
2426
+ statusLine.textContent = open ? t.shopOpenNow : t.shopClosedNow;
2427
+ wallet.textContent = [
2428
+ t.shopCredits + ' ' + fmt(panel.credits),
2429
+ t.shopEnergy + ' ' + fmt(panel.energyKj) + ' kJ',
2430
+ t.shopTungsten + ' ' + fmt(panel.tungsten) + ' kg',
2431
+ t.shopWindowLabel + ' ' + panel.window,
2432
+ open ? (panel.closedNote ?? '') : t.shopNextOpen(panel.nextOpenHours),
2433
+ ]
2434
+ .filter(Boolean)
2435
+ .join(' · ');
2436
+
2437
+ sellBox.replaceChildren(ctx.ui.h('h4', '', t.shopSellHeader));
2438
+ for (const row of panel.sellables) {
2439
+ const line = ctx.ui.h('div');
2440
+ line.style.display = 'flex';
2441
+ line.style.gap = '8px';
2442
+ line.style.alignItems = 'center';
2443
+ line.append(
2444
+ ctx.ui.h('span', 'mono', row.name + ' · ' + row.priceLabel + ' · ' + row.limitLabel),
2445
+ ctx.ui.h('span', 'muted', t.shopHeld(fmt(row.held ?? 0))),
2446
+ );
2447
+ const sell = ctx.ui.button(t.shopSell(row.name, '1'), {
2448
+ size: 'sm',
2449
+ onClick: () => void act('sell', [{ id: row.id, amount: 1 }]),
2450
+ });
2451
+ sell.disabled = !open || (row.held ?? 0) <= 0;
2452
+ line.append(sell);
2453
+ sellBox.append(line);
2454
+ }
2455
+
2456
+ buyBox.replaceChildren(ctx.ui.h('h4', '', t.shopBuyHeader));
2457
+ for (const row of panel.buyables) {
2458
+ const line = ctx.ui.h('div');
2459
+ line.style.display = 'flex';
2460
+ line.style.gap = '8px';
2461
+ line.style.alignItems = 'center';
2462
+ line.append(ctx.ui.h('span', 'mono', row.name + ' · ' + row.priceLabel + ' · ' + row.limitLabel));
2463
+ if (row.note) line.append(ctx.ui.h('span', 'muted', row.note));
2464
+ const buy = ctx.ui.button(t.shopBuy(row.name), {
2465
+ size: 'sm',
2466
+ onClick: () => void act('buy', [buyArgs(row)]),
2467
+ });
2468
+ buy.disabled = !open;
2469
+ line.append(buy);
2470
+ buyBox.append(line);
2471
+ }
2472
+
2473
+ orderBox.replaceChildren(ctx.ui.h('h4', '', t.shopOrdersHeader));
2474
+ if (panel.orders.length === 0) {
2475
+ orderBox.append(ctx.ui.h('p', 'muted', t.shopNoOrders));
2476
+ }
2477
+ for (const order of panel.orders) {
2478
+ const line = ctx.ui.h('div');
2479
+ line.style.display = 'flex';
2480
+ line.style.gap = '8px';
2481
+ line.style.alignItems = 'center';
2482
+ line.append(ctx.ui.h('span', 'mono', order.label));
2483
+ if (order.note) line.append(ctx.ui.h('span', 'muted', order.note));
2484
+ const deliver = ctx.ui.button(t.shopDeliver, { size: 'sm', onClick: () => void act('order', [{ id: order.id }]) });
2485
+ deliver.disabled = !open;
2486
+ line.append(deliver);
2487
+ orderBox.append(line);
2488
+ }
2489
+ }
2490
+
2491
+ async function load(): Promise<void> {
2492
+ try {
2493
+ const panel = await ctx.invoke<GenesisShopPanel>('state', []);
2494
+ render(panel);
2495
+ } catch (error) {
2496
+ statusLine.textContent = error instanceof Error ? error.message : String(error);
2497
+ }
2498
+ }
2499
+
2500
+ refreshButton.addEventListener('click', () => void load());
2501
+ void load();
2502
+ },
2503
+ };
2504
+
2505
+ const bundle: WebUiClientBundle = { panels: { system: panel, upgrade: upgradePanel, protocol: protocolPanel, shop: shopPanel, guide: guidePanel } };
2236
2506
 
2237
2507
  function errorText(error: unknown): string {
2238
2508
  return error instanceof Error ? error.message : String(error);