(
syncOptions: GetNetworkSyncDataOptions
)
| 133 | }; |
| 134 | |
| 135 | getNetworkSyncData( |
| 136 | syncOptions: GetNetworkSyncDataOptions |
| 137 | ): UnnamedVariableNetworkSyncData | undefined { |
| 138 | if ( |
| 139 | // Variable undefined. |
| 140 | this.isUndefinedInContainer() |
| 141 | ) |
| 142 | return; |
| 143 | |
| 144 | const variableOwner = this.getPlayerOwnership(); |
| 145 | |
| 146 | if (syncOptions.shouldExcludeVariableFromData) { |
| 147 | // Saving for "save state": serialize all variables unless excluded. |
| 148 | if (syncOptions.shouldExcludeVariableFromData(this)) { |
| 149 | return; |
| 150 | } |
| 151 | } else { |
| 152 | // Saving for "multiplayer": only serialize the variable if owned by the player. |
| 153 | const syncedPlayerNumber = syncOptions.playerNumber; |
| 154 | const isHost = syncOptions.isHost; |
| 155 | |
| 156 | if ( |
| 157 | // Variable marked as not to be synchronized. |
| 158 | variableOwner === null || |
| 159 | // Getting sync data for a specific player: |
| 160 | (syncedPlayerNumber !== undefined && |
| 161 | // Variable is owned by host but this player number is not the host. |
| 162 | variableOwner === 0 && |
| 163 | !isHost) || |
| 164 | // Variable is owned by a player but not getting sync data for this player number. |
| 165 | (variableOwner !== 0 && syncedPlayerNumber !== variableOwner) |
| 166 | ) { |
| 167 | // In those cases, the variable should not be synchronized. |
| 168 | return; |
| 169 | } |
| 170 | } |
| 171 | |
| 172 | const variableType = this.getType(); |
| 173 | const variableValue = |
| 174 | variableType === 'structure' || variableType === 'array' |
| 175 | ? '' |
| 176 | : this.getValue(); |
| 177 | |
| 178 | return { |
| 179 | value: variableValue, |
| 180 | type: variableType, |
| 181 | children: this.getStructureNetworkSyncData(this), |
| 182 | owner: variableOwner, |
| 183 | }; |
| 184 | } |
| 185 | |
| 186 | // Structure variables can contain other variables, so we need to recursively |
| 187 | // get the sync data for each child variable. |
nothing calls this directly
no test coverage detected