diff --git a/Core/GDCore/Extensions/Builtin/ExternalLayoutsExtension.cpp b/Core/GDCore/Extensions/Builtin/ExternalLayoutsExtension.cpp index 69568e549028..73fc3187f2b0 100644 --- a/Core/GDCore/Extensions/Builtin/ExternalLayoutsExtension.cpp +++ b/Core/GDCore/Extensions/Builtin/ExternalLayoutsExtension.cpp @@ -38,6 +38,8 @@ BuiltinExtensionsImplementer::ImplementsExternalLayoutsExtension( .SetDefaultValue("0") .AddParameter("expression", _("Y position of the origin"), "", true) .SetDefaultValue("0") + .AddParameter("expression", _("Z position of the origin"), "", true) + .SetDefaultValue("0") .MarkAsAdvanced(); } diff --git a/GDJS/Runtime/RuntimeInstanceContainer.ts b/GDJS/Runtime/RuntimeInstanceContainer.ts index f208cbfb05e8..9782104a87e2 100644 --- a/GDJS/Runtime/RuntimeInstanceContainer.ts +++ b/GDJS/Runtime/RuntimeInstanceContainer.ts @@ -237,6 +237,7 @@ namespace gdjs { * @param data The instances data * @param xPos The offset on X axis * @param yPos The offset on Y axis + * @param zPos The offset on Z axis * @param trackByPersistentUuid If true, objects are tracked by setting their `persistentUuid` * to the same as the associated instance. Useful for hot-reloading when instances are changed. */ @@ -244,14 +245,30 @@ namespace gdjs { data: InstanceData[], xPos: float, yPos: float, + zPos: float, trackByPersistentUuid: boolean - ) { + ): void { + let zOffset: number; + let shouldTrackByPersistentUuid: boolean; + + if (arguments.length === 5) { + zOffset = zPos; + shouldTrackByPersistentUuid = trackByPersistentUuid; + } else { + /** + * Support for the previous signature (before 3D was introduced): + * createObjectsFrom(data, xPos, yPos, trackByPersistentUuid) + */ + zOffset = 0; + shouldTrackByPersistentUuid = arguments[3]; + } + for (let i = 0, len = data.length; i < len; ++i) { const instanceData = data[i]; const objectName = instanceData.name; const newObject = this.createObject(objectName); if (newObject !== null) { - if (trackByPersistentUuid) { + if (shouldTrackByPersistentUuid) { // Give the object the same persistentUuid as the instance, so that // it can be hot-reloaded. newObject.persistentUuid = instanceData.persistentUuid || null; @@ -262,7 +279,8 @@ namespace gdjs { gdjs.RuntimeObject3D && newObject instanceof gdjs.RuntimeObject3D ) { - if (instanceData.z !== undefined) newObject.setZ(instanceData.z); + if (instanceData.z !== undefined) + newObject.setZ(instanceData.z + zOffset); if (instanceData.rotationX !== undefined) newObject.setRotationX(instanceData.rotationX); if (instanceData.rotationY !== undefined) diff --git a/GDJS/Runtime/debugger-client/hot-reloader.ts b/GDJS/Runtime/debugger-client/hot-reloader.ts index d55bd0c65aed..3646737d7847 100644 --- a/GDJS/Runtime/debugger-client/hot-reloader.ts +++ b/GDJS/Runtime/debugger-client/hot-reloader.ts @@ -1217,6 +1217,7 @@ namespace gdjs { [newInstance], 0, 0, + 0, /*trackByPersistentUuid=*/ true ); diff --git a/GDJS/Runtime/events-tools/runtimescenetools.ts b/GDJS/Runtime/events-tools/runtimescenetools.ts index ad59fd99476c..fe48cd1d904f 100644 --- a/GDJS/Runtime/events-tools/runtimescenetools.ts +++ b/GDJS/Runtime/events-tools/runtimescenetools.ts @@ -281,7 +281,8 @@ namespace gdjs { scene: gdjs.RuntimeInstanceContainer, externalLayout: string, xPos: float, - yPos: float + yPos: float, + zPos: float ) { const externalLayoutData = scene .getGame() @@ -296,6 +297,12 @@ namespace gdjs { externalLayoutData.instances, xPos, yPos, + /** + * When 3D was introduced, zPos argument was added to the signature. + * Existing calls (in JS events) to createObjectsFromExternalLayout will + * have zPos undefined. So it is set to 0 in that case. + */ + zPos || 0, /*trackByPersistentUuid=*/ false ); diff --git a/GDJS/Runtime/runtimescene.ts b/GDJS/Runtime/runtimescene.ts index 15c98f62f5df..03061a6fff98 100644 --- a/GDJS/Runtime/runtimescene.ts +++ b/GDJS/Runtime/runtimescene.ts @@ -165,6 +165,7 @@ namespace gdjs { sceneData.instances, 0, 0, + 0, /*trackByPersistentUuid=*/ true ); diff --git a/GDJS/Runtime/scenestack.ts b/GDJS/Runtime/scenestack.ts index 9b7e4a7fd86e..be2cecbcee6c 100644 --- a/GDJS/Runtime/scenestack.ts +++ b/GDJS/Runtime/scenestack.ts @@ -113,6 +113,7 @@ namespace gdjs { externalLayoutData.instances, 0, 0, + 0, /*trackByPersistentUuid=*/ true );