Tilemap & layer WorldXY methods: get, has, put, remove

This commit is contained in:
Michael Hadley 2017-11-17 07:58:33 -06:00
parent ea989edca1
commit 3266974ea0
8 changed files with 94 additions and 13 deletions

View file

@ -292,11 +292,11 @@ var Tilemap = new Class({
return TilemapComponents.GetTileAt(tileX, tileY, nonNull, layer);
},
getTileAtWorldXY: function (worldX, worldY, nonNull, layer)
getTileAtWorldXY: function (worldX, worldY, nonNull, camera, layer)
{
layer = this.getLayer(layer);
if (layer === null) { return null; }
return TilemapComponents.GetTileAtWorldXY(worldX, worldY, nonNull, layer);
return TilemapComponents.GetTileAtWorldXY(worldX, worldY, nonNull, camera, layer);
},
getTilesWithin: function (tileX, tileY, width, height, layer)
@ -318,6 +318,13 @@ var Tilemap = new Class({
return TilemapComponents.HasTileAt(tileX, tileY, layer);
},
hasTileAtWorldXY: function (worldX, worldY, camera, layer)
{
layer = this.getLayer(layer);
if (layer === null) { return null; }
return TilemapComponents.HasTileAtWorldXY(worldX, worldY, camera, layer);
},
layer: {
get: function ()
{
@ -338,6 +345,14 @@ var Tilemap = new Class({
return TilemapComponents.PutTile(tile, tileX, tileY, layer);
},
putTileWorldXY: function (tile, worldX, worldY, camera, layer)
{
layer = this.getLayer(layer);
if (this._isStaticCall(layer, 'putTileWorldXY')) { return null; }
if (layer === null) { return null; }
return TilemapComponents.PutTileWorldXY(tile, worldX, worldY, camera, layer);
},
randomize: function (tileX, tileY, width, height, indices, layer)
{
layer = this.getLayer(layer);
@ -364,6 +379,14 @@ var Tilemap = new Class({
return TilemapComponents.RemoveTile(tileX, tileY, replaceWithNull, layer);
},
removeTileWorldXY: function (worldX, worldY, replaceWithNull, camera, layer)
{
layer = this.getLayer(layer);
if (this._isStaticCall(layer, 'removeTileWorldXY')) { return null; }
if (layer === null) { return null; }
return TilemapComponents.RemoveTileWorldXY(worldX, worldY, replaceWithNull, camera, layer);
},
replaceByIndex: function (findIndex, newIndex, tileX, tileY, width, height, layer)
{
layer = this.getLayer(layer);

View file

@ -1,13 +1,11 @@
var GetTileAt = require('./GetTileAt');
var SnapFloor = require('../../../math/snap/SnapFloor');
var WorldToTileX = require('./WorldToTileX');
var WorldToTileY = require('./WorldToTileY');
// NOTE: phaser v2 version doesn't account for TilemapLayer's XY, so neither does this version
// currently.
var GetTileAtWorldXY = function (worldX, worldY, nonNull, layer)
var GetTileAtWorldXY = function (worldX, worldY, nonNull, camera, layer)
{
var tileX = SnapFloor(worldX, layer.tileWidth) / layer.tileWidth;
var tileY = SnapFloor(worldY, layer.tileHeight) / layer.tileHeight;
var tileX = WorldToTileX(worldX, camera, layer);
var tileY = WorldToTileY(worldY, camera, layer);
return GetTileAt(tileX, tileY, nonNull, layer);
};

View file

@ -0,0 +1,13 @@
var HasTileAt = require('./HasTileAt');
var WorldToTileX = require('./WorldToTileX');
var WorldToTileY = require('./WorldToTileY');
var HasTileAtWorldXY = function (worldX, worldY, camera, layer)
{
var tileX = WorldToTileX(worldX, camera, layer);
var tileY = WorldToTileY(worldY, camera, layer);
return HasTileAt(tileX, tileY, layer);
};
module.exports = HasTileAtWorldXY;

View file

@ -0,0 +1,12 @@
var PutTile = require('./PutTile');
var WorldToTileX = require('./WorldToTileX');
var WorldToTileY = require('./WorldToTileY');
var PutTileWorldXY = function (tile, worldX, worldY, camera, layer)
{
var tileX = WorldToTileX(worldX, camera, layer);
var tileY = WorldToTileY(worldY, camera, layer);
return PutTile(tile, tileX, tileY, layer);
};
module.exports = PutTileWorldXY;

View file

@ -0,0 +1,12 @@
var RemoveTile = require('./RemoveTile');
var WorldToTileX = require('./WorldToTileX');
var WorldToTileY = require('./WorldToTileY');
var RemoveTileWorldXY = function (worldX, worldY, replaceWithNull, camera, layer)
{
var tileX = WorldToTileX(worldX, camera, layer);
var tileY = WorldToTileY(worldY, camera, layer);
return RemoveTile(tileX, tileY, replaceWithNull, layer);
};
module.exports = RemoveTileWorldXY;

View file

@ -8,10 +8,13 @@ module.exports = {
GetTileAtWorldXY: require('./GetTileAtWorldXY'),
GetTilesWithin: require('./GetTilesWithin'),
HasTileAt: require('./HasTileAt'),
HasTileAtWorldXY: require('./HasTileAtWorldXY'),
IsInLayerBounds: require('./IsInLayerBounds'),
PutTile: require('./PutTile'),
PutTileWorldXY: require('./PutTileWorldXY'),
Randomize: require('./Randomize'),
RemoveTile: require('./RemoveTile'),
RemoveTileWorldXY: require('./RemoveTileWorldXY'),
ReplaceByIndex: require('./ReplaceByIndex'),
Shuffle: require('./Shuffle'),
SwapByIndex: require('./SwapByIndex'),

View file

@ -137,9 +137,9 @@ var DynamicTilemapLayer = new Class({
return TilemapComponents.GetTileAt(tileX, tileY, nonNull, this.layer);
},
getTileAtWorldXY: function (worldX, worldY, nonNull)
getTileAtWorldXY: function (worldX, worldY, nonNull, camera)
{
return TilemapComponents.GetTileAtWorldXY(worldX, worldY, nonNull, this.layer);
return TilemapComponents.GetTileAtWorldXY(worldX, worldY, nonNull, camera, this.layer);
},
getTilesWithin: function (tileX, tileY, width, height)
@ -152,11 +152,21 @@ var DynamicTilemapLayer = new Class({
return TilemapComponents.HasTileAt(tileX, tileY, this.layer);
},
hasTileAtWorldXY: function (worldX, worldY, camera)
{
return TilemapComponents.HasTileAtWorldXY(worldX, worldY, camera, this.layer);
},
putTile: function (tile, tileX, tileY)
{
return TilemapComponents.PutTile(tile, tileX, tileY, this.layer);
},
putTileWorldXY: function (tile, worldX, worldY, camera)
{
return TilemapComponents.PutTileWorldXY(tile, worldX, worldY, camera, this.layer);
},
randomize: function (tileX, tileY, width, height, indices)
{
TilemapComponents.Randomize(tileX, tileY, width, height, indices, this.layer);
@ -168,6 +178,11 @@ var DynamicTilemapLayer = new Class({
return TilemapComponents.RemoveTile(tileX, tileY, replaceWithNull, this.layer);
},
removeTileWorldXY: function (worldX, worldY, replaceWithNull, camera)
{
return TilemapComponents.RemoveTileWorldXY(worldX, worldY, replaceWithNull, camera, this.layer);
},
replaceByIndex: function (findIndex, newIndex, tileX, tileY, width, height)
{
TilemapComponents.ReplaceByIndex(findIndex, newIndex, tileX, tileY, width, height, this.layer);

View file

@ -298,9 +298,9 @@ var StaticTilemapLayer = new Class({
return TilemapComponents.GetTileAt(tileX, tileY, nonNull, this.layer);
},
getTileAtWorldXY: function (worldX, worldY, nonNull)
getTileAtWorldXY: function (worldX, worldY, nonNull, camera)
{
return TilemapComponents.GetTileAtWorldXY(worldX, worldY, nonNull, this.layer);
return TilemapComponents.GetTileAtWorldXY(worldX, worldY, nonNull, camera, this.layer);
},
getTilesWithin: function (tileX, tileY, width, height)
@ -313,6 +313,11 @@ var StaticTilemapLayer = new Class({
return TilemapComponents.HasTileAt(tileX, tileY, this.layer);
},
hasTileAtWorldXY: function (worldX, worldY, camera)
{
return TilemapComponents.HasTileAtWorldXY(worldX, worldY, camera, this.layer);
},
worldToTileX: function (worldX, camera)
{
return TilemapComponents.WorldToTileX(worldX, camera, this.layer);