@lily-cooperative/custom-farm 0.34.1 → 0.36.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/dist/webui.js CHANGED
@@ -56,8 +56,8 @@ const TEXT = {
56
56
  ecologyTime: '时间与生长',
57
57
  ecologyWater: '浇水',
58
58
  timePerDay: '一个游戏日 = 真实分钟',
59
- maxStepDays: '单次最多推进(游戏日)',
60
- tickMs: '刷新间隔(ms)',
59
+ maxStepDays: '离线最多补几天(安全上限)',
60
+ tickMs: '刷新间隔(ms,不影响生长)',
61
61
  dailyEvent: '每天推「新的一天」事件',
62
62
  saveEcology: '保存生态设置',
63
63
  addGround: '添加自定义贴图',
@@ -160,8 +160,8 @@ const TEXT = {
160
160
  ecologyTime: 'Time & growth',
161
161
  ecologyWater: 'Watering',
162
162
  timePerDay: 'Real minutes per game day',
163
- maxStepDays: 'Max game days per step',
164
- tickMs: 'Refresh interval (ms)',
163
+ maxStepDays: 'Max offline days (safety cap)',
164
+ tickMs: 'Refresh interval (ms, does not affect growth)',
165
165
  dailyEvent: 'Push a "new day" event daily',
166
166
  saveEcology: 'Save ecology settings',
167
167
  addGround: 'Add custom tile',
@@ -2490,7 +2490,7 @@ function ecologyPanel(ctx) {
2490
2490
  decorAmp: Math.max(0, Math.min(40, Number(w.decorAmp ?? w.swayAmp) || 0)),
2491
2491
  squash: Math.max(0, Math.min(0.6, Number(w.squash) || 0)),
2492
2492
  mood: Math.max(-100, Math.min(100, Number(w.mood) || 0)),
2493
- speed: Math.max(0.2, Math.min(4, Number(w.speed) || 1)),
2493
+ speed: Math.max(0, Math.min(20, Number(w.speed) || 1)),
2494
2494
  }));
2495
2495
  if (!out.some((w) => w.id === 'calm')) out.unshift({ ...DEFAULT_WEATHERS[0] });
2496
2496
  if (!out.some((w) => w.id !== 'calm')) out.push(...DEFAULT_WEATHERS.slice(1).map((w) => ({ ...w })));
@@ -2519,9 +2519,10 @@ function ecologyPanel(ctx) {
2519
2519
  if (!draft) draft = cloneSettings(snapshot?.settings);
2520
2520
  return draft;
2521
2521
  };
2522
- const num = (value, onChange, step = '1', min = '0') => {
2522
+ const num = (value, onChange, step = '1', min = '0', max = '') => {
2523
2523
  const input = ui.input({ type: 'number', value: String(value ?? '') });
2524
2524
  input.step = step; input.min = min;
2525
+ if (max !== '') input.max = max;
2525
2526
  input.addEventListener('input', () => { const n = Number(input.value); if (Number.isFinite(n)) onChange(n); }, { signal: ctx.signal });
2526
2527
  return input;
2527
2528
  };
@@ -2596,7 +2597,7 @@ function ecologyPanel(ctx) {
2596
2597
  row1.append(
2597
2598
  ui.field(zh ? '持续(秒)' : 'Duration (s)', num(w.duration, (v) => { w.duration = v; }, '1', '1')),
2598
2599
  ui.field(zh ? '触发概率(权重)' : 'Probability (weight)', num(w.weight, (v) => { w.weight = v; }, '1', '0')),
2599
- ui.field(zh ? '速度(倍率)' : 'Speed (x)', num(w.speed, (v) => { w.speed = v; }, '0.1', '0.2')),
2600
+ ui.field(zh ? '速度(倍率)' : 'Speed (x)', num(w.speed, (v) => { w.speed = v; }, '0.1', '0', '20')),
2600
2601
  ui.field(zh ? '心情变化/结算' : 'Mood per settlement', num(w.mood, (v) => { w.mood = v; }, '1', '-100')),
2601
2602
  );
2602
2603
  const crop = ui.h('div', 'cf-row');
@@ -2633,13 +2634,15 @@ function ecologyPanel(ctx) {
2633
2634
  const d = getDraft();
2634
2635
  const sheet = ui.sheet({
2635
2636
  title: zh ? '生态自定义' : 'Ecology',
2636
- desc: zh ? '生长条件与天气。天气按持续时间切换,触发概率按权重计算。' : 'Growth conditions and weather. Weather changes by duration and weighted probability.',
2637
+ desc: zh
2638
+ ? '1 游戏日 = 现实分钟决定生长速度;离线最多补几天是防止关机回来一次跳太多天;刷新间隔只影响状态/事件更新,不影响生长速度。天气按持续时间切换,触发概率按权重计算。'
2639
+ : 'Real minutes per game day sets growth speed; max offline days caps how many game days a long shutdown can catch up; the refresh interval only affects state/event updates, not growth speed. Weather changes by duration and weighted probability.',
2637
2640
  });
2638
2641
  const time = ui.h('div', 'cf-row');
2639
2642
  time.append(
2640
2643
  ui.field(zh ? '1 游戏日 = 现实分钟' : 'Real minutes per game day', num(d.realMinutesPerDay, (v) => { d.realMinutesPerDay = v; }, '0.5', '0.5')),
2641
- ui.field(zh ? '单次最多补几天' : 'Max offline days', num(d.maxStepDays, (v) => { d.maxStepDays = v; }, '0.1', '0.01')),
2642
- ui.field(zh ? '刷新间隔(毫秒)' : 'Tick interval (ms)', num(d.tickIntervalMs, (v) => { d.tickIntervalMs = v; }, '100', '1000')),
2644
+ ui.field(zh ? '离线最多补几天(安全上限)' : 'Max offline days (safety cap)', num(d.maxStepDays, (v) => { d.maxStepDays = v; }, '0.1', '0.01')),
2645
+ ui.field(zh ? '刷新间隔(毫秒,不影响生长)' : 'Refresh interval (ms, does not affect growth)', num(d.tickIntervalMs, (v) => { d.tickIntervalMs = v; }, '100', '1000')),
2643
2646
  );
2644
2647
  const daily = ui.checkbox(zh ? '每天推送 farm.day' : 'Emit farm.day', {
2645
2648
  checked: d.dailyEvent,
package/package.json CHANGED
@@ -1,12 +1,12 @@
1
1
  {
2
2
  "name": "@lily-cooperative/custom-farm",
3
- "version": "0.34.1",
3
+ "version": "0.36.0",
4
4
  "type": "module",
5
5
  "private": false,
6
6
  "publishConfig": {
7
7
  "access": "public"
8
8
  },
9
- "description": "自定义农场(Custom Farm)—— 给 Coopanion 桌宠的种田扩展:18 种作物只是起点。农作物、杂草、装饰物、天气、状态、道具、合成表和贴图都能在面板里完全自定义;种、浇、收、吃、买卖全部本地确定性运行,不唤模型。",
9
+ "description": "自定义农场(Custom Farm)—— 给 Coopanion 桌宠的种田扩展:18 种作物只是起点。农作物、杂草、装饰物、天气、状态、道具、合成表和贴图都能在面板里完全自定义;种、浇、收、吃、买卖都由你决定。",
10
10
  "keywords": [
11
11
  "cortico-world",
12
12
  "coopanion",
@@ -42,7 +42,6 @@
42
42
  "dist",
43
43
  "overlay",
44
44
  "overlay-electron",
45
- "bag",
46
45
  "assets",
47
46
  "icon.png",
48
47
  "describe.json",
@@ -60,11 +59,11 @@
60
59
  "locales": {
61
60
  "zh": {
62
61
  "displayName": "自定义农场",
63
- "description": "18 种作物只是起点:农作物、杂草、装饰物、天气、状态、道具、合成表和贴图都能在面板里完全自定义,想种什么、长什么样、吃什么补什么,全由你决定。种、浇、收、吃、买卖全部本地确定性运行,不唤模型。"
62
+ "description": "18 种作物只是起点:农作物、杂草、装饰物、天气、状态、道具、合成表和贴图都能在面板里完全自定义,想种什么、长什么样、吃什么补什么,全由你决定。"
64
63
  },
65
64
  "en": {
66
65
  "displayName": "Custom Farm",
67
- "description": "18 crops are just the beginning: crops, weeds, decorations, weather, states, items, recipes and sprites are all fully customizable in the panel. Plant, water, harvest, eat and trade locally with deterministic ticks — no model calls."
66
+ "description": "18 crops are just the beginning: crops, weeds, decorations, weather, states, items, recipes and sprites are all fully customizable in the panel. Plant, water, harvest, eat and trade the way you like."
68
67
  }
69
68
  },
70
69
  "tags": [
package/src/catalog.js CHANGED
@@ -387,6 +387,8 @@ export class FarmCatalog {
387
387
  recipes: [],
388
388
  settings: {},
389
389
  seededDecor: false,
390
+ seededCabin: false,
391
+ seededDecorSet: false,
390
392
  seededFreeCrops: false,
391
393
  seededFood: false,
392
394
  seededMood: false,
@@ -472,18 +474,31 @@ export class FarmCatalog {
472
474
  this.persist();
473
475
  }
474
476
 
475
- /** 旧存档切到免费素材作物集:补全新作物,删掉没有替代的小麦/卷心菜/葡萄。 */
477
+ /** 旧存档切到免费素材作物集:补全新作物,删掉没有替代的小麦/卷心菜/葡萄。只迁移一次,之后保留用户改动。 */
476
478
  ensureFreeCrops() {
477
479
  if (!this.store) return;
480
+ const removed = new Set(['wheat', 'chinese_cabbage', 'grape']);
481
+ const filterConsume = () => {
482
+ let changed = false;
483
+ for (const action of this.store.consume ?? []) {
484
+ const before = (action.items ?? []).length;
485
+ action.items = (action.items ?? []).filter((id) => !removed.has(id) && !removed.has(String(id).replace(/^seed_/, '')));
486
+ if ((action.items ?? []).length !== before) changed = true;
487
+ }
488
+ return changed;
489
+ };
490
+ if (this.store.seededFreeCrops) {
491
+ const before = this.store.crops.length;
492
+ this.store.crops = this.store.crops.filter((c) => !removed.has(c.key));
493
+ if (filterConsume() || this.store.crops.length !== before) this.persist();
494
+ return;
495
+ }
478
496
  const defs = new Map(this.builtinCrops().map((c) => [c.key, c]));
479
- const removed = new Set(["wheat", "chinese_cabbage", "grape"]);
480
497
  const order = Object.keys(CROPS);
481
498
  // 旧档没有 builtin 标记,但 wheat/chinese_cabbage/grape 一定是旧内置作物;删掉。
482
499
  const custom = this.store.crops.filter((c) => !c.builtin && !removed.has(c.key));
483
500
  this.store.crops = order.map((key) => defs.get(key)).filter(Boolean).concat(custom);
484
- for (const action of this.store.consume ?? []) {
485
- action.items = (action.items ?? []).filter((id) => !removed.has(id) && !removed.has(String(id).replace(/^seed_/, "")));
486
- }
501
+ filterConsume();
487
502
  this.store.seededFreeCrops = true;
488
503
  this.persist();
489
504
  }
@@ -519,20 +534,25 @@ export class FarmCatalog {
519
534
  !(r.inputs ?? []).some((x) => removed.has(x.item)));
520
535
  if ((this.store.items?.length ?? 0) !== beforeItems || (this.store.recipes?.length ?? 0) !== beforeRecipes) this.persist();
521
536
  }
522
- /** 稻草堆下架:删掉目录道具、背包和已摆放的旧实例。 */
523
- /** 小木屋是后加的内置装饰;旧存档也补上。 */
537
+ /** 小木屋是后加的内置装饰;只在迁移时补一次,用户删掉后不再回来。 */
524
538
  ensureCabin() {
525
- if (!this.store) return;
526
- if ((this.store.items ?? []).some((it) => it.id === 'deco_cabin')) return;
527
- const def = this.builtinDecorItems().find((it) => it.id === 'deco_cabin');
528
- if (!def) return;
529
- const item = this.normalizeItem(def, this.store.items.length, this.store.states ?? []);
530
- if (item) { this.store.items.push(item); this.persist(); }
539
+ if (!this.store || this.store.seededCabin) return;
540
+ const list = this.store.items ?? (this.store.items = []);
541
+ if (!list.some((it) => it.id === 'deco_cabin')) {
542
+ const def = this.builtinDecorItems().find((it) => it.id === 'deco_cabin');
543
+ if (def) {
544
+ const item = this.normalizeItem(def, list.length, this.store.states ?? []);
545
+ if (item) list.push(item);
546
+ }
547
+ }
548
+ this.store.seededCabin = true;
549
+ this.persist();
531
550
  }
532
551
 
533
552
  ensureDecorSet() {
534
- if (!this.store) return;
553
+ if (!this.store || this.store.seededDecorSet) return;
535
554
  this.store.items = (this.store.items ?? []).filter((it) => it.id !== 'deco_haystack');
555
+ this.store.seededDecorSet = true;
536
556
  this.persist();
537
557
  }
538
558
  /** 老存档补一次内置装饰;只补一次,之后用户删了也不会自动回来。 */
@@ -620,6 +640,8 @@ export class FarmCatalog {
620
640
  recipes,
621
641
  settings: this.normalizeSettings(raw.settings),
622
642
  seededDecor: Boolean(raw.seededDecor),
643
+ seededCabin: Boolean(raw.seededCabin),
644
+ seededDecorSet: Boolean(raw.seededDecorSet),
623
645
  seededFreeCrops: Boolean(raw.seededFreeCrops),
624
646
  seededFood: Boolean(raw.seededFood),
625
647
  seededMood: Boolean(raw.seededMood),
package/src/farm.js CHANGED
@@ -47,6 +47,8 @@ export function farmPatch(cfg = DEFAULTS) {
47
47
  export const REACH = 0.05;
48
48
 
49
49
  export const DEFAULTS = {
50
+ /** 安装目录:overlay / overlay-electron / assets 放在这里;空 = <dataDir>/custom-farm */
51
+ installPath: '',
50
52
  /** 最多同时种几棵(屏幕上不重叠地放得下的上限) */
51
53
  maxPlants: 12,
52
54
  /** 屏幕逻辑宽度,用来把"像素宽"换算成 x 间距 */
@@ -1160,7 +1162,8 @@ export function overlayView(state) {
1160
1162
 
1161
1163
  /** 给工具看的摘要。 */
1162
1164
  export function summary(state, cfg = DEFAULTS) {
1163
- const total = Object.values(state.inventory).reduce((a, b) => a + b, 0);
1165
+ const inventory = Object.fromEntries(Object.entries(state.inventory ?? {}).filter(([id]) => Boolean(live.items?.[id])));
1166
+ const total = Object.values(inventory).reduce((a, b) => a + b, 0);
1164
1167
  const weedList = (state.weeds ?? []).map((w) => {
1165
1168
  const t = weedTypeOf(w);
1166
1169
  const lv = Number(w.level ?? 0);
@@ -1178,6 +1181,17 @@ export function summary(state, cfg = DEFAULTS) {
1178
1181
  };
1179
1182
  });
1180
1183
  const ripeWeeds = weedList.filter((w) => w.ready);
1184
+ const decorations = (state.furniture ?? [])
1185
+ .filter((f) => f.x !== null && f.x !== undefined)
1186
+ .map((f) => ({
1187
+ uid: f.uid,
1188
+ id: f.id,
1189
+ name: live.names?.[f.id] ?? f.id,
1190
+ x: round2(Number(f.x)),
1191
+ xPct: Math.round(Number(f.x) * 100),
1192
+ layer: live.items?.[f.id]?.layer ?? f.layer ?? 'bottom',
1193
+ }))
1194
+ .sort((a, b) => a.x - b.x);
1181
1195
  return {
1182
1196
  day: state.day,
1183
1197
  clock: clockText(state.minute),
@@ -1188,7 +1202,7 @@ export function summary(state, cfg = DEFAULTS) {
1188
1202
  standingAt: Number.isFinite(state.standingAt) ? Number(state.standingAt) : null,
1189
1203
  realMinutesPerDay: Number(cfg.realMinutesPerDay),
1190
1204
  bagTotal: total,
1191
- bag: { ...state.inventory },
1205
+ bag: inventory,
1192
1206
  drops: state.drops.length,
1193
1207
  planted: state.plots.length,
1194
1208
  max: cfg.maxPlants,
@@ -1197,6 +1211,7 @@ export function summary(state, cfg = DEFAULTS) {
1197
1211
  weeds: weedList.length,
1198
1212
  weedRipe: ripeWeeds.length,
1199
1213
  weedList: ripeWeeds,
1214
+ decorations,
1200
1215
  states: (Array.isArray(cfg.stateDefs) ? cfg.stateDefs : []).map((d) => {
1201
1216
  const value = state.states?.[d.id] ?? {};
1202
1217
  const flag = d.kind === 'flag';
package/src/index.js CHANGED
@@ -7,8 +7,8 @@ import { FARM_TOOL_DECLS, FarmWorld } from './world.js';
7
7
 
8
8
  const TOOL_SUMMARIES = {
9
9
  farm_status: {
10
- zh: '看田:每棵作物的位置、等级、进度、水分、是否可收/枯萎,外加背包、地上的掉落物和最近田里的变化(少了哪棵、为什么)。',
11
- en: 'Show every plant (position, level, progress, moisture, ripe/wilted) plus the bag, the drops, and recent field changes (which plant is gone and why).',
10
+ zh: '看田:每棵作物的位置、等级、进度、水分、是否可收/枯萎,外加背包、地上的掉落物、摆放的装饰物位置和最近田里的变化(少了哪棵、为什么)。',
11
+ en: 'Show every plant (position, level, progress, moisture, ripe/wilted) plus the bag, the drops, placed decorations and recent field changes (which plant is gone and why).',
12
12
  },
13
13
  farm_stand: {
14
14
  zh: '站到某个位置(at 必填),播种/收割/捡东西都要先站过去。',
@@ -63,6 +63,7 @@ export const farmDefinition = {
63
63
  dataDir: ctx.dataDir,
64
64
  botDir: ctx.botDir,
65
65
  packageDir: ctx.packageDir,
66
+ persist: (patch) => ctx.persist(patch),
66
67
  }),
67
68
  describe: {
68
69
  tools: describeTools(FARM_TOOL_DECLS),
package/src/paths.js CHANGED
@@ -1,50 +1,47 @@
1
- /**
2
- * 路径解析:所有东西都从扩展自己的位置推出来,不写死本机绝对路径。
3
- *
4
- * <Pet>\custom-farm\src\paths.js ← 本文件
5
- * <Pet>\overlay\overlay.ps1
6
- * <Pet>\bag\bag.ps1
7
- * <Pet>\assets\sprites\
8
- *
9
- * 所以「整个 Pet 文件夹」拷到另一台机器(或换个盘)都能直接用。
10
- * 扩展被复制进 Coopanion 的 extensions 目录(而不是 link)时,用环境变量
11
- * PET_HOME 或 World 配置里的 petRoot 指定 <Pet> 在哪。
12
- */
13
- import { existsSync } from 'node:fs';
14
- import { dirname, join, resolve } from 'node:path';
15
- import { fileURLToPath } from 'node:url';
16
-
17
- const SRC_DIR = dirname(fileURLToPath(import.meta.url));
18
- export const EXTENSION_DIR = resolve(SRC_DIR, '..');
19
-
20
- const looksLikePetHome = (dir) => Boolean(dir) && (
21
- existsSync(join(dir, 'overlay', 'overlay.ps1')) ||
22
- (existsSync(join(dir, 'overlay-electron', 'main.js')) && existsSync(join(dir, 'assets', 'sprites')))
23
- );
24
-
25
- /** 找到 <Pet> 根目录;找不到就返回 null(图层和背包会被自动关掉,不影响农场本身)。 */
26
- export function resolvePetHome(cfgRoot) {
27
- const candidates = [];
28
- if (typeof cfgRoot === 'string' && cfgRoot.trim()) candidates.push(resolve(cfgRoot.trim()));
29
- const env = process.env.PET_HOME;
30
- if (env && env.trim()) candidates.push(resolve(env.trim()));
31
- candidates.push(EXTENSION_DIR);
32
- candidates.push(resolve(EXTENSION_DIR, '..'));
33
- for (const dir of candidates) {
34
- if (looksLikePetHome(dir)) return dir;
35
- }
36
- return null;
37
- }
38
-
39
- export function makePaths(petHome) {
40
- const home = petHome ?? resolve(EXTENSION_DIR, '..');
41
- return {
42
- home,
43
- overlayDir: join(home, 'overlay'),
44
- overlayScript: join(home, 'overlay', 'overlay.ps1'),
45
- overlayState: join(home, 'overlay', 'runtime', 'state.json'),
46
- electronDir: join(home, 'overlay-electron'),
47
- bagScript: join(home, 'bag', 'bag.ps1'),
48
- assetsDir: join(home, 'assets', 'sprites'),
49
- };
50
- }
1
+ /**
2
+ * 路径解析:home 目录里放 overlay / overlay-electron / assets。
3
+ *
4
+ * 默认 home 是 <dataDir>/custom-farm;扩展从 npm 安装时,包内也自带这三个目录,
5
+ * 首次启动会把它们复制过去。之后在「游戏配置 → 安装」里改路径,World 会把 home
6
+ * 搬到新位置并重启桌面图层。
7
+ */
8
+ import { existsSync } from 'node:fs';
9
+ import { dirname, join, resolve } from 'node:path';
10
+ import { fileURLToPath } from 'node:url';
11
+
12
+ const SRC_DIR = dirname(fileURLToPath(import.meta.url));
13
+ export const EXTENSION_DIR = resolve(SRC_DIR, '..');
14
+
15
+ export const HOME_NAME = 'custom-farm';
16
+
17
+ /** 一个目录是否已经有可用的桌面图层和素材。 */
18
+ export function looksLikeHome(dir) {
19
+ if (!dir) return false;
20
+ return existsSync(join(dir, 'overlay', 'overlay.ps1'))
21
+ || (existsSync(join(dir, 'overlay-electron', 'main.js')) && existsSync(join(dir, 'assets', 'sprites')));
22
+ }
23
+
24
+ /** 默认 home:Coopanion 数据目录下的 custom-farm。 */
25
+ export function defaultHome(dataDir) {
26
+ return join(dataDir, HOME_NAME);
27
+ }
28
+
29
+ /** 扩展包自带或开发目录里的 overlay / assets 源。 */
30
+ export function bundleHome(packageDir) {
31
+ const candidates = [packageDir, resolve(packageDir, '..'), EXTENSION_DIR, resolve(EXTENSION_DIR, '..')];
32
+ for (const dir of candidates) {
33
+ if (looksLikeHome(dir)) return dir;
34
+ }
35
+ return packageDir;
36
+ }
37
+
38
+ export function makePaths(home) {
39
+ return {
40
+ home,
41
+ overlayDir: join(home, 'overlay'),
42
+ overlayScript: join(home, 'overlay', 'overlay.ps1'),
43
+ overlayState: join(home, 'overlay', 'runtime', 'state.json'),
44
+ electronDir: join(home, 'overlay-electron'),
45
+ assetsDir: join(home, 'assets', 'sprites'),
46
+ };
47
+ }
package/src/shop.js CHANGED
@@ -101,7 +101,7 @@ export function buyPriceOf(itemId) {
101
101
  /**
102
102
  * 家具总开关:2026-10-27 起暂时下架(摆放方案还没定)。
103
103
  * false = 商店不列、farm_buy 不卖家具、farm_place 报错;存档里已经有的家具保留不删。
104
- * 恢复:改回 true,并把 bag\bag.ps1 里的 $ShowFurniture 改成 $true。
104
+ * 恢复:改回 true。
105
105
  */
106
106
  export const FURNITURE_ENABLED = false;
107
107
 
package/src/weather.js CHANGED
@@ -36,7 +36,7 @@ export function normalizeWeathers(input) {
36
36
  decorAmp: clamp(row.decorAmp ?? row.swayAmp, 0, 40, 3),
37
37
  squash: clamp(row.squash, 0, 0.6, 0),
38
38
  mood: clamp(row.mood ?? { calm: 2, breeze: 1, gale: -6, egg: 4 }[id], -100, 100, 0),
39
- speed: clamp(row.speed, 0.2, 4, 1),
39
+ speed: clamp(row.speed, 0, 20, 1),
40
40
  });
41
41
  }
42
42
  if (!out.some((w) => w.id === 'calm')) out.unshift({ ...DEFAULT_WEATHERS[0] });