(
variable: gdjs.Variable
)
| 186 | // Structure variables can contain other variables, so we need to recursively |
| 187 | // get the sync data for each child variable. |
| 188 | getStructureNetworkSyncData( |
| 189 | variable: gdjs.Variable |
| 190 | ): VariableNetworkSyncData[] | undefined { |
| 191 | if (variable.getType() === 'array') { |
| 192 | const allVariableNetworkSyncData: VariableNetworkSyncData[] = []; |
| 193 | variable.getAllChildrenArray().forEach((childVariable) => { |
| 194 | const childVariableType = childVariable.getType(); |
| 195 | const childVariableValue = |
| 196 | childVariableType === 'structure' || childVariableType === 'array' |
| 197 | ? '' |
| 198 | : childVariable.getValue(); |
| 199 | |
| 200 | const childVariableOwner = childVariable.getPlayerOwnership(); |
| 201 | if ( |
| 202 | // Variable undefined. |
| 203 | childVariable.isUndefinedInContainer() || |
| 204 | // Variable marked as not to be synchronized. |
| 205 | childVariableOwner === null |
| 206 | ) { |
| 207 | // In those cases, the variable should not be synchronized. |
| 208 | return; |
| 209 | } |
| 210 | |
| 211 | allVariableNetworkSyncData.push({ |
| 212 | name: '', |
| 213 | value: childVariableValue, |
| 214 | type: childVariableType, |
| 215 | children: this.getStructureNetworkSyncData(childVariable), |
| 216 | owner: childVariableOwner, |
| 217 | }); |
| 218 | }); |
| 219 | |
| 220 | return allVariableNetworkSyncData; |
| 221 | } |
| 222 | |
| 223 | if (variable.getType() === 'structure') { |
| 224 | const variableChildren = variable.getAllChildren(); |
| 225 | if (!variableChildren) return undefined; |
| 226 | const allVariableNetworkSyncData: VariableNetworkSyncData[] = []; |
| 227 | |
| 228 | Object.entries(variableChildren).forEach( |
| 229 | ([childVariableName, childVariable]) => { |
| 230 | const childVariableType = childVariable.getType(); |
| 231 | const childVariableValue = |
| 232 | childVariableType === 'structure' || childVariableType === 'array' |
| 233 | ? '' |
| 234 | : childVariable.getValue(); |
| 235 | const childVariableOwner = childVariable.getPlayerOwnership(); |
| 236 | if ( |
| 237 | // Variable undefined. |
| 238 | childVariable.isUndefinedInContainer() || |
| 239 | // Variable marked as not to be synchronized. |
| 240 | childVariableOwner === null |
| 241 | ) { |
| 242 | // In those cases, the variable should not be synchronized. |
| 243 | return; |
| 244 | } |
| 245 |
no test coverage detected