MCPcopy
hub / github.com/4ian/GDevelop / constructor

Method constructor

GDevelop.js/TestUtils/GDJSMocks.js:346–386  ·  view source on GitHub ↗
(initialVariablesData)

Source from the content-addressed store, hash-verified

344
345class VariablesContainer {
346 constructor(initialVariablesData) {
347 this._variables = new Hashtable();
348 this._indexedVariables = [];
349 this._isLocal = initialVariablesData === undefined;
350
351 if (initialVariablesData !== undefined) {
352 const setupVariableFromVariableData = (variable, variableData) => {
353 if (variableData.type === 'number') {
354 variable.setNumber(variableData.value);
355 } else if (variableData.type === 'string') {
356 variable.setString(variableData.value);
357 } else if (variableData.type === 'boolean') {
358 variable.setBoolean(variableData.value);
359 } else if (variableData.type === 'structure') {
360 variableData.children.forEach((childVariableData) => {
361 const childVariable = variable.getChild(childVariableData.name);
362 setupVariableFromVariableData(childVariable, childVariableData);
363 });
364 } else if (variableData.type === 'array') {
365 variableData.children.forEach((childVariableData) => {
366 const childVariable = new Variable();
367 setupVariableFromVariableData(childVariable, childVariableData);
368 variable._pushVariable(childVariable);
369 });
370 } else {
371 throw new Error(
372 'Unsupported variable type in GDJS Mock:',
373 variableData.type
374 );
375 }
376 };
377
378 initialVariablesData.forEach((variableData) => {
379 const newVariable = new Variable();
380 setupVariableFromVariableData(newVariable, variableData);
381
382 this._variables.put(variableData.name, newVariable);
383 this._indexedVariables.push(newVariable);
384 });
385 }
386 }
387
388 _declare(name, newVariable) {
389 this._variables.put(name, newVariable);

Callers

nothing calls this directly

Calls 3

forEachMethod · 0.80
putMethod · 0.65
pushMethod · 0.65

Tested by

no test coverage detected