@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.
Files changed (241) hide show
  1. package/README.md +233 -0
  2. package/bin/dialogue-forge.js +78 -0
  3. package/demo/app/layout.tsx +36 -0
  4. package/demo/app/page.tsx +440 -0
  5. package/demo/components/ThemeSwitcher.tsx +611 -0
  6. package/demo/next.config.mjs +7 -0
  7. package/demo/package.json +29 -0
  8. package/demo/postcss.config.mjs +7 -0
  9. package/demo/public/logo.svg +1 -0
  10. package/demo/styles/globals.css +19 -0
  11. package/demo/tailwind.config.ts +90 -0
  12. package/demo/tsconfig.json +42 -0
  13. package/dist/components/ChoiceEdgeV2.d.ts +3 -0
  14. package/dist/components/ChoiceEdgeV2.js +103 -0
  15. package/dist/components/CodeBlock.d.ts +8 -0
  16. package/dist/components/CodeBlock.js +24 -0
  17. package/dist/components/ConditionAutocomplete.d.ts +14 -0
  18. package/dist/components/ConditionAutocomplete.js +284 -0
  19. package/dist/components/ConditionalNodeV2.d.ts +16 -0
  20. package/dist/components/ConditionalNodeV2.js +147 -0
  21. package/dist/components/DialogueEditorV2.d.ts +22 -0
  22. package/dist/components/DialogueEditorV2.js +1170 -0
  23. package/dist/components/EdgeIcon.d.ts +8 -0
  24. package/dist/components/EdgeIcon.js +13 -0
  25. package/dist/components/ExampleLoader.d.ts +11 -0
  26. package/dist/components/ExampleLoader.js +52 -0
  27. package/dist/components/ExampleLoaderButton.d.ts +15 -0
  28. package/dist/components/ExampleLoaderButton.js +102 -0
  29. package/dist/components/FlagManager.d.ts +11 -0
  30. package/dist/components/FlagManager.js +282 -0
  31. package/dist/components/FlagSelector.d.ts +11 -0
  32. package/dist/components/FlagSelector.js +235 -0
  33. package/dist/components/GuidePanel.d.ts +7 -0
  34. package/dist/components/GuidePanel.js +1176 -0
  35. package/dist/components/Minimap.d.ts +16 -0
  36. package/dist/components/Minimap.js +93 -0
  37. package/dist/components/NPCEdgeV2.d.ts +3 -0
  38. package/dist/components/NPCEdgeV2.js +104 -0
  39. package/dist/components/NPCNodeV2.d.ts +26 -0
  40. package/dist/components/NPCNodeV2.js +86 -0
  41. package/dist/components/NodeEditor.d.ts +18 -0
  42. package/dist/components/NodeEditor.js +1025 -0
  43. package/dist/components/PlayView.d.ts +12 -0
  44. package/dist/components/PlayView.js +307 -0
  45. package/dist/components/PlayerNodeV2.d.ts +16 -0
  46. package/dist/components/PlayerNodeV2.js +139 -0
  47. package/dist/components/ReactFlowPOC.d.ts +61 -0
  48. package/dist/components/ReactFlowPOC.js +312 -0
  49. package/dist/components/ScenePlayer.d.ts +18 -0
  50. package/dist/components/ScenePlayer.js +196 -0
  51. package/dist/components/YarnView.d.ts +9 -0
  52. package/dist/components/YarnView.js +45 -0
  53. package/dist/components/ZoomControls.d.ts +11 -0
  54. package/dist/components/ZoomControls.js +34 -0
  55. package/dist/esm/components/ChoiceEdgeV2.d.ts +3 -0
  56. package/dist/esm/components/ChoiceEdgeV2.js +67 -0
  57. package/dist/esm/components/CodeBlock.d.ts +8 -0
  58. package/dist/esm/components/CodeBlock.js +18 -0
  59. package/dist/esm/components/ConditionAutocomplete.d.ts +14 -0
  60. package/dist/esm/components/ConditionAutocomplete.js +248 -0
  61. package/dist/esm/components/ConditionalNodeV2.d.ts +16 -0
  62. package/dist/esm/components/ConditionalNodeV2.js +111 -0
  63. package/dist/esm/components/DialogueEditorV2.d.ts +22 -0
  64. package/dist/esm/components/DialogueEditorV2.js +1134 -0
  65. package/dist/esm/components/EdgeIcon.d.ts +8 -0
  66. package/dist/esm/components/EdgeIcon.js +7 -0
  67. package/dist/esm/components/ExampleLoader.d.ts +11 -0
  68. package/dist/esm/components/ExampleLoader.js +46 -0
  69. package/dist/esm/components/ExampleLoaderButton.d.ts +15 -0
  70. package/dist/esm/components/ExampleLoaderButton.js +66 -0
  71. package/dist/esm/components/FlagManager.d.ts +11 -0
  72. package/dist/esm/components/FlagManager.js +246 -0
  73. package/dist/esm/components/FlagSelector.d.ts +11 -0
  74. package/dist/esm/components/FlagSelector.js +199 -0
  75. package/dist/esm/components/GuidePanel.d.ts +7 -0
  76. package/dist/esm/components/GuidePanel.js +1140 -0
  77. package/dist/esm/components/Minimap.d.ts +16 -0
  78. package/dist/esm/components/Minimap.js +57 -0
  79. package/dist/esm/components/NPCEdgeV2.d.ts +3 -0
  80. package/dist/esm/components/NPCEdgeV2.js +68 -0
  81. package/dist/esm/components/NPCNodeV2.d.ts +26 -0
  82. package/dist/esm/components/NPCNodeV2.js +80 -0
  83. package/dist/esm/components/NodeEditor.d.ts +18 -0
  84. package/dist/esm/components/NodeEditor.js +989 -0
  85. package/dist/esm/components/PlayView.d.ts +12 -0
  86. package/dist/esm/components/PlayView.js +271 -0
  87. package/dist/esm/components/PlayerNodeV2.d.ts +16 -0
  88. package/dist/esm/components/PlayerNodeV2.js +103 -0
  89. package/dist/esm/components/ReactFlowPOC.d.ts +61 -0
  90. package/dist/esm/components/ReactFlowPOC.js +275 -0
  91. package/dist/esm/components/ScenePlayer.d.ts +18 -0
  92. package/dist/esm/components/ScenePlayer.js +160 -0
  93. package/dist/esm/components/YarnView.d.ts +9 -0
  94. package/dist/esm/components/YarnView.js +39 -0
  95. package/dist/esm/components/ZoomControls.d.ts +11 -0
  96. package/dist/esm/components/ZoomControls.js +28 -0
  97. package/dist/esm/examples/example-loader.d.ts +29 -0
  98. package/dist/esm/examples/example-loader.js +103 -0
  99. package/dist/esm/examples/examples-registry.d.ts +38 -0
  100. package/dist/esm/examples/examples-registry.js +153 -0
  101. package/dist/esm/examples/index.d.ts +26 -0
  102. package/dist/esm/examples/index.js +50 -0
  103. package/dist/esm/examples/legacy-examples.d.ts +9 -0
  104. package/dist/esm/examples/legacy-examples.js +814 -0
  105. package/dist/esm/examples/yarn-examples.d.ts +35 -0
  106. package/dist/esm/examples/yarn-examples.js +181 -0
  107. package/dist/esm/index.d.ts +21 -0
  108. package/dist/esm/index.js +26 -0
  109. package/dist/esm/lib/flag-manager.d.ts +21 -0
  110. package/dist/esm/lib/flag-manager.js +93 -0
  111. package/dist/esm/lib/yarn-converter/__tests__/round-trip.test.d.ts +1 -0
  112. package/dist/esm/lib/yarn-converter/__tests__/round-trip.test.js +169 -0
  113. package/dist/esm/lib/yarn-converter.d.ts +17 -0
  114. package/dist/esm/lib/yarn-converter.js +521 -0
  115. package/dist/esm/lib/yarn-runner/__tests__/condition-evaluator.test.d.ts +1 -0
  116. package/dist/esm/lib/yarn-runner/__tests__/condition-evaluator.test.js +171 -0
  117. package/dist/esm/lib/yarn-runner/__tests__/node-processor.test.d.ts +1 -0
  118. package/dist/esm/lib/yarn-runner/__tests__/node-processor.test.js +237 -0
  119. package/dist/esm/lib/yarn-runner/__tests__/variable-manager.test.d.ts +1 -0
  120. package/dist/esm/lib/yarn-runner/__tests__/variable-manager.test.js +106 -0
  121. package/dist/esm/lib/yarn-runner/condition-evaluator.d.ts +12 -0
  122. package/dist/esm/lib/yarn-runner/condition-evaluator.js +56 -0
  123. package/dist/esm/lib/yarn-runner/index.d.ts +12 -0
  124. package/dist/esm/lib/yarn-runner/index.js +11 -0
  125. package/dist/esm/lib/yarn-runner/node-processor.d.ts +18 -0
  126. package/dist/esm/lib/yarn-runner/node-processor.js +129 -0
  127. package/dist/esm/lib/yarn-runner/variable-manager.d.ts +51 -0
  128. package/dist/esm/lib/yarn-runner/variable-manager.js +120 -0
  129. package/dist/esm/lib/yarn-runner/variable-operations.d.ts +16 -0
  130. package/dist/esm/lib/yarn-runner/variable-operations.js +88 -0
  131. package/dist/esm/types/conditionals.d.ts +29 -0
  132. package/dist/esm/types/conditionals.js +1 -0
  133. package/dist/esm/types/constants.d.ts +59 -0
  134. package/dist/esm/types/constants.js +55 -0
  135. package/dist/esm/types/flags.d.ts +49 -0
  136. package/dist/esm/types/flags.js +49 -0
  137. package/dist/esm/types/game-state.d.ts +62 -0
  138. package/dist/esm/types/game-state.js +6 -0
  139. package/dist/esm/types/index.d.ts +77 -0
  140. package/dist/esm/types/index.js +1 -0
  141. package/dist/esm/utils/constants.d.ts +5 -0
  142. package/dist/esm/utils/constants.js +5 -0
  143. package/dist/esm/utils/feature-flags.d.ts +11 -0
  144. package/dist/esm/utils/feature-flags.js +11 -0
  145. package/dist/esm/utils/game-state-flattener.d.ts +41 -0
  146. package/dist/esm/utils/game-state-flattener.js +135 -0
  147. package/dist/esm/utils/layout/collision.d.ts +27 -0
  148. package/dist/esm/utils/layout/collision.js +74 -0
  149. package/dist/esm/utils/layout/index.d.ts +82 -0
  150. package/dist/esm/utils/layout/index.js +98 -0
  151. package/dist/esm/utils/layout/registry.d.ts +91 -0
  152. package/dist/esm/utils/layout/registry.js +148 -0
  153. package/dist/esm/utils/layout/strategies/dagre.d.ts +19 -0
  154. package/dist/esm/utils/layout/strategies/dagre.js +182 -0
  155. package/dist/esm/utils/layout/strategies/force.d.ts +21 -0
  156. package/dist/esm/utils/layout/strategies/force.js +178 -0
  157. package/dist/esm/utils/layout/strategies/grid.d.ts +17 -0
  158. package/dist/esm/utils/layout/strategies/grid.js +91 -0
  159. package/dist/esm/utils/layout/strategies/index.d.ts +8 -0
  160. package/dist/esm/utils/layout/strategies/index.js +8 -0
  161. package/dist/esm/utils/layout/types.d.ts +100 -0
  162. package/dist/esm/utils/layout/types.js +7 -0
  163. package/dist/esm/utils/layout.d.ts +9 -0
  164. package/dist/esm/utils/layout.js +17 -0
  165. package/dist/esm/utils/node-helpers.d.ts +7 -0
  166. package/dist/esm/utils/node-helpers.js +94 -0
  167. package/dist/esm/utils/reactflow-converter.d.ts +42 -0
  168. package/dist/esm/utils/reactflow-converter.js +217 -0
  169. package/dist/examples/example-loader.d.ts +29 -0
  170. package/dist/examples/example-loader.js +109 -0
  171. package/dist/examples/examples-registry.d.ts +38 -0
  172. package/dist/examples/examples-registry.js +160 -0
  173. package/dist/examples/index.d.ts +26 -0
  174. package/dist/examples/index.js +63 -0
  175. package/dist/examples/legacy-examples.d.ts +9 -0
  176. package/dist/examples/legacy-examples.js +817 -0
  177. package/dist/examples/yarn-examples.d.ts +35 -0
  178. package/dist/examples/yarn-examples.js +189 -0
  179. package/dist/index.d.ts +21 -0
  180. package/dist/index.js +66 -0
  181. package/dist/lib/flag-manager.d.ts +21 -0
  182. package/dist/lib/flag-manager.js +99 -0
  183. package/dist/lib/yarn-converter/__tests__/round-trip.test.d.ts +1 -0
  184. package/dist/lib/yarn-converter/__tests__/round-trip.test.js +171 -0
  185. package/dist/lib/yarn-converter.d.ts +17 -0
  186. package/dist/lib/yarn-converter.js +525 -0
  187. package/dist/lib/yarn-runner/__tests__/condition-evaluator.test.d.ts +1 -0
  188. package/dist/lib/yarn-runner/__tests__/condition-evaluator.test.js +173 -0
  189. package/dist/lib/yarn-runner/__tests__/node-processor.test.d.ts +1 -0
  190. package/dist/lib/yarn-runner/__tests__/node-processor.test.js +239 -0
  191. package/dist/lib/yarn-runner/__tests__/variable-manager.test.d.ts +1 -0
  192. package/dist/lib/yarn-runner/__tests__/variable-manager.test.js +108 -0
  193. package/dist/lib/yarn-runner/condition-evaluator.d.ts +12 -0
  194. package/dist/lib/yarn-runner/condition-evaluator.js +60 -0
  195. package/dist/lib/yarn-runner/index.d.ts +12 -0
  196. package/dist/lib/yarn-runner/index.js +21 -0
  197. package/dist/lib/yarn-runner/node-processor.d.ts +18 -0
  198. package/dist/lib/yarn-runner/node-processor.js +133 -0
  199. package/dist/lib/yarn-runner/variable-manager.d.ts +51 -0
  200. package/dist/lib/yarn-runner/variable-manager.js +124 -0
  201. package/dist/lib/yarn-runner/variable-operations.d.ts +16 -0
  202. package/dist/lib/yarn-runner/variable-operations.js +92 -0
  203. package/dist/types/conditionals.d.ts +29 -0
  204. package/dist/types/conditionals.js +2 -0
  205. package/dist/types/constants.d.ts +59 -0
  206. package/dist/types/constants.js +58 -0
  207. package/dist/types/flags.d.ts +49 -0
  208. package/dist/types/flags.js +52 -0
  209. package/dist/types/game-state.d.ts +62 -0
  210. package/dist/types/game-state.js +7 -0
  211. package/dist/types/index.d.ts +77 -0
  212. package/dist/types/index.js +2 -0
  213. package/dist/utils/constants.d.ts +5 -0
  214. package/dist/utils/constants.js +8 -0
  215. package/dist/utils/feature-flags.d.ts +11 -0
  216. package/dist/utils/feature-flags.js +14 -0
  217. package/dist/utils/game-state-flattener.d.ts +41 -0
  218. package/dist/utils/game-state-flattener.js +140 -0
  219. package/dist/utils/layout/collision.d.ts +27 -0
  220. package/dist/utils/layout/collision.js +77 -0
  221. package/dist/utils/layout/index.d.ts +82 -0
  222. package/dist/utils/layout/index.js +109 -0
  223. package/dist/utils/layout/registry.d.ts +91 -0
  224. package/dist/utils/layout/registry.js +151 -0
  225. package/dist/utils/layout/strategies/dagre.d.ts +19 -0
  226. package/dist/utils/layout/strategies/dagre.js +189 -0
  227. package/dist/utils/layout/strategies/force.d.ts +21 -0
  228. package/dist/utils/layout/strategies/force.js +182 -0
  229. package/dist/utils/layout/strategies/grid.d.ts +17 -0
  230. package/dist/utils/layout/strategies/grid.js +95 -0
  231. package/dist/utils/layout/strategies/index.d.ts +8 -0
  232. package/dist/utils/layout/strategies/index.js +14 -0
  233. package/dist/utils/layout/types.d.ts +100 -0
  234. package/dist/utils/layout/types.js +8 -0
  235. package/dist/utils/layout.d.ts +9 -0
  236. package/dist/utils/layout.js +25 -0
  237. package/dist/utils/node-helpers.d.ts +7 -0
  238. package/dist/utils/node-helpers.js +101 -0
  239. package/dist/utils/reactflow-converter.d.ts +42 -0
  240. package/dist/utils/reactflow-converter.js +223 -0
  241. package/package.json +70 -0
@@ -0,0 +1,103 @@
1
+ import { importFromYarn } from '../lib/yarn-converter';
2
+ import { examplesRegistry, getExampleMetadata, getExampleFlagSchema } from './examples-registry';
3
+ /**
4
+ * Load an example dialogue from a Yarn file
5
+ * This is the unified way to load examples - all examples are Yarn files
6
+ */
7
+ export async function loadExampleDialogue(exampleId) {
8
+ const metadata = getExampleMetadata(exampleId);
9
+ if (!metadata) {
10
+ console.warn(`Example not found: ${exampleId}`);
11
+ return null;
12
+ }
13
+ try {
14
+ // Dynamically import the Yarn file
15
+ // In a build environment, these will be bundled
16
+ // In Node.js/test environment, we'll read from filesystem
17
+ const yarnContent = await loadYarnFile(metadata.filename);
18
+ if (!yarnContent) {
19
+ console.warn(`Failed to load Yarn file: ${metadata.filename}`);
20
+ return null;
21
+ }
22
+ // Convert Yarn to DialogueTree
23
+ const dialogue = importFromYarn(yarnContent, metadata.title);
24
+ // Update node count in metadata if not set
25
+ if (!metadata.nodeCount) {
26
+ metadata.nodeCount = Object.keys(dialogue.nodes).length;
27
+ }
28
+ return dialogue;
29
+ }
30
+ catch (error) {
31
+ console.error(`Error loading example ${exampleId}:`, error);
32
+ return null;
33
+ }
34
+ }
35
+ /**
36
+ * Load Yarn file content
37
+ * This handles both browser (bundled) and Node.js (filesystem) environments
38
+ */
39
+ async function loadYarnFile(filename) {
40
+ // In browser/build environment, we'll need to import as text
41
+ // For now, we'll use a simple approach that works in both
42
+ try {
43
+ // Try to import as a module (works in bundlers like Vite/Webpack)
44
+ if (typeof window !== 'undefined') {
45
+ // Browser environment - files should be imported as text
46
+ // This will be handled by the bundler configuration
47
+ const response = await fetch(`/examples/${filename}`);
48
+ if (response.ok) {
49
+ return await response.text();
50
+ }
51
+ }
52
+ // Node.js/test environment - read from filesystem
53
+ if (typeof require !== 'undefined') {
54
+ const fs = require('fs');
55
+ const path = require('path');
56
+ const filePath = path.join(__dirname, filename);
57
+ if (fs.existsSync(filePath)) {
58
+ return fs.readFileSync(filePath, 'utf8');
59
+ }
60
+ }
61
+ return null;
62
+ }
63
+ catch (error) {
64
+ console.error(`Error loading Yarn file ${filename}:`, error);
65
+ return null;
66
+ }
67
+ }
68
+ /**
69
+ * Get flag schema for an example
70
+ */
71
+ export function getFlagSchemaForExample(exampleId) {
72
+ const metadata = getExampleMetadata(exampleId);
73
+ if (!metadata) {
74
+ return null;
75
+ }
76
+ return getExampleFlagSchema(metadata.flagSchemaId);
77
+ }
78
+ /**
79
+ * Get all examples with their metadata
80
+ */
81
+ export function getAllExamples() {
82
+ return examplesRegistry.map(metadata => ({
83
+ ...metadata,
84
+ flagSchema: getExampleFlagSchema(metadata.flagSchemaId)
85
+ }));
86
+ }
87
+ /**
88
+ * Synchronous version for use with pre-loaded examples
89
+ * This is used when examples are bundled/inlined
90
+ */
91
+ export function loadExampleDialogueSync(exampleId, yarnContent) {
92
+ const metadata = getExampleMetadata(exampleId);
93
+ if (!metadata) {
94
+ return null;
95
+ }
96
+ try {
97
+ return importFromYarn(yarnContent, metadata.title);
98
+ }
99
+ catch (error) {
100
+ console.error(`Error loading example ${exampleId}:`, error);
101
+ return null;
102
+ }
103
+ }
@@ -0,0 +1,38 @@
1
+ import { FlagSchema } from '../types/flags';
2
+ /**
3
+ * Example metadata - describes each example file
4
+ */
5
+ export interface ExampleMetadata {
6
+ id: string;
7
+ title: string;
8
+ description: string;
9
+ filename: string;
10
+ flagSchemaId: string;
11
+ nodeCount?: number;
12
+ features: string[];
13
+ }
14
+ /**
15
+ * Registry of all available examples
16
+ * This is the single source of truth for example discovery
17
+ */
18
+ export declare const examplesRegistry: ExampleMetadata[];
19
+ /**
20
+ * Flag schemas for examples
21
+ */
22
+ export declare const exampleFlagSchemas: Record<string, FlagSchema>;
23
+ /**
24
+ * Get example metadata by ID
25
+ */
26
+ export declare function getExampleMetadata(id: string): ExampleMetadata | null;
27
+ /**
28
+ * List all available example IDs
29
+ */
30
+ export declare function listExampleIds(): string[];
31
+ /**
32
+ * Get flag schema by ID
33
+ */
34
+ export declare function getExampleFlagSchema(id: string): FlagSchema | null;
35
+ /**
36
+ * List all available flag schema IDs
37
+ */
38
+ export declare function listFlagSchemaIds(): string[];
@@ -0,0 +1,153 @@
1
+ import { FLAG_TYPE, FLAG_VALUE_TYPE } from '../types/constants';
2
+ /**
3
+ * Registry of all available examples
4
+ * This is the single source of truth for example discovery
5
+ */
6
+ export const examplesRegistry = [
7
+ {
8
+ id: 'basic',
9
+ title: 'Basic Dialogue Example',
10
+ description: 'Simple dialogue with player choices',
11
+ filename: 'basic-dialogue.yarn',
12
+ flagSchemaId: 'basic',
13
+ features: ['basic-choices']
14
+ },
15
+ {
16
+ id: 'conditional',
17
+ title: 'Conditional Dialogue Example',
18
+ description: 'Dialogue with conditional choices based on flags',
19
+ filename: 'conditional-dialogue.yarn',
20
+ flagSchemaId: 'conditional',
21
+ features: ['conditional-choices', 'flag-checks']
22
+ },
23
+ {
24
+ id: 'quest-progression',
25
+ title: 'Quest Progression Example',
26
+ description: 'Quest system with progression and rewards',
27
+ filename: 'quest-progression.yarn',
28
+ flagSchemaId: 'rpg',
29
+ features: ['quest-progression', 'flag-setting']
30
+ },
31
+ {
32
+ id: 'complex-conditional',
33
+ title: 'Complex Conditional Example',
34
+ description: 'Advanced conditional logic with multiple branches',
35
+ filename: 'complex-conditional.yarn',
36
+ flagSchemaId: 'complex_conditional',
37
+ features: ['conditional-nodes', 'multiple-branches', 'complex-conditions']
38
+ },
39
+ {
40
+ id: 'variable-operations',
41
+ title: 'Variable Operations Example',
42
+ description: 'Demonstrates variable operations, interpolation, and numeric calculations',
43
+ filename: 'variable-operations-example.yarn',
44
+ flagSchemaId: 'rpg',
45
+ features: ['variable-operations', 'variable-interpolation', 'numeric-calculations', 'string-variables']
46
+ }
47
+ ];
48
+ /**
49
+ * Flag schemas for examples
50
+ */
51
+ export const exampleFlagSchemas = {
52
+ basic: {
53
+ categories: ['quests', 'items', 'stats'],
54
+ flags: [
55
+ { id: 'quest_intro', name: 'Introduction Quest', type: FLAG_TYPE.QUEST, category: 'quests', valueType: FLAG_VALUE_TYPE.STRING },
56
+ { id: 'item_key', name: 'Key', type: FLAG_TYPE.ITEM, category: 'items' },
57
+ { id: 'stat_reputation', name: 'Reputation', type: FLAG_TYPE.STAT, category: 'stats', valueType: FLAG_VALUE_TYPE.NUMBER, defaultValue: 0 },
58
+ ]
59
+ },
60
+ conditional: {
61
+ categories: ['quests', 'items', 'stats'],
62
+ flags: [
63
+ { id: 'quest_main', name: 'Main Quest', type: FLAG_TYPE.QUEST, category: 'quests', valueType: FLAG_VALUE_TYPE.STRING },
64
+ { id: 'item_key', name: 'Key', type: FLAG_TYPE.ITEM, category: 'items' },
65
+ { id: 'stat_gold', name: 'Gold', type: FLAG_TYPE.STAT, category: 'stats', valueType: FLAG_VALUE_TYPE.NUMBER, defaultValue: 0 },
66
+ { id: 'stat_reputation', name: 'Reputation', type: FLAG_TYPE.STAT, category: 'stats', valueType: FLAG_VALUE_TYPE.NUMBER, defaultValue: 0 },
67
+ ]
68
+ },
69
+ rpg: {
70
+ categories: ['quests', 'achievements', 'items', 'stats', 'titles'],
71
+ flags: [
72
+ { id: 'quest_dragon_slayer', name: 'Dragon Slayer Quest', type: FLAG_TYPE.QUEST, category: 'quests', valueType: FLAG_VALUE_TYPE.STRING },
73
+ { id: 'quest_dragon_slayer_complete', name: 'Dragon Slayer Complete', type: FLAG_TYPE.QUEST, category: 'quests' },
74
+ { id: 'quest_find_key', name: 'Find the Key', type: FLAG_TYPE.QUEST, category: 'quests', valueType: FLAG_VALUE_TYPE.STRING },
75
+ { id: 'achievement_first_quest', name: 'First Quest', type: FLAG_TYPE.ACHIEVEMENT, category: 'achievements' },
76
+ { id: 'achievement_dragon_slayer', name: 'Dragon Slayer', type: FLAG_TYPE.ACHIEVEMENT, category: 'achievements' },
77
+ { id: 'achievement_hero', name: 'Hero', type: FLAG_TYPE.ACHIEVEMENT, category: 'achievements' },
78
+ { id: 'item_ancient_key', name: 'Ancient Key', type: FLAG_TYPE.ITEM, category: 'items' },
79
+ { id: 'item_map', name: 'Treasure Map', type: FLAG_TYPE.ITEM, category: 'items' },
80
+ { id: 'item_sword', name: 'Legendary Sword', type: FLAG_TYPE.ITEM, category: 'items' },
81
+ { id: 'item_potion', name: 'Health Potion', type: FLAG_TYPE.ITEM, category: 'items' },
82
+ { id: 'stat_gold', name: 'Gold', type: FLAG_TYPE.STAT, category: 'stats', valueType: FLAG_VALUE_TYPE.NUMBER, defaultValue: 0 },
83
+ { id: 'stat_reputation', name: 'Reputation', type: FLAG_TYPE.STAT, category: 'stats', valueType: FLAG_VALUE_TYPE.NUMBER, defaultValue: 0 },
84
+ { id: 'stat_charisma', name: 'Charisma', type: FLAG_TYPE.STAT, category: 'stats', valueType: FLAG_VALUE_TYPE.NUMBER, defaultValue: 10 },
85
+ { id: 'stat_strength', name: 'Strength', type: FLAG_TYPE.STAT, category: 'stats', valueType: FLAG_VALUE_TYPE.NUMBER, defaultValue: 10 },
86
+ { id: 'stat_experience', name: 'Experience', type: FLAG_TYPE.STAT, category: 'stats', valueType: FLAG_VALUE_TYPE.NUMBER, defaultValue: 0 },
87
+ { id: 'title_hero', name: 'Hero', type: FLAG_TYPE.TITLE, category: 'titles' },
88
+ { id: 'title_merchant', name: 'Merchant', type: FLAG_TYPE.TITLE, category: 'titles' },
89
+ { id: 'player_name', name: 'Player Name', type: FLAG_TYPE.GLOBAL, category: 'global', valueType: FLAG_VALUE_TYPE.STRING, defaultValue: 'Traveler' },
90
+ { id: 'location_name', name: 'Location Name', type: FLAG_TYPE.GLOBAL, category: 'global', valueType: FLAG_VALUE_TYPE.STRING, defaultValue: 'Town' },
91
+ { id: 'player_title', name: 'Player Title', type: FLAG_TYPE.TITLE, category: 'titles', valueType: FLAG_VALUE_TYPE.STRING },
92
+ { id: 'greeting_count', name: 'Greeting Count', type: FLAG_TYPE.STAT, category: 'stats', valueType: FLAG_VALUE_TYPE.NUMBER, defaultValue: 0 },
93
+ ]
94
+ },
95
+ complex_conditional: {
96
+ categories: ['quests', 'achievements', 'items', 'stats', 'titles', 'global', 'dialogue'],
97
+ flags: [
98
+ { id: 'quest_ancient_ruins', name: 'Ancient Ruins Quest', type: FLAG_TYPE.QUEST, category: 'quests', valueType: FLAG_VALUE_TYPE.STRING },
99
+ { id: 'quest_ancient_ruins_complete', name: 'Ancient Ruins Complete', type: FLAG_TYPE.QUEST, category: 'quests' },
100
+ { id: 'quest_treasure_hunt', name: 'Treasure Hunt', type: FLAG_TYPE.QUEST, category: 'quests', valueType: FLAG_VALUE_TYPE.STRING },
101
+ { id: 'quest_treasure_hunt_complete', name: 'Treasure Hunt Complete', type: FLAG_TYPE.QUEST, category: 'quests' },
102
+ { id: 'quest_dragon_slayer', name: 'Dragon Slayer Quest', type: FLAG_TYPE.QUEST, category: 'quests', valueType: FLAG_VALUE_TYPE.STRING },
103
+ { id: 'achievement_explorer', name: 'Explorer', type: FLAG_TYPE.ACHIEVEMENT, category: 'achievements' },
104
+ { id: 'achievement_rich', name: 'Rich', type: FLAG_TYPE.ACHIEVEMENT, category: 'achievements' },
105
+ { id: 'achievement_hero', name: 'Hero', type: FLAG_TYPE.ACHIEVEMENT, category: 'achievements' },
106
+ { id: 'achievement_diplomat', name: 'Diplomat', type: FLAG_TYPE.ACHIEVEMENT, category: 'achievements' },
107
+ { id: 'item_ancient_key', name: 'Ancient Key', type: FLAG_TYPE.ITEM, category: 'items' },
108
+ { id: 'item_treasure_map', name: 'Treasure Map', type: FLAG_TYPE.ITEM, category: 'items' },
109
+ { id: 'item_legendary_sword', name: 'Legendary Sword', type: FLAG_TYPE.ITEM, category: 'items' },
110
+ { id: 'item_gold_coin', name: 'Gold Coin', type: FLAG_TYPE.ITEM, category: 'items' },
111
+ { id: 'stat_gold', name: 'Gold', type: FLAG_TYPE.STAT, category: 'stats', valueType: FLAG_VALUE_TYPE.NUMBER, defaultValue: 0 },
112
+ { id: 'stat_reputation', name: 'Reputation', type: FLAG_TYPE.STAT, category: 'stats', valueType: FLAG_VALUE_TYPE.NUMBER, defaultValue: 0 },
113
+ { id: 'stat_charisma', name: 'Charisma', type: FLAG_TYPE.STAT, category: 'stats', valueType: FLAG_VALUE_TYPE.NUMBER, defaultValue: 10 },
114
+ { id: 'stat_strength', name: 'Strength', type: FLAG_TYPE.STAT, category: 'stats', valueType: FLAG_VALUE_TYPE.NUMBER, defaultValue: 10 },
115
+ { id: 'stat_wisdom', name: 'Wisdom', type: FLAG_TYPE.STAT, category: 'stats', valueType: FLAG_VALUE_TYPE.NUMBER, defaultValue: 10 },
116
+ { id: 'title_hero', name: 'Hero', type: FLAG_TYPE.TITLE, category: 'titles' },
117
+ { id: 'title_explorer', name: 'Explorer', type: FLAG_TYPE.TITLE, category: 'titles' },
118
+ { id: 'title_merchant', name: 'Merchant', type: FLAG_TYPE.TITLE, category: 'titles' },
119
+ { id: 'global_game_started', name: 'Game Started', type: FLAG_TYPE.GLOBAL, category: 'global' },
120
+ { id: 'global_first_visit', name: 'First Visit', type: FLAG_TYPE.GLOBAL, category: 'global' },
121
+ { id: 'global_difficulty', name: 'Difficulty', type: FLAG_TYPE.GLOBAL, category: 'global', valueType: FLAG_VALUE_TYPE.STRING },
122
+ { id: 'dialogue_met_guard', name: 'Met Guard', type: FLAG_TYPE.DIALOGUE, category: 'dialogue' },
123
+ { id: 'dialogue_hostile', name: 'Hostile Response', type: FLAG_TYPE.DIALOGUE, category: 'dialogue' },
124
+ { id: 'dialogue_friendly', name: 'Friendly Response', type: FLAG_TYPE.DIALOGUE, category: 'dialogue' },
125
+ { id: 'dialogue_seeks_knowledge', name: 'Seeks Knowledge', type: FLAG_TYPE.DIALOGUE, category: 'dialogue' },
126
+ { id: 'dialogue_offered_bribe', name: 'Offered Bribe', type: FLAG_TYPE.DIALOGUE, category: 'dialogue' },
127
+ ]
128
+ }
129
+ };
130
+ /**
131
+ * Get example metadata by ID
132
+ */
133
+ export function getExampleMetadata(id) {
134
+ return examplesRegistry.find(ex => ex.id === id) || null;
135
+ }
136
+ /**
137
+ * List all available example IDs
138
+ */
139
+ export function listExampleIds() {
140
+ return examplesRegistry.map(ex => ex.id);
141
+ }
142
+ /**
143
+ * Get flag schema by ID
144
+ */
145
+ export function getExampleFlagSchema(id) {
146
+ return exampleFlagSchemas[id] || null;
147
+ }
148
+ /**
149
+ * List all available flag schema IDs
150
+ */
151
+ export function listFlagSchemaIds() {
152
+ return Object.keys(exampleFlagSchemas);
153
+ }
@@ -0,0 +1,26 @@
1
+ /**
2
+ * Unified Examples System
3
+ *
4
+ * All examples are stored as Yarn files and loaded through the registry system.
5
+ * This provides a single, organized way to discover and load examples.
6
+ *
7
+ * Structure:
8
+ * - examples-registry.ts: Metadata about all examples (titles, descriptions, features)
9
+ * - yarn-examples.ts: Actual Yarn file contents (all examples as Yarn strings)
10
+ * - legacy-examples.ts: Old TypeScript examples (being migrated to Yarn format)
11
+ * - index.ts: Public API for loading examples (this file)
12
+ */
13
+ export { examplesRegistry, exampleFlagSchemas, getExampleMetadata, listExampleIds, getExampleFlagSchema, listFlagSchemaIds, type ExampleMetadata } from './examples-registry';
14
+ /**
15
+ * Legacy exports for backward compatibility
16
+ * These maintain the old API while we migrate examples to Yarn format
17
+ * TODO: Remove once all examples are migrated and code is updated
18
+ */
19
+ import { DialogueTree } from '../types';
20
+ import { FlagSchema } from '../types/flags';
21
+ export declare const exampleDialogues: Record<string, DialogueTree>;
22
+ export declare const demoFlagSchemas: Record<string, FlagSchema>;
23
+ export declare function listExamples(): string[];
24
+ export declare function listDemoFlagSchemas(): string[];
25
+ export declare function getExampleDialogue(name: string): DialogueTree | null;
26
+ export declare function getDemoFlagSchema(name: string): FlagSchema | null;
@@ -0,0 +1,50 @@
1
+ /**
2
+ * Unified Examples System
3
+ *
4
+ * All examples are stored as Yarn files and loaded through the registry system.
5
+ * This provides a single, organized way to discover and load examples.
6
+ *
7
+ * Structure:
8
+ * - examples-registry.ts: Metadata about all examples (titles, descriptions, features)
9
+ * - yarn-examples.ts: Actual Yarn file contents (all examples as Yarn strings)
10
+ * - legacy-examples.ts: Old TypeScript examples (being migrated to Yarn format)
11
+ * - index.ts: Public API for loading examples (this file)
12
+ */
13
+ // New unified system exports
14
+ export { examplesRegistry, exampleFlagSchemas, getExampleMetadata, listExampleIds, getExampleFlagSchema, listFlagSchemaIds } from './examples-registry';
15
+ import { getExampleDialogue as getYarnExampleDialogue } from './yarn-examples';
16
+ import { listExampleIds, listFlagSchemaIds, getExampleFlagSchema } from './examples-registry';
17
+ import { exampleDialogues as legacyExamples, demoFlagSchemas as legacySchemas } from './legacy-examples';
18
+ // Export legacy examples - these work alongside the new Yarn examples
19
+ export const exampleDialogues = legacyExamples;
20
+ export const demoFlagSchemas = legacySchemas;
21
+ export function listExamples() {
22
+ // Combine both Yarn examples and legacy examples
23
+ const yarnIds = listExampleIds();
24
+ const legacyIds = Object.keys(legacyExamples);
25
+ return [...new Set([...yarnIds, ...legacyIds])];
26
+ }
27
+ export function listDemoFlagSchemas() {
28
+ // Combine both systems
29
+ const yarnIds = listFlagSchemaIds();
30
+ const legacyIds = Object.keys(legacySchemas);
31
+ return [...new Set([...yarnIds, ...legacyIds])];
32
+ }
33
+ export function getExampleDialogue(name) {
34
+ // Try new Yarn system first
35
+ const yarnDialogue = getYarnExampleDialogue(name);
36
+ if (yarnDialogue) {
37
+ return yarnDialogue;
38
+ }
39
+ // Fallback to legacy TypeScript examples
40
+ return legacyExamples[name] || null;
41
+ }
42
+ export function getDemoFlagSchema(name) {
43
+ // Try new system first
44
+ const schema = getExampleFlagSchema(name);
45
+ if (schema) {
46
+ return schema;
47
+ }
48
+ // Fallback to legacy
49
+ return legacySchemas[name] || null;
50
+ }
@@ -0,0 +1,9 @@
1
+ import { DialogueTree } from '../types';
2
+ import { FlagSchema } from '../types/flags';
3
+ /**
4
+ * Legacy TypeScript examples
5
+ * These are kept for backward compatibility while we migrate to Yarn format
6
+ * TODO: Convert these to Yarn format and remove this file
7
+ */
8
+ export declare const demoFlagSchemas: Record<string, FlagSchema>;
9
+ export declare const exampleDialogues: Record<string, DialogueTree>;