var Class = require('../../../utils/Class'); var GameObject = require('../../GameObject'); var Components = require('../../components'); var DynamicTilemapLayerRender = require('./DynamicTilemapLayerRender'); var TilemapComponents = require('../components'); var DynamicTilemapLayer = new Class({ Extends: GameObject, Mixins: [Components.Alpha, Components.BlendMode, Components.Flip, Components.GetBounds, Components.Origin, Components.RenderTarget, Components.ScaleMode, Components.Size, Components.Transform, Components.Visible, Components.ScrollFactor, DynamicTilemapLayerRender] , initialize: function DynamicTilemapLayer(scene, tilemap, layerIndex, tileset, x, y){ GameObject.call(this, scene, 'DynamicTilemapLayer'); this.isTilemap = true ; this.map = tilemap; this.layerIndex = layerIndex; this.layer = tilemap.layers[layerIndex]; this.layer.tilemapLayer = this; this.tileset = tileset; this.culledTiles = [] ; this.setAlpha(this.layer.alpha); this.setPosition(x, y); this.setOrigin(); this.setSize(this.layer.tileWidth * this.layer.width, this.layer.tileHeight * this.layer.height); } , calculateFacesWithin: function (tileX, tileY, width, height){ TilemapComponents.CalculateFacesWithin(tileX, tileY, width, height, this.layer); return this; } , createFromTiles: function (indexes, replacements, spriteConfig, scene, camera){ return TilemapComponents.CreateFromTiles(indexes, replacements, spriteConfig, scene, camera, this.layer); } , cull: function (camera){ return TilemapComponents.CullTiles(this.layer, camera, this.culledTiles); } , copy: function (srcTileX, srcTileY, width, height, destTileX, destTileY, recalculateFaces){ TilemapComponents.Copy(srcTileX, srcTileY, width, height, destTileX, destTileY, recalculateFaces, this.layer); return this; } , destroy: function (){ if (this.layer.tilemapLayer === this) { this.layer.tilemapLayer = undefined; } this.map = undefined; this.layer = undefined; this.tileset = undefined; this.culledTiles.length = 0; GameObject.prototype.destroy.call(this); } , fill: function (index, tileX, tileY, width, height, recalculateFaces){ TilemapComponents.Fill(index, tileX, tileY, width, height, recalculateFaces, this.layer); return this; } , filterTiles: function (callback, context, tileX, tileY, width, height, filteringOptions){ return TilemapComponents.FilterTiles(callback, context, tileX, tileY, width, height, filteringOptions, this.layer); } , findByIndex: function (findIndex, skip, reverse){ return TilemapComponents.FindByIndex(findIndex, skip, reverse, this.layer); } , findTile: function (callback, context, tileX, tileY, width, height, filteringOptions){ return TilemapComponents.FindTile(callback, context, tileX, tileY, width, height, filteringOptions, this.layer); } , forEachTile: function (callback, context, tileX, tileY, width, height, filteringOptions){ TilemapComponents.ForEachTile(callback, context, tileX, tileY, width, height, filteringOptions, this.layer); return this; } , getTileAt: function (tileX, tileY, nonNull){ return TilemapComponents.GetTileAt(tileX, tileY, nonNull, this.layer); } , getTileAtWorldXY: function (worldX, worldY, nonNull, camera){ return TilemapComponents.GetTileAtWorldXY(worldX, worldY, nonNull, camera, this.layer); } , getTilesWithin: function (tileX, tileY, width, height, filteringOptions){ return TilemapComponents.GetTilesWithin(tileX, tileY, width, height, filteringOptions, this.layer); } , getTilesWithinShape: function (shape, filteringOptions, camera){ return TilemapComponents.GetTilesWithinShape(shape, filteringOptions, camera, this.layer); } , getTilesWithinWorldXY: function (worldX, worldY, width, height, filteringOptions, camera){ return TilemapComponents.GetTilesWithinWorldXY(worldX, worldY, width, height, filteringOptions, camera, this.layer); } , hasTileAt: function (tileX, tileY){ return TilemapComponents.HasTileAt(tileX, tileY, this.layer); } , hasTileAtWorldXY: function (worldX, worldY, camera){ return TilemapComponents.HasTileAtWorldXY(worldX, worldY, camera, this.layer); } , putTileAt: function (tile, tileX, tileY, recalculateFaces){ return TilemapComponents.PutTileAt(tile, tileX, tileY, recalculateFaces, this.layer); } , putTileAtWorldXY: function (tile, worldX, worldY, recalculateFaces, camera){ return TilemapComponents.PutTileAtWorldXY(tile, worldX, worldY, recalculateFaces, camera, this.layer); } , putTilesAt: function (tilesArray, tileX, tileY, recalculateFaces){ TilemapComponents.PutTilesAt(tilesArray, tileX, tileY, recalculateFaces, this.layer); return this; } , randomize: function (tileX, tileY, width, height, indexes){ TilemapComponents.Randomize(tileX, tileY, width, height, indexes, this.layer); return this; } , removeTileAt: function (tileX, tileY, replaceWithNull, recalculateFaces){ return TilemapComponents.RemoveTileAt(tileX, tileY, replaceWithNull, recalculateFaces, this.layer); } , removeTileAtWorldXY: function (worldX, worldY, replaceWithNull, recalculateFaces, camera){ return TilemapComponents.RemoveTileAtWorldXY(worldX, worldY, replaceWithNull, recalculateFaces, camera, this.layer); } , renderDebug: function (graphics, styleConfig){ TilemapComponents.RenderDebug(graphics, styleConfig, this.layer); return this; } , replaceByIndex: function (findIndex, newIndex, tileX, tileY, width, height){ TilemapComponents.ReplaceByIndex(findIndex, newIndex, tileX, tileY, width, height, this.layer); return this; } , setCollision: function (indexes, collides, recalculateFaces){ TilemapComponents.SetCollision(indexes, collides, recalculateFaces, this.layer); return this; } , setCollisionBetween: function (start, stop, collides, recalculateFaces){ TilemapComponents.SetCollisionBetween(start, stop, collides, recalculateFaces, this.layer); return this; } , setCollisionByExclusion: function (indexes, collides, recalculateFaces){ TilemapComponents.SetCollisionByExclusion(indexes, collides, recalculateFaces, this.layer); return this; } , setTileIndexCallback: function (indexes, callback, callbackContext){ TilemapComponents.SetTileIndexCallback(indexes, callback, callbackContext, this.layer); return this; } , setTileLocationCallback: function (tileX, tileY, width, height, callback, callbackContext){ TilemapComponents.SetTileLocationCallback(tileX, tileY, width, height, callback, callbackContext, this.layer); return this; } , shuffle: function (tileX, tileY, width, height){ TilemapComponents.Shuffle(tileX, tileY, width, height, this.layer); return this; } , swapByIndex: function (indexA, indexB, tileX, tileY, width, height){ TilemapComponents.SwapByIndex(indexA, indexB, tileX, tileY, width, height, this.layer); return this; } , tileToWorldX: function (tileX, camera){ return TilemapComponents.TileToWorldX(tileX, camera, this.layer); } , tileToWorldY: function (tileY, camera){ return TilemapComponents.TileToWorldY(tileY, camera, this.layer); } , tileToWorldXY: function (tileX, tileY, point, camera){ return TilemapComponents.TileToWorldXY(tileX, tileY, point, camera, this.layer); } , weightedRandomize: function (tileX, tileY, width, height, weightedIndexes){ TilemapComponents.WeightedRandomize(tileX, tileY, width, height, weightedIndexes, this.layer); return this; } , worldToTileX: function (worldX, snapToFloor, camera){ return TilemapComponents.WorldToTileX(worldX, snapToFloor, camera, this.layer); } , worldToTileY: function (worldY, snapToFloor, camera){ return TilemapComponents.WorldToTileY(worldY, snapToFloor, camera, this.layer); } , worldToTileXY: function (worldX, worldY, snapToFloor, point, camera){ return TilemapComponents.WorldToTileXY(worldX, worldY, snapToFloor, point, camera, this.layer); } } ); module.exports = DynamicTilemapLayer;