@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.
- package/commands/adv/[[action]]/index.js +4 -4
- package/commands/adv/[[action]]/index.ts +4 -4
- package/lib/achievements.d.ts +4 -1
- package/lib/achievements.js +18 -17
- package/lib/achievements.js.map +1 -1
- package/lib/adv-command.d.ts +1 -0
- package/lib/adv-command.js +31 -20
- package/lib/adv-command.js.map +1 -1
- package/lib/game-flow.d.ts +1 -1
- package/lib/game-flow.js +50 -21
- package/lib/game-flow.js.map +1 -1
- package/lib/models.d.ts +4 -1
- package/lib/models.js +2 -1
- package/lib/models.js.map +1 -1
- package/lib/profile-format.d.ts +4 -3
- package/lib/profile-format.js +14 -13
- package/lib/profile-format.js.map +1 -1
- package/lib/scene-view.js +5 -3
- package/lib/scene-view.js.map +1 -1
- package/lib/session-service.js +1 -0
- package/lib/session-service.js.map +1 -1
- package/lib/story-catalog.d.ts +4 -2
- package/lib/story-catalog.js +59 -9
- package/lib/story-catalog.js.map +1 -1
- package/lib/story-items.d.ts +2 -1
- package/lib/story-items.js +19 -2
- package/lib/story-items.js.map +1 -1
- package/lib/story-scenes.d.ts +2 -1
- package/lib/story-scenes.js +1358 -464
- package/lib/story-scenes.js.map +1 -1
- package/lib/story.d.ts +4 -3
- package/lib/story.js +8 -8
- package/lib/story.js.map +1 -1
- package/middlewares/adv-alias/index.js +5 -3
- package/middlewares/adv-alias/index.ts +5 -3
- package/package.json +7 -7
- package/plugin.js +4 -0
- package/src/achievements.ts +21 -17
- package/src/adv-command.ts +35 -24
- package/src/game-flow.ts +51 -22
- package/src/models.ts +4 -2
- package/src/profile-format.ts +15 -13
- package/src/scene-view.ts +5 -3
- package/src/session-service.ts +1 -0
- package/src/story-catalog.ts +63 -10
- package/src/story-items.ts +21 -2
- package/src/story-scenes.ts +1103 -206
- 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 {
|
|
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
|
|
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
|
}
|