@linxin666/dsh-pet 0.1.18 → 0.1.19
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/README.i18n.yaml +2 -2
- package/README.md +12 -5
- package/README.zh.md +12 -5
- package/lib/client.js +48 -11
- package/lib/client.js.map +1 -1
- package/lib/index.js +100 -30
- package/lib/invariant.js +2 -2
- package/lib/state-Diiq8vjk.js +394 -0
- package/lib/types/affinity.d.ts +31 -3
- package/lib/types/affinity.d.ts.map +1 -1
- package/lib/types/affinity.js +21 -7
- package/lib/types/client/PetSettingsCard.d.ts +5 -0
- package/lib/types/client/PetSettingsCard.d.ts.map +1 -1
- package/lib/types/client/PetSettingsCard.js +7 -0
- package/lib/types/client/PetSprite.d.ts.map +1 -1
- package/lib/types/client/PetSprite.js +8 -2
- package/lib/types/client/index.d.ts.map +1 -1
- package/lib/types/client/index.js +14 -8
- package/lib/types/client/settings-form.d.ts +8 -0
- package/lib/types/client/settings-form.d.ts.map +1 -1
- package/lib/types/client/settings-form.js +15 -1
- package/lib/types/event-projection.d.ts.map +1 -1
- package/lib/types/event-projection.js +3 -1
- package/lib/types/index.d.ts +4 -2
- package/lib/types/index.d.ts.map +1 -1
- package/lib/types/index.js +2 -1
- package/lib/types/ledger.d.ts +16 -1
- package/lib/types/ledger.d.ts.map +1 -1
- package/lib/types/ledger.js +29 -4
- package/lib/types/registry.d.ts +10 -0
- package/lib/types/registry.d.ts.map +1 -1
- package/lib/types/registry.js +3 -0
- package/lib/types/remarks.d.ts +56 -0
- package/lib/types/remarks.d.ts.map +1 -0
- package/lib/types/remarks.js +157 -0
- package/lib/types/service.d.ts +40 -3
- package/lib/types/service.d.ts.map +1 -1
- package/lib/types/service.js +90 -18
- package/lib/types/state.js +5 -5
- package/lib/types/treats.d.ts +3 -0
- package/lib/types/treats.d.ts.map +1 -1
- package/lib/types/treats.js +5 -2
- package/package.json +1 -1
- package/src/affinity.test.ts +19 -0
- package/src/affinity.ts +22 -7
- package/src/client/PetSettingsCard.tsx +8 -0
- package/src/client/PetSprite.test.tsx +33 -0
- package/src/client/PetSprite.tsx +16 -1
- package/src/client/index.ts +14 -8
- package/src/client/pet.module.css +19 -0
- package/src/client/settings-form.ts +15 -1
- package/src/event-projection.ts +3 -1
- package/src/index.ts +12 -1
- package/src/ledger.test.ts +40 -9
- package/src/ledger.ts +33 -4
- package/src/persist.test.ts +1 -1
- package/src/registry.test.ts +27 -0
- package/src/registry.ts +12 -0
- package/src/remarks.test.ts +89 -0
- package/src/remarks.ts +177 -0
- package/src/service.ts +116 -18
- package/src/state.test.ts +9 -0
- package/src/state.ts +5 -5
- package/src/treats.test.ts +13 -11
- package/src/treats.ts +5 -2
- package/lib/state-CFyJv0sQ.js +0 -213
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"settings-form.d.ts","sourceRoot":"","sources":["../../../src/client/settings-form.ts"],"names":[],"mappings":"AACA;;;;;;;GAOG;AAEH,OAAO,KAAK,EAAE,aAAa,EAAyB,aAAa,EAAE,MAAM,wCAAwC,CAAA;AAGjH,yEAAyE;AACzE,MAAM,MAAM,UAAU,GAClB;IAAE,IAAI,EAAE,KAAK,CAAC;IAAC,KAAK,EAAE,OAAO,CAAA;CAAE,GAC/B;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,CAAA;AAErB,0EAA0E;AAC1E,MAAM,WAAW,SAAS;IACxB,+CAA+C;IAC/C,KAAK,EAAE,MAAM,CAAA;IACb;;;;;;OAMG;IACH,MAAM,CAAC,EAAE,OAAO,CAAA;IAChB,2FAA2F;IAC3F,MAAM,EAAE,CAAC,KAAK,EAAE,OAAO,KAAK,MAAM,CAAA;IAClC;;;OAGG;IACH,KAAK,EAAE,CAAC,IAAI,EAAE,MAAM,KAAK,UAAU,GAAG,SAAS,CAAA;CAChD;AAED,wCAAwC;AACxC,MAAM,WAAW,UAAU;IACzB,sCAAsC;IACtC,IAAI,EAAE,MAAM,CAAA;IACZ,oEAAoE;IAC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AAM,CAAgC;IACvD,OAAO,CAAC,QAAQ,CAAC,SAAS,CAAwB;IAClD,kFAAkF;IAClF,OAAO,CAAC,QAAQ,CAAC,YAAY,CAAY;IACzC,OAAO,CAAC,QAAQ,CAAQ;IACxB,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,MAAM,CAAQ;IACtB,OAAO,CAAC,YAAY,CAAoB;IAExC,yEAAyE;gBAEtD,KAAK,EAAE,aAAa,CAAC,CAAC,CAAC,EACxC,KAAK,EAAE,SAAS,EAAE;IAMpB;;;OAGG;IACH,OAAO,IAAI,IAAI;IAOf,wFAAwF;IACxF,IAAI,CAAC,CAAC,EAAE,OAAO,EAAE,MAAM,CAAC,GAAG,aAAa,CAAC,CAAC,CAAC;IAM3C,iFAAiF;IACjF,KAAK,IAAI,SAAS;IAelB,8EAA8E;IAC9E,KAAK,CAAC,KAAK,EAAE,MAAM,GAAG,UAAU;IAchC,wDAAwD;IACxD,OAAO,IAAI,WAAW;IAiBtB;;;;;;;;;;OAUG;IACG,IAAI,IAAI,OAAO,CAAC,IAAI,CAAC;IAoC3B,0FAA0F;IAC1F,OAAO,CAAC,YAAY;IAKpB;;;;;;OAMG;IACH,OAAO,CAAC,IAAI;YAiBE,KAAK;YAKL,KAAK;IAUnB,OAAO,CAAC,KAAK;IAOb,OAAO,CAAC,MAAM;IAQd,OAAO,CAAC,UAAU;IAIlB,OAAO,CAAC,YAAY;IAIpB,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,SAAS;IAIjB,OAAO,CAAC,MAAM;IAKd,OAAO,CAAC,OAAO;CAGhB"}
|
|
@@ -91,6 +91,9 @@ export class CardForm {
|
|
|
91
91
|
specs;
|
|
92
92
|
staged = new Map();
|
|
93
93
|
listeners = new Set();
|
|
94
|
+
/** The scope subscription installed in the constructor; released by dispose(). */
|
|
95
|
+
disposeScope;
|
|
96
|
+
disposed = false;
|
|
94
97
|
saving = false;
|
|
95
98
|
failed = false;
|
|
96
99
|
failedReason;
|
|
@@ -98,7 +101,18 @@ export class CardForm {
|
|
|
98
101
|
constructor(scope, specs) {
|
|
99
102
|
this.scope = scope;
|
|
100
103
|
this.specs = new Map(specs.map(spec => [spec.field, spec]));
|
|
101
|
-
scope.subscribe(() => { this.publish(); });
|
|
104
|
+
this.disposeScope = scope.subscribe(() => { this.publish(); });
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Release the scope subscription and every bound store listener. The card
|
|
108
|
+
* must call this on teardown; later calls are no-ops.
|
|
109
|
+
*/
|
|
110
|
+
dispose() {
|
|
111
|
+
if (this.disposed)
|
|
112
|
+
return;
|
|
113
|
+
this.disposed = true;
|
|
114
|
+
this.disposeScope();
|
|
115
|
+
this.listeners.clear();
|
|
102
116
|
}
|
|
103
117
|
/** Publish a projection of this form, rebuilt whenever the scope or a draft changes. */
|
|
104
118
|
bind(project) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"event-projection.d.ts","sourceRoot":"","sources":["../../src/event-projection.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE/C,2DAA2D;AAC3D,MAAM,WAAW,uBAAuB;IACtC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,qEAAqE;AACrE,MAAM,WAAW,iBAAiB;IAChC,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IACxB,kBAAkB,EAAE,OAAO,CAAA;IAC3B,cAAc,EAAE,OAAO,CAAA;CACxB;AAED,kFAAkF;AAClF,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,aAAa,CAAA;IACpB,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB;AAED,yDAAyD;AACzD,wBAAgB,sBAAsB,IAAI,iBAAiB,CAE1D;AAQD,wEAAwE;AACxE,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,aAAa,CAAC,OAAO,CAAC,CAE9E;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,YAAY,EACnB,OAAO,EAAE,iBAAiB,GACzB,qBAAqB,GAAG,SAAS,
|
|
1
|
+
{"version":3,"file":"event-projection.d.ts","sourceRoot":"","sources":["../../src/event-projection.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAA;AAC5D,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,YAAY,CAAA;AAE/C,2DAA2D;AAC3D,MAAM,WAAW,uBAAuB;IACtC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,IAAI,CAAC,EAAE,MAAM,CAAA;IACb,MAAM,CAAC,EAAE,MAAM,CAAA;CAChB;AAED,qEAAqE;AACrE,MAAM,WAAW,iBAAiB;IAChC,WAAW,EAAE,GAAG,CAAC,MAAM,CAAC,CAAA;IACxB,kBAAkB,EAAE,OAAO,CAAA;IAC3B,cAAc,EAAE,OAAO,CAAA;CACxB;AAED,kFAAkF;AAClF,MAAM,WAAW,qBAAqB;IACpC,KAAK,EAAE,aAAa,CAAA;IACpB,aAAa,CAAC,EAAE,MAAM,CAAA;CACvB;AAED,yDAAyD;AACzD,wBAAgB,sBAAsB,IAAI,iBAAiB,CAE1D;AAQD,wEAAwE;AACxE,wBAAgB,eAAe,CAAC,KAAK,EAAE,MAAM,GAAG,KAAK,IAAI,aAAa,CAAC,OAAO,CAAC,CAE9E;AAED;;;GAGG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,YAAY,EACnB,OAAO,EAAE,iBAAiB,GACzB,qBAAqB,GAAG,SAAS,CA2EnC"}
|
|
@@ -85,7 +85,9 @@ export function projectOfficialEvent(event, runtime) {
|
|
|
85
85
|
case 'blocked':
|
|
86
86
|
return { input: { phase: 'waiting', line: '等待继续' } };
|
|
87
87
|
case 'aborted':
|
|
88
|
-
|
|
88
|
+
// A stopped session settles to idle without a bubble: the pet
|
|
89
|
+
// visibly calms down and the session drops out of the bubble stack.
|
|
90
|
+
return { input: { phase: 'idle' } };
|
|
89
91
|
default:
|
|
90
92
|
// TurnEndReasonMap is merge-extensible; a newer ending must not
|
|
91
93
|
// leave the pet showing stale in-progress work.
|
package/lib/types/index.d.ts
CHANGED
|
@@ -13,14 +13,16 @@
|
|
|
13
13
|
import { Context } from '@deepseek-ai/cordis';
|
|
14
14
|
import z from 'schemastery';
|
|
15
15
|
import { type PetConfig } from './service.ts';
|
|
16
|
-
export { PetService } from './service.ts';
|
|
17
|
-
export type { PetConfig, PetInteractResult, PetSettingsSection, PetStateView, } from './service.ts';
|
|
16
|
+
export { PetService, MAX_SESSION_BUBBLES } from './service.ts';
|
|
17
|
+
export type { PetConfig, PetInteractResult, PetSettingsSection, PetSessionView, PetStateView, } from './service.ts';
|
|
18
18
|
export { AFFINITY_MAX, AFFINITY_RANKS, applyInteraction, applyTurnReward, emptyAffinity, rankOf, } from './affinity.ts';
|
|
19
19
|
export type { AffinityConfig, AffinityState, InteractionOutcome, PetInteraction, } from './affinity.ts';
|
|
20
20
|
export { animationForPhase, PetStateMachine, rowOf, } from './state.ts';
|
|
21
21
|
export type { ActivityPhase, PetAnimation, PetStateConfig, PetStateInput, PetStateSnapshot, } from './state.ts';
|
|
22
22
|
export { consumeTreat, defaultTreatConfig, emptyTreatLedger, settleTreatGrants, } from './treats.ts';
|
|
23
23
|
export type { TreatConfig, TreatLedger, TreatSettlement } from './treats.ts';
|
|
24
|
+
export { BUILTIN_REMARKS, REMARK_KINDS, REMARK_LINE_MAX, REMARK_LINES_MAX, RemarkPicker, builtinRemark, normalizePetRemarks, } from './remarks.ts';
|
|
25
|
+
export type { PetRemarks, PetRemarksManifest, RemarkKind } from './remarks.ts';
|
|
24
26
|
export { DEFAULT_PET_ID, DEFAULT_PET_NAME, PET_NAME_MAX_LENGTH, defaultDisplayConfig, emptyPersist, loadPetPersist, petHomeDir, savePetPersist, } from './persist.ts';
|
|
25
27
|
export type { PetDisplayConfig, PetPersist } from './persist.ts';
|
|
26
28
|
export { DEFAULT_FRAME_COUNTS, DEFAULT_PET_CELL, DEFAULT_PET_COLUMNS, DEFAULT_PET_ROW_COUNT, DEFAULT_TRACK_PATTERNS, PET_ROW_ORDER, codexPetsDir, loadPetRegistry, petEntryView, petPackageRoot, resolvePetManifest, } from './registry.ts';
|
package/lib/types/index.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAG7C,OAAO,CAAC,MAAM,aAAa,CAAA;AAC3B,OAAO,EAAsC,KAAK,SAAS,EAA2B,MAAM,cAAc,CAAA;AAK1G,OAAO,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,OAAO,EAAE,OAAO,EAAE,MAAM,qBAAqB,CAAA;AAG7C,OAAO,CAAC,MAAM,aAAa,CAAA;AAC3B,OAAO,EAAsC,KAAK,SAAS,EAA2B,MAAM,cAAc,CAAA;AAK1G,OAAO,EAAE,UAAU,EAAE,mBAAmB,EAAE,MAAM,cAAc,CAAA;AAC9D,YAAY,EACV,SAAS,EACT,iBAAiB,EACjB,kBAAkB,EAClB,cAAc,EACd,YAAY,GACb,MAAM,cAAc,CAAA;AACrB,OAAO,EACL,YAAY,EACZ,cAAc,EACd,gBAAgB,EAChB,eAAe,EACf,aAAa,EACb,MAAM,GACP,MAAM,eAAe,CAAA;AACtB,YAAY,EACV,cAAc,EACd,aAAa,EAC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AgB,CAAA;AAEnC;;;;;;;GAOG;AACH,wBAAgB,qBAAqB,CAAC,aAAa,EAAE,MAAM;;;;;;;;;;;;;;IAS1D;AAED,0EAA0E;AAC1E,wBAAgB,KAAK,CAAC,GAAG,EAAE,OAAO,EAAE,MAAM,GAAE,SAAc,GAAG,IAAI,CA+DhE"}
|
package/lib/types/index.js
CHANGED
|
@@ -16,10 +16,11 @@ import { PetService, PET_SETTINGS_NAMESPACE } from "./service.js";
|
|
|
16
16
|
import { makePetRoutes } from "./routes.js";
|
|
17
17
|
import { loadPetRegistry, petPackageRoot } from "./registry.js";
|
|
18
18
|
import { DISPLAY_INSET_MAX, DISPLAY_SIZE_MAX, DISPLAY_SIZE_MIN } from "./persist.js";
|
|
19
|
-
export { PetService } from "./service.js";
|
|
19
|
+
export { PetService, MAX_SESSION_BUBBLES } from "./service.js";
|
|
20
20
|
export { AFFINITY_MAX, AFFINITY_RANKS, applyInteraction, applyTurnReward, emptyAffinity, rankOf, } from "./affinity.js";
|
|
21
21
|
export { animationForPhase, PetStateMachine, rowOf, } from "./state.js";
|
|
22
22
|
export { consumeTreat, defaultTreatConfig, emptyTreatLedger, settleTreatGrants, } from "./treats.js";
|
|
23
|
+
export { BUILTIN_REMARKS, REMARK_KINDS, REMARK_LINE_MAX, REMARK_LINES_MAX, RemarkPicker, builtinRemark, normalizePetRemarks, } from "./remarks.js";
|
|
23
24
|
export { DEFAULT_PET_ID, DEFAULT_PET_NAME, PET_NAME_MAX_LENGTH, defaultDisplayConfig, emptyPersist, loadPetPersist, petHomeDir, savePetPersist, } from "./persist.js";
|
|
24
25
|
export { DEFAULT_FRAME_COUNTS, DEFAULT_PET_CELL, DEFAULT_PET_COLUMNS, DEFAULT_PET_ROW_COUNT, DEFAULT_TRACK_PATTERNS, PET_ROW_ORDER, codexPetsDir, loadPetRegistry, petEntryView, petPackageRoot, resolvePetManifest, } from "./registry.js";
|
|
25
26
|
export { makePetRoutes, PET_API_PREFIX, PET_ASSET_PREFIX, } from "./routes.js";
|
package/lib/types/ledger.d.ts
CHANGED
|
@@ -8,11 +8,14 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { type AffinityConfig, type PetAffinityView, type PetInteraction } from './affinity.ts';
|
|
10
10
|
import { type TreatConfig } from './treats.ts';
|
|
11
|
+
import { type PetRemarks } from './remarks.ts';
|
|
11
12
|
import type { PetDisplayConfig, PetPersist } from './persist.ts';
|
|
12
13
|
/** Tuning overrides for the affinity economy. */
|
|
13
14
|
export interface LedgerConfig {
|
|
14
15
|
affinity?: Partial<AffinityConfig>;
|
|
15
16
|
treats?: Partial<TreatConfig>;
|
|
17
|
+
/** Per-pet remark pools for the selected pet (custom slots override built-ins). */
|
|
18
|
+
remarks?: PetRemarks;
|
|
16
19
|
}
|
|
17
20
|
/** Result of one ledger interaction (the shape the pet RPC returns). */
|
|
18
21
|
export interface LedgerInteractionResult {
|
|
@@ -31,6 +34,8 @@ export interface LedgerInteractionResult {
|
|
|
31
34
|
export declare class PetLedger {
|
|
32
35
|
private readonly affinityConfig;
|
|
33
36
|
private readonly treatConfig;
|
|
37
|
+
/** Round-robin reaction picker; rebuilt when the selected pet changes. */
|
|
38
|
+
private picker;
|
|
34
39
|
private current;
|
|
35
40
|
/** Completed turns already rewarded, per session (turn numbers are per-session). */
|
|
36
41
|
private rewardedTurns;
|
|
@@ -45,16 +50,26 @@ export declare class PetLedger {
|
|
|
45
50
|
get treatMax(): number;
|
|
46
51
|
/** Consume the pending-write flag if any mutation occurred. */
|
|
47
52
|
takeDirty(): boolean;
|
|
53
|
+
/**
|
|
54
|
+
* Drop a session's rewarded-turn bookkeeping once that session is disposed,
|
|
55
|
+
* so the per-session map does not grow without bound.
|
|
56
|
+
*/
|
|
57
|
+
forgetSession(sessionId: string): void;
|
|
48
58
|
/** Replace the display block (clamping stays a caller concern). */
|
|
49
59
|
setDisplay(display: PetDisplayConfig): void;
|
|
50
60
|
/** Replace the selected pet id (validation stays a caller concern). */
|
|
51
61
|
setPetId(petId: string): void;
|
|
52
62
|
/** Replace one pet's display name (validation stays a caller concern). */
|
|
53
63
|
setPetName(petId: string, name: string): void;
|
|
64
|
+
/**
|
|
65
|
+
* Swap the reaction pools to another pet's custom remarks (called on pet
|
|
66
|
+
* selection). Slots the pet does not declare fall back to built-ins.
|
|
67
|
+
*/
|
|
68
|
+
setRemarks(remarks?: PetRemarks): void;
|
|
54
69
|
/**
|
|
55
70
|
* Settle the treat economy (work + time output since the last settlement).
|
|
56
71
|
* A zero-gain first settlement still starts the time clock (anchor write),
|
|
57
|
-
* which is how the
|
|
72
|
+
* which is how the time output can ever accrue. Returns true when
|
|
58
73
|
* the in-memory ledger changed and should be persisted.
|
|
59
74
|
*/
|
|
60
75
|
settleTreats(nowMs: number): boolean;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"ledger.d.ts","sourceRoot":"","sources":["../../src/ledger.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAKL,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,cAAc,EACpB,MAAM,eAAe,CAAA;AACtB,OAAO,EAIL,KAAK,WAAW,EACjB,MAAM,aAAa,CAAA;AACpB,OAAO,KAAK,EAAE,gBAAgB,EAAE,UAAU,EAAE,MAAM,cAAc,CAAA;AAEhE,iDAAiD;AACjD,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,EAAE,OAAO,CAAC,cAAc,CAAC,CAAA;IAClC,MAAM,CAAC,EAAE,OAAO,CAAC,WAAW,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"ledger.d.ts","sourceRoot":"","sources":["../../src/ledger.ts"],"names":[],"mappings":"AAAA;;;;;;;GAOG;AAEH,OAAO,EAKL,KAAK,cAAc,EACnB,KAAK,eAAe,EACpB,KAAK,cAAc,EACpB,MAAM,eAAe,CAAA;AACtB,OAAO,EAIL,KAAK,WAAW,EACjB,MAAM,aAAa,CAAA;AACpB,OAAO,EAAgB,KAAK,UAAU,EAAE,MAA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AA0E;IAC1E,UAAU,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,IAAI;IAK7C;;;OAGG;IACH,UAAU,CAAC,OAAO,CAAC,EAAE,UAAU,GAAG,IAAI;IAItC;;;;;OAKG;IACH,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IAapC;;;;OAIG;IACH,UAAU,CAAC,SAAS,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,EAAE,KAAK,EAAE,MAAM,GAAG,OAAO;IASnE,8EAA8E;IAC9E,gBAAgB,CAAC,KAAK,EAAE,MAAM,GAAG,OAAO;IASxC,OAAO,CAAC,eAAe;IASvB;;;;OAIG;IACH,QAAQ,CAAC,IAAI,EAAE,cAAc,EAAE,KAAK,EAAE,MAAM,GAAG,uBAAuB;IAgCtE,kDAAkD;IAClD,YAAY,CAAC,KAAK,EAAE,MAAM,GAAG,eAAe;CAG7C"}
|
package/lib/types/ledger.js
CHANGED
|
@@ -8,6 +8,7 @@
|
|
|
8
8
|
*/
|
|
9
9
|
import { applyInteraction, affinityViewOf, applyTurnReward, defaultAffinityConfig, } from "./affinity.js";
|
|
10
10
|
import { consumeTreat, defaultTreatConfig, settleTreatGrants, } from "./treats.js";
|
|
11
|
+
import { RemarkPicker } from "./remarks.js";
|
|
11
12
|
/**
|
|
12
13
|
* Holds the current persistence snapshot and all economy bookkeeping. Every
|
|
13
14
|
* mutating call flags takeDirty so the facade persists exactly once per
|
|
@@ -16,6 +17,8 @@ import { consumeTreat, defaultTreatConfig, settleTreatGrants, } from "./treats.j
|
|
|
16
17
|
export class PetLedger {
|
|
17
18
|
affinityConfig;
|
|
18
19
|
treatConfig;
|
|
20
|
+
/** Round-robin reaction picker; rebuilt when the selected pet changes. */
|
|
21
|
+
picker;
|
|
19
22
|
current;
|
|
20
23
|
/** Completed turns already rewarded, per session (turn numbers are per-session). */
|
|
21
24
|
rewardedTurns = new Map();
|
|
@@ -24,6 +27,7 @@ export class PetLedger {
|
|
|
24
27
|
constructor(persist, config = {}) {
|
|
25
28
|
this.affinityConfig = { ...defaultAffinityConfig, ...(config.affinity ?? {}) };
|
|
26
29
|
this.treatConfig = { ...defaultTreatConfig, ...(config.treats ?? {}) };
|
|
30
|
+
this.picker = new RemarkPicker(config.remarks);
|
|
27
31
|
this.current = persist;
|
|
28
32
|
}
|
|
29
33
|
/** Affinity cooldown/rank tuning (read-only). */
|
|
@@ -44,6 +48,13 @@ export class PetLedger {
|
|
|
44
48
|
this.dirty = false;
|
|
45
49
|
return was;
|
|
46
50
|
}
|
|
51
|
+
/**
|
|
52
|
+
* Drop a session's rewarded-turn bookkeeping once that session is disposed,
|
|
53
|
+
* so the per-session map does not grow without bound.
|
|
54
|
+
*/
|
|
55
|
+
forgetSession(sessionId) {
|
|
56
|
+
this.rewardedTurns.delete(sessionId);
|
|
57
|
+
}
|
|
47
58
|
/** Replace the display block (clamping stays a caller concern). */
|
|
48
59
|
setDisplay(display) {
|
|
49
60
|
this.current = { ...this.current, display };
|
|
@@ -61,10 +72,17 @@ export class PetLedger {
|
|
|
61
72
|
this.current = { ...this.current, names: { ...this.current.names, [petId]: name } };
|
|
62
73
|
this.dirty = true;
|
|
63
74
|
}
|
|
75
|
+
/**
|
|
76
|
+
* Swap the reaction pools to another pet's custom remarks (called on pet
|
|
77
|
+
* selection). Slots the pet does not declare fall back to built-ins.
|
|
78
|
+
*/
|
|
79
|
+
setRemarks(remarks) {
|
|
80
|
+
this.picker = new RemarkPicker(remarks);
|
|
81
|
+
}
|
|
64
82
|
/**
|
|
65
83
|
* Settle the treat economy (work + time output since the last settlement).
|
|
66
84
|
* A zero-gain first settlement still starts the time clock (anchor write),
|
|
67
|
-
* which is how the
|
|
85
|
+
* which is how the time output can ever accrue. Returns true when
|
|
68
86
|
* the in-memory ledger changed and should be persisted.
|
|
69
87
|
*/
|
|
70
88
|
settleTreats(nowMs) {
|
|
@@ -118,14 +136,17 @@ export class PetLedger {
|
|
|
118
136
|
if (kind === 'feed')
|
|
119
137
|
this.settleTreats(nowMs);
|
|
120
138
|
const outcome = applyInteraction(this.current.affinity, kind, nowMs, this.affinityConfig);
|
|
139
|
+
// Reactions come from the picker pools (custom per-pet slots override
|
|
140
|
+
// the built-in library per slot); outcome.reaction stays the fallback
|
|
141
|
+
// copy for direct applyInteraction callers.
|
|
121
142
|
if (kind === 'feed' && !outcome.accepted) {
|
|
122
|
-
return { reaction:
|
|
143
|
+
return { reaction: this.picker.pick('feedCooldown'), delta: 0, affinity: this.affinityView(nowMs) };
|
|
123
144
|
}
|
|
124
145
|
if (kind === 'feed') {
|
|
125
146
|
const consume = consumeTreat(this.current.treats);
|
|
126
147
|
if (!consume.ok) {
|
|
127
148
|
return {
|
|
128
|
-
reaction: '
|
|
149
|
+
reaction: this.picker.pick('noTreats'),
|
|
129
150
|
delta: 0,
|
|
130
151
|
affinity: this.affinityView(nowMs),
|
|
131
152
|
};
|
|
@@ -137,7 +158,11 @@ export class PetLedger {
|
|
|
137
158
|
this.current = { ...this.current, affinity: outcome.affinity };
|
|
138
159
|
this.dirty = true;
|
|
139
160
|
}
|
|
140
|
-
return {
|
|
161
|
+
return {
|
|
162
|
+
reaction: this.picker.pick(outcome.accepted ? kind : 'petCooldown'),
|
|
163
|
+
delta: outcome.delta,
|
|
164
|
+
affinity: this.affinityView(nowMs),
|
|
165
|
+
};
|
|
141
166
|
}
|
|
142
167
|
/** Current affinity view for the RPC snapshot. */
|
|
143
168
|
affinityView(nowMs) {
|
package/lib/types/registry.d.ts
CHANGED
|
@@ -17,6 +17,7 @@
|
|
|
17
17
|
* @module @linxin666/dsh-pet/registry
|
|
18
18
|
*/
|
|
19
19
|
import type { PetAnimation } from './state.ts';
|
|
20
|
+
import { type PetRemarks, type PetRemarksManifest } from './remarks.ts';
|
|
20
21
|
/** Fixed row order of the 9-state animation contract. */
|
|
21
22
|
export declare const PET_ROW_ORDER: readonly PetAnimation[];
|
|
22
23
|
/** Atlas cell size in px. */
|
|
@@ -80,6 +81,13 @@ export interface PetManifest {
|
|
|
80
81
|
frames?: number[];
|
|
81
82
|
/** Optional per-track rhythm overrides; omitted tracks use the defaults. */
|
|
82
83
|
tracks?: Partial<Record<PetAnimation, PetTrackOverride>>;
|
|
84
|
+
/**
|
|
85
|
+
* Optional witty-remark overrides the pet speaks on interactions
|
|
86
|
+
* (community contributions use this to give their pet its own voice).
|
|
87
|
+
* Each slot accepts one line or a pool of lines; a slot replaces the
|
|
88
|
+
* built-in default pool for that slot only.
|
|
89
|
+
*/
|
|
90
|
+
remarks?: PetRemarksManifest;
|
|
83
91
|
}
|
|
84
92
|
/** Per-track rhythm overrides a manifest may carry. */
|
|
85
93
|
export interface PetTrackOverride {
|
|
@@ -114,6 +122,8 @@ export interface PetEntry extends PetDefinition {
|
|
|
114
122
|
dir: string;
|
|
115
123
|
/** Atlas path relative to 'dir' (declared by the manifest). */
|
|
116
124
|
spritesheetPath: string;
|
|
125
|
+
/** Normalized per-pet remark pools (manifest 'remarks'), when declared. */
|
|
126
|
+
remarks?: PetRemarks;
|
|
117
127
|
}
|
|
118
128
|
/** Registry load result: resolved entries plus load warnings. */
|
|
119
129
|
export interface PetRegistry {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAMH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;
|
|
1
|
+
{"version":3,"file":"registry.d.ts","sourceRoot":"","sources":["../../src/registry.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;;;;;;;GAiBG;AAMH,OAAO,KAAK,EAAE,YAAY,EAAE,MAAM,YAAY,CAAA;AAC9C,OAAO,EAAuB,KAAK,UAAU,EAAE,KAAK,kBAAkB,EAAE,MAAM,cAAc,CAAA;AAE5F,yDAAyD;AACzD,eAAO,MAAM,aAAa,EAAE,SAAS,YAAY,EAUhD,CAAA;AAED,6BAA6B;AAC7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O,EAAE,QAAQ,EAAE,CAAA;IACnB,QAAQ,EAAE,MAAM,EAAE,CAAA;IAClB,IAAI,CAAC,EAAE,EAAE,MAAM,GAAG,QAAQ,GAAG,SAAS,CAAA;IACtC,2EAA2E;IAC3E,YAAY,IAAI,QAAQ,CAAA;CACzB;AAED,wBAAwB;AACxB,MAAM,WAAW,kBAAkB;IACjC,iEAAiE;IACjE,WAAW,EAAE,MAAM,CAAA;IACnB,2DAA2D;IAC3D,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB,yEAAyE;IACzE,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,oEAAoE;IACpE,KAAK,CAAC,EAAE,SAAS,WAAW,EAAE,CAAA;CAC/B;AAQD;;;GAGG;AACH,wBAAgB,kBAAkB,CAChC,GAAG,EAAE,OAAO,EACZ,GAAG,EAAE,MAAM,EACX,OAAO,GAAE;IAAE,WAAW,CAAC,EAAE,MAAM,CAAC;IAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAA;CAAO,GAC1D,QAAQ,GAAG,SAAS,CAoFtB;AAkCD;;;;;GAKG;AACH,wBAAgB,eAAe,CAAC,OAAO,EAAE,kBAAkB,GAAG,WAAW,CAwCxE;AAED,qEAAqE;AACrE,wBAAgB,YAAY,CAAC,KAAK,EAAE,QAAQ,GAAG,aAAa,CAY3D;AAED,sEAAsE;AACtE,wBAAgB,YAAY,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM,CAEpD;AAED,gFAAgF;AAChF,wBAAgB,WAAW,CAAC,KAAK,EAAE,QAAQ,GAAG,MAAM,CAEnD"}
|
package/lib/types/registry.js
CHANGED
|
@@ -20,6 +20,7 @@ import { existsSync, readdirSync, readFileSync } from 'node:fs';
|
|
|
20
20
|
import { homedir } from 'node:os';
|
|
21
21
|
import { basename, dirname, isAbsolute, join, resolve } from 'node:path';
|
|
22
22
|
import { fileURLToPath } from 'node:url';
|
|
23
|
+
import { normalizePetRemarks } from "./remarks.js";
|
|
23
24
|
/** Fixed row order of the 9-state animation contract. */
|
|
24
25
|
export const PET_ROW_ORDER = [
|
|
25
26
|
'idle',
|
|
@@ -129,6 +130,7 @@ export function resolvePetManifest(raw, dir, options = {}) {
|
|
|
129
130
|
const value = Array.isArray(source.frames) ? source.frames[index] : undefined;
|
|
130
131
|
return finiteInt(value, fallback, columns);
|
|
131
132
|
});
|
|
133
|
+
const remarks = normalizePetRemarks(source.remarks, message => warn('manifest ' + id + ': ' + message));
|
|
132
134
|
const trackOverrides = (typeof source.tracks === 'object' && source.tracks !== null ? source.tracks : {});
|
|
133
135
|
const tracks = {};
|
|
134
136
|
for (const [row, animation] of PET_ROW_ORDER.entries()) {
|
|
@@ -168,6 +170,7 @@ export function resolvePetManifest(raw, dir, options = {}) {
|
|
|
168
170
|
manifestUrl: assetUrl(assetPrefix, id, 'pet.json'),
|
|
169
171
|
dir,
|
|
170
172
|
spritesheetPath: spritesheetPath.join('/'),
|
|
173
|
+
...(remarks === undefined ? {} : { remarks }),
|
|
171
174
|
};
|
|
172
175
|
}
|
|
173
176
|
/** Scan one directory of pet folders; entries come back in name order. */
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pet remark (reaction copy) library — pure. Reaction bubbles the pet speaks
|
|
3
|
+
* on interaction events come from two layers:
|
|
4
|
+
* - the built-in default library below (a generous pool per event kind);
|
|
5
|
+
* - per-pet custom lines declared in a manifest's 'remarks' block, which
|
|
6
|
+
* community pet contributions (PRs) use to give their pet its own voice.
|
|
7
|
+
* A custom slot replaces the built-in pool for that slot only; the other
|
|
8
|
+
* slots keep the built-in lines. Picks cycle round-robin within a pool so
|
|
9
|
+
* repeated interactions stay varied while tests stay deterministic (no
|
|
10
|
+
* randomness, no clock).
|
|
11
|
+
* @module @linxin666/dsh-pet/remarks
|
|
12
|
+
*/
|
|
13
|
+
/** Interaction events a reaction line can accompany. */
|
|
14
|
+
export type RemarkKind = 'pet' | 'petCooldown' | 'feed' | 'feedCooldown' | 'noTreats';
|
|
15
|
+
/** Every remark slot, in a stable order. */
|
|
16
|
+
export declare const REMARK_KINDS: readonly RemarkKind[];
|
|
17
|
+
/** Per-pet remark overrides (normalized shape; each slot is a line pool). */
|
|
18
|
+
export type PetRemarks = Partial<Record<RemarkKind, string[]>>;
|
|
19
|
+
/** Raw manifest shape: each slot accepts one line or a pool of lines. */
|
|
20
|
+
export type PetRemarksManifest = Partial<Record<RemarkKind, string | string[]>>;
|
|
21
|
+
/** Longest accepted reaction line (characters, trimmed before slicing). */
|
|
22
|
+
export declare const REMARK_LINE_MAX = 120;
|
|
23
|
+
/** Longest accepted pool per slot. */
|
|
24
|
+
export declare const REMARK_LINES_MAX = 64;
|
|
25
|
+
/**
|
|
26
|
+
* Built-in default remark library. Every pool is plain zh copy in the
|
|
27
|
+
* whale-girl voice; the first line of each pool is the legacy reaction the
|
|
28
|
+
* plugin has always spoken, so existing installs and tests keep their
|
|
29
|
+
* wording while the pool adds variety. No emoji characters anywhere (the
|
|
30
|
+
* repo bans them); ~ is the whale-girl's signature.
|
|
31
|
+
*/
|
|
32
|
+
export declare const BUILTIN_REMARKS: Readonly<Record<RemarkKind, readonly string[]>>;
|
|
33
|
+
/** The legacy first line of one kind (direct callers' fallback copy). */
|
|
34
|
+
export declare function builtinRemark(kind: RemarkKind): string;
|
|
35
|
+
/**
|
|
36
|
+
* Normalize a manifest 'remarks' block into per-kind line pools. Unknown
|
|
37
|
+
* slots and non-string entries are skipped with a warning; empty pools are
|
|
38
|
+
* dropped so the built-in library takes the slot. Returns undefined when no
|
|
39
|
+
* usable slot remains.
|
|
40
|
+
*/
|
|
41
|
+
export declare function normalizePetRemarks(raw: unknown, onWarning?: (message: string) => void): PetRemarks | undefined;
|
|
42
|
+
/**
|
|
43
|
+
* Round-robin reaction picker over the effective pools (per-pet custom lines
|
|
44
|
+
* override the built-in pool per slot). Counters are per slot, so each slot
|
|
45
|
+
* cycles its own list independently and picks stay deterministic for tests.
|
|
46
|
+
*/
|
|
47
|
+
export declare class RemarkPicker {
|
|
48
|
+
private readonly counters;
|
|
49
|
+
private readonly pools;
|
|
50
|
+
constructor(overrides?: PetRemarks);
|
|
51
|
+
/** The effective pool for one slot (custom override or built-in). */
|
|
52
|
+
pool(kind: RemarkKind): readonly string[];
|
|
53
|
+
/** The next line for one slot (round-robin within its pool). */
|
|
54
|
+
pick(kind: RemarkKind): string;
|
|
55
|
+
}
|
|
56
|
+
//# sourceMappingURL=remarks.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"remarks.d.ts","sourceRoot":"","sources":["../../src/remarks.ts"],"names":[],"mappings":"AAAA;;;;;;;;;;;GAWG;AAEH,wDAAwD;AACxD,MAAM,MAAM,UAAU,GAAG,KAAK,GAAG,aAAa,GAAG,MAAM,GAAG,cAAc,GAAG,UAAU,CAAA;AAErF,4CAA4C;AAC5C,eAAO,MAAM,YAAY,EAAE,SAAS,UAAU,EAM7C,CAAA;AAED,6EAA6E;AAC7E,MAAM,MAAM,UAAU,GAAG,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,EAAE,CAAC,CAAC,CAAA;AAE9D,yEAAyE;AACzE,MAAM,MAAM,kBAAkB,GAAG,OAAO,CAAC,MAAM,CAAC,UAAU,EAAE,MAAM,GAAG,MAAM,EAAE,CAAC,CAAC,CAAA;AAE/E,2EAA2E;AAC3E,eAAO,MAAM,eAAe,MAAM,CAAA;AAClC,sCAAsC;AACtC,eAAO,MAAM,gBAAgB,KAAK,CAAA;AAElC;;;;;;GAMG;AACH,eAAO,MAAM,eAAe,EAAE,QAAQ,CAAC,MAAM,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC,CA6D3E,CAAA;AAED,yEAAyE;AACzE,wBAAgB,aAAa,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM,CAEtD;AAED;;;;;GAKG;AACH,wBAAgB,mBAAmB,CACjC,GAAG,EAAE,OAAO,EACZ,SAAS,GAAE,CAAC,OAAO,EAAE,MAAM,KAAK,IAAe,GAC9C,UAAU,GAAG,SAAS,CAyBxB;AAED;;;;GAIG;AACH,qBAAa,YAAY;IACvB,OAAO,CAAC,QAAQ,CAAC,QAAQ,CAAgC;IACzD,OAAO,CAAC,QAAQ,CAAC,KAAK,CAAuC;gBAEjD,SAAS,CAAC,EAAE,UAAU;IAQlC,qEAAqE;IACrE,IAAI,CAAC,IAAI,EAAE,UAAU,GAAG,SAAS,MAAM,EAAE;IAIzC,gEAAgE;IAChE,IAAI,CAAC,IAAI,EAAE,UAAU,GAAG,MAAM;CAM/B"}
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Pet remark (reaction copy) library — pure. Reaction bubbles the pet speaks
|
|
3
|
+
* on interaction events come from two layers:
|
|
4
|
+
* - the built-in default library below (a generous pool per event kind);
|
|
5
|
+
* - per-pet custom lines declared in a manifest's 'remarks' block, which
|
|
6
|
+
* community pet contributions (PRs) use to give their pet its own voice.
|
|
7
|
+
* A custom slot replaces the built-in pool for that slot only; the other
|
|
8
|
+
* slots keep the built-in lines. Picks cycle round-robin within a pool so
|
|
9
|
+
* repeated interactions stay varied while tests stay deterministic (no
|
|
10
|
+
* randomness, no clock).
|
|
11
|
+
* @module @linxin666/dsh-pet/remarks
|
|
12
|
+
*/
|
|
13
|
+
/** Every remark slot, in a stable order. */
|
|
14
|
+
export const REMARK_KINDS = [
|
|
15
|
+
'pet',
|
|
16
|
+
'petCooldown',
|
|
17
|
+
'feed',
|
|
18
|
+
'feedCooldown',
|
|
19
|
+
'noTreats',
|
|
20
|
+
];
|
|
21
|
+
/** Longest accepted reaction line (characters, trimmed before slicing). */
|
|
22
|
+
export const REMARK_LINE_MAX = 120;
|
|
23
|
+
/** Longest accepted pool per slot. */
|
|
24
|
+
export const REMARK_LINES_MAX = 64;
|
|
25
|
+
/**
|
|
26
|
+
* Built-in default remark library. Every pool is plain zh copy in the
|
|
27
|
+
* whale-girl voice; the first line of each pool is the legacy reaction the
|
|
28
|
+
* plugin has always spoken, so existing installs and tests keep their
|
|
29
|
+
* wording while the pool adds variety. No emoji characters anywhere (the
|
|
30
|
+
* repo bans them); ~ is the whale-girl's signature.
|
|
31
|
+
*/
|
|
32
|
+
export const BUILTIN_REMARKS = {
|
|
33
|
+
pet: [
|
|
34
|
+
'咕噜咕噜~被摸摸好舒服!',
|
|
35
|
+
'再摸摸这里,痒痒的~',
|
|
36
|
+
'头顶温度刚刚好,安心~',
|
|
37
|
+
'被摸到耳朵啦,扑通扑通!',
|
|
38
|
+
'你的手掌好温暖,舍不得你走~',
|
|
39
|
+
'呼噜呼噜~就靠在这里不走了!',
|
|
40
|
+
'今天的摸头也收货成功!',
|
|
41
|
+
'蹭蹭你的手心,这是回礼~',
|
|
42
|
+
'多摸摸我,亲密度会涨哦!',
|
|
43
|
+
'闭眼享受中,请勿打扰~',
|
|
44
|
+
],
|
|
45
|
+
petCooldown: [
|
|
46
|
+
'摸过头啦,让鲸鱼娘歇口气~',
|
|
47
|
+
'羽毛都快被摸秃啦,缓一缓~',
|
|
48
|
+
'呼……先让我喘口气嘛!',
|
|
49
|
+
'再摸就要睡着了哦~',
|
|
50
|
+
'稍微休息一下,待会儿再摸~',
|
|
51
|
+
'头顶要冒烟啦,停一停!',
|
|
52
|
+
'我知道你喜欢我,但也要节制呀~',
|
|
53
|
+
'歇一歇,摸摸的手感会更好哦~',
|
|
54
|
+
'咕……等我回个蓝~',
|
|
55
|
+
'让我先消化一下刚才的爱!',
|
|
56
|
+
],
|
|
57
|
+
feed: [
|
|
58
|
+
'呜哇!小鱼干好好吃!',
|
|
59
|
+
'咔嚓咔嚓,美味到尾巴打结~',
|
|
60
|
+
'这条小鱼干是刚晒好的,好香!',
|
|
61
|
+
'谢谢你,胃里暖暖的~',
|
|
62
|
+
'囤粮 +1,今天也有好好被爱!',
|
|
63
|
+
'好吃到想转圈圈~',
|
|
64
|
+
'小鱼干最好吃了,再来亿条!',
|
|
65
|
+
'饱餐一顿,马上满血复活~',
|
|
66
|
+
'这个味道,是幸福的味道!',
|
|
67
|
+
'吃完了还不忘舔舔爪子~',
|
|
68
|
+
],
|
|
69
|
+
feedCooldown: [
|
|
70
|
+
'吃饱啦,晚点再喂~',
|
|
71
|
+
'肚子圆滚滚的,装不下啦~',
|
|
72
|
+
'再喂就要变成球啦!',
|
|
73
|
+
'让我慢慢消化这份心意~',
|
|
74
|
+
'小鱼干的香气还没散呢~',
|
|
75
|
+
'呼……满足得动不了了~',
|
|
76
|
+
'先散步一圈再吃下一顿!',
|
|
77
|
+
'肚皮已经鼓鼓的啦~',
|
|
78
|
+
'好吃是好吃,可也得节制呀~',
|
|
79
|
+
'等我饿了会告诉你哦~',
|
|
80
|
+
],
|
|
81
|
+
noTreats: [
|
|
82
|
+
'没有小鱼干了,多陪我工作一会儿吧~',
|
|
83
|
+
'粮仓空空,陪我完成几轮任务就会有小鱼干啦~',
|
|
84
|
+
'小鱼干在路上啦,先一起加油工作!',
|
|
85
|
+
'嘴巴寂寞了……快去完成一轮任务!',
|
|
86
|
+
'陪我多工作一会儿,鱼干自动到账~',
|
|
87
|
+
'现在喂我也只会饿着肚子说谢谢哦~',
|
|
88
|
+
'粮仓见底啦,用几轮任务换一条鱼干吧~',
|
|
89
|
+
'饿着肚子等你完成下一轮任务~',
|
|
90
|
+
'小鱼干藏在你的工作里,去找找看!',
|
|
91
|
+
'先工作后干饭,我们的约定哦~',
|
|
92
|
+
],
|
|
93
|
+
};
|
|
94
|
+
/** The legacy first line of one kind (direct callers' fallback copy). */
|
|
95
|
+
export function builtinRemark(kind) {
|
|
96
|
+
return BUILTIN_REMARKS[kind][0];
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* Normalize a manifest 'remarks' block into per-kind line pools. Unknown
|
|
100
|
+
* slots and non-string entries are skipped with a warning; empty pools are
|
|
101
|
+
* dropped so the built-in library takes the slot. Returns undefined when no
|
|
102
|
+
* usable slot remains.
|
|
103
|
+
*/
|
|
104
|
+
export function normalizePetRemarks(raw, onWarning = () => { }) {
|
|
105
|
+
if (raw === undefined)
|
|
106
|
+
return undefined;
|
|
107
|
+
if (typeof raw !== 'object' || raw === null || Array.isArray(raw)) {
|
|
108
|
+
onWarning('remarks must be an object with pet/petCooldown/feed/feedCooldown/noTreats slots');
|
|
109
|
+
return undefined;
|
|
110
|
+
}
|
|
111
|
+
const remarks = {};
|
|
112
|
+
for (const [key, value] of Object.entries(raw)) {
|
|
113
|
+
if (!REMARK_KINDS.includes(key)) {
|
|
114
|
+
onWarning('unknown remarks slot ' + JSON.stringify(key));
|
|
115
|
+
continue;
|
|
116
|
+
}
|
|
117
|
+
const lines = (Array.isArray(value) ? value : [value])
|
|
118
|
+
.filter((line) => typeof line === 'string')
|
|
119
|
+
.map(line => line.trim())
|
|
120
|
+
.filter(line => line !== '')
|
|
121
|
+
.slice(0, REMARK_LINES_MAX)
|
|
122
|
+
.map(line => line.slice(0, REMARK_LINE_MAX));
|
|
123
|
+
if (lines.length === 0) {
|
|
124
|
+
onWarning('remarks slot ' + key + ' carries no usable lines');
|
|
125
|
+
continue;
|
|
126
|
+
}
|
|
127
|
+
remarks[key] = lines;
|
|
128
|
+
}
|
|
129
|
+
return Object.keys(remarks).length === 0 ? undefined : remarks;
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Round-robin reaction picker over the effective pools (per-pet custom lines
|
|
133
|
+
* override the built-in pool per slot). Counters are per slot, so each slot
|
|
134
|
+
* cycles its own list independently and picks stay deterministic for tests.
|
|
135
|
+
*/
|
|
136
|
+
export class RemarkPicker {
|
|
137
|
+
counters = new Map();
|
|
138
|
+
pools;
|
|
139
|
+
constructor(overrides) {
|
|
140
|
+
this.pools = {};
|
|
141
|
+
for (const kind of REMARK_KINDS) {
|
|
142
|
+
const custom = overrides?.[kind];
|
|
143
|
+
this.pools[kind] = custom !== undefined && custom.length > 0 ? custom : BUILTIN_REMARKS[kind];
|
|
144
|
+
}
|
|
145
|
+
}
|
|
146
|
+
/** The effective pool for one slot (custom override or built-in). */
|
|
147
|
+
pool(kind) {
|
|
148
|
+
return this.pools[kind];
|
|
149
|
+
}
|
|
150
|
+
/** The next line for one slot (round-robin within its pool). */
|
|
151
|
+
pick(kind) {
|
|
152
|
+
const pool = this.pools[kind];
|
|
153
|
+
const index = (this.counters.get(kind) ?? 0) % pool.length;
|
|
154
|
+
this.counters.set(kind, index + 1);
|
|
155
|
+
return pool[index];
|
|
156
|
+
}
|
|
157
|
+
}
|
package/lib/types/service.d.ts
CHANGED
|
@@ -5,6 +5,10 @@
|
|
|
5
5
|
* persistence through `persist`. The API gateway maps these methods onto
|
|
6
6
|
* `pet.state` / `pet.pets` / `pet.interact` / `pet.setVisible` /
|
|
7
7
|
* `pet.setConfig` / `pet.setName` / `pet.setPet` for browser consumers.
|
|
8
|
+
*
|
|
9
|
+
* Concurrent sessions each keep their own machine: the sprite animation
|
|
10
|
+
* follows the most recent meaningful event (the display session) while the
|
|
11
|
+
* state view carries one bubble per active session.
|
|
8
12
|
* @module @linxin666/dsh-pet/service
|
|
9
13
|
*/
|
|
10
14
|
import { Context, Service } from '@deepseek-ai/cordis';
|
|
@@ -54,12 +58,35 @@ export interface PetSettingsSection {
|
|
|
54
58
|
}
|
|
55
59
|
/** Settings namespace of the pet capability. Spelled here rather than imported: the browser half spells the same value. */
|
|
56
60
|
export declare const PET_SETTINGS_NAMESPACE = "pet";
|
|
61
|
+
/**
|
|
62
|
+
* One active session as the pet displays it. Sessions run in parallel, so
|
|
63
|
+
* each gets its own bubble while the sprite itself follows the most recent
|
|
64
|
+
* meaningful event (the display session).
|
|
65
|
+
*/
|
|
66
|
+
export interface PetSessionView {
|
|
67
|
+
/** Session identity (stringified for the wire; never exposed as a key). */
|
|
68
|
+
sessionId: string;
|
|
69
|
+
/** The animation this session's activity maps onto. */
|
|
70
|
+
animation: PetStateSnapshot['animation'];
|
|
71
|
+
/** This session's status bubble copy. */
|
|
72
|
+
bubble: string;
|
|
73
|
+
/** This session's raw activity phase. */
|
|
74
|
+
phase: PetStateSnapshot['phase'];
|
|
75
|
+
}
|
|
76
|
+
/** Hard cap on simultaneously displayed session bubbles (most recent first). */
|
|
77
|
+
export declare const MAX_SESSION_BUBBLES = 12;
|
|
57
78
|
/** Snapshot returned by `pet.state`. */
|
|
58
79
|
export interface PetStateView {
|
|
59
80
|
animation: PetStateSnapshot['animation'];
|
|
60
81
|
bubble?: string;
|
|
61
82
|
phase: PetStateSnapshot['phase'];
|
|
62
83
|
sessionActive: boolean;
|
|
84
|
+
/**
|
|
85
|
+
* Per-session bubbles for every concurrently active session, most recent
|
|
86
|
+
* first; optional so older hosts without the multi-session view stay
|
|
87
|
+
* consumable. The single 'bubble' above mirrors the display session.
|
|
88
|
+
*/
|
|
89
|
+
sessions?: PetSessionView[];
|
|
63
90
|
/** Affinity ledger snapshot. */
|
|
64
91
|
affinity: PetAffinityView;
|
|
65
92
|
/** Display configuration. */
|
|
@@ -99,6 +126,7 @@ declare module '@deepseek-ai/cordis' {
|
|
|
99
126
|
export declare class PetService extends Service {
|
|
100
127
|
static inject: string[];
|
|
101
128
|
private readonly machine;
|
|
129
|
+
private readonly stateConfig;
|
|
102
130
|
private readonly ledger;
|
|
103
131
|
private readonly registry;
|
|
104
132
|
private readonly persistDir;
|
|
@@ -106,6 +134,11 @@ export declare class PetService extends Service {
|
|
|
106
134
|
private disposeActivity;
|
|
107
135
|
/** Session whose most recent meaningful event currently drives the global pet. */
|
|
108
136
|
private displaySession;
|
|
137
|
+
/**
|
|
138
|
+
* Per-session activity, most recent last (Map insertion order). Bounded by
|
|
139
|
+
* MAX_SESSION_BUBBLES so a burst of sessions cannot grow it without bound;
|
|
140
|
+
* disposed sessions are removed by the 'session/disposed' listener.
|
|
141
|
+
*/
|
|
109
142
|
private readonly sessionActivity;
|
|
110
143
|
constructor(ctx: Context, config?: PetConfig);
|
|
111
144
|
/** Whether the pet service consumes session activity while enabled. */
|
|
@@ -135,9 +168,13 @@ export declare class PetService extends Service {
|
|
|
135
168
|
/** Start or stop the session-activity listeners that drive the pet. */
|
|
136
169
|
setEnabled(enabled: boolean): void;
|
|
137
170
|
private syncActivity;
|
|
138
|
-
/** Return the
|
|
139
|
-
private
|
|
140
|
-
/**
|
|
171
|
+
/** Return the per-session activity record, creating it on first sight. */
|
|
172
|
+
private activityOf;
|
|
173
|
+
/**
|
|
174
|
+
* Commit one activity: the session's own machine renders its bubble, and
|
|
175
|
+
* the session becomes the host-global display session (most recent
|
|
176
|
+
* meaningful event wins the sprite animation).
|
|
177
|
+
*/
|
|
141
178
|
private applyActivity;
|
|
142
179
|
/** RPC: pet or feed the pet. */
|
|
143
180
|
interact(kind: PetInteraction): Promise<PetInteractResult>;
|