gdcore-tools 2.0.0-gd-v5.4.218-autobuild → 2.0.0-gd-v5.4.219-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/physics2runtimebehavior.js +1 -1
- package/dist/Runtime/Extensions/Physics2Behavior/physics2runtimebehavior.js.map +2 -2
- package/dist/Runtime/Extensions/TileMap/simpletilemapruntimeobject.js +1 -1
- package/dist/Runtime/Extensions/TileMap/simpletilemapruntimeobject.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/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 +13 -1
- package/package.json +1 -1
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
var gdjs;(function(s){const a=class extends s.RuntimeObject{constructor(e,t){super(e,t);this._displayMode="all";this._layerIndex=0;this._initialTileMapAsJsObject=null;this._isTileMapDirty=!1;this._sceneToTileMapTransformation=new s.AffineTransformation;this._tileMapToSceneTransformation=new s.AffineTransformation;this._collisionTileMap=null;this._hitBoxTag="collision";this._transformationIsUpToDate=!1;this._opacity=t.content.opacity,this._atlasImage=t.content.atlasImage,this._rowCount=t.content.rowCount,this._columnCount=t.content.columnCount,this._tileSize=t.content.tileSize,this._initialTilesWithHitBox=t.content.tilesWithHitBox.split(",").filter(i=>!!i).map(i=>parseInt(i,10)),this._tileMapManager=s.TileMap.TileMapRuntimeManager.getManager(e),this._renderer=new s.TileMapRuntimeObjectRenderer(this,e),this.onCreated()}getRendererObject(){return this._renderer.getRendererObject()}updatePreRender(e){if(this._isTileMapDirty){let t=!0;if(this._tileMapManager.getOrLoadSimpleTileMapTextureCache(i=>this.getInstanceContainer().getGame().getImageManager().getPIXITexture(i),this._atlasImage,this._tileSize,this._columnCount,this._rowCount,i=>{!i||this._renderer.refreshPixiTileMap(i)},i=>{t=!1,console.error(`Could not load texture cache for atlas ${this._atlasImage} during prerender. The tilemap might be badly configured or an issues happened with the loaded atlas image:`,i)}),!t)return;if(this._collisionTileMap){const i=this._renderer.getTileMap();i&&this._collisionTileMap.updateFromTileMap(i)}this._isTileMapDirty=!1}}updateFromObjectData(e,t){return e.content.opacity!==t.content.opacity&&this.setOpacity(t.content.opacity),e.content.atlasImage===t.content.atlasImage}getNetworkSyncData(){return{...super.getNetworkSyncData(),op:this._opacity,ai:this._atlasImage,wid:this.getWidth(),hei:this.getHeight()}}updateFromNetworkSyncData(e){super.updateFromNetworkSyncData(e),e.op!==void 0&&e.op!==this._opacity&&this.setOpacity(e.op),e.wid!==void 0&&e.wid!==this.getWidth()&&this.setWidth(e.wid),e.hei!==void 0&&e.hei!==this.getHeight()&&this.setHeight(e.hei),e.ai!==void 0}extraInitializationFromInitialInstance(e){for(const t of e.stringProperties)t.name==="tilemap"&&(this._initialTileMapAsJsObject=JSON.parse(t.value));this._loadInitialTileMap(t=>{e.customSize&&(this.setWidth(e.width),this.setHeight(e.height)),e.opacity!==void 0&&this.setOpacity(e.opacity),this._renderer.updatePosition(),this._collisionTileMap?this._collisionTileMap.updateFromTileMap(t):this._collisionTileMap=new s.TileMap.TransformedCollisionTileMap(t,this._hitBoxTag),this.updateTransformation()})}_loadInitialTileMap(e){if(!!this._initialTileMapAsJsObject){if(this._columnCount<=0||this._rowCount<=0){console.error(`Tilemap object ${this.name} is not configured properly.`);return}this._tileMapManager.getOrLoadSimpleTileMap(this._initialTileMapAsJsObject,this.name,this._tileSize,this._columnCount,this._rowCount,t=>{this._initialTilesWithHitBox.forEach(i=>{const o=t.getTileDefinition(i);if(!o){console.warn(`Could not set hit box for tile with id ${i}. Continuing.`);return}o.addHitBox(this._hitBoxTag,[[0,0],[0,t.getTileHeight()],[t.getTileWidth(),t.getTileHeight()],[t.getTileWidth(),0]],!0)}),this._tileMapManager.getOrLoadSimpleTileMapTextureCache(i=>this.getInstanceContainer().getGame().getImageManager().getPIXITexture(i),this._atlasImage,this._tileSize,this._columnCount,this._rowCount,i=>{!i||(this._renderer.updatePixiTileMap(t,i),e(t))},i=>{console.error(`Could not load texture cache for atlas ${this._atlasImage} during initial loading. The tilemap might be badly configured or an issues happened with the loaded atlas image:`,i)})})}}onDestroyed(){super.onDestroyed(),this._renderer.destroy()}setWidth(e){this.getWidth()!==e&&(this._transformationIsUpToDate=!1,this._renderer.setWidth(e),this.invalidateHitboxes())}setHeight(e){this.getHeight()!==e&&(this._transformationIsUpToDate=!1,this._renderer.setHeight(e),this.invalidateHitboxes())}setSize(e,t){this.setWidth(e),this.setHeight(t),this._transformationIsUpToDate=!1}getScale(){const e=this.getScaleX(),t=this.getScaleY();return e===t?e:Math.sqrt(e*t)}setScale(e){this.setScaleX(e),this.setScaleY(e),this._transformationIsUpToDate=!1}setScaleX(e){e<0&&(e=0),this.getScaleX()!==e&&(this._renderer.setScaleX(e),this.invalidateHitboxes(),this._transformationIsUpToDate=!1)}setScaleY(e){e<0&&(e=0),this.getScaleY()!==e&&(this._renderer.setScaleY(e),this.invalidateHitboxes(),this._transformationIsUpToDate=!1)}setX(e){super.setX(e),this._renderer.updatePosition(),this._transformationIsUpToDate=!1}setY(e){super.setY(e),this._renderer.updatePosition(),this._transformationIsUpToDate=!1}setAngle(e){super.setAngle(e),this._renderer.updateAngle(),this._transformationIsUpToDate=!1}setOpacity(e){this._opacity=e,this._renderer.updateOpacity(),this._isTileMapDirty=!0}getOpacity(){return this._opacity}getWidth(){return this._renderer.getWidth()}getHeight(){return this._renderer.getHeight()}getScaleX(){return this._renderer.getScaleX()}getScaleY(){return this._renderer.getScaleY()}getHitBoxes(){return this.hitBoxesDirty&&(this.updateHitBoxes(),this.updateAABB(),this.hitBoxesDirty=!1),this.hitBoxes}updateHitBoxes(){this.updateTransformation(),!!this._collisionTileMap&&(this.hitBoxes=Array.from(this._collisionTileMap.getAllHitboxes(this._hitBoxTag)),this.hitBoxesDirty=!1,this.updateAABB())}updateAABB(){if(this.getAngle()===0)this.aabb.min[0]=this.x,this.aabb.min[1]=this.y,this.aabb.max[0]=this.aabb.min[0]+this.getWidth(),this.aabb.max[1]=this.aabb.min[1]+this.getHeight();else{if(!this._collisionTileMap)return;const e=this._collisionTileMap.getTransformation(),t=0,i=this._collisionTileMap.getWidth(),o=0,r=this._collisionTileMap.getHeight(),n=this.aabb.min;n[0]=t,n[1]=o,e.transform(n,n);const l=n[0],h=n[1];n[0]=i,n[1]=o,e.transform(n,n);const d=n[0],p=n[1];n[0]=i,n[1]=r,e.transform(n,n);const g=n[0],f=n[1];n[0]=t,n[1]=r,e.transform(n,n);const u=n[0],c=n[1];this.aabb.min[0]=Math.min(l,d,g,u),this.aabb.max[0]=Math.max(l,d,g,u),this.aabb.min[1]=Math.min(h,p,f,c),this.aabb.max[1]=Math.max(h,p,f,c)}}getHitBoxesAround(e,t,i,o){return this.updateTransformation(),this._collisionTileMap?this._collisionTileMap.getHitboxesAround(this._hitBoxTag,e,t,i,o):[]}updateTransformation(){if(this._transformationIsUpToDate)return;const e=Math.abs(this._renderer.getScaleX()),t=Math.abs(this._renderer.getScaleY());this._tileMapToSceneTransformation.setToIdentity(),this._tileMapToSceneTransformation.translate(this.getX(),this.getY());const i=this.getAngle()*Math.PI/180;if(this._tileMapToSceneTransformation.rotateAround(i,this.getCenterX(),this.getCenterY()),this._tileMapToSceneTransformation.scale(e,t),this._collisionTileMap){const o=this._collisionTileMap.getTransformation();o.copyFrom(this._tileMapToSceneTransformation),this._collisionTileMap.setTransformation(o)}this._sceneToTileMapTransformation.copyFrom(this._tileMapToSceneTransformation),this._sceneToTileMapTransformation.invert(),this._transformationIsUpToDate=!0}getSceneXCoordinateOfTileCenter(e,t){const i=a.workingPoint;return this._tileMapToSceneTransformation.transform([(e+.5)*this._tileSize,(t+.5)*this._tileSize],i),i[0]}getSceneYCoordinateOfTileCenter(e,t){const i=a.workingPoint;return this._tileMapToSceneTransformation.transform([(e+.5)*this._tileSize,(t+.5)*this._tileSize],i),i[1]}getGridCoordinatesFromSceneCoordinates(e,t){this.updateTransformation();const i=a.workingPoint;this._sceneToTileMapTransformation.transform([e,t],i);const o=Math.floor(i[0]/this._tileSize),r=Math.floor(i[1]/this._tileSize);return[o,r]}getColumnIndexAtPosition(e,t){return this.getGridCoordinatesFromSceneCoordinates(e,t)[0]}getRowIndexAtPosition(e,t){return this.getGridCoordinatesFromSceneCoordinates(e,t)[1]}getTileAtPosition(e,t){const[i,o]=this.getGridCoordinatesFromSceneCoordinates(e,t);return this.getTileAtGridCoordinates(i,o)}getTileAtGridCoordinates(e,t){return this._renderer.getTileId(e,t,0)}setTileAtPosition(e,t,i){const[o,r]=this.getGridCoordinatesFromSceneCoordinates(t,i);this.setTileAtGridCoordinates(e,o,r)}setTileAtGridCoordinates(e,t,i){const o=this._renderer._tileMap;if(!o)return;const r=o.getTileLayer(this._layerIndex);if(!r)return;const n=r.getTileId(t,i);if(e!==n){if(r.setTile(t,i,e),this._collisionTileMap){const l=n!==void 0&&o.getTileDefinition(n),h=o.getTileDefinition(e),d=!!l&&l.hasFullHitBox(this._hitBoxTag),p=!!h&&h.hasFullHitBox(this._hitBoxTag);d!==p&&this._collisionTileMap.invalidateTile(this._layerIndex,t,i)}this._isTileMapDirty=!0,this.invalidateHitboxes()}}flipTileOnYAtPosition(e,t,i){const[o,r]=this.getGridCoordinatesFromSceneCoordinates(e,t);this.flipTileOnYAtGridCoordinates(o,r,i)}flipTileOnXAtPosition(e,t,i){const[o,r]=this.getGridCoordinatesFromSceneCoordinates(e,t);this.flipTileOnXAtGridCoordinates(o,r,i)}flipTileOnYAtGridCoordinates(e,t,i){this._renderer.flipTileOnY(e,t,0,i),this._isTileMapDirty=!0}flipTileOnXAtGridCoordinates(e,t,i){this._renderer.flipTileOnX(e,t,0,i),this._isTileMapDirty=!0}isTileFlippedOnXAtPosition(e,t){const[i,o]=this.getGridCoordinatesFromSceneCoordinates(e,t);return this._renderer.isTileFlippedOnX(i,o,0)}isTileFlippedOnXAtGridCoordinates(e,t){return this._renderer.isTileFlippedOnX(e,t,0)}isTileFlippedOnYAtPosition(e,t){const[i,o]=this.getGridCoordinatesFromSceneCoordinates(e,t);return this._renderer.isTileFlippedOnY(i,o,0)}isTileFlippedOnYAtGridCoordinates(e,t){return this._renderer.isTileFlippedOnY(e,t,0)}removeTileAtPosition(e,t){const[i,o]=this.getGridCoordinatesFromSceneCoordinates(e,t);this.removeTileAtGridCoordinates(i,o)}removeTileAtGridCoordinates(e,t){const i=this._renderer._tileMap;if(!i)return;const o=i.getTileLayer(this._layerIndex);!o||o.getTileId(e,t)===void 0||(o.removeTile(e,t),this._collisionTileMap&&this._collisionTileMap.invalidateTile(this._layerIndex,e,t),this._isTileMapDirty=!0,this.invalidateHitboxes())}setGridRowCount(e){e<=0||(this._renderer.setGridRowCount(e),this._isTileMapDirty=!0,this.invalidateHitboxes())}setGridColumnCount(e){e<=0||(this._renderer.setGridColumnCount(e),this._isTileMapDirty=!0,this.invalidateHitboxes())}getGridRowCount(){return this._renderer.getGridRowCount()}getGridColumnCount(){return this._renderer.getGridColumnCount()}getTilesetColumnCount(){return this._columnCount}getTilesetRowCount(){return this._rowCount}};let T=a;T.workingPoint=[0,0],s.SimpleTileMapRuntimeObject=T,s.registerObject("TileMap::SimpleTileMap",s.SimpleTileMapRuntimeObject)})(gdjs||(gdjs={}));
|
|
1
|
+
var gdjs;(function(s){const a=class extends s.RuntimeObject{constructor(e,t){super(e,t);this._opacity=255;this._displayMode="all";this._layerIndex=0;this._isTileMapDirty=!1;this._sceneToTileMapTransformation=new s.AffineTransformation;this._tileMapToSceneTransformation=new s.AffineTransformation;this._collisionTileMap=null;this._hitBoxTag="collision";this._transformationIsUpToDate=!1;this._opacity=t.content.opacity,this._atlasImage=t.content.atlasImage,this._rowCount=t.content.rowCount,this._columnCount=t.content.columnCount,this._tileSize=t.content.tileSize,this._initialTileMapAsJsObject={tileWidth:this._tileSize,tileHeight:this._tileSize,dimX:1,dimY:1,layers:[{id:0,alpha:this._opacity/255,tiles:[]}]},this._initialTilesWithHitBox=t.content.tilesWithHitBox.split(",").filter(i=>!!i).map(i=>parseInt(i,10)),this._tileMapManager=s.TileMap.TileMapRuntimeManager.getManager(e),this._renderer=new s.TileMapRuntimeObjectRenderer(this,e),this._loadInitialTileMap(i=>{this._renderer.updatePosition(),this._collisionTileMap=new s.TileMap.TransformedCollisionTileMap(i,this._hitBoxTag),this.updateTransformation()}),this.onCreated()}getRendererObject(){return this._renderer.getRendererObject()}updatePreRender(e){if(this._isTileMapDirty){let t=!0;if(this._tileMapManager.getOrLoadSimpleTileMapTextureCache(i=>this.getInstanceContainer().getGame().getImageManager().getPIXITexture(i),this._atlasImage,this._tileSize,this._columnCount,this._rowCount,i=>{!i||this._renderer.refreshPixiTileMap(i)},i=>{t=!1,console.error(`Could not load texture cache for atlas ${this._atlasImage} during prerender. The tilemap might be badly configured or an issues happened with the loaded atlas image:`,i)}),!t)return;if(this._collisionTileMap){const i=this._renderer.getTileMap();i&&this._collisionTileMap.updateFromTileMap(i)}this._isTileMapDirty=!1}}updateFromObjectData(e,t){return e.content.opacity!==t.content.opacity&&this.setOpacity(t.content.opacity),e.content.atlasImage===t.content.atlasImage}getNetworkSyncData(){return{...super.getNetworkSyncData(),op:this._opacity,ai:this._atlasImage,wid:this.getWidth(),hei:this.getHeight()}}updateFromNetworkSyncData(e){super.updateFromNetworkSyncData(e),e.op!==void 0&&e.op!==this._opacity&&this.setOpacity(e.op),e.wid!==void 0&&e.wid!==this.getWidth()&&this.setWidth(e.wid),e.hei!==void 0&&e.hei!==this.getHeight()&&this.setHeight(e.hei),e.ai!==void 0}extraInitializationFromInitialInstance(e){for(const t of e.stringProperties)t.name==="tilemap"&&(this._initialTileMapAsJsObject=JSON.parse(t.value));this._loadInitialTileMap(t=>{e.customSize&&(this.setWidth(e.width),this.setHeight(e.height)),e.opacity!==void 0&&this.setOpacity(e.opacity),this._renderer.updatePosition(),this._collisionTileMap?this._collisionTileMap.updateFromTileMap(t):this._collisionTileMap=new s.TileMap.TransformedCollisionTileMap(t,this._hitBoxTag),this.updateTransformation()})}_loadInitialTileMap(e){if(!!this._initialTileMapAsJsObject){if(this._columnCount<=0||this._rowCount<=0){console.error(`Tilemap object ${this.name} is not configured properly.`);return}this._tileMapManager.getOrLoadSimpleTileMap(this._initialTileMapAsJsObject,this.name,this._tileSize,this._columnCount,this._rowCount,t=>{this._initialTilesWithHitBox.forEach(i=>{const o=t.getTileDefinition(i);if(!o){console.warn(`Could not set hit box for tile with id ${i}. Continuing.`);return}o.addHitBox(this._hitBoxTag,[[0,0],[0,t.getTileHeight()],[t.getTileWidth(),t.getTileHeight()],[t.getTileWidth(),0]],!0)}),this._tileMapManager.getOrLoadSimpleTileMapTextureCache(i=>this.getInstanceContainer().getGame().getImageManager().getPIXITexture(i),this._atlasImage,this._tileSize,this._columnCount,this._rowCount,i=>{!i||(this._renderer.updatePixiTileMap(t,i),e(t))},i=>{console.error(`Could not load texture cache for atlas ${this._atlasImage} during initial loading. The tilemap might be badly configured or an issues happened with the loaded atlas image:`,i)})})}}onDestroyed(){super.onDestroyed(),this._renderer.destroy()}setWidth(e){this.getWidth()!==e&&(this._transformationIsUpToDate=!1,this._renderer.setWidth(e),this.invalidateHitboxes())}setHeight(e){this.getHeight()!==e&&(this._transformationIsUpToDate=!1,this._renderer.setHeight(e),this.invalidateHitboxes())}setSize(e,t){this.setWidth(e),this.setHeight(t),this._transformationIsUpToDate=!1}getScale(){const e=this.getScaleX(),t=this.getScaleY();return e===t?e:Math.sqrt(e*t)}setScale(e){this.setScaleX(e),this.setScaleY(e),this._transformationIsUpToDate=!1}setScaleX(e){e<0&&(e=0),this.getScaleX()!==e&&(this._renderer.setScaleX(e),this.invalidateHitboxes(),this._transformationIsUpToDate=!1)}setScaleY(e){e<0&&(e=0),this.getScaleY()!==e&&(this._renderer.setScaleY(e),this.invalidateHitboxes(),this._transformationIsUpToDate=!1)}setX(e){super.setX(e),this._renderer.updatePosition(),this._transformationIsUpToDate=!1}setY(e){super.setY(e),this._renderer.updatePosition(),this._transformationIsUpToDate=!1}setAngle(e){super.setAngle(e),this._renderer.updateAngle(),this._transformationIsUpToDate=!1}setOpacity(e){this._opacity=e,this._renderer.updateOpacity(),this._isTileMapDirty=!0}getOpacity(){return this._opacity}getWidth(){return this._renderer.getWidth()}getHeight(){return this._renderer.getHeight()}getScaleX(){return this._renderer.getScaleX()}getScaleY(){return this._renderer.getScaleY()}getHitBoxes(){return this.hitBoxesDirty&&(this.updateHitBoxes(),this.updateAABB(),this.hitBoxesDirty=!1),this.hitBoxes}updateHitBoxes(){this.updateTransformation(),!!this._collisionTileMap&&(this.hitBoxes=Array.from(this._collisionTileMap.getAllHitboxes(this._hitBoxTag)),this.hitBoxesDirty=!1,this.updateAABB())}updateAABB(){if(this.getAngle()===0)this.aabb.min[0]=this.x,this.aabb.min[1]=this.y,this.aabb.max[0]=this.aabb.min[0]+this.getWidth(),this.aabb.max[1]=this.aabb.min[1]+this.getHeight();else{if(!this._collisionTileMap)return;const e=this._collisionTileMap.getTransformation(),t=0,i=this._collisionTileMap.getWidth(),o=0,r=this._collisionTileMap.getHeight(),n=this.aabb.min;n[0]=t,n[1]=o,e.transform(n,n);const l=n[0],h=n[1];n[0]=i,n[1]=o,e.transform(n,n);const d=n[0],p=n[1];n[0]=i,n[1]=r,e.transform(n,n);const g=n[0],f=n[1];n[0]=t,n[1]=r,e.transform(n,n);const u=n[0],c=n[1];this.aabb.min[0]=Math.min(l,d,g,u),this.aabb.max[0]=Math.max(l,d,g,u),this.aabb.min[1]=Math.min(h,p,f,c),this.aabb.max[1]=Math.max(h,p,f,c)}}getHitBoxesAround(e,t,i,o){return this.updateTransformation(),this._collisionTileMap?this._collisionTileMap.getHitboxesAround(this._hitBoxTag,e,t,i,o):[]}updateTransformation(){if(this._transformationIsUpToDate)return;const e=Math.abs(this._renderer.getScaleX()),t=Math.abs(this._renderer.getScaleY());this._tileMapToSceneTransformation.setToIdentity(),this._tileMapToSceneTransformation.translate(this.getX(),this.getY());const i=this.getAngle()*Math.PI/180;if(this._tileMapToSceneTransformation.rotateAround(i,this.getCenterX(),this.getCenterY()),this._tileMapToSceneTransformation.scale(e,t),this._collisionTileMap){const o=this._collisionTileMap.getTransformation();o.copyFrom(this._tileMapToSceneTransformation),this._collisionTileMap.setTransformation(o)}this._sceneToTileMapTransformation.copyFrom(this._tileMapToSceneTransformation),this._sceneToTileMapTransformation.invert(),this._transformationIsUpToDate=!0}getSceneXCoordinateOfTileCenter(e,t){const i=a.workingPoint;return this._tileMapToSceneTransformation.transform([(e+.5)*this._tileSize,(t+.5)*this._tileSize],i),i[0]}getSceneYCoordinateOfTileCenter(e,t){const i=a.workingPoint;return this._tileMapToSceneTransformation.transform([(e+.5)*this._tileSize,(t+.5)*this._tileSize],i),i[1]}getGridCoordinatesFromSceneCoordinates(e,t){this.updateTransformation();const i=a.workingPoint;this._sceneToTileMapTransformation.transform([e,t],i);const o=Math.floor(i[0]/this._tileSize),r=Math.floor(i[1]/this._tileSize);return[o,r]}getColumnIndexAtPosition(e,t){return this.getGridCoordinatesFromSceneCoordinates(e,t)[0]}getRowIndexAtPosition(e,t){return this.getGridCoordinatesFromSceneCoordinates(e,t)[1]}getTileAtPosition(e,t){const[i,o]=this.getGridCoordinatesFromSceneCoordinates(e,t);return this.getTileAtGridCoordinates(i,o)}getTileAtGridCoordinates(e,t){return this._renderer.getTileId(e,t,0)}setTileAtPosition(e,t,i){const[o,r]=this.getGridCoordinatesFromSceneCoordinates(t,i);this.setTileAtGridCoordinates(e,o,r)}setTileAtGridCoordinates(e,t,i){const o=this._renderer._tileMap;if(!o)return;const r=o.getTileLayer(this._layerIndex);if(!r)return;const n=r.getTileId(t,i);if(e!==n){if(r.setTile(t,i,e),this._collisionTileMap){const l=n!==void 0&&o.getTileDefinition(n),h=o.getTileDefinition(e),d=!!l&&l.hasFullHitBox(this._hitBoxTag),p=!!h&&h.hasFullHitBox(this._hitBoxTag);d!==p&&this._collisionTileMap.invalidateTile(this._layerIndex,t,i)}this._isTileMapDirty=!0,this.invalidateHitboxes()}}flipTileOnYAtPosition(e,t,i){const[o,r]=this.getGridCoordinatesFromSceneCoordinates(e,t);this.flipTileOnYAtGridCoordinates(o,r,i)}flipTileOnXAtPosition(e,t,i){const[o,r]=this.getGridCoordinatesFromSceneCoordinates(e,t);this.flipTileOnXAtGridCoordinates(o,r,i)}flipTileOnYAtGridCoordinates(e,t,i){this._renderer.flipTileOnY(e,t,0,i),this._isTileMapDirty=!0}flipTileOnXAtGridCoordinates(e,t,i){this._renderer.flipTileOnX(e,t,0,i),this._isTileMapDirty=!0}isTileFlippedOnXAtPosition(e,t){const[i,o]=this.getGridCoordinatesFromSceneCoordinates(e,t);return this._renderer.isTileFlippedOnX(i,o,0)}isTileFlippedOnXAtGridCoordinates(e,t){return this._renderer.isTileFlippedOnX(e,t,0)}isTileFlippedOnYAtPosition(e,t){const[i,o]=this.getGridCoordinatesFromSceneCoordinates(e,t);return this._renderer.isTileFlippedOnY(i,o,0)}isTileFlippedOnYAtGridCoordinates(e,t){return this._renderer.isTileFlippedOnY(e,t,0)}removeTileAtPosition(e,t){const[i,o]=this.getGridCoordinatesFromSceneCoordinates(e,t);this.removeTileAtGridCoordinates(i,o)}removeTileAtGridCoordinates(e,t){const i=this._renderer._tileMap;if(!i)return;const o=i.getTileLayer(this._layerIndex);!o||o.getTileId(e,t)===void 0||(o.removeTile(e,t),this._collisionTileMap&&this._collisionTileMap.invalidateTile(this._layerIndex,e,t),this._isTileMapDirty=!0,this.invalidateHitboxes())}setGridRowCount(e){e<=0||(this._renderer.setGridRowCount(e),this._isTileMapDirty=!0,this.invalidateHitboxes())}setGridColumnCount(e){e<=0||(this._renderer.setGridColumnCount(e),this._isTileMapDirty=!0,this.invalidateHitboxes())}getGridRowCount(){return this._renderer.getGridRowCount()}getGridColumnCount(){return this._renderer.getGridColumnCount()}getTilesetColumnCount(){return this._columnCount}getTilesetRowCount(){return this._rowCount}};let T=a;T.workingPoint=[0,0],s.SimpleTileMapRuntimeObject=T,s.registerObject("TileMap::SimpleTileMap",s.SimpleTileMapRuntimeObject)})(gdjs||(gdjs={}));
|
|
2
2
|
//# sourceMappingURL=simpletilemapruntimeobject.js.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../GDevelop/Extensions/TileMap/simpletilemapruntimeobject.ts"],
|
|
4
|
-
"sourcesContent": ["/// <reference path=\"helper/TileMapHelper.d.ts\" />\nnamespace gdjs {\n export type SimpleTileMapObjectDataType = {\n content: {\n opacity: number;\n atlasImage: string;\n rowCount: number;\n columnCount: number;\n tileSize: number;\n tilesWithHitBox: string;\n };\n };\n\n export type SimpleTileMapObjectData = ObjectData &\n SimpleTileMapObjectDataType;\n\n export type SimpleTileMapNetworkSyncDataType = {\n op: number;\n ai: string;\n wid: number;\n hei: number;\n // TODO: Support tilemap synchronization. Find an efficient way to send tiles changes.\n };\n\n export type SimpleTileMapNetworkSyncData = ObjectNetworkSyncData &\n SimpleTileMapNetworkSyncDataType;\n\n /**\n * Displays a SimpleTileMap object.\n */\n export class SimpleTileMapRuntimeObject\n extends gdjs.RuntimeObject\n implements gdjs.Resizable, gdjs.Scalable, gdjs.OpacityHandler {\n /**\n * A reusable Point to avoid allocations.\n */\n private static readonly workingPoint: FloatPoint = [0, 0];\n\n _opacity: float;\n _atlasImage: string;\n _tileMapManager: gdjs.TileMap.TileMapRuntimeManager;\n _renderer: gdjs.TileMapRuntimeObjectPixiRenderer;\n readonly _rowCount: number;\n readonly _columnCount: number;\n readonly _tileSize: number;\n _displayMode = 'all';\n _layerIndex = 0;\n _initialTileMapAsJsObject: TileMapHelper.EditableTileMapAsJsObject | null = null;\n readonly _initialTilesWithHitBox: number[];\n _isTileMapDirty: boolean = false;\n _sceneToTileMapTransformation: gdjs.AffineTransformation = new gdjs.AffineTransformation();\n _tileMapToSceneTransformation: gdjs.AffineTransformation = new gdjs.AffineTransformation();\n _collisionTileMap: gdjs.TileMap.TransformedCollisionTileMap | null = null;\n _hitBoxTag: string = 'collision';\n private _transformationIsUpToDate: boolean = false;\n\n // TODO: Add a debug mode like for TileMapCollisionMaskRuntimeObject to draw?\n\n constructor(\n instanceContainer: gdjs.RuntimeInstanceContainer,\n objectData: SimpleTileMapObjectDataType\n ) {\n super(instanceContainer, objectData);\n this._opacity = objectData.content.opacity;\n this._atlasImage = objectData.content.atlasImage;\n this._rowCount = objectData.content.rowCount;\n this._columnCount = objectData.content.columnCount;\n this._tileSize = objectData.content.tileSize;\n this._initialTilesWithHitBox = (objectData.content\n .tilesWithHitBox as string)\n .split(',')\n .filter((id) => !!id)\n .map((idAsString) => parseInt(idAsString, 10));\n this._tileMapManager = gdjs.TileMap.TileMapRuntimeManager.getManager(\n instanceContainer\n );\n this._renderer = new gdjs.TileMapRuntimeObjectRenderer(\n this,\n instanceContainer\n );\n\n // *ALWAYS* call `this.onCreated()` at the very end of your object constructor.\n this.onCreated();\n }\n\n getRendererObject() {\n return this._renderer.getRendererObject();\n }\n\n updatePreRender(instanceContainer: gdjs.RuntimeInstanceContainer): void {\n if (this._isTileMapDirty) {\n let shouldContinue = true;\n this._tileMapManager.getOrLoadSimpleTileMapTextureCache(\n (textureName) => {\n return (this.getInstanceContainer()\n .getGame()\n .getImageManager()\n .getPIXITexture(textureName) as unknown) as PIXI.BaseTexture<\n PIXI.Resource\n >;\n },\n this._atlasImage,\n this._tileSize,\n this._columnCount,\n this._rowCount,\n (textureCache: TileMapHelper.TileTextureCache | null) => {\n if (!textureCache) {\n // getOrLoadTextureCache already log warns and errors.\n return;\n }\n this._renderer.refreshPixiTileMap(textureCache);\n },\n (error) => {\n shouldContinue = false;\n console.error(\n `Could not load texture cache for atlas ${this._atlasImage} during prerender. The tilemap might be badly configured or an issues happened with the loaded atlas image:`,\n error\n );\n }\n );\n if (!shouldContinue) return;\n if (this._collisionTileMap) {\n const tileMap = this._renderer.getTileMap();\n if (tileMap) this._collisionTileMap.updateFromTileMap(tileMap);\n }\n this._isTileMapDirty = false;\n }\n }\n\n updateFromObjectData(\n oldObjectData: SimpleTileMapObjectData,\n newObjectData: SimpleTileMapObjectData\n ): boolean {\n if (oldObjectData.content.opacity !== newObjectData.content.opacity) {\n this.setOpacity(newObjectData.content.opacity);\n }\n if (\n oldObjectData.content.atlasImage !== newObjectData.content.atlasImage\n ) {\n // TODO: support changing the atlas texture\n return false;\n }\n // Map content is updated at hot-reload by extraInitializationFromInitialInstance.\n return true;\n }\n\n getNetworkSyncData(): SimpleTileMapNetworkSyncData {\n return {\n ...super.getNetworkSyncData(),\n op: this._opacity,\n ai: this._atlasImage,\n wid: this.getWidth(),\n hei: this.getHeight(),\n };\n }\n\n updateFromNetworkSyncData(\n networkSyncData: SimpleTileMapNetworkSyncData\n ): void {\n super.updateFromNetworkSyncData(networkSyncData);\n\n if (\n networkSyncData.op !== undefined &&\n networkSyncData.op !== this._opacity\n ) {\n this.setOpacity(networkSyncData.op);\n }\n if (\n networkSyncData.wid !== undefined &&\n networkSyncData.wid !== this.getWidth()\n ) {\n this.setWidth(networkSyncData.wid);\n }\n if (\n networkSyncData.hei !== undefined &&\n networkSyncData.hei !== this.getHeight()\n ) {\n this.setHeight(networkSyncData.hei);\n }\n if (networkSyncData.ai !== undefined) {\n // TODO: support changing the atlas texture\n }\n }\n\n extraInitializationFromInitialInstance(\n initialInstanceData: InstanceData\n ): void {\n // 1. load the tilemap from the instance.\n for (const property of initialInstanceData.stringProperties) {\n if (property.name === 'tilemap') {\n this._initialTileMapAsJsObject = JSON.parse(property.value);\n }\n }\n\n // 2. Update the renderer so that it updates the tilemap object\n // (used for width and position calculations).\n this._loadInitialTileMap((tileMap: TileMapHelper.EditableTileMap) => {\n // 3. Set custom dimensions & opacity if applicable.\n if (initialInstanceData.customSize) {\n this.setWidth(initialInstanceData.width);\n this.setHeight(initialInstanceData.height);\n }\n if (initialInstanceData.opacity !== undefined) {\n this.setOpacity(initialInstanceData.opacity);\n }\n\n // 4. Update position (calculations based on renderer's dimensions).\n this._renderer.updatePosition();\n\n if (this._collisionTileMap) {\n // If collision tile map is already defined, there's a good chance it means\n // extraInitializationFromInitialInstance is called when hot reloading the\n // scene so the collision is tile map is updated instead of being re-created.\n this._collisionTileMap.updateFromTileMap(tileMap);\n } else {\n this._collisionTileMap = new gdjs.TileMap.TransformedCollisionTileMap(\n tileMap,\n this._hitBoxTag\n );\n }\n\n this.updateTransformation();\n });\n }\n\n private _loadInitialTileMap(\n tileMapLoadingCallback: (tileMap: TileMapHelper.EditableTileMap) => void\n ): void {\n if (!this._initialTileMapAsJsObject) return;\n if (this._columnCount <= 0 || this._rowCount <= 0) {\n console.error(\n `Tilemap object ${this.name} is not configured properly.`\n );\n return;\n }\n\n this._tileMapManager.getOrLoadSimpleTileMap(\n this._initialTileMapAsJsObject,\n this.name,\n this._tileSize,\n this._columnCount,\n this._rowCount,\n (tileMap: TileMapHelper.EditableTileMap) => {\n this._initialTilesWithHitBox.forEach((tileId) => {\n const tileDefinition = tileMap.getTileDefinition(tileId);\n if (!tileDefinition) {\n console.warn(\n `Could not set hit box for tile with id ${tileId}. Continuing.`\n );\n return;\n }\n tileDefinition.addHitBox(\n this._hitBoxTag,\n [\n [0, 0],\n [0, tileMap.getTileHeight()],\n [tileMap.getTileWidth(), tileMap.getTileHeight()],\n [tileMap.getTileWidth(), 0],\n ],\n true\n );\n });\n\n this._tileMapManager.getOrLoadSimpleTileMapTextureCache(\n (textureName) => {\n return (this.getInstanceContainer()\n .getGame()\n .getImageManager()\n .getPIXITexture(textureName) as unknown) as PIXI.BaseTexture<\n PIXI.Resource\n >;\n },\n this._atlasImage,\n this._tileSize,\n this._columnCount,\n this._rowCount,\n (textureCache: TileMapHelper.TileTextureCache | null) => {\n if (!textureCache) {\n // getOrLoadTextureCache already log warns and errors.\n return;\n }\n this._renderer.updatePixiTileMap(tileMap, textureCache);\n tileMapLoadingCallback(tileMap);\n },\n (error) => {\n console.error(\n `Could not load texture cache for atlas ${this._atlasImage} during initial loading. The tilemap might be badly configured or an issues happened with the loaded atlas image:`,\n error\n );\n }\n );\n }\n );\n }\n\n onDestroyed(): void {\n super.onDestroyed();\n this._renderer.destroy();\n }\n\n setWidth(width: float): void {\n if (this.getWidth() === width) return;\n\n this._transformationIsUpToDate = false;\n this._renderer.setWidth(width);\n this.invalidateHitboxes();\n }\n\n setHeight(height: float): void {\n if (this.getHeight() === height) return;\n\n this._transformationIsUpToDate = false;\n this._renderer.setHeight(height);\n this.invalidateHitboxes();\n }\n\n setSize(newWidth: float, newHeight: float): void {\n this.setWidth(newWidth);\n this.setHeight(newHeight);\n this._transformationIsUpToDate = false;\n }\n\n /**\n * Get the scale of the object (or the geometric mean of the X and Y scale in case they are different).\n *\n * @return the scale of the object (or the geometric mean of the X and Y scale in case they are different).\n */\n getScale(): float {\n const scaleX = this.getScaleX();\n const scaleY = this.getScaleY();\n return scaleX === scaleY ? scaleX : Math.sqrt(scaleX * scaleY);\n }\n\n /**\n * Change the scale on X and Y axis of the object.\n *\n * @param scale The new scale (must be greater than 0).\n */\n setScale(scale: float): void {\n this.setScaleX(scale);\n this.setScaleY(scale);\n this._transformationIsUpToDate = false;\n }\n\n /**\n * Change the scale on X axis of the object (changing its width).\n *\n * @param scaleX The new scale (must be greater than 0).\n */\n setScaleX(scaleX: float): void {\n if (scaleX < 0) {\n scaleX = 0;\n }\n if (this.getScaleX() === scaleX) return;\n\n this._renderer.setScaleX(scaleX);\n this.invalidateHitboxes();\n this._transformationIsUpToDate = false;\n }\n\n /**\n * Change the scale on Y axis of the object (changing its width).\n *\n * @param scaleY The new scale (must be greater than 0).\n */\n setScaleY(scaleY: float): void {\n if (scaleY < 0) {\n scaleY = 0;\n }\n if (this.getScaleY() === scaleY) return;\n\n this._renderer.setScaleY(scaleY);\n this.invalidateHitboxes();\n this._transformationIsUpToDate = false;\n }\n\n setX(x: float): void {\n super.setX(x);\n this._renderer.updatePosition();\n this._transformationIsUpToDate = false;\n }\n\n setY(y: float): void {\n super.setY(y);\n this._renderer.updatePosition();\n this._transformationIsUpToDate = false;\n }\n\n setAngle(angle: float): void {\n super.setAngle(angle);\n this._renderer.updateAngle();\n this._transformationIsUpToDate = false;\n }\n\n setOpacity(opacity: float): void {\n this._opacity = opacity;\n this._renderer.updateOpacity();\n this._isTileMapDirty = true;\n }\n\n getOpacity(): float {\n return this._opacity;\n }\n\n getWidth(): float {\n return this._renderer.getWidth();\n }\n\n getHeight(): float {\n return this._renderer.getHeight();\n }\n\n getScaleX(): float {\n return this._renderer.getScaleX();\n }\n\n getScaleY(): float {\n return this._renderer.getScaleY();\n }\n\n /**\n * This method is expensive and should not be called.\n * Prefer using {@link getHitBoxesAround} rather than getHitBoxes.\n */\n getHitBoxes(): gdjs.Polygon[] {\n if (this.hitBoxesDirty) {\n this.updateHitBoxes();\n this.updateAABB();\n this.hitBoxesDirty = false;\n }\n return this.hitBoxes;\n }\n\n updateHitBoxes(): void {\n this.updateTransformation();\n if (!this._collisionTileMap) return;\n this.hitBoxes = Array.from(\n this._collisionTileMap.getAllHitboxes(this._hitBoxTag)\n );\n this.hitBoxesDirty = false;\n this.updateAABB();\n }\n\n // This implementation doesn't use updateHitBoxes.\n // It's important for good performances.\n updateAABB(): void {\n if (this.getAngle() === 0) {\n // Fast computation of AABB for non rotated object\n this.aabb.min[0] = this.x;\n this.aabb.min[1] = this.y;\n this.aabb.max[0] = this.aabb.min[0] + this.getWidth();\n this.aabb.max[1] = this.aabb.min[1] + this.getHeight();\n } else {\n if (!this._collisionTileMap) return;\n const affineTransformation = this._collisionTileMap.getTransformation();\n\n const left = 0;\n const right = this._collisionTileMap.getWidth();\n const top = 0;\n const bottom = this._collisionTileMap.getHeight();\n\n const workingPoint = this.aabb.min;\n\n workingPoint[0] = left;\n workingPoint[1] = top;\n affineTransformation.transform(workingPoint, workingPoint);\n const topLeftX = workingPoint[0];\n const topLeftY = workingPoint[1];\n\n workingPoint[0] = right;\n workingPoint[1] = top;\n affineTransformation.transform(workingPoint, workingPoint);\n const topRightX = workingPoint[0];\n const topRightY = workingPoint[1];\n\n workingPoint[0] = right;\n workingPoint[1] = bottom;\n affineTransformation.transform(workingPoint, workingPoint);\n const bottomRightX = workingPoint[0];\n const bottomRightY = workingPoint[1];\n\n workingPoint[0] = left;\n workingPoint[1] = bottom;\n affineTransformation.transform(workingPoint, workingPoint);\n const bottomLeftX = workingPoint[0];\n const bottomLeftY = workingPoint[1];\n\n this.aabb.min[0] = Math.min(\n topLeftX,\n topRightX,\n bottomRightX,\n bottomLeftX\n );\n this.aabb.max[0] = Math.max(\n topLeftX,\n topRightX,\n bottomRightX,\n bottomLeftX\n );\n this.aabb.min[1] = Math.min(\n topLeftY,\n topRightY,\n bottomRightY,\n bottomLeftY\n );\n this.aabb.max[1] = Math.max(\n topLeftY,\n topRightY,\n bottomRightY,\n bottomLeftY\n );\n }\n }\n\n getHitBoxesAround(\n left: float,\n top: float,\n right: float,\n bottom: float\n ): Iterable<gdjs.Polygon> {\n // This implementation doesn't call updateHitBoxes.\n // It's important for good performances because there is no need to\n // update the whole collision mask where only a few hitboxes must be\n // checked.\n this.updateTransformation();\n if (!this._collisionTileMap) return [];\n return this._collisionTileMap.getHitboxesAround(\n this._hitBoxTag,\n left,\n top,\n right,\n bottom\n );\n }\n\n updateTransformation() {\n if (this._transformationIsUpToDate) {\n return;\n }\n const absScaleX = Math.abs(this._renderer.getScaleX());\n const absScaleY = Math.abs(this._renderer.getScaleY());\n\n this._tileMapToSceneTransformation.setToIdentity();\n\n // Translation\n this._tileMapToSceneTransformation.translate(this.getX(), this.getY());\n\n // Rotation\n const angleInRadians = (this.getAngle() * Math.PI) / 180;\n this._tileMapToSceneTransformation.rotateAround(\n angleInRadians,\n this.getCenterX(),\n this.getCenterY()\n );\n\n // Scale\n this._tileMapToSceneTransformation.scale(absScaleX, absScaleY);\n if (this._collisionTileMap) {\n const collisionTileMapTransformation = this._collisionTileMap.getTransformation();\n collisionTileMapTransformation.copyFrom(\n this._tileMapToSceneTransformation\n );\n this._collisionTileMap.setTransformation(\n collisionTileMapTransformation\n );\n }\n this._sceneToTileMapTransformation.copyFrom(\n this._tileMapToSceneTransformation\n );\n this._sceneToTileMapTransformation.invert();\n this._transformationIsUpToDate = true;\n }\n\n getSceneXCoordinateOfTileCenter(\n columnIndex: integer,\n rowIndex: integer\n ): float {\n const sceneCoordinates: FloatPoint =\n SimpleTileMapRuntimeObject.workingPoint;\n this._tileMapToSceneTransformation.transform(\n [\n (columnIndex + 0.5) * this._tileSize,\n (rowIndex + 0.5) * this._tileSize,\n ],\n sceneCoordinates\n );\n return sceneCoordinates[0];\n }\n\n getSceneYCoordinateOfTileCenter(\n columnIndex: integer,\n rowIndex: integer\n ): float {\n const sceneCoordinates: FloatPoint =\n SimpleTileMapRuntimeObject.workingPoint;\n this._tileMapToSceneTransformation.transform(\n [\n (columnIndex + 0.5) * this._tileSize,\n (rowIndex + 0.5) * this._tileSize,\n ],\n sceneCoordinates\n );\n return sceneCoordinates[1];\n }\n\n getGridCoordinatesFromSceneCoordinates(\n x: float,\n y: float\n ): [integer, integer] {\n this.updateTransformation();\n\n const gridCoordinates: FloatPoint =\n SimpleTileMapRuntimeObject.workingPoint;\n this._sceneToTileMapTransformation.transform([x, y], gridCoordinates);\n\n const columnIndex = Math.floor(gridCoordinates[0] / this._tileSize);\n const rowIndex = Math.floor(gridCoordinates[1] / this._tileSize);\n\n return [columnIndex, rowIndex];\n }\n\n getColumnIndexAtPosition(x: float, y: float): integer {\n return this.getGridCoordinatesFromSceneCoordinates(x, y)[0];\n }\n\n getRowIndexAtPosition(x: float, y: float): integer {\n return this.getGridCoordinatesFromSceneCoordinates(x, y)[1];\n }\n\n getTileAtPosition(x: float, y: float): integer {\n const [\n columnIndex,\n rowIndex,\n ] = this.getGridCoordinatesFromSceneCoordinates(x, y);\n return this.getTileAtGridCoordinates(columnIndex, rowIndex);\n }\n\n getTileAtGridCoordinates(columnIndex: integer, rowIndex: integer): integer {\n return this._renderer.getTileId(columnIndex, rowIndex, 0);\n }\n\n setTileAtPosition(tileId: number, x: float, y: float) {\n const [\n columnIndex,\n rowIndex,\n ] = this.getGridCoordinatesFromSceneCoordinates(x, y);\n this.setTileAtGridCoordinates(tileId, columnIndex, rowIndex);\n }\n\n setTileAtGridCoordinates(\n tileId: number,\n columnIndex: integer,\n rowIndex: integer\n ) {\n const tileMap = this._renderer._tileMap;\n if (!tileMap) {\n return;\n }\n const layer = tileMap.getTileLayer(this._layerIndex);\n if (!layer) {\n return;\n }\n const oldTileId = layer.getTileId(columnIndex, rowIndex);\n if (tileId === oldTileId) {\n return;\n }\n layer.setTile(columnIndex, rowIndex, tileId);\n\n if (this._collisionTileMap) {\n const oldTileDefinition =\n oldTileId !== undefined && tileMap.getTileDefinition(oldTileId);\n const newTileDefinition = tileMap.getTileDefinition(tileId);\n const hadFullHitBox =\n !!oldTileDefinition &&\n oldTileDefinition.hasFullHitBox(this._hitBoxTag);\n const haveFullHitBox =\n !!newTileDefinition &&\n newTileDefinition.hasFullHitBox(this._hitBoxTag);\n if (hadFullHitBox !== haveFullHitBox) {\n this._collisionTileMap.invalidateTile(\n this._layerIndex,\n columnIndex,\n rowIndex\n );\n }\n }\n this._isTileMapDirty = true;\n this.invalidateHitboxes();\n }\n\n flipTileOnYAtPosition(x: float, y: float, flip: boolean) {\n const [\n columnIndex,\n rowIndex,\n ] = this.getGridCoordinatesFromSceneCoordinates(x, y);\n this.flipTileOnYAtGridCoordinates(columnIndex, rowIndex, flip);\n }\n\n flipTileOnXAtPosition(x: float, y: float, flip: boolean) {\n const [\n columnIndex,\n rowIndex,\n ] = this.getGridCoordinatesFromSceneCoordinates(x, y);\n this.flipTileOnXAtGridCoordinates(columnIndex, rowIndex, flip);\n }\n\n flipTileOnYAtGridCoordinates(\n columnIndex: integer,\n rowIndex: integer,\n flip: boolean\n ) {\n this._renderer.flipTileOnY(columnIndex, rowIndex, 0, flip);\n this._isTileMapDirty = true;\n // No need to invalidate hit boxes since at the moment, collision mask\n // cannot be configured on each tile.\n }\n\n flipTileOnXAtGridCoordinates(\n columnIndex: integer,\n rowIndex: integer,\n flip: boolean\n ) {\n this._renderer.flipTileOnX(columnIndex, rowIndex, 0, flip);\n this._isTileMapDirty = true;\n // No need to invalidate hit boxes since at the moment, collision mask\n // cannot be configured on each tile.\n }\n\n isTileFlippedOnXAtPosition(x: float, y: float) {\n const [\n columnIndex,\n rowIndex,\n ] = this.getGridCoordinatesFromSceneCoordinates(x, y);\n\n return this._renderer.isTileFlippedOnX(columnIndex, rowIndex, 0);\n }\n\n isTileFlippedOnXAtGridCoordinates(columnIndex: integer, rowIndex: integer) {\n return this._renderer.isTileFlippedOnX(columnIndex, rowIndex, 0);\n }\n\n isTileFlippedOnYAtPosition(x: float, y: float) {\n const [\n columnIndex,\n rowIndex,\n ] = this.getGridCoordinatesFromSceneCoordinates(x, y);\n\n return this._renderer.isTileFlippedOnY(columnIndex, rowIndex, 0);\n }\n\n isTileFlippedOnYAtGridCoordinates(columnIndex: integer, rowIndex: integer) {\n return this._renderer.isTileFlippedOnY(columnIndex, rowIndex, 0);\n }\n\n removeTileAtPosition(x: float, y: float) {\n const [\n columnIndex,\n rowIndex,\n ] = this.getGridCoordinatesFromSceneCoordinates(x, y);\n this.removeTileAtGridCoordinates(columnIndex, rowIndex);\n }\n\n removeTileAtGridCoordinates(columnIndex: integer, rowIndex: integer) {\n const tileMap = this._renderer._tileMap;\n if (!tileMap) {\n return;\n }\n const layer = tileMap.getTileLayer(this._layerIndex);\n if (!layer) {\n return;\n }\n const oldTileId = layer.getTileId(columnIndex, rowIndex);\n if (oldTileId === undefined) {\n return;\n }\n layer.removeTile(columnIndex, rowIndex);\n if (this._collisionTileMap) {\n this._collisionTileMap.invalidateTile(\n this._layerIndex,\n columnIndex,\n rowIndex\n );\n }\n this._isTileMapDirty = true;\n this.invalidateHitboxes();\n }\n\n setGridRowCount(targetRowCount: integer) {\n if (targetRowCount <= 0) return;\n this._renderer.setGridRowCount(targetRowCount);\n this._isTileMapDirty = true;\n this.invalidateHitboxes();\n }\n\n setGridColumnCount(targetColumnCount: integer) {\n if (targetColumnCount <= 0) return;\n this._renderer.setGridColumnCount(targetColumnCount);\n this._isTileMapDirty = true;\n this.invalidateHitboxes();\n }\n\n getGridRowCount(): integer {\n return this._renderer.getGridRowCount();\n }\n\n getGridColumnCount(): integer {\n return this._renderer.getGridColumnCount();\n }\n\n getTilesetColumnCount(): integer {\n return this._columnCount;\n }\n\n getTilesetRowCount(): integer {\n return this._rowCount;\n }\n }\n gdjs.registerObject(\n 'TileMap::SimpleTileMap',\n gdjs.SimpleTileMapRuntimeObject\n );\n}\n"],
|
|
5
|
-
"mappings": "AACA,GAAU,MAAV,UAAU,EAAV,CA6BS,qBACG,GAAK,aACiD,CA0B9D,YACE,EACA,EACA,CACA,MAAM,EAAmB,
|
|
4
|
+
"sourcesContent": ["/// <reference path=\"helper/TileMapHelper.d.ts\" />\nnamespace gdjs {\n export type SimpleTileMapObjectDataType = {\n content: {\n opacity: number;\n atlasImage: string;\n rowCount: number;\n columnCount: number;\n tileSize: number;\n tilesWithHitBox: string;\n };\n };\n\n export type SimpleTileMapObjectData = ObjectData &\n SimpleTileMapObjectDataType;\n\n export type SimpleTileMapNetworkSyncDataType = {\n op: number;\n ai: string;\n wid: number;\n hei: number;\n // TODO: Support tilemap synchronization. Find an efficient way to send tiles changes.\n };\n\n export type SimpleTileMapNetworkSyncData = ObjectNetworkSyncData &\n SimpleTileMapNetworkSyncDataType;\n\n /**\n * Displays a SimpleTileMap object.\n */\n export class SimpleTileMapRuntimeObject\n extends gdjs.RuntimeObject\n implements gdjs.Resizable, gdjs.Scalable, gdjs.OpacityHandler {\n /**\n * A reusable Point to avoid allocations.\n */\n private static readonly workingPoint: FloatPoint = [0, 0];\n\n _opacity: float = 255;\n _atlasImage: string;\n _tileMapManager: gdjs.TileMap.TileMapRuntimeManager;\n _renderer: gdjs.TileMapRuntimeObjectPixiRenderer;\n readonly _rowCount: number;\n readonly _columnCount: number;\n readonly _tileSize: number;\n _displayMode = 'all';\n _layerIndex = 0;\n _initialTileMapAsJsObject: TileMapHelper.EditableTileMapAsJsObject;\n readonly _initialTilesWithHitBox: number[];\n _isTileMapDirty: boolean = false;\n _sceneToTileMapTransformation: gdjs.AffineTransformation = new gdjs.AffineTransformation();\n _tileMapToSceneTransformation: gdjs.AffineTransformation = new gdjs.AffineTransformation();\n _collisionTileMap: gdjs.TileMap.TransformedCollisionTileMap | null = null;\n _hitBoxTag: string = 'collision';\n private _transformationIsUpToDate: boolean = false;\n\n // TODO: Add a debug mode like for TileMapCollisionMaskRuntimeObject to draw?\n\n constructor(\n instanceContainer: gdjs.RuntimeInstanceContainer,\n objectData: SimpleTileMapObjectDataType\n ) {\n super(instanceContainer, objectData);\n this._opacity = objectData.content.opacity;\n this._atlasImage = objectData.content.atlasImage;\n this._rowCount = objectData.content.rowCount;\n this._columnCount = objectData.content.columnCount;\n this._tileSize = objectData.content.tileSize;\n this._initialTileMapAsJsObject = {\n tileWidth: this._tileSize,\n tileHeight: this._tileSize,\n dimX: 1,\n dimY: 1,\n layers: [{ id: 0, alpha: this._opacity / 255, tiles: [] }],\n };\n this._initialTilesWithHitBox = (objectData.content\n .tilesWithHitBox as string)\n .split(',')\n .filter((id) => !!id)\n .map((idAsString) => parseInt(idAsString, 10));\n this._tileMapManager = gdjs.TileMap.TileMapRuntimeManager.getManager(\n instanceContainer\n );\n this._renderer = new gdjs.TileMapRuntimeObjectRenderer(\n this,\n instanceContainer\n );\n\n this._loadInitialTileMap((tileMap: TileMapHelper.EditableTileMap) => {\n this._renderer.updatePosition();\n\n this._collisionTileMap = new gdjs.TileMap.TransformedCollisionTileMap(\n tileMap,\n this._hitBoxTag\n );\n\n this.updateTransformation();\n });\n\n // *ALWAYS* call `this.onCreated()` at the very end of your object constructor.\n this.onCreated();\n }\n\n getRendererObject() {\n return this._renderer.getRendererObject();\n }\n\n updatePreRender(instanceContainer: gdjs.RuntimeInstanceContainer): void {\n if (this._isTileMapDirty) {\n let shouldContinue = true;\n this._tileMapManager.getOrLoadSimpleTileMapTextureCache(\n (textureName) => {\n return (this.getInstanceContainer()\n .getGame()\n .getImageManager()\n .getPIXITexture(textureName) as unknown) as PIXI.BaseTexture<\n PIXI.Resource\n >;\n },\n this._atlasImage,\n this._tileSize,\n this._columnCount,\n this._rowCount,\n (textureCache: TileMapHelper.TileTextureCache | null) => {\n if (!textureCache) {\n // getOrLoadTextureCache already log warns and errors.\n return;\n }\n this._renderer.refreshPixiTileMap(textureCache);\n },\n (error) => {\n shouldContinue = false;\n console.error(\n `Could not load texture cache for atlas ${this._atlasImage} during prerender. The tilemap might be badly configured or an issues happened with the loaded atlas image:`,\n error\n );\n }\n );\n if (!shouldContinue) return;\n if (this._collisionTileMap) {\n const tileMap = this._renderer.getTileMap();\n if (tileMap) this._collisionTileMap.updateFromTileMap(tileMap);\n }\n this._isTileMapDirty = false;\n }\n }\n\n updateFromObjectData(\n oldObjectData: SimpleTileMapObjectData,\n newObjectData: SimpleTileMapObjectData\n ): boolean {\n if (oldObjectData.content.opacity !== newObjectData.content.opacity) {\n this.setOpacity(newObjectData.content.opacity);\n }\n if (\n oldObjectData.content.atlasImage !== newObjectData.content.atlasImage\n ) {\n // TODO: support changing the atlas texture\n return false;\n }\n // Map content is updated at hot-reload by extraInitializationFromInitialInstance.\n return true;\n }\n\n getNetworkSyncData(): SimpleTileMapNetworkSyncData {\n return {\n ...super.getNetworkSyncData(),\n op: this._opacity,\n ai: this._atlasImage,\n wid: this.getWidth(),\n hei: this.getHeight(),\n };\n }\n\n updateFromNetworkSyncData(\n networkSyncData: SimpleTileMapNetworkSyncData\n ): void {\n super.updateFromNetworkSyncData(networkSyncData);\n\n if (\n networkSyncData.op !== undefined &&\n networkSyncData.op !== this._opacity\n ) {\n this.setOpacity(networkSyncData.op);\n }\n if (\n networkSyncData.wid !== undefined &&\n networkSyncData.wid !== this.getWidth()\n ) {\n this.setWidth(networkSyncData.wid);\n }\n if (\n networkSyncData.hei !== undefined &&\n networkSyncData.hei !== this.getHeight()\n ) {\n this.setHeight(networkSyncData.hei);\n }\n if (networkSyncData.ai !== undefined) {\n // TODO: support changing the atlas texture\n }\n }\n\n extraInitializationFromInitialInstance(\n initialInstanceData: InstanceData\n ): void {\n // 1. load the tilemap from the instance.\n for (const property of initialInstanceData.stringProperties) {\n if (property.name === 'tilemap') {\n this._initialTileMapAsJsObject = JSON.parse(property.value);\n }\n }\n\n // 2. Update the renderer so that it updates the tilemap object\n // (used for width and position calculations).\n this._loadInitialTileMap((tileMap: TileMapHelper.EditableTileMap) => {\n // 3. Set custom dimensions & opacity if applicable.\n if (initialInstanceData.customSize) {\n this.setWidth(initialInstanceData.width);\n this.setHeight(initialInstanceData.height);\n }\n if (initialInstanceData.opacity !== undefined) {\n this.setOpacity(initialInstanceData.opacity);\n }\n\n // 4. Update position (calculations based on renderer's dimensions).\n this._renderer.updatePosition();\n\n if (this._collisionTileMap) {\n // If collision tile map is already defined, there's a good chance it means\n // extraInitializationFromInitialInstance is called when hot reloading the\n // scene so the collision is tile map is updated instead of being re-created.\n this._collisionTileMap.updateFromTileMap(tileMap);\n } else {\n this._collisionTileMap = new gdjs.TileMap.TransformedCollisionTileMap(\n tileMap,\n this._hitBoxTag\n );\n }\n\n this.updateTransformation();\n });\n }\n\n private _loadInitialTileMap(\n tileMapLoadingCallback: (tileMap: TileMapHelper.EditableTileMap) => void\n ): void {\n if (!this._initialTileMapAsJsObject) return;\n if (this._columnCount <= 0 || this._rowCount <= 0) {\n console.error(\n `Tilemap object ${this.name} is not configured properly.`\n );\n return;\n }\n\n this._tileMapManager.getOrLoadSimpleTileMap(\n this._initialTileMapAsJsObject,\n this.name,\n this._tileSize,\n this._columnCount,\n this._rowCount,\n (tileMap: TileMapHelper.EditableTileMap) => {\n this._initialTilesWithHitBox.forEach((tileId) => {\n const tileDefinition = tileMap.getTileDefinition(tileId);\n if (!tileDefinition) {\n console.warn(\n `Could not set hit box for tile with id ${tileId}. Continuing.`\n );\n return;\n }\n tileDefinition.addHitBox(\n this._hitBoxTag,\n [\n [0, 0],\n [0, tileMap.getTileHeight()],\n [tileMap.getTileWidth(), tileMap.getTileHeight()],\n [tileMap.getTileWidth(), 0],\n ],\n true\n );\n });\n\n this._tileMapManager.getOrLoadSimpleTileMapTextureCache(\n (textureName) => {\n return (this.getInstanceContainer()\n .getGame()\n .getImageManager()\n .getPIXITexture(textureName) as unknown) as PIXI.BaseTexture<\n PIXI.Resource\n >;\n },\n this._atlasImage,\n this._tileSize,\n this._columnCount,\n this._rowCount,\n (textureCache: TileMapHelper.TileTextureCache | null) => {\n if (!textureCache) {\n // getOrLoadTextureCache already log warns and errors.\n return;\n }\n this._renderer.updatePixiTileMap(tileMap, textureCache);\n tileMapLoadingCallback(tileMap);\n },\n (error) => {\n console.error(\n `Could not load texture cache for atlas ${this._atlasImage} during initial loading. The tilemap might be badly configured or an issues happened with the loaded atlas image:`,\n error\n );\n }\n );\n }\n );\n }\n\n onDestroyed(): void {\n super.onDestroyed();\n this._renderer.destroy();\n }\n\n setWidth(width: float): void {\n if (this.getWidth() === width) return;\n\n this._transformationIsUpToDate = false;\n this._renderer.setWidth(width);\n this.invalidateHitboxes();\n }\n\n setHeight(height: float): void {\n if (this.getHeight() === height) return;\n\n this._transformationIsUpToDate = false;\n this._renderer.setHeight(height);\n this.invalidateHitboxes();\n }\n\n setSize(newWidth: float, newHeight: float): void {\n this.setWidth(newWidth);\n this.setHeight(newHeight);\n this._transformationIsUpToDate = false;\n }\n\n /**\n * Get the scale of the object (or the geometric mean of the X and Y scale in case they are different).\n *\n * @return the scale of the object (or the geometric mean of the X and Y scale in case they are different).\n */\n getScale(): float {\n const scaleX = this.getScaleX();\n const scaleY = this.getScaleY();\n return scaleX === scaleY ? scaleX : Math.sqrt(scaleX * scaleY);\n }\n\n /**\n * Change the scale on X and Y axis of the object.\n *\n * @param scale The new scale (must be greater than 0).\n */\n setScale(scale: float): void {\n this.setScaleX(scale);\n this.setScaleY(scale);\n this._transformationIsUpToDate = false;\n }\n\n /**\n * Change the scale on X axis of the object (changing its width).\n *\n * @param scaleX The new scale (must be greater than 0).\n */\n setScaleX(scaleX: float): void {\n if (scaleX < 0) {\n scaleX = 0;\n }\n if (this.getScaleX() === scaleX) return;\n\n this._renderer.setScaleX(scaleX);\n this.invalidateHitboxes();\n this._transformationIsUpToDate = false;\n }\n\n /**\n * Change the scale on Y axis of the object (changing its width).\n *\n * @param scaleY The new scale (must be greater than 0).\n */\n setScaleY(scaleY: float): void {\n if (scaleY < 0) {\n scaleY = 0;\n }\n if (this.getScaleY() === scaleY) return;\n\n this._renderer.setScaleY(scaleY);\n this.invalidateHitboxes();\n this._transformationIsUpToDate = false;\n }\n\n setX(x: float): void {\n super.setX(x);\n this._renderer.updatePosition();\n this._transformationIsUpToDate = false;\n }\n\n setY(y: float): void {\n super.setY(y);\n this._renderer.updatePosition();\n this._transformationIsUpToDate = false;\n }\n\n setAngle(angle: float): void {\n super.setAngle(angle);\n this._renderer.updateAngle();\n this._transformationIsUpToDate = false;\n }\n\n setOpacity(opacity: float): void {\n this._opacity = opacity;\n this._renderer.updateOpacity();\n this._isTileMapDirty = true;\n }\n\n getOpacity(): float {\n return this._opacity;\n }\n\n getWidth(): float {\n return this._renderer.getWidth();\n }\n\n getHeight(): float {\n return this._renderer.getHeight();\n }\n\n getScaleX(): float {\n return this._renderer.getScaleX();\n }\n\n getScaleY(): float {\n return this._renderer.getScaleY();\n }\n\n /**\n * This method is expensive and should not be called.\n * Prefer using {@link getHitBoxesAround} rather than getHitBoxes.\n */\n getHitBoxes(): gdjs.Polygon[] {\n if (this.hitBoxesDirty) {\n this.updateHitBoxes();\n this.updateAABB();\n this.hitBoxesDirty = false;\n }\n return this.hitBoxes;\n }\n\n updateHitBoxes(): void {\n this.updateTransformation();\n if (!this._collisionTileMap) return;\n this.hitBoxes = Array.from(\n this._collisionTileMap.getAllHitboxes(this._hitBoxTag)\n );\n this.hitBoxesDirty = false;\n this.updateAABB();\n }\n\n // This implementation doesn't use updateHitBoxes.\n // It's important for good performances.\n updateAABB(): void {\n if (this.getAngle() === 0) {\n // Fast computation of AABB for non rotated object\n this.aabb.min[0] = this.x;\n this.aabb.min[1] = this.y;\n this.aabb.max[0] = this.aabb.min[0] + this.getWidth();\n this.aabb.max[1] = this.aabb.min[1] + this.getHeight();\n } else {\n if (!this._collisionTileMap) return;\n const affineTransformation = this._collisionTileMap.getTransformation();\n\n const left = 0;\n const right = this._collisionTileMap.getWidth();\n const top = 0;\n const bottom = this._collisionTileMap.getHeight();\n\n const workingPoint = this.aabb.min;\n\n workingPoint[0] = left;\n workingPoint[1] = top;\n affineTransformation.transform(workingPoint, workingPoint);\n const topLeftX = workingPoint[0];\n const topLeftY = workingPoint[1];\n\n workingPoint[0] = right;\n workingPoint[1] = top;\n affineTransformation.transform(workingPoint, workingPoint);\n const topRightX = workingPoint[0];\n const topRightY = workingPoint[1];\n\n workingPoint[0] = right;\n workingPoint[1] = bottom;\n affineTransformation.transform(workingPoint, workingPoint);\n const bottomRightX = workingPoint[0];\n const bottomRightY = workingPoint[1];\n\n workingPoint[0] = left;\n workingPoint[1] = bottom;\n affineTransformation.transform(workingPoint, workingPoint);\n const bottomLeftX = workingPoint[0];\n const bottomLeftY = workingPoint[1];\n\n this.aabb.min[0] = Math.min(\n topLeftX,\n topRightX,\n bottomRightX,\n bottomLeftX\n );\n this.aabb.max[0] = Math.max(\n topLeftX,\n topRightX,\n bottomRightX,\n bottomLeftX\n );\n this.aabb.min[1] = Math.min(\n topLeftY,\n topRightY,\n bottomRightY,\n bottomLeftY\n );\n this.aabb.max[1] = Math.max(\n topLeftY,\n topRightY,\n bottomRightY,\n bottomLeftY\n );\n }\n }\n\n getHitBoxesAround(\n left: float,\n top: float,\n right: float,\n bottom: float\n ): Iterable<gdjs.Polygon> {\n // This implementation doesn't call updateHitBoxes.\n // It's important for good performances because there is no need to\n // update the whole collision mask where only a few hitboxes must be\n // checked.\n this.updateTransformation();\n if (!this._collisionTileMap) return [];\n return this._collisionTileMap.getHitboxesAround(\n this._hitBoxTag,\n left,\n top,\n right,\n bottom\n );\n }\n\n updateTransformation() {\n if (this._transformationIsUpToDate) {\n return;\n }\n const absScaleX = Math.abs(this._renderer.getScaleX());\n const absScaleY = Math.abs(this._renderer.getScaleY());\n\n this._tileMapToSceneTransformation.setToIdentity();\n\n // Translation\n this._tileMapToSceneTransformation.translate(this.getX(), this.getY());\n\n // Rotation\n const angleInRadians = (this.getAngle() * Math.PI) / 180;\n this._tileMapToSceneTransformation.rotateAround(\n angleInRadians,\n this.getCenterX(),\n this.getCenterY()\n );\n\n // Scale\n this._tileMapToSceneTransformation.scale(absScaleX, absScaleY);\n if (this._collisionTileMap) {\n const collisionTileMapTransformation = this._collisionTileMap.getTransformation();\n collisionTileMapTransformation.copyFrom(\n this._tileMapToSceneTransformation\n );\n this._collisionTileMap.setTransformation(\n collisionTileMapTransformation\n );\n }\n this._sceneToTileMapTransformation.copyFrom(\n this._tileMapToSceneTransformation\n );\n this._sceneToTileMapTransformation.invert();\n this._transformationIsUpToDate = true;\n }\n\n getSceneXCoordinateOfTileCenter(\n columnIndex: integer,\n rowIndex: integer\n ): float {\n const sceneCoordinates: FloatPoint =\n SimpleTileMapRuntimeObject.workingPoint;\n this._tileMapToSceneTransformation.transform(\n [\n (columnIndex + 0.5) * this._tileSize,\n (rowIndex + 0.5) * this._tileSize,\n ],\n sceneCoordinates\n );\n return sceneCoordinates[0];\n }\n\n getSceneYCoordinateOfTileCenter(\n columnIndex: integer,\n rowIndex: integer\n ): float {\n const sceneCoordinates: FloatPoint =\n SimpleTileMapRuntimeObject.workingPoint;\n this._tileMapToSceneTransformation.transform(\n [\n (columnIndex + 0.5) * this._tileSize,\n (rowIndex + 0.5) * this._tileSize,\n ],\n sceneCoordinates\n );\n return sceneCoordinates[1];\n }\n\n getGridCoordinatesFromSceneCoordinates(\n x: float,\n y: float\n ): [integer, integer] {\n this.updateTransformation();\n\n const gridCoordinates: FloatPoint =\n SimpleTileMapRuntimeObject.workingPoint;\n this._sceneToTileMapTransformation.transform([x, y], gridCoordinates);\n\n const columnIndex = Math.floor(gridCoordinates[0] / this._tileSize);\n const rowIndex = Math.floor(gridCoordinates[1] / this._tileSize);\n\n return [columnIndex, rowIndex];\n }\n\n getColumnIndexAtPosition(x: float, y: float): integer {\n return this.getGridCoordinatesFromSceneCoordinates(x, y)[0];\n }\n\n getRowIndexAtPosition(x: float, y: float): integer {\n return this.getGridCoordinatesFromSceneCoordinates(x, y)[1];\n }\n\n getTileAtPosition(x: float, y: float): integer {\n const [\n columnIndex,\n rowIndex,\n ] = this.getGridCoordinatesFromSceneCoordinates(x, y);\n return this.getTileAtGridCoordinates(columnIndex, rowIndex);\n }\n\n getTileAtGridCoordinates(columnIndex: integer, rowIndex: integer): integer {\n return this._renderer.getTileId(columnIndex, rowIndex, 0);\n }\n\n setTileAtPosition(tileId: number, x: float, y: float) {\n const [\n columnIndex,\n rowIndex,\n ] = this.getGridCoordinatesFromSceneCoordinates(x, y);\n this.setTileAtGridCoordinates(tileId, columnIndex, rowIndex);\n }\n\n setTileAtGridCoordinates(\n tileId: number,\n columnIndex: integer,\n rowIndex: integer\n ) {\n const tileMap = this._renderer._tileMap;\n if (!tileMap) {\n return;\n }\n const layer = tileMap.getTileLayer(this._layerIndex);\n if (!layer) {\n return;\n }\n const oldTileId = layer.getTileId(columnIndex, rowIndex);\n if (tileId === oldTileId) {\n return;\n }\n layer.setTile(columnIndex, rowIndex, tileId);\n\n if (this._collisionTileMap) {\n const oldTileDefinition =\n oldTileId !== undefined && tileMap.getTileDefinition(oldTileId);\n const newTileDefinition = tileMap.getTileDefinition(tileId);\n const hadFullHitBox =\n !!oldTileDefinition &&\n oldTileDefinition.hasFullHitBox(this._hitBoxTag);\n const haveFullHitBox =\n !!newTileDefinition &&\n newTileDefinition.hasFullHitBox(this._hitBoxTag);\n if (hadFullHitBox !== haveFullHitBox) {\n this._collisionTileMap.invalidateTile(\n this._layerIndex,\n columnIndex,\n rowIndex\n );\n }\n }\n this._isTileMapDirty = true;\n this.invalidateHitboxes();\n }\n\n flipTileOnYAtPosition(x: float, y: float, flip: boolean) {\n const [\n columnIndex,\n rowIndex,\n ] = this.getGridCoordinatesFromSceneCoordinates(x, y);\n this.flipTileOnYAtGridCoordinates(columnIndex, rowIndex, flip);\n }\n\n flipTileOnXAtPosition(x: float, y: float, flip: boolean) {\n const [\n columnIndex,\n rowIndex,\n ] = this.getGridCoordinatesFromSceneCoordinates(x, y);\n this.flipTileOnXAtGridCoordinates(columnIndex, rowIndex, flip);\n }\n\n flipTileOnYAtGridCoordinates(\n columnIndex: integer,\n rowIndex: integer,\n flip: boolean\n ) {\n this._renderer.flipTileOnY(columnIndex, rowIndex, 0, flip);\n this._isTileMapDirty = true;\n // No need to invalidate hit boxes since at the moment, collision mask\n // cannot be configured on each tile.\n }\n\n flipTileOnXAtGridCoordinates(\n columnIndex: integer,\n rowIndex: integer,\n flip: boolean\n ) {\n this._renderer.flipTileOnX(columnIndex, rowIndex, 0, flip);\n this._isTileMapDirty = true;\n // No need to invalidate hit boxes since at the moment, collision mask\n // cannot be configured on each tile.\n }\n\n isTileFlippedOnXAtPosition(x: float, y: float) {\n const [\n columnIndex,\n rowIndex,\n ] = this.getGridCoordinatesFromSceneCoordinates(x, y);\n\n return this._renderer.isTileFlippedOnX(columnIndex, rowIndex, 0);\n }\n\n isTileFlippedOnXAtGridCoordinates(columnIndex: integer, rowIndex: integer) {\n return this._renderer.isTileFlippedOnX(columnIndex, rowIndex, 0);\n }\n\n isTileFlippedOnYAtPosition(x: float, y: float) {\n const [\n columnIndex,\n rowIndex,\n ] = this.getGridCoordinatesFromSceneCoordinates(x, y);\n\n return this._renderer.isTileFlippedOnY(columnIndex, rowIndex, 0);\n }\n\n isTileFlippedOnYAtGridCoordinates(columnIndex: integer, rowIndex: integer) {\n return this._renderer.isTileFlippedOnY(columnIndex, rowIndex, 0);\n }\n\n removeTileAtPosition(x: float, y: float) {\n const [\n columnIndex,\n rowIndex,\n ] = this.getGridCoordinatesFromSceneCoordinates(x, y);\n this.removeTileAtGridCoordinates(columnIndex, rowIndex);\n }\n\n removeTileAtGridCoordinates(columnIndex: integer, rowIndex: integer) {\n const tileMap = this._renderer._tileMap;\n if (!tileMap) {\n return;\n }\n const layer = tileMap.getTileLayer(this._layerIndex);\n if (!layer) {\n return;\n }\n const oldTileId = layer.getTileId(columnIndex, rowIndex);\n if (oldTileId === undefined) {\n return;\n }\n layer.removeTile(columnIndex, rowIndex);\n if (this._collisionTileMap) {\n this._collisionTileMap.invalidateTile(\n this._layerIndex,\n columnIndex,\n rowIndex\n );\n }\n this._isTileMapDirty = true;\n this.invalidateHitboxes();\n }\n\n setGridRowCount(targetRowCount: integer) {\n if (targetRowCount <= 0) return;\n this._renderer.setGridRowCount(targetRowCount);\n this._isTileMapDirty = true;\n this.invalidateHitboxes();\n }\n\n setGridColumnCount(targetColumnCount: integer) {\n if (targetColumnCount <= 0) return;\n this._renderer.setGridColumnCount(targetColumnCount);\n this._isTileMapDirty = true;\n this.invalidateHitboxes();\n }\n\n getGridRowCount(): integer {\n return this._renderer.getGridRowCount();\n }\n\n getGridColumnCount(): integer {\n return this._renderer.getGridColumnCount();\n }\n\n getTilesetColumnCount(): integer {\n return this._columnCount;\n }\n\n getTilesetRowCount(): integer {\n return this._rowCount;\n }\n }\n gdjs.registerObject(\n 'TileMap::SimpleTileMap',\n gdjs.SimpleTileMapRuntimeObject\n );\n}\n"],
|
|
5
|
+
"mappings": "AACA,GAAU,MAAV,UAAU,EAAV,CA6BS,qBACG,GAAK,aACiD,CA0B9D,YACE,EACA,EACA,CACA,MAAM,EAAmB,GAxB3B,cAAkB,IAOlB,kBAAe,MACf,iBAAc,EAGd,qBAA2B,GAC3B,mCAA2D,GAAI,GAAK,qBACpE,mCAA2D,GAAI,GAAK,qBACpE,uBAAqE,KACrE,gBAAqB,YACb,+BAAqC,GAS3C,KAAK,SAAW,EAAW,QAAQ,QACnC,KAAK,YAAc,EAAW,QAAQ,WACtC,KAAK,UAAY,EAAW,QAAQ,SACpC,KAAK,aAAe,EAAW,QAAQ,YACvC,KAAK,UAAY,EAAW,QAAQ,SACpC,KAAK,0BAA4B,CAC/B,UAAW,KAAK,UAChB,WAAY,KAAK,UACjB,KAAM,EACN,KAAM,EACN,OAAQ,CAAC,CAAE,GAAI,EAAG,MAAO,KAAK,SAAW,IAAK,MAAO,MAEvD,KAAK,wBAA2B,EAAW,QACxC,gBACA,MAAM,KACN,OAAO,AAAC,GAAO,CAAC,CAAC,GACjB,IAAI,AAAC,GAAe,SAAS,EAAY,KAC5C,KAAK,gBAAkB,EAAK,QAAQ,sBAAsB,WACxD,GAEF,KAAK,UAAY,GAAI,GAAK,6BACxB,KACA,GAGF,KAAK,oBAAoB,AAAC,GAA2C,CACnE,KAAK,UAAU,iBAEf,KAAK,kBAAoB,GAAI,GAAK,QAAQ,4BACxC,EACA,KAAK,YAGP,KAAK,yBAIP,KAAK,YAGP,mBAAoB,CAClB,MAAO,MAAK,UAAU,oBAGxB,gBAAgB,EAAwD,CACtE,GAAI,KAAK,gBAAiB,CACxB,GAAI,GAAiB,GA6BrB,GA5BA,KAAK,gBAAgB,mCACnB,AAAC,GACS,KAAK,uBAC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,EAAU,GAGhE,kCAAkC,EAAsB,EAAmB,CACzE,MAAO,MAAK,UAAU,iBAAiB,EAAa,EAAU,GAGhE,qBAAqB,EAAU,EAAU,CACvC,KAAM,CACJ,EACA,GACE,KAAK,uCAAuC,EAAG,GACnD,KAAK,4BAA4B,EAAa,GAGhD,4BAA4B,EAAsB,EAAmB,CACnE,KAAM,GAAU,KAAK,UAAU,SAC/B,GAAI,CAAC,EACH,OAEF,KAAM,GAAQ,EAAQ,aAAa,KAAK,aAKxC,AAJI,CAAC,GAID,AADc,EAAM,UAAU,EAAa,KAC7B,QAGlB,GAAM,WAAW,EAAa,GAC1B,KAAK,mBACP,KAAK,kBAAkB,eACrB,KAAK,YACL,EACA,GAGJ,KAAK,gBAAkB,GACvB,KAAK,sBAGP,gBAAgB,EAAyB,CACvC,AAAI,GAAkB,GACtB,MAAK,UAAU,gBAAgB,GAC/B,KAAK,gBAAkB,GACvB,KAAK,sBAGP,mBAAmB,EAA4B,CAC7C,AAAI,GAAqB,GACzB,MAAK,UAAU,mBAAmB,GAClC,KAAK,gBAAkB,GACvB,KAAK,sBAGP,iBAA2B,CACzB,MAAO,MAAK,UAAU,kBAGxB,oBAA8B,CAC5B,MAAO,MAAK,UAAU,qBAGxB,uBAAiC,CAC/B,MAAO,MAAK,aAGd,oBAA8B,CAC5B,MAAO,MAAK,YAlyBT,QAMmB,AANnB,EAMmB,aAA2B,CAAC,EAAG,GANlD,EAAM,6BAqyBb,EAAK,eACH,yBACA,EAAK,8BAp0BC",
|
|
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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gBAAgB,gBAC1B,KAAK,iBACL,KACA,GASJ,UAAU,EAAuB,CAC/B,MAAO,MAAK,gBAAgB,UAAU,KAAK,iBAAkB,GAQ/D,aAAa,EAAwB,CACnC,AAAI,GAAa,GACf,MAAK,WAAa,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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C9B,EAAI,EAAW,EAAM,EAAW,EAChC,EAAO,GAAK,EAAI,KAAK,WAAW,GAChC,EAAO,GAAK,EAAI,KAAK,WAAW,GAEzB,EAcT,qBACE,EACA,EACA,EAAoB,EACpB,EACY,CAIZ,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 u=new l.Logger("PIXI game renderer"),f=[37,38,39,40];class R{constructor(t,e){this._isFullPage=!0;this._isFullscreen=!1;this._pixiRenderer=null;this._threeRenderer=null;this._gameCanvas=null;this._domElementsContainer=null;this._canvasWidth=0;this._canvasHeight=0;this._keepRatio=!0;this._nextFrameId=0;this._wasDisposed=!1;this.getElectronRemote=()=>{if(typeof require=="function"){const t=this._game.getAdditionalOptions(),e=t&&t.electronRemoteRequirePath?t.electronRemoteRequirePath:"@electron/remote";try{return require(e)}catch(i){console.error(`Could not load @electron/remote from "${e}". Error is:`,i)}}return null};this._game=t,this._forceFullscreen=e,this._marginLeft=this._marginTop=this._marginRight=this._marginBottom=0,this._setupOrientation()}createStandardCanvas(t){this._throwIfDisposed();let e;typeof THREE!="undefined"?(e=document.createElement("canvas"),this._threeRenderer=new THREE.WebGLRenderer({canvas:e,antialias:this._game.getAntialiasingMode()!=="none"&&(this._game.isAntialisingEnabledOnMobile()||!l.evtTools.common.isMobile()),preserveDrawingBuffer:!0}),this._threeRenderer.useLegacyLights=!0,this._threeRenderer.autoClear=!1,this._threeRenderer.setSize(this._game.getGameResolutionWidth(),this._game.getGameResolutionHeight()),this._pixiRenderer=new PIXI.Renderer({width:this._game.getGameResolutionWidth(),height:this._game.getGameResolutionHeight(),view:e,context:this._threeRenderer.getContext(),clearBeforeRender:!1,preserveDrawingBuffer:!0,antialias:!1,backgroundAlpha:0}),e=this._threeRenderer.domElement):(this._pixiRenderer=PIXI.autoDetectRenderer({width:this._game.getGameResolutionWidth(),height:this._game.getGameResolutionHeight(),preserveDrawingBuffer:!0,antialias:!1}),e=this._pixiRenderer.view),this._pixiRenderer.plugins.accessibility.destroy(),delete this._pixiRenderer.plugins.accessibility,t.appendChild(e),this._gameCanvas=e,e.style.position="absolute",e.tabIndex=1,e.style.userSelect="none",e.style.outline="none";const i=document.createElement("div");i.style.position="absolute",i.style.overflow="hidden",i.style.outline="none",i.style.pointerEvents="none",i.addEventListener("scroll",s=>{i.scrollLeft=0,i.scrollTop=0,s.preventDefault()}),e.addEventListener("pointerdown",()=>{e.focus()}),i.style["-webkit-user-select"]="none",t.appendChild(i),this._domElementsContainer=i,this._resizeCanvas(),this._game.getScaleMode()==="nearest"&&(e.style["image-rendering"]="-moz-crisp-edges",e.style["image-rendering"]="-webkit-optimize-contrast",e.style["image-rendering"]="-webkit-crisp-edges",e.style["image-rendering"]="pixelated"),this._game.getPixelsRounding()&&(PIXI.settings.ROUND_PIXELS=!0),window.addEventListener("resize",()=>{this._game.onWindowInnerSizeChanged(),this._resizeCanvas()}),e.focus()}static getWindowInnerWidth(){return typeof window!="undefined"?window.innerWidth:800}static getWindowInnerHeight(){return typeof window!="undefined"?window.innerHeight:800}updateRendererSize(){this._resizeCanvas()}_setupOrientation(){if(typeof window=="undefined"||!window.screen||!window.screen.orientation)return;const t=this._game.getGameData().properties.orientation;try{if(t==="default"){const e=window.screen.orientation.unlock();e&&e.catch(()=>{})}else window.screen.orientation.lock(t).catch(()=>{})}catch(e){u.error("Unexpected error while setting up orientation: ",e)}}_resizeCanvas(){if(!this._pixiRenderer||!this._domElementsContainer)return;(this._pixiRenderer.width!==this._game.getGameResolutionWidth()||this._pixiRenderer.height!==this._game.getGameResolutionHeight())&&(this._pixiRenderer.resize(this._game.getGameResolutionWidth(),this._game.getGameResolutionHeight()),this._threeRenderer&&this._threeRenderer.setSize(this._game.getGameResolutionWidth(),this._game.getGameResolutionHeight()));const t=this._forceFullscreen||this._isFullPage||this._isFullscreen;let e=this._game.getGameResolutionWidth(),i=this._game.getGameResolutionHeight(),s=window.innerWidth-this._marginLeft-this._marginRight,r=window.innerHeight-this._marginTop-this._marginBottom;if(s<0&&(s=0),r<0&&(r=0),t&&!this._keepRatio)e=s,i=r;else if(t&&this._keepRatio||e>s||i>r){let d=s/e;i*d>r&&(d=r/i),e*=d,i*=d}this._gameCanvas&&(this._gameCanvas.style.top=this._marginTop+(r-i)/2+"px",this._gameCanvas.style.left=this._marginLeft+(s-e)/2+"px",this._gameCanvas.style.width=e+"px",this._gameCanvas.style.height=i+"px"),this._domElementsContainer.style.top=this._marginTop+(r-i)/2+"px",this._domElementsContainer.style.left=this._marginLeft+(s-e)/2+"px",this._domElementsContainer.style.width=e+"px",this._domElementsContainer.style.height=i+"px",this._canvasWidth=e,this._canvasHeight=i}keepAspectRatio(t){this._keepRatio!==t&&(this._keepRatio=t,this._resizeCanvas())}setMargins(t,e,i,s){this._throwIfDisposed(),!(this._marginTop===t&&this._marginRight===e&&this._marginBottom===i&&this._marginLeft===s)&&(this._marginTop=t,this._marginRight=e,this._marginBottom=i,this._marginLeft=s,this._resizeCanvas())}setWindowSize(t,e){this._throwIfDisposed();const i=this.getElectronRemote();if(i){const s=i.getCurrentWindow();try{s&&s.setContentSize(t,e)}catch(r){u.error(`Window size setting to width ${t} and height ${e} failed. See error:`,r)}}else u.warn("Window size can't be changed on this platform.")}centerWindow(){this._throwIfDisposed();const t=this.getElectronRemote();if(t){const e=t.getCurrentWindow();try{e&&e.center()}catch(i){u.error("Window centering failed. See error:",i)}}else u.warn("Window can't be centered on this platform.")}setFullScreen(t){if(this._throwIfDisposed(),!this._forceFullscreen&&this._isFullscreen!==t){this._isFullscreen=!!t;const e=this.getElectronRemote();if(e){const i=e.getCurrentWindow();try{i&&i.setFullScreen(this._isFullscreen)}catch(s){u.error(`Full screen setting to ${this._isFullscreen} failed. See error:`,s)}}else this._isFullscreen?document.documentElement.requestFullscreen?document.documentElement.requestFullscreen():document.documentElement.mozRequestFullScreen?document.documentElement.mozRequestFullScreen():document.documentElement.webkitRequestFullScreen&&document.documentElement.webkitRequestFullScreen():document.exitFullscreen?document.exitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitCancelFullScreen&&document.webkitCancelFullScreen();this._resizeCanvas()}}isFullScreen(){const t=this.getElectronRemote();if(t)try{return t.getCurrentWindow().isFullScreen()}catch(e){return u.error("Full screen detection failed. See error:",e),!1}return this._isFullscreen||window.screen.height===window.innerHeight}convertCanvasToDomElementContainerCoords(t,e){const i=e||[0,0];return i[0]=t[0]*this._canvasWidth/this._game.getGameResolutionWidth(),i[1]=t[1]*this._canvasHeight/this._game.getGameResolutionHeight(),i}getCanvasToDomElementContainerHeightScale(){return(this._canvasHeight||1)/this._game.getGameResolutionHeight()}bindStandardEvents(t,e,i){this._throwIfDisposed();const s=this._gameCanvas;if(!s)return;const r=n=>{const o=[n.pageX-s.offsetLeft,n.pageY-s.offsetTop];return o[0]*=this._game.getGameResolutionWidth()/(this._canvasWidth||1),o[1]*=this._game.getGameResolutionHeight()/(this._canvasHeight||1),o},d=n=>{const o=n.pageX-s.offsetLeft,a=n.pageY-s.offsetTop;return 0<=o&&o<(this._canvasWidth||1)&&0<=a&&a<(this._canvasHeight||1)};(function(){isNaN(s.offsetLeft)&&(s.offsetLeft=0,s.offsetTop=0),isNaN(i.body.scrollLeft)&&(i.body.scrollLeft=0,i.body.scrollTop=0),(i.documentElement===void 0||i.documentElement===null)&&(i.documentElement={}),isNaN(i.documentElement.scrollLeft)&&(i.documentElement.scrollLeft=0,i.documentElement.scrollTop=0),isNaN(s.offsetLeft)&&(s.offsetLeft=0,s.offsetTop=0)})();const m=()=>!(i.activeElement===s||i.activeElement===i.body||i.activeElement===null),h=n=>!(n.target===s||n.target===i.body);i.onkeydown=function(n){m()||(f.includes(n.keyCode)&&n.preventDefault(),t.onKeyPressed(n.keyCode,n.location))},i.onkeyup=function(n){m()||(f.includes(n.keyCode)&&n.preventDefault(),t.onKeyReleased(n.keyCode,n.location))};function g(n){switch(n){case 1:return l.InputManager.MOUSE_MIDDLE_BUTTON;case 2:return l.InputManager.MOUSE_RIGHT_BUTTON}return n}s.onmousemove=function(n){const o=r(n);t.onMouseMove(o[0],o[1])},s.onmousedown=function(n){return t.onMouseButtonPressed(g(n.button)),e.focus!==void 0&&e.focus(),!1},s.onmouseup=function(n){return t.onMouseButtonReleased(g(n.button)),!1},s.onmouseleave=function(n){t.onMouseLeave()},s.onmouseenter=function(n){t.onMouseEnter();const o=[l.InputManager.MOUSE_LEFT_BUTTON,l.InputManager.MOUSE_RIGHT_BUTTON,l.InputManager.MOUSE_MIDDLE_BUTTON,l.InputManager.MOUSE_BACK_BUTTON,l.InputManager.MOUSE_FORWARD_BUTTON];for(let a=0,v=o.length;a<v;++a){const c=o[a],p=(n.buttons&1<<a)!=0,_=t.isMouseButtonPressed(c);p&&!_?t.onMouseButtonPressed(c):!p&&_&&t.onMouseButtonReleased(c)}},e.addEventListener("click",function(n){return e.focus!==void 0&&e.focus(),!1},!1),s.oncontextmenu=function(n){return n.preventDefault(),n.stopPropagation(),!1},s.onwheel=function(n){t.onMouseWheel(-n.deltaY)},e.addEventListener("touchmove",function(n){if(!h(n)&&(n.preventDefault(),n.changedTouches))for(let o=0;o<n.changedTouches.length;++o){const a=r(n.changedTouches[o]);t.onTouchMove(n.changedTouches[o].identifier,a[0],a[1]),t.isSimulatingMouseWithTouch()&&(d(n.changedTouches[o])?t.onMouseEnter():t.onMouseLeave())}},{passive:!1}),e.addEventListener("touchstart",function(n){if(!h(n)){if(n.preventDefault(),n.changedTouches)for(let o=0;o<n.changedTouches.length;++o){const a=r(n.changedTouches[o]);t.onTouchStart(n.changedTouches[o].identifier,a[0],a[1])}return!1}},{passive:!1}),e.addEventListener("touchend",function(n){if(!h(n)){if(n.preventDefault(),n.changedTouches)for(let o=0;o<n.changedTouches.length;++o)t.onTouchEnd(n.changedTouches[o].identifier);return!1}},{passive:!1}),e.addEventListener("touchcancel",function(n){if(!h(n)){if(n.preventDefault(),n.changedTouches)for(let o=0;o<n.changedTouches.length;++o)t.onTouchCancel(n.changedTouches[o].identifier);return!1}},{passive:!1})}setWindowTitle(t){typeof document!="undefined"&&(document.title=t)}getWindowTitle(){return typeof document!="undefined"?document.title:""}startGameLoop(t){this._throwIfDisposed();let e=0;const i=s=>{this._nextFrameId=requestAnimationFrame(i);const r=e?s-e:0;e=s,t(r)||cancelAnimationFrame(this._nextFrameId)};requestAnimationFrame(i)}stopGameLoop(){cancelAnimationFrame(this._nextFrameId)}getPIXIRenderer(){return this._pixiRenderer}getThreeRenderer(){return this._threeRenderer}getDomElementContainer(){return this._domElementsContainer}openURL(t){if(typeof window!="undefined"){const e=this.getElectron();e?e.shell.openExternal(t):typeof window.cordova!="undefined"&&typeof window.cordova.InAppBrowser!="undefined"?window.cordova.InAppBrowser.open(t,"_system","location=yes"):window.open(t,"_blank")}}stopGame(){const t=this.getElectronRemote();if(t){const e=t.getCurrentWindow();if(e)try{e.close()}catch(i){u.error("Window closing failed. See error:",i)}}else typeof navigator!="undefined"&&navigator.app&&navigator.app.exitApp&&navigator.app.exitApp()}dispose(){this._pixiRenderer?.destroy(!0),this._threeRenderer?.dispose(),this._pixiRenderer=null,this._threeRenderer=null,this._gameCanvas=null,this._domElementsContainer=null,this._wasDisposed=!0}getCanvas(){return this._gameCanvas}isWebGLSupported(){return!!this._pixiRenderer&&this._pixiRenderer.type===PIXI.RENDERER_TYPE.WEBGL}getElectron(){return typeof require=="function"?require("electron"):null}getGame(){return this._game}_throwIfDisposed(){if(this._wasDisposed)throw"The RuntimeGameRenderer has been disposed and should not be used anymore."}}l.RuntimeGamePixiRenderer=R,l.RuntimeGameRenderer=R})(gdjs||(gdjs={}));
|
|
1
|
+
var gdjs;(function(l){const u=new l.Logger("PIXI game renderer"),f=[37,38,39,40];class R{constructor(e,t){this._isFullPage=!0;this._isFullscreen=!1;this._pixiRenderer=null;this._threeRenderer=null;this._gameCanvas=null;this._domElementsContainer=null;this._canvasWidth=0;this._canvasHeight=0;this._keepRatio=!0;this._nextFrameId=0;this._wasDisposed=!1;this.getElectronRemote=()=>{if(typeof require=="function"){const e=this._game.getAdditionalOptions(),t=e&&e.electronRemoteRequirePath?e.electronRemoteRequirePath:"@electron/remote";try{return require(t)}catch(i){console.error(`Could not load @electron/remote from "${t}". Error is:`,i)}}return null};this._game=e,this._forceFullscreen=t,this._marginLeft=this._marginTop=this._marginRight=this._marginBottom=0,this._setupOrientation()}createStandardCanvas(e){this._throwIfDisposed();const t=document.createElement("canvas");e.appendChild(t),this.initializeForCanvas(t)}initializeForCanvas(e){this._throwIfDisposed(),typeof THREE!="undefined"?(this._threeRenderer=new THREE.WebGLRenderer({canvas:e,antialias:this._game.getAntialiasingMode()!=="none"&&(this._game.isAntialisingEnabledOnMobile()||!l.evtTools.common.isMobile()),preserveDrawingBuffer:!0}),this._threeRenderer.useLegacyLights=!0,this._threeRenderer.autoClear=!1,this._threeRenderer.setSize(this._game.getGameResolutionWidth(),this._game.getGameResolutionHeight()),this._pixiRenderer=new PIXI.Renderer({width:this._game.getGameResolutionWidth(),height:this._game.getGameResolutionHeight(),view:e,context:this._threeRenderer.getContext(),clearBeforeRender:!1,preserveDrawingBuffer:!0,antialias:!1,backgroundAlpha:0})):this._pixiRenderer=PIXI.autoDetectRenderer({width:this._game.getGameResolutionWidth(),height:this._game.getGameResolutionHeight(),view:e,preserveDrawingBuffer:!0,antialias:!1}),this._pixiRenderer.plugins.accessibility.destroy(),delete this._pixiRenderer.plugins.accessibility,this._gameCanvas=e,e.style.position="absolute",e.tabIndex=1,e.style.userSelect="none",e.style.outline="none";const t=document.createElement("div");t.style.position="absolute",t.style.overflow="hidden",t.style.outline="none",t.style.pointerEvents="none",t.addEventListener("scroll",i=>{t.scrollLeft=0,t.scrollTop=0,i.preventDefault()}),e.addEventListener("pointerdown",()=>{e.focus()}),t.style["-webkit-user-select"]="none",e.parentNode?.appendChild(t),this._domElementsContainer=t,this._resizeCanvas(),this._game.getScaleMode()==="nearest"&&(e.style["image-rendering"]="-moz-crisp-edges",e.style["image-rendering"]="-webkit-optimize-contrast",e.style["image-rendering"]="-webkit-crisp-edges",e.style["image-rendering"]="pixelated"),this._game.getPixelsRounding()&&(PIXI.settings.ROUND_PIXELS=!0),window.addEventListener("resize",()=>{this._game.onWindowInnerSizeChanged(),this._resizeCanvas()}),e.focus()}static getWindowInnerWidth(){return typeof window!="undefined"?window.innerWidth:800}static getWindowInnerHeight(){return typeof window!="undefined"?window.innerHeight:800}updateRendererSize(){this._resizeCanvas()}_setupOrientation(){if(typeof window=="undefined"||!window.screen||!window.screen.orientation)return;const e=this._game.getGameData().properties.orientation;try{if(e==="default"){const t=window.screen.orientation.unlock();t&&t.catch(()=>{})}else window.screen.orientation.lock(e).catch(()=>{})}catch(t){u.error("Unexpected error while setting up orientation: ",t)}}_resizeCanvas(){if(!this._pixiRenderer||!this._domElementsContainer)return;(this._pixiRenderer.width!==this._game.getGameResolutionWidth()||this._pixiRenderer.height!==this._game.getGameResolutionHeight())&&(this._pixiRenderer.resize(this._game.getGameResolutionWidth(),this._game.getGameResolutionHeight()),this._threeRenderer&&this._threeRenderer.setSize(this._game.getGameResolutionWidth(),this._game.getGameResolutionHeight()));const e=this._forceFullscreen||this._isFullPage||this._isFullscreen;let t=this._game.getGameResolutionWidth(),i=this._game.getGameResolutionHeight(),o=window.innerWidth-this._marginLeft-this._marginRight,r=window.innerHeight-this._marginTop-this._marginBottom;if(o<0&&(o=0),r<0&&(r=0),e&&!this._keepRatio)t=o,i=r;else if(e&&this._keepRatio||t>o||i>r){let d=o/t;i*d>r&&(d=r/i),t*=d,i*=d}this._gameCanvas&&(this._gameCanvas.style.top=this._marginTop+(r-i)/2+"px",this._gameCanvas.style.left=this._marginLeft+(o-t)/2+"px",this._gameCanvas.style.width=t+"px",this._gameCanvas.style.height=i+"px"),this._domElementsContainer.style.top=this._marginTop+(r-i)/2+"px",this._domElementsContainer.style.left=this._marginLeft+(o-t)/2+"px",this._domElementsContainer.style.width=t+"px",this._domElementsContainer.style.height=i+"px",this._canvasWidth=t,this._canvasHeight=i}keepAspectRatio(e){this._keepRatio!==e&&(this._keepRatio=e,this._resizeCanvas())}setMargins(e,t,i,o){this._throwIfDisposed(),!(this._marginTop===e&&this._marginRight===t&&this._marginBottom===i&&this._marginLeft===o)&&(this._marginTop=e,this._marginRight=t,this._marginBottom=i,this._marginLeft=o,this._resizeCanvas())}setWindowSize(e,t){this._throwIfDisposed();const i=this.getElectronRemote();if(i){const o=i.getCurrentWindow();try{o&&o.setContentSize(e,t)}catch(r){u.error(`Window size setting to width ${e} and height ${t} failed. See error:`,r)}}else u.warn("Window size can't be changed on this platform.")}centerWindow(){this._throwIfDisposed();const e=this.getElectronRemote();if(e){const t=e.getCurrentWindow();try{t&&t.center()}catch(i){u.error("Window centering failed. See error:",i)}}else u.warn("Window can't be centered on this platform.")}setFullScreen(e){if(this._throwIfDisposed(),!this._forceFullscreen&&this._isFullscreen!==e){this._isFullscreen=!!e;const t=this.getElectronRemote();if(t){const i=t.getCurrentWindow();try{i&&i.setFullScreen(this._isFullscreen)}catch(o){u.error(`Full screen setting to ${this._isFullscreen} failed. See error:`,o)}}else this._isFullscreen?document.documentElement.requestFullscreen?document.documentElement.requestFullscreen():document.documentElement.mozRequestFullScreen?document.documentElement.mozRequestFullScreen():document.documentElement.webkitRequestFullScreen&&document.documentElement.webkitRequestFullScreen():document.exitFullscreen?document.exitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitCancelFullScreen&&document.webkitCancelFullScreen();this._resizeCanvas()}}isFullScreen(){const e=this.getElectronRemote();if(e)try{return e.getCurrentWindow().isFullScreen()}catch(t){return u.error("Full screen detection failed. See error:",t),!1}return this._isFullscreen||window.screen.height===window.innerHeight}convertCanvasToDomElementContainerCoords(e,t){const i=t||[0,0];return i[0]=e[0]*this._canvasWidth/this._game.getGameResolutionWidth(),i[1]=e[1]*this._canvasHeight/this._game.getGameResolutionHeight(),i}getCanvasToDomElementContainerHeightScale(){return(this._canvasHeight||1)/this._game.getGameResolutionHeight()}bindStandardEvents(e,t,i){this._throwIfDisposed();const o=this._gameCanvas;if(!o)return;const r=n=>{const s=[n.pageX-o.offsetLeft,n.pageY-o.offsetTop];return s[0]*=this._game.getGameResolutionWidth()/(this._canvasWidth||1),s[1]*=this._game.getGameResolutionHeight()/(this._canvasHeight||1),s},d=n=>{const s=n.pageX-o.offsetLeft,a=n.pageY-o.offsetTop;return 0<=s&&s<(this._canvasWidth||1)&&0<=a&&a<(this._canvasHeight||1)};(function(){isNaN(o.offsetLeft)&&(o.offsetLeft=0,o.offsetTop=0),isNaN(i.body.scrollLeft)&&(i.body.scrollLeft=0,i.body.scrollTop=0),(i.documentElement===void 0||i.documentElement===null)&&(i.documentElement={}),isNaN(i.documentElement.scrollLeft)&&(i.documentElement.scrollLeft=0,i.documentElement.scrollTop=0),isNaN(o.offsetLeft)&&(o.offsetLeft=0,o.offsetTop=0)})();const m=()=>!(i.activeElement===o||i.activeElement===i.body||i.activeElement===null),h=n=>!(n.target===o||n.target===i.body);i.onkeydown=function(n){m()||(f.includes(n.keyCode)&&n.preventDefault(),e.onKeyPressed(n.keyCode,n.location))},i.onkeyup=function(n){m()||(f.includes(n.keyCode)&&n.preventDefault(),e.onKeyReleased(n.keyCode,n.location))};function g(n){switch(n){case 1:return l.InputManager.MOUSE_MIDDLE_BUTTON;case 2:return l.InputManager.MOUSE_RIGHT_BUTTON}return n}o.onmousemove=function(n){const s=r(n);e.onMouseMove(s[0],s[1])},o.onmousedown=function(n){return e.onMouseButtonPressed(g(n.button)),t.focus!==void 0&&t.focus(),!1},o.onmouseup=function(n){return e.onMouseButtonReleased(g(n.button)),!1},o.onmouseleave=function(n){e.onMouseLeave()},o.onmouseenter=function(n){e.onMouseEnter();const s=[l.InputManager.MOUSE_LEFT_BUTTON,l.InputManager.MOUSE_RIGHT_BUTTON,l.InputManager.MOUSE_MIDDLE_BUTTON,l.InputManager.MOUSE_BACK_BUTTON,l.InputManager.MOUSE_FORWARD_BUTTON];for(let a=0,v=s.length;a<v;++a){const c=s[a],p=(n.buttons&1<<a)!=0,_=e.isMouseButtonPressed(c);p&&!_?e.onMouseButtonPressed(c):!p&&_&&e.onMouseButtonReleased(c)}},t.addEventListener("click",function(n){return t.focus!==void 0&&t.focus(),!1},!1),o.oncontextmenu=function(n){return n.preventDefault(),n.stopPropagation(),!1},o.onwheel=function(n){e.onMouseWheel(-n.deltaY)},t.addEventListener("touchmove",function(n){if(!h(n)&&(n.preventDefault(),n.changedTouches))for(let s=0;s<n.changedTouches.length;++s){const a=r(n.changedTouches[s]);e.onTouchMove(n.changedTouches[s].identifier,a[0],a[1]),e.isSimulatingMouseWithTouch()&&(d(n.changedTouches[s])?e.onMouseEnter():e.onMouseLeave())}},{passive:!1}),t.addEventListener("touchstart",function(n){if(!h(n)){if(n.preventDefault(),n.changedTouches)for(let s=0;s<n.changedTouches.length;++s){const a=r(n.changedTouches[s]);e.onTouchStart(n.changedTouches[s].identifier,a[0],a[1])}return!1}},{passive:!1}),t.addEventListener("touchend",function(n){if(!h(n)){if(n.preventDefault(),n.changedTouches)for(let s=0;s<n.changedTouches.length;++s)e.onTouchEnd(n.changedTouches[s].identifier);return!1}},{passive:!1}),t.addEventListener("touchcancel",function(n){if(!h(n)){if(n.preventDefault(),n.changedTouches)for(let s=0;s<n.changedTouches.length;++s)e.onTouchCancel(n.changedTouches[s].identifier);return!1}},{passive:!1})}setWindowTitle(e){typeof document!="undefined"&&(document.title=e)}getWindowTitle(){return typeof document!="undefined"?document.title:""}startGameLoop(e){this._throwIfDisposed();let t=0;const i=o=>{this._nextFrameId=requestAnimationFrame(i);const r=t?o-t:0;t=o,e(r)||cancelAnimationFrame(this._nextFrameId)};requestAnimationFrame(i)}stopGameLoop(){cancelAnimationFrame(this._nextFrameId)}getPIXIRenderer(){return this._pixiRenderer}getThreeRenderer(){return this._threeRenderer}getDomElementContainer(){return this._domElementsContainer}openURL(e){if(typeof window!="undefined"){const t=this.getElectron();t?t.shell.openExternal(e):typeof window.cordova!="undefined"&&typeof window.cordova.InAppBrowser!="undefined"?window.cordova.InAppBrowser.open(e,"_system","location=yes"):window.open(e,"_blank")}}stopGame(){const e=this.getElectronRemote();if(e){const t=e.getCurrentWindow();if(t)try{t.close()}catch(i){u.error("Window closing failed. See error:",i)}}else typeof navigator!="undefined"&&navigator.app&&navigator.app.exitApp&&navigator.app.exitApp()}dispose(e){this._pixiRenderer?.destroy(),this._threeRenderer?.dispose(),this._pixiRenderer=null,this._threeRenderer=null,e&&this._gameCanvas&&this._gameCanvas.parentNode?.removeChild(this._gameCanvas),this._gameCanvas=null,this._domElementsContainer?.parentNode?.removeChild(this._domElementsContainer),this._domElementsContainer=null,this._wasDisposed=!0}getCanvas(){return this._gameCanvas}isWebGLSupported(){return!!this._pixiRenderer&&this._pixiRenderer.type===PIXI.RENDERER_TYPE.WEBGL}getElectron(){return typeof require=="function"?require("electron"):null}getGame(){return this._game}_throwIfDisposed(){if(this._wasDisposed)throw"The RuntimeGameRenderer has been disposed and should not be used anymore."}}l.RuntimeGamePixiRenderer=R,l.RuntimeGameRenderer=R})(gdjs||(gdjs={}));
|
|
2
2
|
//# sourceMappingURL=runtimegame-pixi-renderer.js.map
|