@magicborn/dialogue-forge 0.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 +233 -0
- package/bin/dialogue-forge.js +78 -0
- package/demo/app/layout.tsx +36 -0
- package/demo/app/page.tsx +440 -0
- package/demo/components/ThemeSwitcher.tsx +611 -0
- package/demo/next.config.mjs +7 -0
- package/demo/package.json +29 -0
- package/demo/postcss.config.mjs +7 -0
- package/demo/public/logo.svg +1 -0
- package/demo/styles/globals.css +19 -0
- package/demo/tailwind.config.ts +90 -0
- package/demo/tsconfig.json +42 -0
- package/dist/components/ChoiceEdgeV2.d.ts +3 -0
- package/dist/components/ChoiceEdgeV2.js +103 -0
- package/dist/components/CodeBlock.d.ts +8 -0
- package/dist/components/CodeBlock.js +24 -0
- package/dist/components/ConditionAutocomplete.d.ts +14 -0
- package/dist/components/ConditionAutocomplete.js +284 -0
- package/dist/components/ConditionalNodeV2.d.ts +16 -0
- package/dist/components/ConditionalNodeV2.js +147 -0
- package/dist/components/DialogueEditorV2.d.ts +22 -0
- package/dist/components/DialogueEditorV2.js +1170 -0
- package/dist/components/EdgeIcon.d.ts +8 -0
- package/dist/components/EdgeIcon.js +13 -0
- package/dist/components/ExampleLoader.d.ts +11 -0
- package/dist/components/ExampleLoader.js +52 -0
- package/dist/components/ExampleLoaderButton.d.ts +15 -0
- package/dist/components/ExampleLoaderButton.js +102 -0
- package/dist/components/FlagManager.d.ts +11 -0
- package/dist/components/FlagManager.js +282 -0
- package/dist/components/FlagSelector.d.ts +11 -0
- package/dist/components/FlagSelector.js +235 -0
- package/dist/components/GuidePanel.d.ts +7 -0
- package/dist/components/GuidePanel.js +1176 -0
- package/dist/components/Minimap.d.ts +16 -0
- package/dist/components/Minimap.js +93 -0
- package/dist/components/NPCEdgeV2.d.ts +3 -0
- package/dist/components/NPCEdgeV2.js +104 -0
- package/dist/components/NPCNodeV2.d.ts +26 -0
- package/dist/components/NPCNodeV2.js +86 -0
- package/dist/components/NodeEditor.d.ts +18 -0
- package/dist/components/NodeEditor.js +1025 -0
- package/dist/components/PlayView.d.ts +12 -0
- package/dist/components/PlayView.js +307 -0
- package/dist/components/PlayerNodeV2.d.ts +16 -0
- package/dist/components/PlayerNodeV2.js +139 -0
- package/dist/components/ReactFlowPOC.d.ts +61 -0
- package/dist/components/ReactFlowPOC.js +312 -0
- package/dist/components/ScenePlayer.d.ts +18 -0
- package/dist/components/ScenePlayer.js +196 -0
- package/dist/components/YarnView.d.ts +9 -0
- package/dist/components/YarnView.js +45 -0
- package/dist/components/ZoomControls.d.ts +11 -0
- package/dist/components/ZoomControls.js +34 -0
- package/dist/esm/components/ChoiceEdgeV2.d.ts +3 -0
- package/dist/esm/components/ChoiceEdgeV2.js +67 -0
- package/dist/esm/components/CodeBlock.d.ts +8 -0
- package/dist/esm/components/CodeBlock.js +18 -0
- package/dist/esm/components/ConditionAutocomplete.d.ts +14 -0
- package/dist/esm/components/ConditionAutocomplete.js +248 -0
- package/dist/esm/components/ConditionalNodeV2.d.ts +16 -0
- package/dist/esm/components/ConditionalNodeV2.js +111 -0
- package/dist/esm/components/DialogueEditorV2.d.ts +22 -0
- package/dist/esm/components/DialogueEditorV2.js +1134 -0
- package/dist/esm/components/EdgeIcon.d.ts +8 -0
- package/dist/esm/components/EdgeIcon.js +7 -0
- package/dist/esm/components/ExampleLoader.d.ts +11 -0
- package/dist/esm/components/ExampleLoader.js +46 -0
- package/dist/esm/components/ExampleLoaderButton.d.ts +15 -0
- package/dist/esm/components/ExampleLoaderButton.js +66 -0
- package/dist/esm/components/FlagManager.d.ts +11 -0
- package/dist/esm/components/FlagManager.js +246 -0
- package/dist/esm/components/FlagSelector.d.ts +11 -0
- package/dist/esm/components/FlagSelector.js +199 -0
- package/dist/esm/components/GuidePanel.d.ts +7 -0
- package/dist/esm/components/GuidePanel.js +1140 -0
- package/dist/esm/components/Minimap.d.ts +16 -0
- package/dist/esm/components/Minimap.js +57 -0
- package/dist/esm/components/NPCEdgeV2.d.ts +3 -0
- package/dist/esm/components/NPCEdgeV2.js +68 -0
- package/dist/esm/components/NPCNodeV2.d.ts +26 -0
- package/dist/esm/components/NPCNodeV2.js +80 -0
- package/dist/esm/components/NodeEditor.d.ts +18 -0
- package/dist/esm/components/NodeEditor.js +989 -0
- package/dist/esm/components/PlayView.d.ts +12 -0
- package/dist/esm/components/PlayView.js +271 -0
- package/dist/esm/components/PlayerNodeV2.d.ts +16 -0
- package/dist/esm/components/PlayerNodeV2.js +103 -0
- package/dist/esm/components/ReactFlowPOC.d.ts +61 -0
- package/dist/esm/components/ReactFlowPOC.js +275 -0
- package/dist/esm/components/ScenePlayer.d.ts +18 -0
- package/dist/esm/components/ScenePlayer.js +160 -0
- package/dist/esm/components/YarnView.d.ts +9 -0
- package/dist/esm/components/YarnView.js +39 -0
- package/dist/esm/components/ZoomControls.d.ts +11 -0
- package/dist/esm/components/ZoomControls.js +28 -0
- package/dist/esm/examples/example-loader.d.ts +29 -0
- package/dist/esm/examples/example-loader.js +103 -0
- package/dist/esm/examples/examples-registry.d.ts +38 -0
- package/dist/esm/examples/examples-registry.js +153 -0
- package/dist/esm/examples/index.d.ts +26 -0
- package/dist/esm/examples/index.js +50 -0
- package/dist/esm/examples/legacy-examples.d.ts +9 -0
- package/dist/esm/examples/legacy-examples.js +814 -0
- package/dist/esm/examples/yarn-examples.d.ts +35 -0
- package/dist/esm/examples/yarn-examples.js +181 -0
- package/dist/esm/index.d.ts +21 -0
- package/dist/esm/index.js +26 -0
- package/dist/esm/lib/flag-manager.d.ts +21 -0
- package/dist/esm/lib/flag-manager.js +93 -0
- package/dist/esm/lib/yarn-converter/__tests__/round-trip.test.d.ts +1 -0
- package/dist/esm/lib/yarn-converter/__tests__/round-trip.test.js +169 -0
- package/dist/esm/lib/yarn-converter.d.ts +17 -0
- package/dist/esm/lib/yarn-converter.js +521 -0
- package/dist/esm/lib/yarn-runner/__tests__/condition-evaluator.test.d.ts +1 -0
- package/dist/esm/lib/yarn-runner/__tests__/condition-evaluator.test.js +171 -0
- package/dist/esm/lib/yarn-runner/__tests__/node-processor.test.d.ts +1 -0
- package/dist/esm/lib/yarn-runner/__tests__/node-processor.test.js +237 -0
- package/dist/esm/lib/yarn-runner/__tests__/variable-manager.test.d.ts +1 -0
- package/dist/esm/lib/yarn-runner/__tests__/variable-manager.test.js +106 -0
- package/dist/esm/lib/yarn-runner/condition-evaluator.d.ts +12 -0
- package/dist/esm/lib/yarn-runner/condition-evaluator.js +56 -0
- package/dist/esm/lib/yarn-runner/index.d.ts +12 -0
- package/dist/esm/lib/yarn-runner/index.js +11 -0
- package/dist/esm/lib/yarn-runner/node-processor.d.ts +18 -0
- package/dist/esm/lib/yarn-runner/node-processor.js +129 -0
- package/dist/esm/lib/yarn-runner/variable-manager.d.ts +51 -0
- package/dist/esm/lib/yarn-runner/variable-manager.js +120 -0
- package/dist/esm/lib/yarn-runner/variable-operations.d.ts +16 -0
- package/dist/esm/lib/yarn-runner/variable-operations.js +88 -0
- package/dist/esm/types/conditionals.d.ts +29 -0
- package/dist/esm/types/conditionals.js +1 -0
- package/dist/esm/types/constants.d.ts +59 -0
- package/dist/esm/types/constants.js +55 -0
- package/dist/esm/types/flags.d.ts +49 -0
- package/dist/esm/types/flags.js +49 -0
- package/dist/esm/types/game-state.d.ts +62 -0
- package/dist/esm/types/game-state.js +6 -0
- package/dist/esm/types/index.d.ts +77 -0
- package/dist/esm/types/index.js +1 -0
- package/dist/esm/utils/constants.d.ts +5 -0
- package/dist/esm/utils/constants.js +5 -0
- package/dist/esm/utils/feature-flags.d.ts +11 -0
- package/dist/esm/utils/feature-flags.js +11 -0
- package/dist/esm/utils/game-state-flattener.d.ts +41 -0
- package/dist/esm/utils/game-state-flattener.js +135 -0
- package/dist/esm/utils/layout/collision.d.ts +27 -0
- package/dist/esm/utils/layout/collision.js +74 -0
- package/dist/esm/utils/layout/index.d.ts +82 -0
- package/dist/esm/utils/layout/index.js +98 -0
- package/dist/esm/utils/layout/registry.d.ts +91 -0
- package/dist/esm/utils/layout/registry.js +148 -0
- package/dist/esm/utils/layout/strategies/dagre.d.ts +19 -0
- package/dist/esm/utils/layout/strategies/dagre.js +182 -0
- package/dist/esm/utils/layout/strategies/force.d.ts +21 -0
- package/dist/esm/utils/layout/strategies/force.js +178 -0
- package/dist/esm/utils/layout/strategies/grid.d.ts +17 -0
- package/dist/esm/utils/layout/strategies/grid.js +91 -0
- package/dist/esm/utils/layout/strategies/index.d.ts +8 -0
- package/dist/esm/utils/layout/strategies/index.js +8 -0
- package/dist/esm/utils/layout/types.d.ts +100 -0
- package/dist/esm/utils/layout/types.js +7 -0
- package/dist/esm/utils/layout.d.ts +9 -0
- package/dist/esm/utils/layout.js +17 -0
- package/dist/esm/utils/node-helpers.d.ts +7 -0
- package/dist/esm/utils/node-helpers.js +94 -0
- package/dist/esm/utils/reactflow-converter.d.ts +42 -0
- package/dist/esm/utils/reactflow-converter.js +217 -0
- package/dist/examples/example-loader.d.ts +29 -0
- package/dist/examples/example-loader.js +109 -0
- package/dist/examples/examples-registry.d.ts +38 -0
- package/dist/examples/examples-registry.js +160 -0
- package/dist/examples/index.d.ts +26 -0
- package/dist/examples/index.js +63 -0
- package/dist/examples/legacy-examples.d.ts +9 -0
- package/dist/examples/legacy-examples.js +817 -0
- package/dist/examples/yarn-examples.d.ts +35 -0
- package/dist/examples/yarn-examples.js +189 -0
- package/dist/index.d.ts +21 -0
- package/dist/index.js +66 -0
- package/dist/lib/flag-manager.d.ts +21 -0
- package/dist/lib/flag-manager.js +99 -0
- package/dist/lib/yarn-converter/__tests__/round-trip.test.d.ts +1 -0
- package/dist/lib/yarn-converter/__tests__/round-trip.test.js +171 -0
- package/dist/lib/yarn-converter.d.ts +17 -0
- package/dist/lib/yarn-converter.js +525 -0
- package/dist/lib/yarn-runner/__tests__/condition-evaluator.test.d.ts +1 -0
- package/dist/lib/yarn-runner/__tests__/condition-evaluator.test.js +173 -0
- package/dist/lib/yarn-runner/__tests__/node-processor.test.d.ts +1 -0
- package/dist/lib/yarn-runner/__tests__/node-processor.test.js +239 -0
- package/dist/lib/yarn-runner/__tests__/variable-manager.test.d.ts +1 -0
- package/dist/lib/yarn-runner/__tests__/variable-manager.test.js +108 -0
- package/dist/lib/yarn-runner/condition-evaluator.d.ts +12 -0
- package/dist/lib/yarn-runner/condition-evaluator.js +60 -0
- package/dist/lib/yarn-runner/index.d.ts +12 -0
- package/dist/lib/yarn-runner/index.js +21 -0
- package/dist/lib/yarn-runner/node-processor.d.ts +18 -0
- package/dist/lib/yarn-runner/node-processor.js +133 -0
- package/dist/lib/yarn-runner/variable-manager.d.ts +51 -0
- package/dist/lib/yarn-runner/variable-manager.js +124 -0
- package/dist/lib/yarn-runner/variable-operations.d.ts +16 -0
- package/dist/lib/yarn-runner/variable-operations.js +92 -0
- package/dist/types/conditionals.d.ts +29 -0
- package/dist/types/conditionals.js +2 -0
- package/dist/types/constants.d.ts +59 -0
- package/dist/types/constants.js +58 -0
- package/dist/types/flags.d.ts +49 -0
- package/dist/types/flags.js +52 -0
- package/dist/types/game-state.d.ts +62 -0
- package/dist/types/game-state.js +7 -0
- package/dist/types/index.d.ts +77 -0
- package/dist/types/index.js +2 -0
- package/dist/utils/constants.d.ts +5 -0
- package/dist/utils/constants.js +8 -0
- package/dist/utils/feature-flags.d.ts +11 -0
- package/dist/utils/feature-flags.js +14 -0
- package/dist/utils/game-state-flattener.d.ts +41 -0
- package/dist/utils/game-state-flattener.js +140 -0
- package/dist/utils/layout/collision.d.ts +27 -0
- package/dist/utils/layout/collision.js +77 -0
- package/dist/utils/layout/index.d.ts +82 -0
- package/dist/utils/layout/index.js +109 -0
- package/dist/utils/layout/registry.d.ts +91 -0
- package/dist/utils/layout/registry.js +151 -0
- package/dist/utils/layout/strategies/dagre.d.ts +19 -0
- package/dist/utils/layout/strategies/dagre.js +189 -0
- package/dist/utils/layout/strategies/force.d.ts +21 -0
- package/dist/utils/layout/strategies/force.js +182 -0
- package/dist/utils/layout/strategies/grid.d.ts +17 -0
- package/dist/utils/layout/strategies/grid.js +95 -0
- package/dist/utils/layout/strategies/index.d.ts +8 -0
- package/dist/utils/layout/strategies/index.js +14 -0
- package/dist/utils/layout/types.d.ts +100 -0
- package/dist/utils/layout/types.js +8 -0
- package/dist/utils/layout.d.ts +9 -0
- package/dist/utils/layout.js +25 -0
- package/dist/utils/node-helpers.d.ts +7 -0
- package/dist/utils/node-helpers.js +101 -0
- package/dist/utils/reactflow-converter.d.ts +42 -0
- package/dist/utils/reactflow-converter.js +223 -0
- package/package.json +70 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Inline Yarn file contents for examples
|
|
3
|
+
* This allows examples to be bundled and loaded synchronously
|
|
4
|
+
*
|
|
5
|
+
* To add a new example:
|
|
6
|
+
* 1. Create a .yarn file in the examples directory
|
|
7
|
+
* 2. Copy its content here as a string literal
|
|
8
|
+
* 3. Add it to the yarnExamplesContent object
|
|
9
|
+
*/
|
|
10
|
+
import { DialogueTree } from '../types';
|
|
11
|
+
/**
|
|
12
|
+
* Load all examples synchronously
|
|
13
|
+
* This should be called once at initialization
|
|
14
|
+
*/
|
|
15
|
+
export declare function loadAllExamples(): Record<string, DialogueTree>;
|
|
16
|
+
/**
|
|
17
|
+
* Get a loaded example dialogue
|
|
18
|
+
*/
|
|
19
|
+
export declare function getExampleDialogue(exampleId: string): DialogueTree | null;
|
|
20
|
+
/**
|
|
21
|
+
* Get all loaded examples
|
|
22
|
+
*/
|
|
23
|
+
export declare function getAllExampleDialogues(): Record<string, DialogueTree>;
|
|
24
|
+
/**
|
|
25
|
+
* Get flag schema for an example
|
|
26
|
+
*/
|
|
27
|
+
export declare function getExampleFlagSchema(exampleId: string): import("..").FlagSchema | null;
|
|
28
|
+
/**
|
|
29
|
+
* Check if an example has Yarn content available
|
|
30
|
+
*/
|
|
31
|
+
export declare function hasExampleContent(exampleId: string): boolean;
|
|
32
|
+
/**
|
|
33
|
+
* Get list of example IDs that have content available
|
|
34
|
+
*/
|
|
35
|
+
export declare function getAvailableExampleIds(): string[];
|
|
@@ -0,0 +1,189 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Inline Yarn file contents for examples
|
|
4
|
+
* This allows examples to be bundled and loaded synchronously
|
|
5
|
+
*
|
|
6
|
+
* To add a new example:
|
|
7
|
+
* 1. Create a .yarn file in the examples directory
|
|
8
|
+
* 2. Copy its content here as a string literal
|
|
9
|
+
* 3. Add it to the yarnExamplesContent object
|
|
10
|
+
*/
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.loadAllExamples = loadAllExamples;
|
|
13
|
+
exports.getExampleDialogue = getExampleDialogue;
|
|
14
|
+
exports.getAllExampleDialogues = getAllExampleDialogues;
|
|
15
|
+
exports.getExampleFlagSchema = getExampleFlagSchema;
|
|
16
|
+
exports.hasExampleContent = hasExampleContent;
|
|
17
|
+
exports.getAvailableExampleIds = getAvailableExampleIds;
|
|
18
|
+
const yarn_converter_1 = require("../lib/yarn-converter");
|
|
19
|
+
const examples_registry_1 = require("./examples-registry");
|
|
20
|
+
/**
|
|
21
|
+
* Map of example ID to Yarn file content
|
|
22
|
+
* All examples are stored as Yarn strings here for easy discovery and maintenance
|
|
23
|
+
*/
|
|
24
|
+
const yarnExamplesContent = {
|
|
25
|
+
'variable-operations': `title: merchant_shop
|
|
26
|
+
---
|
|
27
|
+
Merchant: Welcome to my shop, {$player_name}!
|
|
28
|
+
Merchant: You currently have {$stat_gold} gold pieces.
|
|
29
|
+
<<if $stat_gold >= 100>>
|
|
30
|
+
Merchant: You can afford the sword! It costs 100 gold.
|
|
31
|
+
-> Buy the sword
|
|
32
|
+
<<set $item_sword = true>>
|
|
33
|
+
<<set $stat_gold -= 100>>
|
|
34
|
+
Merchant: Thank you for your purchase! You now have {$stat_gold} gold.
|
|
35
|
+
<<jump after_purchase>>
|
|
36
|
+
-> Maybe later
|
|
37
|
+
Merchant: Come back anytime!
|
|
38
|
+
<<jump end>>
|
|
39
|
+
<<elseif $stat_gold >= 50>>
|
|
40
|
+
Merchant: You can afford the potion! It costs 50 gold.
|
|
41
|
+
-> Buy the potion
|
|
42
|
+
<<set $item_potion = true>>
|
|
43
|
+
<<set $stat_gold -= 50>>
|
|
44
|
+
Merchant: Thank you! You now have {$stat_gold} gold.
|
|
45
|
+
<<jump after_purchase>>
|
|
46
|
+
-> Save up for the sword
|
|
47
|
+
Merchant: Wise choice! Come back when you have more gold.
|
|
48
|
+
<<jump end>>
|
|
49
|
+
<<else>>
|
|
50
|
+
Merchant: I'm sorry, but you don't have enough gold for anything.
|
|
51
|
+
Merchant: Come back when you have at least 50 gold pieces.
|
|
52
|
+
<<jump end>>
|
|
53
|
+
<<endif>>
|
|
54
|
+
===
|
|
55
|
+
|
|
56
|
+
title: after_purchase
|
|
57
|
+
---
|
|
58
|
+
Merchant: Is there anything else you'd like?
|
|
59
|
+
<<set $stat_reputation += 5>>
|
|
60
|
+
Merchant: Your reputation with me has increased! It's now {$stat_reputation}.
|
|
61
|
+
-> Browse more
|
|
62
|
+
<<jump merchant_shop>>
|
|
63
|
+
-> Leave
|
|
64
|
+
Merchant: Thanks for shopping!
|
|
65
|
+
<<jump end>>
|
|
66
|
+
===
|
|
67
|
+
|
|
68
|
+
title: quest_reward
|
|
69
|
+
---
|
|
70
|
+
QuestGiver: You've completed the quest! Here's your reward.
|
|
71
|
+
<<set $stat_gold += 500>>
|
|
72
|
+
<<set $stat_experience += 100>>
|
|
73
|
+
<<set $quest_dragon_slayer = "complete">>
|
|
74
|
+
QuestGiver: You received 500 gold and 100 experience!
|
|
75
|
+
QuestGiver: You now have {$stat_gold} gold and {$stat_experience} experience points.
|
|
76
|
+
<<jump end>>
|
|
77
|
+
===
|
|
78
|
+
|
|
79
|
+
title: stat_multiplier
|
|
80
|
+
---
|
|
81
|
+
Trainer: I can double your strength for a price.
|
|
82
|
+
<<if $stat_gold >= 200>>
|
|
83
|
+
Trainer: For 200 gold, I'll double your strength stat.
|
|
84
|
+
-> Pay for training
|
|
85
|
+
<<set $stat_strength *= 2>>
|
|
86
|
+
<<set $stat_gold -= 200>>
|
|
87
|
+
Trainer: Your strength is now {$stat_strength}!
|
|
88
|
+
<<jump end>>
|
|
89
|
+
-> Not right now
|
|
90
|
+
Trainer: Come back when you're ready.
|
|
91
|
+
<<jump end>>
|
|
92
|
+
<<else>>
|
|
93
|
+
Trainer: You need 200 gold for this training.
|
|
94
|
+
<<jump end>>
|
|
95
|
+
<<endif>>
|
|
96
|
+
===
|
|
97
|
+
|
|
98
|
+
title: string_variables
|
|
99
|
+
---
|
|
100
|
+
NPC: Hello, {$player_name}! Welcome to {$location_name}.
|
|
101
|
+
NPC: Your title is {$player_title}.
|
|
102
|
+
<<set $greeting_count += 1>>
|
|
103
|
+
NPC: I've greeted you {$greeting_count} times now.
|
|
104
|
+
<<if $greeting_count >= 5>>
|
|
105
|
+
NPC: You're a regular here! Let me give you a discount.
|
|
106
|
+
<<set $stat_reputation += 10>>
|
|
107
|
+
<<endif>>
|
|
108
|
+
<<jump end>>
|
|
109
|
+
===
|
|
110
|
+
|
|
111
|
+
title: end
|
|
112
|
+
---
|
|
113
|
+
===
|
|
114
|
+
`,
|
|
115
|
+
// Add more examples here as they're converted to Yarn format
|
|
116
|
+
};
|
|
117
|
+
/**
|
|
118
|
+
* Pre-loaded examples cache
|
|
119
|
+
*/
|
|
120
|
+
let examplesCache = {};
|
|
121
|
+
/**
|
|
122
|
+
* Load all examples synchronously
|
|
123
|
+
* This should be called once at initialization
|
|
124
|
+
*/
|
|
125
|
+
function loadAllExamples() {
|
|
126
|
+
if (Object.keys(examplesCache).length > 0) {
|
|
127
|
+
return examplesCache;
|
|
128
|
+
}
|
|
129
|
+
const loaded = {};
|
|
130
|
+
for (const metadata of examples_registry_1.examplesRegistry) {
|
|
131
|
+
const yarnContent = yarnExamplesContent[metadata.id];
|
|
132
|
+
if (yarnContent) {
|
|
133
|
+
try {
|
|
134
|
+
const dialogue = (0, yarn_converter_1.importFromYarn)(yarnContent, metadata.title);
|
|
135
|
+
loaded[metadata.id] = dialogue;
|
|
136
|
+
metadata.nodeCount = Object.keys(dialogue.nodes).length;
|
|
137
|
+
}
|
|
138
|
+
catch (error) {
|
|
139
|
+
console.error(`Error loading example ${metadata.id}:`, error);
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
examplesCache = loaded;
|
|
144
|
+
return loaded;
|
|
145
|
+
}
|
|
146
|
+
// Pre-load examples when module is imported
|
|
147
|
+
loadAllExamples();
|
|
148
|
+
/**
|
|
149
|
+
* Get a loaded example dialogue
|
|
150
|
+
*/
|
|
151
|
+
function getExampleDialogue(exampleId) {
|
|
152
|
+
if (Object.keys(examplesCache).length === 0) {
|
|
153
|
+
loadAllExamples();
|
|
154
|
+
}
|
|
155
|
+
return examplesCache[exampleId] || null;
|
|
156
|
+
}
|
|
157
|
+
/**
|
|
158
|
+
* Get all loaded examples
|
|
159
|
+
*/
|
|
160
|
+
function getAllExampleDialogues() {
|
|
161
|
+
if (Object.keys(examplesCache).length === 0) {
|
|
162
|
+
loadAllExamples();
|
|
163
|
+
}
|
|
164
|
+
return examplesCache;
|
|
165
|
+
}
|
|
166
|
+
/**
|
|
167
|
+
* Get flag schema for an example
|
|
168
|
+
*/
|
|
169
|
+
function getExampleFlagSchema(exampleId) {
|
|
170
|
+
const metadata = examples_registry_1.examplesRegistry.find(ex => ex.id === exampleId);
|
|
171
|
+
if (!metadata) {
|
|
172
|
+
return null;
|
|
173
|
+
}
|
|
174
|
+
return examples_registry_1.exampleFlagSchemas[metadata.flagSchemaId] || null;
|
|
175
|
+
}
|
|
176
|
+
/**
|
|
177
|
+
* Check if an example has Yarn content available
|
|
178
|
+
*/
|
|
179
|
+
function hasExampleContent(exampleId) {
|
|
180
|
+
return exampleId in yarnExamplesContent;
|
|
181
|
+
}
|
|
182
|
+
/**
|
|
183
|
+
* Get list of example IDs that have content available
|
|
184
|
+
*/
|
|
185
|
+
function getAvailableExampleIds() {
|
|
186
|
+
return examples_registry_1.examplesRegistry
|
|
187
|
+
.filter(metadata => hasExampleContent(metadata.id))
|
|
188
|
+
.map(metadata => metadata.id);
|
|
189
|
+
}
|
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
export { DialogueEditorV2 } from './components/DialogueEditorV2';
|
|
2
|
+
export { ScenePlayer } from './components/ScenePlayer';
|
|
3
|
+
export type { ScenePlayerProps } from './components/ScenePlayer';
|
|
4
|
+
export { ScenePlayer as DialogueSimulator } from './components/ScenePlayer';
|
|
5
|
+
export { GuidePanel } from './components/GuidePanel';
|
|
6
|
+
export { FlagSelector } from './components/FlagSelector';
|
|
7
|
+
export { FlagManager } from './components/FlagManager';
|
|
8
|
+
export { ZoomControls } from './components/ZoomControls';
|
|
9
|
+
export { ExampleLoader } from './components/ExampleLoader';
|
|
10
|
+
import './styles/scrollbar.css';
|
|
11
|
+
import './styles/theme.css';
|
|
12
|
+
export { exampleDialogues, demoFlagSchemas, getExampleDialogue, getDemoFlagSchema, listExamples, listDemoFlagSchemas } from './examples';
|
|
13
|
+
export * from './types';
|
|
14
|
+
export * from './types/flags';
|
|
15
|
+
export * from './types/game-state';
|
|
16
|
+
export * from './types/constants';
|
|
17
|
+
export { flattenGameState, validateGameState, extractFlagsFromGameState, type FlattenConfig, type FlattenedState } from './utils/game-state-flattener';
|
|
18
|
+
export { exportToYarn, importFromYarn } from './lib/yarn-converter';
|
|
19
|
+
export { initializeFlags, mergeFlagUpdates, validateFlags, getFlagValue } from './lib/flag-manager';
|
|
20
|
+
export * from './utils/node-helpers';
|
|
21
|
+
export * from './utils/feature-flags';
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
14
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
15
|
+
};
|
|
16
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
17
|
+
exports.getFlagValue = exports.validateFlags = exports.mergeFlagUpdates = exports.initializeFlags = exports.importFromYarn = exports.exportToYarn = exports.extractFlagsFromGameState = exports.validateGameState = exports.flattenGameState = exports.listDemoFlagSchemas = exports.listExamples = exports.getDemoFlagSchema = exports.getExampleDialogue = exports.demoFlagSchemas = exports.exampleDialogues = exports.ExampleLoader = exports.ZoomControls = exports.FlagManager = exports.FlagSelector = exports.GuidePanel = exports.DialogueSimulator = exports.ScenePlayer = exports.DialogueEditorV2 = void 0;
|
|
18
|
+
var DialogueEditorV2_1 = require("./components/DialogueEditorV2");
|
|
19
|
+
Object.defineProperty(exports, "DialogueEditorV2", { enumerable: true, get: function () { return DialogueEditorV2_1.DialogueEditorV2; } });
|
|
20
|
+
var ScenePlayer_1 = require("./components/ScenePlayer");
|
|
21
|
+
Object.defineProperty(exports, "ScenePlayer", { enumerable: true, get: function () { return ScenePlayer_1.ScenePlayer; } });
|
|
22
|
+
// Legacy export for backward compatibility
|
|
23
|
+
var ScenePlayer_2 = require("./components/ScenePlayer");
|
|
24
|
+
Object.defineProperty(exports, "DialogueSimulator", { enumerable: true, get: function () { return ScenePlayer_2.ScenePlayer; } });
|
|
25
|
+
var GuidePanel_1 = require("./components/GuidePanel");
|
|
26
|
+
Object.defineProperty(exports, "GuidePanel", { enumerable: true, get: function () { return GuidePanel_1.GuidePanel; } });
|
|
27
|
+
var FlagSelector_1 = require("./components/FlagSelector");
|
|
28
|
+
Object.defineProperty(exports, "FlagSelector", { enumerable: true, get: function () { return FlagSelector_1.FlagSelector; } });
|
|
29
|
+
var FlagManager_1 = require("./components/FlagManager");
|
|
30
|
+
Object.defineProperty(exports, "FlagManager", { enumerable: true, get: function () { return FlagManager_1.FlagManager; } });
|
|
31
|
+
var ZoomControls_1 = require("./components/ZoomControls");
|
|
32
|
+
Object.defineProperty(exports, "ZoomControls", { enumerable: true, get: function () { return ZoomControls_1.ZoomControls; } });
|
|
33
|
+
var ExampleLoader_1 = require("./components/ExampleLoader");
|
|
34
|
+
Object.defineProperty(exports, "ExampleLoader", { enumerable: true, get: function () { return ExampleLoader_1.ExampleLoader; } });
|
|
35
|
+
// Export styles
|
|
36
|
+
require("./styles/scrollbar.css");
|
|
37
|
+
require("./styles/theme.css");
|
|
38
|
+
// Export examples
|
|
39
|
+
var examples_1 = require("./examples");
|
|
40
|
+
Object.defineProperty(exports, "exampleDialogues", { enumerable: true, get: function () { return examples_1.exampleDialogues; } });
|
|
41
|
+
Object.defineProperty(exports, "demoFlagSchemas", { enumerable: true, get: function () { return examples_1.demoFlagSchemas; } });
|
|
42
|
+
Object.defineProperty(exports, "getExampleDialogue", { enumerable: true, get: function () { return examples_1.getExampleDialogue; } });
|
|
43
|
+
Object.defineProperty(exports, "getDemoFlagSchema", { enumerable: true, get: function () { return examples_1.getDemoFlagSchema; } });
|
|
44
|
+
Object.defineProperty(exports, "listExamples", { enumerable: true, get: function () { return examples_1.listExamples; } });
|
|
45
|
+
Object.defineProperty(exports, "listDemoFlagSchemas", { enumerable: true, get: function () { return examples_1.listDemoFlagSchemas; } });
|
|
46
|
+
// Export all types
|
|
47
|
+
__exportStar(require("./types"), exports);
|
|
48
|
+
__exportStar(require("./types/flags"), exports);
|
|
49
|
+
__exportStar(require("./types/game-state"), exports);
|
|
50
|
+
__exportStar(require("./types/constants"), exports);
|
|
51
|
+
// Export game state utilities
|
|
52
|
+
var game_state_flattener_1 = require("./utils/game-state-flattener");
|
|
53
|
+
Object.defineProperty(exports, "flattenGameState", { enumerable: true, get: function () { return game_state_flattener_1.flattenGameState; } });
|
|
54
|
+
Object.defineProperty(exports, "validateGameState", { enumerable: true, get: function () { return game_state_flattener_1.validateGameState; } });
|
|
55
|
+
Object.defineProperty(exports, "extractFlagsFromGameState", { enumerable: true, get: function () { return game_state_flattener_1.extractFlagsFromGameState; } });
|
|
56
|
+
// Export utilities
|
|
57
|
+
var yarn_converter_1 = require("./lib/yarn-converter");
|
|
58
|
+
Object.defineProperty(exports, "exportToYarn", { enumerable: true, get: function () { return yarn_converter_1.exportToYarn; } });
|
|
59
|
+
Object.defineProperty(exports, "importFromYarn", { enumerable: true, get: function () { return yarn_converter_1.importFromYarn; } });
|
|
60
|
+
var flag_manager_1 = require("./lib/flag-manager");
|
|
61
|
+
Object.defineProperty(exports, "initializeFlags", { enumerable: true, get: function () { return flag_manager_1.initializeFlags; } });
|
|
62
|
+
Object.defineProperty(exports, "mergeFlagUpdates", { enumerable: true, get: function () { return flag_manager_1.mergeFlagUpdates; } });
|
|
63
|
+
Object.defineProperty(exports, "validateFlags", { enumerable: true, get: function () { return flag_manager_1.validateFlags; } });
|
|
64
|
+
Object.defineProperty(exports, "getFlagValue", { enumerable: true, get: function () { return flag_manager_1.getFlagValue; } });
|
|
65
|
+
__exportStar(require("./utils/node-helpers"), exports);
|
|
66
|
+
__exportStar(require("./utils/feature-flags"), exports);
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import { GameFlagState } from '../types/game-state';
|
|
2
|
+
import { FlagSchema } from '../types/flags';
|
|
3
|
+
/**
|
|
4
|
+
* Initialize game flags from schema with default values
|
|
5
|
+
*/
|
|
6
|
+
export declare function initializeFlags(schema: FlagSchema): GameFlagState;
|
|
7
|
+
/**
|
|
8
|
+
* Merge current flags with updates from dialogue
|
|
9
|
+
*/
|
|
10
|
+
export declare function mergeFlagUpdates(currentFlags: GameFlagState, updates: string[], schema?: FlagSchema): GameFlagState;
|
|
11
|
+
/**
|
|
12
|
+
* Validate flags against schema
|
|
13
|
+
*/
|
|
14
|
+
export declare function validateFlags(flags: GameFlagState, schema: FlagSchema): {
|
|
15
|
+
valid: boolean;
|
|
16
|
+
errors: string[];
|
|
17
|
+
};
|
|
18
|
+
/**
|
|
19
|
+
* Get flag value with type safety
|
|
20
|
+
*/
|
|
21
|
+
export declare function getFlagValue(flags: GameFlagState, flagId: string, defaultValue?: boolean | number | string): boolean | number | string;
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.initializeFlags = initializeFlags;
|
|
4
|
+
exports.mergeFlagUpdates = mergeFlagUpdates;
|
|
5
|
+
exports.validateFlags = validateFlags;
|
|
6
|
+
exports.getFlagValue = getFlagValue;
|
|
7
|
+
const constants_1 = require("../types/constants");
|
|
8
|
+
/**
|
|
9
|
+
* Initialize game flags from schema with default values
|
|
10
|
+
*/
|
|
11
|
+
function initializeFlags(schema) {
|
|
12
|
+
const flags = {};
|
|
13
|
+
schema.flags.forEach(flag => {
|
|
14
|
+
if (flag.defaultValue !== undefined) {
|
|
15
|
+
flags[flag.id] = flag.defaultValue;
|
|
16
|
+
}
|
|
17
|
+
else if (flag.valueType === 'number') {
|
|
18
|
+
flags[flag.id] = 0;
|
|
19
|
+
}
|
|
20
|
+
else if (flag.valueType === 'string') {
|
|
21
|
+
flags[flag.id] = '';
|
|
22
|
+
}
|
|
23
|
+
else {
|
|
24
|
+
flags[flag.id] = false;
|
|
25
|
+
}
|
|
26
|
+
});
|
|
27
|
+
return flags;
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* Merge current flags with updates from dialogue
|
|
31
|
+
*/
|
|
32
|
+
function mergeFlagUpdates(currentFlags, updates, schema) {
|
|
33
|
+
const newFlags = { ...currentFlags };
|
|
34
|
+
updates.forEach(flagId => {
|
|
35
|
+
const flagDef = schema?.flags.find(f => f.id === flagId);
|
|
36
|
+
if (flagDef) {
|
|
37
|
+
// Use default value or increment if number
|
|
38
|
+
if (flagDef.valueType === 'number' && typeof newFlags[flagId] === 'number') {
|
|
39
|
+
newFlags[flagId] = newFlags[flagId] + 1;
|
|
40
|
+
}
|
|
41
|
+
else if (flagDef.valueType === constants_1.FLAG_VALUE_TYPE.STRING) {
|
|
42
|
+
// For string flags, use smart defaults based on type
|
|
43
|
+
if (flagDef.type === constants_1.FLAG_TYPE.QUEST) {
|
|
44
|
+
// Quest flags: if not set, mark as "started", otherwise keep current value
|
|
45
|
+
newFlags[flagId] = newFlags[flagId] || 'started';
|
|
46
|
+
}
|
|
47
|
+
else {
|
|
48
|
+
// Other string flags: use default or empty string
|
|
49
|
+
newFlags[flagId] = flagDef.defaultValue !== undefined ? flagDef.defaultValue : '';
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
else if (flagDef.defaultValue !== undefined) {
|
|
53
|
+
newFlags[flagId] = flagDef.defaultValue;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
newFlags[flagId] = true;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
else {
|
|
60
|
+
// Default to true if not in schema
|
|
61
|
+
newFlags[flagId] = true;
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
return newFlags;
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Validate flags against schema
|
|
68
|
+
*/
|
|
69
|
+
function validateFlags(flags, schema) {
|
|
70
|
+
const errors = [];
|
|
71
|
+
Object.keys(flags).forEach(flagId => {
|
|
72
|
+
const flagDef = schema.flags.find(f => f.id === flagId);
|
|
73
|
+
if (!flagDef) {
|
|
74
|
+
errors.push(`Unknown flag: ${flagId}`);
|
|
75
|
+
}
|
|
76
|
+
else if (flagDef.valueType) {
|
|
77
|
+
const value = flags[flagId];
|
|
78
|
+
if (flagDef.valueType === constants_1.FLAG_VALUE_TYPE.NUMBER && typeof value !== 'number') {
|
|
79
|
+
errors.push(`Flag ${flagId} should be a number, got ${typeof value}`);
|
|
80
|
+
}
|
|
81
|
+
else if (flagDef.valueType === constants_1.FLAG_VALUE_TYPE.STRING && typeof value !== 'string') {
|
|
82
|
+
errors.push(`Flag ${flagId} should be a string, got ${typeof value}`);
|
|
83
|
+
}
|
|
84
|
+
else if (flagDef.valueType === constants_1.FLAG_VALUE_TYPE.BOOLEAN && typeof value !== 'boolean') {
|
|
85
|
+
errors.push(`Flag ${flagId} should be a boolean, got ${typeof value}`);
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
});
|
|
89
|
+
return {
|
|
90
|
+
valid: errors.length === 0,
|
|
91
|
+
errors
|
|
92
|
+
};
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Get flag value with type safety
|
|
96
|
+
*/
|
|
97
|
+
function getFlagValue(flags, flagId, defaultValue) {
|
|
98
|
+
return flags[flagId] ?? defaultValue ?? false;
|
|
99
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,171 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const yarn_converter_1 = require("../../yarn-converter");
|
|
5
|
+
/**
|
|
6
|
+
* Test round-trip conversion: Yarn → DialogueTree → Yarn
|
|
7
|
+
* This ensures we can import and export without data loss
|
|
8
|
+
*/
|
|
9
|
+
(0, vitest_1.describe)('Yarn Round-Trip Conversion', () => {
|
|
10
|
+
const testCases = [
|
|
11
|
+
{
|
|
12
|
+
name: 'Basic dialogue with choices',
|
|
13
|
+
yarn: `title: start
|
|
14
|
+
---
|
|
15
|
+
NPC: Hello! How can I help you?
|
|
16
|
+
-> Option 1
|
|
17
|
+
<<jump option1>>
|
|
18
|
+
-> Option 2
|
|
19
|
+
<<jump option2>>
|
|
20
|
+
===
|
|
21
|
+
|
|
22
|
+
title: option1
|
|
23
|
+
---
|
|
24
|
+
NPC: You chose option 1!
|
|
25
|
+
===
|
|
26
|
+
|
|
27
|
+
title: option2
|
|
28
|
+
---
|
|
29
|
+
NPC: You chose option 2!
|
|
30
|
+
===
|
|
31
|
+
`
|
|
32
|
+
},
|
|
33
|
+
{
|
|
34
|
+
name: 'Dialogue with flags',
|
|
35
|
+
yarn: `title: start
|
|
36
|
+
---
|
|
37
|
+
NPC: Welcome!
|
|
38
|
+
<<set $flag1 = true>>
|
|
39
|
+
<<set $flag2 = true>>
|
|
40
|
+
-> Continue
|
|
41
|
+
<<set $flag3 = true>>
|
|
42
|
+
<<jump next>>
|
|
43
|
+
===
|
|
44
|
+
|
|
45
|
+
title: next
|
|
46
|
+
---
|
|
47
|
+
NPC: Flags have been set!
|
|
48
|
+
===
|
|
49
|
+
`
|
|
50
|
+
},
|
|
51
|
+
{
|
|
52
|
+
name: 'Conditional blocks',
|
|
53
|
+
yarn: `title: start
|
|
54
|
+
---
|
|
55
|
+
<<if $has_key>>
|
|
56
|
+
Guard: The door is unlocked.
|
|
57
|
+
<<else>>
|
|
58
|
+
Guard: The door is locked.
|
|
59
|
+
<<endif>>
|
|
60
|
+
===
|
|
61
|
+
`
|
|
62
|
+
},
|
|
63
|
+
{
|
|
64
|
+
name: 'Variable operations',
|
|
65
|
+
yarn: `title: merchant
|
|
66
|
+
---
|
|
67
|
+
Merchant: You have {$stat_gold} gold.
|
|
68
|
+
<<set $stat_gold += 100>>
|
|
69
|
+
Merchant: Now you have {$stat_gold} gold!
|
|
70
|
+
-> Buy item
|
|
71
|
+
<<set $stat_gold -= 50>>
|
|
72
|
+
<<set $item_sword = true>>
|
|
73
|
+
Merchant: You bought a sword! You have {$stat_gold} gold left.
|
|
74
|
+
<<jump end>>
|
|
75
|
+
===
|
|
76
|
+
|
|
77
|
+
title: end
|
|
78
|
+
---
|
|
79
|
+
===
|
|
80
|
+
`
|
|
81
|
+
},
|
|
82
|
+
{
|
|
83
|
+
name: 'Complex conditional with multiple blocks',
|
|
84
|
+
yarn: `title: start
|
|
85
|
+
---
|
|
86
|
+
<<if $stat_gold >= 100>>
|
|
87
|
+
Merchant: You can afford the sword!
|
|
88
|
+
<<elseif $stat_gold >= 50>>
|
|
89
|
+
Merchant: You can afford the potion!
|
|
90
|
+
<<else>>
|
|
91
|
+
Merchant: You don't have enough gold.
|
|
92
|
+
<<endif>>
|
|
93
|
+
===
|
|
94
|
+
`
|
|
95
|
+
}
|
|
96
|
+
];
|
|
97
|
+
testCases.forEach(({ name, yarn }) => {
|
|
98
|
+
(0, vitest_1.it)(`should round-trip: ${name}`, () => {
|
|
99
|
+
// Import Yarn to DialogueTree
|
|
100
|
+
const dialogue = (0, yarn_converter_1.importFromYarn)(yarn, 'Test Dialogue');
|
|
101
|
+
// Export DialogueTree back to Yarn
|
|
102
|
+
const exportedYarn = (0, yarn_converter_1.exportToYarn)(dialogue);
|
|
103
|
+
// Import the exported Yarn again
|
|
104
|
+
const reimportedDialogue = (0, yarn_converter_1.importFromYarn)(exportedYarn, 'Test Dialogue');
|
|
105
|
+
// Verify structure is preserved
|
|
106
|
+
(0, vitest_1.expect)(reimportedDialogue.nodes).toBeDefined();
|
|
107
|
+
(0, vitest_1.expect)(Object.keys(reimportedDialogue.nodes).length).toBeGreaterThan(0);
|
|
108
|
+
// Verify all nodes are present
|
|
109
|
+
const originalNodeIds = Object.keys(dialogue.nodes);
|
|
110
|
+
const reimportedNodeIds = Object.keys(reimportedDialogue.nodes);
|
|
111
|
+
(0, vitest_1.expect)(reimportedNodeIds.length).toBe(originalNodeIds.length);
|
|
112
|
+
// Verify node types are preserved
|
|
113
|
+
originalNodeIds.forEach(nodeId => {
|
|
114
|
+
const original = dialogue.nodes[nodeId];
|
|
115
|
+
const reimported = reimportedDialogue.nodes[nodeId];
|
|
116
|
+
(0, vitest_1.expect)(reimported).toBeDefined();
|
|
117
|
+
(0, vitest_1.expect)(reimported.type).toBe(original.type);
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
(0, vitest_1.it)('should preserve variable operations', () => {
|
|
122
|
+
const yarn = `title: test
|
|
123
|
+
---
|
|
124
|
+
NPC: Test
|
|
125
|
+
<<set $stat_gold += 100>>
|
|
126
|
+
<<set $stat_gold -= 50>>
|
|
127
|
+
<<set $stat_strength *= 2>>
|
|
128
|
+
===
|
|
129
|
+
`;
|
|
130
|
+
const dialogue = (0, yarn_converter_1.importFromYarn)(yarn, 'Test');
|
|
131
|
+
const exported = (0, yarn_converter_1.exportToYarn)(dialogue);
|
|
132
|
+
// Verify operations are in exported Yarn
|
|
133
|
+
(0, vitest_1.expect)(exported).toContain('<<set $stat_gold += 100>>');
|
|
134
|
+
(0, vitest_1.expect)(exported).toContain('<<set $stat_gold -= 50>>');
|
|
135
|
+
(0, vitest_1.expect)(exported).toContain('<<set $stat_strength *= 2>>');
|
|
136
|
+
});
|
|
137
|
+
(0, vitest_1.it)('should preserve variable interpolation', () => {
|
|
138
|
+
const yarn = `title: test
|
|
139
|
+
---
|
|
140
|
+
NPC: Hello {$player_name}! You have {$stat_gold} gold.
|
|
141
|
+
===
|
|
142
|
+
`;
|
|
143
|
+
const dialogue = (0, yarn_converter_1.importFromYarn)(yarn, 'Test');
|
|
144
|
+
const exported = (0, yarn_converter_1.exportToYarn)(dialogue);
|
|
145
|
+
// Variable interpolation should be preserved in content
|
|
146
|
+
(0, vitest_1.expect)(dialogue.nodes.test.content).toContain('{$player_name}');
|
|
147
|
+
(0, vitest_1.expect)(dialogue.nodes.test.content).toContain('{$stat_gold}');
|
|
148
|
+
});
|
|
149
|
+
(0, vitest_1.it)('should preserve conditional choices', () => {
|
|
150
|
+
const yarn = `title: start
|
|
151
|
+
---
|
|
152
|
+
<<if $has_key>>
|
|
153
|
+
-> Use key
|
|
154
|
+
<<jump unlocked>>
|
|
155
|
+
<<endif>>
|
|
156
|
+
-> Try to force
|
|
157
|
+
<<jump forced>>
|
|
158
|
+
===
|
|
159
|
+
`;
|
|
160
|
+
const dialogue = (0, yarn_converter_1.importFromYarn)(yarn, 'Test');
|
|
161
|
+
const exported = (0, yarn_converter_1.exportToYarn)(dialogue);
|
|
162
|
+
// Verify conditional choice structure
|
|
163
|
+
const playerNode = dialogue.nodes.start;
|
|
164
|
+
(0, vitest_1.expect)(playerNode.type).toBe('player');
|
|
165
|
+
(0, vitest_1.expect)(playerNode.choices).toBeDefined();
|
|
166
|
+
(0, vitest_1.expect)(playerNode.choices.length).toBeGreaterThan(0);
|
|
167
|
+
// Verify conditions are exported
|
|
168
|
+
(0, vitest_1.expect)(exported).toContain('<<if');
|
|
169
|
+
(0, vitest_1.expect)(exported).toContain('<<endif>>');
|
|
170
|
+
});
|
|
171
|
+
});
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { DialogueTree } from '../types';
|
|
2
|
+
/**
|
|
3
|
+
* Convert DialogueTree to Yarn Spinner format
|
|
4
|
+
*
|
|
5
|
+
* Flags are converted to Yarn variables ($variable).
|
|
6
|
+
* Variables are NOT stored in the .yarn file - they're managed by
|
|
7
|
+
* Yarn Spinner's Variable Storage at runtime.
|
|
8
|
+
*
|
|
9
|
+
* The .yarn file contains commands like:
|
|
10
|
+
* - <<set $flag_name = value>> - Sets variable in Variable Storage
|
|
11
|
+
* - <<if $flag_name>> - Checks variable in Variable Storage
|
|
12
|
+
*/
|
|
13
|
+
export declare function exportToYarn(tree: DialogueTree): string;
|
|
14
|
+
/**
|
|
15
|
+
* Parse Yarn Spinner format to DialogueTree
|
|
16
|
+
*/
|
|
17
|
+
export declare function importFromYarn(yarnContent: string, title?: string): DialogueTree;
|