2017-06-09 04:00:12 +00:00
|
|
|
var Class = require('../../../utils/Class');
|
|
|
|
var GameObject = require('../../GameObject');
|
2017-07-04 00:59:31 +00:00
|
|
|
var Components = require('../../components');
|
2017-11-09 18:18:23 +00:00
|
|
|
var DynamicTilemapLayerRender = require('./DynamicTilemapLayerRender');
|
2017-11-15 21:28:15 +00:00
|
|
|
var TilemapComponents = require('../components');
|
2017-06-09 04:00:12 +00:00
|
|
|
|
2017-11-09 18:18:23 +00:00
|
|
|
var DynamicTilemapLayer = new Class({
|
2017-06-09 04:00:12 +00:00
|
|
|
|
|
|
|
Extends: GameObject,
|
|
|
|
|
|
|
|
Mixins: [
|
|
|
|
Components.Alpha,
|
|
|
|
Components.BlendMode,
|
|
|
|
Components.Flip,
|
|
|
|
Components.GetBounds,
|
|
|
|
Components.Origin,
|
|
|
|
Components.RenderTarget,
|
|
|
|
Components.ScaleMode,
|
|
|
|
Components.Size,
|
|
|
|
Components.Texture,
|
|
|
|
Components.Transform,
|
|
|
|
Components.Visible,
|
2017-06-22 02:19:03 +00:00
|
|
|
Components.ScrollFactor,
|
2017-11-09 18:18:23 +00:00
|
|
|
DynamicTilemapLayerRender
|
2017-06-09 04:00:12 +00:00
|
|
|
],
|
|
|
|
|
|
|
|
initialize:
|
|
|
|
|
2017-11-11 16:38:52 +00:00
|
|
|
function DynamicTilemapLayer (scene, tilemap, layerIndex, tileset, x, y)
|
2017-06-09 04:00:12 +00:00
|
|
|
{
|
2017-11-09 18:18:23 +00:00
|
|
|
GameObject.call(this, scene, 'DynamicTilemapLayer');
|
2017-06-09 04:00:12 +00:00
|
|
|
|
2017-11-11 16:38:52 +00:00
|
|
|
this.map = tilemap;
|
|
|
|
this.layerIndex = layerIndex;
|
|
|
|
this.layer = tilemap.layers[layerIndex];
|
|
|
|
this.tileset = tileset;
|
2017-11-03 16:52:57 +00:00
|
|
|
|
2017-11-17 01:55:17 +00:00
|
|
|
// Link the layer data with this dynamic tilemap layer
|
|
|
|
this.layer.tilemapLayer = this;
|
|
|
|
|
2017-06-09 04:00:12 +00:00
|
|
|
this.culledTiles = [];
|
2017-11-03 16:52:57 +00:00
|
|
|
|
2017-11-11 16:38:52 +00:00
|
|
|
this.setTexture(tileset.image.key);
|
2017-06-09 04:00:12 +00:00
|
|
|
this.setPosition(x, y);
|
|
|
|
this.setSizeToFrame();
|
|
|
|
this.setOrigin();
|
2017-11-11 16:38:52 +00:00
|
|
|
this.setSize(this.map.tileWidth * this.layer.width, this.map.tileheight * this.layer.height);
|
2017-11-03 16:52:57 +00:00
|
|
|
|
|
|
|
this.skipIndexZero = false;
|
2017-06-09 04:00:12 +00:00
|
|
|
},
|
|
|
|
|
2017-11-22 01:18:34 +00:00
|
|
|
calculateFacesWithin: function (tileX, tileY, width, height)
|
|
|
|
{
|
|
|
|
TilemapComponents.CalculateFacesWithin(tileX, tileY, width, height, this.layer);
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2017-11-14 21:35:18 +00:00
|
|
|
cull: function (camera)
|
2017-06-09 04:00:12 +00:00
|
|
|
{
|
2017-11-18 14:31:59 +00:00
|
|
|
TilemapComponents.CullTiles(this.layer, camera, this.culledTiles);
|
2017-11-15 19:50:56 +00:00
|
|
|
},
|
|
|
|
|
2017-11-26 14:58:38 +00:00
|
|
|
copy: function (srcTileX, srcTileY, width, height, destTileX, destTileY, recalculateFaces)
|
2017-11-16 02:16:43 +00:00
|
|
|
{
|
2017-11-26 14:58:38 +00:00
|
|
|
TilemapComponents.Copy(srcTileX, srcTileY, width, height, destTileX, destTileY, recalculateFaces, this.layer);
|
2017-11-16 02:16:43 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2017-11-17 01:55:17 +00:00
|
|
|
destroy: function ()
|
|
|
|
{
|
|
|
|
this.layer.tilemapLayer = undefined;
|
|
|
|
this.map = undefined;
|
|
|
|
this.layer = undefined;
|
|
|
|
this.tileset = undefined;
|
|
|
|
this.culledTiles.length = 0;
|
|
|
|
GameObject.prototype.destroy.call(this);
|
|
|
|
},
|
|
|
|
|
2017-11-26 15:19:57 +00:00
|
|
|
fill: function (index, tileX, tileY, width, height, recalculateFaces)
|
2017-11-16 02:16:43 +00:00
|
|
|
{
|
2017-11-26 15:19:57 +00:00
|
|
|
TilemapComponents.Fill(index, tileX, tileY, width, height, recalculateFaces, this.layer);
|
2017-11-16 02:16:43 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2017-11-17 01:08:58 +00:00
|
|
|
findByIndex: function (findIndex, skip, reverse)
|
|
|
|
{
|
|
|
|
return TilemapComponents.FindByIndex(findIndex, skip, reverse, this.layer);
|
|
|
|
},
|
|
|
|
|
2017-11-26 00:03:21 +00:00
|
|
|
forEachTile: function (callback, context, tileX, tileY, width, height, filteringOptions)
|
2017-11-15 22:36:41 +00:00
|
|
|
{
|
2017-11-26 00:03:21 +00:00
|
|
|
TilemapComponents.ForEachTile(callback, context, tileX, tileY, width, height, filteringOptions, this.layer);
|
2017-11-16 02:16:43 +00:00
|
|
|
return this;
|
2017-11-15 22:36:41 +00:00
|
|
|
},
|
|
|
|
|
2017-11-15 21:28:15 +00:00
|
|
|
getTileAt: function (tileX, tileY, nonNull)
|
2017-11-15 19:50:56 +00:00
|
|
|
{
|
2017-11-16 19:09:07 +00:00
|
|
|
return TilemapComponents.GetTileAt(tileX, tileY, nonNull, this.layer);
|
2017-11-15 21:28:15 +00:00
|
|
|
},
|
|
|
|
|
2017-11-17 13:58:33 +00:00
|
|
|
getTileAtWorldXY: function (worldX, worldY, nonNull, camera)
|
2017-11-16 19:27:52 +00:00
|
|
|
{
|
2017-11-17 13:58:33 +00:00
|
|
|
return TilemapComponents.GetTileAtWorldXY(worldX, worldY, nonNull, camera, this.layer);
|
2017-11-16 19:27:52 +00:00
|
|
|
},
|
|
|
|
|
2017-11-26 00:03:21 +00:00
|
|
|
getTilesWithin: function (tileX, tileY, width, height, filteringOptions)
|
2017-11-15 22:36:41 +00:00
|
|
|
{
|
2017-11-26 00:03:21 +00:00
|
|
|
return TilemapComponents.GetTilesWithin(tileX, tileY, width, height, filteringOptions, this.layer);
|
2017-11-15 22:36:41 +00:00
|
|
|
},
|
|
|
|
|
2017-11-26 13:55:44 +00:00
|
|
|
getTilesWithinShape: function (shape, filteringOptions, camera)
|
|
|
|
{
|
|
|
|
return TilemapComponents.GetTilesWithinShape(shape, filteringOptions, camera, this.layer);
|
|
|
|
},
|
|
|
|
|
2017-11-26 00:03:21 +00:00
|
|
|
getTilesWithinWorldXY: function (worldX, worldY, width, height, filteringOptions, camera)
|
2017-11-25 14:42:19 +00:00
|
|
|
{
|
2017-11-26 00:03:21 +00:00
|
|
|
return TilemapComponents.GetTilesWithinWorldXY(worldX, worldY, width, height, filteringOptions, camera, this.layer);
|
2017-11-25 14:42:19 +00:00
|
|
|
},
|
|
|
|
|
2017-11-15 21:28:15 +00:00
|
|
|
hasTileAt: function (tileX, tileY)
|
|
|
|
{
|
|
|
|
return TilemapComponents.HasTileAt(tileX, tileY, this.layer);
|
2017-11-16 02:16:43 +00:00
|
|
|
},
|
|
|
|
|
2017-11-17 13:58:33 +00:00
|
|
|
hasTileAtWorldXY: function (worldX, worldY, camera)
|
|
|
|
{
|
|
|
|
return TilemapComponents.HasTileAtWorldXY(worldX, worldY, camera, this.layer);
|
|
|
|
},
|
|
|
|
|
2017-11-22 01:18:34 +00:00
|
|
|
putTileAt: function (tile, tileX, tileY, recalculateFaces)
|
2017-11-16 19:09:07 +00:00
|
|
|
{
|
2017-11-22 01:18:34 +00:00
|
|
|
return TilemapComponents.PutTileAt(tile, tileX, tileY, recalculateFaces, this.layer);
|
2017-11-16 19:09:07 +00:00
|
|
|
},
|
|
|
|
|
2017-11-22 01:18:34 +00:00
|
|
|
putTileAtWorldXY: function (tile, worldX, worldY, recalculateFaces, camera)
|
2017-11-17 13:58:33 +00:00
|
|
|
{
|
2017-11-22 01:18:34 +00:00
|
|
|
return TilemapComponents.PutTileAtWorldXY(tile, worldX, worldY, recalculateFaces, camera, this.layer);
|
2017-11-17 13:58:33 +00:00
|
|
|
},
|
|
|
|
|
2017-11-16 02:16:43 +00:00
|
|
|
randomize: function (tileX, tileY, width, height, indices)
|
|
|
|
{
|
|
|
|
TilemapComponents.Randomize(tileX, tileY, width, height, indices, this.layer);
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2017-11-22 01:18:34 +00:00
|
|
|
removeTileAt: function (tileX, tileY, replaceWithNull, recalculateFaces)
|
2017-11-16 19:09:07 +00:00
|
|
|
{
|
2017-11-22 01:18:34 +00:00
|
|
|
return TilemapComponents.RemoveTileAt(tileX, tileY, replaceWithNull, recalculateFaces, this.layer);
|
2017-11-16 19:09:07 +00:00
|
|
|
},
|
|
|
|
|
2017-11-22 01:18:34 +00:00
|
|
|
removeTileAtWorldXY: function (worldX, worldY, replaceWithNull, recalculateFaces, camera)
|
2017-11-17 13:58:33 +00:00
|
|
|
{
|
2017-11-22 01:18:34 +00:00
|
|
|
return TilemapComponents.RemoveTileAtWorldXY(worldX, worldY, replaceWithNull, recalculateFaces, camera, this.layer);
|
2017-11-17 13:58:33 +00:00
|
|
|
},
|
|
|
|
|
2017-11-17 01:08:58 +00:00
|
|
|
replaceByIndex: function (findIndex, newIndex, tileX, tileY, width, height)
|
|
|
|
{
|
|
|
|
TilemapComponents.ReplaceByIndex(findIndex, newIndex, tileX, tileY, width, height, this.layer);
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
|
2017-11-21 02:06:49 +00:00
|
|
|
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;
|
|
|
|
},
|
|
|
|
|
2017-11-16 02:16:43 +00:00
|
|
|
shuffle: function (tileX, tileY, width, height)
|
|
|
|
{
|
|
|
|
TilemapComponents.Shuffle(tileX, tileY, width, height, this.layer);
|
|
|
|
return this;
|
2017-11-17 01:08:58 +00:00
|
|
|
},
|
2017-06-22 02:19:03 +00:00
|
|
|
|
2017-11-17 01:08:58 +00:00
|
|
|
swapByIndex: function (indexA, indexB, tileX, tileY, width, height)
|
|
|
|
{
|
|
|
|
TilemapComponents.SwapByIndex(indexA, indexB, tileX, tileY, width, height, this.layer);
|
|
|
|
return this;
|
2017-11-17 02:36:45 +00:00
|
|
|
},
|
|
|
|
|
2017-11-25 13:08:06 +00:00
|
|
|
worldToTileX: function (worldX, snapToFloor, camera)
|
2017-11-17 02:36:45 +00:00
|
|
|
{
|
2017-11-25 13:08:06 +00:00
|
|
|
return TilemapComponents.WorldToTileX(worldX, snapToFloor, camera, this.layer);
|
2017-11-17 02:36:45 +00:00
|
|
|
},
|
|
|
|
|
2017-11-25 13:08:06 +00:00
|
|
|
worldToTileY: function (worldY, snapToFloor, camera)
|
2017-11-17 02:36:45 +00:00
|
|
|
{
|
2017-11-25 13:08:06 +00:00
|
|
|
return TilemapComponents.WorldToTileY(worldY, snapToFloor, camera, this.layer);
|
2017-11-17 02:36:45 +00:00
|
|
|
},
|
|
|
|
|
2017-11-25 13:08:06 +00:00
|
|
|
worldToTileXY: function (worldX, worldY, snapToFloor, point, camera)
|
2017-11-17 02:36:45 +00:00
|
|
|
{
|
2017-11-25 13:08:06 +00:00
|
|
|
return TilemapComponents.WorldToTileXY(worldX, worldY, snapToFloor, point, camera, this.layer);
|
2017-11-17 01:08:58 +00:00
|
|
|
}
|
2017-06-09 04:00:12 +00:00
|
|
|
|
|
|
|
});
|
|
|
|
|
2017-11-09 18:18:23 +00:00
|
|
|
module.exports = DynamicTilemapLayer;
|