@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,173 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const condition_evaluator_1 = require("../condition-evaluator");
|
|
5
|
+
const constants_1 = require("../../../types/constants");
|
|
6
|
+
(0, vitest_1.describe)('condition-evaluator', () => {
|
|
7
|
+
(0, vitest_1.describe)('evaluateCondition', () => {
|
|
8
|
+
const variables = {
|
|
9
|
+
flag1: true,
|
|
10
|
+
flag2: false,
|
|
11
|
+
flag3: 42,
|
|
12
|
+
flag4: 'hello',
|
|
13
|
+
flag5: 0,
|
|
14
|
+
};
|
|
15
|
+
const memoryFlags = new Set(['memory1', 'memory2']);
|
|
16
|
+
(0, vitest_1.it)('should evaluate IS_SET correctly', () => {
|
|
17
|
+
const condition = {
|
|
18
|
+
flag: 'flag1',
|
|
19
|
+
operator: constants_1.CONDITION_OPERATOR.IS_SET,
|
|
20
|
+
};
|
|
21
|
+
(0, vitest_1.expect)((0, condition_evaluator_1.evaluateCondition)(condition, variables, memoryFlags)).toBe(true);
|
|
22
|
+
const condition2 = {
|
|
23
|
+
flag: 'flag2',
|
|
24
|
+
operator: constants_1.CONDITION_OPERATOR.IS_SET,
|
|
25
|
+
};
|
|
26
|
+
(0, vitest_1.expect)((0, condition_evaluator_1.evaluateCondition)(condition2, variables, memoryFlags)).toBe(false);
|
|
27
|
+
const condition3 = {
|
|
28
|
+
flag: 'memory1',
|
|
29
|
+
operator: constants_1.CONDITION_OPERATOR.IS_SET,
|
|
30
|
+
};
|
|
31
|
+
(0, vitest_1.expect)((0, condition_evaluator_1.evaluateCondition)(condition3, variables, memoryFlags)).toBe(true);
|
|
32
|
+
});
|
|
33
|
+
(0, vitest_1.it)('should evaluate IS_NOT_SET correctly', () => {
|
|
34
|
+
const condition = {
|
|
35
|
+
flag: 'nonexistent',
|
|
36
|
+
operator: constants_1.CONDITION_OPERATOR.IS_NOT_SET,
|
|
37
|
+
};
|
|
38
|
+
(0, vitest_1.expect)((0, condition_evaluator_1.evaluateCondition)(condition, variables, memoryFlags)).toBe(true);
|
|
39
|
+
const condition2 = {
|
|
40
|
+
flag: 'flag1',
|
|
41
|
+
operator: constants_1.CONDITION_OPERATOR.IS_NOT_SET,
|
|
42
|
+
};
|
|
43
|
+
(0, vitest_1.expect)((0, condition_evaluator_1.evaluateCondition)(condition2, variables, memoryFlags)).toBe(false);
|
|
44
|
+
});
|
|
45
|
+
(0, vitest_1.it)('should evaluate EQUALS correctly', () => {
|
|
46
|
+
const condition = {
|
|
47
|
+
flag: 'flag3',
|
|
48
|
+
operator: constants_1.CONDITION_OPERATOR.EQUALS,
|
|
49
|
+
value: 42,
|
|
50
|
+
};
|
|
51
|
+
(0, vitest_1.expect)((0, condition_evaluator_1.evaluateCondition)(condition, variables, memoryFlags)).toBe(true);
|
|
52
|
+
const condition2 = {
|
|
53
|
+
flag: 'flag4',
|
|
54
|
+
operator: constants_1.CONDITION_OPERATOR.EQUALS,
|
|
55
|
+
value: 'hello',
|
|
56
|
+
};
|
|
57
|
+
(0, vitest_1.expect)((0, condition_evaluator_1.evaluateCondition)(condition2, variables, memoryFlags)).toBe(true);
|
|
58
|
+
const condition3 = {
|
|
59
|
+
flag: 'flag3',
|
|
60
|
+
operator: constants_1.CONDITION_OPERATOR.EQUALS,
|
|
61
|
+
value: 10,
|
|
62
|
+
};
|
|
63
|
+
(0, vitest_1.expect)((0, condition_evaluator_1.evaluateCondition)(condition3, variables, memoryFlags)).toBe(false);
|
|
64
|
+
});
|
|
65
|
+
(0, vitest_1.it)('should evaluate NOT_EQUALS correctly', () => {
|
|
66
|
+
const condition = {
|
|
67
|
+
flag: 'flag3',
|
|
68
|
+
operator: constants_1.CONDITION_OPERATOR.NOT_EQUALS,
|
|
69
|
+
value: 10,
|
|
70
|
+
};
|
|
71
|
+
(0, vitest_1.expect)((0, condition_evaluator_1.evaluateCondition)(condition, variables, memoryFlags)).toBe(true);
|
|
72
|
+
const condition2 = {
|
|
73
|
+
flag: 'flag3',
|
|
74
|
+
operator: constants_1.CONDITION_OPERATOR.NOT_EQUALS,
|
|
75
|
+
value: 42,
|
|
76
|
+
};
|
|
77
|
+
(0, vitest_1.expect)((0, condition_evaluator_1.evaluateCondition)(condition2, variables, memoryFlags)).toBe(false);
|
|
78
|
+
});
|
|
79
|
+
(0, vitest_1.it)('should evaluate GREATER_THAN correctly', () => {
|
|
80
|
+
const condition = {
|
|
81
|
+
flag: 'flag3',
|
|
82
|
+
operator: constants_1.CONDITION_OPERATOR.GREATER_THAN,
|
|
83
|
+
value: 40,
|
|
84
|
+
};
|
|
85
|
+
(0, vitest_1.expect)((0, condition_evaluator_1.evaluateCondition)(condition, variables, memoryFlags)).toBe(true);
|
|
86
|
+
const condition2 = {
|
|
87
|
+
flag: 'flag3',
|
|
88
|
+
operator: constants_1.CONDITION_OPERATOR.GREATER_THAN,
|
|
89
|
+
value: 50,
|
|
90
|
+
};
|
|
91
|
+
(0, vitest_1.expect)((0, condition_evaluator_1.evaluateCondition)(condition2, variables, memoryFlags)).toBe(false);
|
|
92
|
+
});
|
|
93
|
+
(0, vitest_1.it)('should evaluate LESS_THAN correctly', () => {
|
|
94
|
+
const condition = {
|
|
95
|
+
flag: 'flag3',
|
|
96
|
+
operator: constants_1.CONDITION_OPERATOR.LESS_THAN,
|
|
97
|
+
value: 50,
|
|
98
|
+
};
|
|
99
|
+
(0, vitest_1.expect)((0, condition_evaluator_1.evaluateCondition)(condition, variables, memoryFlags)).toBe(true);
|
|
100
|
+
const condition2 = {
|
|
101
|
+
flag: 'flag3',
|
|
102
|
+
operator: constants_1.CONDITION_OPERATOR.LESS_THAN,
|
|
103
|
+
value: 40,
|
|
104
|
+
};
|
|
105
|
+
(0, vitest_1.expect)((0, condition_evaluator_1.evaluateCondition)(condition2, variables, memoryFlags)).toBe(false);
|
|
106
|
+
});
|
|
107
|
+
(0, vitest_1.it)('should evaluate GREATER_EQUAL correctly', () => {
|
|
108
|
+
const condition = {
|
|
109
|
+
flag: 'flag3',
|
|
110
|
+
operator: constants_1.CONDITION_OPERATOR.GREATER_EQUAL,
|
|
111
|
+
value: 42,
|
|
112
|
+
};
|
|
113
|
+
(0, vitest_1.expect)((0, condition_evaluator_1.evaluateCondition)(condition, variables, memoryFlags)).toBe(true);
|
|
114
|
+
const condition2 = {
|
|
115
|
+
flag: 'flag3',
|
|
116
|
+
operator: constants_1.CONDITION_OPERATOR.GREATER_EQUAL,
|
|
117
|
+
value: 41,
|
|
118
|
+
};
|
|
119
|
+
(0, vitest_1.expect)((0, condition_evaluator_1.evaluateCondition)(condition2, variables, memoryFlags)).toBe(true);
|
|
120
|
+
});
|
|
121
|
+
(0, vitest_1.it)('should evaluate LESS_EQUAL correctly', () => {
|
|
122
|
+
const condition = {
|
|
123
|
+
flag: 'flag3',
|
|
124
|
+
operator: constants_1.CONDITION_OPERATOR.LESS_EQUAL,
|
|
125
|
+
value: 42,
|
|
126
|
+
};
|
|
127
|
+
(0, vitest_1.expect)((0, condition_evaluator_1.evaluateCondition)(condition, variables, memoryFlags)).toBe(true);
|
|
128
|
+
const condition2 = {
|
|
129
|
+
flag: 'flag3',
|
|
130
|
+
operator: constants_1.CONDITION_OPERATOR.LESS_EQUAL,
|
|
131
|
+
value: 43,
|
|
132
|
+
};
|
|
133
|
+
(0, vitest_1.expect)((0, condition_evaluator_1.evaluateCondition)(condition2, variables, memoryFlags)).toBe(true);
|
|
134
|
+
});
|
|
135
|
+
(0, vitest_1.it)('should treat undefined as 0 for numeric comparisons', () => {
|
|
136
|
+
const condition = {
|
|
137
|
+
flag: 'nonexistent',
|
|
138
|
+
operator: constants_1.CONDITION_OPERATOR.GREATER_THAN,
|
|
139
|
+
value: -1,
|
|
140
|
+
};
|
|
141
|
+
(0, vitest_1.expect)((0, condition_evaluator_1.evaluateCondition)(condition, variables, memoryFlags)).toBe(true);
|
|
142
|
+
const condition2 = {
|
|
143
|
+
flag: 'nonexistent',
|
|
144
|
+
operator: constants_1.CONDITION_OPERATOR.LESS_THAN,
|
|
145
|
+
value: 1,
|
|
146
|
+
};
|
|
147
|
+
(0, vitest_1.expect)((0, condition_evaluator_1.evaluateCondition)(condition2, variables, memoryFlags)).toBe(true);
|
|
148
|
+
});
|
|
149
|
+
});
|
|
150
|
+
(0, vitest_1.describe)('evaluateConditions', () => {
|
|
151
|
+
const variables = {
|
|
152
|
+
flag1: true,
|
|
153
|
+
flag2: 42,
|
|
154
|
+
};
|
|
155
|
+
(0, vitest_1.it)('should return true when all conditions are true', () => {
|
|
156
|
+
const conditions = [
|
|
157
|
+
{ flag: 'flag1', operator: constants_1.CONDITION_OPERATOR.IS_SET },
|
|
158
|
+
{ flag: 'flag2', operator: constants_1.CONDITION_OPERATOR.EQUALS, value: 42 },
|
|
159
|
+
];
|
|
160
|
+
(0, vitest_1.expect)((0, condition_evaluator_1.evaluateConditions)(conditions, variables)).toBe(true);
|
|
161
|
+
});
|
|
162
|
+
(0, vitest_1.it)('should return false when any condition is false', () => {
|
|
163
|
+
const conditions = [
|
|
164
|
+
{ flag: 'flag1', operator: constants_1.CONDITION_OPERATOR.IS_SET },
|
|
165
|
+
{ flag: 'flag2', operator: constants_1.CONDITION_OPERATOR.EQUALS, value: 10 },
|
|
166
|
+
];
|
|
167
|
+
(0, vitest_1.expect)((0, condition_evaluator_1.evaluateConditions)(conditions, variables)).toBe(false);
|
|
168
|
+
});
|
|
169
|
+
(0, vitest_1.it)('should return true for empty conditions array', () => {
|
|
170
|
+
(0, vitest_1.expect)((0, condition_evaluator_1.evaluateConditions)([], variables)).toBe(true);
|
|
171
|
+
});
|
|
172
|
+
});
|
|
173
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,239 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const node_processor_1 = require("../node-processor");
|
|
5
|
+
const variable_manager_1 = require("../variable-manager");
|
|
6
|
+
(0, vitest_1.describe)('node-processor', () => {
|
|
7
|
+
let variableManager;
|
|
8
|
+
let availableNodes;
|
|
9
|
+
(0, vitest_1.beforeEach)(() => {
|
|
10
|
+
variableManager = new variable_manager_1.VariableManager({ flag1: true, flag2: 42 });
|
|
11
|
+
availableNodes = {
|
|
12
|
+
node1: {
|
|
13
|
+
id: 'node1',
|
|
14
|
+
type: 'npc',
|
|
15
|
+
content: 'Hello',
|
|
16
|
+
x: 0,
|
|
17
|
+
y: 0,
|
|
18
|
+
},
|
|
19
|
+
node2: {
|
|
20
|
+
id: 'node2',
|
|
21
|
+
type: 'npc',
|
|
22
|
+
content: 'World',
|
|
23
|
+
x: 0,
|
|
24
|
+
y: 0,
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
});
|
|
28
|
+
(0, vitest_1.describe)('processNode', () => {
|
|
29
|
+
(0, vitest_1.describe)('NPC nodes', () => {
|
|
30
|
+
(0, vitest_1.it)('should process simple NPC node', () => {
|
|
31
|
+
const node = {
|
|
32
|
+
id: 'test',
|
|
33
|
+
type: 'npc',
|
|
34
|
+
content: 'Hello world',
|
|
35
|
+
speaker: 'NPC',
|
|
36
|
+
nextNodeId: 'node1',
|
|
37
|
+
x: 0,
|
|
38
|
+
y: 0,
|
|
39
|
+
};
|
|
40
|
+
const result = (0, node_processor_1.processNode)(node, variableManager);
|
|
41
|
+
(0, vitest_1.expect)(result.content).toBe('Hello world');
|
|
42
|
+
(0, vitest_1.expect)(result.speaker).toBe('NPC');
|
|
43
|
+
(0, vitest_1.expect)(result.nextNodeId).toBe('node1');
|
|
44
|
+
(0, vitest_1.expect)(result.isEnd).toBe(false);
|
|
45
|
+
(0, vitest_1.expect)(result.isPlayerChoice).toBe(false);
|
|
46
|
+
});
|
|
47
|
+
(0, vitest_1.it)('should mark as end when no nextNodeId', () => {
|
|
48
|
+
const node = {
|
|
49
|
+
id: 'test',
|
|
50
|
+
type: 'npc',
|
|
51
|
+
content: 'End',
|
|
52
|
+
x: 0,
|
|
53
|
+
y: 0,
|
|
54
|
+
};
|
|
55
|
+
const result = (0, node_processor_1.processNode)(node, variableManager);
|
|
56
|
+
(0, vitest_1.expect)(result.isEnd).toBe(true);
|
|
57
|
+
(0, vitest_1.expect)(result.nextNodeId).toBeUndefined();
|
|
58
|
+
});
|
|
59
|
+
});
|
|
60
|
+
(0, vitest_1.describe)('Player nodes', () => {
|
|
61
|
+
(0, vitest_1.it)('should return choices for player node', () => {
|
|
62
|
+
const node = {
|
|
63
|
+
id: 'test',
|
|
64
|
+
type: 'player',
|
|
65
|
+
content: '',
|
|
66
|
+
choices: [
|
|
67
|
+
{
|
|
68
|
+
id: 'c1',
|
|
69
|
+
text: 'Choice 1',
|
|
70
|
+
nextNodeId: 'node1',
|
|
71
|
+
},
|
|
72
|
+
{
|
|
73
|
+
id: 'c2',
|
|
74
|
+
text: 'Choice 2',
|
|
75
|
+
nextNodeId: 'node2',
|
|
76
|
+
},
|
|
77
|
+
],
|
|
78
|
+
x: 0,
|
|
79
|
+
y: 0,
|
|
80
|
+
};
|
|
81
|
+
const result = (0, node_processor_1.processNode)(node, variableManager);
|
|
82
|
+
(0, vitest_1.expect)(result.isPlayerChoice).toBe(true);
|
|
83
|
+
(0, vitest_1.expect)(result.choices).toHaveLength(2);
|
|
84
|
+
(0, vitest_1.expect)(result.choices?.[0].text).toBe('Choice 1');
|
|
85
|
+
});
|
|
86
|
+
(0, vitest_1.it)('should filter choices based on conditions', () => {
|
|
87
|
+
const node = {
|
|
88
|
+
id: 'test',
|
|
89
|
+
type: 'player',
|
|
90
|
+
content: '',
|
|
91
|
+
choices: [
|
|
92
|
+
{
|
|
93
|
+
id: 'c1',
|
|
94
|
+
text: 'Choice 1',
|
|
95
|
+
nextNodeId: 'node1',
|
|
96
|
+
conditions: [
|
|
97
|
+
{ flag: 'flag1', operator: 'is_set' },
|
|
98
|
+
],
|
|
99
|
+
},
|
|
100
|
+
{
|
|
101
|
+
id: 'c2',
|
|
102
|
+
text: 'Choice 2',
|
|
103
|
+
nextNodeId: 'node2',
|
|
104
|
+
conditions: [
|
|
105
|
+
{ flag: 'flag3', operator: 'is_set' },
|
|
106
|
+
],
|
|
107
|
+
},
|
|
108
|
+
],
|
|
109
|
+
x: 0,
|
|
110
|
+
y: 0,
|
|
111
|
+
};
|
|
112
|
+
const result = (0, node_processor_1.processNode)(node, variableManager);
|
|
113
|
+
(0, vitest_1.expect)(result.choices).toHaveLength(1);
|
|
114
|
+
(0, vitest_1.expect)(result.choices?.[0].text).toBe('Choice 1');
|
|
115
|
+
});
|
|
116
|
+
});
|
|
117
|
+
(0, vitest_1.describe)('Conditional nodes', () => {
|
|
118
|
+
(0, vitest_1.it)('should process conditional node with matching if block', () => {
|
|
119
|
+
const node = {
|
|
120
|
+
id: 'test',
|
|
121
|
+
type: 'conditional',
|
|
122
|
+
content: '',
|
|
123
|
+
conditionalBlocks: [
|
|
124
|
+
{
|
|
125
|
+
id: 'b1',
|
|
126
|
+
type: 'if',
|
|
127
|
+
condition: [{ flag: 'flag1', operator: 'is_set' }],
|
|
128
|
+
content: 'If content',
|
|
129
|
+
speaker: 'Speaker',
|
|
130
|
+
nextNodeId: 'node1',
|
|
131
|
+
},
|
|
132
|
+
{
|
|
133
|
+
id: 'b2',
|
|
134
|
+
type: 'else',
|
|
135
|
+
content: 'Else content',
|
|
136
|
+
},
|
|
137
|
+
],
|
|
138
|
+
x: 0,
|
|
139
|
+
y: 0,
|
|
140
|
+
};
|
|
141
|
+
const result = (0, node_processor_1.processNode)(node, variableManager);
|
|
142
|
+
(0, vitest_1.expect)(result.content).toBe('If content');
|
|
143
|
+
(0, vitest_1.expect)(result.speaker).toBe('Speaker');
|
|
144
|
+
(0, vitest_1.expect)(result.nextNodeId).toBe('node1');
|
|
145
|
+
});
|
|
146
|
+
(0, vitest_1.it)('should process conditional node with matching elseif block', () => {
|
|
147
|
+
const node = {
|
|
148
|
+
id: 'test',
|
|
149
|
+
type: 'conditional',
|
|
150
|
+
content: '',
|
|
151
|
+
conditionalBlocks: [
|
|
152
|
+
{
|
|
153
|
+
id: 'b1',
|
|
154
|
+
type: 'if',
|
|
155
|
+
condition: [{ flag: 'flag3', operator: 'is_set' }],
|
|
156
|
+
content: 'If content',
|
|
157
|
+
},
|
|
158
|
+
{
|
|
159
|
+
id: 'b2',
|
|
160
|
+
type: 'elseif',
|
|
161
|
+
condition: [{ flag: 'flag1', operator: 'is_set' }],
|
|
162
|
+
content: 'Elseif content',
|
|
163
|
+
},
|
|
164
|
+
{
|
|
165
|
+
id: 'b3',
|
|
166
|
+
type: 'else',
|
|
167
|
+
content: 'Else content',
|
|
168
|
+
},
|
|
169
|
+
],
|
|
170
|
+
x: 0,
|
|
171
|
+
y: 0,
|
|
172
|
+
};
|
|
173
|
+
const result = (0, node_processor_1.processNode)(node, variableManager);
|
|
174
|
+
(0, vitest_1.expect)(result.content).toBe('Elseif content');
|
|
175
|
+
});
|
|
176
|
+
(0, vitest_1.it)('should process conditional node with else block when no conditions match', () => {
|
|
177
|
+
const node = {
|
|
178
|
+
id: 'test',
|
|
179
|
+
type: 'conditional',
|
|
180
|
+
content: '',
|
|
181
|
+
conditionalBlocks: [
|
|
182
|
+
{
|
|
183
|
+
id: 'b1',
|
|
184
|
+
type: 'if',
|
|
185
|
+
condition: [{ flag: 'flag3', operator: 'is_set' }],
|
|
186
|
+
content: 'If content',
|
|
187
|
+
},
|
|
188
|
+
{
|
|
189
|
+
id: 'b2',
|
|
190
|
+
type: 'else',
|
|
191
|
+
content: 'Else content',
|
|
192
|
+
},
|
|
193
|
+
],
|
|
194
|
+
x: 0,
|
|
195
|
+
y: 0,
|
|
196
|
+
};
|
|
197
|
+
const result = (0, node_processor_1.processNode)(node, variableManager);
|
|
198
|
+
(0, vitest_1.expect)(result.content).toBe('Else content');
|
|
199
|
+
});
|
|
200
|
+
(0, vitest_1.it)('should return end when no block matches', () => {
|
|
201
|
+
const node = {
|
|
202
|
+
id: 'test',
|
|
203
|
+
type: 'conditional',
|
|
204
|
+
content: '',
|
|
205
|
+
conditionalBlocks: [
|
|
206
|
+
{
|
|
207
|
+
id: 'b1',
|
|
208
|
+
type: 'if',
|
|
209
|
+
condition: [{ flag: 'flag3', operator: 'is_set' }],
|
|
210
|
+
content: 'If content',
|
|
211
|
+
},
|
|
212
|
+
],
|
|
213
|
+
x: 0,
|
|
214
|
+
y: 0,
|
|
215
|
+
};
|
|
216
|
+
const result = (0, node_processor_1.processNode)(node, variableManager);
|
|
217
|
+
(0, vitest_1.expect)(result.isEnd).toBe(true);
|
|
218
|
+
(0, vitest_1.expect)(result.content).toBe('');
|
|
219
|
+
});
|
|
220
|
+
});
|
|
221
|
+
});
|
|
222
|
+
(0, vitest_1.describe)('isValidNextNode', () => {
|
|
223
|
+
(0, vitest_1.it)('should return true for valid node ID', () => {
|
|
224
|
+
(0, vitest_1.expect)((0, node_processor_1.isValidNextNode)('node1', availableNodes)).toBe(true);
|
|
225
|
+
});
|
|
226
|
+
(0, vitest_1.it)('should return false for undefined', () => {
|
|
227
|
+
(0, vitest_1.expect)((0, node_processor_1.isValidNextNode)(undefined, availableNodes)).toBe(false);
|
|
228
|
+
});
|
|
229
|
+
(0, vitest_1.it)('should return false for empty string', () => {
|
|
230
|
+
(0, vitest_1.expect)((0, node_processor_1.isValidNextNode)('', availableNodes)).toBe(false);
|
|
231
|
+
});
|
|
232
|
+
(0, vitest_1.it)('should return false for whitespace-only string', () => {
|
|
233
|
+
(0, vitest_1.expect)((0, node_processor_1.isValidNextNode)(' ', availableNodes)).toBe(false);
|
|
234
|
+
});
|
|
235
|
+
(0, vitest_1.it)('should return false for non-existent node', () => {
|
|
236
|
+
(0, vitest_1.expect)((0, node_processor_1.isValidNextNode)('nonexistent', availableNodes)).toBe(false);
|
|
237
|
+
});
|
|
238
|
+
});
|
|
239
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,108 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
const vitest_1 = require("vitest");
|
|
4
|
+
const variable_manager_1 = require("../variable-manager");
|
|
5
|
+
(0, vitest_1.describe)('VariableManager', () => {
|
|
6
|
+
let manager;
|
|
7
|
+
(0, vitest_1.beforeEach)(() => {
|
|
8
|
+
manager = new variable_manager_1.VariableManager();
|
|
9
|
+
});
|
|
10
|
+
(0, vitest_1.describe)('constructor', () => {
|
|
11
|
+
(0, vitest_1.it)('should initialize with empty state by default', () => {
|
|
12
|
+
(0, vitest_1.expect)(manager.get('test')).toBeUndefined();
|
|
13
|
+
(0, vitest_1.expect)(manager.getAllMemoryFlags().size).toBe(0);
|
|
14
|
+
});
|
|
15
|
+
(0, vitest_1.it)('should initialize with provided variables', () => {
|
|
16
|
+
const vars = { flag1: true, flag2: 42 };
|
|
17
|
+
const manager2 = new variable_manager_1.VariableManager(vars);
|
|
18
|
+
(0, vitest_1.expect)(manager2.get('flag1')).toBe(true);
|
|
19
|
+
(0, vitest_1.expect)(manager2.get('flag2')).toBe(42);
|
|
20
|
+
});
|
|
21
|
+
(0, vitest_1.it)('should initialize with provided memory flags', () => {
|
|
22
|
+
const memoryFlags = new Set(['mem1', 'mem2']);
|
|
23
|
+
const manager2 = new variable_manager_1.VariableManager(undefined, memoryFlags);
|
|
24
|
+
(0, vitest_1.expect)(manager2.hasMemoryFlag('mem1')).toBe(true);
|
|
25
|
+
(0, vitest_1.expect)(manager2.hasMemoryFlag('mem2')).toBe(true);
|
|
26
|
+
});
|
|
27
|
+
});
|
|
28
|
+
(0, vitest_1.describe)('set and get', () => {
|
|
29
|
+
(0, vitest_1.it)('should set and get boolean values', () => {
|
|
30
|
+
manager.set('flag1', true);
|
|
31
|
+
(0, vitest_1.expect)(manager.get('flag1')).toBe(true);
|
|
32
|
+
});
|
|
33
|
+
(0, vitest_1.it)('should set and get number values', () => {
|
|
34
|
+
manager.set('flag2', 42);
|
|
35
|
+
(0, vitest_1.expect)(manager.get('flag2')).toBe(42);
|
|
36
|
+
});
|
|
37
|
+
(0, vitest_1.it)('should set and get string values', () => {
|
|
38
|
+
manager.set('flag3', 'hello');
|
|
39
|
+
(0, vitest_1.expect)(manager.get('flag3')).toBe('hello');
|
|
40
|
+
});
|
|
41
|
+
(0, vitest_1.it)('should return undefined for unset variables', () => {
|
|
42
|
+
(0, vitest_1.expect)(manager.get('nonexistent')).toBeUndefined();
|
|
43
|
+
});
|
|
44
|
+
});
|
|
45
|
+
(0, vitest_1.describe)('memory flags', () => {
|
|
46
|
+
(0, vitest_1.it)('should add memory flags', () => {
|
|
47
|
+
manager.addMemoryFlag('mem1');
|
|
48
|
+
(0, vitest_1.expect)(manager.hasMemoryFlag('mem1')).toBe(true);
|
|
49
|
+
(0, vitest_1.expect)(manager.get('mem1')).toBe(true);
|
|
50
|
+
});
|
|
51
|
+
(0, vitest_1.it)('should remove memory flags', () => {
|
|
52
|
+
manager.addMemoryFlag('mem1');
|
|
53
|
+
manager.removeMemoryFlag('mem1');
|
|
54
|
+
(0, vitest_1.expect)(manager.hasMemoryFlag('mem1')).toBe(false);
|
|
55
|
+
});
|
|
56
|
+
(0, vitest_1.it)('should return memory flags as true when getting', () => {
|
|
57
|
+
manager.addMemoryFlag('mem1');
|
|
58
|
+
(0, vitest_1.expect)(manager.get('mem1')).toBe(true);
|
|
59
|
+
});
|
|
60
|
+
});
|
|
61
|
+
(0, vitest_1.describe)('getAllVariables', () => {
|
|
62
|
+
(0, vitest_1.it)('should return a copy of all variables', () => {
|
|
63
|
+
manager.set('flag1', true);
|
|
64
|
+
manager.set('flag2', 42);
|
|
65
|
+
const vars = manager.getAllVariables();
|
|
66
|
+
(0, vitest_1.expect)(vars).toEqual({ flag1: true, flag2: 42 });
|
|
67
|
+
// Should be a copy, not a reference
|
|
68
|
+
vars.flag1 = false;
|
|
69
|
+
(0, vitest_1.expect)(manager.get('flag1')).toBe(true);
|
|
70
|
+
});
|
|
71
|
+
});
|
|
72
|
+
(0, vitest_1.describe)('getAllMemoryFlags', () => {
|
|
73
|
+
(0, vitest_1.it)('should return a copy of memory flags', () => {
|
|
74
|
+
manager.addMemoryFlag('mem1');
|
|
75
|
+
manager.addMemoryFlag('mem2');
|
|
76
|
+
const flags = manager.getAllMemoryFlags();
|
|
77
|
+
(0, vitest_1.expect)(flags.has('mem1')).toBe(true);
|
|
78
|
+
(0, vitest_1.expect)(flags.has('mem2')).toBe(true);
|
|
79
|
+
// Should be a copy
|
|
80
|
+
flags.delete('mem1');
|
|
81
|
+
(0, vitest_1.expect)(manager.hasMemoryFlag('mem1')).toBe(true);
|
|
82
|
+
});
|
|
83
|
+
});
|
|
84
|
+
(0, vitest_1.describe)('clearMemoryFlags', () => {
|
|
85
|
+
(0, vitest_1.it)('should clear all memory flags', () => {
|
|
86
|
+
manager.addMemoryFlag('mem1');
|
|
87
|
+
manager.addMemoryFlag('mem2');
|
|
88
|
+
manager.clearMemoryFlags();
|
|
89
|
+
(0, vitest_1.expect)(manager.getAllMemoryFlags().size).toBe(0);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
(0, vitest_1.describe)('reset', () => {
|
|
93
|
+
(0, vitest_1.it)('should reset to initial state', () => {
|
|
94
|
+
manager.set('flag1', true);
|
|
95
|
+
manager.addMemoryFlag('mem1');
|
|
96
|
+
manager.reset();
|
|
97
|
+
(0, vitest_1.expect)(manager.get('flag1')).toBeUndefined();
|
|
98
|
+
(0, vitest_1.expect)(manager.hasMemoryFlag('mem1')).toBe(false);
|
|
99
|
+
});
|
|
100
|
+
(0, vitest_1.it)('should reset to provided state', () => {
|
|
101
|
+
manager.set('flag1', true);
|
|
102
|
+
manager.reset({ flag2: 42 }, new Set(['mem2']));
|
|
103
|
+
(0, vitest_1.expect)(manager.get('flag1')).toBeUndefined();
|
|
104
|
+
(0, vitest_1.expect)(manager.get('flag2')).toBe(42);
|
|
105
|
+
(0, vitest_1.expect)(manager.hasMemoryFlag('mem2')).toBe(true);
|
|
106
|
+
});
|
|
107
|
+
});
|
|
108
|
+
});
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { Condition } from '../../types';
|
|
2
|
+
export interface VariableState {
|
|
3
|
+
[key: string]: boolean | number | string | undefined;
|
|
4
|
+
}
|
|
5
|
+
/**
|
|
6
|
+
* Evaluates a single condition against variable state
|
|
7
|
+
*/
|
|
8
|
+
export declare function evaluateCondition(condition: Condition, variables: VariableState, memoryFlags?: Set<string>): boolean;
|
|
9
|
+
/**
|
|
10
|
+
* Evaluates multiple conditions with AND logic
|
|
11
|
+
*/
|
|
12
|
+
export declare function evaluateConditions(conditions: Condition[], variables: VariableState, memoryFlags?: Set<string>): boolean;
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.evaluateCondition = evaluateCondition;
|
|
4
|
+
exports.evaluateConditions = evaluateConditions;
|
|
5
|
+
const constants_1 = require("../../types/constants");
|
|
6
|
+
/**
|
|
7
|
+
* Evaluates a single condition against variable state
|
|
8
|
+
*/
|
|
9
|
+
function evaluateCondition(condition, variables, memoryFlags) {
|
|
10
|
+
let value = variables[condition.flag];
|
|
11
|
+
// If not in variables, check memoryFlags (dialogue flags)
|
|
12
|
+
if (value === undefined && memoryFlags) {
|
|
13
|
+
value = memoryFlags.has(condition.flag) ? true : undefined;
|
|
14
|
+
}
|
|
15
|
+
// For numeric comparisons, treat undefined as 0
|
|
16
|
+
const numericOperators = [
|
|
17
|
+
constants_1.CONDITION_OPERATOR.GREATER_THAN,
|
|
18
|
+
constants_1.CONDITION_OPERATOR.LESS_THAN,
|
|
19
|
+
constants_1.CONDITION_OPERATOR.GREATER_EQUAL,
|
|
20
|
+
constants_1.CONDITION_OPERATOR.LESS_EQUAL
|
|
21
|
+
];
|
|
22
|
+
const isNumericComparison = numericOperators.includes(condition.operator);
|
|
23
|
+
if (isNumericComparison && value === undefined) {
|
|
24
|
+
value = 0;
|
|
25
|
+
}
|
|
26
|
+
switch (condition.operator) {
|
|
27
|
+
case constants_1.CONDITION_OPERATOR.IS_SET:
|
|
28
|
+
return value !== undefined && value !== false && value !== 0 && value !== '';
|
|
29
|
+
case constants_1.CONDITION_OPERATOR.IS_NOT_SET:
|
|
30
|
+
return value === undefined || value === false || value === 0 || value === '';
|
|
31
|
+
case constants_1.CONDITION_OPERATOR.EQUALS:
|
|
32
|
+
return value === condition.value;
|
|
33
|
+
case constants_1.CONDITION_OPERATOR.NOT_EQUALS:
|
|
34
|
+
return value !== condition.value;
|
|
35
|
+
case constants_1.CONDITION_OPERATOR.GREATER_THAN:
|
|
36
|
+
const numValueGT = typeof value === 'number' ? value : (typeof value === 'string' ? parseFloat(value) : 0);
|
|
37
|
+
const numCondGT = typeof condition.value === 'number' ? condition.value : parseFloat(String(condition.value));
|
|
38
|
+
return !isNaN(numValueGT) && !isNaN(numCondGT) && numValueGT > numCondGT;
|
|
39
|
+
case constants_1.CONDITION_OPERATOR.LESS_THAN:
|
|
40
|
+
const numValueLT = typeof value === 'number' ? value : (typeof value === 'string' ? parseFloat(value) : 0);
|
|
41
|
+
const numCondLT = typeof condition.value === 'number' ? condition.value : parseFloat(String(condition.value));
|
|
42
|
+
return !isNaN(numValueLT) && !isNaN(numCondLT) && numValueLT < numCondLT;
|
|
43
|
+
case constants_1.CONDITION_OPERATOR.GREATER_EQUAL:
|
|
44
|
+
const numValueGE = typeof value === 'number' ? value : (typeof value === 'string' ? parseFloat(value) : 0);
|
|
45
|
+
const numCondGE = typeof condition.value === 'number' ? condition.value : parseFloat(String(condition.value));
|
|
46
|
+
return !isNaN(numValueGE) && !isNaN(numCondGE) && numValueGE >= numCondGE;
|
|
47
|
+
case constants_1.CONDITION_OPERATOR.LESS_EQUAL:
|
|
48
|
+
const numValueLE = typeof value === 'number' ? value : (typeof value === 'string' ? parseFloat(value) : 0);
|
|
49
|
+
const numCondLE = typeof condition.value === 'number' ? condition.value : parseFloat(String(condition.value));
|
|
50
|
+
return !isNaN(numValueLE) && !isNaN(numCondLE) && numValueLE <= numCondLE;
|
|
51
|
+
default:
|
|
52
|
+
return true;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
/**
|
|
56
|
+
* Evaluates multiple conditions with AND logic
|
|
57
|
+
*/
|
|
58
|
+
function evaluateConditions(conditions, variables, memoryFlags) {
|
|
59
|
+
return conditions.every(cond => evaluateCondition(cond, variables, memoryFlags));
|
|
60
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Yarn Spinner Runner
|
|
3
|
+
*
|
|
4
|
+
* Modular execution engine for running Yarn Spinner dialogue trees.
|
|
5
|
+
* This module provides the core logic for processing nodes, evaluating conditions,
|
|
6
|
+
* and managing state, separate from the UI components.
|
|
7
|
+
*/
|
|
8
|
+
export { VariableManager } from './variable-manager';
|
|
9
|
+
export { evaluateCondition, evaluateConditions } from './condition-evaluator';
|
|
10
|
+
export { processNode, isValidNextNode, ProcessedNodeResult } from './node-processor';
|
|
11
|
+
export { executeVariableOperation, processVariableOperationsInContent } from './variable-operations';
|
|
12
|
+
export type { VariableState } from './condition-evaluator';
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Yarn Spinner Runner
|
|
4
|
+
*
|
|
5
|
+
* Modular execution engine for running Yarn Spinner dialogue trees.
|
|
6
|
+
* This module provides the core logic for processing nodes, evaluating conditions,
|
|
7
|
+
* and managing state, separate from the UI components.
|
|
8
|
+
*/
|
|
9
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
10
|
+
exports.processVariableOperationsInContent = exports.executeVariableOperation = exports.isValidNextNode = exports.processNode = exports.evaluateConditions = exports.evaluateCondition = exports.VariableManager = void 0;
|
|
11
|
+
var variable_manager_1 = require("./variable-manager");
|
|
12
|
+
Object.defineProperty(exports, "VariableManager", { enumerable: true, get: function () { return variable_manager_1.VariableManager; } });
|
|
13
|
+
var condition_evaluator_1 = require("./condition-evaluator");
|
|
14
|
+
Object.defineProperty(exports, "evaluateCondition", { enumerable: true, get: function () { return condition_evaluator_1.evaluateCondition; } });
|
|
15
|
+
Object.defineProperty(exports, "evaluateConditions", { enumerable: true, get: function () { return condition_evaluator_1.evaluateConditions; } });
|
|
16
|
+
var node_processor_1 = require("./node-processor");
|
|
17
|
+
Object.defineProperty(exports, "processNode", { enumerable: true, get: function () { return node_processor_1.processNode; } });
|
|
18
|
+
Object.defineProperty(exports, "isValidNextNode", { enumerable: true, get: function () { return node_processor_1.isValidNextNode; } });
|
|
19
|
+
var variable_operations_1 = require("./variable-operations");
|
|
20
|
+
Object.defineProperty(exports, "executeVariableOperation", { enumerable: true, get: function () { return variable_operations_1.executeVariableOperation; } });
|
|
21
|
+
Object.defineProperty(exports, "processVariableOperationsInContent", { enumerable: true, get: function () { return variable_operations_1.processVariableOperationsInContent; } });
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import { DialogueNode, Choice } from '../../types';
|
|
2
|
+
import { VariableManager } from './variable-manager';
|
|
3
|
+
export interface ProcessedNodeResult {
|
|
4
|
+
content: string;
|
|
5
|
+
speaker?: string;
|
|
6
|
+
nextNodeId?: string;
|
|
7
|
+
isEnd: boolean;
|
|
8
|
+
isPlayerChoice: boolean;
|
|
9
|
+
choices?: Choice[];
|
|
10
|
+
}
|
|
11
|
+
/**
|
|
12
|
+
* Processes a dialogue node and returns the result
|
|
13
|
+
*/
|
|
14
|
+
export declare function processNode(node: DialogueNode, variableManager: VariableManager): ProcessedNodeResult;
|
|
15
|
+
/**
|
|
16
|
+
* Validates that a nextNodeId exists and is valid
|
|
17
|
+
*/
|
|
18
|
+
export declare function isValidNextNode(nextNodeId: string | undefined, availableNodes: Record<string, DialogueNode>): boolean;
|