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

Function createObjectsFrom

GDJS/Runtime/RuntimeInstanceContainer.ts:334–388  ·  view source on GitHub ↗

* Create objects from initial instances data (for example, the initial instances * of the scene or the instances of an external layout). * * @param data The instances data * @param xPos The offset on X axis * @param yPos The offset on Y axis * @param zPos The offset on

(
      data: InstanceData[],
      xPos: float,
      yPos: float,
      zPos: float,
      trackByPersistentUuid: boolean,
      options?: {
        excludedObjectNames?: Set<string> | null;
      }
    )

Source from the content-addressed store, hash-verified

332 * to the same as the associated instance. Useful for hot-reloading when instances are changed.
333 */
334 createObjectsFrom(
335 data: InstanceData[],
336 xPos: float,
337 yPos: float,
338 zPos: float,
339 trackByPersistentUuid: boolean,
340 options?: {
341 excludedObjectNames?: Set<string> | null;
342 }
343 ): void {
344 let zOffset: number = zPos;
345 let shouldTrackByPersistentUuid: boolean = trackByPersistentUuid;
346
347 if (arguments.length <= 4) {
348 /**
349 * Support for the previous signature (before 3D was introduced):
350 * createObjectsFrom(data, xPos, yPos, trackByPersistentUuid)
351 */
352 zOffset = 0;
353 shouldTrackByPersistentUuid = arguments[3];
354 }
355
356 for (let i = 0, len = data.length; i < len; ++i) {
357 const instanceData = data[i];
358 const objectName = instanceData.name;
359 if (options?.excludedObjectNames?.has(objectName)) {
360 continue;
361 }
362
363 const newObject = this.createObject(objectName, instanceData);
364 if (newObject !== null) {
365 if (shouldTrackByPersistentUuid) {
366 // Give the object the same persistentUuid as the instance, so that
367 // it can be hot-reloaded.
368 newObject.persistentUuid = instanceData.persistentUuid || null;
369 }
370 newObject.setPosition(instanceData.x + xPos, instanceData.y + yPos);
371 newObject.setAngle(instanceData.angle);
372 if (gdjs.Base3DHandler && gdjs.Base3DHandler.is3D(newObject)) {
373 newObject.setZ((instanceData.z || 0) + zOffset);
374 if (instanceData.rotationX !== undefined)
375 newObject.setRotationX(instanceData.rotationX);
376 if (instanceData.rotationY !== undefined)
377 newObject.setRotationY(instanceData.rotationY);
378 }
379
380 newObject.setZOrder(instanceData.zOrder);
381 newObject.setLayer(instanceData.layer);
382 newObject
383 .getVariables()
384 .initFrom(instanceData.initialVariables, true);
385 newObject.extraInitializationFromInitialInstance(instanceData);
386 }
387 }
388 }
389
390 /**
391 * Get the data representing the initial shared data of the scene for the specified behavior.

Callers

nothing calls this directly

Calls 13

initFromMethod · 0.80
is3DMethod · 0.65
setZMethod · 0.65
setRotationXMethod · 0.65
setRotationYMethod · 0.65
hasMethod · 0.45
createObjectMethod · 0.45
setPositionMethod · 0.45
setAngleMethod · 0.45
setZOrderMethod · 0.45
setLayerMethod · 0.45
getVariablesMethod · 0.45

Tested by

no test coverage detected