gdcore-tools 2.0.0-gd-v5.4.218-autobuild → 2.0.0-gd-v5.4.220-autobuild
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/Runtime/Extensions/3D/CustomRuntimeObject3D.js +1 -1
- package/dist/Runtime/Extensions/3D/CustomRuntimeObject3D.js.map +2 -2
- package/dist/Runtime/Extensions/AnchorBehavior/anchorruntimebehavior.js +1 -1
- package/dist/Runtime/Extensions/AnchorBehavior/anchorruntimebehavior.js.map +2 -2
- package/dist/Runtime/Extensions/Physics2Behavior/JsExtension.js +19 -19
- package/dist/Runtime/Extensions/Physics2Behavior/physics2runtimebehavior.js +1 -1
- package/dist/Runtime/Extensions/Physics2Behavior/physics2runtimebehavior.js.map +2 -2
- package/dist/Runtime/Extensions/Physics2Behavior/physics2tools.js +1 -1
- package/dist/Runtime/Extensions/Physics2Behavior/physics2tools.js.map +2 -2
- package/dist/Runtime/Extensions/Physics3DBehavior/JsExtension.js +2442 -0
- package/dist/Runtime/Extensions/Physics3DBehavior/Physics3DRuntimeBehavior.js +2 -0
- package/dist/Runtime/Extensions/Physics3DBehavior/Physics3DRuntimeBehavior.js.map +7 -0
- package/dist/Runtime/Extensions/Physics3DBehavior/Physics3DTools.js +2 -0
- package/dist/Runtime/Extensions/Physics3DBehavior/Physics3DTools.js.map +7 -0
- package/dist/Runtime/Extensions/Physics3DBehavior/PhysicsCharacter3DRuntimeBehavior.js +2 -0
- package/dist/Runtime/Extensions/Physics3DBehavior/PhysicsCharacter3DRuntimeBehavior.js.map +7 -0
- package/dist/Runtime/Extensions/Physics3DBehavior/jolt-physics.d.ts +4874 -0
- package/dist/Runtime/Extensions/Physics3DBehavior/jolt-physics.wasm.js +2 -0
- package/dist/Runtime/Extensions/Physics3DBehavior/jolt-physics.wasm.js.map +7 -0
- package/dist/Runtime/Extensions/Physics3DBehavior/jolt-physics.wasm.wasm +0 -0
- package/dist/Runtime/Extensions/PlatformBehavior/platformerobjectruntimebehavior.js.map +2 -2
- package/dist/Runtime/Extensions/TileMap/helper/TileMapHelper.js +1 -1
- package/dist/Runtime/Extensions/TileMap/helper/TileMapHelper.js.map +1 -1
- package/dist/Runtime/Extensions/TileMap/simpletilemapruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/TileMap/simpletilemapruntimeobject.js.map +2 -2
- package/dist/Runtime/RuntimeInstanceContainer.js +1 -1
- package/dist/Runtime/RuntimeInstanceContainer.js.map +2 -2
- package/dist/Runtime/RuntimeLayer.js +1 -1
- package/dist/Runtime/RuntimeLayer.js.map +2 -2
- package/dist/Runtime/layer.js +1 -1
- package/dist/Runtime/layer.js.map +2 -2
- package/dist/Runtime/pixi-renderers/pixi-image-manager.js +1 -1
- package/dist/Runtime/pixi-renderers/pixi-image-manager.js.map +2 -2
- package/dist/Runtime/pixi-renderers/runtimegame-pixi-renderer.js +1 -1
- package/dist/Runtime/pixi-renderers/runtimegame-pixi-renderer.js.map +2 -2
- package/dist/Runtime/runtimegame.js +1 -1
- package/dist/Runtime/runtimegame.js.map +2 -2
- package/dist/Runtime/types/global-types.d.ts +20 -3
- package/dist/Runtime/types/project-data.d.ts +1 -1
- package/dist/lib/libGD.cjs +1 -1
- package/dist/lib/libGD.wasm +0 -0
- package/gd.d.ts +17 -3
- package/package.json +1 -1
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../GDevelop/GDJS/Runtime/RuntimeInstanceContainer.ts"],
|
|
4
|
-
"sourcesContent": ["/*\n * GDevelop JS Platform\n * Copyright 2013-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.\n * This project is released under the MIT License.\n */\nnamespace gdjs {\n const logger = new gdjs.Logger('RuntimeInstanceContainer');\n\n /**\n * A container of object instances rendered on screen.\n */\n export abstract class RuntimeInstanceContainer {\n _initialBehaviorSharedData: Hashtable<BehaviorSharedData | null>;\n\n /** Contains the instances living on the container */\n _instances: Hashtable<RuntimeObject[]>;\n\n /**\n * An array used to create a list of all instance when necessary.\n * @see gdjs.RuntimeInstanceContainer#_constructListOfAllInstances}\n */\n private _allInstancesList: gdjs.RuntimeObject[] = [];\n _allInstancesListIsUpToDate = true;\n\n /** Used to recycle destroyed instance instead of creating new ones. */\n _instancesCache: Hashtable<RuntimeObject[]>;\n\n /** The instances removed from the container and waiting to be sent to the cache. */\n _instancesRemoved: gdjs.RuntimeObject[] = [];\n\n /** Contains the objects data stored in the project */\n _objects: Hashtable<ObjectData>;\n _objectsCtor: Hashtable<typeof RuntimeObject>;\n\n _layers: Hashtable<RuntimeLayer>;\n _orderedLayers: RuntimeLayer[]; // TODO: should this be a single structure with _layers, to enforce its usage?\n _layersCameraCoordinates: Record<string, [float, float, float, float]> = {};\n\n // Options for the debug draw:\n _debugDrawEnabled: boolean = false;\n _debugDrawShowHiddenInstances: boolean = false;\n _debugDrawShowPointsNames: boolean = false;\n _debugDrawShowCustomPoints: boolean = false;\n\n constructor() {\n this._initialBehaviorSharedData = new Hashtable();\n this._instances = new Hashtable();\n this._instancesCache = new Hashtable();\n this._objects = new Hashtable();\n this._objectsCtor = new Hashtable();\n this._layers = new Hashtable();\n this._orderedLayers = [];\n }\n\n /**\n * Return the time elapsed since the last frame,\n * in milliseconds, for objects on the layer.\n */\n abstract getElapsedTime(): float;\n\n /**\n * Get the renderer associated to the container.\n */\n abstract getRenderer(): gdjs.RuntimeInstanceContainerRenderer;\n\n /**\n * Get the renderer for visual debugging associated to the container.\n */\n abstract getDebuggerRenderer(): gdjs.DebuggerRenderer;\n\n /**\n * Get the {@link gdjs.RuntimeGame} associated to this.\n */\n abstract getGame(): gdjs.RuntimeGame;\n\n /**\n * Get the {@link gdjs.RuntimeScene} associated to this.\n */\n abstract getScene(): gdjs.RuntimeScene;\n\n abstract getAsyncTasksManager(): gdjs.AsyncTasksManager;\n\n /**\n * Convert a point from the canvas coordinates (for example,\n * the mouse position) to the container coordinates.\n *\n * @param x The x position, in container coordinates.\n * @param y The y position, in container coordinates.\n * @param result The point instance that is used to return the result.\n */\n abstract convertCoords(x: float, y: float, result?: FloatPoint): FloatPoint;\n\n /**\n * Convert a point from the container coordinates (for example,\n * an object position) to the canvas coordinates.\n *\n * @param sceneX The x position, in container coordinates.\n * @param sceneY The y position, in container coordinates.\n * @param result The point instance that is used to return the result.\n */\n abstract convertInverseCoords(\n sceneX: float,\n sceneY: float,\n result: FloatPoint\n ): FloatPoint;\n\n /**\n * @return the left bound of:\n * - the game resolution for a {@link gdjs.RuntimeScene}\n * - the default dimensions (the AABB of all its children) for a\n * {@link gdjs.CustomRuntimeObject}.\n */\n abstract getUnrotatedViewportMinX(): float;\n\n /**\n * @return the top bound of:\n * - the game resolution for a {@link gdjs.RuntimeScene}\n * - the default dimensions (the AABB of all its children) for a\n * {@link gdjs.CustomRuntimeObject}.\n */\n abstract getUnrotatedViewportMinY(): float;\n\n /**\n * @return the right bound of:\n * - the game resolution for a {@link gdjs.RuntimeScene}\n * - the default dimensions (the AABB of all its children) for a\n * {@link gdjs.CustomRuntimeObject}.\n */\n abstract getUnrotatedViewportMaxX(): float;\n\n /**\n * @return the bottom bound of:\n * - the game resolution for a {@link gdjs.RuntimeScene}\n * - the default dimensions (the AABB of all its children) for a\n * {@link gdjs.CustomRuntimeObject}.\n */\n abstract getUnrotatedViewportMaxY(): float;\n\n /**\n * @return the left bound of:\n * - the initial game resolution for a {@link gdjs.RuntimeScene}\n * - the initial default dimensions (inner area) set in the editor for a\n * {@link gdjs.CustomRuntimeObject}.\n */\n abstract getInitialUnrotatedViewportMinX(): float;\n\n /**\n * @return the top bound of:\n * - the initial game resolution for a {@link gdjs.RuntimeScene}\n * - the initial default dimensions (inner area) set in the editor for a\n * {@link gdjs.CustomRuntimeObject}.\n */\n abstract getInitialUnrotatedViewportMinY(): float;\n\n /**\n * @return the right bound of:\n * - the initial game resolution for a {@link gdjs.RuntimeScene}\n * - the initial default dimensions (inner area) set in the editor for a\n * {@link gdjs.CustomRuntimeObject}.\n */\n abstract getInitialUnrotatedViewportMaxX(): float;\n\n /**\n * @return the bottom bound of:\n * - the initial game resolution for a {@link gdjs.RuntimeScene}\n * - the initial default dimensions (inner area) set in the editor for a\n * {@link gdjs.CustomRuntimeObject}.\n */\n abstract getInitialUnrotatedViewportMaxY(): float;\n\n /**\n * @return the width of:\n * - the game resolution for a {@link gdjs.RuntimeScene}\n * - the default dimensions (the AABB of all its children) for a\n * {@link gdjs.CustomRuntimeObject}.\n */\n abstract getViewportWidth(): float;\n\n /**\n * @return the height of:\n * - the game resolution for a {@link gdjs.RuntimeScene}\n * - the default dimensions (the AABB of all its children) for a\n * {@link gdjs.CustomRuntimeObject}.\n */\n abstract getViewportHeight(): float;\n\n /**\n * @return the center X of:\n * - the game resolution for a {@link gdjs.RuntimeScene}\n * - the default dimensions (the AABB of all its children) for a\n * {@link gdjs.CustomRuntimeObject}.\n */\n abstract getViewportOriginX(): float;\n\n /**\n * @return the center Y of:\n * - the game resolution for a {@link gdjs.RuntimeScene}\n * - the default dimensions (the AABB of all its children) for a\n * {@link gdjs.CustomRuntimeObject}.\n */\n abstract getViewportOriginY(): float;\n\n /**\n * Triggered when the AABB of a child of the container could have changed.\n */\n abstract onChildrenLocationChanged(): void;\n\n /**\n * Activate or deactivate the debug visualization for collisions and points.\n */\n enableDebugDraw(\n enableDebugDraw: boolean,\n showHiddenInstances: boolean,\n showPointsNames: boolean,\n showCustomPoints: boolean\n ): void {\n if (this._debugDrawEnabled && !enableDebugDraw) {\n this.getDebuggerRenderer().clearDebugDraw();\n }\n\n this._debugDrawEnabled = enableDebugDraw;\n this._debugDrawShowHiddenInstances = showHiddenInstances;\n this._debugDrawShowPointsNames = showPointsNames;\n this._debugDrawShowCustomPoints = showCustomPoints;\n }\n\n /**\n * Check if an object is registered, meaning that instances of it can be\n * created and lives in the container.\n * @see gdjs.RuntimeInstanceContainer#registerObject\n */\n isObjectRegistered(objectName: string): boolean {\n return (\n this._objects.containsKey(objectName) &&\n this._instances.containsKey(objectName) &&\n this._objectsCtor.containsKey(objectName)\n );\n }\n\n /**\n * Register a {@link gdjs.RuntimeObject} so that instances of it can be\n * used in the container.\n * @param objectData The data for the object to register.\n */\n registerObject(objectData: ObjectData) {\n this._objects.put(objectData.name, objectData);\n this._instances.put(objectData.name, []);\n\n // Cache the constructor\n const Ctor = gdjs.getObjectConstructor(objectData.type);\n this._objectsCtor.put(objectData.name, Ctor);\n\n // Also prepare a cache for recycled instances, if the object supports it.\n if (Ctor.supportsReinitialization) {\n this._instancesCache.put(objectData.name, []);\n }\n }\n\n /**\n * Update the data of a {@link gdjs.RuntimeObject} so that instances use\n * this when constructed.\n * @param objectData The data for the object to register.\n */\n updateObject(objectData: ObjectData): void {\n if (!this.isObjectRegistered(objectData.name)) {\n logger.warn(\n 'Tried to call updateObject for an object that was not registered (' +\n objectData.name +\n '). Call registerObject first.'\n );\n }\n this._objects.put(objectData.name, objectData);\n }\n\n // Don't erase instances, nor instances cache, or objectsCtor cache.\n /**\n * Unregister a {@link gdjs.RuntimeObject}. Instances will be destroyed.\n * @param objectName The name of the object to unregister.\n */\n unregisterObject(objectName: string) {\n const instances = this._instances.get(objectName);\n if (instances) {\n // This is sub-optimal: markObjectForDeletion will search the instance to\n // remove in instances, so cost is O(n^2), n being the number of instances.\n // As we're unregistering an object which only happen during a hot-reloading,\n // this is fine.\n const instancesToRemove = instances.slice();\n for (let i = 0; i < instancesToRemove.length; i++) {\n this.markObjectForDeletion(instancesToRemove[i]);\n }\n this._cacheOrClearRemovedInstances();\n }\n this._objects.remove(objectName);\n this._instances.remove(objectName);\n this._instancesCache.remove(objectName);\n this._objectsCtor.remove(objectName);\n }\n\n /**\n * Create objects from initial instances data (for example, the initial instances\n * of the scene or the instances of an external layout).\n *\n * @param data The instances data\n * @param xPos The offset on X axis\n * @param yPos The offset on Y axis\n * @param zPos The offset on Z axis\n * @param trackByPersistentUuid If true, objects are tracked by setting their `persistentUuid`\n * to the same as the associated instance. Useful for hot-reloading when instances are changed.\n */\n createObjectsFrom(\n data: InstanceData[],\n xPos: float,\n yPos: float,\n zPos: float,\n trackByPersistentUuid: boolean\n ): void {\n let zOffset: number;\n let shouldTrackByPersistentUuid: boolean;\n\n if (arguments.length === 5) {\n zOffset = zPos;\n shouldTrackByPersistentUuid = trackByPersistentUuid;\n } else {\n /**\n * Support for the previous signature (before 3D was introduced):\n * createObjectsFrom(data, xPos, yPos, trackByPersistentUuid)\n */\n zOffset = 0;\n shouldTrackByPersistentUuid = arguments[3];\n }\n\n for (let i = 0, len = data.length; i < len; ++i) {\n const instanceData = data[i];\n const objectName = instanceData.name;\n const newObject = this.createObject(objectName);\n if (newObject !== null) {\n if (shouldTrackByPersistentUuid) {\n // Give the object the same persistentUuid as the instance, so that\n // it can be hot-reloaded.\n newObject.persistentUuid = instanceData.persistentUuid || null;\n }\n newObject.setPosition(instanceData.x + xPos, instanceData.y + yPos);\n newObject.setAngle(instanceData.angle);\n if (gdjs.Base3DHandler && gdjs.Base3DHandler.is3D(newObject)) {\n if (instanceData.z !== undefined)\n newObject.setZ(instanceData.z + zOffset);\n if (instanceData.rotationX !== undefined)\n newObject.setRotationX(instanceData.rotationX);\n if (instanceData.rotationY !== undefined)\n newObject.setRotationY(instanceData.rotationY);\n }\n\n newObject.setZOrder(instanceData.zOrder);\n newObject.setLayer(instanceData.layer);\n newObject\n .getVariables()\n .initFrom(instanceData.initialVariables, true);\n newObject.extraInitializationFromInitialInstance(instanceData);\n }\n }\n }\n\n /**\n * Get the data representing the initial shared data of the scene for the specified behavior.\n * @param name The name of the behavior\n * @returns The shared data for the behavior, if any.\n */\n getInitialSharedDataForBehavior(name: string): BehaviorSharedData | null {\n return this._initialBehaviorSharedData.get(name);\n }\n\n /**\n * Set the data representing the initial shared data of the scene for the specified behavior.\n * @param name The name of the behavior\n * @param sharedData The shared data for the behavior, or null to remove it.\n */\n setInitialSharedDataForBehavior(\n name: string,\n sharedData: BehaviorSharedData | null\n ): void {\n this._initialBehaviorSharedData.put(name, sharedData);\n }\n\n /**\n * Set the default Z order for each layer, which is the highest Z order found on each layer.\n * Useful as it ensures that instances created from events are, by default, shown in front\n * of other instances.\n */\n _setLayerDefaultZOrders() {\n if (\n this.getGame().getGameData().properties.useDeprecatedZeroAsDefaultZOrder\n ) {\n // Deprecated option to still support games that were made considered 0 as the\n // default Z order for all layers.\n return;\n }\n const layerHighestZOrders: Record<string, number> = {};\n const allInstances = this.getAdhocListOfAllInstances();\n for (let i = 0, len = allInstances.length; i < len; ++i) {\n const object = allInstances[i];\n let layerName = object.getLayer();\n const zOrder = object.getZOrder();\n if (\n layerHighestZOrders[layerName] === undefined ||\n layerHighestZOrders[layerName] < zOrder\n ) {\n layerHighestZOrders[layerName] = zOrder;\n }\n }\n for (let layerName in layerHighestZOrders) {\n this.getLayer(layerName).setDefaultZOrder(\n layerHighestZOrders[layerName] + 1\n );\n }\n }\n\n _updateLayersCameraCoordinates(scale: float) {\n this._layersCameraCoordinates = this._layersCameraCoordinates || {};\n for (const name in this._layers.items) {\n if (this._layers.items.hasOwnProperty(name)) {\n const theLayer = this._layers.items[name];\n this._layersCameraCoordinates[name] = this._layersCameraCoordinates[\n name\n ] || [0, 0, 0, 0];\n this._layersCameraCoordinates[name][0] =\n theLayer.getCameraX() - (theLayer.getCameraWidth() / 2) * scale;\n this._layersCameraCoordinates[name][1] =\n theLayer.getCameraY() - (theLayer.getCameraHeight() / 2) * scale;\n this._layersCameraCoordinates[name][2] =\n theLayer.getCameraX() + (theLayer.getCameraWidth() / 2) * scale;\n this._layersCameraCoordinates[name][3] =\n theLayer.getCameraY() + (theLayer.getCameraHeight() / 2) * scale;\n }\n }\n }\n\n /**\n * Called to update effects of layers before rendering.\n */\n _updateLayersPreRender() {\n for (const layer of this._orderedLayers) {\n layer.updatePreRender(this);\n }\n }\n\n /**\n * Called to update visibility of the renderers of objects\n * rendered on the scene (\"culling\"), update effects (of visible objects)\n * and give a last chance for objects to update before rendering.\n *\n * Visibility is set to false if object is hidden, or if\n * object is too far from the camera of its layer (\"culling\").\n */\n _updateObjectsPreRender() {\n const allInstancesList = this.getAdhocListOfAllInstances();\n // TODO (3D) culling - add support for 3D object culling?\n for (let i = 0, len = allInstancesList.length; i < len; ++i) {\n const object = allInstancesList[i];\n const rendererObject = object.getRendererObject();\n if (rendererObject) {\n rendererObject.visible = !object.isHidden();\n\n // Update effects, only for visible objects.\n if (rendererObject.visible) {\n this.getGame()\n .getEffectsManager()\n .updatePreRender(object.getRendererEffects(), object);\n }\n }\n\n // Perform pre-render update.\n object.updatePreRender(this);\n }\n return;\n }\n\n /**\n * Empty the list of the removed objects:\n *\n * When an object is removed from the container, it is still kept in\n * {@link gdjs.RuntimeInstanceContainer#_instancesRemoved}.\n *\n * This method should be called regularly (after events or behaviors steps) so as to clear this list\n * and allows the removed objects to be cached (or destroyed if the cache is full).\n *\n * The removed objects could not be sent directly to the cache, as events may still be using them after\n * removing them from the scene for example.\n */\n _cacheOrClearRemovedInstances() {\n for (let k = 0, lenk = this._instancesRemoved.length; k < lenk; ++k) {\n const instance = this._instancesRemoved[k];\n // Cache the instance to recycle it into a new instance later.\n // If the object does not support recycling, the cache won't be defined.\n const cache = this._instancesCache.get(instance.getName());\n if (cache) {\n if (cache.length < 128) {\n cache.push(instance);\n }\n }\n instance.onDestroyed();\n }\n this._instancesRemoved.length = 0;\n }\n\n /**\n * Tool function filling _allInstancesList member with all the living object instances.\n */\n private _constructListOfAllInstances() {\n let currentListSize = 0;\n for (const name in this._instances.items) {\n if (this._instances.items.hasOwnProperty(name)) {\n const list = this._instances.items[name];\n const oldSize = currentListSize;\n currentListSize += list.length;\n for (let j = 0, lenj = list.length; j < lenj; ++j) {\n if (oldSize + j < this._allInstancesList.length) {\n this._allInstancesList[oldSize + j] = list[j];\n } else {\n this._allInstancesList.push(list[j]);\n }\n }\n }\n }\n this._allInstancesList.length = currentListSize;\n this._allInstancesListIsUpToDate = true;\n }\n\n /**\n * @param objectName The name of the object\n * @returns the instances of a given object in the container.\n */\n getInstancesOf(objectName: string): gdjs.RuntimeObject[] {\n return this._instances.items[objectName];\n }\n\n /**\n * Get a list of all {@link gdjs.RuntimeObject} living in the container.\n * You should not, normally, need this method at all. It's only to be used\n * in exceptional use cases where you need to loop through all objects,\n * and it won't be performant.\n *\n * @returns The list of all runtime objects in the container\n */\n getAdhocListOfAllInstances(): gdjs.RuntimeObject[] {\n if (!this._allInstancesListIsUpToDate) {\n this._constructListOfAllInstances();\n }\n return this._allInstancesList;\n }\n\n /**\n * Update the objects before launching the events.\n */\n _updateObjectsPreEvents() {\n // It is *mandatory* to create and iterate on a external list of all objects, as the behaviors\n // may delete the objects.\n const allInstancesList = this.getAdhocListOfAllInstances();\n for (let i = 0, len = allInstancesList.length; i < len; ++i) {\n const obj = allInstancesList[i];\n const elapsedTime = obj.getElapsedTime();\n if (!obj.hasNoForces()) {\n const averageForce = obj.getAverageForce();\n const elapsedTimeInSeconds = elapsedTime / 1000;\n obj.setX(obj.getX() + averageForce.getX() * elapsedTimeInSeconds);\n obj.setY(obj.getY() + averageForce.getY() * elapsedTimeInSeconds);\n obj.update(this);\n obj.updateForces(elapsedTimeInSeconds);\n } else {\n obj.update(this);\n }\n obj.updateTimers(elapsedTime);\n allInstancesList[i].stepBehaviorsPreEvents(this);\n }\n\n // Some behaviors may have request objects to be deleted.\n this._cacheOrClearRemovedInstances();\n }\n\n /**\n * Update the objects (update positions, time management...)\n */\n _updateObjectsPostEvents() {\n this._cacheOrClearRemovedInstances();\n\n // It is *mandatory* to create and iterate on a external list of all objects, as the behaviors\n // may delete the objects.\n const allInstancesList = this.getAdhocListOfAllInstances();\n for (let i = 0, len = allInstancesList.length; i < len; ++i) {\n allInstancesList[i].stepBehaviorsPostEvents(this);\n }\n\n // Some behaviors may have request objects to be deleted.\n this._cacheOrClearRemovedInstances();\n }\n\n /**\n * Add an object to the instances living in the container.\n * @param obj The object to be added.\n */\n addObject(obj: gdjs.RuntimeObject) {\n if (!this._instances.containsKey(obj.name)) {\n this._instances.put(obj.name, []);\n }\n this._instances.get(obj.name).push(obj);\n this._allInstancesListIsUpToDate = false;\n }\n\n /**\n * Get all the instances of the object called name.\n * @param name Name of the object for which the instances must be returned.\n * @return The list of objects with the given name\n */\n getObjects(name: string): gdjs.RuntimeObject[] | undefined {\n if (!this._instances.containsKey(name)) {\n logger.info(\n 'RuntimeScene.getObjects: No instances called \"' +\n name +\n '\"! Adding it.'\n );\n this._instances.put(name, []);\n }\n return this._instances.get(name);\n }\n\n /**\n * Create a new object from its name. The object is also added to the instances\n * living in the container (No need to call {@link gdjs.RuntimeScene.addObject})\n * @param objectName The name of the object to be created\n * @return The created object\n */\n createObject(objectName: string): gdjs.RuntimeObject | null {\n if (\n !this._objectsCtor.containsKey(objectName) ||\n !this._objects.containsKey(objectName)\n ) {\n // There is no such object in this container.\n return null;\n }\n\n // Create a new object using the object constructor (cached during loading)\n // and the stored object's data:\n const cache = this._instancesCache.get(objectName);\n const ctor = this._objectsCtor.get(objectName);\n let obj;\n if (!cache || cache.length === 0) {\n obj = new ctor(this, this._objects.get(objectName));\n } else {\n // Reuse an objet destroyed before. If there is an object in the cache,\n // then it means it does support reinitialization.\n obj = cache.pop();\n obj.reinitialize(this._objects.get(objectName));\n }\n this.addObject(obj);\n return obj;\n }\n\n /**\n * Must be called whenever an object must be removed from the container.\n * @param obj The object to be removed.\n */\n markObjectForDeletion(obj: gdjs.RuntimeObject) {\n // Add to the objects removed list.\n // The objects will be sent to the instances cache or really deleted from memory later.\n if (this._instancesRemoved.indexOf(obj) === -1) {\n this._instancesRemoved.push(obj);\n }\n\n // Delete from the living instances.\n if (this._instances.containsKey(obj.getName())) {\n const objId = obj.id;\n const allInstances = this._instances.get(obj.getName());\n for (let i = 0, len = allInstances.length; i < len; ++i) {\n if (allInstances[i].id == objId) {\n allInstances.splice(i, 1);\n this._allInstancesListIsUpToDate = false;\n break;\n }\n }\n }\n\n // Notify the object it was removed from the container\n obj.onDeletedFromScene(this);\n\n // Notify the global callbacks\n for (let j = 0; j < gdjs.callbacksObjectDeletedFromScene.length; ++j) {\n gdjs.callbacksObjectDeletedFromScene[j](this, obj);\n }\n return;\n }\n\n /**\n * Get the layer with the given name\n * @param name The name of the layer\n * @returns The layer, or the base layer if not found\n */\n getLayer(name: string): gdjs.RuntimeLayer {\n if (this._layers.containsKey(name)) {\n return this._layers.get(name);\n }\n return this._layers.get('');\n }\n\n /**\n * Check if a layer exists\n * @param name The name of the layer\n */\n hasLayer(name: string): boolean {\n return this._layers.containsKey(name);\n }\n\n /**\n * Add a layer.\n * @param layerData The data to construct the layer\n */\n abstract addLayer(layerData: LayerData);\n\n /**\n * Remove a layer. All {@link gdjs.RuntimeObject} on this layer will\n * be moved back to the base layer.\n * @param layerName The name of the layer to remove\n */\n removeLayer(layerName: string) {\n const existingLayer = this._layers.get(layerName);\n if (!existingLayer) return;\n\n const allInstances = this.getAdhocListOfAllInstances();\n for (let i = 0; i < allInstances.length; ++i) {\n const runtimeObject = allInstances[i];\n if (runtimeObject.getLayer() === layerName) {\n runtimeObject.setLayer('');\n }\n }\n this._layers.remove(layerName);\n const layerIndex = this._orderedLayers.indexOf(existingLayer);\n this._orderedLayers.splice(layerIndex, 1);\n }\n\n /**\n * Change the position of a layer.\n *\n * @param layerName The name of the layer to reorder\n * @param index The new position in the list of layers\n */\n setLayerIndex(layerName: string, newIndex: integer): void {\n const layer: gdjs.RuntimeLayer = this._layers.get(layerName);\n if (!layer) {\n return;\n }\n const layerIndex = this._orderedLayers.indexOf(layer);\n if (layerIndex === newIndex) return;\n\n this._orderedLayers.splice(layerIndex, 1);\n this._orderedLayers.splice(newIndex, 0, layer);\n\n this.getRenderer().setLayerIndex(layer, newIndex);\n }\n\n /**\n * Fill the array passed as argument with the names of all layers\n * @param result The array where to put the layer names\n */\n getAllLayerNames(result: string[]) {\n this._layers.keys(result);\n }\n\n /**\n * Return the number of instances of the specified object living in the container.\n * @param objectName The object name for which instances must be counted.\n */\n getInstancesCountOnScene(objectName: string): integer {\n const instances = this._instances.get(objectName);\n if (instances) {\n return instances.length;\n }\n\n return 0;\n }\n\n /**\n * Update the objects positions according to their forces\n */\n updateObjectsForces(): void {\n for (const name in this._instances.items) {\n if (this._instances.items.hasOwnProperty(name)) {\n const list = this._instances.items[name];\n for (let j = 0, listLen = list.length; j < listLen; ++j) {\n const obj = list[j];\n if (!obj.hasNoForces()) {\n const averageForce = obj.getAverageForce();\n const elapsedTimeInSeconds = obj.getElapsedTime() / 1000;\n obj.setX(obj.getX() + averageForce.getX() * elapsedTimeInSeconds);\n obj.setY(obj.getY() + averageForce.getY() * elapsedTimeInSeconds);\n obj.updateForces(elapsedTimeInSeconds);\n }\n }\n }\n }\n }\n\n /**\n * Clear any data structures to make sure memory is freed as soon as\n * possible.\n */\n _destroy() {\n // It should not be necessary to reset these variables, but this help\n // ensuring that all memory related to the container is released immediately.\n this._layers = new Hashtable();\n this._orderedLayers = [];\n this._objects = new Hashtable();\n this._instances = new Hashtable();\n this._instancesCache = new Hashtable();\n this._objectsCtor = new Hashtable();\n this._allInstancesList = [];\n this._instancesRemoved = [];\n }\n }\n}\n"],
|
|
5
|
-
"mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CACE,KAAM,GAAS,GAAI,GAAK,OAAO,4BAKxB,OAAwC,CAiC7C,aAAc,CAvBN,uBAA0C,GAClD,iCAA8B,GAM9B,uBAA0C,GAQ1C,8BAAyE,GAGzE,uBAA6B,GAC7B,mCAAyC,GACzC,+BAAqC,GACrC,gCAAsC,GAGpC,KAAK,2BAA6B,GAAI,WACtC,KAAK,WAAa,GAAI,WACtB,KAAK,gBAAkB,GAAI,WAC3B,KAAK,SAAW,GAAI,WACpB,KAAK,aAAe,GAAI,WACxB,KAAK,QAAU,GAAI,WACnB,KAAK,eAAiB,GA+JxB,gBACE,EACA,EACA,EACA,EACM,CACN,AAAI,KAAK,mBAAqB,CAAC,GAC7B,KAAK,sBAAsB,iBAG7B,KAAK,kBAAoB,EACzB,KAAK,8BAAgC,EACrC,KAAK,0B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\n * GDevelop JS Platform\n * Copyright 2013-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.\n * This project is released under the MIT License.\n */\nnamespace gdjs {\n const logger = new gdjs.Logger('RuntimeInstanceContainer');\n\n /**\n * A container of object instances rendered on screen.\n */\n export abstract class RuntimeInstanceContainer {\n _initialBehaviorSharedData: Hashtable<BehaviorSharedData | null>;\n\n /** Contains the instances living on the container */\n _instances: Hashtable<RuntimeObject[]>;\n\n /**\n * An array used to create a list of all instance when necessary.\n * @see gdjs.RuntimeInstanceContainer#_constructListOfAllInstances}\n */\n private _allInstancesList: gdjs.RuntimeObject[] = [];\n _allInstancesListIsUpToDate = true;\n\n /** Used to recycle destroyed instance instead of creating new ones. */\n _instancesCache: Hashtable<RuntimeObject[]>;\n\n /** The instances removed from the container and waiting to be sent to the cache. */\n _instancesRemoved: gdjs.RuntimeObject[] = [];\n\n /** Contains the objects data stored in the project */\n _objects: Hashtable<ObjectData>;\n _objectsCtor: Hashtable<typeof RuntimeObject>;\n\n _layers: Hashtable<RuntimeLayer>;\n _orderedLayers: RuntimeLayer[]; // TODO: should this be a single structure with _layers, to enforce its usage?\n _layersCameraCoordinates: Record<string, [float, float, float, float]> = {};\n\n // Options for the debug draw:\n _debugDrawEnabled: boolean = false;\n _debugDrawShowHiddenInstances: boolean = false;\n _debugDrawShowPointsNames: boolean = false;\n _debugDrawShowCustomPoints: boolean = false;\n\n constructor() {\n this._initialBehaviorSharedData = new Hashtable();\n this._instances = new Hashtable();\n this._instancesCache = new Hashtable();\n this._objects = new Hashtable();\n this._objectsCtor = new Hashtable();\n this._layers = new Hashtable();\n this._orderedLayers = [];\n }\n\n /**\n * Return the time elapsed since the last frame,\n * in milliseconds, for objects on the layer.\n */\n abstract getElapsedTime(): float;\n\n /**\n * Get the renderer associated to the container.\n */\n abstract getRenderer(): gdjs.RuntimeInstanceContainerRenderer;\n\n /**\n * Get the renderer for visual debugging associated to the container.\n */\n abstract getDebuggerRenderer(): gdjs.DebuggerRenderer;\n\n /**\n * Get the {@link gdjs.RuntimeGame} associated to this.\n */\n abstract getGame(): gdjs.RuntimeGame;\n\n /**\n * Get the {@link gdjs.RuntimeScene} associated to this.\n */\n abstract getScene(): gdjs.RuntimeScene;\n\n abstract getAsyncTasksManager(): gdjs.AsyncTasksManager;\n\n /**\n * Convert a point from the canvas coordinates (for example,\n * the mouse position) to the container coordinates.\n *\n * @param x The x position, in container coordinates.\n * @param y The y position, in container coordinates.\n * @param result The point instance that is used to return the result.\n */\n abstract convertCoords(x: float, y: float, result?: FloatPoint): FloatPoint;\n\n /**\n * Convert a point from the container coordinates (for example,\n * an object position) to the canvas coordinates.\n *\n * @param sceneX The x position, in container coordinates.\n * @param sceneY The y position, in container coordinates.\n * @param result The point instance that is used to return the result.\n */\n abstract convertInverseCoords(\n sceneX: float,\n sceneY: float,\n result: FloatPoint\n ): FloatPoint;\n\n /**\n * @return the left bound of:\n * - the game resolution for a {@link gdjs.RuntimeScene}\n * - the default dimensions (the AABB of all its children) for a\n * {@link gdjs.CustomRuntimeObject}.\n */\n abstract getUnrotatedViewportMinX(): float;\n\n /**\n * @return the top bound of:\n * - the game resolution for a {@link gdjs.RuntimeScene}\n * - the default dimensions (the AABB of all its children) for a\n * {@link gdjs.CustomRuntimeObject}.\n */\n abstract getUnrotatedViewportMinY(): float;\n\n /**\n * @return the right bound of:\n * - the game resolution for a {@link gdjs.RuntimeScene}\n * - the default dimensions (the AABB of all its children) for a\n * {@link gdjs.CustomRuntimeObject}.\n */\n abstract getUnrotatedViewportMaxX(): float;\n\n /**\n * @return the bottom bound of:\n * - the game resolution for a {@link gdjs.RuntimeScene}\n * - the default dimensions (the AABB of all its children) for a\n * {@link gdjs.CustomRuntimeObject}.\n */\n abstract getUnrotatedViewportMaxY(): float;\n\n /**\n * @return the left bound of:\n * - the initial game resolution for a {@link gdjs.RuntimeScene}\n * - the initial default dimensions (inner area) set in the editor for a\n * {@link gdjs.CustomRuntimeObject}.\n */\n abstract getInitialUnrotatedViewportMinX(): float;\n\n /**\n * @return the top bound of:\n * - the initial game resolution for a {@link gdjs.RuntimeScene}\n * - the initial default dimensions (inner area) set in the editor for a\n * {@link gdjs.CustomRuntimeObject}.\n */\n abstract getInitialUnrotatedViewportMinY(): float;\n\n /**\n * @return the right bound of:\n * - the initial game resolution for a {@link gdjs.RuntimeScene}\n * - the initial default dimensions (inner area) set in the editor for a\n * {@link gdjs.CustomRuntimeObject}.\n */\n abstract getInitialUnrotatedViewportMaxX(): float;\n\n /**\n * @return the bottom bound of:\n * - the initial game resolution for a {@link gdjs.RuntimeScene}\n * - the initial default dimensions (inner area) set in the editor for a\n * {@link gdjs.CustomRuntimeObject}.\n */\n abstract getInitialUnrotatedViewportMaxY(): float;\n\n /**\n * @return the width of:\n * - the game resolution for a {@link gdjs.RuntimeScene}\n * - the default dimensions (the AABB of all its children) for a\n * {@link gdjs.CustomRuntimeObject}.\n */\n abstract getViewportWidth(): float;\n\n /**\n * @return the height of:\n * - the game resolution for a {@link gdjs.RuntimeScene}\n * - the default dimensions (the AABB of all its children) for a\n * {@link gdjs.CustomRuntimeObject}.\n */\n abstract getViewportHeight(): float;\n\n /**\n * @return the center X of:\n * - the game resolution for a {@link gdjs.RuntimeScene}\n * - the default dimensions (the AABB of all its children) for a\n * {@link gdjs.CustomRuntimeObject}.\n */\n abstract getViewportOriginX(): float;\n\n /**\n * @return the center Y of:\n * - the game resolution for a {@link gdjs.RuntimeScene}\n * - the default dimensions (the AABB of all its children) for a\n * {@link gdjs.CustomRuntimeObject}.\n */\n abstract getViewportOriginY(): float;\n\n /**\n * Triggered when the AABB of a child of the container could have changed.\n */\n abstract onChildrenLocationChanged(): void;\n\n /**\n * Activate or deactivate the debug visualization for collisions and points.\n */\n enableDebugDraw(\n enableDebugDraw: boolean,\n showHiddenInstances: boolean,\n showPointsNames: boolean,\n showCustomPoints: boolean\n ): void {\n if (this._debugDrawEnabled && !enableDebugDraw) {\n this.getDebuggerRenderer().clearDebugDraw();\n }\n\n this._debugDrawEnabled = enableDebugDraw;\n this._debugDrawShowHiddenInstances = showHiddenInstances;\n this._debugDrawShowPointsNames = showPointsNames;\n this._debugDrawShowCustomPoints = showCustomPoints;\n }\n\n /**\n * Check if an object is registered, meaning that instances of it can be\n * created and lives in the container.\n * @see gdjs.RuntimeInstanceContainer#registerObject\n */\n isObjectRegistered(objectName: string): boolean {\n return (\n this._objects.containsKey(objectName) &&\n this._instances.containsKey(objectName) &&\n this._objectsCtor.containsKey(objectName)\n );\n }\n\n /**\n * Register a {@link gdjs.RuntimeObject} so that instances of it can be\n * used in the container.\n * @param objectData The data for the object to register.\n */\n registerObject(objectData: ObjectData) {\n this._objects.put(objectData.name, objectData);\n this._instances.put(objectData.name, []);\n\n // Cache the constructor\n const Ctor = gdjs.getObjectConstructor(objectData.type);\n this._objectsCtor.put(objectData.name, Ctor);\n\n // Also prepare a cache for recycled instances, if the object supports it.\n if (Ctor.supportsReinitialization) {\n this._instancesCache.put(objectData.name, []);\n }\n }\n\n /**\n * Update the data of a {@link gdjs.RuntimeObject} so that instances use\n * this when constructed.\n * @param objectData The data for the object to register.\n */\n updateObject(objectData: ObjectData): void {\n if (!this.isObjectRegistered(objectData.name)) {\n logger.warn(\n 'Tried to call updateObject for an object that was not registered (' +\n objectData.name +\n '). Call registerObject first.'\n );\n }\n this._objects.put(objectData.name, objectData);\n }\n\n // Don't erase instances, nor instances cache, or objectsCtor cache.\n /**\n * Unregister a {@link gdjs.RuntimeObject}. Instances will be destroyed.\n * @param objectName The name of the object to unregister.\n */\n unregisterObject(objectName: string) {\n const instances = this._instances.get(objectName);\n if (instances) {\n // This is sub-optimal: markObjectForDeletion will search the instance to\n // remove in instances, so cost is O(n^2), n being the number of instances.\n // As we're unregistering an object which only happen during a hot-reloading,\n // this is fine.\n const instancesToRemove = instances.slice();\n for (let i = 0; i < instancesToRemove.length; i++) {\n this.markObjectForDeletion(instancesToRemove[i]);\n }\n this._cacheOrClearRemovedInstances();\n }\n this._objects.remove(objectName);\n this._instances.remove(objectName);\n this._instancesCache.remove(objectName);\n this._objectsCtor.remove(objectName);\n }\n\n /**\n * Create objects from initial instances data (for example, the initial instances\n * of the scene or the instances of an external layout).\n *\n * @param data The instances data\n * @param xPos The offset on X axis\n * @param yPos The offset on Y axis\n * @param zPos The offset on Z axis\n * @param trackByPersistentUuid If true, objects are tracked by setting their `persistentUuid`\n * to the same as the associated instance. Useful for hot-reloading when instances are changed.\n */\n createObjectsFrom(\n data: InstanceData[],\n xPos: float,\n yPos: float,\n zPos: float,\n trackByPersistentUuid: boolean\n ): void {\n let zOffset: number;\n let shouldTrackByPersistentUuid: boolean;\n\n if (arguments.length === 5) {\n zOffset = zPos;\n shouldTrackByPersistentUuid = trackByPersistentUuid;\n } else {\n /**\n * Support for the previous signature (before 3D was introduced):\n * createObjectsFrom(data, xPos, yPos, trackByPersistentUuid)\n */\n zOffset = 0;\n shouldTrackByPersistentUuid = arguments[3];\n }\n\n for (let i = 0, len = data.length; i < len; ++i) {\n const instanceData = data[i];\n const objectName = instanceData.name;\n const newObject = this.createObject(objectName);\n if (newObject !== null) {\n if (shouldTrackByPersistentUuid) {\n // Give the object the same persistentUuid as the instance, so that\n // it can be hot-reloaded.\n newObject.persistentUuid = instanceData.persistentUuid || null;\n }\n newObject.setPosition(instanceData.x + xPos, instanceData.y + yPos);\n newObject.setAngle(instanceData.angle);\n if (gdjs.Base3DHandler && gdjs.Base3DHandler.is3D(newObject)) {\n newObject.setZ((instanceData.z || 0) + zOffset);\n if (instanceData.rotationX !== undefined)\n newObject.setRotationX(instanceData.rotationX);\n if (instanceData.rotationY !== undefined)\n newObject.setRotationY(instanceData.rotationY);\n }\n\n newObject.setZOrder(instanceData.zOrder);\n newObject.setLayer(instanceData.layer);\n newObject\n .getVariables()\n .initFrom(instanceData.initialVariables, true);\n newObject.extraInitializationFromInitialInstance(instanceData);\n }\n }\n }\n\n /**\n * Get the data representing the initial shared data of the scene for the specified behavior.\n * @param name The name of the behavior\n * @returns The shared data for the behavior, if any.\n */\n getInitialSharedDataForBehavior(name: string): BehaviorSharedData | null {\n return this._initialBehaviorSharedData.get(name);\n }\n\n /**\n * Set the data representing the initial shared data of the scene for the specified behavior.\n * @param name The name of the behavior\n * @param sharedData The shared data for the behavior, or null to remove it.\n */\n setInitialSharedDataForBehavior(\n name: string,\n sharedData: BehaviorSharedData | null\n ): void {\n this._initialBehaviorSharedData.put(name, sharedData);\n }\n\n /**\n * Set the default Z order for each layer, which is the highest Z order found on each layer.\n * Useful as it ensures that instances created from events are, by default, shown in front\n * of other instances.\n */\n _setLayerDefaultZOrders() {\n if (\n this.getGame().getGameData().properties.useDeprecatedZeroAsDefaultZOrder\n ) {\n // Deprecated option to still support games that were made considered 0 as the\n // default Z order for all layers.\n return;\n }\n const layerHighestZOrders: Record<string, number> = {};\n const allInstances = this.getAdhocListOfAllInstances();\n for (let i = 0, len = allInstances.length; i < len; ++i) {\n const object = allInstances[i];\n let layerName = object.getLayer();\n const zOrder = object.getZOrder();\n if (\n layerHighestZOrders[layerName] === undefined ||\n layerHighestZOrders[layerName] < zOrder\n ) {\n layerHighestZOrders[layerName] = zOrder;\n }\n }\n for (let layerName in layerHighestZOrders) {\n this.getLayer(layerName).setDefaultZOrder(\n layerHighestZOrders[layerName] + 1\n );\n }\n }\n\n _updateLayersCameraCoordinates(scale: float) {\n this._layersCameraCoordinates = this._layersCameraCoordinates || {};\n for (const name in this._layers.items) {\n if (this._layers.items.hasOwnProperty(name)) {\n const theLayer = this._layers.items[name];\n this._layersCameraCoordinates[name] = this._layersCameraCoordinates[\n name\n ] || [0, 0, 0, 0];\n this._layersCameraCoordinates[name][0] =\n theLayer.getCameraX() - (theLayer.getCameraWidth() / 2) * scale;\n this._layersCameraCoordinates[name][1] =\n theLayer.getCameraY() - (theLayer.getCameraHeight() / 2) * scale;\n this._layersCameraCoordinates[name][2] =\n theLayer.getCameraX() + (theLayer.getCameraWidth() / 2) * scale;\n this._layersCameraCoordinates[name][3] =\n theLayer.getCameraY() + (theLayer.getCameraHeight() / 2) * scale;\n }\n }\n }\n\n /**\n * Called to update effects of layers before rendering.\n */\n _updateLayersPreRender() {\n for (const layer of this._orderedLayers) {\n layer.updatePreRender(this);\n }\n }\n\n /**\n * Called to update visibility of the renderers of objects\n * rendered on the scene (\"culling\"), update effects (of visible objects)\n * and give a last chance for objects to update before rendering.\n *\n * Visibility is set to false if object is hidden, or if\n * object is too far from the camera of its layer (\"culling\").\n */\n _updateObjectsPreRender() {\n const allInstancesList = this.getAdhocListOfAllInstances();\n // TODO (3D) culling - add support for 3D object culling?\n for (let i = 0, len = allInstancesList.length; i < len; ++i) {\n const object = allInstancesList[i];\n const rendererObject = object.getRendererObject();\n if (rendererObject) {\n rendererObject.visible = !object.isHidden();\n\n // Update effects, only for visible objects.\n if (rendererObject.visible) {\n this.getGame()\n .getEffectsManager()\n .updatePreRender(object.getRendererEffects(), object);\n }\n }\n\n // Perform pre-render update.\n object.updatePreRender(this);\n }\n return;\n }\n\n /**\n * Empty the list of the removed objects:\n *\n * When an object is removed from the container, it is still kept in\n * {@link gdjs.RuntimeInstanceContainer#_instancesRemoved}.\n *\n * This method should be called regularly (after events or behaviors steps) so as to clear this list\n * and allows the removed objects to be cached (or destroyed if the cache is full).\n *\n * The removed objects could not be sent directly to the cache, as events may still be using them after\n * removing them from the scene for example.\n */\n _cacheOrClearRemovedInstances() {\n for (let k = 0, lenk = this._instancesRemoved.length; k < lenk; ++k) {\n const instance = this._instancesRemoved[k];\n // Cache the instance to recycle it into a new instance later.\n // If the object does not support recycling, the cache won't be defined.\n const cache = this._instancesCache.get(instance.getName());\n if (cache) {\n if (cache.length < 128) {\n cache.push(instance);\n }\n }\n instance.onDestroyed();\n }\n this._instancesRemoved.length = 0;\n }\n\n /**\n * Tool function filling _allInstancesList member with all the living object instances.\n */\n private _constructListOfAllInstances() {\n let currentListSize = 0;\n for (const name in this._instances.items) {\n if (this._instances.items.hasOwnProperty(name)) {\n const list = this._instances.items[name];\n const oldSize = currentListSize;\n currentListSize += list.length;\n for (let j = 0, lenj = list.length; j < lenj; ++j) {\n if (oldSize + j < this._allInstancesList.length) {\n this._allInstancesList[oldSize + j] = list[j];\n } else {\n this._allInstancesList.push(list[j]);\n }\n }\n }\n }\n this._allInstancesList.length = currentListSize;\n this._allInstancesListIsUpToDate = true;\n }\n\n /**\n * @param objectName The name of the object\n * @returns the instances of a given object in the container.\n */\n getInstancesOf(objectName: string): gdjs.RuntimeObject[] {\n return this._instances.items[objectName];\n }\n\n /**\n * Get a list of all {@link gdjs.RuntimeObject} living in the container.\n * You should not, normally, need this method at all. It's only to be used\n * in exceptional use cases where you need to loop through all objects,\n * and it won't be performant.\n *\n * @returns The list of all runtime objects in the container\n */\n getAdhocListOfAllInstances(): gdjs.RuntimeObject[] {\n if (!this._allInstancesListIsUpToDate) {\n this._constructListOfAllInstances();\n }\n return this._allInstancesList;\n }\n\n /**\n * Update the objects before launching the events.\n */\n _updateObjectsPreEvents() {\n // It is *mandatory* to create and iterate on a external list of all objects, as the behaviors\n // may delete the objects.\n const allInstancesList = this.getAdhocListOfAllInstances();\n for (let i = 0, len = allInstancesList.length; i < len; ++i) {\n const obj = allInstancesList[i];\n const elapsedTime = obj.getElapsedTime();\n if (!obj.hasNoForces()) {\n const averageForce = obj.getAverageForce();\n const elapsedTimeInSeconds = elapsedTime / 1000;\n obj.setX(obj.getX() + averageForce.getX() * elapsedTimeInSeconds);\n obj.setY(obj.getY() + averageForce.getY() * elapsedTimeInSeconds);\n obj.update(this);\n obj.updateForces(elapsedTimeInSeconds);\n } else {\n obj.update(this);\n }\n obj.updateTimers(elapsedTime);\n allInstancesList[i].stepBehaviorsPreEvents(this);\n }\n\n // Some behaviors may have request objects to be deleted.\n this._cacheOrClearRemovedInstances();\n }\n\n /**\n * Update the objects (update positions, time management...)\n */\n _updateObjectsPostEvents() {\n this._cacheOrClearRemovedInstances();\n\n // It is *mandatory* to create and iterate on a external list of all objects, as the behaviors\n // may delete the objects.\n const allInstancesList = this.getAdhocListOfAllInstances();\n for (let i = 0, len = allInstancesList.length; i < len; ++i) {\n allInstancesList[i].stepBehaviorsPostEvents(this);\n }\n\n // Some behaviors may have request objects to be deleted.\n this._cacheOrClearRemovedInstances();\n }\n\n /**\n * Add an object to the instances living in the container.\n * @param obj The object to be added.\n */\n addObject(obj: gdjs.RuntimeObject) {\n if (!this._instances.containsKey(obj.name)) {\n this._instances.put(obj.name, []);\n }\n this._instances.get(obj.name).push(obj);\n this._allInstancesListIsUpToDate = false;\n }\n\n /**\n * Get all the instances of the object called name.\n * @param name Name of the object for which the instances must be returned.\n * @return The list of objects with the given name\n */\n getObjects(name: string): gdjs.RuntimeObject[] | undefined {\n if (!this._instances.containsKey(name)) {\n logger.info(\n 'RuntimeScene.getObjects: No instances called \"' +\n name +\n '\"! Adding it.'\n );\n this._instances.put(name, []);\n }\n return this._instances.get(name);\n }\n\n /**\n * Create a new object from its name. The object is also added to the instances\n * living in the container (No need to call {@link gdjs.RuntimeScene.addObject})\n * @param objectName The name of the object to be created\n * @return The created object\n */\n createObject(objectName: string): gdjs.RuntimeObject | null {\n if (\n !this._objectsCtor.containsKey(objectName) ||\n !this._objects.containsKey(objectName)\n ) {\n // There is no such object in this container.\n return null;\n }\n\n // Create a new object using the object constructor (cached during loading)\n // and the stored object's data:\n const cache = this._instancesCache.get(objectName);\n const ctor = this._objectsCtor.get(objectName);\n let obj;\n if (!cache || cache.length === 0) {\n obj = new ctor(this, this._objects.get(objectName));\n } else {\n // Reuse an objet destroyed before. If there is an object in the cache,\n // then it means it does support reinitialization.\n obj = cache.pop();\n obj.reinitialize(this._objects.get(objectName));\n }\n this.addObject(obj);\n return obj;\n }\n\n /**\n * Must be called whenever an object must be removed from the container.\n * @param obj The object to be removed.\n */\n markObjectForDeletion(obj: gdjs.RuntimeObject) {\n // Add to the objects removed list.\n // The objects will be sent to the instances cache or really deleted from memory later.\n if (this._instancesRemoved.indexOf(obj) === -1) {\n this._instancesRemoved.push(obj);\n }\n\n // Delete from the living instances.\n if (this._instances.containsKey(obj.getName())) {\n const objId = obj.id;\n const allInstances = this._instances.get(obj.getName());\n for (let i = 0, len = allInstances.length; i < len; ++i) {\n if (allInstances[i].id == objId) {\n allInstances.splice(i, 1);\n this._allInstancesListIsUpToDate = false;\n break;\n }\n }\n }\n\n // Notify the object it was removed from the container\n obj.onDeletedFromScene(this);\n\n // Notify the global callbacks\n for (let j = 0; j < gdjs.callbacksObjectDeletedFromScene.length; ++j) {\n gdjs.callbacksObjectDeletedFromScene[j](this, obj);\n }\n return;\n }\n\n /**\n * Get the layer with the given name\n * @param name The name of the layer\n * @returns The layer, or the base layer if not found\n */\n getLayer(name: string): gdjs.RuntimeLayer {\n if (this._layers.containsKey(name)) {\n return this._layers.get(name);\n }\n return this._layers.get('');\n }\n\n /**\n * Check if a layer exists\n * @param name The name of the layer\n */\n hasLayer(name: string): boolean {\n return this._layers.containsKey(name);\n }\n\n /**\n * Add a layer.\n * @param layerData The data to construct the layer\n */\n abstract addLayer(layerData: LayerData);\n\n /**\n * Remove a layer. All {@link gdjs.RuntimeObject} on this layer will\n * be moved back to the base layer.\n * @param layerName The name of the layer to remove\n */\n removeLayer(layerName: string) {\n const existingLayer = this._layers.get(layerName);\n if (!existingLayer) return;\n\n const allInstances = this.getAdhocListOfAllInstances();\n for (let i = 0; i < allInstances.length; ++i) {\n const runtimeObject = allInstances[i];\n if (runtimeObject.getLayer() === layerName) {\n runtimeObject.setLayer('');\n }\n }\n this._layers.remove(layerName);\n const layerIndex = this._orderedLayers.indexOf(existingLayer);\n this._orderedLayers.splice(layerIndex, 1);\n }\n\n /**\n * Change the position of a layer.\n *\n * @param layerName The name of the layer to reorder\n * @param index The new position in the list of layers\n */\n setLayerIndex(layerName: string, newIndex: integer): void {\n const layer: gdjs.RuntimeLayer = this._layers.get(layerName);\n if (!layer) {\n return;\n }\n const layerIndex = this._orderedLayers.indexOf(layer);\n if (layerIndex === newIndex) return;\n\n this._orderedLayers.splice(layerIndex, 1);\n this._orderedLayers.splice(newIndex, 0, layer);\n\n this.getRenderer().setLayerIndex(layer, newIndex);\n }\n\n /**\n * Fill the array passed as argument with the names of all layers\n * @param result The array where to put the layer names\n */\n getAllLayerNames(result: string[]) {\n this._layers.keys(result);\n }\n\n /**\n * Return the number of instances of the specified object living in the container.\n * @param objectName The object name for which instances must be counted.\n */\n getInstancesCountOnScene(objectName: string): integer {\n const instances = this._instances.get(objectName);\n if (instances) {\n return instances.length;\n }\n\n return 0;\n }\n\n /**\n * Update the objects positions according to their forces\n */\n updateObjectsForces(): void {\n for (const name in this._instances.items) {\n if (this._instances.items.hasOwnProperty(name)) {\n const list = this._instances.items[name];\n for (let j = 0, listLen = list.length; j < listLen; ++j) {\n const obj = list[j];\n if (!obj.hasNoForces()) {\n const averageForce = obj.getAverageForce();\n const elapsedTimeInSeconds = obj.getElapsedTime() / 1000;\n obj.setX(obj.getX() + averageForce.getX() * elapsedTimeInSeconds);\n obj.setY(obj.getY() + averageForce.getY() * elapsedTimeInSeconds);\n obj.updateForces(elapsedTimeInSeconds);\n }\n }\n }\n }\n }\n\n /**\n * Clear any data structures to make sure memory is freed as soon as\n * possible.\n */\n _destroy() {\n // It should not be necessary to reset these variables, but this help\n // ensuring that all memory related to the container is released immediately.\n this._layers = new Hashtable();\n this._orderedLayers = [];\n this._objects = new Hashtable();\n this._instances = new Hashtable();\n this._instancesCache = new Hashtable();\n this._objectsCtor = new Hashtable();\n this._allInstancesList = [];\n this._instancesRemoved = [];\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CACE,KAAM,GAAS,GAAI,GAAK,OAAO,4BAKxB,OAAwC,CAiC7C,aAAc,CAvBN,uBAA0C,GAClD,iCAA8B,GAM9B,uBAA0C,GAQ1C,8BAAyE,GAGzE,uBAA6B,GAC7B,mCAAyC,GACzC,+BAAqC,GACrC,gCAAsC,GAGpC,KAAK,2BAA6B,GAAI,WACtC,KAAK,WAAa,GAAI,WACtB,KAAK,gBAAkB,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cAAc,cAAc,EAAO,IAO1C,iBAAiB,EAAkB,CACjC,KAAK,QAAQ,KAAK,GAOpB,yBAAyB,EAA6B,CACpD,KAAM,GAAY,KAAK,WAAW,IAAI,GACtC,MAAI,GACK,EAAU,OAGZ,EAMT,qBAA4B,CAC1B,SAAW,KAAQ,MAAK,WAAW,MACjC,GAAI,KAAK,WAAW,MAAM,eAAe,GAAO,CAC9C,KAAM,GAAO,KAAK,WAAW,MAAM,GACnC,OAAS,GAAI,EAAG,EAAU,EAAK,OAAQ,EAAI,EAAS,EAAE,EAAG,CACvD,KAAM,GAAM,EAAK,GACjB,GAAI,CAAC,EAAI,cAAe,CACtB,KAAM,GAAe,EAAI,kBACnB,EAAuB,EAAI,iBAAmB,IACpD,EAAI,KAAK,EAAI,OAAS,EAAa,OAAS,GAC5C,EAAI,KAAK,EAAI,OAAS,EAAa,OAAS,GAC5C,EAAI,aAAa,MAW3B,UAAW,CAGT,KAAK,QAAU,GAAI,WACnB,KAAK,eAAiB,GACtB,KAAK,SAAW,GAAI,WACpB,KAAK,WAAa,GAAI,WACtB,KAAK,gBAAkB,GAAI,WAC3B,KAAK,aAAe,GAAI,WACxB,KAAK,kBAAoB,GACzB,KAAK,kBAAoB,IAjyBtB,EAAe,6BANd",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var gdjs;(function(i){let n;(function(
|
|
1
|
+
var gdjs;(function(i){let n;(function(r){r[r.TWO_D=0]="TWO_D",r[r.THREE_D=1]="THREE_D",r[r.TWO_D_PLUS_THREE_D=2]="TWO_D_PLUS_THREE_D"})(n=i.RuntimeLayerRenderingType||(i.RuntimeLayerRenderingType={}));const f=a=>a==="3d"?1:a==="2d+3d"||a===""?2:0;let s;(function(t){t[t.PERSPECTIVE=0]="PERSPECTIVE",t[t.ORTHOGRAPHIC=1]="ORTHOGRAPHIC"})(s=i.RuntimeLayerCameraType||(i.RuntimeLayerCameraType={}));const l=a=>a==="orthographic"?1:0;let o;(function(t){t[t.DO_NOTHING=0]="DO_NOTHING",t[t.TOP_LEFT_ANCHORED_IF_NEVER_MOVED=1]="TOP_LEFT_ANCHORED_IF_NEVER_MOVED"})(o=i.RuntimeLayerDefaultCameraBehavior||(i.RuntimeLayerDefaultCameraBehavior={}));const c=a=>a==="top-left-anchored-if-never-moved"?1:0;class d{constructor(e,t){this._timeScale=1;this._defaultZOrder=0;this._rendererEffects={};this._name=e.name,this._renderingType=f(e.renderingType),this._cameraType=l(e.cameraType),this._defaultCameraBehavior=c(e.defaultCameraBehavior||"top-left-anchored-if-never-moved"),this._hidden=!e.visibility,this._initialCamera3DFieldOfView=e.camera3DFieldOfView||45,this._initialCamera3DNearPlaneDistance=e.camera3DNearPlaneDistance||.1,this._initialCamera3DFarPlaneDistance=e.camera3DFarPlaneDistance||2e3,this._initialEffectsData=e.effects||[],this._runtimeScene=t,this._effectsManager=t.getGame().getEffectsManager(),this._isLightingLayer=e.isLightingLayer,this._followBaseLayerCamera=e.followBaseLayerCamera,this._clearColor=[e.ambientLightColorR/255,e.ambientLightColorG/255,e.ambientLightColorB/255,1],this._renderer=new i.LayerRenderer(this,t.getRenderer(),t.getGame().getRenderer()),this.show(!this._hidden);for(let r=0;r<e.effects.length;++r)this.addEffect(e.effects[r])}getRenderer(){return this._renderer}getRendererObject(){return this._renderer.getRendererObject()}get3DRendererObject(){return this._renderer.getThreeScene()}getRenderingType(){return this._renderingType}getCameraType(){return this._cameraType}getDefaultZOrder(){return this._defaultZOrder}setDefaultZOrder(e){this._defaultZOrder=e}getRuntimeScene(){return this._runtimeScene.getScene()}updatePreRender(e){this._followBaseLayerCamera&&this.followBaseLayer(),this._renderer.updatePreRender(),this._effectsManager.updatePreRender(this._rendererEffects,this)}getName(){return this._name}show(e){this._hidden=!e,this._renderer.updateVisibility(e)}isVisible(){return!this._hidden}getWidth(){return this._runtimeScene.getViewportWidth()}getHeight(){return this._runtimeScene.getViewportHeight()}getInitialCamera3DFieldOfView(){return this._initialCamera3DFieldOfView}getInitialCamera3DNearPlaneDistance(){return this._initialCamera3DNearPlaneDistance}getInitialCamera3DFarPlaneDistance(){return this._initialCamera3DFarPlaneDistance}getInitialEffectsData(){return this._initialEffectsData}getRendererEffects(){return this._rendererEffects}addEffect(e){this._effectsManager.addEffect(e,this._rendererEffects,this)}removeEffect(e){this._effectsManager.removeEffect(this._rendererEffects,this,e)}setEffectDoubleParameter(e,t,r){this._effectsManager.setEffectDoubleParameter(this._rendererEffects,e,t,r)}setEffectStringParameter(e,t,r){this._effectsManager.setEffectStringParameter(this._rendererEffects,e,t,r)}setEffectBooleanParameter(e,t,r){this._effectsManager.setEffectBooleanParameter(this._rendererEffects,e,t,r)}enableEffect(e,t){this._effectsManager.enableEffect(this._rendererEffects,this,e,t)}isEffectEnabled(e){return this._effectsManager.isEffectEnabled(this._rendererEffects,this,e)}hasEffect(e){return this._effectsManager.hasEffect(this._rendererEffects,e)}setTimeScale(e){e>=0&&(this._timeScale=e)}getTimeScale(){return this._timeScale}getElapsedTime(e){return(e||this._runtimeScene).getElapsedTime()*this._timeScale}followBaseLayer(){const e=this._runtimeScene.getLayer("");this.setCameraX(e.getCameraX()),this.setCameraY(e.getCameraY()),this.setCameraRotation(e.getCameraRotation()),this.setCameraZoom(e.getCameraZoom())}getClearColor(){return this._clearColor}setClearColor(e,t,r){this._clearColor[0]=e/255,this._clearColor[1]=t/255,this._clearColor[2]=r/255,this._renderer.updateClearColor()}setFollowBaseLayerCamera(e){this._followBaseLayerCamera=e}isLightingLayer(){return this._isLightingLayer}}i.RuntimeLayer=d})(gdjs||(gdjs={}));
|
|
2
2
|
//# sourceMappingURL=RuntimeLayer.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../GDevelop/GDJS/Runtime/RuntimeLayer.ts"],
|
|
4
|
-
"sourcesContent": ["/*\n * GDevelop JS Platform\n * Copyright 2013-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.\n * This project is released under the MIT License.\n */\nnamespace gdjs {\n export enum RuntimeLayerRenderingType {\n TWO_D,\n THREE_D,\n TWO_D_PLUS_THREE_D,\n }\n\n const getRenderingTypeFromString = (\n renderingTypeAsString: string | undefined\n ) =>\n renderingTypeAsString === '3d'\n ? RuntimeLayerRenderingType.THREE_D\n : renderingTypeAsString === '2d+3d' || renderingTypeAsString === ''\n ? RuntimeLayerRenderingType.TWO_D_PLUS_THREE_D\n : RuntimeLayerRenderingType.TWO_D;\n\n export enum RuntimeLayerCameraType {\n PERSPECTIVE,\n ORTHOGRAPHIC,\n }\n\n const getCameraTypeFromString = (renderingTypeAsString: string | undefined) =>\n renderingTypeAsString === 'orthographic'\n ? RuntimeLayerCameraType.ORTHOGRAPHIC\n : RuntimeLayerCameraType.PERSPECTIVE;\n /**\n * Represents a layer of a \"container\", used to display objects.\n * The container can be a scene (see gdjs.Layer)\n * or a custom object (see gdjs.RuntimeCustomObjectLayer).\n */\n export abstract class RuntimeLayer implements EffectsTarget {\n _name: string;\n _renderingType: RuntimeLayerRenderingType;\n _cameraType: RuntimeLayerCameraType;\n _timeScale: float = 1;\n _defaultZOrder: integer = 0;\n _hidden: boolean;\n _initialEffectsData: Array<EffectData>;\n\n // TODO EBO Don't store scene layer related data in layers used by custom objects.\n // (both these 3D settings and the lighting layer properties below).\n _initialCamera3DFieldOfView: float;\n _initialCamera3DFarPlaneDistance: float;\n _initialCamera3DNearPlaneDistance: float;\n\n _runtimeScene: gdjs.RuntimeInstanceContainer;\n _effectsManager: gdjs.EffectsManager;\n\n // Lighting layer properties.\n _isLightingLayer: boolean;\n _followBaseLayerCamera: boolean;\n _clearColor: Array<integer>;\n\n _rendererEffects: Record<string, gdjs.PixiFiltersTools.Filter> = {};\n _renderer: gdjs.LayerRenderer;\n\n /**\n * @param layerData The data used to initialize the layer\n * @param instanceContainer The container in which the layer is used\n */\n constructor(\n layerData: LayerData,\n instanceContainer: gdjs.RuntimeInstanceContainer\n ) {\n this._name = layerData.name;\n this._renderingType = getRenderingTypeFromString(layerData.renderingType);\n this._cameraType = getCameraTypeFromString(layerData.cameraType);\n this._hidden = !layerData.visibility;\n this._initialCamera3DFieldOfView = layerData.camera3DFieldOfView || 45;\n this._initialCamera3DNearPlaneDistance =\n layerData.camera3DNearPlaneDistance || 0.1;\n this._initialCamera3DFarPlaneDistance =\n layerData.camera3DFarPlaneDistance || 2000;\n this._initialEffectsData = layerData.effects || [];\n this._runtimeScene = instanceContainer;\n this._effectsManager = instanceContainer.getGame().getEffectsManager();\n this._isLightingLayer = layerData.isLightingLayer;\n this._followBaseLayerCamera = layerData.followBaseLayerCamera;\n this._clearColor = [\n layerData.ambientLightColorR / 255,\n layerData.ambientLightColorG / 255,\n layerData.ambientLightColorB / 255,\n 1.0,\n ];\n this._renderer = new gdjs.LayerRenderer(\n this,\n instanceContainer.getRenderer(),\n instanceContainer.getGame().getRenderer()\n );\n this.show(!this._hidden);\n for (let i = 0; i < layerData.effects.length; ++i) {\n this.addEffect(layerData.effects[i]);\n }\n }\n\n getRenderer(): gdjs.LayerRenderer {\n return this._renderer;\n }\n\n getRendererObject() {\n return this._renderer.getRendererObject();\n }\n\n get3DRendererObject() {\n return this._renderer.getThreeScene();\n }\n\n getRenderingType(): RuntimeLayerRenderingType {\n return this._renderingType;\n }\n\n getCameraType(): RuntimeLayerCameraType {\n return this._cameraType;\n }\n\n /**\n * Get the default Z order to be attributed to objects created on this layer\n * (usually from events generated code).\n */\n getDefaultZOrder(): float {\n return this._defaultZOrder;\n }\n\n /**\n * Set the default Z order to be attributed to objects created on this layer.\n * @param defaultZOrder The Z order to use when creating a new object from events.\n */\n setDefaultZOrder(defaultZOrder: integer): void {\n this._defaultZOrder = defaultZOrder;\n }\n\n /**\n * Called by the RuntimeScene whenever the game resolution size is changed.\n * Updates the layer width/height and position.\n */\n abstract onGameResolutionResized(\n oldGameResolutionOriginX: float,\n oldGameResolutionOriginY: float\n ): void;\n\n /**\n * Returns the scene the layer belongs to directly or indirectly\n * @returns the scene the layer belongs to directly or indirectly\n */\n getRuntimeScene(): gdjs.RuntimeScene {\n return this._runtimeScene.getScene();\n }\n\n /**\n * Called at each frame, after events are run and before rendering.\n */\n updatePreRender(instanceContainer?: gdjs.RuntimeInstanceContainer): void {\n if (this._followBaseLayerCamera) {\n this.followBaseLayer();\n }\n this._renderer.updatePreRender();\n this._effectsManager.updatePreRender(this._rendererEffects, this);\n }\n\n /**\n * Get the name of the layer\n * @return The name of the layer\n */\n getName(): string {\n return this._name;\n }\n\n /**\n * Change the camera center X position.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The x position of the camera\n */\n abstract getCameraX(cameraId?: integer): float;\n\n /**\n * Change the camera center Y position.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The y position of the camera\n */\n abstract getCameraY(cameraId?: integer): float;\n\n /**\n * Set the camera center X position.\n *\n * @param x The new x position\n * @param cameraId The camera number. Currently ignored.\n */\n abstract setCameraX(x: float, cameraId?: integer): void;\n\n /**\n * Set the camera center Y position.\n *\n * @param y The new y position\n * @param cameraId The camera number. Currently ignored.\n */\n abstract setCameraY(y: float, cameraId?: integer): void;\n\n /**\n * Get the camera width (which can be different than the game resolution width\n * if the camera is zoomed).\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The width of the camera\n */\n abstract getCameraWidth(cameraId?: integer): float;\n\n /**\n * Get the camera height (which can be different than the game resolution height\n * if the camera is zoomed).\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The height of the camera\n */\n abstract getCameraHeight(cameraId?: integer): float;\n\n /**\n * Show (or hide) the layer.\n * @param enable true to show the layer, false to hide it.\n */\n show(enable: boolean): void {\n this._hidden = !enable;\n this._renderer.updateVisibility(enable);\n }\n\n /**\n * Check if the layer is visible.\n *\n * @return true if the layer is visible.\n */\n isVisible(): boolean {\n return !this._hidden;\n }\n\n /**\n * Set the zoom of a camera.\n *\n * @param newZoom The new zoom. Must be superior to 0. 1 is the default zoom.\n * @param cameraId The camera number. Currently ignored.\n */\n abstract setCameraZoom(newZoom: float, cameraId?: integer): void;\n\n /**\n * Get the zoom of a camera.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The zoom.\n */\n abstract getCameraZoom(cameraId?: integer): float;\n\n /**\n * Set the camera center Z position.\n *\n * @param z The new y position.\n * @param fov The field of view.\n * @param cameraId The camera number. Currently ignored.\n */\n abstract setCameraZ(z: float, fov: float | null, cameraId?: integer): void;\n\n /**\n * Get the camera center Z position.\n *\n * @param fov The field of view.\n * @param cameraId The camera number. Currently ignored.\n * @return The z position of the camera\n */\n abstract getCameraZ(fov: float | null, cameraId?: integer): float;\n\n /**\n * Get the rotation of the camera, expressed in degrees.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The rotation, in degrees.\n */\n abstract getCameraRotation(cameraId?: integer): float;\n\n /**\n * Set the rotation of the camera, expressed in degrees.\n * The rotation is made around the camera center.\n *\n * @param rotation The new rotation, in degrees.\n * @param cameraId The camera number. Currently ignored.\n */\n abstract setCameraRotation(rotation: float, cameraId?: integer): void;\n\n /**\n * Convert a point from the canvas coordinates (for example,\n * the mouse position) to the container coordinates.\n *\n * @param x The x position, in canvas coordinates.\n * @param y The y position, in canvas coordinates.\n * @param cameraId The camera number. Currently ignored.\n * @param result The point instance that is used to return the result.\n */\n abstract convertCoords(\n x: float,\n y: float,\n cameraId: integer,\n result: FloatPoint\n ): FloatPoint;\n\n /**\n * Return an array containing the coordinates of the point passed as parameter\n * in parent coordinate coordinates (as opposed to the layer local coordinates).\n *\n * All transformations (scale, rotation) are supported.\n *\n * @param x The X position of the point, in layer coordinates.\n * @param y The Y position of the point, in layer coordinates.\n * @param result Array that will be updated with the result\n * (x and y position of the point in parent coordinates).\n */\n abstract applyLayerTransformation(\n x: float,\n y: float,\n cameraId: integer,\n result: FloatPoint\n ): FloatPoint;\n\n /**\n * Convert a point from the container coordinates (for example,\n * an object position) to the canvas coordinates.\n *\n * @param x The x position, in container coordinates.\n * @param y The y position, in container coordinates.\n * @param cameraId The camera number. Currently ignored.\n * @param result The point instance that is used to return the result.\n */\n abstract convertInverseCoords(\n x: float,\n y: float,\n cameraId: integer,\n result: FloatPoint\n ): FloatPoint;\n\n /**\n * Return an array containing the coordinates of the point passed as parameter\n * in layer local coordinates (as opposed to the parent coordinates).\n *\n * All transformations (scale, rotation) are supported.\n *\n * @param x The X position of the point, in parent coordinates.\n * @param y The Y position of the point, in parent coordinates.\n * @param result Array that will be updated with the result\n * @param result The point instance that is used to return the result.\n * (x and y position of the point in layer coordinates).\n */\n abstract applyLayerInverseTransformation(\n x: float,\n y: float,\n cameraId: integer,\n result: FloatPoint\n ): FloatPoint;\n\n getWidth(): float {\n return this._runtimeScene.getViewportWidth();\n }\n\n getHeight(): float {\n return this._runtimeScene.getViewportHeight();\n }\n\n getInitialCamera3DFieldOfView(): float {\n return this._initialCamera3DFieldOfView;\n }\n getInitialCamera3DNearPlaneDistance(): float {\n return this._initialCamera3DNearPlaneDistance;\n }\n getInitialCamera3DFarPlaneDistance(): float {\n return this._initialCamera3DFarPlaneDistance;\n }\n\n /**\n * Return the initial effects data for the layer. Only to\n * be used by renderers.\n * @deprecated\n */\n getInitialEffectsData(): EffectData[] {\n return this._initialEffectsData;\n }\n\n /**\n * Returns the collection of effects to be rendered by the\n * underlying renderer.\n * @returns The renderer effects.\n */\n getRendererEffects() {\n return this._rendererEffects;\n }\n\n /**\n * Add a new effect, or replace the one with the same name.\n * @param effectData The data of the effect to add.\n */\n addEffect(effectData: EffectData): void {\n this._effectsManager.addEffect(effectData, this._rendererEffects, this);\n }\n\n /**\n * Remove the effect with the specified name\n * @param effectName The name of the effect.\n */\n removeEffect(effectName: string): void {\n this._effectsManager.removeEffect(\n this._rendererEffects,\n this,\n effectName\n );\n }\n\n /**\n * Change an effect property value (for properties that are numbers).\n * @param name The name of the effect to update.\n * @param parameterName The name of the property to update.\n * @param value The new value (number).\n */\n setEffectDoubleParameter(\n name: string,\n parameterName: string,\n value: float\n ): void {\n this._effectsManager.setEffectDoubleParameter(\n this._rendererEffects,\n name,\n parameterName,\n value\n );\n }\n\n /**\n * Change an effect property value (for properties that are strings).\n * @param name The name of the effect to update.\n * @param parameterName The name of the property to update.\n * @param value The new value (string).\n */\n setEffectStringParameter(\n name: string,\n parameterName: string,\n value: string\n ): void {\n this._effectsManager.setEffectStringParameter(\n this._rendererEffects,\n name,\n parameterName,\n value\n );\n }\n\n /**\n * Change an effect property value (for properties that are booleans).\n * @param name The name of the effect to update.\n * @param parameterName The name of the property to update.\n * @param value The new value (boolean).\n */\n setEffectBooleanParameter(\n name: string,\n parameterName: string,\n value: boolean\n ): void {\n this._effectsManager.setEffectBooleanParameter(\n this._rendererEffects,\n name,\n parameterName,\n value\n );\n }\n\n /**\n * Enable or disable an effect.\n * @param name The name of the effect to enable or disable.\n * @param enable true to enable, false to disable\n */\n enableEffect(name: string, enable: boolean): void {\n this._effectsManager.enableEffect(\n this._rendererEffects,\n this,\n name,\n enable\n );\n }\n\n /**\n * Check if an effect is enabled\n * @param name The name of the effect\n * @return true if the effect is enabled, false otherwise.\n */\n isEffectEnabled(name: string): boolean {\n return this._effectsManager.isEffectEnabled(\n this._rendererEffects,\n this,\n name\n );\n }\n\n /**\n * Check if an effect exists on this layer\n * @param name The name of the effect\n * @return true if the effect exists, false otherwise.\n */\n hasEffect(name: string): boolean {\n return this._effectsManager.hasEffect(this._rendererEffects, name);\n }\n\n /**\n * Set the time scale for the objects on the layer:\n * time will be slower if time scale is < 1, faster if > 1.\n * @param timeScale The new time scale (must be positive).\n */\n setTimeScale(timeScale: float): void {\n if (timeScale >= 0) {\n this._timeScale = timeScale;\n }\n }\n\n /**\n * Get the time scale for the objects on the layer.\n */\n getTimeScale(): float {\n return this._timeScale;\n }\n\n /**\n * Return the time elapsed since the last frame,\n * in milliseconds, for objects on the layer.\n *\n * @param instanceContainer The instance container the layer belongs to (deprecated - can be omitted).\n */\n getElapsedTime(instanceContainer?: gdjs.RuntimeInstanceContainer): float {\n const container = instanceContainer || this._runtimeScene;\n return container.getElapsedTime() * this._timeScale;\n }\n\n /**\n * Change the position, rotation and scale (zoom) of the layer camera to be the same as the base layer camera.\n */\n followBaseLayer(): void {\n const baseLayer = this._runtimeScene.getLayer('');\n this.setCameraX(baseLayer.getCameraX());\n this.setCameraY(baseLayer.getCameraY());\n this.setCameraRotation(baseLayer.getCameraRotation());\n this.setCameraZoom(baseLayer.getCameraZoom());\n }\n\n /**\n * The clear color is defined in the format [r, g, b], with components in the range of 0 to 1.\n * @return the clear color of layer in the range of [0, 1].\n */\n getClearColor(): Array<integer> {\n return this._clearColor;\n }\n\n /**\n * Set the clear color in format [r, g, b], with components in the range of 0 to 1.;\n * @param r Red color component in the range 0-255.\n * @param g Green color component in the range 0-255.\n * @param b Blue color component in the range 0-255.\n */\n setClearColor(r: integer, g: integer, b: integer): void {\n this._clearColor[0] = r / 255;\n this._clearColor[1] = g / 255;\n this._clearColor[2] = b / 255;\n this._renderer.updateClearColor();\n }\n\n /**\n * Set whether layer's camera follows base layer's camera or not.\n */\n setFollowBaseLayerCamera(follow: boolean): void {\n this._followBaseLayerCamera = follow;\n }\n\n /**\n * Return true if the layer is a lighting layer, false otherwise.\n * @return true if it is a lighting layer, false otherwise.\n */\n isLightingLayer(): boolean {\n return this._isLightingLayer;\n }\n }\n}\n"],
|
|
5
|
-
"mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CACS,GAAK,GAAL,UAAK,EAAL,CACL,qBACA,yBACA,iDAHU,iEAMZ,KAAM,GAA6B,AACjC,GAEA,IAA0B,KACtB,EACA,IAA0B,SAAW,IAA0B,GAC/D,EACA,EAEC,GAAK,GAAL,UAAK,EAAL,CACL,iCACA,qCAFU,
|
|
4
|
+
"sourcesContent": ["/*\n * GDevelop JS Platform\n * Copyright 2013-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.\n * This project is released under the MIT License.\n */\nnamespace gdjs {\n export enum RuntimeLayerRenderingType {\n TWO_D,\n THREE_D,\n TWO_D_PLUS_THREE_D,\n }\n\n const getRenderingTypeFromString = (\n renderingTypeAsString: string | undefined\n ) =>\n renderingTypeAsString === '3d'\n ? RuntimeLayerRenderingType.THREE_D\n : renderingTypeAsString === '2d+3d' || renderingTypeAsString === ''\n ? RuntimeLayerRenderingType.TWO_D_PLUS_THREE_D\n : RuntimeLayerRenderingType.TWO_D;\n\n export enum RuntimeLayerCameraType {\n PERSPECTIVE,\n ORTHOGRAPHIC,\n }\n const getCameraTypeFromString = (renderingTypeAsString: string | undefined) =>\n renderingTypeAsString === 'orthographic'\n ? RuntimeLayerCameraType.ORTHOGRAPHIC\n : RuntimeLayerCameraType.PERSPECTIVE;\n\n export enum RuntimeLayerDefaultCameraBehavior {\n DO_NOTHING,\n TOP_LEFT_ANCHORED_IF_NEVER_MOVED,\n }\n\n const getDefaultCameraBehaviorFromString = (\n defaultCameraBehaviorAsString: string\n ) =>\n defaultCameraBehaviorAsString === 'top-left-anchored-if-never-moved'\n ? RuntimeLayerDefaultCameraBehavior.TOP_LEFT_ANCHORED_IF_NEVER_MOVED\n : RuntimeLayerDefaultCameraBehavior.DO_NOTHING;\n\n /**\n * Represents a layer of a \"container\", used to display objects.\n * The container can be a scene (see gdjs.Layer)\n * or a custom object (see gdjs.RuntimeCustomObjectLayer).\n */\n export abstract class RuntimeLayer implements EffectsTarget {\n _name: string;\n _renderingType: RuntimeLayerRenderingType;\n _cameraType: RuntimeLayerCameraType;\n _defaultCameraBehavior: RuntimeLayerDefaultCameraBehavior;\n _timeScale: float = 1;\n _defaultZOrder: integer = 0;\n _hidden: boolean;\n _initialEffectsData: Array<EffectData>;\n\n // TODO EBO Don't store scene layer related data in layers used by custom objects.\n // (both these 3D settings and the lighting layer properties below).\n _initialCamera3DFieldOfView: float;\n _initialCamera3DFarPlaneDistance: float;\n _initialCamera3DNearPlaneDistance: float;\n\n _runtimeScene: gdjs.RuntimeInstanceContainer;\n _effectsManager: gdjs.EffectsManager;\n\n // Lighting layer properties.\n _isLightingLayer: boolean;\n _followBaseLayerCamera: boolean;\n _clearColor: Array<integer>;\n\n _rendererEffects: Record<string, gdjs.PixiFiltersTools.Filter> = {};\n _renderer: gdjs.LayerRenderer;\n\n /**\n * @param layerData The data used to initialize the layer\n * @param instanceContainer The container in which the layer is used\n */\n constructor(\n layerData: LayerData,\n instanceContainer: gdjs.RuntimeInstanceContainer\n ) {\n this._name = layerData.name;\n this._renderingType = getRenderingTypeFromString(layerData.renderingType);\n this._cameraType = getCameraTypeFromString(layerData.cameraType);\n this._defaultCameraBehavior = getDefaultCameraBehaviorFromString(\n layerData.defaultCameraBehavior || 'top-left-anchored-if-never-moved'\n );\n this._hidden = !layerData.visibility;\n this._initialCamera3DFieldOfView = layerData.camera3DFieldOfView || 45;\n this._initialCamera3DNearPlaneDistance =\n layerData.camera3DNearPlaneDistance || 0.1;\n this._initialCamera3DFarPlaneDistance =\n layerData.camera3DFarPlaneDistance || 2000;\n this._initialEffectsData = layerData.effects || [];\n this._runtimeScene = instanceContainer;\n this._effectsManager = instanceContainer.getGame().getEffectsManager();\n this._isLightingLayer = layerData.isLightingLayer;\n this._followBaseLayerCamera = layerData.followBaseLayerCamera;\n this._clearColor = [\n layerData.ambientLightColorR / 255,\n layerData.ambientLightColorG / 255,\n layerData.ambientLightColorB / 255,\n 1.0,\n ];\n this._renderer = new gdjs.LayerRenderer(\n this,\n instanceContainer.getRenderer(),\n instanceContainer.getGame().getRenderer()\n );\n this.show(!this._hidden);\n for (let i = 0; i < layerData.effects.length; ++i) {\n this.addEffect(layerData.effects[i]);\n }\n }\n\n getRenderer(): gdjs.LayerRenderer {\n return this._renderer;\n }\n\n getRendererObject() {\n return this._renderer.getRendererObject();\n }\n\n get3DRendererObject() {\n return this._renderer.getThreeScene();\n }\n\n getRenderingType(): RuntimeLayerRenderingType {\n return this._renderingType;\n }\n\n getCameraType(): RuntimeLayerCameraType {\n return this._cameraType;\n }\n\n /**\n * Get the default Z order to be attributed to objects created on this layer\n * (usually from events generated code).\n */\n getDefaultZOrder(): float {\n return this._defaultZOrder;\n }\n\n /**\n * Set the default Z order to be attributed to objects created on this layer.\n * @param defaultZOrder The Z order to use when creating a new object from events.\n */\n setDefaultZOrder(defaultZOrder: integer): void {\n this._defaultZOrder = defaultZOrder;\n }\n\n /**\n * Called by the RuntimeScene whenever the game resolution size is changed.\n * Updates the layer width/height and position.\n */\n abstract onGameResolutionResized(\n oldGameResolutionOriginX: float,\n oldGameResolutionOriginY: float\n ): void;\n\n /**\n * Returns the scene the layer belongs to directly or indirectly\n * @returns the scene the layer belongs to directly or indirectly\n */\n getRuntimeScene(): gdjs.RuntimeScene {\n return this._runtimeScene.getScene();\n }\n\n /**\n * Called at each frame, after events are run and before rendering.\n */\n updatePreRender(instanceContainer?: gdjs.RuntimeInstanceContainer): void {\n if (this._followBaseLayerCamera) {\n this.followBaseLayer();\n }\n this._renderer.updatePreRender();\n this._effectsManager.updatePreRender(this._rendererEffects, this);\n }\n\n /**\n * Get the name of the layer\n * @return The name of the layer\n */\n getName(): string {\n return this._name;\n }\n\n /**\n * Change the camera center X position.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The x position of the camera\n */\n abstract getCameraX(cameraId?: integer): float;\n\n /**\n * Change the camera center Y position.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The y position of the camera\n */\n abstract getCameraY(cameraId?: integer): float;\n\n /**\n * Set the camera center X position.\n *\n * @param x The new x position\n * @param cameraId The camera number. Currently ignored.\n */\n abstract setCameraX(x: float, cameraId?: integer): void;\n\n /**\n * Set the camera center Y position.\n *\n * @param y The new y position\n * @param cameraId The camera number. Currently ignored.\n */\n abstract setCameraY(y: float, cameraId?: integer): void;\n\n /**\n * Get the camera width (which can be different than the game resolution width\n * if the camera is zoomed).\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The width of the camera\n */\n abstract getCameraWidth(cameraId?: integer): float;\n\n /**\n * Get the camera height (which can be different than the game resolution height\n * if the camera is zoomed).\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The height of the camera\n */\n abstract getCameraHeight(cameraId?: integer): float;\n\n /**\n * Show (or hide) the layer.\n * @param enable true to show the layer, false to hide it.\n */\n show(enable: boolean): void {\n this._hidden = !enable;\n this._renderer.updateVisibility(enable);\n }\n\n /**\n * Check if the layer is visible.\n *\n * @return true if the layer is visible.\n */\n isVisible(): boolean {\n return !this._hidden;\n }\n\n /**\n * Set the zoom of a camera.\n *\n * @param newZoom The new zoom. Must be superior to 0. 1 is the default zoom.\n * @param cameraId The camera number. Currently ignored.\n */\n abstract setCameraZoom(newZoom: float, cameraId?: integer): void;\n\n /**\n * Get the zoom of a camera.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The zoom.\n */\n abstract getCameraZoom(cameraId?: integer): float;\n\n /**\n * Set the camera center Z position.\n *\n * @param z The new y position.\n * @param fov The field of view.\n * @param cameraId The camera number. Currently ignored.\n */\n abstract setCameraZ(z: float, fov: float | null, cameraId?: integer): void;\n\n /**\n * Get the camera center Z position.\n *\n * @param fov The field of view.\n * @param cameraId The camera number. Currently ignored.\n * @return The z position of the camera\n */\n abstract getCameraZ(fov: float | null, cameraId?: integer): float;\n\n /**\n * Get the rotation of the camera, expressed in degrees.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The rotation, in degrees.\n */\n abstract getCameraRotation(cameraId?: integer): float;\n\n /**\n * Set the rotation of the camera, expressed in degrees.\n * The rotation is made around the camera center.\n *\n * @param rotation The new rotation, in degrees.\n * @param cameraId The camera number. Currently ignored.\n */\n abstract setCameraRotation(rotation: float, cameraId?: integer): void;\n\n /**\n * Convert a point from the canvas coordinates (for example,\n * the mouse position) to the container coordinates.\n *\n * @param x The x position, in canvas coordinates.\n * @param y The y position, in canvas coordinates.\n * @param cameraId The camera number. Currently ignored.\n * @param result The point instance that is used to return the result.\n */\n abstract convertCoords(\n x: float,\n y: float,\n cameraId: integer,\n result: FloatPoint\n ): FloatPoint;\n\n /**\n * Return an array containing the coordinates of the point passed as parameter\n * in parent coordinate coordinates (as opposed to the layer local coordinates).\n *\n * All transformations (scale, rotation) are supported.\n *\n * @param x The X position of the point, in layer coordinates.\n * @param y The Y position of the point, in layer coordinates.\n * @param result Array that will be updated with the result\n * (x and y position of the point in parent coordinates).\n */\n abstract applyLayerTransformation(\n x: float,\n y: float,\n cameraId: integer,\n result: FloatPoint\n ): FloatPoint;\n\n /**\n * Convert a point from the container coordinates (for example,\n * an object position) to the canvas coordinates.\n *\n * @param x The x position, in container coordinates.\n * @param y The y position, in container coordinates.\n * @param cameraId The camera number. Currently ignored.\n * @param result The point instance that is used to return the result.\n */\n abstract convertInverseCoords(\n x: float,\n y: float,\n cameraId: integer,\n result: FloatPoint\n ): FloatPoint;\n\n /**\n * Return an array containing the coordinates of the point passed as parameter\n * in layer local coordinates (as opposed to the parent coordinates).\n *\n * All transformations (scale, rotation) are supported.\n *\n * @param x The X position of the point, in parent coordinates.\n * @param y The Y position of the point, in parent coordinates.\n * @param result Array that will be updated with the result\n * @param result The point instance that is used to return the result.\n * (x and y position of the point in layer coordinates).\n */\n abstract applyLayerInverseTransformation(\n x: float,\n y: float,\n cameraId: integer,\n result: FloatPoint\n ): FloatPoint;\n\n getWidth(): float {\n return this._runtimeScene.getViewportWidth();\n }\n\n getHeight(): float {\n return this._runtimeScene.getViewportHeight();\n }\n\n getInitialCamera3DFieldOfView(): float {\n return this._initialCamera3DFieldOfView;\n }\n getInitialCamera3DNearPlaneDistance(): float {\n return this._initialCamera3DNearPlaneDistance;\n }\n getInitialCamera3DFarPlaneDistance(): float {\n return this._initialCamera3DFarPlaneDistance;\n }\n\n /**\n * Return the initial effects data for the layer. Only to\n * be used by renderers.\n * @deprecated\n */\n getInitialEffectsData(): EffectData[] {\n return this._initialEffectsData;\n }\n\n /**\n * Returns the collection of effects to be rendered by the\n * underlying renderer.\n * @returns The renderer effects.\n */\n getRendererEffects() {\n return this._rendererEffects;\n }\n\n /**\n * Add a new effect, or replace the one with the same name.\n * @param effectData The data of the effect to add.\n */\n addEffect(effectData: EffectData): void {\n this._effectsManager.addEffect(effectData, this._rendererEffects, this);\n }\n\n /**\n * Remove the effect with the specified name\n * @param effectName The name of the effect.\n */\n removeEffect(effectName: string): void {\n this._effectsManager.removeEffect(\n this._rendererEffects,\n this,\n effectName\n );\n }\n\n /**\n * Change an effect property value (for properties that are numbers).\n * @param name The name of the effect to update.\n * @param parameterName The name of the property to update.\n * @param value The new value (number).\n */\n setEffectDoubleParameter(\n name: string,\n parameterName: string,\n value: float\n ): void {\n this._effectsManager.setEffectDoubleParameter(\n this._rendererEffects,\n name,\n parameterName,\n value\n );\n }\n\n /**\n * Change an effect property value (for properties that are strings).\n * @param name The name of the effect to update.\n * @param parameterName The name of the property to update.\n * @param value The new value (string).\n */\n setEffectStringParameter(\n name: string,\n parameterName: string,\n value: string\n ): void {\n this._effectsManager.setEffectStringParameter(\n this._rendererEffects,\n name,\n parameterName,\n value\n );\n }\n\n /**\n * Change an effect property value (for properties that are booleans).\n * @param name The name of the effect to update.\n * @param parameterName The name of the property to update.\n * @param value The new value (boolean).\n */\n setEffectBooleanParameter(\n name: string,\n parameterName: string,\n value: boolean\n ): void {\n this._effectsManager.setEffectBooleanParameter(\n this._rendererEffects,\n name,\n parameterName,\n value\n );\n }\n\n /**\n * Enable or disable an effect.\n * @param name The name of the effect to enable or disable.\n * @param enable true to enable, false to disable\n */\n enableEffect(name: string, enable: boolean): void {\n this._effectsManager.enableEffect(\n this._rendererEffects,\n this,\n name,\n enable\n );\n }\n\n /**\n * Check if an effect is enabled\n * @param name The name of the effect\n * @return true if the effect is enabled, false otherwise.\n */\n isEffectEnabled(name: string): boolean {\n return this._effectsManager.isEffectEnabled(\n this._rendererEffects,\n this,\n name\n );\n }\n\n /**\n * Check if an effect exists on this layer\n * @param name The name of the effect\n * @return true if the effect exists, false otherwise.\n */\n hasEffect(name: string): boolean {\n return this._effectsManager.hasEffect(this._rendererEffects, name);\n }\n\n /**\n * Set the time scale for the objects on the layer:\n * time will be slower if time scale is < 1, faster if > 1.\n * @param timeScale The new time scale (must be positive).\n */\n setTimeScale(timeScale: float): void {\n if (timeScale >= 0) {\n this._timeScale = timeScale;\n }\n }\n\n /**\n * Get the time scale for the objects on the layer.\n */\n getTimeScale(): float {\n return this._timeScale;\n }\n\n /**\n * Return the time elapsed since the last frame,\n * in milliseconds, for objects on the layer.\n *\n * @param instanceContainer The instance container the layer belongs to (deprecated - can be omitted).\n */\n getElapsedTime(instanceContainer?: gdjs.RuntimeInstanceContainer): float {\n const container = instanceContainer || this._runtimeScene;\n return container.getElapsedTime() * this._timeScale;\n }\n\n /**\n * Change the position, rotation and scale (zoom) of the layer camera to be the same as the base layer camera.\n */\n followBaseLayer(): void {\n const baseLayer = this._runtimeScene.getLayer('');\n this.setCameraX(baseLayer.getCameraX());\n this.setCameraY(baseLayer.getCameraY());\n this.setCameraRotation(baseLayer.getCameraRotation());\n this.setCameraZoom(baseLayer.getCameraZoom());\n }\n\n /**\n * The clear color is defined in the format [r, g, b], with components in the range of 0 to 1.\n * @return the clear color of layer in the range of [0, 1].\n */\n getClearColor(): Array<integer> {\n return this._clearColor;\n }\n\n /**\n * Set the clear color in format [r, g, b], with components in the range of 0 to 1.;\n * @param r Red color component in the range 0-255.\n * @param g Green color component in the range 0-255.\n * @param b Blue color component in the range 0-255.\n */\n setClearColor(r: integer, g: integer, b: integer): void {\n this._clearColor[0] = r / 255;\n this._clearColor[1] = g / 255;\n this._clearColor[2] = b / 255;\n this._renderer.updateClearColor();\n }\n\n /**\n * Set whether layer's camera follows base layer's camera or not.\n */\n setFollowBaseLayerCamera(follow: boolean): void {\n this._followBaseLayerCamera = follow;\n }\n\n /**\n * Return true if the layer is a lighting layer, false otherwise.\n * @return true if it is a lighting layer, false otherwise.\n */\n isLightingLayer(): boolean {\n return this._isLightingLayer;\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CACS,GAAK,GAAL,UAAK,EAAL,CACL,qBACA,yBACA,iDAHU,iEAMZ,KAAM,GAA6B,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Aa,GAOtB,cAAsB,CACpB,MAAO,MAAK,WASd,eAAe,EAA0D,CAEvE,MAAO,AADW,IAAqB,KAAK,eAC3B,iBAAmB,KAAK,WAM3C,iBAAwB,CACtB,KAAM,GAAY,KAAK,cAAc,SAAS,IAC9C,KAAK,WAAW,EAAU,cAC1B,KAAK,WAAW,EAAU,cAC1B,KAAK,kBAAkB,EAAU,qBACjC,KAAK,cAAc,EAAU,iBAO/B,eAAgC,CAC9B,MAAO,MAAK,YASd,cAAc,EAAY,EAAY,EAAkB,CACtD,KAAK,YAAY,GAAK,EAAI,IAC1B,KAAK,YAAY,GAAK,EAAI,IAC1B,KAAK,YAAY,GAAK,EAAI,IAC1B,KAAK,UAAU,mBAMjB,yBAAyB,EAAuB,CAC9C,KAAK,uBAAyB,EAOhC,iBAA2B,CACzB,MAAO,MAAK,kBAviBT,EAAe,iBA1Cd",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/Runtime/layer.js
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var gdjs;(function(
|
|
1
|
+
var gdjs;(function(h){class c extends h.RuntimeLayer{constructor(t,e){super(t,e);this._cameraRotation=0;this._zoomFactor=1;this._cameraZ=0;this._isCameraZDirty=!0;this._defaultCameraBehavior===h.RuntimeLayerDefaultCameraBehavior.TOP_LEFT_ANCHORED_IF_NEVER_MOVED?(this._cameraX=this._runtimeScene.getViewportOriginX(),this._cameraY=this._runtimeScene.getViewportOriginY()):(this._cameraX=(this._runtimeScene.getInitialUnrotatedViewportMinX()+this._runtimeScene.getInitialUnrotatedViewportMaxX())/2,this._cameraY=(this._runtimeScene.getInitialUnrotatedViewportMinY()+this._runtimeScene.getInitialUnrotatedViewportMaxY())/2),this.getCameraType()===h.RuntimeLayerCameraType.ORTHOGRAPHIC&&(this._cameraZ=(this._initialCamera3DFarPlaneDistance+this._initialCamera3DNearPlaneDistance)/2),this._renderer.onCreated()}onGameResolutionResized(t,e){this._defaultCameraBehavior===h.RuntimeLayerDefaultCameraBehavior.TOP_LEFT_ANCHORED_IF_NEVER_MOVED&&Math.abs(this._cameraX-t)<1&&Math.abs(this._cameraY-e)<1&&this._zoomFactor===1&&(this._cameraX+=this._runtimeScene.getViewportOriginX()-t,this._cameraY+=this._runtimeScene.getViewportOriginY()-e),this._renderer.updatePosition(),this._renderer.updateResolution()}getCameraX(t){return this._forceDimensionUpdate(),this._cameraX}getCameraY(t){return this._forceDimensionUpdate(),this._cameraY}setCameraX(t,e){this._forceDimensionUpdate(),this._cameraX=t,this._renderer.updatePosition()}setCameraY(t,e){this._forceDimensionUpdate(),this._cameraY=t,this._renderer.updatePosition()}getCameraWidth(t){return this.getWidth()/this._zoomFactor}getCameraHeight(t){return this.getHeight()/this._zoomFactor}setCameraZoom(t,e){this._zoomFactor=t,this._isCameraZDirty=!0,this._renderer.updatePosition()}getCameraZoom(t){return this._zoomFactor}setCameraZ(t,e,i){if(e){const r=h.toRad(e),a=Math.min(Number.MAX_SAFE_INTEGER,.5*this.getHeight()/(t*Math.tan(.5*r)));a>0&&(this._zoomFactor=a)}this._cameraZ=t,this._isCameraZDirty=!1,this._renderer.updatePosition()}getCameraZ(t,e){return!this._isCameraZDirty||!t?this._cameraZ:.5*this.getHeight()/this.getCameraZoom()/Math.tan(.5*h.toRad(t))}getCameraRotation(t){return this._cameraRotation}setCameraRotation(t,e){this._cameraRotation=t,this._renderer.updatePosition()}convertCoords(t,e,i=0,r){let a=r||[0,0];if(this._renderer.isCameraRotatedIn3D())return this._renderer.transformTo3DWorld(t,e,0,i,r);t-=this.getRuntimeScene()._cachedGameResolutionWidth/2,e-=this.getRuntimeScene()._cachedGameResolutionHeight/2,t/=Math.abs(this._zoomFactor),e/=Math.abs(this._zoomFactor);const n=this._cameraRotation/180*Math.PI,s=t,o=Math.cos(n),m=Math.sin(n);return t=o*t-m*e,e=m*s+o*e,a[0]=t+this.getCameraX(i),a[1]=e+this.getCameraY(i),a}applyLayerInverseTransformation(t,e,i,r){t-=this._runtimeScene.getViewportOriginX(),e-=this._runtimeScene.getViewportOriginY(),t/=Math.abs(this._zoomFactor),e/=Math.abs(this._zoomFactor);const a=this._cameraRotation/180*Math.PI,n=t,s=Math.cos(a),o=Math.sin(a);return t=s*t-o*e,e=o*n+s*e,r[0]=t+this.getCameraX(i),r[1]=e+this.getCameraY(i),r}convertInverseCoords(t,e,i=0,r){let a=r||[0,0];t-=this.getCameraX(i),e-=this.getCameraY(i);const n=this._cameraRotation/180*Math.PI,s=t,o=Math.cos(-n),m=Math.sin(-n);return t=o*t-m*e,e=m*s+o*e,t*=Math.abs(this._zoomFactor),e*=Math.abs(this._zoomFactor),a[0]=t+this.getRuntimeScene()._cachedGameResolutionWidth/2,a[1]=e+this.getRuntimeScene()._cachedGameResolutionHeight/2,a}applyLayerTransformation(t,e,i,r){t-=this.getCameraX(i),e-=this.getCameraY(i);const a=this._cameraRotation/180*Math.PI,n=t,s=Math.cos(-a),o=Math.sin(-a);return t=s*t-o*e,e=o*n+s*e,t*=Math.abs(this._zoomFactor),e*=Math.abs(this._zoomFactor),t+=this._runtimeScene.getViewportOriginX(),e+=this._runtimeScene.getViewportOriginY(),r[0]=t,r[1]=e,r}_forceDimensionUpdate(){this._runtimeScene.getViewportWidth()}}h.Layer=c})(gdjs||(gdjs={}));
|
|
2
2
|
//# sourceMappingURL=layer.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../GDevelop/GDJS/Runtime/layer.ts"],
|
|
4
|
-
"sourcesContent": ["/*\n * GDevelop JS Platform\n * Copyright 2013-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.\n * This project is released under the MIT License.\n */\nnamespace gdjs {\n /**\n * Represents a layer of a scene, used to display objects.\n */\n export class Layer extends gdjs.RuntimeLayer {\n _cameraRotation: float = 0;\n _zoomFactor: float = 1;\n _cameraX: float;\n _cameraY: float;\n _cameraZ: float = 0;\n /**\n * `_cameraZ` is dirty when the zoom factor is set last.\n */\n _isCameraZDirty: boolean = true;\n\n /**\n * @param layerData The data used to initialize the layer\n * @param instanceContainer The container in which the layer is used\n */\n constructor(\n layerData: LayerData,\n instanceContainer: gdjs.RuntimeInstanceContainer\n ) {\n super(layerData, instanceContainer);\n\n this._cameraX = this.getWidth() / 2;\n this._cameraY = this.getHeight() / 2;\n if (this.getCameraType() === gdjs.RuntimeLayerCameraType.ORTHOGRAPHIC) {\n this._cameraZ =\n (this._initialCamera3DFarPlaneDistance +\n this._initialCamera3DNearPlaneDistance) /\n 2;\n }\n\n // Let the renderer do its final set up:\n this._renderer.onCreated();\n }\n\n /**\n * Called by the RuntimeScene whenever the game resolution size is changed.\n * Updates the layer width/height and position.\n */\n onGameResolutionResized(\n oldGameResolutionOriginX: float,\n oldGameResolutionOriginY: float\n ): void {\n // Adapt position of the camera center only if the camera has never moved as:\n // * When the camera follows a player/object, it will rarely be at the default position.\n // (and if is, it will be moved again by the behavior/events).\n // * Cameras not following a player/object are usually UIs which are intuitively\n // expected not to \"move\". Not adapting the center position would make the camera\n // move from its initial position (which is centered on the screen) - and anchor\n // behavior would behave counterintuitively.\n if (\n // Have a safety margin of 1 pixel to avoid rounding errors.\n Math.abs(this._cameraX - oldGameResolutionOriginX) < 1 &&\n Math.abs(this._cameraY - oldGameResolutionOriginY) < 1 &&\n this._zoomFactor === 1\n ) {\n this._cameraX +=\n this._runtimeScene.getViewportOriginX() - oldGameResolutionOriginX;\n this._cameraY +=\n this._runtimeScene.getViewportOriginY() - oldGameResolutionOriginY;\n }\n\n this._renderer.updatePosition();\n this._renderer.updateResolution();\n }\n\n /**\n * Change the camera center X position.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The x position of the camera\n */\n getCameraX(cameraId?: integer): float {\n this._forceDimensionUpdate();\n return this._cameraX;\n }\n\n /**\n * Change the camera center Y position.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The y position of the camera\n */\n getCameraY(cameraId?: integer): float {\n this._forceDimensionUpdate();\n return this._cameraY;\n }\n\n /**\n * Set the camera center X position.\n *\n * @param x The new x position\n * @param cameraId The camera number. Currently ignored.\n */\n setCameraX(x: float, cameraId?: integer): void {\n this._forceDimensionUpdate();\n this._cameraX = x;\n this._renderer.updatePosition();\n }\n\n /**\n * Set the camera center Y position.\n *\n * @param y The new y position\n * @param cameraId The camera number. Currently ignored.\n */\n setCameraY(y: float, cameraId?: integer): void {\n this._forceDimensionUpdate();\n this._cameraY = y;\n this._renderer.updatePosition();\n }\n\n /**\n * Get the camera width (which can be different than the game resolution width\n * if the camera is zoomed).\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The width of the camera\n */\n getCameraWidth(cameraId?: integer): float {\n return this.getWidth() / this._zoomFactor;\n }\n\n /**\n * Get the camera height (which can be different than the game resolution height\n * if the camera is zoomed).\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The height of the camera\n */\n getCameraHeight(cameraId?: integer): float {\n return this.getHeight() / this._zoomFactor;\n }\n\n /**\n * Set the zoom of a camera.\n *\n * @param newZoom The new zoom. Must be superior to 0. 1 is the default zoom.\n * @param cameraId The camera number. Currently ignored.\n */\n setCameraZoom(newZoom: float, cameraId?: integer): void {\n this._zoomFactor = newZoom;\n this._isCameraZDirty = true;\n this._renderer.updatePosition();\n }\n\n /**\n * Get the zoom of a camera.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The zoom.\n */\n getCameraZoom(cameraId?: integer): float {\n return this._zoomFactor;\n }\n\n /**\n * Set the camera center Z position.\n *\n * @param z The new y position.\n * @param fov The field of view.\n * @param cameraId The camera number. Currently ignored.\n */\n setCameraZ(z: float, fov: float | null, cameraId?: integer): void {\n if (fov) {\n const cameraFovInRadians = gdjs.toRad(fov);\n\n // The zoom factor is capped to a not too big value to avoid infinity.\n // MAX_SAFE_INTEGER is an arbitrary choice. It's big but not too big.\n const zoomFactor = Math.min(\n Number.MAX_SAFE_INTEGER,\n (0.5 * this.getHeight()) / (z * Math.tan(0.5 * cameraFovInRadians))\n );\n\n if (zoomFactor > 0) {\n this._zoomFactor = zoomFactor;\n }\n }\n\n this._cameraZ = z;\n this._isCameraZDirty = false;\n this._renderer.updatePosition();\n }\n\n /**\n * Get the camera center Z position.\n *\n * @param fov The field of view.\n * @param cameraId The camera number. Currently ignored.\n * @return The z position of the camera\n */\n getCameraZ(fov: float | null, cameraId?: integer): float {\n if (!this._isCameraZDirty || !fov) {\n return this._cameraZ;\n }\n\n // Set the camera so that it displays the whole PixiJS plane, as if it was a 2D rendering.\n // The Z position is computed by taking the half height of the displayed rendering,\n // and using the angle of the triangle defined by the field of view to compute the length\n // of the triangle defining the distance between the camera and the rendering plane.\n const cameraZPosition =\n (0.5 * this.getHeight()) /\n this.getCameraZoom() /\n Math.tan(0.5 * gdjs.toRad(fov));\n\n return cameraZPosition;\n }\n\n /**\n * Get the rotation of the camera, expressed in degrees.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The rotation, in degrees.\n */\n getCameraRotation(cameraId?: integer): float {\n return this._cameraRotation;\n }\n\n /**\n * Set the rotation of the camera, expressed in degrees.\n * The rotation is made around the camera center.\n *\n * @param rotation The new rotation, in degrees.\n * @param cameraId The camera number. Currently ignored.\n */\n setCameraRotation(rotation: float, cameraId?: integer): void {\n this._cameraRotation = rotation;\n this._renderer.updatePosition();\n }\n\n /**\n * Convert a point from the canvas coordinates (for example,\n * the mouse position) to the container coordinates.\n *\n * This method handles 3D rotations.\n *\n * @param x The x position, in canvas coordinates.\n * @param y The y position, in canvas coordinates.\n * @param cameraId The camera number. Currently ignored.\n * @param result The point instance that is used to return the result.\n */\n convertCoords(\n x: float,\n y: float,\n cameraId: integer = 0,\n result: FloatPoint\n ): FloatPoint {\n // This code duplicates applyLayerInverseTransformation for performance reasons;\n\n // The result parameter used to be optional.\n let position = result || [0, 0];\n\n if (this._renderer.isCameraRotatedIn3D()) {\n return this._renderer.transformTo3DWorld(x, y, 0, cameraId, result);\n }\n\n x -= this.getRuntimeScene()._cachedGameResolutionWidth / 2;\n y -= this.getRuntimeScene()._cachedGameResolutionHeight / 2;\n x /= Math.abs(this._zoomFactor);\n y /= Math.abs(this._zoomFactor);\n\n // Only compute angle and cos/sin once (allow heavy optimization from JS engines).\n const angleInRadians = (this._cameraRotation / 180) * Math.PI;\n const tmp = x;\n const cosValue = Math.cos(angleInRadians);\n const sinValue = Math.sin(angleInRadians);\n x = cosValue * x - sinValue * y;\n y = sinValue * tmp + cosValue * y;\n position[0] = x + this.getCameraX(cameraId);\n position[1] = y + this.getCameraY(cameraId);\n return position;\n }\n\n /**\n * Return an array containing the coordinates of the point passed as parameter\n * in layer local coordinates (as opposed to the parent coordinates).\n *\n * All transformations (scale, rotation) are supported.\n *\n * This method doesn't handle 3D rotations.\n *\n * @param x The X position of the point, in parent coordinates.\n * @param y The Y position of the point, in parent coordinates.\n * @param result Array that will be updated with the result\n * @param result The point instance that is used to return the result.\n * (x and y position of the point in layer coordinates).\n */\n applyLayerInverseTransformation(\n x: float,\n y: float,\n cameraId: integer,\n result: FloatPoint\n ): FloatPoint {\n x -= this._runtimeScene.getViewportOriginX();\n y -= this._runtimeScene.getViewportOriginY();\n x /= Math.abs(this._zoomFactor);\n y /= Math.abs(this._zoomFactor);\n\n // Only compute angle and cos/sin once (allow heavy optimization from JS engines).\n const angleInRadians = (this._cameraRotation / 180) * Math.PI;\n const tmp = x;\n const cosValue = Math.cos(angleInRadians);\n const sinValue = Math.sin(angleInRadians);\n x = cosValue * x - sinValue * y;\n y = sinValue * tmp + cosValue * y;\n result[0] = x + this.getCameraX(cameraId);\n result[1] = y + this.getCameraY(cameraId);\n\n return result;\n }\n\n /**\n * Convert a point from the container coordinates (for example,\n * an object position) to the canvas coordinates.\n *\n * This method doesn't handle 3D rotations.\n *\n * @param x The x position, in container coordinates.\n * @param y The y position, in container coordinates.\n * @param cameraId The camera number. Currently ignored.\n * @param result The point instance that is used to return the result.\n */\n convertInverseCoords(\n x: float,\n y: float,\n cameraId: integer = 0,\n result: FloatPoint\n ): FloatPoint {\n // This code duplicates applyLayerTransformation for performance reasons;\n\n // The result parameter used to be optional.\n let position = result || [0, 0];\n x -= this.getCameraX(cameraId);\n y -= this.getCameraY(cameraId);\n\n // Only compute angle and cos/sin once (allow heavy optimization from JS engines).\n const angleInRadians = (this._cameraRotation / 180) * Math.PI;\n const tmp = x;\n const cosValue = Math.cos(-angleInRadians);\n const sinValue = Math.sin(-angleInRadians);\n x = cosValue * x - sinValue * y;\n y = sinValue * tmp + cosValue * y;\n x *= Math.abs(this._zoomFactor);\n y *= Math.abs(this._zoomFactor);\n position[0] = x + this.getRuntimeScene()._cachedGameResolutionWidth / 2;\n position[1] = y + this.getRuntimeScene()._cachedGameResolutionHeight / 2;\n return position;\n }\n\n /**\n * Return an array containing the coordinates of the point passed as parameter\n * in parent coordinate coordinates (as opposed to the layer local coordinates).\n *\n * All transformations (scale, rotation) are supported.\n *\n * This method doesn't handle 3D rotations.\n *\n * @param x The X position of the point, in layer coordinates.\n * @param y The Y position of the point, in layer coordinates.\n * @param result Array that will be updated with the result\n * (x and y position of the point in parent coordinates).\n */\n applyLayerTransformation(\n x: float,\n y: float,\n cameraId: integer,\n result: FloatPoint\n ): FloatPoint {\n x -= this.getCameraX(cameraId);\n y -= this.getCameraY(cameraId);\n\n // Only compute angle and cos/sin once (allow heavy optimization from JS engines).\n const angleInRadians = (this._cameraRotation / 180) * Math.PI;\n const tmp = x;\n const cosValue = Math.cos(-angleInRadians);\n const sinValue = Math.sin(-angleInRadians);\n x = cosValue * x - sinValue * y;\n y = sinValue * tmp + cosValue * y;\n x *= Math.abs(this._zoomFactor);\n y *= Math.abs(this._zoomFactor);\n x += this._runtimeScene.getViewportOriginX();\n y += this._runtimeScene.getViewportOriginY();\n\n result[0] = x;\n result[1] = y;\n return result;\n }\n\n /**\n * This ensure that the viewport dimensions are up to date.\n *\n * It's needed because custom objects dimensions are only updated on\n * demand for efficiency reasons.\n */\n private _forceDimensionUpdate(): void {\n // This will update dimensions.\n this._runtimeScene.getViewportWidth();\n }\n }\n}\n"],
|
|
5
|
-
"mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CAIS,eAAoB,GAAK,YAAa,CAe3C,YACE,EACA,EACA,CACA,MAAM,EAAW,GAlBnB,qBAAyB,EACzB,iBAAqB,EAGrB,cAAkB,EAIlB,qBAA2B,GAYzB,KAAK,SAAW,KAAK,
|
|
4
|
+
"sourcesContent": ["/*\n * GDevelop JS Platform\n * Copyright 2013-2016 Florian Rival (Florian.Rival@gmail.com). All rights reserved.\n * This project is released under the MIT License.\n */\nnamespace gdjs {\n /**\n * Represents a layer of a scene, used to display objects.\n */\n export class Layer extends gdjs.RuntimeLayer {\n _cameraRotation: float = 0;\n _zoomFactor: float = 1;\n _cameraX: float;\n _cameraY: float;\n _cameraZ: float = 0;\n /**\n * `_cameraZ` is dirty when the zoom factor is set last.\n */\n _isCameraZDirty: boolean = true;\n\n /**\n * @param layerData The data used to initialize the layer\n * @param instanceContainer The container in which the layer is used\n */\n constructor(\n layerData: LayerData,\n instanceContainer: gdjs.RuntimeInstanceContainer\n ) {\n super(layerData, instanceContainer);\n\n if (\n this._defaultCameraBehavior ===\n gdjs.RuntimeLayerDefaultCameraBehavior.TOP_LEFT_ANCHORED_IF_NEVER_MOVED\n ) {\n // If top-left must stay in the top-left corner, this means we center the camera on the current size.\n this._cameraX = this._runtimeScene.getViewportOriginX();\n this._cameraY = this._runtimeScene.getViewportOriginY();\n } else {\n // Otherwise, the default camera position is the center of the initial viewport.\n this._cameraX =\n (this._runtimeScene.getInitialUnrotatedViewportMinX() +\n this._runtimeScene.getInitialUnrotatedViewportMaxX()) /\n 2;\n this._cameraY =\n (this._runtimeScene.getInitialUnrotatedViewportMinY() +\n this._runtimeScene.getInitialUnrotatedViewportMaxY()) /\n 2;\n }\n if (this.getCameraType() === gdjs.RuntimeLayerCameraType.ORTHOGRAPHIC) {\n this._cameraZ =\n (this._initialCamera3DFarPlaneDistance +\n this._initialCamera3DNearPlaneDistance) /\n 2;\n }\n\n // Let the renderer do its final set up:\n this._renderer.onCreated();\n }\n\n /**\n * Called by the RuntimeScene whenever the game resolution size is changed.\n * Updates the layer width/height and position.\n */\n onGameResolutionResized(\n oldGameResolutionOriginX: float,\n oldGameResolutionOriginY: float\n ): void {\n // Adapt position of the camera center only if the camera has never moved as:\n // * When the camera follows a player/object, it will rarely be at the default position.\n // (and if is, it will be moved again by the behavior/events).\n // * Cameras not following a player/object are usually UIs which are intuitively\n // expected not to \"move\" (top-left stays \"fixed\"), while gameplay is \"centered\" (center stays \"fixed\").\n //\n // Note that anchor behavior is usually a better choice for UIs.\n if (\n this._defaultCameraBehavior ===\n gdjs.RuntimeLayerDefaultCameraBehavior\n .TOP_LEFT_ANCHORED_IF_NEVER_MOVED &&\n // Have a safety margin of 1 pixel to avoid rounding errors.\n Math.abs(this._cameraX - oldGameResolutionOriginX) < 1 &&\n Math.abs(this._cameraY - oldGameResolutionOriginY) < 1 &&\n this._zoomFactor === 1\n ) {\n this._cameraX +=\n this._runtimeScene.getViewportOriginX() - oldGameResolutionOriginX;\n this._cameraY +=\n this._runtimeScene.getViewportOriginY() - oldGameResolutionOriginY;\n }\n\n this._renderer.updatePosition();\n this._renderer.updateResolution();\n }\n\n /**\n * Change the camera center X position.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The x position of the camera\n */\n getCameraX(cameraId?: integer): float {\n this._forceDimensionUpdate();\n return this._cameraX;\n }\n\n /**\n * Change the camera center Y position.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The y position of the camera\n */\n getCameraY(cameraId?: integer): float {\n this._forceDimensionUpdate();\n return this._cameraY;\n }\n\n /**\n * Set the camera center X position.\n *\n * @param x The new x position\n * @param cameraId The camera number. Currently ignored.\n */\n setCameraX(x: float, cameraId?: integer): void {\n this._forceDimensionUpdate();\n this._cameraX = x;\n this._renderer.updatePosition();\n }\n\n /**\n * Set the camera center Y position.\n *\n * @param y The new y position\n * @param cameraId The camera number. Currently ignored.\n */\n setCameraY(y: float, cameraId?: integer): void {\n this._forceDimensionUpdate();\n this._cameraY = y;\n this._renderer.updatePosition();\n }\n\n /**\n * Get the camera width (which can be different than the game resolution width\n * if the camera is zoomed).\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The width of the camera\n */\n getCameraWidth(cameraId?: integer): float {\n return this.getWidth() / this._zoomFactor;\n }\n\n /**\n * Get the camera height (which can be different than the game resolution height\n * if the camera is zoomed).\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The height of the camera\n */\n getCameraHeight(cameraId?: integer): float {\n return this.getHeight() / this._zoomFactor;\n }\n\n /**\n * Set the zoom of a camera.\n *\n * @param newZoom The new zoom. Must be superior to 0. 1 is the default zoom.\n * @param cameraId The camera number. Currently ignored.\n */\n setCameraZoom(newZoom: float, cameraId?: integer): void {\n this._zoomFactor = newZoom;\n this._isCameraZDirty = true;\n this._renderer.updatePosition();\n }\n\n /**\n * Get the zoom of a camera.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The zoom.\n */\n getCameraZoom(cameraId?: integer): float {\n return this._zoomFactor;\n }\n\n /**\n * Set the camera center Z position.\n *\n * @param z The new y position.\n * @param fov The field of view.\n * @param cameraId The camera number. Currently ignored.\n */\n setCameraZ(z: float, fov: float | null, cameraId?: integer): void {\n if (fov) {\n const cameraFovInRadians = gdjs.toRad(fov);\n\n // The zoom factor is capped to a not too big value to avoid infinity.\n // MAX_SAFE_INTEGER is an arbitrary choice. It's big but not too big.\n const zoomFactor = Math.min(\n Number.MAX_SAFE_INTEGER,\n (0.5 * this.getHeight()) / (z * Math.tan(0.5 * cameraFovInRadians))\n );\n\n if (zoomFactor > 0) {\n this._zoomFactor = zoomFactor;\n }\n }\n\n this._cameraZ = z;\n this._isCameraZDirty = false;\n this._renderer.updatePosition();\n }\n\n /**\n * Get the camera center Z position.\n *\n * @param fov The field of view.\n * @param cameraId The camera number. Currently ignored.\n * @return The z position of the camera\n */\n getCameraZ(fov: float | null, cameraId?: integer): float {\n if (!this._isCameraZDirty || !fov) {\n return this._cameraZ;\n }\n\n // Set the camera so that it displays the whole PixiJS plane, as if it was a 2D rendering.\n // The Z position is computed by taking the half height of the displayed rendering,\n // and using the angle of the triangle defined by the field of view to compute the length\n // of the triangle defining the distance between the camera and the rendering plane.\n const cameraZPosition =\n (0.5 * this.getHeight()) /\n this.getCameraZoom() /\n Math.tan(0.5 * gdjs.toRad(fov));\n\n return cameraZPosition;\n }\n\n /**\n * Get the rotation of the camera, expressed in degrees.\n *\n * @param cameraId The camera number. Currently ignored.\n * @return The rotation, in degrees.\n */\n getCameraRotation(cameraId?: integer): float {\n return this._cameraRotation;\n }\n\n /**\n * Set the rotation of the camera, expressed in degrees.\n * The rotation is made around the camera center.\n *\n * @param rotation The new rotation, in degrees.\n * @param cameraId The camera number. Currently ignored.\n */\n setCameraRotation(rotation: float, cameraId?: integer): void {\n this._cameraRotation = rotation;\n this._renderer.updatePosition();\n }\n\n /**\n * Convert a point from the canvas coordinates (for example,\n * the mouse position) to the container coordinates.\n *\n * This method handles 3D rotations.\n *\n * @param x The x position, in canvas coordinates.\n * @param y The y position, in canvas coordinates.\n * @param cameraId The camera number. Currently ignored.\n * @param result The point instance that is used to return the result.\n */\n convertCoords(\n x: float,\n y: float,\n cameraId: integer = 0,\n result: FloatPoint\n ): FloatPoint {\n // This code duplicates applyLayerInverseTransformation for performance reasons;\n\n // The result parameter used to be optional.\n let position = result || [0, 0];\n\n if (this._renderer.isCameraRotatedIn3D()) {\n return this._renderer.transformTo3DWorld(x, y, 0, cameraId, result);\n }\n\n x -= this.getRuntimeScene()._cachedGameResolutionWidth / 2;\n y -= this.getRuntimeScene()._cachedGameResolutionHeight / 2;\n x /= Math.abs(this._zoomFactor);\n y /= Math.abs(this._zoomFactor);\n\n // Only compute angle and cos/sin once (allow heavy optimization from JS engines).\n const angleInRadians = (this._cameraRotation / 180) * Math.PI;\n const tmp = x;\n const cosValue = Math.cos(angleInRadians);\n const sinValue = Math.sin(angleInRadians);\n x = cosValue * x - sinValue * y;\n y = sinValue * tmp + cosValue * y;\n position[0] = x + this.getCameraX(cameraId);\n position[1] = y + this.getCameraY(cameraId);\n return position;\n }\n\n /**\n * Return an array containing the coordinates of the point passed as parameter\n * in layer local coordinates (as opposed to the parent coordinates).\n *\n * All transformations (scale, rotation) are supported.\n *\n * This method doesn't handle 3D rotations.\n *\n * @param x The X position of the point, in parent coordinates.\n * @param y The Y position of the point, in parent coordinates.\n * @param result Array that will be updated with the result\n * @param result The point instance that is used to return the result.\n * (x and y position of the point in layer coordinates).\n */\n applyLayerInverseTransformation(\n x: float,\n y: float,\n cameraId: integer,\n result: FloatPoint\n ): FloatPoint {\n x -= this._runtimeScene.getViewportOriginX();\n y -= this._runtimeScene.getViewportOriginY();\n x /= Math.abs(this._zoomFactor);\n y /= Math.abs(this._zoomFactor);\n\n // Only compute angle and cos/sin once (allow heavy optimization from JS engines).\n const angleInRadians = (this._cameraRotation / 180) * Math.PI;\n const tmp = x;\n const cosValue = Math.cos(angleInRadians);\n const sinValue = Math.sin(angleInRadians);\n x = cosValue * x - sinValue * y;\n y = sinValue * tmp + cosValue * y;\n result[0] = x + this.getCameraX(cameraId);\n result[1] = y + this.getCameraY(cameraId);\n\n return result;\n }\n\n /**\n * Convert a point from the container coordinates (for example,\n * an object position) to the canvas coordinates.\n *\n * This method doesn't handle 3D rotations.\n *\n * @param x The x position, in container coordinates.\n * @param y The y position, in container coordinates.\n * @param cameraId The camera number. Currently ignored.\n * @param result The point instance that is used to return the result.\n */\n convertInverseCoords(\n x: float,\n y: float,\n cameraId: integer = 0,\n result: FloatPoint\n ): FloatPoint {\n // This code duplicates applyLayerTransformation for performance reasons;\n\n // The result parameter used to be optional.\n let position = result || [0, 0];\n x -= this.getCameraX(cameraId);\n y -= this.getCameraY(cameraId);\n\n // Only compute angle and cos/sin once (allow heavy optimization from JS engines).\n const angleInRadians = (this._cameraRotation / 180) * Math.PI;\n const tmp = x;\n const cosValue = Math.cos(-angleInRadians);\n const sinValue = Math.sin(-angleInRadians);\n x = cosValue * x - sinValue * y;\n y = sinValue * tmp + cosValue * y;\n x *= Math.abs(this._zoomFactor);\n y *= Math.abs(this._zoomFactor);\n position[0] = x + this.getRuntimeScene()._cachedGameResolutionWidth / 2;\n position[1] = y + this.getRuntimeScene()._cachedGameResolutionHeight / 2;\n\n return position;\n }\n\n /**\n * Return an array containing the coordinates of the point passed as parameter\n * in parent coordinate coordinates (as opposed to the layer local coordinates).\n *\n * All transformations (scale, rotation) are supported.\n *\n * This method doesn't handle 3D rotations.\n *\n * @param x The X position of the point, in layer coordinates.\n * @param y The Y position of the point, in layer coordinates.\n * @param result Array that will be updated with the result\n * (x and y position of the point in parent coordinates).\n */\n applyLayerTransformation(\n x: float,\n y: float,\n cameraId: integer,\n result: FloatPoint\n ): FloatPoint {\n x -= this.getCameraX(cameraId);\n y -= this.getCameraY(cameraId);\n\n // Only compute angle and cos/sin once (allow heavy optimization from JS engines).\n const angleInRadians = (this._cameraRotation / 180) * Math.PI;\n const tmp = x;\n const cosValue = Math.cos(-angleInRadians);\n const sinValue = Math.sin(-angleInRadians);\n x = cosValue * x - sinValue * y;\n y = sinValue * tmp + cosValue * y;\n x *= Math.abs(this._zoomFactor);\n y *= Math.abs(this._zoomFactor);\n x += this._runtimeScene.getViewportOriginX();\n y += this._runtimeScene.getViewportOriginY();\n\n result[0] = x;\n result[1] = y;\n return result;\n }\n\n /**\n * This ensure that the viewport dimensions are up to date.\n *\n * It's needed because custom objects dimensions are only updated on\n * demand for efficiency reasons.\n */\n private _forceDimensionUpdate(): void {\n // This will update dimensions.\n this._runtimeScene.getViewportWidth();\n }\n }\n}\n"],
|
|
5
|
+
"mappings": "AAKA,GAAU,MAAV,UAAU,EAAV,CAIS,eAAoB,GAAK,YAAa,CAe3C,YACE,EACA,EACA,CACA,MAAM,EAAW,GAlBnB,qBAAyB,EACzB,iBAAqB,EAGrB,cAAkB,EAIlB,qBAA2B,GAYzB,AACE,KAAK,yBACL,EAAK,kCAAkC,iCAGvC,MAAK,SAAW,KAAK,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,GAAI,GAAW,GAAU,CAAC,EAAG,GAC7B,GAAK,KAAK,WAAW,GACrB,GAAK,KAAK,WAAW,GAGrB,KAAM,GAAkB,KAAK,gBAAkB,IAAO,KAAK,GACrD,EAAM,EACN,EAAW,KAAK,IAAI,CAAC,GACrB,EAAW,KAAK,IAAI,CAAC,GAC3B,SAAI,EAAW,EAAI,EAAW,EAC9B,EAAI,EAAW,EAAM,EAAW,EAChC,GAAK,KAAK,IAAI,KAAK,aACnB,GAAK,KAAK,IAAI,KAAK,aACnB,EAAS,GAAK,EAAI,KAAK,kBAAkB,2BAA6B,EACtE,EAAS,GAAK,EAAI,KAAK,kBAAkB,4BAA8B,EAEhE,EAgBT,yBACE,EACA,EACA,EACA,EACY,CACZ,GAAK,KAAK,WAAW,GACrB,GAAK,KAAK,WAAW,GAGrB,KAAM,GAAkB,KAAK,gBAAkB,IAAO,KAAK,GACrD,EAAM,EACN,EAAW,KAAK,IAAI,CAAC,GACrB,EAAW,KAAK,IAAI,CAAC,GAC3B,SAAI,EAAW,EAAI,EAAW,EAC9B,EAAI,EAAW,EAAM,EAAW,EAChC,GAAK,KAAK,IAAI,KAAK,aACnB,GAAK,KAAK,IAAI,KAAK,aACnB,GAAK,KAAK,cAAc,qBACxB,GAAK,KAAK,cAAc,qBAExB,EAAO,GAAK,EACZ,EAAO,GAAK,EACL,EASD,uBAA8B,CAEpC,KAAK,cAAc,oBA/ZhB,EAAM,UAJL",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var gdjs;(function(l){const
|
|
1
|
+
var gdjs;(function(l){const a=new l.Logger("PIXI Image manager"),T=(n,e)=>{a.error("Unable to load file "+n+" with error:",e||"(unknown error)")},d=(n,e)=>{!n||e.smoothed||(n.baseTexture.scaleMode=PIXI.SCALE_MODES.NEAREST)},A=(n,e)=>{e&&!e.smoothed&&(n.magFilter=THREE.NearestFilter,n.minFilter=THREE.NearestFilter)},g=["image","video"];class x{constructor(e){this._loadedTextures=new l.ResourceCache;this._diskTextures=new Map;this._rectangleTextures=new Map;this._scaledTextures=new Map;this._getImageResource=e=>{const r=this._resourceLoader.getResource(e);return r&&this.getResourceKinds().includes(r.kind)?r:null};this._resourceLoader=e,this._invalidTexture=PIXI.Texture.from("data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAMAAAADACAMAAABlApw1AAAAkFBMVEWdIvr///+hOfrx6v7i0/39/P+eK/rn2v6vbPv7+f/cx/359v/38v7s4v7Wvf3LqvzFnvysY/v18P6jQvrz7P7u5P7ezP3Or/yoV/qlTfrq3v7l1v3hz/2fLvrTuPy0efufMvraxP3YwP3AlPu2fvuuavvRtPy8i/uqXfu5hvvIo/y4gvuxcvugNfq+j/vCmfxfwZ2lAAAF60lEQVR42uzPMQ0AAAjEQPBvmhkBDE+uAppcdXgfAHXY9R4AAAAAAAAAAGAFAAAAAAAAAAAAAAAAAAAAAAAAAAAAEA/YAQAMNfa2nCoMhmE4HxhcFESggMhGtNa11NLl/d9dO53pQRMklPKn4TllhuEdEjb/CK/WWPXvBTjOOVxvDsvVO3u03e8EnC9BZnNMwNcfYDU728NkLpoDLpmPSQU6Ax5vNsfE0lpbwOs1AYGbroDnBCQyPQH7tQsanpYAqwQVftEQEKWgE9AHtAkIpTV1QBOD1Jk4IPJA6y9tQF2C2Io24ApqXq4OMHgBvTsSBjgVBnA9P7HH2xEGPOM+7hVPQdhGUZRvt4/WeHvCgBJ3uFXYsn4m/BO3HJ2Ko8XuMSogQBdvzXoYFRCjQ3GazWQuRIfKms1o0Skge3DmMxvdckiWzoyGu0dIvGhO0+kAkmBW4/UVRPw0qwAfopKpmRPwh0N0ZGrmBPyDyI2Yms6AaiH48nd3g8hmsijMFkrZ9UQSwCFY9j+EHpgor1wM4gaO9oAKog0TtDEGuxoQIF7DOcZwqQEB4kJe4Bt83QHOEiJLuAGe2QG2KuAF37HUHVAn0wZsdAfs/WkD8pkHrGrtSyhWBVgxhnti5m1itsZg/IUiIO4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EfABiFyKlbEl+gqOoGZKJl484gjLLkEa4HTobfYlxxGrtgWcpzzremf7x2OO4vMoMvBsWnjkQB4gmEd5J8PU5r2nj23yEt1scORAFdCsm0znD4Zg9/eC0a+JuVa0bOARb5BXpor4/v8qdOV7DDstvKQd4kYAfllW/l+Sx+RfzW+XDDy8V8BPnyc511wvHCQPb+F3DDDsIHcfJStc9p5w//zRrL1qazH7ZJ6nP4a8XOI77IlTAld4w4FVu7qqA31SAClABKkAFqAAVoAJUgApQASpABagAFaACVIAKUAH/TcB7e/uA7+03ZsJSaNOuAAAAAElFTkSuQmCC",{width:192,height:192}),this._loadedThreeTextures=new Hashtable,this._loadedThreeMaterials=new Hashtable}getResourceKinds(){return g}getPIXITexture(e){const r=this._getImageResource(e);if(!r)return a.warn('Unable to find texture for resource "'+e+'".'),this._invalidTexture;const t=this._loadedTextures.get(r);return t?t.valid?t:(a.error("Texture for "+e+" is not valid anymore (or never was)."),this._invalidTexture):this._invalidTexture}getOrLoadPIXITexture(e){const r=this._getImageResource(e);if(!r)return a.warn('Unable to find texture for resource "'+e+'".'),this._invalidTexture;const t=this._loadedTextures.get(r);if(t)return t.valid?t:(a.error("Texture for "+e+" is not valid anymore (or never was)."),this._invalidTexture);a.log('Loading texture for resource "'+e+'"...');const i=r.file,o=this._resourceLoader.getFullUrl(i),s=PIXI.Texture.from(o,{resourceOptions:{crossorigin:this._resourceLoader.checkIfCredentialsRequired(i)?"use-credentials":"anonymous"}}).on("error",u=>{T(i,u)});if(!s)throw new Error("Texture loading by PIXI returned nothing for file "+i+" behind url "+o);return d(s,r),this._loadedTextures.set(r,s),s}getThreeTexture(e){const r=this._loadedThreeTextures.get(e);if(r)return r;const t=this.getPIXITexture(e);if(!this._resourceLoader._runtimeGame.getRenderer().getPIXIRenderer())throw new Error("No PIXI renderer was found.");const o=t.baseTexture.resource.source;if(!(o instanceof HTMLImageElement))throw new Error(`Can't load texture for resource "${e}" as it's not an image.`);const s=new THREE.Texture(o);s.magFilter=THREE.LinearFilter,s.minFilter=THREE.LinearFilter,s.wrapS=THREE.RepeatWrapping,s.wrapT=THREE.RepeatWrapping,s.colorSpace=THREE.SRGBColorSpace,s.needsUpdate=!0;const u=this._getImageResource(e);return A(s,u),this._loadedThreeTextures.put(e,s),s}getThreeMaterial(e,{useTransparentTexture:r,forceBasicMaterial:t}){const i=`${e}|${r?1:0}|${t?1:0}`,o=this._loadedThreeMaterials.get(i);if(o)return o;const s=t?new THREE.MeshBasicMaterial({map:this.getThreeTexture(e),side:r?THREE.DoubleSide:THREE.FrontSide,transparent:r}):new THREE.MeshStandardMaterial({map:this.getThreeTexture(e),side:r?THREE.DoubleSide:THREE.FrontSide,transparent:r,metalness:0});return this._loadedThreeMaterials.put(i,s),s}getPIXIVideoTexture(e){if(e==="")return this._invalidTexture;const r=this._getImageResource(e);if(!r)return a.warn('Unable to find video texture for resource "'+e+'".'),this._invalidTexture;const t=this._loadedTextures.get(r);return t||this._invalidTexture}getInvalidPIXITexture(){return this._invalidTexture}async loadResource(e){const r=this._resourceLoader.getResource(e);if(!r){a.warn('Unable to find texture for resource "'+e+'".');return}await this._loadTexture(r)}async processResource(e){}async _loadTexture(e){if(!this._loadedTextures.get(e))try{if(e.kind==="video")await new Promise((r,t)=>{const i=PIXI.Texture.from(this._resourceLoader.getFullUrl(e.file),{resourceOptions:{crossorigin:this._resourceLoader.checkIfCredentialsRequired(e.file)?"use-credentials":"anonymous",autoPlay:!1}}).on("error",s=>{t(s)});i.baseTexture.on("loaded",()=>{this._loadedTextures.set(e,i),d(i,e),r()}).on("error",s=>{t(s)})});else{const r=PIXI.Texture.from(this._resourceLoader.getFullUrl(e.file),{resourceOptions:{autoLoad:!1,crossorigin:this._resourceLoader.checkIfCredentialsRequired(e.file)?"use-credentials":"anonymous"}});await r.baseTexture.resource.load(),this._loadedTextures.set(e,r),d(r,e)}}catch(r){T(e.file,r)}}getOrCreateDiskTexture(e,r){let t=this._diskTextures.get(e);if(!t){const i=new PIXI.Graphics;i.lineStyle(0,0,0),i.beginFill(l.rgbToHexNumber(255,255,255),1),i.drawCircle(0,0,e),i.endFill(),t=r.generateTexture(i),i.destroy(),this._diskTextures.set(e,t)}return t}getOrCreateRectangleTexture(e,r,t){const i=`${e}_${r}`;let o=this._rectangleTextures.get(i);if(!o){const s=new PIXI.Graphics;s.lineStyle(0,0,0),s.beginFill(l.rgbToHexNumber(255,255,255),1),s.drawRect(0,0,e,r),s.endFill(),o=t.generateTexture(s),s.destroy(),this._rectangleTextures.set(i,o)}return o}getOrCreateScaledTexture(e,r,t,i){const o=`${e}_${r}_${t}`;let s=this._scaledTextures.get(o);if(!s){const u=new PIXI.Graphics,c=new PIXI.Sprite(this.getPIXITexture(e));c.width=r,c.height=t,u.addChild(c),s=i.generateTexture(u),u.destroy(),this._scaledTextures.set(o,s)}return s}dispose(){this._loadedTextures.clear();const e=[];this._loadedThreeTextures.values(e),this._loadedThreeTextures.clear();for(const t of e)t.dispose();const r=[];this._loadedThreeMaterials.values(r),this._loadedThreeMaterials.clear();for(const t of r)t.dispose();for(const t of this._diskTextures.values())t.destroyed||t.destroy();this._diskTextures.clear();for(const t of this._rectangleTextures.values())t.destroyed||t.destroy();this._rectangleTextures.clear();for(const t of this._scaledTextures.values())t.destroyed||t.destroy();this._scaledTextures.clear()}}l.PixiImageManager=x,l.ImageManager=l.PixiImageManager})(gdjs||(gdjs={}));
|
|
2
2
|
//# sourceMappingURL=pixi-image-manager.js.map
|