@zhin.js/plugin-text-adventure 1.1.15 → 1.1.17

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.
Files changed (48) hide show
  1. package/commands/adv/[[action]]/index.js +4 -4
  2. package/commands/adv/[[action]]/index.ts +4 -4
  3. package/lib/achievements.d.ts +4 -1
  4. package/lib/achievements.js +18 -17
  5. package/lib/achievements.js.map +1 -1
  6. package/lib/adv-command.d.ts +1 -0
  7. package/lib/adv-command.js +31 -20
  8. package/lib/adv-command.js.map +1 -1
  9. package/lib/game-flow.d.ts +1 -1
  10. package/lib/game-flow.js +50 -21
  11. package/lib/game-flow.js.map +1 -1
  12. package/lib/models.d.ts +4 -1
  13. package/lib/models.js +2 -1
  14. package/lib/models.js.map +1 -1
  15. package/lib/profile-format.d.ts +4 -3
  16. package/lib/profile-format.js +14 -13
  17. package/lib/profile-format.js.map +1 -1
  18. package/lib/scene-view.js +5 -3
  19. package/lib/scene-view.js.map +1 -1
  20. package/lib/session-service.js +1 -0
  21. package/lib/session-service.js.map +1 -1
  22. package/lib/story-catalog.d.ts +4 -2
  23. package/lib/story-catalog.js +59 -9
  24. package/lib/story-catalog.js.map +1 -1
  25. package/lib/story-items.d.ts +2 -1
  26. package/lib/story-items.js +19 -2
  27. package/lib/story-items.js.map +1 -1
  28. package/lib/story-scenes.d.ts +2 -1
  29. package/lib/story-scenes.js +1358 -464
  30. package/lib/story-scenes.js.map +1 -1
  31. package/lib/story.d.ts +4 -3
  32. package/lib/story.js +8 -8
  33. package/lib/story.js.map +1 -1
  34. package/middlewares/adv-alias/index.js +5 -3
  35. package/middlewares/adv-alias/index.ts +5 -3
  36. package/package.json +7 -7
  37. package/plugin.js +4 -0
  38. package/src/achievements.ts +21 -17
  39. package/src/adv-command.ts +35 -24
  40. package/src/game-flow.ts +51 -22
  41. package/src/models.ts +4 -2
  42. package/src/profile-format.ts +15 -13
  43. package/src/scene-view.ts +5 -3
  44. package/src/session-service.ts +1 -0
  45. package/src/story-catalog.ts +63 -10
  46. package/src/story-items.ts +21 -2
  47. package/src/story-scenes.ts +1103 -206
  48. package/src/story.ts +9 -8
package/src/story.ts CHANGED
@@ -1,3 +1,4 @@
1
+ import { type Locale } from 'zhin.js/i18n';
1
2
  export { ADV_PREFIX } from './story-types.js';
2
3
  export type { SceneChoice, Scene, GameState, ChoiceResult } from './story-types.js';
3
4
  export { ITEM_LABELS, ITEM_IDS, itemLabel } from './story-items.js';
@@ -5,7 +6,7 @@ export { SCENES, countScenes } from './story-scenes.js';
5
6
 
6
7
  import type { GameState, ChoiceResult, Scene } from './story-types.js';
7
8
  import { itemLabel } from './story-items.js';
8
- import { SCENES } from './story-scenes.js';
9
+ import { sceneCatalog } from './story-scenes.js';
9
10
  import { resolveTransition } from './story-transitions.js';
10
11
 
11
12
  export function parseInventory(value: string | string[] | unknown): string[] {
@@ -52,10 +53,10 @@ export function stateFromSession(row: {
52
53
  };
53
54
  }
54
55
 
55
- export function formatStatusBar(state: GameState): string {
56
+ export function formatStatusBar(state: GameState, locale: Locale = 'zh-CN'): string {
56
57
  const items = state.inventory.length
57
- ? state.inventory.map(itemLabel).join('、')
58
- : '无';
58
+ ? state.inventory.map((id) => itemLabel(id, locale)).join(locale === 'en' ? ', ' : '、')
59
+ : locale === 'en' ? 'None' : '无';
59
60
  return `❤️ ${Math.max(0, state.hp)} · 🎒 ${items}`;
60
61
  }
61
62
 
@@ -63,8 +64,8 @@ export function resolveChoice(state: GameState, choiceId: string): ChoiceResult
63
64
  return resolveTransition(state, choiceId);
64
65
  }
65
66
 
66
- export function getScene(sceneId: string): Scene | undefined {
67
- return SCENES[sceneId];
67
+ export function getScene(sceneId: string, locale: Locale = 'zh-CN'): Scene | undefined {
68
+ return sceneCatalog(locale)[sceneId];
68
69
  }
69
70
 
70
71
  export function visibleChoices(scene: Scene, state: GameState) {
@@ -97,8 +98,8 @@ export function applyChoiceResult(state: GameState, result: ChoiceResult): GameS
97
98
  };
98
99
  }
99
100
 
100
- export function sceneNarrative(scene: Scene, state: GameState): string {
101
+ export function sceneNarrative(scene: Scene, state: GameState, locale: Locale = 'zh-CN'): string {
101
102
  const body = typeof scene.text === 'function' ? scene.text(state) : scene.text;
102
103
  if (scene.terminal) return body;
103
- return `${body}\n\n${formatStatusBar(state)}`;
104
+ return `${body}\n\n${formatStatusBar(state, locale)}`;
104
105
  }