steamsheep-ts-game-engine 3.0.0 → 3.1.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/README.md +62 -5
- package/dist/core/index.d.mts +2 -2
- package/dist/core/index.d.ts +2 -2
- package/dist/index.d.mts +2 -2
- package/dist/index.d.ts +2 -2
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/index.mjs +1 -1
- package/dist/index.mjs.map +1 -1
- package/dist/state/index.d.mts +2 -2
- package/dist/state/index.d.ts +2 -2
- package/dist/{store-B7yMYHpB.d.mts → store-5-3GQpi9.d.mts} +1 -1
- package/dist/{store-BKROShPq.d.ts → store-PPh__zkF.d.ts} +1 -1
- package/dist/systems/index.d.mts +2 -2
- package/dist/systems/index.d.ts +2 -2
- package/dist/systems/index.js +1 -1
- package/dist/systems/index.js.map +1 -1
- package/dist/systems/index.mjs +1 -1
- package/dist/systems/index.mjs.map +1 -1
- package/dist/{types-C3Q7UPWy.d.mts → types-D-nDlnv3.d.mts} +69 -20
- package/dist/{types-C3Q7UPWy.d.ts → types-D-nDlnv3.d.ts} +69 -20
- package/dist/ui/index.d.mts +1 -1
- package/dist/ui/index.d.ts +1 -1
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -197,7 +197,7 @@ effects: {
|
|
|
197
197
|
}
|
|
198
198
|
```
|
|
199
199
|
|
|
200
|
-
### 4. 职责分离 (afterEffects)
|
|
200
|
+
### 4. 职责分离 (afterEffects + resultText 双参数)
|
|
201
201
|
|
|
202
202
|
```typescript
|
|
203
203
|
{
|
|
@@ -213,10 +213,11 @@ effects: {
|
|
|
213
213
|
}
|
|
214
214
|
},
|
|
215
215
|
|
|
216
|
-
//
|
|
217
|
-
resultText: (state) => {
|
|
218
|
-
|
|
219
|
-
|
|
216
|
+
// 文本生成 - 可以比较前后状态
|
|
217
|
+
resultText: (state, original) => {
|
|
218
|
+
const sanityLoss = original.stats.sanity - state.stats.sanity;
|
|
219
|
+
return sanityLoss > 15
|
|
220
|
+
? `你失去了 ${sanityLoss} 点理智,感到崩溃...`
|
|
220
221
|
: '仪式完成了。';
|
|
221
222
|
}
|
|
222
223
|
}
|
|
@@ -359,6 +360,61 @@ if (store.hasSnapshot('before_boss_fight')) {
|
|
|
359
360
|
store.deleteSnapshot('before_boss_fight');
|
|
360
361
|
```
|
|
361
362
|
|
|
363
|
+
### 11. ResultText 比较前后状态
|
|
364
|
+
|
|
365
|
+
```typescript
|
|
366
|
+
// 简化前:需要通过 afterEffects + extra 传递信息
|
|
367
|
+
{
|
|
368
|
+
effects: {
|
|
369
|
+
conditionalEffects: () => {
|
|
370
|
+
if (Math.random() < 0.15) {
|
|
371
|
+
return { statsChange: { gnosis: 1 } };
|
|
372
|
+
}
|
|
373
|
+
return null;
|
|
374
|
+
}
|
|
375
|
+
},
|
|
376
|
+
afterEffects: (state, original, actions) => {
|
|
377
|
+
const gainedGnosis = state.stats.gnosis > original.stats.gnosis;
|
|
378
|
+
actions.setExtra({ lastMeditateGainedGnosis: gainedGnosis });
|
|
379
|
+
},
|
|
380
|
+
resultText: (state) => {
|
|
381
|
+
return state.extra.lastMeditateGainedGnosis
|
|
382
|
+
? "获得了灵知!"
|
|
383
|
+
: "平静地冥想。";
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
|
|
387
|
+
// 简化后:直接比较前后状态
|
|
388
|
+
{
|
|
389
|
+
effects: {
|
|
390
|
+
conditionalEffects: () => {
|
|
391
|
+
if (Math.random() < 0.15) {
|
|
392
|
+
return { statsChange: { gnosis: 1 } };
|
|
393
|
+
}
|
|
394
|
+
return null;
|
|
395
|
+
}
|
|
396
|
+
},
|
|
397
|
+
resultText: (state, original) => {
|
|
398
|
+
const gainedGnosis = state.stats.gnosis > original.stats.gnosis;
|
|
399
|
+
return gainedGnosis
|
|
400
|
+
? "获得了灵知!"
|
|
401
|
+
: "平静地冥想。";
|
|
402
|
+
}
|
|
403
|
+
}
|
|
404
|
+
|
|
405
|
+
// 显示具体变化量
|
|
406
|
+
resultText: (state, original) => {
|
|
407
|
+
const hpChange = state.stats.hp - original.stats.hp;
|
|
408
|
+
const goldChange = state.stats.gold - original.stats.gold;
|
|
409
|
+
|
|
410
|
+
const parts = [];
|
|
411
|
+
if (hpChange < 0) parts.push(`失去 ${-hpChange} HP`);
|
|
412
|
+
if (goldChange > 0) parts.push(`获得 ${goldChange} 金币`);
|
|
413
|
+
|
|
414
|
+
return parts.join(',') || '什么都没发生。';
|
|
415
|
+
}
|
|
416
|
+
```
|
|
417
|
+
|
|
362
418
|
---
|
|
363
419
|
|
|
364
420
|
## 🎮 完整示例
|
|
@@ -477,6 +533,7 @@ const performRitualAction: ActionDef<Stats, Items, Flags, Extra> = {
|
|
|
477
533
|
8. ✅ **灵活的 Requirements** - custom 可返回失败原因
|
|
478
534
|
9. ✅ **明确的执行顺序** - 5 个阶段,清晰的文档说明
|
|
479
535
|
10. ✅ **命名快照系统** - 支持保存和恢复命名快照
|
|
536
|
+
11. ✅ **ResultText 双参数** - 可以比较前后状态,无需 extra 传递
|
|
480
537
|
|
|
481
538
|
所有功能都是类型安全的,并且完全向后兼容!
|
|
482
539
|
|
package/dist/core/index.d.mts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as GameState } from '../types-
|
|
2
|
-
export { A as ActionDef, E as EffectDef, F as FlagsBatchOperation, G as GameStoreActions, d as LocationDef, L as LogEntry, b as NotificationPayload, N as NotificationType, R as RequirementCheckResult, c as RequirementDef, S as StatRequirement, W as WorldState } from '../types-
|
|
1
|
+
import { a as GameState } from '../types-D-nDlnv3.mjs';
|
|
2
|
+
export { A as ActionDef, E as EffectDef, F as FlagsBatchOperation, G as GameStoreActions, d as LocationDef, L as LogEntry, b as NotificationPayload, N as NotificationType, R as RequirementCheckResult, c as RequirementDef, S as StatRequirement, W as WorldState } from '../types-D-nDlnv3.mjs';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* 系统消息常量
|
package/dist/core/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { a as GameState } from '../types-
|
|
2
|
-
export { A as ActionDef, E as EffectDef, F as FlagsBatchOperation, G as GameStoreActions, d as LocationDef, L as LogEntry, b as NotificationPayload, N as NotificationType, R as RequirementCheckResult, c as RequirementDef, S as StatRequirement, W as WorldState } from '../types-
|
|
1
|
+
import { a as GameState } from '../types-D-nDlnv3.js';
|
|
2
|
+
export { A as ActionDef, E as EffectDef, F as FlagsBatchOperation, G as GameStoreActions, d as LocationDef, L as LogEntry, b as NotificationPayload, N as NotificationType, R as RequirementCheckResult, c as RequirementDef, S as StatRequirement, W as WorldState } from '../types-D-nDlnv3.js';
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* 系统消息常量
|
package/dist/index.d.mts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { A as ActionDef, E as EffectDef, F as FlagsBatchOperation, a as GameState, G as GameStoreActions, d as LocationDef, L as LogEntry, b as NotificationPayload, N as NotificationType, R as RequirementCheckResult, c as RequirementDef, S as StatRequirement, W as WorldState } from './types-
|
|
1
|
+
export { A as ActionDef, E as EffectDef, F as FlagsBatchOperation, a as GameState, G as GameStoreActions, d as LocationDef, L as LogEntry, b as NotificationPayload, N as NotificationType, R as RequirementCheckResult, c as RequirementDef, S as StatRequirement, W as WorldState } from './types-D-nDlnv3.mjs';
|
|
2
2
|
export { DEFAULT_CONFIG, DEFAULT_STATS, ENGINE_VERSION, LOG_TYPE_COLORS, SystemMessages, TIME_CONSTANTS, UI_CONSTANTS, VALIDATION, clamp, debounce, deepClone, delay, formatGameTime, formatNumber, generateId, get, getPercentage, getStateDiff, getTimeOfDay, isEmpty, randomChoice, randomInt, shuffle, throttle } from './core/index.mjs';
|
|
3
|
-
export { G as GameStore, c as createGameEngineStore } from './store-
|
|
3
|
+
export { G as GameStore, c as createGameEngineStore } from './store-5-3GQpi9.mjs';
|
|
4
4
|
export { HistoryManager, SnapshotInfo } from './state/index.mjs';
|
|
5
5
|
export { EngineEvents, EventBus, FlowSystem, QuerySystem, gameEvents } from './systems/index.mjs';
|
|
6
6
|
export { Layout, LogStream, MainContent, OverlaySystem } from './ui/index.mjs';
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
export { A as ActionDef, E as EffectDef, F as FlagsBatchOperation, a as GameState, G as GameStoreActions, d as LocationDef, L as LogEntry, b as NotificationPayload, N as NotificationType, R as RequirementCheckResult, c as RequirementDef, S as StatRequirement, W as WorldState } from './types-
|
|
1
|
+
export { A as ActionDef, E as EffectDef, F as FlagsBatchOperation, a as GameState, G as GameStoreActions, d as LocationDef, L as LogEntry, b as NotificationPayload, N as NotificationType, R as RequirementCheckResult, c as RequirementDef, S as StatRequirement, W as WorldState } from './types-D-nDlnv3.js';
|
|
2
2
|
export { DEFAULT_CONFIG, DEFAULT_STATS, ENGINE_VERSION, LOG_TYPE_COLORS, SystemMessages, TIME_CONSTANTS, UI_CONSTANTS, VALIDATION, clamp, debounce, deepClone, delay, formatGameTime, formatNumber, generateId, get, getPercentage, getStateDiff, getTimeOfDay, isEmpty, randomChoice, randomInt, shuffle, throttle } from './core/index.js';
|
|
3
|
-
export { G as GameStore, c as createGameEngineStore } from './store-
|
|
3
|
+
export { G as GameStore, c as createGameEngineStore } from './store-PPh__zkF.js';
|
|
4
4
|
export { HistoryManager, SnapshotInfo } from './state/index.js';
|
|
5
5
|
export { EngineEvents, EventBus, FlowSystem, QuerySystem, gameEvents } from './systems/index.js';
|
|
6
6
|
export { Layout, LogStream, MainContent, OverlaySystem } from './ui/index.js';
|
package/dist/index.js
CHANGED
|
@@ -1355,7 +1355,7 @@ var FlowSystem = class {
|
|
|
1355
1355
|
action.afterEffects(currentState, originalState, actions);
|
|
1356
1356
|
}
|
|
1357
1357
|
const finalState = store;
|
|
1358
|
-
const resultText = typeof action.resultText === "function" ? action.resultText(finalState) : action.resultText;
|
|
1358
|
+
const resultText = typeof action.resultText === "function" ? action.resultText(finalState, state) : action.resultText;
|
|
1359
1359
|
store.addLog(resultText, "result");
|
|
1360
1360
|
gameEvents.emit(EngineEvents.ACTION_EXECUTED, { actionId: action.id });
|
|
1361
1361
|
return true;
|