(varData?: VariableData | undefined)
| 42 | } |
| 43 | |
| 44 | reinitialize(varData?: VariableData | undefined) { |
| 45 | this._type = 'number'; |
| 46 | this._value = 0; |
| 47 | this._str = '0'; |
| 48 | this._bool = false; |
| 49 | this._children = {}; |
| 50 | this._childrenArray = []; |
| 51 | this._undefinedInContainer = false; |
| 52 | |
| 53 | if (varData !== undefined) { |
| 54 | this._type = varData.type || 'number'; |
| 55 | if (this._type === 'number') { |
| 56 | this._value = parseFloat((varData.value as string) || '0'); |
| 57 | // Protect against NaN. |
| 58 | if (this._value !== this._value) this._value = 0; |
| 59 | } else if (this._type === 'string') { |
| 60 | this._str = gdjs.Variable.useDeprecatedZeroAsDefaultStringVariable |
| 61 | ? '' + varData.value || '0' |
| 62 | : varData.value !== undefined |
| 63 | ? '' + varData.value |
| 64 | : ''; |
| 65 | } else if (this._type === 'boolean') { |
| 66 | this._bool = !!varData.value; |
| 67 | } else if (this._type === 'structure') { |
| 68 | if (varData.children !== undefined) { |
| 69 | for (var i = 0, len = varData.children.length; i < len; ++i) { |
| 70 | var childData = varData.children[i]; |
| 71 | if (childData.name === undefined) continue; |
| 72 | this._children[childData.name] = new gdjs.Variable(childData); |
| 73 | } |
| 74 | } |
| 75 | } else if (this._type === 'array' && varData.children) { |
| 76 | for (const childData of varData.children) |
| 77 | this._childrenArray.push(new gdjs.Variable(childData)); |
| 78 | } |
| 79 | } |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Return true if the variable type is a primitive type. |
no test coverage detected