@holoscript/core 2.0.1 → 2.0.2
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/LICENSE +21 -0
- package/dist/chunk-3N67RLQP.cjs +1298 -0
- package/dist/chunk-3N67RLQP.cjs.map +1 -0
- package/dist/chunk-3X2EGU7Z.cjs +52 -0
- package/dist/chunk-3X2EGU7Z.cjs.map +1 -0
- package/dist/chunk-4CV4JOE5.js +24 -0
- package/dist/chunk-4CV4JOE5.js.map +1 -0
- package/dist/chunk-4OHVW4XR.cjs +1027 -0
- package/dist/chunk-4OHVW4XR.cjs.map +1 -0
- package/dist/chunk-CZLDE2OZ.cjs +28 -0
- package/dist/chunk-CZLDE2OZ.cjs.map +1 -0
- package/{src/HoloScriptRuntime.ts → dist/chunk-EU6CZMGJ.js} +437 -794
- package/dist/chunk-EU6CZMGJ.js.map +1 -0
- package/dist/chunk-KWYIVRIH.js +344 -0
- package/dist/chunk-KWYIVRIH.js.map +1 -0
- package/dist/chunk-MCP6D4LT.js +1025 -0
- package/dist/chunk-MCP6D4LT.js.map +1 -0
- package/dist/chunk-SATNCODL.js +45 -0
- package/dist/chunk-SATNCODL.js.map +1 -0
- package/dist/chunk-VMZN4EVR.cjs +347 -0
- package/dist/chunk-VMZN4EVR.cjs.map +1 -0
- package/{src/HoloScriptDebugger.ts → dist/chunk-VYIDLUCV.js} +118 -257
- package/dist/chunk-VYIDLUCV.js.map +1 -0
- package/dist/chunk-WFI4T3XB.cjs +424 -0
- package/dist/chunk-WFI4T3XB.cjs.map +1 -0
- package/dist/debugger.cjs +20 -0
- package/dist/debugger.cjs.map +1 -0
- package/dist/debugger.d.cts +171 -0
- package/dist/debugger.d.ts +171 -0
- package/dist/debugger.js +7 -0
- package/dist/debugger.js.map +1 -0
- package/dist/index.cjs +6006 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +2482 -0
- package/dist/index.d.ts +2482 -0
- package/dist/index.js +5926 -0
- package/dist/index.js.map +1 -0
- package/dist/parser.cjs +14 -0
- package/dist/parser.cjs.map +1 -0
- package/dist/parser.d.cts +139 -0
- package/dist/parser.d.ts +139 -0
- package/dist/parser.js +5 -0
- package/dist/parser.js.map +1 -0
- package/dist/runtime.cjs +14 -0
- package/dist/runtime.cjs.map +1 -0
- package/dist/runtime.d.cts +180 -0
- package/dist/runtime.d.ts +180 -0
- package/dist/runtime.js +5 -0
- package/dist/runtime.js.map +1 -0
- package/dist/type-checker.cjs +17 -0
- package/dist/type-checker.cjs.map +1 -0
- package/dist/type-checker.d.cts +105 -0
- package/dist/type-checker.d.ts +105 -0
- package/dist/type-checker.js +4 -0
- package/dist/type-checker.js.map +1 -0
- package/dist/types-D6g4ACjP.d.cts +262 -0
- package/dist/types-D6g4ACjP.d.ts +262 -0
- package/package.json +11 -8
- package/src/HoloScript2DParser.js +0 -227
- package/src/HoloScript2DParser.ts +0 -261
- package/src/HoloScriptCodeParser.js +0 -1102
- package/src/HoloScriptCodeParser.ts +0 -1188
- package/src/HoloScriptDebugger.js +0 -458
- package/src/HoloScriptParser.js +0 -338
- package/src/HoloScriptParser.ts +0 -397
- package/src/HoloScriptPlusParser.js +0 -371
- package/src/HoloScriptPlusParser.ts +0 -543
- package/src/HoloScriptRuntime.js +0 -1399
- package/src/HoloScriptRuntime.test.js +0 -351
- package/src/HoloScriptRuntime.test.ts +0 -436
- package/src/HoloScriptTypeChecker.js +0 -356
- package/src/HoloScriptTypeChecker.ts +0 -475
- package/src/__tests__/GraphicsServices.test.js +0 -357
- package/src/__tests__/GraphicsServices.test.ts +0 -427
- package/src/__tests__/HoloScriptPlusParser.test.js +0 -317
- package/src/__tests__/HoloScriptPlusParser.test.ts +0 -392
- package/src/__tests__/integration.test.js +0 -336
- package/src/__tests__/integration.test.ts +0 -416
- package/src/__tests__/performance.bench.js +0 -218
- package/src/__tests__/performance.bench.ts +0 -262
- package/src/__tests__/type-checker.test.js +0 -60
- package/src/__tests__/type-checker.test.ts +0 -73
- package/src/index.js +0 -217
- package/src/index.ts +0 -426
- package/src/interop/Interoperability.js +0 -413
- package/src/interop/Interoperability.ts +0 -494
- package/src/logger.js +0 -42
- package/src/logger.ts +0 -57
- package/src/parser/EnhancedParser.js +0 -205
- package/src/parser/EnhancedParser.ts +0 -251
- package/src/parser/HoloScriptPlusParser.js +0 -928
- package/src/parser/HoloScriptPlusParser.ts +0 -1089
- package/src/runtime/HoloScriptPlusRuntime.js +0 -674
- package/src/runtime/HoloScriptPlusRuntime.ts +0 -861
- package/src/runtime/PerformanceTelemetry.js +0 -323
- package/src/runtime/PerformanceTelemetry.ts +0 -467
- package/src/runtime/RuntimeOptimization.js +0 -361
- package/src/runtime/RuntimeOptimization.ts +0 -416
- package/src/services/HololandGraphicsPipelineService.js +0 -506
- package/src/services/HololandGraphicsPipelineService.ts +0 -662
- package/src/services/PlatformPerformanceOptimizer.js +0 -356
- package/src/services/PlatformPerformanceOptimizer.ts +0 -503
- package/src/state/ReactiveState.js +0 -427
- package/src/state/ReactiveState.ts +0 -572
- package/src/tools/DeveloperExperience.js +0 -376
- package/src/tools/DeveloperExperience.ts +0 -438
- package/src/traits/AIDriverTrait.js +0 -322
- package/src/traits/AIDriverTrait.test.js +0 -329
- package/src/traits/AIDriverTrait.test.ts +0 -357
- package/src/traits/AIDriverTrait.ts +0 -474
- package/src/traits/LightingTrait.js +0 -313
- package/src/traits/LightingTrait.test.js +0 -410
- package/src/traits/LightingTrait.test.ts +0 -462
- package/src/traits/LightingTrait.ts +0 -505
- package/src/traits/MaterialTrait.js +0 -194
- package/src/traits/MaterialTrait.test.js +0 -286
- package/src/traits/MaterialTrait.test.ts +0 -329
- package/src/traits/MaterialTrait.ts +0 -324
- package/src/traits/RenderingTrait.js +0 -356
- package/src/traits/RenderingTrait.test.js +0 -363
- package/src/traits/RenderingTrait.test.ts +0 -427
- package/src/traits/RenderingTrait.ts +0 -555
- package/src/traits/VRTraitSystem.js +0 -740
- package/src/traits/VRTraitSystem.ts +0 -1040
- package/src/traits/VoiceInputTrait.js +0 -284
- package/src/traits/VoiceInputTrait.test.js +0 -226
- package/src/traits/VoiceInputTrait.test.ts +0 -252
- package/src/traits/VoiceInputTrait.ts +0 -401
- package/src/types/AdvancedTypeSystem.js +0 -226
- package/src/types/AdvancedTypeSystem.ts +0 -494
- package/src/types/HoloScriptPlus.d.ts +0 -853
- package/src/types.js +0 -6
- package/src/types.ts +0 -369
- package/tsconfig.json +0 -23
- package/tsup.config.d.ts +0 -2
- package/tsup.config.js +0 -18
- package/tsup.config.ts +0 -19
package/src/HoloScriptRuntime.js
DELETED
|
@@ -1,1399 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* HoloScript Runtime Engine
|
|
3
|
-
*
|
|
4
|
-
* Executes HoloScript AST in VR environment with spatial computation.
|
|
5
|
-
* Supports:
|
|
6
|
-
* - Orb creation and manipulation
|
|
7
|
-
* - Function definition and invocation with arguments
|
|
8
|
-
* - Connections and reactive data flow
|
|
9
|
-
* - Gates (conditionals)
|
|
10
|
-
* - Streams (data pipelines)
|
|
11
|
-
* - 2D UI elements
|
|
12
|
-
* - Built-in commands (show, hide, animate, pulse)
|
|
13
|
-
* - Expression evaluation
|
|
14
|
-
* - Event system
|
|
15
|
-
*/
|
|
16
|
-
import { logger } from './logger';
|
|
17
|
-
const RUNTIME_SECURITY_LIMITS = {
|
|
18
|
-
maxExecutionDepth: 50,
|
|
19
|
-
maxTotalNodes: 1000,
|
|
20
|
-
maxExecutionTimeMs: 5000,
|
|
21
|
-
maxParticlesPerSystem: 1000,
|
|
22
|
-
maxStringLength: 10000,
|
|
23
|
-
maxCallStackDepth: 100,
|
|
24
|
-
};
|
|
25
|
-
export class HoloScriptRuntime {
|
|
26
|
-
constructor(_importLoader) {
|
|
27
|
-
this.particleSystems = new Map();
|
|
28
|
-
this.executionHistory = [];
|
|
29
|
-
this.startTime = 0;
|
|
30
|
-
this.nodeCount = 0;
|
|
31
|
-
this.callStack = [];
|
|
32
|
-
this.eventHandlers = new Map();
|
|
33
|
-
this.animations = new Map();
|
|
34
|
-
this.uiElements = new Map();
|
|
35
|
-
this.context = this.createEmptyContext();
|
|
36
|
-
this.currentScope = { variables: this.context.variables };
|
|
37
|
-
this.builtinFunctions = this.initBuiltins();
|
|
38
|
-
}
|
|
39
|
-
/**
|
|
40
|
-
* Initialize built-in functions
|
|
41
|
-
*/
|
|
42
|
-
initBuiltins() {
|
|
43
|
-
const builtins = new Map();
|
|
44
|
-
// Display commands
|
|
45
|
-
builtins.set('show', (args) => {
|
|
46
|
-
const target = String(args[0]);
|
|
47
|
-
const element = this.uiElements.get(target);
|
|
48
|
-
if (element)
|
|
49
|
-
element.visible = true;
|
|
50
|
-
const hologram = this.context.hologramState.get(target);
|
|
51
|
-
if (hologram) {
|
|
52
|
-
this.createParticleEffect(`${target}_show`, { x: 0, y: 0, z: 0 }, hologram.color, 15);
|
|
53
|
-
}
|
|
54
|
-
logger.info('show', { target });
|
|
55
|
-
return { shown: target };
|
|
56
|
-
});
|
|
57
|
-
builtins.set('hide', (args) => {
|
|
58
|
-
const target = String(args[0]);
|
|
59
|
-
const element = this.uiElements.get(target);
|
|
60
|
-
if (element)
|
|
61
|
-
element.visible = false;
|
|
62
|
-
logger.info('hide', { target });
|
|
63
|
-
return { hidden: target };
|
|
64
|
-
});
|
|
65
|
-
// Animation commands
|
|
66
|
-
builtins.set('pulse', (args) => {
|
|
67
|
-
const target = String(args[0]);
|
|
68
|
-
const options = args[1] || {};
|
|
69
|
-
const duration = Number(options.duration) || 1000;
|
|
70
|
-
const color = String(options.color || '#ffffff');
|
|
71
|
-
const position = this.context.spatialMemory.get(target) || { x: 0, y: 0, z: 0 };
|
|
72
|
-
this.createParticleEffect(`${target}_pulse`, position, color, 30);
|
|
73
|
-
return { pulsing: target, duration };
|
|
74
|
-
});
|
|
75
|
-
builtins.set('animate', (args) => {
|
|
76
|
-
const target = String(args[0]);
|
|
77
|
-
const options = args[1] || {};
|
|
78
|
-
const animation = {
|
|
79
|
-
target,
|
|
80
|
-
property: String(options.property || 'position.y'),
|
|
81
|
-
from: Number(options.from || 0),
|
|
82
|
-
to: Number(options.to || 1),
|
|
83
|
-
duration: Number(options.duration || 1000),
|
|
84
|
-
startTime: Date.now(),
|
|
85
|
-
easing: String(options.easing || 'linear'),
|
|
86
|
-
loop: Boolean(options.loop),
|
|
87
|
-
yoyo: Boolean(options.yoyo),
|
|
88
|
-
};
|
|
89
|
-
this.animations.set(`${target}_${animation.property}`, animation);
|
|
90
|
-
return { animating: target, animation };
|
|
91
|
-
});
|
|
92
|
-
// Spatial commands
|
|
93
|
-
builtins.set('spawn', (args) => {
|
|
94
|
-
const target = String(args[0]);
|
|
95
|
-
const position = args[1] || { x: 0, y: 0, z: 0 };
|
|
96
|
-
this.context.spatialMemory.set(target, position);
|
|
97
|
-
this.createParticleEffect(`${target}_spawn`, position, '#00ff00', 25);
|
|
98
|
-
return { spawned: target, at: position };
|
|
99
|
-
});
|
|
100
|
-
builtins.set('move', (args) => {
|
|
101
|
-
const target = String(args[0]);
|
|
102
|
-
const position = args[1] || { x: 0, y: 0, z: 0 };
|
|
103
|
-
const current = this.context.spatialMemory.get(target);
|
|
104
|
-
if (current) {
|
|
105
|
-
this.context.spatialMemory.set(target, position);
|
|
106
|
-
this.createConnectionStream(target, `${target}_dest`, current, position, 'move');
|
|
107
|
-
}
|
|
108
|
-
return { moved: target, to: position };
|
|
109
|
-
});
|
|
110
|
-
// Data commands
|
|
111
|
-
builtins.set('set', (args) => {
|
|
112
|
-
const target = String(args[0]);
|
|
113
|
-
const value = args[1];
|
|
114
|
-
this.setVariable(target, value);
|
|
115
|
-
return { set: target, value };
|
|
116
|
-
});
|
|
117
|
-
builtins.set('get', (args) => {
|
|
118
|
-
const target = String(args[0]);
|
|
119
|
-
return this.getVariable(target);
|
|
120
|
-
});
|
|
121
|
-
// Math functions
|
|
122
|
-
builtins.set('add', (args) => Number(args[0]) + Number(args[1]));
|
|
123
|
-
builtins.set('subtract', (args) => Number(args[0]) - Number(args[1]));
|
|
124
|
-
builtins.set('multiply', (args) => Number(args[0]) * Number(args[1]));
|
|
125
|
-
builtins.set('divide', (args) => Number(args[1]) !== 0 ? Number(args[0]) / Number(args[1]) : 0);
|
|
126
|
-
builtins.set('mod', (args) => Number(args[0]) % Number(args[1]));
|
|
127
|
-
builtins.set('abs', (args) => Math.abs(Number(args[0])));
|
|
128
|
-
builtins.set('floor', (args) => Math.floor(Number(args[0])));
|
|
129
|
-
builtins.set('ceil', (args) => Math.ceil(Number(args[0])));
|
|
130
|
-
builtins.set('round', (args) => Math.round(Number(args[0])));
|
|
131
|
-
builtins.set('min', (args) => Math.min(...args.map(Number)));
|
|
132
|
-
builtins.set('max', (args) => Math.max(...args.map(Number)));
|
|
133
|
-
builtins.set('random', () => Math.random());
|
|
134
|
-
// String functions
|
|
135
|
-
builtins.set('concat', (args) => args.map(String).join(''));
|
|
136
|
-
builtins.set('length', (args) => {
|
|
137
|
-
const val = args[0];
|
|
138
|
-
if (typeof val === 'string')
|
|
139
|
-
return val.length;
|
|
140
|
-
if (Array.isArray(val))
|
|
141
|
-
return val.length;
|
|
142
|
-
return 0;
|
|
143
|
-
});
|
|
144
|
-
builtins.set('substring', (args) => String(args[0]).substring(Number(args[1]), Number(args[2])));
|
|
145
|
-
builtins.set('uppercase', (args) => String(args[0]).toUpperCase());
|
|
146
|
-
builtins.set('lowercase', (args) => String(args[0]).toLowerCase());
|
|
147
|
-
// Array functions
|
|
148
|
-
builtins.set('push', (args) => {
|
|
149
|
-
const arr = args[0];
|
|
150
|
-
if (Array.isArray(arr)) {
|
|
151
|
-
arr.push(args[1]);
|
|
152
|
-
return arr;
|
|
153
|
-
}
|
|
154
|
-
return [args[0], args[1]];
|
|
155
|
-
});
|
|
156
|
-
builtins.set('pop', (args) => {
|
|
157
|
-
const arr = args[0];
|
|
158
|
-
if (Array.isArray(arr))
|
|
159
|
-
return arr.pop();
|
|
160
|
-
return undefined;
|
|
161
|
-
});
|
|
162
|
-
builtins.set('at', (args) => {
|
|
163
|
-
const arr = args[0];
|
|
164
|
-
const index = Number(args[1]);
|
|
165
|
-
if (Array.isArray(arr))
|
|
166
|
-
return arr[index];
|
|
167
|
-
return undefined;
|
|
168
|
-
});
|
|
169
|
-
// Console/Debug
|
|
170
|
-
builtins.set('log', (args) => {
|
|
171
|
-
logger.info('HoloScript log', { args });
|
|
172
|
-
return args[0];
|
|
173
|
-
});
|
|
174
|
-
builtins.set('print', (args) => {
|
|
175
|
-
const message = args.map(String).join(' ');
|
|
176
|
-
logger.info('print', { message });
|
|
177
|
-
return message;
|
|
178
|
-
});
|
|
179
|
-
// Type checking
|
|
180
|
-
builtins.set('typeof', (args) => typeof args[0]);
|
|
181
|
-
builtins.set('isArray', (args) => Array.isArray(args[0]));
|
|
182
|
-
builtins.set('isNumber', (args) => typeof args[0] === 'number' && !isNaN(args[0]));
|
|
183
|
-
builtins.set('isString', (args) => typeof args[0] === 'string');
|
|
184
|
-
return builtins;
|
|
185
|
-
}
|
|
186
|
-
/**
|
|
187
|
-
* Execute a single AST node
|
|
188
|
-
*/
|
|
189
|
-
async executeNode(node) {
|
|
190
|
-
const startTime = Date.now();
|
|
191
|
-
try {
|
|
192
|
-
this.context.executionStack.push(node);
|
|
193
|
-
let result;
|
|
194
|
-
switch (node.type) {
|
|
195
|
-
case 'orb':
|
|
196
|
-
result = await this.executeOrb(node);
|
|
197
|
-
break;
|
|
198
|
-
case 'method':
|
|
199
|
-
case 'function':
|
|
200
|
-
result = await this.executeFunction(node);
|
|
201
|
-
break;
|
|
202
|
-
case 'connection':
|
|
203
|
-
result = await this.executeConnection(node);
|
|
204
|
-
break;
|
|
205
|
-
case 'gate':
|
|
206
|
-
result = await this.executeGate(node);
|
|
207
|
-
break;
|
|
208
|
-
case 'stream':
|
|
209
|
-
result = await this.executeStream(node);
|
|
210
|
-
break;
|
|
211
|
-
case 'execute':
|
|
212
|
-
case 'call':
|
|
213
|
-
result = await this.executeCall(node);
|
|
214
|
-
break;
|
|
215
|
-
case 'debug':
|
|
216
|
-
result = await this.executeDebug(node);
|
|
217
|
-
break;
|
|
218
|
-
case 'visualize':
|
|
219
|
-
result = await this.executeVisualize(node);
|
|
220
|
-
break;
|
|
221
|
-
case '2d-element':
|
|
222
|
-
result = await this.executeUIElement(node);
|
|
223
|
-
break;
|
|
224
|
-
case 'nexus':
|
|
225
|
-
case 'building':
|
|
226
|
-
result = await this.executeStructure(node);
|
|
227
|
-
break;
|
|
228
|
-
case 'assignment':
|
|
229
|
-
result = await this.executeAssignment(node);
|
|
230
|
-
break;
|
|
231
|
-
case 'return':
|
|
232
|
-
result = await this.executeReturn(node);
|
|
233
|
-
break;
|
|
234
|
-
case 'generic':
|
|
235
|
-
result = await this.executeGeneric(node);
|
|
236
|
-
break;
|
|
237
|
-
case 'expression-statement':
|
|
238
|
-
result = await this.executeCall(node);
|
|
239
|
-
break;
|
|
240
|
-
default:
|
|
241
|
-
result = {
|
|
242
|
-
success: false,
|
|
243
|
-
error: `Unknown node type: ${node.type}`,
|
|
244
|
-
executionTime: Date.now() - startTime,
|
|
245
|
-
};
|
|
246
|
-
}
|
|
247
|
-
result.executionTime = Date.now() - startTime;
|
|
248
|
-
this.executionHistory.push(result);
|
|
249
|
-
this.context.executionStack.pop();
|
|
250
|
-
return result;
|
|
251
|
-
}
|
|
252
|
-
catch (error) {
|
|
253
|
-
const execTime = Date.now() - startTime;
|
|
254
|
-
const errorResult = {
|
|
255
|
-
success: false,
|
|
256
|
-
error: error instanceof Error ? error.message : String(error),
|
|
257
|
-
executionTime: execTime,
|
|
258
|
-
};
|
|
259
|
-
this.executionHistory.push(errorResult);
|
|
260
|
-
this.context.executionStack.pop();
|
|
261
|
-
return errorResult;
|
|
262
|
-
}
|
|
263
|
-
}
|
|
264
|
-
/**
|
|
265
|
-
* Execute multiple nodes in sequence
|
|
266
|
-
*/
|
|
267
|
-
async executeProgram(nodes, depth = 0) {
|
|
268
|
-
if (depth === 0) {
|
|
269
|
-
this.startTime = Date.now();
|
|
270
|
-
this.nodeCount = 0;
|
|
271
|
-
}
|
|
272
|
-
if (depth > RUNTIME_SECURITY_LIMITS.maxExecutionDepth) {
|
|
273
|
-
logger.error('Max execution depth exceeded', { depth });
|
|
274
|
-
return [{
|
|
275
|
-
success: false,
|
|
276
|
-
error: `Max execution depth exceeded (${RUNTIME_SECURITY_LIMITS.maxExecutionDepth})`,
|
|
277
|
-
executionTime: 0,
|
|
278
|
-
}];
|
|
279
|
-
}
|
|
280
|
-
const results = [];
|
|
281
|
-
for (const node of nodes) {
|
|
282
|
-
this.nodeCount++;
|
|
283
|
-
if (this.nodeCount > RUNTIME_SECURITY_LIMITS.maxTotalNodes) {
|
|
284
|
-
logger.error('Max total nodes exceeded', { count: this.nodeCount });
|
|
285
|
-
results.push({
|
|
286
|
-
success: false,
|
|
287
|
-
error: 'Max total nodes exceeded',
|
|
288
|
-
executionTime: Date.now() - this.startTime,
|
|
289
|
-
});
|
|
290
|
-
break;
|
|
291
|
-
}
|
|
292
|
-
if (Date.now() - this.startTime > RUNTIME_SECURITY_LIMITS.maxExecutionTimeMs) {
|
|
293
|
-
logger.error('Execution timeout', { duration: Date.now() - this.startTime });
|
|
294
|
-
results.push({
|
|
295
|
-
success: false,
|
|
296
|
-
error: 'Execution timeout',
|
|
297
|
-
executionTime: Date.now() - this.startTime,
|
|
298
|
-
});
|
|
299
|
-
break;
|
|
300
|
-
}
|
|
301
|
-
const result = await this.executeNode(node);
|
|
302
|
-
results.push(result);
|
|
303
|
-
// Stop on error (except visualize) or return statement
|
|
304
|
-
if (!result.success && node.type !== 'visualize') {
|
|
305
|
-
break;
|
|
306
|
-
}
|
|
307
|
-
if (node.type === 'return') {
|
|
308
|
-
break;
|
|
309
|
-
}
|
|
310
|
-
}
|
|
311
|
-
return results;
|
|
312
|
-
}
|
|
313
|
-
/**
|
|
314
|
-
* Call a function with arguments
|
|
315
|
-
*/
|
|
316
|
-
async callFunction(name, args = []) {
|
|
317
|
-
// Check built-in functions first
|
|
318
|
-
const builtin = this.builtinFunctions.get(name);
|
|
319
|
-
if (builtin) {
|
|
320
|
-
try {
|
|
321
|
-
const result = builtin(args);
|
|
322
|
-
return {
|
|
323
|
-
success: true,
|
|
324
|
-
output: result,
|
|
325
|
-
};
|
|
326
|
-
}
|
|
327
|
-
catch (error) {
|
|
328
|
-
return {
|
|
329
|
-
success: false,
|
|
330
|
-
error: `Built-in function ${name} failed: ${error}`,
|
|
331
|
-
};
|
|
332
|
-
}
|
|
333
|
-
}
|
|
334
|
-
// Check user-defined functions
|
|
335
|
-
const func = this.context.functions.get(name);
|
|
336
|
-
if (!func) {
|
|
337
|
-
return {
|
|
338
|
-
success: false,
|
|
339
|
-
error: `Function '${name}' not found`,
|
|
340
|
-
};
|
|
341
|
-
}
|
|
342
|
-
// Check call stack depth
|
|
343
|
-
if (this.callStack.length >= RUNTIME_SECURITY_LIMITS.maxCallStackDepth) {
|
|
344
|
-
return {
|
|
345
|
-
success: false,
|
|
346
|
-
error: `Max call stack depth exceeded (${RUNTIME_SECURITY_LIMITS.maxCallStackDepth})`,
|
|
347
|
-
};
|
|
348
|
-
}
|
|
349
|
-
// Create new scope
|
|
350
|
-
const parentScope = this.currentScope;
|
|
351
|
-
this.currentScope = {
|
|
352
|
-
variables: new Map(),
|
|
353
|
-
parent: parentScope,
|
|
354
|
-
};
|
|
355
|
-
// Bind parameters
|
|
356
|
-
func.parameters.forEach((param, index) => {
|
|
357
|
-
const value = index < args.length ? args[index] : param.defaultValue;
|
|
358
|
-
this.currentScope.variables.set(param.name, value);
|
|
359
|
-
});
|
|
360
|
-
// Push to call stack
|
|
361
|
-
this.callStack.push(name);
|
|
362
|
-
// Execute function body
|
|
363
|
-
let returnValue = undefined;
|
|
364
|
-
try {
|
|
365
|
-
const results = await this.executeProgram(func.body, this.callStack.length);
|
|
366
|
-
const lastResult = results[results.length - 1];
|
|
367
|
-
if (lastResult?.output !== undefined) {
|
|
368
|
-
returnValue = lastResult.output;
|
|
369
|
-
}
|
|
370
|
-
// Visual effect
|
|
371
|
-
this.createExecutionEffect(name, func.position || { x: 0, y: 0, z: 0 });
|
|
372
|
-
return {
|
|
373
|
-
success: results.every(r => r.success),
|
|
374
|
-
output: returnValue,
|
|
375
|
-
hologram: func.hologram,
|
|
376
|
-
spatialPosition: func.position,
|
|
377
|
-
};
|
|
378
|
-
}
|
|
379
|
-
finally {
|
|
380
|
-
// Restore scope
|
|
381
|
-
this.currentScope = parentScope;
|
|
382
|
-
this.callStack.pop();
|
|
383
|
-
}
|
|
384
|
-
}
|
|
385
|
-
/**
|
|
386
|
-
* Set a variable in current scope
|
|
387
|
-
*/
|
|
388
|
-
setVariable(name, value) {
|
|
389
|
-
// Handle property access (e.g., "obj.prop")
|
|
390
|
-
if (name.includes('.')) {
|
|
391
|
-
const parts = name.split('.');
|
|
392
|
-
const objName = parts[0];
|
|
393
|
-
const propPath = parts.slice(1);
|
|
394
|
-
let obj = this.getVariable(objName);
|
|
395
|
-
if (obj === undefined || typeof obj !== 'object' || obj === null) {
|
|
396
|
-
obj = {};
|
|
397
|
-
this.currentScope.variables.set(objName, obj);
|
|
398
|
-
}
|
|
399
|
-
let current = obj;
|
|
400
|
-
for (let i = 0; i < propPath.length - 1; i++) {
|
|
401
|
-
if (current[propPath[i]] === undefined || typeof current[propPath[i]] !== 'object') {
|
|
402
|
-
current[propPath[i]] = {};
|
|
403
|
-
}
|
|
404
|
-
current = current[propPath[i]];
|
|
405
|
-
}
|
|
406
|
-
current[propPath[propPath.length - 1]] = value;
|
|
407
|
-
}
|
|
408
|
-
else {
|
|
409
|
-
this.currentScope.variables.set(name, value);
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
/**
|
|
413
|
-
* Get a variable from scope chain
|
|
414
|
-
*/
|
|
415
|
-
getVariable(name) {
|
|
416
|
-
// Handle property access (e.g., "obj.prop")
|
|
417
|
-
if (name.includes('.')) {
|
|
418
|
-
const parts = name.split('.');
|
|
419
|
-
let value = this.getVariable(parts[0]);
|
|
420
|
-
for (let i = 1; i < parts.length && value !== undefined; i++) {
|
|
421
|
-
if (typeof value === 'object' && value !== null) {
|
|
422
|
-
value = value[parts[i]];
|
|
423
|
-
}
|
|
424
|
-
else {
|
|
425
|
-
return undefined;
|
|
426
|
-
}
|
|
427
|
-
}
|
|
428
|
-
return value;
|
|
429
|
-
}
|
|
430
|
-
// Walk scope chain
|
|
431
|
-
let scope = this.currentScope;
|
|
432
|
-
while (scope) {
|
|
433
|
-
if (scope.variables.has(name)) {
|
|
434
|
-
return scope.variables.get(name);
|
|
435
|
-
}
|
|
436
|
-
scope = scope.parent;
|
|
437
|
-
}
|
|
438
|
-
// Check context variables
|
|
439
|
-
if (this.context.variables.has(name)) {
|
|
440
|
-
return this.context.variables.get(name);
|
|
441
|
-
}
|
|
442
|
-
// Fallback to functions map (for imported functions)
|
|
443
|
-
if (this.context.functions.has(name)) {
|
|
444
|
-
return this.context.functions.get(name);
|
|
445
|
-
}
|
|
446
|
-
return undefined;
|
|
447
|
-
}
|
|
448
|
-
/**
|
|
449
|
-
* Evaluate an expression
|
|
450
|
-
*/
|
|
451
|
-
evaluateExpression(expr) {
|
|
452
|
-
if (!expr || typeof expr !== 'string')
|
|
453
|
-
return expr;
|
|
454
|
-
expr = expr.trim();
|
|
455
|
-
// Security check
|
|
456
|
-
const suspicious = ['eval', 'process', 'require', '__proto__', 'constructor', 'Function'];
|
|
457
|
-
if (suspicious.some(kw => expr.toLowerCase().includes(kw))) {
|
|
458
|
-
logger.warn('Suspicious expression blocked', { expr });
|
|
459
|
-
return undefined;
|
|
460
|
-
}
|
|
461
|
-
// String literal
|
|
462
|
-
if ((expr.startsWith('"') && expr.endsWith('"')) || (expr.startsWith("'") && expr.endsWith("'"))) {
|
|
463
|
-
return expr.slice(1, -1);
|
|
464
|
-
}
|
|
465
|
-
// Number literal
|
|
466
|
-
if (/^-?\d+(\.\d+)?$/.test(expr)) {
|
|
467
|
-
return parseFloat(expr);
|
|
468
|
-
}
|
|
469
|
-
// Boolean literal
|
|
470
|
-
if (expr === 'true')
|
|
471
|
-
return true;
|
|
472
|
-
if (expr === 'false')
|
|
473
|
-
return false;
|
|
474
|
-
if (expr === 'null')
|
|
475
|
-
return null;
|
|
476
|
-
if (expr === 'undefined')
|
|
477
|
-
return undefined;
|
|
478
|
-
// Array literal [a, b, c]
|
|
479
|
-
if (expr.startsWith('[') && expr.endsWith(']')) {
|
|
480
|
-
const inner = expr.slice(1, -1);
|
|
481
|
-
if (!inner.trim())
|
|
482
|
-
return [];
|
|
483
|
-
const elements = this.splitByComma(inner);
|
|
484
|
-
return elements.map(e => this.evaluateExpression(e.trim()));
|
|
485
|
-
}
|
|
486
|
-
// Object literal {a: 1, b: 2}
|
|
487
|
-
if (expr.startsWith('{') && expr.endsWith('}')) {
|
|
488
|
-
const inner = expr.slice(1, -1);
|
|
489
|
-
if (!inner.trim())
|
|
490
|
-
return {};
|
|
491
|
-
const pairs = this.splitByComma(inner);
|
|
492
|
-
const obj = {};
|
|
493
|
-
for (const pair of pairs) {
|
|
494
|
-
const colonIndex = pair.indexOf(':');
|
|
495
|
-
if (colonIndex > 0) {
|
|
496
|
-
const key = pair.slice(0, colonIndex).trim();
|
|
497
|
-
const value = pair.slice(colonIndex + 1).trim();
|
|
498
|
-
obj[key] = this.evaluateExpression(value);
|
|
499
|
-
}
|
|
500
|
-
}
|
|
501
|
-
return obj;
|
|
502
|
-
}
|
|
503
|
-
// Function call: name(args)
|
|
504
|
-
const funcMatch = expr.match(/^(\w+)\s*\((.*)?\)$/);
|
|
505
|
-
if (funcMatch) {
|
|
506
|
-
const [, funcName, argsStr] = funcMatch;
|
|
507
|
-
const args = argsStr ? this.splitByComma(argsStr).map(a => this.evaluateExpression(a.trim())) : [];
|
|
508
|
-
// Check builtins
|
|
509
|
-
const builtin = this.builtinFunctions.get(funcName);
|
|
510
|
-
if (builtin) {
|
|
511
|
-
return builtin(args);
|
|
512
|
-
}
|
|
513
|
-
// Check user functions (but don't execute - just reference)
|
|
514
|
-
if (this.context.functions.has(funcName)) {
|
|
515
|
-
// For async execution, return a promise marker
|
|
516
|
-
return { __holoCall: funcName, args };
|
|
517
|
-
}
|
|
518
|
-
return undefined;
|
|
519
|
-
}
|
|
520
|
-
// Binary operations: a + b, a - b, etc.
|
|
521
|
-
const binaryOps = [
|
|
522
|
-
{ pattern: /(.+)\s*\+\s*(.+)/, op: (a, b) => Number(a) + Number(b) },
|
|
523
|
-
{ pattern: /(.+)\s*-\s*(.+)/, op: (a, b) => Number(a) - Number(b) },
|
|
524
|
-
{ pattern: /(.+)\s*\*\s*(.+)/, op: (a, b) => Number(a) * Number(b) },
|
|
525
|
-
{ pattern: /(.+)\s*\/\s*(.+)/, op: (a, b) => Number(b) !== 0 ? Number(a) / Number(b) : 0 },
|
|
526
|
-
{ pattern: /(.+)\s*%\s*(.+)/, op: (a, b) => Number(a) % Number(b) },
|
|
527
|
-
];
|
|
528
|
-
for (const { pattern, op } of binaryOps) {
|
|
529
|
-
const match = expr.match(pattern);
|
|
530
|
-
if (match) {
|
|
531
|
-
const left = this.evaluateExpression(match[1]);
|
|
532
|
-
const right = this.evaluateExpression(match[2]);
|
|
533
|
-
return op(left, right);
|
|
534
|
-
}
|
|
535
|
-
}
|
|
536
|
-
// Variable reference
|
|
537
|
-
return this.getVariable(expr);
|
|
538
|
-
}
|
|
539
|
-
/**
|
|
540
|
-
* Split string by comma, respecting nesting
|
|
541
|
-
*/
|
|
542
|
-
splitByComma(str) {
|
|
543
|
-
const parts = [];
|
|
544
|
-
let current = '';
|
|
545
|
-
let depth = 0;
|
|
546
|
-
let inString = false;
|
|
547
|
-
let stringChar = '';
|
|
548
|
-
for (let i = 0; i < str.length; i++) {
|
|
549
|
-
const char = str[i];
|
|
550
|
-
if (!inString && (char === '"' || char === "'")) {
|
|
551
|
-
inString = true;
|
|
552
|
-
stringChar = char;
|
|
553
|
-
}
|
|
554
|
-
else if (inString && char === stringChar && str[i - 1] !== '\\') {
|
|
555
|
-
inString = false;
|
|
556
|
-
}
|
|
557
|
-
if (!inString) {
|
|
558
|
-
if (char === '(' || char === '[' || char === '{')
|
|
559
|
-
depth++;
|
|
560
|
-
if (char === ')' || char === ']' || char === '}')
|
|
561
|
-
depth--;
|
|
562
|
-
if (char === ',' && depth === 0) {
|
|
563
|
-
parts.push(current.trim());
|
|
564
|
-
current = '';
|
|
565
|
-
continue;
|
|
566
|
-
}
|
|
567
|
-
}
|
|
568
|
-
current += char;
|
|
569
|
-
}
|
|
570
|
-
if (current.trim()) {
|
|
571
|
-
parts.push(current.trim());
|
|
572
|
-
}
|
|
573
|
-
return parts;
|
|
574
|
-
}
|
|
575
|
-
// ============================================================================
|
|
576
|
-
// Node Executors
|
|
577
|
-
// ============================================================================
|
|
578
|
-
async executeOrb(node) {
|
|
579
|
-
if (node.position) {
|
|
580
|
-
this.context.spatialMemory.set(node.name, node.position);
|
|
581
|
-
}
|
|
582
|
-
// Create orb object with reactive properties
|
|
583
|
-
const orbData = {
|
|
584
|
-
__type: 'orb',
|
|
585
|
-
name: node.name,
|
|
586
|
-
properties: { ...node.properties },
|
|
587
|
-
position: node.position || { x: 0, y: 0, z: 0 },
|
|
588
|
-
hologram: node.hologram,
|
|
589
|
-
created: Date.now(),
|
|
590
|
-
// Methods bound to this orb
|
|
591
|
-
show: () => this.builtinFunctions.get('show')([node.name]),
|
|
592
|
-
hide: () => this.builtinFunctions.get('hide')([node.name]),
|
|
593
|
-
pulse: (opts) => this.builtinFunctions.get('pulse')([node.name, opts]),
|
|
594
|
-
};
|
|
595
|
-
this.context.variables.set(node.name, orbData);
|
|
596
|
-
if (node.hologram) {
|
|
597
|
-
this.context.hologramState.set(node.name, node.hologram);
|
|
598
|
-
}
|
|
599
|
-
this.createParticleEffect(`${node.name}_creation`, node.position || { x: 0, y: 0, z: 0 }, '#00ffff', 20);
|
|
600
|
-
logger.info('Orb created', { name: node.name, properties: Object.keys(node.properties) });
|
|
601
|
-
return {
|
|
602
|
-
success: true,
|
|
603
|
-
output: orbData,
|
|
604
|
-
hologram: node.hologram,
|
|
605
|
-
spatialPosition: node.position,
|
|
606
|
-
};
|
|
607
|
-
}
|
|
608
|
-
async executeFunction(node) {
|
|
609
|
-
this.context.functions.set(node.name, node);
|
|
610
|
-
const hologram = {
|
|
611
|
-
shape: 'cube',
|
|
612
|
-
color: '#ff6b35',
|
|
613
|
-
size: 1.5,
|
|
614
|
-
glow: true,
|
|
615
|
-
interactive: true,
|
|
616
|
-
...node.hologram,
|
|
617
|
-
};
|
|
618
|
-
this.context.hologramState.set(node.name, hologram);
|
|
619
|
-
logger.info('Function defined', { name: node.name, params: node.parameters.map(p => p.name) });
|
|
620
|
-
return {
|
|
621
|
-
success: true,
|
|
622
|
-
output: `Function '${node.name}' defined with ${node.parameters.length} parameter(s)`,
|
|
623
|
-
hologram,
|
|
624
|
-
spatialPosition: node.position,
|
|
625
|
-
};
|
|
626
|
-
}
|
|
627
|
-
async executeConnection(node) {
|
|
628
|
-
this.context.connections.push(node);
|
|
629
|
-
const fromPos = this.context.spatialMemory.get(node.from);
|
|
630
|
-
const toPos = this.context.spatialMemory.get(node.to);
|
|
631
|
-
if (fromPos && toPos) {
|
|
632
|
-
this.createConnectionStream(node.from, node.to, fromPos, toPos, node.dataType);
|
|
633
|
-
}
|
|
634
|
-
// Set up reactive binding if bidirectional
|
|
635
|
-
if (node.bidirectional) {
|
|
636
|
-
// When 'from' changes, update 'to'
|
|
637
|
-
this.on(`${node.from}.changed`, async (data) => {
|
|
638
|
-
this.setVariable(node.to, data);
|
|
639
|
-
this.emit(`${node.to}.changed`, data);
|
|
640
|
-
});
|
|
641
|
-
// When 'to' changes, update 'from'
|
|
642
|
-
this.on(`${node.to}.changed`, async (data) => {
|
|
643
|
-
this.setVariable(node.from, data);
|
|
644
|
-
this.emit(`${node.from}.changed`, data);
|
|
645
|
-
});
|
|
646
|
-
}
|
|
647
|
-
logger.info('Connection created', { from: node.from, to: node.to, dataType: node.dataType });
|
|
648
|
-
return {
|
|
649
|
-
success: true,
|
|
650
|
-
output: `Connected '${node.from}' to '${node.to}' (${node.dataType})`,
|
|
651
|
-
hologram: {
|
|
652
|
-
shape: 'cylinder',
|
|
653
|
-
color: this.getDataTypeColor(node.dataType),
|
|
654
|
-
size: 0.1,
|
|
655
|
-
glow: true,
|
|
656
|
-
interactive: false,
|
|
657
|
-
},
|
|
658
|
-
};
|
|
659
|
-
}
|
|
660
|
-
async executeGate(node) {
|
|
661
|
-
try {
|
|
662
|
-
const condition = this.evaluateCondition(node.condition);
|
|
663
|
-
const path = condition ? node.truePath : node.falsePath;
|
|
664
|
-
logger.info('Gate evaluation', { condition: node.condition, result: condition });
|
|
665
|
-
if (path.length > 0) {
|
|
666
|
-
await this.executeProgram(path, this.callStack.length + 1);
|
|
667
|
-
}
|
|
668
|
-
return {
|
|
669
|
-
success: true,
|
|
670
|
-
output: `Gate: took ${condition ? 'true' : 'false'} path`,
|
|
671
|
-
hologram: {
|
|
672
|
-
shape: 'pyramid',
|
|
673
|
-
color: condition ? '#00ff00' : '#ff0000',
|
|
674
|
-
size: 1,
|
|
675
|
-
glow: true,
|
|
676
|
-
interactive: true,
|
|
677
|
-
},
|
|
678
|
-
};
|
|
679
|
-
}
|
|
680
|
-
catch (error) {
|
|
681
|
-
return {
|
|
682
|
-
success: false,
|
|
683
|
-
error: `Gate execution failed: ${error}`,
|
|
684
|
-
};
|
|
685
|
-
}
|
|
686
|
-
}
|
|
687
|
-
async executeStream(node) {
|
|
688
|
-
let data = this.getVariable(node.source);
|
|
689
|
-
logger.info('Stream processing', { name: node.name, source: node.source, transforms: node.transformations.length });
|
|
690
|
-
for (const transform of node.transformations) {
|
|
691
|
-
data = await this.applyTransformation(data, transform);
|
|
692
|
-
}
|
|
693
|
-
this.setVariable(`${node.name}_result`, data);
|
|
694
|
-
this.createFlowingStream(node.name, node.position || { x: 0, y: 0, z: 0 }, data);
|
|
695
|
-
return {
|
|
696
|
-
success: true,
|
|
697
|
-
output: `Stream '${node.name}' processed ${Array.isArray(data) ? data.length : 1} item(s)`,
|
|
698
|
-
hologram: node.hologram,
|
|
699
|
-
spatialPosition: node.position,
|
|
700
|
-
};
|
|
701
|
-
}
|
|
702
|
-
async executeCall(node) {
|
|
703
|
-
const funcName = node.target || '';
|
|
704
|
-
const args = node.args || [];
|
|
705
|
-
return this.callFunction(funcName, args);
|
|
706
|
-
}
|
|
707
|
-
async executeDebug(node) {
|
|
708
|
-
const debugInfo = {
|
|
709
|
-
variables: Object.fromEntries(this.currentScope.variables),
|
|
710
|
-
contextVariables: Object.fromEntries(this.context.variables),
|
|
711
|
-
functions: Array.from(this.context.functions.keys()),
|
|
712
|
-
connections: this.context.connections.length,
|
|
713
|
-
callStack: [...this.callStack],
|
|
714
|
-
uiElements: Array.from(this.uiElements.keys()),
|
|
715
|
-
animations: Array.from(this.animations.keys()),
|
|
716
|
-
executionHistory: this.executionHistory.slice(-10),
|
|
717
|
-
};
|
|
718
|
-
const debugOrb = {
|
|
719
|
-
shape: 'pyramid',
|
|
720
|
-
color: '#ff1493',
|
|
721
|
-
size: 0.8,
|
|
722
|
-
glow: true,
|
|
723
|
-
interactive: true,
|
|
724
|
-
};
|
|
725
|
-
this.context.hologramState.set(`debug_${node.target || 'program'}`, debugOrb);
|
|
726
|
-
logger.info('Debug info', debugInfo);
|
|
727
|
-
return {
|
|
728
|
-
success: true,
|
|
729
|
-
output: debugInfo,
|
|
730
|
-
hologram: debugOrb,
|
|
731
|
-
};
|
|
732
|
-
}
|
|
733
|
-
async executeVisualize(node) {
|
|
734
|
-
const target = node.target || '';
|
|
735
|
-
const data = this.getVariable(target);
|
|
736
|
-
if (data === undefined) {
|
|
737
|
-
return {
|
|
738
|
-
success: false,
|
|
739
|
-
error: `No data found for '${target}'`,
|
|
740
|
-
};
|
|
741
|
-
}
|
|
742
|
-
const visHologram = {
|
|
743
|
-
shape: 'cylinder',
|
|
744
|
-
color: '#32cd32',
|
|
745
|
-
size: 1.5,
|
|
746
|
-
glow: true,
|
|
747
|
-
interactive: true,
|
|
748
|
-
};
|
|
749
|
-
this.createDataVisualization(target, data, node.position || { x: 0, y: 0, z: 0 });
|
|
750
|
-
return {
|
|
751
|
-
success: true,
|
|
752
|
-
output: { visualizing: target, data },
|
|
753
|
-
hologram: visHologram,
|
|
754
|
-
};
|
|
755
|
-
}
|
|
756
|
-
async executeUIElement(node) {
|
|
757
|
-
const element = {
|
|
758
|
-
type: node.elementType,
|
|
759
|
-
name: node.name,
|
|
760
|
-
properties: { ...node.properties },
|
|
761
|
-
visible: true,
|
|
762
|
-
enabled: true,
|
|
763
|
-
};
|
|
764
|
-
// Set initial value based on element type
|
|
765
|
-
if (node.elementType === 'textinput') {
|
|
766
|
-
element.value = node.properties.value || '';
|
|
767
|
-
}
|
|
768
|
-
else if (node.elementType === 'slider') {
|
|
769
|
-
element.value = node.properties.value || node.properties.min || 0;
|
|
770
|
-
}
|
|
771
|
-
else if (node.elementType === 'toggle') {
|
|
772
|
-
element.value = node.properties.checked || false;
|
|
773
|
-
}
|
|
774
|
-
this.uiElements.set(node.name, element);
|
|
775
|
-
// Register event handlers
|
|
776
|
-
if (node.events) {
|
|
777
|
-
for (const [eventName, handlerName] of Object.entries(node.events)) {
|
|
778
|
-
this.on(`${node.name}.${eventName}`, async () => {
|
|
779
|
-
await this.callFunction(handlerName);
|
|
780
|
-
});
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
|
-
logger.info('UI element created', { type: node.elementType, name: node.name });
|
|
784
|
-
return {
|
|
785
|
-
success: true,
|
|
786
|
-
output: element,
|
|
787
|
-
};
|
|
788
|
-
}
|
|
789
|
-
/**
|
|
790
|
-
* Execute generic voice commands
|
|
791
|
-
* Handles commands like: show, hide, animate, pulse, create
|
|
792
|
-
*/
|
|
793
|
-
async executeGeneric(_node) {
|
|
794
|
-
const genericNode = _node;
|
|
795
|
-
const command = String(genericNode.command || '').trim().toLowerCase();
|
|
796
|
-
const tokens = command.split(/\s+/);
|
|
797
|
-
const action = tokens[0];
|
|
798
|
-
const target = tokens[1];
|
|
799
|
-
logger.info('Executing generic command', { command, action, target });
|
|
800
|
-
try {
|
|
801
|
-
let result;
|
|
802
|
-
switch (action) {
|
|
803
|
-
case 'show':
|
|
804
|
-
result = await this.executeShowCommand(target, genericNode);
|
|
805
|
-
break;
|
|
806
|
-
case 'hide':
|
|
807
|
-
result = await this.executeHideCommand(target, genericNode);
|
|
808
|
-
break;
|
|
809
|
-
case 'create':
|
|
810
|
-
case 'summon':
|
|
811
|
-
result = await this.executeCreateCommand(tokens.slice(1), genericNode);
|
|
812
|
-
break;
|
|
813
|
-
case 'animate':
|
|
814
|
-
result = await this.executeAnimateCommand(target, tokens.slice(2), genericNode);
|
|
815
|
-
break;
|
|
816
|
-
case 'pulse':
|
|
817
|
-
result = await this.executePulseCommand(target, tokens.slice(2), genericNode);
|
|
818
|
-
break;
|
|
819
|
-
case 'move':
|
|
820
|
-
result = await this.executeMoveCommand(target, tokens.slice(2), genericNode);
|
|
821
|
-
break;
|
|
822
|
-
case 'delete':
|
|
823
|
-
case 'remove':
|
|
824
|
-
result = await this.executeDeleteCommand(target, genericNode);
|
|
825
|
-
break;
|
|
826
|
-
default:
|
|
827
|
-
// Default: create visual representation of the generic command
|
|
828
|
-
logger.warn('Unknown voice command action', { action, command });
|
|
829
|
-
result = {
|
|
830
|
-
executed: false,
|
|
831
|
-
message: `Unknown command: ${action}`,
|
|
832
|
-
};
|
|
833
|
-
}
|
|
834
|
-
return {
|
|
835
|
-
success: true,
|
|
836
|
-
output: result,
|
|
837
|
-
};
|
|
838
|
-
}
|
|
839
|
-
catch (error) {
|
|
840
|
-
return {
|
|
841
|
-
success: false,
|
|
842
|
-
error: `Generic command execution failed: ${String(error)}`,
|
|
843
|
-
};
|
|
844
|
-
}
|
|
845
|
-
}
|
|
846
|
-
/**
|
|
847
|
-
* Execute 'show' command
|
|
848
|
-
*/
|
|
849
|
-
async executeShowCommand(target, _node) {
|
|
850
|
-
// Create or show orb for this target
|
|
851
|
-
const hologram = _node.hologram || {
|
|
852
|
-
shape: 'orb',
|
|
853
|
-
color: '#00ffff',
|
|
854
|
-
size: 0.8,
|
|
855
|
-
glow: true,
|
|
856
|
-
interactive: true,
|
|
857
|
-
};
|
|
858
|
-
const position = _node.position || { x: 0, y: 0, z: 0 };
|
|
859
|
-
this.context.spatialMemory.set(target, position);
|
|
860
|
-
this.createParticleEffect(`${target}_show`, position, hologram.color, 15);
|
|
861
|
-
logger.info('Show command executed', { target, position });
|
|
862
|
-
return {
|
|
863
|
-
showed: target,
|
|
864
|
-
hologram,
|
|
865
|
-
position,
|
|
866
|
-
};
|
|
867
|
-
}
|
|
868
|
-
/**
|
|
869
|
-
* Execute 'hide' command
|
|
870
|
-
*/
|
|
871
|
-
async executeHideCommand(target, _node) {
|
|
872
|
-
const position = this.context.spatialMemory.get(target) || { x: 0, y: 0, z: 0 };
|
|
873
|
-
this.createParticleEffect(`${target}_hide`, position, '#ff0000', 10);
|
|
874
|
-
logger.info('Hide command executed', { target });
|
|
875
|
-
return {
|
|
876
|
-
hidden: target,
|
|
877
|
-
};
|
|
878
|
-
}
|
|
879
|
-
/**
|
|
880
|
-
* Execute 'create' command
|
|
881
|
-
*/
|
|
882
|
-
async executeCreateCommand(tokens, _node) {
|
|
883
|
-
if (tokens.length < 2) {
|
|
884
|
-
return { error: 'Create command requires shape and name' };
|
|
885
|
-
}
|
|
886
|
-
const shape = tokens[0];
|
|
887
|
-
const name = tokens[1];
|
|
888
|
-
const position = _node.position || { x: 0, y: 0, z: 0 };
|
|
889
|
-
const hologram = {
|
|
890
|
-
shape: shape,
|
|
891
|
-
color: _node.hologram?.color || '#00ffff',
|
|
892
|
-
size: _node.hologram?.size || 1,
|
|
893
|
-
glow: _node.hologram?.glow !== false,
|
|
894
|
-
interactive: _node.hologram?.interactive !== false,
|
|
895
|
-
};
|
|
896
|
-
this.context.spatialMemory.set(name, position);
|
|
897
|
-
this.createParticleEffect(`${name}_create`, position, hologram.color, 20);
|
|
898
|
-
logger.info('Create command executed', { shape, name, position });
|
|
899
|
-
return {
|
|
900
|
-
created: name,
|
|
901
|
-
shape,
|
|
902
|
-
hologram,
|
|
903
|
-
position,
|
|
904
|
-
};
|
|
905
|
-
}
|
|
906
|
-
/**
|
|
907
|
-
* Execute 'animate' command
|
|
908
|
-
*/
|
|
909
|
-
async executeAnimateCommand(target, tokens, _node) {
|
|
910
|
-
const property = tokens[0] || 'position.y';
|
|
911
|
-
const duration = parseInt(tokens[1] || '1000', 10);
|
|
912
|
-
const animation = {
|
|
913
|
-
target,
|
|
914
|
-
property,
|
|
915
|
-
from: 0,
|
|
916
|
-
to: 1,
|
|
917
|
-
duration,
|
|
918
|
-
startTime: Date.now(),
|
|
919
|
-
easing: 'ease-in-out',
|
|
920
|
-
};
|
|
921
|
-
this.animations.set(`${target}_${property}`, animation);
|
|
922
|
-
logger.info('Animate command executed', { target, property, duration });
|
|
923
|
-
return {
|
|
924
|
-
animating: target,
|
|
925
|
-
animation,
|
|
926
|
-
};
|
|
927
|
-
}
|
|
928
|
-
/**
|
|
929
|
-
* Execute 'pulse' command
|
|
930
|
-
*/
|
|
931
|
-
async executePulseCommand(target, tokens, _node) {
|
|
932
|
-
const duration = parseInt(tokens[0] || '500', 10);
|
|
933
|
-
const position = this.context.spatialMemory.get(target) || { x: 0, y: 0, z: 0 };
|
|
934
|
-
// Create pulsing particle effect
|
|
935
|
-
this.createParticleEffect(`${target}_pulse`, position, '#ffff00', 30);
|
|
936
|
-
// Create animation for scale
|
|
937
|
-
const animation = {
|
|
938
|
-
target,
|
|
939
|
-
property: 'scale',
|
|
940
|
-
from: 1,
|
|
941
|
-
to: 1.5,
|
|
942
|
-
duration,
|
|
943
|
-
startTime: Date.now(),
|
|
944
|
-
easing: 'sine',
|
|
945
|
-
yoyo: true,
|
|
946
|
-
loop: true,
|
|
947
|
-
};
|
|
948
|
-
this.animations.set(`${target}_pulse`, animation);
|
|
949
|
-
logger.info('Pulse command executed', { target, duration });
|
|
950
|
-
return {
|
|
951
|
-
pulsing: target,
|
|
952
|
-
duration,
|
|
953
|
-
};
|
|
954
|
-
}
|
|
955
|
-
/**
|
|
956
|
-
* Execute 'move' command
|
|
957
|
-
*/
|
|
958
|
-
async executeMoveCommand(target, tokens, _node) {
|
|
959
|
-
const x = parseFloat(tokens[0] || '0');
|
|
960
|
-
const y = parseFloat(tokens[1] || '0');
|
|
961
|
-
const z = parseFloat(tokens[2] || '0');
|
|
962
|
-
const position = { x, y, z };
|
|
963
|
-
const current = this.context.spatialMemory.get(target);
|
|
964
|
-
if (current) {
|
|
965
|
-
this.context.spatialMemory.set(target, position);
|
|
966
|
-
this.createConnectionStream(target, `${target}_move`, current, position, 'movement');
|
|
967
|
-
}
|
|
968
|
-
else {
|
|
969
|
-
this.context.spatialMemory.set(target, position);
|
|
970
|
-
}
|
|
971
|
-
logger.info('Move command executed', { target, position });
|
|
972
|
-
return {
|
|
973
|
-
moved: target,
|
|
974
|
-
to: position,
|
|
975
|
-
};
|
|
976
|
-
}
|
|
977
|
-
/**
|
|
978
|
-
* Execute 'delete' command
|
|
979
|
-
*/
|
|
980
|
-
async executeDeleteCommand(target, _node) {
|
|
981
|
-
const position = this.context.spatialMemory.get(target);
|
|
982
|
-
if (position) {
|
|
983
|
-
this.createParticleEffect(`${target}_delete`, position, '#ff0000', 15);
|
|
984
|
-
this.context.spatialMemory.delete(target);
|
|
985
|
-
}
|
|
986
|
-
logger.info('Delete command executed', { target });
|
|
987
|
-
return {
|
|
988
|
-
deleted: target,
|
|
989
|
-
};
|
|
990
|
-
}
|
|
991
|
-
async executeStructure(node) {
|
|
992
|
-
// Handle nexus, building, and other structural elements
|
|
993
|
-
const hologram = node.hologram || {
|
|
994
|
-
shape: node.type === 'nexus' ? 'sphere' : 'cube',
|
|
995
|
-
color: node.type === 'nexus' ? '#9b59b6' : '#e74c3c',
|
|
996
|
-
size: node.type === 'nexus' ? 3 : 4,
|
|
997
|
-
glow: true,
|
|
998
|
-
interactive: true,
|
|
999
|
-
};
|
|
1000
|
-
return {
|
|
1001
|
-
success: true,
|
|
1002
|
-
output: { type: node.type, created: true },
|
|
1003
|
-
hologram,
|
|
1004
|
-
spatialPosition: node.position,
|
|
1005
|
-
};
|
|
1006
|
-
}
|
|
1007
|
-
async executeAssignment(node) {
|
|
1008
|
-
const value = this.evaluateExpression(String(node.value));
|
|
1009
|
-
this.setVariable(node.name, value);
|
|
1010
|
-
return {
|
|
1011
|
-
success: true,
|
|
1012
|
-
output: { assigned: node.name, value },
|
|
1013
|
-
};
|
|
1014
|
-
}
|
|
1015
|
-
async executeReturn(node) {
|
|
1016
|
-
const value = this.evaluateExpression(String(node.value));
|
|
1017
|
-
return {
|
|
1018
|
-
success: true,
|
|
1019
|
-
output: value,
|
|
1020
|
-
};
|
|
1021
|
-
}
|
|
1022
|
-
// ============================================================================
|
|
1023
|
-
// Condition Evaluation
|
|
1024
|
-
// ============================================================================
|
|
1025
|
-
evaluateCondition(condition) {
|
|
1026
|
-
if (!condition)
|
|
1027
|
-
return false;
|
|
1028
|
-
const suspiciousKeywords = ['eval', 'process', 'require', '__proto__', 'constructor'];
|
|
1029
|
-
if (suspiciousKeywords.some(kw => condition.toLowerCase().includes(kw))) {
|
|
1030
|
-
logger.warn('Suspicious condition blocked', { condition });
|
|
1031
|
-
return false;
|
|
1032
|
-
}
|
|
1033
|
-
try {
|
|
1034
|
-
// Boolean literals
|
|
1035
|
-
if (condition.trim().toLowerCase() === 'true')
|
|
1036
|
-
return true;
|
|
1037
|
-
if (condition.trim().toLowerCase() === 'false')
|
|
1038
|
-
return false;
|
|
1039
|
-
// Comparison operators
|
|
1040
|
-
const comparisonPatterns = [
|
|
1041
|
-
{ regex: /^(.+?)\s*(===|!==)\s*(.+)$/ },
|
|
1042
|
-
{ regex: /^(.+?)\s*(==|!=|>=|<=|>|<)\s*(.+)$/ },
|
|
1043
|
-
{ regex: /^(.+?)\s*(&&)\s*(.+)$/, logical: 'and' },
|
|
1044
|
-
{ regex: /^(.+?)\s*(\|\|)\s*(.+)$/, logical: 'or' },
|
|
1045
|
-
];
|
|
1046
|
-
for (const { regex, logical } of comparisonPatterns) {
|
|
1047
|
-
const match = condition.match(regex);
|
|
1048
|
-
if (match) {
|
|
1049
|
-
const [, leftExpr, operator, rightExpr] = match;
|
|
1050
|
-
const left = this.evaluateExpression(leftExpr.trim());
|
|
1051
|
-
const right = this.evaluateExpression(rightExpr.trim());
|
|
1052
|
-
if (logical === 'and')
|
|
1053
|
-
return Boolean(left) && Boolean(right);
|
|
1054
|
-
if (logical === 'or')
|
|
1055
|
-
return Boolean(left) || Boolean(right);
|
|
1056
|
-
switch (operator) {
|
|
1057
|
-
case '===': return left === right;
|
|
1058
|
-
case '!==': return left !== right;
|
|
1059
|
-
case '==': return left == right;
|
|
1060
|
-
case '!=': return left != right;
|
|
1061
|
-
case '>=': return Number(left) >= Number(right);
|
|
1062
|
-
case '<=': return Number(left) <= Number(right);
|
|
1063
|
-
case '>': return Number(left) > Number(right);
|
|
1064
|
-
case '<': return Number(left) < Number(right);
|
|
1065
|
-
}
|
|
1066
|
-
}
|
|
1067
|
-
}
|
|
1068
|
-
// Negation
|
|
1069
|
-
if (condition.startsWith('!')) {
|
|
1070
|
-
return !this.evaluateCondition(condition.slice(1).trim());
|
|
1071
|
-
}
|
|
1072
|
-
// Variable truthiness
|
|
1073
|
-
const value = this.evaluateExpression(condition.trim());
|
|
1074
|
-
return Boolean(value);
|
|
1075
|
-
}
|
|
1076
|
-
catch (error) {
|
|
1077
|
-
logger.error('Condition evaluation error', { condition, error });
|
|
1078
|
-
return false;
|
|
1079
|
-
}
|
|
1080
|
-
}
|
|
1081
|
-
// ============================================================================
|
|
1082
|
-
// Transformation
|
|
1083
|
-
// ============================================================================
|
|
1084
|
-
async applyTransformation(data, transform) {
|
|
1085
|
-
const params = transform.parameters || {};
|
|
1086
|
-
switch (transform.operation) {
|
|
1087
|
-
case 'filter': {
|
|
1088
|
-
if (!Array.isArray(data))
|
|
1089
|
-
return data;
|
|
1090
|
-
const predicate = params.predicate;
|
|
1091
|
-
if (predicate) {
|
|
1092
|
-
return data.filter(item => {
|
|
1093
|
-
this.setVariable('_item', item);
|
|
1094
|
-
return this.evaluateCondition(predicate);
|
|
1095
|
-
});
|
|
1096
|
-
}
|
|
1097
|
-
return data.filter(item => item !== null && item !== undefined);
|
|
1098
|
-
}
|
|
1099
|
-
case 'map': {
|
|
1100
|
-
if (!Array.isArray(data))
|
|
1101
|
-
return data;
|
|
1102
|
-
const mapper = params.mapper;
|
|
1103
|
-
if (mapper) {
|
|
1104
|
-
return data.map(item => {
|
|
1105
|
-
this.setVariable('_item', item);
|
|
1106
|
-
return this.evaluateExpression(mapper);
|
|
1107
|
-
});
|
|
1108
|
-
}
|
|
1109
|
-
return data.map(item => ({ value: item, processed: true }));
|
|
1110
|
-
}
|
|
1111
|
-
case 'reduce': {
|
|
1112
|
-
if (!Array.isArray(data))
|
|
1113
|
-
return data;
|
|
1114
|
-
const initial = params.initial ?? 0;
|
|
1115
|
-
const reducer = params.reducer;
|
|
1116
|
-
if (reducer) {
|
|
1117
|
-
return data.reduce((acc, item) => {
|
|
1118
|
-
this.setVariable('_acc', acc);
|
|
1119
|
-
this.setVariable('_item', item);
|
|
1120
|
-
return this.evaluateExpression(reducer);
|
|
1121
|
-
}, initial);
|
|
1122
|
-
}
|
|
1123
|
-
return data.reduce((acc, item) => acc + (typeof item === 'number' ? item : 0), 0);
|
|
1124
|
-
}
|
|
1125
|
-
case 'sort': {
|
|
1126
|
-
if (!Array.isArray(data))
|
|
1127
|
-
return data;
|
|
1128
|
-
const key = params.key;
|
|
1129
|
-
const desc = params.descending;
|
|
1130
|
-
const sorted = [...data].sort((a, b) => {
|
|
1131
|
-
const aVal = key ? a[key] : a;
|
|
1132
|
-
const bVal = key ? b[key] : b;
|
|
1133
|
-
if (aVal < bVal)
|
|
1134
|
-
return desc ? 1 : -1;
|
|
1135
|
-
if (aVal > bVal)
|
|
1136
|
-
return desc ? -1 : 1;
|
|
1137
|
-
return 0;
|
|
1138
|
-
});
|
|
1139
|
-
return sorted;
|
|
1140
|
-
}
|
|
1141
|
-
case 'sum':
|
|
1142
|
-
return Array.isArray(data) ? data.reduce((sum, item) => sum + (typeof item === 'number' ? item : 0), 0) : data;
|
|
1143
|
-
case 'count':
|
|
1144
|
-
return Array.isArray(data) ? data.length : 1;
|
|
1145
|
-
case 'unique':
|
|
1146
|
-
return Array.isArray(data) ? [...new Set(data)] : data;
|
|
1147
|
-
case 'flatten':
|
|
1148
|
-
return Array.isArray(data) ? data.flat() : data;
|
|
1149
|
-
case 'reverse':
|
|
1150
|
-
return Array.isArray(data) ? [...data].reverse() : data;
|
|
1151
|
-
case 'take': {
|
|
1152
|
-
if (!Array.isArray(data))
|
|
1153
|
-
return data;
|
|
1154
|
-
const count = Number(params.count) || 10;
|
|
1155
|
-
return data.slice(0, count);
|
|
1156
|
-
}
|
|
1157
|
-
case 'skip': {
|
|
1158
|
-
if (!Array.isArray(data))
|
|
1159
|
-
return data;
|
|
1160
|
-
const count = Number(params.count) || 0;
|
|
1161
|
-
return data.slice(count);
|
|
1162
|
-
}
|
|
1163
|
-
default:
|
|
1164
|
-
logger.warn('Unknown transformation', { operation: transform.operation });
|
|
1165
|
-
return data;
|
|
1166
|
-
}
|
|
1167
|
-
}
|
|
1168
|
-
// ============================================================================
|
|
1169
|
-
// Event System
|
|
1170
|
-
// ============================================================================
|
|
1171
|
-
/**
|
|
1172
|
-
* Register event handler
|
|
1173
|
-
*/
|
|
1174
|
-
on(event, handler) {
|
|
1175
|
-
const handlers = this.eventHandlers.get(event) || [];
|
|
1176
|
-
handlers.push(handler);
|
|
1177
|
-
this.eventHandlers.set(event, handlers);
|
|
1178
|
-
}
|
|
1179
|
-
/**
|
|
1180
|
-
* Remove event handler
|
|
1181
|
-
*/
|
|
1182
|
-
off(event, handler) {
|
|
1183
|
-
if (!handler) {
|
|
1184
|
-
this.eventHandlers.delete(event);
|
|
1185
|
-
}
|
|
1186
|
-
else {
|
|
1187
|
-
const handlers = this.eventHandlers.get(event) || [];
|
|
1188
|
-
this.eventHandlers.set(event, handlers.filter(h => h !== handler));
|
|
1189
|
-
}
|
|
1190
|
-
}
|
|
1191
|
-
/**
|
|
1192
|
-
* Emit event
|
|
1193
|
-
*/
|
|
1194
|
-
async emit(event, data) {
|
|
1195
|
-
const handlers = this.eventHandlers.get(event) || [];
|
|
1196
|
-
for (const handler of handlers) {
|
|
1197
|
-
try {
|
|
1198
|
-
await handler(data);
|
|
1199
|
-
}
|
|
1200
|
-
catch (error) {
|
|
1201
|
-
logger.error('Event handler error', { event, error });
|
|
1202
|
-
}
|
|
1203
|
-
}
|
|
1204
|
-
}
|
|
1205
|
-
/**
|
|
1206
|
-
* Trigger UI event
|
|
1207
|
-
*/
|
|
1208
|
-
async triggerUIEvent(elementName, eventType, data) {
|
|
1209
|
-
const element = this.uiElements.get(elementName);
|
|
1210
|
-
if (!element) {
|
|
1211
|
-
logger.warn('UI element not found', { elementName });
|
|
1212
|
-
return;
|
|
1213
|
-
}
|
|
1214
|
-
// Update element state based on event
|
|
1215
|
-
if (eventType === 'change' && data !== undefined) {
|
|
1216
|
-
element.value = data;
|
|
1217
|
-
}
|
|
1218
|
-
await this.emit(`${elementName}.${eventType}`, data);
|
|
1219
|
-
}
|
|
1220
|
-
// ============================================================================
|
|
1221
|
-
// Animation System
|
|
1222
|
-
// ============================================================================
|
|
1223
|
-
/**
|
|
1224
|
-
* Update all animations
|
|
1225
|
-
*/
|
|
1226
|
-
updateAnimations() {
|
|
1227
|
-
const now = Date.now();
|
|
1228
|
-
for (const [key, anim] of this.animations) {
|
|
1229
|
-
const elapsed = now - anim.startTime;
|
|
1230
|
-
let progress = Math.min(elapsed / anim.duration, 1);
|
|
1231
|
-
// Apply easing
|
|
1232
|
-
progress = this.applyEasing(progress, anim.easing);
|
|
1233
|
-
// Calculate current value
|
|
1234
|
-
let currentValue = anim.from + (anim.to - anim.from) * progress;
|
|
1235
|
-
// Handle yoyo
|
|
1236
|
-
if (anim.yoyo && progress >= 1) {
|
|
1237
|
-
anim.startTime = now;
|
|
1238
|
-
[anim.from, anim.to] = [anim.to, anim.from];
|
|
1239
|
-
}
|
|
1240
|
-
// Update the property
|
|
1241
|
-
this.setVariable(`${anim.target}.${anim.property}`, currentValue);
|
|
1242
|
-
// Remove completed non-looping animations
|
|
1243
|
-
if (progress >= 1 && !anim.loop && !anim.yoyo) {
|
|
1244
|
-
this.animations.delete(key);
|
|
1245
|
-
}
|
|
1246
|
-
else if (progress >= 1 && anim.loop) {
|
|
1247
|
-
anim.startTime = now;
|
|
1248
|
-
}
|
|
1249
|
-
}
|
|
1250
|
-
}
|
|
1251
|
-
applyEasing(t, easing) {
|
|
1252
|
-
switch (easing) {
|
|
1253
|
-
case 'easeIn':
|
|
1254
|
-
return t * t;
|
|
1255
|
-
case 'easeOut':
|
|
1256
|
-
return t * (2 - t);
|
|
1257
|
-
case 'easeInOut':
|
|
1258
|
-
return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
|
|
1259
|
-
case 'easeInQuad':
|
|
1260
|
-
return t * t;
|
|
1261
|
-
case 'easeOutQuad':
|
|
1262
|
-
return t * (2 - t);
|
|
1263
|
-
case 'easeInOutQuad':
|
|
1264
|
-
return t < 0.5 ? 2 * t * t : -1 + (4 - 2 * t) * t;
|
|
1265
|
-
case 'linear':
|
|
1266
|
-
default:
|
|
1267
|
-
return t;
|
|
1268
|
-
}
|
|
1269
|
-
}
|
|
1270
|
-
// ============================================================================
|
|
1271
|
-
// Particle Effects
|
|
1272
|
-
// ============================================================================
|
|
1273
|
-
createParticleEffect(name, position, color, count) {
|
|
1274
|
-
const limitedCount = Math.min(count, RUNTIME_SECURITY_LIMITS.maxParticlesPerSystem);
|
|
1275
|
-
const particles = [];
|
|
1276
|
-
for (let i = 0; i < limitedCount; i++) {
|
|
1277
|
-
particles.push({
|
|
1278
|
-
x: position.x + (Math.random() - 0.5) * 2,
|
|
1279
|
-
y: position.y + (Math.random() - 0.5) * 2,
|
|
1280
|
-
z: position.z + (Math.random() - 0.5) * 2,
|
|
1281
|
-
});
|
|
1282
|
-
}
|
|
1283
|
-
this.particleSystems.set(name, {
|
|
1284
|
-
particles,
|
|
1285
|
-
color,
|
|
1286
|
-
lifetime: 3000,
|
|
1287
|
-
speed: 0.01,
|
|
1288
|
-
});
|
|
1289
|
-
}
|
|
1290
|
-
createConnectionStream(from, to, fromPos, toPos, dataType) {
|
|
1291
|
-
const streamName = `connection_${from}_${to}`;
|
|
1292
|
-
const particles = [];
|
|
1293
|
-
const steps = 20;
|
|
1294
|
-
for (let i = 0; i <= steps; i++) {
|
|
1295
|
-
const t = i / steps;
|
|
1296
|
-
particles.push({
|
|
1297
|
-
x: fromPos.x + (toPos.x - fromPos.x) * t,
|
|
1298
|
-
y: fromPos.y + (toPos.y - fromPos.y) * t,
|
|
1299
|
-
z: fromPos.z + (toPos.z - fromPos.z) * t,
|
|
1300
|
-
});
|
|
1301
|
-
}
|
|
1302
|
-
this.particleSystems.set(streamName, {
|
|
1303
|
-
particles,
|
|
1304
|
-
color: this.getDataTypeColor(dataType),
|
|
1305
|
-
lifetime: 5000,
|
|
1306
|
-
speed: 0.02,
|
|
1307
|
-
});
|
|
1308
|
-
}
|
|
1309
|
-
createFlowingStream(name, position, data) {
|
|
1310
|
-
const count = Array.isArray(data) ? Math.min(data.length, 50) : 10;
|
|
1311
|
-
this.createParticleEffect(`${name}_flow`, position, '#45b7d1', count);
|
|
1312
|
-
}
|
|
1313
|
-
createExecutionEffect(name, position) {
|
|
1314
|
-
this.createParticleEffect(`${name}_execution`, position, '#ff4500', 30);
|
|
1315
|
-
}
|
|
1316
|
-
createDataVisualization(name, data, position) {
|
|
1317
|
-
let count = 10;
|
|
1318
|
-
if (Array.isArray(data)) {
|
|
1319
|
-
count = Math.min(data.length, 100);
|
|
1320
|
-
}
|
|
1321
|
-
else if (typeof data === 'object' && data !== null) {
|
|
1322
|
-
count = Math.min(Object.keys(data).length * 5, 50);
|
|
1323
|
-
}
|
|
1324
|
-
this.createParticleEffect(`${name}_visualization`, position, '#32cd32', count);
|
|
1325
|
-
}
|
|
1326
|
-
getDataTypeColor(dataType) {
|
|
1327
|
-
const colors = {
|
|
1328
|
-
'string': '#ff6b35',
|
|
1329
|
-
'number': '#4ecdc4',
|
|
1330
|
-
'boolean': '#45b7d1',
|
|
1331
|
-
'object': '#96ceb4',
|
|
1332
|
-
'array': '#ffeaa7',
|
|
1333
|
-
'any': '#dda0dd',
|
|
1334
|
-
'move': '#ff69b4',
|
|
1335
|
-
};
|
|
1336
|
-
return colors[dataType] || '#ffffff';
|
|
1337
|
-
}
|
|
1338
|
-
// ============================================================================
|
|
1339
|
-
// Public API
|
|
1340
|
-
// ============================================================================
|
|
1341
|
-
getParticleSystems() {
|
|
1342
|
-
return new Map(this.particleSystems);
|
|
1343
|
-
}
|
|
1344
|
-
updateParticles(deltaTime) {
|
|
1345
|
-
for (const [name, system] of this.particleSystems) {
|
|
1346
|
-
system.lifetime -= deltaTime;
|
|
1347
|
-
system.particles.forEach(particle => {
|
|
1348
|
-
particle.x += (Math.random() - 0.5) * system.speed;
|
|
1349
|
-
particle.y += (Math.random() - 0.5) * system.speed;
|
|
1350
|
-
particle.z += (Math.random() - 0.5) * system.speed;
|
|
1351
|
-
});
|
|
1352
|
-
if (system.lifetime <= 0) {
|
|
1353
|
-
this.particleSystems.delete(name);
|
|
1354
|
-
}
|
|
1355
|
-
}
|
|
1356
|
-
}
|
|
1357
|
-
getContext() {
|
|
1358
|
-
return { ...this.context };
|
|
1359
|
-
}
|
|
1360
|
-
getUIElements() {
|
|
1361
|
-
return new Map(this.uiElements);
|
|
1362
|
-
}
|
|
1363
|
-
getUIElement(name) {
|
|
1364
|
-
return this.uiElements.get(name);
|
|
1365
|
-
}
|
|
1366
|
-
getAnimations() {
|
|
1367
|
-
return new Map(this.animations);
|
|
1368
|
-
}
|
|
1369
|
-
reset() {
|
|
1370
|
-
this.context = this.createEmptyContext();
|
|
1371
|
-
this.currentScope = { variables: this.context.variables };
|
|
1372
|
-
this.callStack = [];
|
|
1373
|
-
this.particleSystems.clear();
|
|
1374
|
-
this.executionHistory = [];
|
|
1375
|
-
this.eventHandlers.clear();
|
|
1376
|
-
this.animations.clear();
|
|
1377
|
-
this.uiElements.clear();
|
|
1378
|
-
}
|
|
1379
|
-
createEmptyContext() {
|
|
1380
|
-
return {
|
|
1381
|
-
variables: new Map(),
|
|
1382
|
-
functions: new Map(),
|
|
1383
|
-
exports: new Map(),
|
|
1384
|
-
connections: [],
|
|
1385
|
-
spatialMemory: new Map(),
|
|
1386
|
-
hologramState: new Map(),
|
|
1387
|
-
executionStack: [],
|
|
1388
|
-
};
|
|
1389
|
-
}
|
|
1390
|
-
getExecutionHistory() {
|
|
1391
|
-
return [...this.executionHistory];
|
|
1392
|
-
}
|
|
1393
|
-
getHologramStates() {
|
|
1394
|
-
return new Map(this.context.hologramState);
|
|
1395
|
-
}
|
|
1396
|
-
getCallStack() {
|
|
1397
|
-
return [...this.callStack];
|
|
1398
|
-
}
|
|
1399
|
-
}
|