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

Method updateFromNetworkSyncData

GDJS/Runtime/variable.ts:262–302  ·  view source on GitHub ↗
(
      networkSyncData: VariableNetworkSyncData,
      options: UpdateFromNetworkSyncDataOptions
    )

Source from the content-addressed store, hash-verified

260 }
261
262 updateFromNetworkSyncData(
263 networkSyncData: VariableNetworkSyncData,
264 options: UpdateFromNetworkSyncDataOptions
265 ) {
266 // // If we receive an update for this variable for a different owner than the one we know about,
267 // then 2 cases:
268 // - If we are the owner of the variable, then ignore the message, we assume it's a late update message or a wrong one,
269 // we are confident that we own this variable. (it may be reverted if we don't receive an acknowledgment in time)
270 // - If we are not the owner of the variable, then assume that we missed the ownership change message, so update the variable's
271 // ownership and then update the variable.
272 const syncedVariableOwner = networkSyncData.owner;
273 const variableData =
274 gdjs.Variable.getVariableDataFromNetworkSyncData(networkSyncData);
275
276 if (
277 options.shouldExcludeVariableFromUpdate &&
278 options.shouldExcludeVariableFromUpdate(this)
279 ) {
280 return;
281 }
282
283 if (!options.ignoreVariableOwnership) {
284 const currentPlayerNumber = gdjs.multiplayer.getCurrentPlayerNumber();
285
286 const currentVariableOwner = this.getPlayerOwnership();
287 if (currentPlayerNumber === currentVariableOwner) {
288 // Variable owned by us, ignoring update message.
289 return;
290 }
291
292 if (
293 syncedVariableOwner &&
294 syncedVariableOwner !== currentVariableOwner
295 ) {
296 /// Variable owned by someone else on our game, changing ownership as part of the update event.
297 this.setPlayerOwnership(syncedVariableOwner);
298 }
299 }
300
301 this.reinitialize(variableData);
302 }
303
304 /**
305 * Converts a JavaScript object into a value compatible

Callers

nothing calls this directly

Calls 3

getPlayerOwnershipMethod · 0.95
setPlayerOwnershipMethod · 0.95
reinitializeMethod · 0.95

Tested by

no test coverage detected