From 0b4a08730c255948b95c1b5327cf86154805f4a0 Mon Sep 17 00:00:00 2001 From: Michael Hadley Date: Wed, 29 Nov 2017 09:05:53 -0600 Subject: [PATCH 01/13] Adding debug rendering method to tilemap and layers --- v3/src/gameobjects/tilemap/Tilemap.js | 8 +++ .../tilemap/components/RenderDebug.js | 70 +++++++++++++++++++ .../gameobjects/tilemap/components/index.js | 1 + .../dynamiclayer/DynamicTilemapLayer.js | 6 ++ .../tilemap/staticlayer/StaticTilemapLayer.js | 6 ++ 5 files changed, 91 insertions(+) create mode 100644 v3/src/gameobjects/tilemap/components/RenderDebug.js diff --git a/v3/src/gameobjects/tilemap/Tilemap.js b/v3/src/gameobjects/tilemap/Tilemap.js index 9a4670237..2920ba4d1 100644 --- a/v3/src/gameobjects/tilemap/Tilemap.js +++ b/v3/src/gameobjects/tilemap/Tilemap.js @@ -514,6 +514,14 @@ var Tilemap = new Class({ return TilemapComponents.RemoveTileAtWorldXY(worldX, worldY, replaceWithNull, recalculateFaces, camera, layer); }, + renderDebug: function (graphics, styleConfig, layer) + { + layer = this.getLayer(layer); + if (layer === null) { return this; } + TilemapComponents.RenderDebug(graphics, styleConfig, layer); + return this; + }, + replaceByIndex: function (findIndex, newIndex, tileX, tileY, width, height, layer) { layer = this.getLayer(layer); diff --git a/v3/src/gameobjects/tilemap/components/RenderDebug.js b/v3/src/gameobjects/tilemap/components/RenderDebug.js new file mode 100644 index 000000000..bd5df0a8f --- /dev/null +++ b/v3/src/gameobjects/tilemap/components/RenderDebug.js @@ -0,0 +1,70 @@ +var GetTilesWithin = require('./GetTilesWithin'); +var Color = require('../../../display/color'); + +/** + * Draws a debug representation of the layer to the given Graphics. This is helpful when you want to + * get a quick idea of which of your tiles are colliding and which have interesting faces. The tiles + * are drawn starting at (0, 0) in the Graphics, allowing you to place the debug representation + * wherever you want on the screen. + * + * @param {Graphics} graphics - The target Graphics object to draw upon. + * @param {object} styleConfig - An object specifying the colors to use for the debug drawing. + * @param {Color|null} [styleConfig.tileColor=blue] - Color to use for drawing a filled rectangle at + * non-colliding tile locations. If set to null, non-colliding tiles will not be drawn. + * @param {Color|null} [styleConfig.collidingTileColor=orange] - Color to use for drawing a filled + * rectangle at colliding tile locations. If set to null, colliding tiles will not be drawn. + * @param {Color|null} [styleConfig.faceColor=grey] - Color to use for drawing a line at interesting + * tile faces. If set to null, interesting tile faces will not be drawn. + * @param {LayerData} layer - [description] + */ +var RenderDebug = function (graphics, styleConfig, layer) +{ + if (styleConfig === undefined) { styleConfig = {}; } + + // Default colors without needlessly creating Color objects + var tileColor = styleConfig.tileColor !== undefined + ? styleConfig.tileColor + : new Color(105, 210, 231, 150); + var collidingTileColor = styleConfig.collidingTileColor !== undefined + ? styleConfig.collidingTileColor + : new Color(243, 134, 48, 200); + var faceColor = styleConfig.faceColor !== undefined + ? styleConfig.faceColor + : new Color(40, 39, 37, 150); + + var tiles = GetTilesWithin(0, 0, layer.width, layer.height, null, layer); + + for (var i = 0; i < tiles.length; i++) + { + var tile = tiles[i]; + + var tw = tile.width; + var th = tile.height; + var x = tile.worldX; + var y = tile.worldY; + + var color = tile.collides ? collidingTileColor : tileColor; + if (color !== null) + { + graphics.fillStyle(color.color, color.alpha / 255); + graphics.fillRect(x, y, tw, th); + } + + // Inset the face line to prevent neighboring tile's lines from overlapping + x += 1; + y += 1; + tw -= 2; + th -= 2; + + if (faceColor !== null) + { + graphics.lineStyle(1, faceColor.color, faceColor.alpha / 255); + if (tile.faceTop) { graphics.lineBetween(x, y, x + tw, y); } + if (tile.faceRight) { graphics.lineBetween(x + tw, y, x + tw, y + th); } + if (tile.faceBottom) { graphics.lineBetween(x, y + th, x + tw, y + th); } + if (tile.faceLeft) { graphics.lineBetween(x, y, x, y + th); } + } + } +}; + +module.exports = RenderDebug; diff --git a/v3/src/gameobjects/tilemap/components/index.js b/v3/src/gameobjects/tilemap/components/index.js index c1f8f2e26..56e8b2e50 100644 --- a/v3/src/gameobjects/tilemap/components/index.js +++ b/v3/src/gameobjects/tilemap/components/index.js @@ -22,6 +22,7 @@ module.exports = { RemoveTileAt: require('./RemoveTileAt'), RemoveTileAtWorldXY: require('./RemoveTileAtWorldXY'), ReplaceByIndex: require('./ReplaceByIndex'), + RenderDebug: require('./RenderDebug'), SetCollision: require('./SetCollision'), SetCollisionBetween: require('./SetCollisionBetween'), SetCollisionByExclusion: require('./SetCollisionByExclusion'), diff --git a/v3/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayer.js b/v3/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayer.js index b8bdff32f..58e09fd10 100644 --- a/v3/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayer.js +++ b/v3/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayer.js @@ -164,6 +164,12 @@ var DynamicTilemapLayer = new Class({ 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); diff --git a/v3/src/gameobjects/tilemap/staticlayer/StaticTilemapLayer.js b/v3/src/gameobjects/tilemap/staticlayer/StaticTilemapLayer.js index ae0033d3f..f8e7d9b78 100644 --- a/v3/src/gameobjects/tilemap/staticlayer/StaticTilemapLayer.js +++ b/v3/src/gameobjects/tilemap/staticlayer/StaticTilemapLayer.js @@ -279,6 +279,12 @@ var StaticTilemapLayer = new Class({ return TilemapComponents.HasTileAtWorldXY(worldX, worldY, camera, this.layer); }, + renderDebug: function (graphics, styleConfig) + { + TilemapComponents.RenderDebug(graphics, styleConfig, this.layer); + return this; + }, + setCollision: function (indexes, collides, recalculateFaces) { TilemapComponents.SetCollision(indexes, collides, recalculateFaces, this.layer); From f4a6888d866de7f8c1c7136b367fd915e339b958 Mon Sep 17 00:00:00 2001 From: Michael Hadley Date: Wed, 29 Nov 2017 11:36:36 -0600 Subject: [PATCH 02/13] Tilemap: add method for converting layer from dynamic to static --- v3/src/gameobjects/tilemap/Tilemap.js | 21 +++++++++++++++++++ .../dynamiclayer/DynamicTilemapLayer.js | 3 ++- .../tilemap/staticlayer/StaticTilemapLayer.js | 5 +++-- 3 files changed, 26 insertions(+), 3 deletions(-) diff --git a/v3/src/gameobjects/tilemap/Tilemap.js b/v3/src/gameobjects/tilemap/Tilemap.js index 2920ba4d1..e9b829d63 100644 --- a/v3/src/gameobjects/tilemap/Tilemap.js +++ b/v3/src/gameobjects/tilemap/Tilemap.js @@ -276,6 +276,27 @@ var Tilemap = new Class({ return layer; }, + convertLayerToStatic: function (layer) + { + layer = this.getLayer(layer); + if (layer === null) { return null; } + + var dynamicLayer = layer.tilemapLayer; + + if (!dynamicLayer || !(dynamicLayer instanceof DynamicTilemapLayer)) + { + return null; + } + + var staticLayer = new StaticTilemapLayer(dynamicLayer.scene, dynamicLayer.map, + dynamicLayer.layerIndex, dynamicLayer.tileset, dynamicLayer.x, dynamicLayer.y); + this.scene.sys.displayList.add(staticLayer); + + dynamicLayer.destroy(); + + return staticLayer; + }, + copy: function (srcTileX, srcTileY, width, height, destTileX, destTileY, recalculateFaces, layer) { layer = this.getLayer(layer); diff --git a/v3/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayer.js b/v3/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayer.js index 58e09fd10..fa7ab8bab 100644 --- a/v3/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayer.js +++ b/v3/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayer.js @@ -73,7 +73,8 @@ var DynamicTilemapLayer = new Class({ destroy: function () { - this.layer.tilemapLayer = undefined; + // Uninstall this layer only if it is still installed on the LayerData object + if (this.layer.tilemapLayer === this) { this.layer.tilemapLayer = undefined; } this.map = undefined; this.layer = undefined; this.tileset = undefined; diff --git a/v3/src/gameobjects/tilemap/staticlayer/StaticTilemapLayer.js b/v3/src/gameobjects/tilemap/staticlayer/StaticTilemapLayer.js index f8e7d9b78..98d84e336 100644 --- a/v3/src/gameobjects/tilemap/staticlayer/StaticTilemapLayer.js +++ b/v3/src/gameobjects/tilemap/staticlayer/StaticTilemapLayer.js @@ -36,7 +36,7 @@ var StaticTilemapLayer = new Class({ this.layer = tilemap.layers[layerIndex]; this.tileset = tileset; - // Link the layer data with this dynamic tilemap layer + // Link the layer data with this static tilemap layer this.layer.tilemapLayer = this; this.vbo = null; @@ -221,7 +221,8 @@ var StaticTilemapLayer = new Class({ destroy: function () { - this.layer.tilemapLayer = undefined; + // Uninstall this layer only if it is still installed on the LayerData object + if (this.layer.tilemapLayer === this) { this.layer.tilemapLayer = undefined; } this.map = undefined; this.layer = undefined; this.tileset = undefined; From a7df7c2df94eb29c67fe91344d3eda71222d1890 Mon Sep 17 00:00:00 2001 From: Michael Hadley Date: Wed, 29 Nov 2017 11:46:19 -0600 Subject: [PATCH 03/13] Tidying up linting, notes and comments --- v3/src/gameobjects/tilemap/Tile.js | 4 +--- v3/src/gameobjects/tilemap/Tilemap.js | 14 -------------- .../gameobjects/tilemap/components/ForEachTile.js | 8 ++++---- .../tilemap/components/GetTilesWithin.js | 2 -- .../tilemap/parsers/parsetiledjson/index.js | 2 +- 5 files changed, 6 insertions(+), 24 deletions(-) diff --git a/v3/src/gameobjects/tilemap/Tile.js b/v3/src/gameobjects/tilemap/Tile.js index d39a0b64b..1e825f6c4 100644 --- a/v3/src/gameobjects/tilemap/Tile.js +++ b/v3/src/gameobjects/tilemap/Tile.js @@ -3,8 +3,6 @@ var Components = require('../components'); var Tile = new Class({ - // TODO: custom rotation or use transform component - // TODO: Add in bounds mixin, or custom replacement Mixins: [ Components.Alpha, Components.Flip, @@ -37,7 +35,7 @@ var Tile = new Class({ this.collisionCallbackContext = this; this.scanned = false; - // TODO: update renders to allow for using Components.Tint + // Note: tint is currently a single color value instead of the 4 corner tint component this.tint = 0xFFFFFF; }, diff --git a/v3/src/gameobjects/tilemap/Tilemap.js b/v3/src/gameobjects/tilemap/Tilemap.js index e9b829d63..6c876ac6a 100644 --- a/v3/src/gameobjects/tilemap/Tilemap.js +++ b/v3/src/gameobjects/tilemap/Tilemap.js @@ -38,8 +38,6 @@ var Tilemap = new Class({ this.tiles = mapData.tiles; this.objects = mapData.objects; this.currentLayerIndex = 0; - - // TODO: debugging methods }, addTilesetImage: function (tilesetName, key, tileWidth, tileHeight, tileMargin, tileSpacing, gid) @@ -57,8 +55,6 @@ var Tilemap = new Class({ var texture = this.scene.sys.textures.get(key); - // TODO: potentially add in v2 support for bitmap data - var index = this.getTilesetIndex(tilesetName); if (index === null && this.format === Formats.TILEMAP_TILED_JSON) @@ -83,8 +79,6 @@ var Tilemap = new Class({ tileset.setImage(texture); this.tilesets.push(tileset); return tileset; - - // TODO: add in GID & master list of tiles }, // Creates & selects @@ -127,8 +121,6 @@ var Tilemap = new Class({ this.layers.push(layerData); this.currentLayerIndex = this.layers.length - 1; - // TODO: decide about v2 trimming to game width/height - var dynamicLayer = new DynamicTilemapLayer(this.scene, this, this.currentLayerIndex, tileset, x, y); this.scene.sys.displayList.add(dynamicLayer); @@ -238,9 +230,6 @@ var Tilemap = new Class({ return null; } - // TODO: new feature, allow multiple CSV layers - // TODO: display dimension - this.currentLayerIndex = index; var layer = new StaticTilemapLayer(this.scene, this, index, tileset, x, y); @@ -266,9 +255,6 @@ var Tilemap = new Class({ return null; } - // TODO: new feature, allow multiple CSV layers - // TODO: display dimension - this.currentLayerIndex = index; var layer = new DynamicTilemapLayer(this.scene, this, index, tileset, x, y); diff --git a/v3/src/gameobjects/tilemap/components/ForEachTile.js b/v3/src/gameobjects/tilemap/components/ForEachTile.js index ea08eb30b..f6750d77f 100644 --- a/v3/src/gameobjects/tilemap/components/ForEachTile.js +++ b/v3/src/gameobjects/tilemap/components/ForEachTile.js @@ -2,11 +2,11 @@ var GetTilesWithin = require('./GetTilesWithin'); /** * For each tile in the given rectangular area (in tile coordinates) of the layer, run the given - * callback. + * callback. Similar to Array.prototype.forEach in vanilla JS. * * @param {number} callback - The callback. Each tile in the given area will be passed to this * callback as the first and only parameter. - * @param {number} context - The context under which the callback should be run. + * @param {number} [context] - The context under which the callback should be run. * @param {number} [tileX=0] - [description] * @param {number} [tileY=0] - [description] * @param {number} [width=max width based on tileX] - [description] @@ -14,8 +14,8 @@ var GetTilesWithin = require('./GetTilesWithin'); * @param {object} [filteringOptions] - Optional filters to apply when getting the tiles. * @param {boolean} [filteringOptions.isNotEmpty=false] - If true, only return tiles that don't have * -1 for an index. - * @param {boolean} [filteringOptions.isColliding=false] - If true, only return tiles that collide on - * at least one side. + * @param {boolean} [filteringOptions.isColliding=false] - If true, only return tiles that collide + * on at least one side. * @param {boolean} [filteringOptions.hasInterestingFace=false] - If true, only return tiles that * have at least one interesting face. * @param {LayerData} layer - [description] diff --git a/v3/src/gameobjects/tilemap/components/GetTilesWithin.js b/v3/src/gameobjects/tilemap/components/GetTilesWithin.js index 5cdad790b..16597fac6 100644 --- a/v3/src/gameobjects/tilemap/components/GetTilesWithin.js +++ b/v3/src/gameobjects/tilemap/components/GetTilesWithin.js @@ -1,5 +1,3 @@ - - var GetFastValue = require('../../../utils/object/GetFastValue'); /** diff --git a/v3/src/gameobjects/tilemap/parsers/parsetiledjson/index.js b/v3/src/gameobjects/tilemap/parsers/parsetiledjson/index.js index 67a29a54c..2654bcb41 100644 --- a/v3/src/gameobjects/tilemap/parsers/parsetiledjson/index.js +++ b/v3/src/gameobjects/tilemap/parsers/parsetiledjson/index.js @@ -139,7 +139,7 @@ var ParseJSONTiled = function (key, json, insertNull) y: GetFastValue(curi, 'offsety', 0) + curi.y, alpha: curi.opacity, visible: curi.visible, - properties: GetFastValue(curi, "properties", {}) + properties: GetFastValue(curi, 'properties', {}) }); } From 184cfd197904a75e15c419c6e8be72f1462d194e Mon Sep 17 00:00:00 2001 From: Michael Hadley Date: Wed, 29 Nov 2017 11:59:25 -0600 Subject: [PATCH 04/13] When creating a Tilemap layer, use Tiled layer offset if no xy specified --- v3/src/gameobjects/tilemap/Tilemap.js | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/v3/src/gameobjects/tilemap/Tilemap.js b/v3/src/gameobjects/tilemap/Tilemap.js index 6c876ac6a..1dc98da68 100644 --- a/v3/src/gameobjects/tilemap/Tilemap.js +++ b/v3/src/gameobjects/tilemap/Tilemap.js @@ -212,7 +212,7 @@ var Tilemap = new Class({ return sprites; }, - // Creates & selects + // Creates & selects, uses layer offset if x,y undefined createStaticLayer: function (layerID, tileset, x, y) { var index = this.getLayerIndex(layerID); @@ -232,12 +232,16 @@ var Tilemap = new Class({ this.currentLayerIndex = index; + // Default the x/y position to match Tiled layer offset, if it exists. + if (x === undefined && this.layers[index].x) { x = this.layers[index].x; } + if (y === undefined && this.layers[index].y) { y = this.layers[index].y; } + var layer = new StaticTilemapLayer(this.scene, this, index, tileset, x, y); this.scene.sys.displayList.add(layer); return layer; }, - // Creates & selects + // Creates & selects, uses layer offset if x,y undefined createDynamicLayer: function (layerID, tileset, x, y) { var index = this.getLayerIndex(layerID); @@ -257,6 +261,10 @@ var Tilemap = new Class({ this.currentLayerIndex = index; + // Default the x/y position to match Tiled layer offset, if it exists. + if (x === undefined && this.layers[index].x) { x = this.layers[index].x; } + if (y === undefined && this.layers[index].y) { y = this.layers[index].y; } + var layer = new DynamicTilemapLayer(this.scene, this, index, tileset, x, y); this.scene.sys.displayList.add(layer); return layer; From 80a16065e25d5a65205338d419c5d5d9c41990eb Mon Sep 17 00:00:00 2001 From: Michael Hadley Date: Wed, 29 Nov 2017 12:52:34 -0600 Subject: [PATCH 05/13] Update to allow multiple tileset sizes within one map Tileset is source of truth for tile size, so this update makes sure that layers are sync'd with the tileset --- v3/src/gameobjects/tilemap/Tilemap.js | 71 +++++++++++++------ .../dynamiclayer/DynamicTilemapLayer.js | 2 +- .../tilemap/parsers/parsetiledjson/index.js | 4 +- .../tilemap/staticlayer/StaticTilemapLayer.js | 6 +- 4 files changed, 56 insertions(+), 27 deletions(-) diff --git a/v3/src/gameobjects/tilemap/Tilemap.js b/v3/src/gameobjects/tilemap/Tilemap.js index 1dc98da68..492a55bb0 100644 --- a/v3/src/gameobjects/tilemap/Tilemap.js +++ b/v3/src/gameobjects/tilemap/Tilemap.js @@ -44,8 +44,6 @@ var Tilemap = new Class({ { if (tilesetName === undefined) { return null; } if (key === undefined || key === null) { key = tilesetName; } - if (tileWidth === undefined) { tileWidth = this.tileWidth; } - if (tileHeight === undefined) { tileHeight = this.tileHeight; } if (!this.scene.sys.textures.exists(key)) { @@ -71,6 +69,8 @@ var Tilemap = new Class({ return this.tilesets[index]; } + if (tileWidth === undefined) { tileWidth = this.tileWidth; } + if (tileHeight === undefined) { tileHeight = this.tileHeight; } if (tileMargin === undefined) { tileMargin = 0; } if (tileSpacing === undefined) { tileSpacing = 0; } if (gid === undefined) { gid = 0; } @@ -84,8 +84,8 @@ var Tilemap = new Class({ // Creates & selects createBlankDynamicLayer: function (name, tileset, x, y, width, height, tileWidth, tileHeight) { - if (tileWidth === undefined) { tileWidth = this.tileWidth; } - if (tileHeight === undefined) { tileHeight = this.tileHeight; } + if (tileWidth === undefined) { tileWidth = tileset.tileWidth; } + if (tileHeight === undefined) { tileHeight = tileset.tileHeight; } if (width === undefined) { width = this.width; } if (height === undefined) { height = this.height; } if (x === undefined) { x = 0; } @@ -124,6 +124,8 @@ var Tilemap = new Class({ var dynamicLayer = new DynamicTilemapLayer(this.scene, this, this.currentLayerIndex, tileset, x, y); this.scene.sys.displayList.add(dynamicLayer); + this.setTileSize(layerData); + return dynamicLayer; }, @@ -223,8 +225,10 @@ var Tilemap = new Class({ return null; } + var layerData = this.layers[index]; + // Check for an associated static or dynamic tilemap layer - if (this.layers[index].tilemapLayer) + if (layerData.tilemapLayer) { console.warn('Cannot create static tilemap layer since a static or dynamic tilemap layer exists for layer ID:' + layerID); return null; @@ -232,12 +236,21 @@ var Tilemap = new Class({ this.currentLayerIndex = index; + // Make sure that all the LayerData & the tiles have the correct tile size. They usually + // are, but wouldn't match if you try to load a 2x or 4x res tileset when the map was made + // with a 1x res tileset. + if (layerData.tileWidth !== tileset.tileWidth || layerData.tileHeight !== tileset.tileHeight) + { + this.setLayerTileSize(tileset.tileWidth, tileset.tileHeight, index); + } + // Default the x/y position to match Tiled layer offset, if it exists. if (x === undefined && this.layers[index].x) { x = this.layers[index].x; } if (y === undefined && this.layers[index].y) { y = this.layers[index].y; } var layer = new StaticTilemapLayer(this.scene, this, index, tileset, x, y); this.scene.sys.displayList.add(layer); + return layer; }, @@ -252,8 +265,10 @@ var Tilemap = new Class({ return null; } + var layerData = this.layers[index]; + // Check for an associated static or dynamic tilemap layer - if (this.layers[index].tilemapLayer) + if (layerData.tilemapLayer) { console.warn('Cannot create dynamic tilemap layer since a static or dynamic tilemap layer exists for layer ID:' + layerID); return null; @@ -261,12 +276,21 @@ var Tilemap = new Class({ this.currentLayerIndex = index; + // Make sure that all the LayerData & the tiles have the correct tile size. They usually + // are, but wouldn't match if you try to load a 2x or 4x res tileset when the map was made + // with a 1x res tileset. + if (layerData.tileWidth !== tileset.tileWidth || layerData.tileHeight !== tileset.tileHeight) + { + this.setLayerTileSize(tileset.tileWidth, tileset.tileHeight, index); + } + // Default the x/y position to match Tiled layer offset, if it exists. if (x === undefined && this.layers[index].x) { x = this.layers[index].x; } if (y === undefined && this.layers[index].y) { y = this.layers[index].y; } var layer = new DynamicTilemapLayer(this.scene, this, index, tileset, x, y); this.scene.sys.displayList.add(layer); + return layer; }, @@ -598,30 +622,33 @@ var Tilemap = new Class({ return this; }, - setTileSize: function (tileWidth, tileHeight) + setBaseTileSize: function (tileWidth, tileHeight) { this.tileWidth = tileWidth; this.tileHeight = tileHeight; this.widthInPixels = this.width * tileWidth; this.heightInPixels = this.height * tileHeight; + }, - // Update all the layers & tiles - for (var i = 0; i < this.layers.length; i++) + // Sets the tile size for a given layer + setLayerTileSize: function (tileWidth, tileHeight, layer) + { + layer = this.getLayer(layer); + if (layer === null) { return this; } + + layer.tileWidth = tileWidth; + layer.tileHeight = tileHeight; + + var mapData = layer.data; + var mapWidth = layer.width; + var mapHeight = layer.height; + + for (var row = 0; row < mapHeight; ++row) { - this.layers[i].tileWidth = tileWidth; - this.layers[i].tileHeight = tileHeight; - - var mapData = this.layers[i].data; - var mapWidth = this.layers[i].width; - var mapHeight = this.layers[i].height; - - for (var row = 0; row < mapHeight; ++row) + for (var col = 0; col < mapWidth; ++col) { - for (var col = 0; col < mapWidth; ++col) - { - var tile = mapData[row][col]; - if (tile !== null) { tile.setSize(tileWidth, tileHeight); } - } + var tile = mapData[row][col]; + if (tile !== null) { tile.setSize(tileWidth, tileHeight); } } } diff --git a/v3/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayer.js b/v3/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayer.js index fa7ab8bab..745049091 100644 --- a/v3/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayer.js +++ b/v3/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayer.js @@ -44,7 +44,7 @@ var DynamicTilemapLayer = new Class({ this.setPosition(x, y); this.setSizeToFrame(); this.setOrigin(); - this.setSize(this.map.tileWidth * this.layer.width, this.map.tileheight * this.layer.height); + this.setSize(this.layer.tileWidth * this.layer.width, this.layer.tileHeight * this.layer.height); this.skipIndexZero = false; }, diff --git a/v3/src/gameobjects/tilemap/parsers/parsetiledjson/index.js b/v3/src/gameobjects/tilemap/parsers/parsetiledjson/index.js index 2654bcb41..7cd208275 100644 --- a/v3/src/gameobjects/tilemap/parsers/parsetiledjson/index.js +++ b/v3/src/gameobjects/tilemap/parsers/parsetiledjson/index.js @@ -327,9 +327,11 @@ var ParseJSONTiled = function (key, json, insertNull) sid = mapData.tiles[tile.index][2]; set = mapData.tilesets[sid]; + // Ensure that a tile's size matches its tileset + tile.width = set.tileWidth; + tile.height = set.tileHeight; // if that tile type has any properties, add them to the tile object - if (set.tileProperties && set.tileProperties[tile.index - set.firstgid]) { tile.properties = Extend(tile.properties, set.tileProperties[tile.index - set.firstgid]); diff --git a/v3/src/gameobjects/tilemap/staticlayer/StaticTilemapLayer.js b/v3/src/gameobjects/tilemap/staticlayer/StaticTilemapLayer.js index 98d84e336..0e5508b21 100644 --- a/v3/src/gameobjects/tilemap/staticlayer/StaticTilemapLayer.js +++ b/v3/src/gameobjects/tilemap/staticlayer/StaticTilemapLayer.js @@ -53,7 +53,7 @@ var StaticTilemapLayer = new Class({ this.setPosition(x, y); this.setSizeToFrame(); this.setOrigin(); - this.setSize(this.map.tileWidth * this.layer.width, this.map.tileHeight * this.layer.height); + this.setSize(this.layer.tileWidth * this.layer.width, this.layer.tileHeight * this.layer.height); this.skipIndexZero = false; @@ -74,8 +74,8 @@ var StaticTilemapLayer = new Class({ var tileset = this.tileset; var mapWidth = this.layer.width; var mapHeight = this.layer.height; - var tileWidth = this.map.tileWidth; - var tileHeight = this.map.tileHeight; + var tileWidth = this.layer.tileWidth; + var tileHeight = this.layer.tileHeight; var width = this.texture.source[0].width; var height = this.texture.source[0].height; var mapData = this.layer.data; From b8695342e14847b8cd81ef18e430a9a0c85e9562 Mon Sep 17 00:00:00 2001 From: Michael Hadley Date: Wed, 29 Nov 2017 13:22:30 -0600 Subject: [PATCH 06/13] Prefer UK spelling over US: indices -> indexes --- v3/src/gameobjects/tilemap/Tilemap.js | 4 +-- v3/src/gameobjects/tilemap/TilemapCreator.js | 2 +- .../tilemap/components/Randomize.js | 26 +++++++++---------- .../gameobjects/tilemap/components/Shuffle.js | 6 ++--- .../dynamiclayer/DynamicTilemapLayer.js | 4 +-- .../tilemap/parsers/parsetiledjson/index.js | 4 +-- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/v3/src/gameobjects/tilemap/Tilemap.js b/v3/src/gameobjects/tilemap/Tilemap.js index 492a55bb0..e0e2eaaa4 100644 --- a/v3/src/gameobjects/tilemap/Tilemap.js +++ b/v3/src/gameobjects/tilemap/Tilemap.js @@ -511,13 +511,13 @@ var Tilemap = new Class({ return TilemapComponents.PutTileAtWorldXY(tile, worldX, worldY, recalculateFaces, camera, layer); }, - randomize: function (tileX, tileY, width, height, indices, layer) + randomize: function (tileX, tileY, width, height, indexes, layer) { layer = this.getLayer(layer); if (this._isStaticCall(layer, 'randomize')) { return this; } if (layer !== null) { - TilemapComponents.Randomize(tileX, tileY, width, height, indices, layer); + TilemapComponents.Randomize(tileX, tileY, width, height, indexes, layer); } return this; }, diff --git a/v3/src/gameobjects/tilemap/TilemapCreator.js b/v3/src/gameobjects/tilemap/TilemapCreator.js index 9a91af28e..d6ddcf625 100644 --- a/v3/src/gameobjects/tilemap/TilemapCreator.js +++ b/v3/src/gameobjects/tilemap/TilemapCreator.js @@ -11,7 +11,7 @@ GameObjectCreator.register('tilemap', function (config) // tileHeight: 32, // width: 10, // height: 10, - // data: null (2D array of tile indices), + // data: null (2D array of tile indexes), // insertNull: false // } diff --git a/v3/src/gameobjects/tilemap/components/Randomize.js b/v3/src/gameobjects/tilemap/components/Randomize.js index bd99558e7..af8ada9e3 100644 --- a/v3/src/gameobjects/tilemap/components/Randomize.js +++ b/v3/src/gameobjects/tilemap/components/Randomize.js @@ -2,40 +2,40 @@ var GetTilesWithin = require('./GetTilesWithin'); var GetRandomElement = require('../../../utils/array/GetRandomElement'); /** - * Randomizes the indices of a rectangular region of tiles (in tile coordinates) within the - * specified layer. Each tile will recieve a new index. If an array of indices is passed in, then - * those will be used for randomly assigning new tile indices. If an array is not provided, the - * indices found within the region (excluding -1) will be used for randomly assigning new tile - * indices. This method only modifies tile indexes and does not change collision information. + * Randomizes the indexes of a rectangular region of tiles (in tile coordinates) within the + * specified layer. Each tile will recieve a new index. If an array of indexes is passed in, then + * those will be used for randomly assigning new tile indexes. If an array is not provided, the + * indexes found within the region (excluding -1) will be used for randomly assigning new tile + * indexes. This method only modifies tile indexes and does not change collision information. * * @param {number} [tileX=0] - [description] * @param {number} [tileY=0] - [description] * @param {number} [width=max width based on tileX] - [description] * @param {number} [height=max height based on tileY] - [description] - * @param {array} [indices] - An array of indices to randomly draw from during randomization. + * @param {array} [indexes] - An array of indexes to randomly draw from during randomization. * @param {LayerData} layer - [description] */ -var Randomize = function (tileX, tileY, width, height, indices, layer) +var Randomize = function (tileX, tileY, width, height, indexes, layer) { var i; var tiles = GetTilesWithin(tileX, tileY, width, height, null, layer); - // If no indicies are given, then find all the unique indices within the specified region - if (indices === undefined) + // If no indicies are given, then find all the unique indexes within the specified region + if (indexes === undefined) { - indices = []; + indexes = []; for (i = 0; i < tiles.length; i++) { - if (indices.indexOf(tiles[i].index) === -1) + if (indexes.indexOf(tiles[i].index) === -1) { - indices.push(tiles[i].index); + indexes.push(tiles[i].index); } } } for (i = 0; i < tiles.length; i++) { - tiles[i].index = GetRandomElement(indices); + tiles[i].index = GetRandomElement(indexes); } }; diff --git a/v3/src/gameobjects/tilemap/components/Shuffle.js b/v3/src/gameobjects/tilemap/components/Shuffle.js index 4dc39a258..76039b94f 100644 --- a/v3/src/gameobjects/tilemap/components/Shuffle.js +++ b/v3/src/gameobjects/tilemap/components/Shuffle.js @@ -17,12 +17,12 @@ var Shuffle = function (tileX, tileY, width, height, layer) { var tiles = GetTilesWithin(tileX, tileY, width, height, null, layer); - var indices = tiles.map(function (tile) { return tile.index; }); - ShuffleArray(indices); + var indexes = tiles.map(function (tile) { return tile.index; }); + ShuffleArray(indexes); for (var i = 0; i < tiles.length; i++) { - tiles[i].index = indices[i]; + tiles[i].index = indexes[i]; } }; diff --git a/v3/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayer.js b/v3/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayer.js index 745049091..d97ca856a 100644 --- a/v3/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayer.js +++ b/v3/src/gameobjects/tilemap/dynamiclayer/DynamicTilemapLayer.js @@ -149,9 +149,9 @@ var DynamicTilemapLayer = new Class({ return TilemapComponents.PutTileAtWorldXY(tile, worldX, worldY, recalculateFaces, camera, this.layer); }, - randomize: function (tileX, tileY, width, height, indices) + randomize: function (tileX, tileY, width, height, indexes) { - TilemapComponents.Randomize(tileX, tileY, width, height, indices, this.layer); + TilemapComponents.Randomize(tileX, tileY, width, height, indexes, this.layer); return this; }, diff --git a/v3/src/gameobjects/tilemap/parsers/parsetiledjson/index.js b/v3/src/gameobjects/tilemap/parsers/parsetiledjson/index.js index 7cd208275..c94031e11 100644 --- a/v3/src/gameobjects/tilemap/parsers/parsetiledjson/index.js +++ b/v3/src/gameobjects/tilemap/parsers/parsetiledjson/index.js @@ -159,13 +159,13 @@ var ParseJSONTiled = function (key, json, insertNull) { var newSet = new Tileset(set.name, set.firstgid, set.tilewidth, set.tileheight, set.margin, set.spacing, set.properties); - // Properties stored per-tile in object with string indices starting at "0" + // Properties stored per-tile in object with string indexes starting at "0" if (set.tileproperties) { newSet.tileProperties = set.tileproperties; } - // Object & terrain shapes stored per-tile in object with string indices starting at "0" + // Object & terrain shapes stored per-tile in object with string indexes starting at "0" if (set.tiles) { newSet.tileData = set.tiles; From f0e59b3d3dee0c077d43379e5ca0080636a04bd6 Mon Sep 17 00:00:00 2001 From: Michael Hadley Date: Wed, 29 Nov 2017 13:23:01 -0600 Subject: [PATCH 07/13] Blank Layer: remove unnecessary setting of tile size --- v3/src/gameobjects/tilemap/Tilemap.js | 2 -- 1 file changed, 2 deletions(-) diff --git a/v3/src/gameobjects/tilemap/Tilemap.js b/v3/src/gameobjects/tilemap/Tilemap.js index e0e2eaaa4..0b845f8f5 100644 --- a/v3/src/gameobjects/tilemap/Tilemap.js +++ b/v3/src/gameobjects/tilemap/Tilemap.js @@ -124,8 +124,6 @@ var Tilemap = new Class({ var dynamicLayer = new DynamicTilemapLayer(this.scene, this, this.currentLayerIndex, tileset, x, y); this.scene.sys.displayList.add(dynamicLayer); - this.setTileSize(layerData); - return dynamicLayer; }, From 382d8edfcc683de85e02451b2341e7b5390d2f70 Mon Sep 17 00:00:00 2001 From: Michael Hadley Date: Wed, 29 Nov 2017 13:46:29 -0600 Subject: [PATCH 08/13] Jsdocs: Tilemap Creator & Factor --- v3/src/gameobjects/tilemap/TilemapCreator.js | 34 +++++++++++++------- v3/src/gameobjects/tilemap/TilemapFactory.js | 30 ++++++++++++++--- 2 files changed, 48 insertions(+), 16 deletions(-) diff --git a/v3/src/gameobjects/tilemap/TilemapCreator.js b/v3/src/gameobjects/tilemap/TilemapCreator.js index d6ddcf625..24d94d3da 100644 --- a/v3/src/gameobjects/tilemap/TilemapCreator.js +++ b/v3/src/gameobjects/tilemap/TilemapCreator.js @@ -3,18 +3,30 @@ var ParseToTilemap = require('./ParseToTilemap'); // When registering a factory function 'this' refers to the GameObjectCreator context. +/** + * Creates a Tilemap from the given key or data, or creates a blank Tilemap if no key/data provided. + * + * @param {object} [config] - The config options for the Tilemap. + * @param {string} [config.key] - The key in the Phaser cache that corresponds to the loaded tilemap + * data. + * @param {array} [config.data] - Instead of loading from the cache, you can also load directly from + * a 2D array of tile indexes. + * @param {number} [config.tileWidth=32] - The width of a tile in pixels. + * @param {number} [config.tileHeight=32] - The height of a tile in pixels. + * @param {number} [config.width=10] - The width of the map in tiles. + * @param {number} [config.height=10] - The height of the map in tiles. + * @param {boolean} [config.insertNull=false] - Controls how empty tiles, tiles with an index of -1, + * in the map data are handled. If `true`, empty locations will get a value of `null`. If `false`, + * empty location will get a Tile object with an index of -1. If you've a large sparsely populated + * map and the tile data doesn't need to change then setting this value to `true` will help with + * memory consumption. However if your map is small or you need to update the tiles dynamically, + * then leave the default value set. + * @returns {Tilemap} + */ GameObjectCreator.register('tilemap', function (config) { - // config { - // key: undefined, (string|number), - // tileWidth: 32, - // tileHeight: 32, - // width: 10, - // height: 10, - // data: null (2D array of tile indexes), - // insertNull: false - // } - + // Defaults are applied in ParseToTilemap var c = config !== undefined ? config : {}; - return ParseToTilemap(this.scene, c.key, c.tileWidth, c.tileHeight, c.width, c.height, c.data, c.insertNull); + return ParseToTilemap(this.scene, c.key, c.tileWidth, c.tileHeight, c.width, c.height, c.data, + c.insertNull); }); diff --git a/v3/src/gameobjects/tilemap/TilemapFactory.js b/v3/src/gameobjects/tilemap/TilemapFactory.js index ae57ff7e8..95658b1fd 100644 --- a/v3/src/gameobjects/tilemap/TilemapFactory.js +++ b/v3/src/gameobjects/tilemap/TilemapFactory.js @@ -1,7 +1,6 @@ var GameObjectFactory = require('../../scene/plugins/GameObjectFactory'); var ParseToTilemap = require('./ParseToTilemap'); - // When registering a factory function 'this' refers to the GameObjectFactory context. // // There are several properties available to use: @@ -10,17 +9,38 @@ var ParseToTilemap = require('./ParseToTilemap'); // this.displayList - a reference to the Display List the Scene owns // this.updateList - a reference to the Update List the Scene owns +/** + * Creates a Tilemap from the given key or data, or creates a blank Tilemap if no key/data provided. + * + * @param {string} [key] - The key in the Phaser cache that corresponds to the loaded tilemap data. + * @param {number} [tileWidth=32] - The width of a tile in pixels. Pass in `null` to leave as the + * default. + * @param {number} [tileHeight=32] - The height of a tile in pixels. Pass in `null` to leave as the + * default. + * @param {number} [width=10] - The width of the map in tiles. Pass in `null` to leave as the + * default. + * @param {number} [height=10] - The height of the map in tiles. Pass in `null` to leave as the + * default. + * @param {array} [data] - Instead of loading from the cache, you can also load directly from a 2D + * array of tile indexes. Pass in `null` for no data. + * @param {boolean} [insertNull=false] - Controls how empty tiles, tiles with an index of -1, in the + * map data are handled. If `true`, empty locations will get a value of `null`. If `false`, empty + * location will get a Tile object with an index of -1. If you've a large sparsely populated map and + * the tile data doesn't need to change then setting this value to `true` will help with memory + * consumption. However if your map is small or you need to update the tiles dynamically, then leave + * the default value set. + * @returns {Tilemap} + */ GameObjectFactory.register('tilemap', function (key, tileWidth, tileHeight, width, height, data, insertNull) { - // Allow users to specify null as default parameter, but convert it to undefined to match what - // the creator function passed to the parser. + // Allow users to specify null to indicate that they want the default value, since null is + // shorter & more legible than undefined. Convert null to undefined to allow ParseToTilemap + // defaults to take effect. if (key === null) { key = undefined; } if (tileWidth === null) { tileWidth = undefined; } if (tileHeight === null) { tileHeight = undefined; } if (width === null) { width = undefined; } if (height === null) { height = undefined; } - if (data === null) { data = undefined; } - if (insertNull === null) { insertNull = undefined; } return ParseToTilemap(this.scene, key, tileWidth, tileHeight, width, height, data, insertNull); }); From 0ee08b76a81f0a7d47f089cfd9873c1e432d239e Mon Sep 17 00:00:00 2001 From: Michael Hadley Date: Wed, 29 Nov 2017 13:53:05 -0600 Subject: [PATCH 09/13] Jsdocs: ParseToTilemap --- v3/src/gameobjects/tilemap/ParseToTilemap.js | 23 +++++++++++++++++++- v3/src/gameobjects/tilemap/TilemapCreator.js | 5 ++++- v3/src/gameobjects/tilemap/TilemapFactory.js | 3 +++ 3 files changed, 29 insertions(+), 2 deletions(-) diff --git a/v3/src/gameobjects/tilemap/ParseToTilemap.js b/v3/src/gameobjects/tilemap/ParseToTilemap.js index 8879aea19..32e90707e 100644 --- a/v3/src/gameobjects/tilemap/ParseToTilemap.js +++ b/v3/src/gameobjects/tilemap/ParseToTilemap.js @@ -3,7 +3,28 @@ var Parse = require('./parsers/Parse'); var MapData = require('./mapdata/MapData'); var Tilemap = require('./Tilemap'); -// Parse from key or data and create a Tilemap. If neither is given, make an empty Tilemap. +/** + * Create a Tilemap from the given key or data. If neither is given, make a blank Tilemap. When + * loading from CSV or a 2D array, you should specify the tileWidth & tileHeight. When parsing from + * a map from Tiled, the tileWidth, tileHeight, width & height will be pulled from the map data. For + * an empty map, you should specify tileWidth, tileHeight, width & height. + * + * @param {Scene} scene - [description] + * @param {string} [key] - The key in the Phaser cache that corresponds to the loaded tilemap data. + * @param {number} [tileWidth=32] - The width of a tile in pixels. + * @param {number} [tileHeight=32] - The height of a tile in pixels. + * @param {number} [width=10] - The width of the map in tiles. + * @param {number} [height=10] - The height of the map in tiles. + * @param {array} [data] - Instead of loading from the cache, you can also load directly from a 2D + * array of tile indexes. + * @param {boolean} [insertNull=false] - Controls how empty tiles, tiles with an index of -1, in the + * map data are handled. If `true`, empty locations will get a value of `null`. If `false`, empty + * location will get a Tile object with an index of -1. If you've a large sparsely populated map and + * the tile data doesn't need to change then setting this value to `true` will help with memory + * consumption. However if your map is small or you need to update the tiles dynamically, then leave + * the default value set. + * @returns {Tilemap} + */ var ParseToTilemap = function (scene, key, tileWidth, tileHeight, width, height, data, insertNull) { if (tileWidth === undefined) { tileWidth = 32; } diff --git a/v3/src/gameobjects/tilemap/TilemapCreator.js b/v3/src/gameobjects/tilemap/TilemapCreator.js index 24d94d3da..de17581d0 100644 --- a/v3/src/gameobjects/tilemap/TilemapCreator.js +++ b/v3/src/gameobjects/tilemap/TilemapCreator.js @@ -4,7 +4,10 @@ var ParseToTilemap = require('./ParseToTilemap'); // When registering a factory function 'this' refers to the GameObjectCreator context. /** - * Creates a Tilemap from the given key or data, or creates a blank Tilemap if no key/data provided. + * Creates a Tilemap from the given key or data, or creates a blank Tilemap if no key/data + * provided. When loading from CSV or a 2D array, you should specify the tileWidth & tileHeight. When + * parsing from a map from Tiled, the tileWidth, tileHeight, width & height will be pulled from the + * map data. For an empty map, you should specify tileWidth, tileHeight, width & height. * * @param {object} [config] - The config options for the Tilemap. * @param {string} [config.key] - The key in the Phaser cache that corresponds to the loaded tilemap diff --git a/v3/src/gameobjects/tilemap/TilemapFactory.js b/v3/src/gameobjects/tilemap/TilemapFactory.js index 95658b1fd..6c4e482f7 100644 --- a/v3/src/gameobjects/tilemap/TilemapFactory.js +++ b/v3/src/gameobjects/tilemap/TilemapFactory.js @@ -11,6 +11,9 @@ var ParseToTilemap = require('./ParseToTilemap'); /** * Creates a Tilemap from the given key or data, or creates a blank Tilemap if no key/data provided. + * When loading from CSV or a 2D array, you should specify the tileWidth & tileHeight. When parsing + * from a map from Tiled, the tileWidth, tileHeight, width & height will be pulled from the map + * data. For an empty map, you should specify tileWidth, tileHeight, width & height. * * @param {string} [key] - The key in the Phaser cache that corresponds to the loaded tilemap data. * @param {number} [tileWidth=32] - The width of a tile in pixels. Pass in `null` to leave as the From 5f3156e2b8233d2b3ac4fb7cf0291a865ce0ecc4 Mon Sep 17 00:00:00 2001 From: Michael Hadley Date: Wed, 29 Nov 2017 14:02:45 -0600 Subject: [PATCH 10/13] Jsdocs: Tilemap parsing --- v3/src/gameobjects/tilemap/parsers/Parse.js | 24 ++++++++++++------- .../tilemap/parsers/Parse2DArray.js | 18 ++++++++++++-- .../gameobjects/tilemap/parsers/ParseCSV.js | 18 ++++++++++++-- .../tilemap/parsers/parsetiledjson/index.js | 16 +++++++++++-- 4 files changed, 61 insertions(+), 15 deletions(-) diff --git a/v3/src/gameobjects/tilemap/parsers/Parse.js b/v3/src/gameobjects/tilemap/parsers/Parse.js index 42c85f414..8b5fa2317 100644 --- a/v3/src/gameobjects/tilemap/parsers/Parse.js +++ b/v3/src/gameobjects/tilemap/parsers/Parse.js @@ -5,18 +5,24 @@ var ParseTiledJSON = require('./parsetiledjson/'); var Formats = require('../Formats'); /** - * Parses raw data of a given Tilemap format into a new MapData object. + * Parses raw data of a given Tilemap format into a new MapData object. If no recognized data format + * is found, returns `null`. When loading from CSV or a 2D array, you should specify the tileWidth & + * tileHeight. When parsing from a map from Tiled, the tileWidth & tileHeight will be pulled from + * the map data. * * @param {string} name - The name of the tilemap, used to set the name on the MapData. * @param {number} mapFormat - See ../Formats.js. - * @param {array|string|object} data - 2D array, CSV string or Tiled JSON object - * @param {number} tileWidth - Required for 2D array and CSV, but ignored for Tiled JSON. - * @param {number} tileHeight - Required for 2D array and CSV, but ignored for Tiled JSON. - * @param {boolean} [insertNull=false] - If true, instead of placing empty tiles at locations where - * the tile index is -1, this will place null. If you've a large sparsely populated map and the tile - * data doesn't need to change then setting this value to `true` will help with memory consumption. - * However if your map is small, or you need to update the tiles (perhaps the map dynamically - * changes during the game) then leave the default value set. + * @param {array|string|object} data - 2D array, CSV string or Tiled JSON object. + * @param {number} tileWidth - The width of a tile in pixels. Required for 2D array and CSV, but + * ignored for Tiled JSON. + * @param {number} tileHeight - The height of a tile in pixels. Required for 2D array and CSV, but + * ignored for Tiled JSON. + * @param {boolean} insertNull - Controls how empty tiles, tiles with an index of -1, in the map + * data are handled. If `true`, empty locations will get a value of `null`. If `false`, empty + * location will get a Tile object with an index of -1. If you've a large sparsely populated map and + * the tile data doesn't need to change then setting this value to `true` will help with memory + * consumption. However if your map is small or you need to update the tiles dynamically, then leave + * the default value set. */ var Parse = function (name, mapFormat, data, tileWidth, tileHeight, insertNull) { diff --git a/v3/src/gameobjects/tilemap/parsers/Parse2DArray.js b/v3/src/gameobjects/tilemap/parsers/Parse2DArray.js index d8fc6cb8f..4b6e53a05 100644 --- a/v3/src/gameobjects/tilemap/parsers/Parse2DArray.js +++ b/v3/src/gameobjects/tilemap/parsers/Parse2DArray.js @@ -3,7 +3,21 @@ var LayerData = require('../mapdata/LayerData'); var Formats = require('../Formats'); var Tile = require('../Tile'); -var Parse2DArray = function (key, data, tileWidth, tileHeight, insertNull) +/** + * Parses a 2D array of tile indexes into a new MapData object with a single layer. + * + * @param {string} name - The name of the tilemap, used to set the name on the MapData. + * @param {array} data - 2D array, CSV string or Tiled JSON object. + * @param {number} tileWidth - The width of a tile in pixels. + * @param {number} tileHeight - The height of a tile in pixels. + * @param {boolean} insertNull - Controls how empty tiles, tiles with an index of -1, in the map + * data are handled. If `true`, empty locations will get a value of `null`. If `false`, empty + * location will get a Tile object with an index of -1. If you've a large sparsely populated map and + * the tile data doesn't need to change then setting this value to `true` will help with memory + * consumption. However if your map is small or you need to update the tiles dynamically, then leave + * the default value set. + */ +var Parse2DArray = function (name, data, tileWidth, tileHeight, insertNull) { var layerData = new LayerData({ tileWidth: tileWidth, @@ -11,7 +25,7 @@ var Parse2DArray = function (key, data, tileWidth, tileHeight, insertNull) }); var mapData = new MapData({ - name: key, + name: name, tileWidth: tileWidth, tileHeight: tileHeight, format: Formats.TILEMAP_2D_ARRAY, diff --git a/v3/src/gameobjects/tilemap/parsers/ParseCSV.js b/v3/src/gameobjects/tilemap/parsers/ParseCSV.js index 4b2320535..6c143250c 100644 --- a/v3/src/gameobjects/tilemap/parsers/ParseCSV.js +++ b/v3/src/gameobjects/tilemap/parsers/ParseCSV.js @@ -1,14 +1,28 @@ var Formats = require('../Formats'); var Parse2DArray = require('./Parse2DArray'); -var ParseCSV = function (key, data, tileWidth, tileHeight, insertNull) +/** + * Parses a CSV string of tile indexes into a new MapData object with a single layer. + * + * @param {string} name - The name of the tilemap, used to set the name on the MapData. + * @param {string} data - CSV string of tile indexes. + * @param {number} tileWidth - The width of a tile in pixels. + * @param {number} tileHeight - The height of a tile in pixels. + * @param {boolean} insertNull - Controls how empty tiles, tiles with an index of -1, in the map + * data are handled. If `true`, empty locations will get a value of `null`. If `false`, empty + * location will get a Tile object with an index of -1. If you've a large sparsely populated map and + * the tile data doesn't need to change then setting this value to `true` will help with memory + * consumption. However if your map is small or you need to update the tiles dynamically, then leave + * the default value set. + */ +var ParseCSV = function (name, data, tileWidth, tileHeight, insertNull) { var array2D = data .trim() .split('\n') .map(function (row) { return row.split(','); }); - var map = Parse2DArray(key, array2D, tileWidth, tileHeight, insertNull); + var map = Parse2DArray(name, array2D, tileWidth, tileHeight, insertNull); map.format = Formats.TILEMAP_CSV; return map; diff --git a/v3/src/gameobjects/tilemap/parsers/parsetiledjson/index.js b/v3/src/gameobjects/tilemap/parsers/parsetiledjson/index.js index c94031e11..54c630a97 100644 --- a/v3/src/gameobjects/tilemap/parsers/parsetiledjson/index.js +++ b/v3/src/gameobjects/tilemap/parsers/parsetiledjson/index.js @@ -10,7 +10,19 @@ var ParseGID = require('./ParseGID'); var Base64Decode = require('./Base64Decode'); var ParseObject = require('./ParseObject'); -var ParseJSONTiled = function (key, json, insertNull) +/** + * Parses a Tiled JSON object into a new MapData object. + * + * @param {string} name - The name of the tilemap, used to set the name on the MapData. + * @param {object} json - The Tiled JSON object. + * @param {boolean} insertNull - Controls how empty tiles, tiles with an index of -1, in the map + * data are handled. If `true`, empty locations will get a value of `null`. If `false`, empty + * location will get a Tile object with an index of -1. If you've a large sparsely populated map and + * the tile data doesn't need to change then setting this value to `true` will help with memory + * consumption. However if your map is small or you need to update the tiles dynamically, then leave + * the default value set. + */ +var ParseJSONTiled = function (name, json, insertNull) { if (json.orientation !== 'orthogonal') { @@ -22,7 +34,7 @@ var ParseJSONTiled = function (key, json, insertNull) var mapData = new MapData({ width: json.width, height: json.height, - name: key, + name: name, tileWidth: json.tilewidth, tileHeight: json.tileheight, orientation: json.orientation, From 191f621dad8d1e843a96227c1303e2d4cdac4783 Mon Sep 17 00:00:00 2001 From: Michael Hadley Date: Wed, 29 Nov 2017 14:39:30 -0600 Subject: [PATCH 11/13] Jsdocs: Tileset --- v3/src/gameobjects/tilemap/Tileset.js | 179 ++++++++++++++++-- .../tilemap/parsers/parsetiledjson/index.js | 2 +- 2 files changed, 168 insertions(+), 13 deletions(-) diff --git a/v3/src/gameobjects/tilemap/Tileset.js b/v3/src/gameobjects/tilemap/Tileset.js index 803d0a453..09f1b497b 100644 --- a/v3/src/gameobjects/tilemap/Tileset.js +++ b/v3/src/gameobjects/tilemap/Tileset.js @@ -4,48 +4,155 @@ var Tileset = new Class({ initialize: - function Tileset (name, firstgid, tileWidth, tileHeight, tileMargin, tileSpacing, properties, tileData) + /** + * A Tileset is a combination of an image containing the tiles and a container for data about + * each tile. + * + * @class MapData + * @constructor + * + * @param {string} name - The name of the tileset in the map data. + * @param {integer} firstgid - The first tile index this tileset contains. + * @param {integer} [tileWidth=32] - Width of each tile (in pixels). + * @param {integer} [tileHeight=32] - Height of each tile (in pixels). + * @param {integer} [tileMargin=0] - The margin around all tiles in the sheet (in pixels). + * @param {integer} [tileSpacing=0] - The spacing between each tile in the sheet (in pixels). + * @param {object} [tileProperties={}] - Custom properties defined per tile in the Tileset. + * These typically are custom properties created in Tiled when editing a tileset. + * @param {object} [tileData={}] - Data stored per tile. These typically are created in Tiled + * when editing a tileset, e.g. from Tiled's tile collision editor or terrain editor. + */ + function Tileset (name, firstgid, tileWidth, tileHeight, tileMargin, tileSpacing, tileProperties, tileData) { if (tileWidth === undefined || tileWidth <= 0) { tileWidth = 32; } if (tileHeight === undefined || tileHeight <= 0) { tileHeight = 32; } if (tileMargin === undefined) { tileMargin = 0; } if (tileSpacing === undefined) { tileSpacing = 0; } - if (properties === undefined) { properties = {}; } + if (tileProperties === undefined) { tileProperties = {}; } if (tileData === undefined) { tileData = {}; } + /** + * The name of the Tileset. + * @property {string} name + */ this.name = name; + + /** + * The starting index of the first tile index this Tileset contains. + * @property {integer} firstgid + */ this.firstgid = firstgid; + + /** + * The width of each tile (in pixels). Use setTileSize to change. + * @property {integer} tileWidth + * @readonly + */ this.tileWidth = tileWidth; + + /** + * The height of each tile (in pixels). Use setTileSize to change. + * @property {integer} tileHeight + * @readonly + */ this.tileHeight = tileHeight; + + /** + * The margin around the tiles in the sheet (in pixels). Use `setSpacing` to change. + * @property {integer} tileMargin + * @readonly + */ this.tileMargin = tileMargin; + + /** + * The spacing between each the tile in the sheet (in pixels). Use `setSpacing` to change. + * @property {integer} tileSpacing + * @readonly + */ this.tileSpacing = tileSpacing; - this.properties = properties; + + /** + * Tileset-specific properties per tile that are typically defined in the Tiled editor. + * @property {object} tileProperties + */ + this.tileProperties = tileProperties; + + /** + * Tileset-specific data per tile that are typically defined in the Tiled editor. This is + * where collision objects and terrain are stored. + * @property {object} tileData + */ this.tileData = tileData; + + /** + * The cached image that contains the individual tiles. Use setImage to set. + * @property {Texture|null} image + * @readonly + */ this.image = null; + + /** + * The number of tile rows in the the tileset. + * @property {integer} rows + * @readonly + */ this.rows = 0; + + /** + * The number of tile columns in the tileset. + * @property {integer} columns + * @readonly + */ this.columns = 0; + + /** + * The total number of tiles in the tileset. + * @property {integer} total + * @readonly + */ this.total = 0; + + /** + * The look-up table to specific tile image texture coordinates (UV in pixels). Each element + * contains the coordinates for a tile in an object of the form {x, y}. + * @property {array} texCoordinates + * @readonly + */ this.texCoordinates = []; }, + /** + * Get a tile's properties that are stored in the Tileset. Returns null if tile index is not + * contained in this Tileset. + * + * @param {integer} tileIndex - The unique id of the tile across all tilesets in the map. + * @returns {object|undefined|null} + */ getTileProperty: function (tileIndex) { if (!this.containsTileIndex(tileIndex)) { return null; } - return this.properties[tileIndex - this.firstgid]; + return this.tileProperties[tileIndex - this.firstgid]; }, + /** + * Get a tile's data that is stored in the Tileset. Returns null if tile index is not + * contained in this Tileset. + * + * @param {integer} tileIndex - The unique id of the tile across all tilesets in the map. + * @returns {object|undefined|null} + */ getTileData: function (tileIndex) { if (!this.containsTileIndex(tileIndex)) { return null; } return this.tileData[tileIndex - this.firstgid]; }, - setImage: function (texture) - { - this.image = texture; - this.updateTileData(this.image.source[0].width, this.image.source[0].height); - }, - + /** + * Returns true if and only if this Tileset contains the given tile index. + * + * @param {integer} tileIndex - The unique id of the tile across all tilesets in the map. + * @returns {boolean} + */ containsTileIndex: function (tileIndex) { return ( @@ -54,12 +161,40 @@ var Tileset = new Class({ ); }, + /** + * Returns the texture coordinates (UV in pixels) in the Tileset image for the given tile index. + * Returns null if tile index is not contained in this Tileset. + * + * @param {integer} tileIndex - The unique id of the tile across all tilesets in the map. + * @returns {object|null} Object in the form { x, y } representing the top-left UV coordinate + * within the Tileset image. + */ getTileTextureCoordinates: function (tileIndex) { if (!this.containsTileIndex(tileIndex)) { return null; } return this.texCoordinates[tileIndex - this.firstgid]; }, + /** + * Sets the image associated with this Tileset and updates the tile data (rows, columns, etc.). + * + * @param {Texture} texture - The image that contains the tiles. + * @returns {this} + */ + setImage: function (texture) + { + this.image = texture; + this.updateTileData(this.image.source[0].width, this.image.source[0].height); + return this; + }, + + /** + * Sets the tile width & height and updates the tile data (rows, columns, etc.). + * + * @param {integer} [tileWidth] - The width of a tile in pixels. + * @param {integer} [tileHeight] - The height of a tile in pixels. + * @returns {this} + */ setTileSize: function (tileWidth, tileHeight) { if (tileWidth !== undefined) { this.tileWidth = tileWidth; } @@ -69,8 +204,17 @@ var Tileset = new Class({ { this.updateTileData(this.image.source[0].width, this.image.source[0].height); } + + return this; }, + /** + * Sets the tile margin & spacing and updates the tile data (rows, columns, etc.). + * + * @param {integer} [margin] - The margin around the tiles in the sheet (in pixels). + * @param {integer} [spacing] - The spacing between the tiles in the sheet (in pixels). + * @returns {this} + */ setSpacing: function (margin, spacing) { if (margin !== undefined) { this.tileMargin = margin; } @@ -80,8 +224,17 @@ var Tileset = new Class({ { this.updateTileData(this.image.source[0].width, this.image.source[0].height); } + + return this; }, + /** + * Updates tile texture coordinates and tileset data. + * + * @param {integer} imageWidth - The (expected) width of the image to slice. + * @param {integer} imageHeight - The (expected) height of the image to slice. + * @returns {this} + */ updateTileData: function (imageWidth, imageHeight) { var rowCount = (imageHeight - this.tileMargin * 2 + this.tileSpacing) / (this.tileHeight + this.tileSpacing); @@ -92,8 +245,8 @@ var Tileset = new Class({ console.warn('Tileset ' + this.name + ' image tile area is not an even multiple of tile size'); } - // In Tiled a tileset image that is not an even multiple of the tile dimensions - // is truncated - hence the floor when calculating the rows/columns. + // In Tiled a tileset image that is not an even multiple of the tile dimensions is truncated + // - hence the floor when calculating the rows/columns. rowCount = Math.floor(rowCount); colCount = Math.floor(colCount); @@ -119,6 +272,8 @@ var Tileset = new Class({ tx = this.tileMargin; ty += this.tileHeight + this.tileSpacing; } + + return this; } }); diff --git a/v3/src/gameobjects/tilemap/parsers/parsetiledjson/index.js b/v3/src/gameobjects/tilemap/parsers/parsetiledjson/index.js index 54c630a97..51dd6d4d2 100644 --- a/v3/src/gameobjects/tilemap/parsers/parsetiledjson/index.js +++ b/v3/src/gameobjects/tilemap/parsers/parsetiledjson/index.js @@ -169,7 +169,7 @@ var ParseJSONTiled = function (name, json, insertNull) if (set.image) { - var newSet = new Tileset(set.name, set.firstgid, set.tilewidth, set.tileheight, set.margin, set.spacing, set.properties); + var newSet = new Tileset(set.name, set.firstgid, set.tilewidth, set.tileheight, set.margin, set.spacing); // Properties stored per-tile in object with string indexes starting at "0" if (set.tileproperties) From a76e270c785c5e90f9e1cade2b84b0423e12cc2a Mon Sep 17 00:00:00 2001 From: Michael Hadley Date: Wed, 29 Nov 2017 15:07:56 -0600 Subject: [PATCH 12/13] Jsdoc fixup: Number -> Integer, array -> Type[] --- v3/src/gameobjects/tilemap/ParseToTilemap.js | 12 +++++------ v3/src/gameobjects/tilemap/Tilemap.js | 8 ++++---- v3/src/gameobjects/tilemap/TilemapCreator.js | 20 +++++++++---------- v3/src/gameobjects/tilemap/TilemapFactory.js | 12 +++++------ v3/src/gameobjects/tilemap/Tileset.js | 4 ++-- .../components/CalculateFacesWithin.js | 8 ++++---- v3/src/gameobjects/tilemap/components/Copy.js | 14 ++++++------- .../tilemap/components/CreateFromTiles.js | 6 +++--- .../tilemap/components/CullTiles.js | 2 +- v3/src/gameobjects/tilemap/components/Fill.js | 10 +++++----- .../tilemap/components/FilterTiles.js | 14 ++++++------- .../tilemap/components/FindByIndex.js | 6 +++--- .../tilemap/components/ForEachTile.js | 12 +++++------ .../tilemap/components/GetTileAt.js | 4 ++-- .../tilemap/components/GetTilesWithin.js | 10 +++++----- .../tilemap/components/GetTilesWithinShape.js | 2 +- .../components/GetTilesWithinWorldXY.js | 2 +- .../tilemap/components/HasTileAt.js | 4 ++-- .../tilemap/components/IsInLayerBounds.js | 4 ++-- .../tilemap/components/PutTileAt.js | 6 +++--- .../tilemap/components/PutTileAtWorldXY.js | 6 +++--- .../tilemap/components/Randomize.js | 10 +++++----- .../tilemap/components/RecalculateFacesAt.js | 4 ++-- .../tilemap/components/RemoveTileAt.js | 6 +++--- .../tilemap/components/RemoveTileAtWorldXY.js | 2 +- .../tilemap/components/ReplaceByIndex.js | 12 +++++------ .../tilemap/components/SetCollision.js | 2 +- .../tilemap/components/SetCollisionBetween.js | 4 ++-- .../components/SetCollisionByExclusion.js | 2 +- .../components/SetLayerCollisionIndex.js | 2 +- .../components/SetTileIndexCallback.js | 2 +- .../components/SetTileLocationCallback.js | 8 ++++---- .../gameobjects/tilemap/components/Shuffle.js | 8 ++++---- .../tilemap/components/SwapByIndex.js | 12 +++++------ .../tilemap/components/TileToWorldX.js | 2 +- .../tilemap/components/TileToWorldY.js | 2 +- v3/src/gameobjects/tilemap/parsers/Parse.js | 8 ++++---- .../tilemap/parsers/Parse2DArray.js | 6 +++--- .../gameobjects/tilemap/parsers/ParseCSV.js | 4 ++-- 39 files changed, 131 insertions(+), 131 deletions(-) diff --git a/v3/src/gameobjects/tilemap/ParseToTilemap.js b/v3/src/gameobjects/tilemap/ParseToTilemap.js index 32e90707e..d41d5e6a8 100644 --- a/v3/src/gameobjects/tilemap/ParseToTilemap.js +++ b/v3/src/gameobjects/tilemap/ParseToTilemap.js @@ -11,12 +11,12 @@ var Tilemap = require('./Tilemap'); * * @param {Scene} scene - [description] * @param {string} [key] - The key in the Phaser cache that corresponds to the loaded tilemap data. - * @param {number} [tileWidth=32] - The width of a tile in pixels. - * @param {number} [tileHeight=32] - The height of a tile in pixels. - * @param {number} [width=10] - The width of the map in tiles. - * @param {number} [height=10] - The height of the map in tiles. - * @param {array} [data] - Instead of loading from the cache, you can also load directly from a 2D - * array of tile indexes. + * @param {integer} [tileWidth=32] - The width of a tile in pixels. + * @param {integer} [tileHeight=32] - The height of a tile in pixels. + * @param {integer} [width=10] - The width of the map in tiles. + * @param {integer} [height=10] - The height of the map in tiles. + * @param {integer[][]} [data] - Instead of loading from the cache, you can also load directly from + * a 2D array of tile indexes. * @param {boolean} [insertNull=false] - Controls how empty tiles, tiles with an index of -1, in the * map data are handled. If `true`, empty locations will get a value of `null`. If `false`, empty * location will get a Tile object with an index of -1. If you've a large sparsely populated map and diff --git a/v3/src/gameobjects/tilemap/Tilemap.js b/v3/src/gameobjects/tilemap/Tilemap.js index 0b845f8f5..3db52d1b3 100644 --- a/v3/src/gameobjects/tilemap/Tilemap.js +++ b/v3/src/gameobjects/tilemap/Tilemap.js @@ -134,13 +134,13 @@ var Tilemap = new Class({ * property of alpha: 0.5 in the map editor will duplicate that when the Sprite is created. * * @param {string} name - The name of the object layer (from Tiled) to create Sprites from. - * @param {number} id - Either the id (object), gid (tile object) or name (object or tile - * object) from Tiled. Ids are unique in Tiled, but a gid is shared by all tile objects with the - * same graphic. The same name can be used on multiple objects. + * @param {integer|string} id - Either the id (object), gid (tile object) or name (object or + * tile object) from Tiled. Ids are unique in Tiled, but a gid is shared by all tile objects + * with the same graphic. The same name can be used on multiple objects. * @param {object} spriteConfig - The config object to pass into the Sprite creator (i.e. * scene.make.sprite). * @param {Scene} [scene=the scene the map is within] - The Scene to create the Sprites within. - * @return {array} An array of the Sprites that were created. + * @return {Sprite[]} An array of the Sprites that were created. */ createFromObjects: function (name, id, spriteConfig, scene) { diff --git a/v3/src/gameobjects/tilemap/TilemapCreator.js b/v3/src/gameobjects/tilemap/TilemapCreator.js index de17581d0..851d56543 100644 --- a/v3/src/gameobjects/tilemap/TilemapCreator.js +++ b/v3/src/gameobjects/tilemap/TilemapCreator.js @@ -4,20 +4,20 @@ var ParseToTilemap = require('./ParseToTilemap'); // When registering a factory function 'this' refers to the GameObjectCreator context. /** - * Creates a Tilemap from the given key or data, or creates a blank Tilemap if no key/data - * provided. When loading from CSV or a 2D array, you should specify the tileWidth & tileHeight. When - * parsing from a map from Tiled, the tileWidth, tileHeight, width & height will be pulled from the - * map data. For an empty map, you should specify tileWidth, tileHeight, width & height. + * Creates a Tilemap from the given key or data, or creates a blank Tilemap if no key/data provided. + * When loading from CSV or a 2D array, you should specify the tileWidth & tileHeight. When parsing + * from a map from Tiled, the tileWidth, tileHeight, width & height will be pulled from the map + * data. For an empty map, you should specify tileWidth, tileHeight, width & height. * * @param {object} [config] - The config options for the Tilemap. * @param {string} [config.key] - The key in the Phaser cache that corresponds to the loaded tilemap * data. - * @param {array} [config.data] - Instead of loading from the cache, you can also load directly from - * a 2D array of tile indexes. - * @param {number} [config.tileWidth=32] - The width of a tile in pixels. - * @param {number} [config.tileHeight=32] - The height of a tile in pixels. - * @param {number} [config.width=10] - The width of the map in tiles. - * @param {number} [config.height=10] - The height of the map in tiles. + * @param {integer[][]} [config.data] - Instead of loading from the cache, you can also load + * directly from a 2D array of tile indexes. + * @param {integer} [config.tileWidth=32] - The width of a tile in pixels. + * @param {integer} [config.tileHeight=32] - The height of a tile in pixels. + * @param {integer} [config.width=10] - The width of the map in tiles. + * @param {integer} [config.height=10] - The height of the map in tiles. * @param {boolean} [config.insertNull=false] - Controls how empty tiles, tiles with an index of -1, * in the map data are handled. If `true`, empty locations will get a value of `null`. If `false`, * empty location will get a Tile object with an index of -1. If you've a large sparsely populated diff --git a/v3/src/gameobjects/tilemap/TilemapFactory.js b/v3/src/gameobjects/tilemap/TilemapFactory.js index 6c4e482f7..463aad167 100644 --- a/v3/src/gameobjects/tilemap/TilemapFactory.js +++ b/v3/src/gameobjects/tilemap/TilemapFactory.js @@ -16,16 +16,16 @@ var ParseToTilemap = require('./ParseToTilemap'); * data. For an empty map, you should specify tileWidth, tileHeight, width & height. * * @param {string} [key] - The key in the Phaser cache that corresponds to the loaded tilemap data. - * @param {number} [tileWidth=32] - The width of a tile in pixels. Pass in `null` to leave as the + * @param {integer} [tileWidth=32] - The width of a tile in pixels. Pass in `null` to leave as the * default. - * @param {number} [tileHeight=32] - The height of a tile in pixels. Pass in `null` to leave as the + * @param {integer} [tileHeight=32] - The height of a tile in pixels. Pass in `null` to leave as the * default. - * @param {number} [width=10] - The width of the map in tiles. Pass in `null` to leave as the + * @param {integer} [width=10] - The width of the map in tiles. Pass in `null` to leave as the * default. - * @param {number} [height=10] - The height of the map in tiles. Pass in `null` to leave as the + * @param {integer} [height=10] - The height of the map in tiles. Pass in `null` to leave as the * default. - * @param {array} [data] - Instead of loading from the cache, you can also load directly from a 2D - * array of tile indexes. Pass in `null` for no data. + * @param {integer[][]} [data] - Instead of loading from the cache, you can also load directly from + * a 2D array of tile indexes. Pass in `null` for no data. * @param {boolean} [insertNull=false] - Controls how empty tiles, tiles with an index of -1, in the * map data are handled. If `true`, empty locations will get a value of `null`. If `false`, empty * location will get a Tile object with an index of -1. If you've a large sparsely populated map and diff --git a/v3/src/gameobjects/tilemap/Tileset.js b/v3/src/gameobjects/tilemap/Tileset.js index 09f1b497b..e702215cb 100644 --- a/v3/src/gameobjects/tilemap/Tileset.js +++ b/v3/src/gameobjects/tilemap/Tileset.js @@ -8,7 +8,7 @@ var Tileset = new Class({ * A Tileset is a combination of an image containing the tiles and a container for data about * each tile. * - * @class MapData + * @class Tileset * @constructor * * @param {string} name - The name of the tileset in the map data. @@ -115,7 +115,7 @@ var Tileset = new Class({ /** * The look-up table to specific tile image texture coordinates (UV in pixels). Each element * contains the coordinates for a tile in an object of the form {x, y}. - * @property {array} texCoordinates + * @property {object[]} texCoordinates * @readonly */ this.texCoordinates = []; diff --git a/v3/src/gameobjects/tilemap/components/CalculateFacesWithin.js b/v3/src/gameobjects/tilemap/components/CalculateFacesWithin.js index eaffcd16f..2a6499be2 100644 --- a/v3/src/gameobjects/tilemap/components/CalculateFacesWithin.js +++ b/v3/src/gameobjects/tilemap/components/CalculateFacesWithin.js @@ -6,10 +6,10 @@ var GetTilesWithin = require('./GetTilesWithin'); * layer. Interesting faces are used internally for optimizing collisions against tiles. This method * is mostly used internally. * - * @param {number} [tileX=0] - [description] - * @param {number} [tileY=0] - [description] - * @param {number} [width=max width based on tileX] - [description] - * @param {number} [height=max height based on tileY] - [description] + * @param {integer} [tileX=0] - [description] + * @param {integer} [tileY=0] - [description] + * @param {integer} [width=max width based on tileX] - [description] + * @param {integer} [height=max height based on tileY] - [description] * @param {LayerData} layer - [description] */ var CalculateFacesWithin = function (tileX, tileY, width, height, layer) diff --git a/v3/src/gameobjects/tilemap/components/Copy.js b/v3/src/gameobjects/tilemap/components/Copy.js index fe390a16e..ab21c063e 100644 --- a/v3/src/gameobjects/tilemap/components/Copy.js +++ b/v3/src/gameobjects/tilemap/components/Copy.js @@ -6,13 +6,13 @@ var CalculateFacesWithin = require('./CalculateFacesWithin'); * coordinates) within the layer. This copies all tile properties & recalculates collision * information in the destination region. * - * @param {number} srcTileX - [description] - * @param {number} srcTileY - [description] - * @param {number} width - [description] - * @param {number} height - [description] - * @param {number} destTileX - [description] - * @param {number} destTileY - [description] - * @param {number} destTileY - [description] + * @param {integer} srcTileX - [description] + * @param {integer} srcTileY - [description] + * @param {integer} width - [description] + * @param {integer} height - [description] + * @param {integer} destTileX - [description] + * @param {integer} destTileY - [description] + * @param {integer} destTileY - [description] * @param {boolean} [recalculateFaces=true] - [description] * @param {LayerData} layer - [description] */ diff --git a/v3/src/gameobjects/tilemap/components/CreateFromTiles.js b/v3/src/gameobjects/tilemap/components/CreateFromTiles.js index e4737318c..ec358e03c 100644 --- a/v3/src/gameobjects/tilemap/components/CreateFromTiles.js +++ b/v3/src/gameobjects/tilemap/components/CreateFromTiles.js @@ -9,8 +9,8 @@ var ReplaceByIndex = require('./ReplaceByIndex'); * created. This is useful if you want to lay down special tiles in a level that are converted to * Sprites, but want to replace the tile itself with a floor tile or similar once converted. * - * @param {number|array} indexes - The tile index, or array of indexes, to create Sprites from. - * @param {number|array} replacements - The tile index, or array of indexes, to change a converted + * @param {integer|array} indexes - The tile index, or array of indexes, to create Sprites from. + * @param {integer|array} replacements - The tile index, or array of indexes, to change a converted * tile to. Set to `null` to leave the tiles unchanged. If an array is given, it is assumed to be a * one-to-one mapping with the indexes array. * @param {object} spriteConfig - The config object to pass into the Sprite creator (i.e. @@ -18,7 +18,7 @@ var ReplaceByIndex = require('./ReplaceByIndex'); * @param {Scene} [scene=scene the map is within] - The Scene to create the Sprites within. * @param {Camera} [camera=main camera] - The Camera to use when determining the world XY * @param {LayerData} layer - [description] - * @return {array} An array of the Sprites that were created. + * @return {Sprite[]} An array of the Sprites that were created. */ var CreateFromTiles = function (indexes, replacements, spriteConfig, scene, camera, layer) { diff --git a/v3/src/gameobjects/tilemap/components/CullTiles.js b/v3/src/gameobjects/tilemap/components/CullTiles.js index fa9e9cf8d..38c2ef4bb 100644 --- a/v3/src/gameobjects/tilemap/components/CullTiles.js +++ b/v3/src/gameobjects/tilemap/components/CullTiles.js @@ -5,7 +5,7 @@ * @param {LayerData} layer - [description] * @param {Camera} [camera=main camera] - [description] * @param {array} [outputArray] - [description] - * @returns {array} + * @returns {Tile[]} */ var CullTiles = function (layer, camera, outputArray) { diff --git a/v3/src/gameobjects/tilemap/components/Fill.js b/v3/src/gameobjects/tilemap/components/Fill.js index 7828a8ac8..6da21bbfe 100644 --- a/v3/src/gameobjects/tilemap/components/Fill.js +++ b/v3/src/gameobjects/tilemap/components/Fill.js @@ -6,11 +6,11 @@ var CalculateFacesWithin = require('./CalculateFacesWithin'); * specified index. Tiles will be set to collide if the given index is a colliding index. * Collision information in the region will be recalculated. * - * @param {number} index - [description] - * @param {number} [tileX=0] - [description] - * @param {number} [tileY=0] - [description] - * @param {number} [width=max width based on tileX] - [description] - * @param {number} [height=max height based on tileY] - [description] + * @param {integer} index - [description] + * @param {integer} [tileX=0] - [description] + * @param {integer} [tileY=0] - [description] + * @param {integer} [width=max width based on tileX] - [description] + * @param {integer} [height=max height based on tileY] - [description] * @param {boolean} [recalculateFaces=true] - [description] * @param {LayerData} layer - [description] */ diff --git a/v3/src/gameobjects/tilemap/components/FilterTiles.js b/v3/src/gameobjects/tilemap/components/FilterTiles.js index e64986917..e4fd9e2bd 100644 --- a/v3/src/gameobjects/tilemap/components/FilterTiles.js +++ b/v3/src/gameobjects/tilemap/components/FilterTiles.js @@ -5,14 +5,14 @@ var GetTilesWithin = require('./GetTilesWithin'); * filter callback function. Any tiles that pass the filter test (i.e. where the callback returns * true) will returned as a new array. Similar to Array.prototype.Filter in vanilla JS. * - * @param {number} callback - The callback. Each tile in the given area will be passed to this + * @param {function} callback - The callback. Each tile in the given area will be passed to this * callback as the first and only parameter. The callback should return true for tiles that pass the * filter. - * @param {number} [context] - The context under which the callback should be run. - * @param {number} [tileX=0] - [description] - * @param {number} [tileY=0] - [description] - * @param {number} [width=max width based on tileX] - [description] - * @param {number} [height=max height based on tileY] - [description] + * @param {object} [context] - The context under which the callback should be run. + * @param {integer} [tileX=0] - [description] + * @param {integer} [tileY=0] - [description] + * @param {integer} [width=max width based on tileX] - [description] + * @param {integer} [height=max height based on tileY] - [description] * @param {object} [filteringOptions] - Optional filters to apply when getting the tiles. * @param {boolean} [filteringOptions.isNotEmpty=false] - If true, only return tiles that don't have * -1 for an index. @@ -21,7 +21,7 @@ var GetTilesWithin = require('./GetTilesWithin'); * @param {boolean} [filteringOptions.hasInterestingFace=false] - If true, only return tiles that * have at least one interesting face. * @param {LayerData} layer - [description] - * @returns {array} The filtered array of Tiles. + * @returns {Tile[]} The filtered array of Tiles. */ var FilterTiles = function (callback, context, tileX, tileY, width, height, filteringOptions, layer) { diff --git a/v3/src/gameobjects/tilemap/components/FindByIndex.js b/v3/src/gameobjects/tilemap/components/FindByIndex.js index 9f5ba29ff..88e1787bb 100644 --- a/v3/src/gameobjects/tilemap/components/FindByIndex.js +++ b/v3/src/gameobjects/tilemap/components/FindByIndex.js @@ -5,9 +5,9 @@ * If the reverse boolean is true, it scans starting from the bottom-right corner traveling up to * the top-left. * - * @param {number} index - The tile index value to search for. - * @param {number} [skip=0] - The number of times to skip a matching tile before returning. - * @param {number} [reverse=false] - If true it will scan the layer in reverse, starting at the + * @param {integer} index - The tile index value to search for. + * @param {integer} [skip=0] - The number of times to skip a matching tile before returning. + * @param {boolean} [reverse=false] - If true it will scan the layer in reverse, starting at the * bottom-right. Otherwise it scans from the top-left. * @param {LayerData} layer - [description] * @return {Tile|null} The first (or n skipped) tile with the matching index. diff --git a/v3/src/gameobjects/tilemap/components/ForEachTile.js b/v3/src/gameobjects/tilemap/components/ForEachTile.js index f6750d77f..478f27318 100644 --- a/v3/src/gameobjects/tilemap/components/ForEachTile.js +++ b/v3/src/gameobjects/tilemap/components/ForEachTile.js @@ -4,13 +4,13 @@ var GetTilesWithin = require('./GetTilesWithin'); * For each tile in the given rectangular area (in tile coordinates) of the layer, run the given * callback. Similar to Array.prototype.forEach in vanilla JS. * - * @param {number} callback - The callback. Each tile in the given area will be passed to this + * @param {function} callback - The callback. Each tile in the given area will be passed to this * callback as the first and only parameter. - * @param {number} [context] - The context under which the callback should be run. - * @param {number} [tileX=0] - [description] - * @param {number} [tileY=0] - [description] - * @param {number} [width=max width based on tileX] - [description] - * @param {number} [height=max height based on tileY] - [description] + * @param {object} [context] - The context under which the callback should be run. + * @param {integer} [tileX=0] - [description] + * @param {integer} [tileY=0] - [description] + * @param {integer} [width=max width based on tileX] - [description] + * @param {integer} [height=max height based on tileY] - [description] * @param {object} [filteringOptions] - Optional filters to apply when getting the tiles. * @param {boolean} [filteringOptions.isNotEmpty=false] - If true, only return tiles that don't have * -1 for an index. diff --git a/v3/src/gameobjects/tilemap/components/GetTileAt.js b/v3/src/gameobjects/tilemap/components/GetTileAt.js index 09721d21b..4bd634fed 100644 --- a/v3/src/gameobjects/tilemap/components/GetTileAt.js +++ b/v3/src/gameobjects/tilemap/components/GetTileAt.js @@ -3,8 +3,8 @@ var IsInLayerBounds = require('./IsInLayerBounds'); /** * Gets a tile at the given tile coordinates from the given layer. * - * @param {number} tileX - X position to get the tile from (given in tile units, not pixels) - * @param {number} tileY - Y position to get the tile from (given in tile units, not pixels) + * @param {integer} tileX - X position to get the tile from (given in tile units, not pixels). + * @param {integer} tileY - Y position to get the tile from (given in tile units, not pixels). * @param {boolean} [nonNull=false] - If true getTile won't return null for empty tiles, but a Tile * object with an index of -1. * @param {LayerData} layer - [description] diff --git a/v3/src/gameobjects/tilemap/components/GetTilesWithin.js b/v3/src/gameobjects/tilemap/components/GetTilesWithin.js index 16597fac6..2f3d33b85 100644 --- a/v3/src/gameobjects/tilemap/components/GetTilesWithin.js +++ b/v3/src/gameobjects/tilemap/components/GetTilesWithin.js @@ -3,10 +3,10 @@ var GetFastValue = require('../../../utils/object/GetFastValue'); /** * Gets the tiles in the given rectangular area (in tile coordinates) of the layer. * - * @param {number} [tileX=0] - [description] - * @param {number} [tileY=0] - [description] - * @param {number} [width=max width based on tileX] - [description] - * @param {number} [height=max height based on tileY] - [description] + * @param {integer} [tileX=0] - [description] + * @param {integer} [tileY=0] - [description] + * @param {integer} [width=max width based on tileX] - [description] + * @param {integer} [height=max height based on tileY] - [description] * @param {object} [filteringOptions] - Optional filters to apply when getting the tiles. * @param {boolean} [filteringOptions.isNotEmpty=false] - If true, only return tiles that don't have * -1 for an index. @@ -15,7 +15,7 @@ var GetFastValue = require('../../../utils/object/GetFastValue'); * @param {boolean} [filteringOptions.hasInterestingFace=false] - If true, only return tiles that * have at least one interesting face. * @param {LayerData} layer - [description] - * @return {array} Array of Tile objects. + * @return {Tile[]} Array of Tile objects. */ var GetTilesWithin = function (tileX, tileY, width, height, filteringOptions, layer) { diff --git a/v3/src/gameobjects/tilemap/components/GetTilesWithinShape.js b/v3/src/gameobjects/tilemap/components/GetTilesWithinShape.js index 18e2c4d9a..b11ff0121 100644 --- a/v3/src/gameobjects/tilemap/components/GetTilesWithinShape.js +++ b/v3/src/gameobjects/tilemap/components/GetTilesWithinShape.js @@ -30,7 +30,7 @@ var TriangleToRectangle = function (triangle, rect) * have at least one interesting face. * @param {Camera} [camera=main camera] - [description] * @param {LayerData} layer - [description] - * @return {array} Array of Tile objects. + * @return {Tile[]} Array of Tile objects. */ var GetTilesWithinShape = function (shape, filteringOptions, camera, layer) { diff --git a/v3/src/gameobjects/tilemap/components/GetTilesWithinWorldXY.js b/v3/src/gameobjects/tilemap/components/GetTilesWithinWorldXY.js index ad9b67a18..94d028153 100644 --- a/v3/src/gameobjects/tilemap/components/GetTilesWithinWorldXY.js +++ b/v3/src/gameobjects/tilemap/components/GetTilesWithinWorldXY.js @@ -18,7 +18,7 @@ var WorldToTileY = require('./WorldToTileY'); * have at least one interesting face. * @param {Camera} [camera=main camera] - [description] * @param {LayerData} layer - [description] - * @return {array} Array of Tile objects. + * @return {Tile[]} Array of Tile objects. */ var GetTilesWithinWorldXY = function (worldX, worldY, width, height, filteringOptions, camera, layer) { diff --git a/v3/src/gameobjects/tilemap/components/HasTileAt.js b/v3/src/gameobjects/tilemap/components/HasTileAt.js index 998b1dbbe..7500b0c28 100644 --- a/v3/src/gameobjects/tilemap/components/HasTileAt.js +++ b/v3/src/gameobjects/tilemap/components/HasTileAt.js @@ -4,8 +4,8 @@ var IsInLayerBounds = require('./IsInLayerBounds'); * Checks if there is a tile at the given location (in tile coordinates) in the given layer. Returns * false if there is no tile or if the tile at that location has an index of -1. * - * @param {number} tileX - [description] - * @param {number} tileY - [description] + * @param {integer} tileX - [description] + * @param {integer} tileY - [description] * @param {LayerData} layer - [description] * @return {boolean} */ diff --git a/v3/src/gameobjects/tilemap/components/IsInLayerBounds.js b/v3/src/gameobjects/tilemap/components/IsInLayerBounds.js index 5ba52b3f6..c85f9d6a6 100644 --- a/v3/src/gameobjects/tilemap/components/IsInLayerBounds.js +++ b/v3/src/gameobjects/tilemap/components/IsInLayerBounds.js @@ -1,8 +1,8 @@ /** * Checks if the given tile coordinates are within the bounds of the layer. * - * @param {number} tileX - [description] - * @param {number} tileY - [description] + * @param {integer} tileX - [description] + * @param {integer} tileY - [description] * @param {LayerData} layer - [description] * @return {boolean} */ diff --git a/v3/src/gameobjects/tilemap/components/PutTileAt.js b/v3/src/gameobjects/tilemap/components/PutTileAt.js index f1a7e2116..8530303f3 100644 --- a/v3/src/gameobjects/tilemap/components/PutTileAt.js +++ b/v3/src/gameobjects/tilemap/components/PutTileAt.js @@ -8,9 +8,9 @@ var RecalculateFacesAt = require('./RecalculateFacesAt'); * location. If you pass in an index, only the index at the specified location will be changed. * Collision information will be recalculated at the specified location. * - * @param {number|Tile} tile - The index of this tile to set or a Tile object. - * @param {number} tileX - [description] - * @param {number} tileY - [description] + * @param {integer|Tile} tile - The index of this tile to set or a Tile object. + * @param {integer} tileX - [description] + * @param {integer} tileY - [description] * @param {boolean} [recalculateFaces=true] - [description] * @param {LayerData} layer - [description] * @return {Tile} The Tile object that was created or added to this map. diff --git a/v3/src/gameobjects/tilemap/components/PutTileAtWorldXY.js b/v3/src/gameobjects/tilemap/components/PutTileAtWorldXY.js index c1d84c59e..f7bd19711 100644 --- a/v3/src/gameobjects/tilemap/components/PutTileAtWorldXY.js +++ b/v3/src/gameobjects/tilemap/components/PutTileAtWorldXY.js @@ -8,9 +8,9 @@ var WorldToTileY = require('./WorldToTileY'); * specified location. If you pass in an index, only the index at the specified location will be * changed. Collision information will be recalculated at the specified location. * - * @param {number|Tile} tile - The index of this tile to set or a Tile object. - * @param {number} worldX - [description] - * @param {number} worldY - [description] + * @param {integer|Tile} tile - The index of this tile to set or a Tile object. + * @param {integer} worldX - [description] + * @param {integer} worldY - [description] * @param {boolean} [recalculateFaces=true] - [description] * @param {Camera} [camera=main camera] - [description] * @param {LayerData} layer - [description] diff --git a/v3/src/gameobjects/tilemap/components/Randomize.js b/v3/src/gameobjects/tilemap/components/Randomize.js index af8ada9e3..c5e9f99e4 100644 --- a/v3/src/gameobjects/tilemap/components/Randomize.js +++ b/v3/src/gameobjects/tilemap/components/Randomize.js @@ -8,11 +8,11 @@ var GetRandomElement = require('../../../utils/array/GetRandomElement'); * indexes found within the region (excluding -1) will be used for randomly assigning new tile * indexes. This method only modifies tile indexes and does not change collision information. * - * @param {number} [tileX=0] - [description] - * @param {number} [tileY=0] - [description] - * @param {number} [width=max width based on tileX] - [description] - * @param {number} [height=max height based on tileY] - [description] - * @param {array} [indexes] - An array of indexes to randomly draw from during randomization. + * @param {integer} [tileX=0] - [description] + * @param {integer} [tileY=0] - [description] + * @param {integer} [width=max width based on tileX] - [description] + * @param {integer} [height=max height based on tileY] - [description] + * @param {integer[]} [indexes] - An array of indexes to randomly draw from during randomization. * @param {LayerData} layer - [description] */ var Randomize = function (tileX, tileY, width, height, indexes, layer) diff --git a/v3/src/gameobjects/tilemap/components/RecalculateFacesAt.js b/v3/src/gameobjects/tilemap/components/RecalculateFacesAt.js index 92e9e8985..fbbda04f9 100644 --- a/v3/src/gameobjects/tilemap/components/RecalculateFacesAt.js +++ b/v3/src/gameobjects/tilemap/components/RecalculateFacesAt.js @@ -5,8 +5,8 @@ var GetTileAt = require('./GetTileAt'); * faces are used internally for optimizing collisions against tiles. This method is mostly used * internally to optimize recalculating faces when only one tile has been changed. * - * @param {number} tileX - [description] - * @param {number} tileY - [description] + * @param {integer} tileX - [description] + * @param {integer} tileY - [description] * @param {LayerData} layer - [description] */ var RecalculateFacesAt = function (tileX, tileY, layer) diff --git a/v3/src/gameobjects/tilemap/components/RemoveTileAt.js b/v3/src/gameobjects/tilemap/components/RemoveTileAt.js index bfd043c5e..bf6c1653f 100644 --- a/v3/src/gameobjects/tilemap/components/RemoveTileAt.js +++ b/v3/src/gameobjects/tilemap/components/RemoveTileAt.js @@ -6,9 +6,9 @@ var RecalculateFacesAt = require('./RecalculateFacesAt'); * Removes the tile at the given tile coordinates in the specified layer and updates the layer's * collision information. * - * @param {number|Tile} tile - The index of this tile to set or a Tile object. - * @param {number} tileX - [description] - * @param {number} tileY - [description] + * @param {integer|Tile} tile - The index of this tile to set or a Tile object. + * @param {integer} tileX - [description] + * @param {integer} tileY - [description] * @param {boolean} [replaceWithNull=true] - If true, this will replace the tile at the specified * location with null instead of a Tile with an index of -1. * @param {boolean} [recalculateFaces=true] - [description] diff --git a/v3/src/gameobjects/tilemap/components/RemoveTileAtWorldXY.js b/v3/src/gameobjects/tilemap/components/RemoveTileAtWorldXY.js index a5285b232..85c0962ef 100644 --- a/v3/src/gameobjects/tilemap/components/RemoveTileAtWorldXY.js +++ b/v3/src/gameobjects/tilemap/components/RemoveTileAtWorldXY.js @@ -6,7 +6,7 @@ var WorldToTileY = require('./WorldToTileY'); * Removes the tile at the given world coordinates in the specified layer and updates the layer's * collision information. * - * @param {number|Tile} tile - The index of this tile to set or a Tile object. + * @param {integer|Tile} tile - The index of this tile to set or a Tile object. * @param {number} worldX - [description] * @param {number} worldY - [description] * @param {boolean} [replaceWithNull=true] - If true, this will replace the tile at the specified diff --git a/v3/src/gameobjects/tilemap/components/ReplaceByIndex.js b/v3/src/gameobjects/tilemap/components/ReplaceByIndex.js index f4844811b..290ff3bd2 100644 --- a/v3/src/gameobjects/tilemap/components/ReplaceByIndex.js +++ b/v3/src/gameobjects/tilemap/components/ReplaceByIndex.js @@ -5,12 +5,12 @@ var GetTilesWithin = require('./GetTilesWithin'); * `findIndex` and updates their index to match `newIndex`. This only modifies the index and does * not change collision information. * - * @param {number} findIndex - [description] - * @param {number} newIndex - [description] - * @param {number} [tileX=0] - [description] - * @param {number} [tileY=0] - [description] - * @param {number} [width=max width based on tileX] - [description] - * @param {number} [height=max height based on tileY] - [description] + * @param {integer} findIndex - [description] + * @param {integer} newIndex - [description] + * @param {integer} [tileX=0] - [description] + * @param {integer} [tileY=0] - [description] + * @param {integer} [width=max width based on tileX] - [description] + * @param {integer} [height=max height based on tileY] - [description] * @param {LayerData} layer - [description] */ var ReplaceByIndex = function (findIndex, newIndex, tileX, tileY, width, height, layer) diff --git a/v3/src/gameobjects/tilemap/components/SetCollision.js b/v3/src/gameobjects/tilemap/components/SetCollision.js index fb5e9a510..8e95a0006 100644 --- a/v3/src/gameobjects/tilemap/components/SetCollision.js +++ b/v3/src/gameobjects/tilemap/components/SetCollision.js @@ -7,7 +7,7 @@ var SetLayerCollisionIndex = require('./SetLayerCollisionIndex'); * single numeric index or an array of indexes: [2, 3, 15, 20]. The `collides` parameter controls if * collision will be enabled (true) or disabled (false). * - * @param {number|array} indexes - Either a single tile index, or an array of tile indexes. + * @param {integer|array} indexes - Either a single tile index, or an array of tile indexes. * @param {boolean} [collides=true] - If true it will enable collision. If false it will clear * collision. * @param {boolean} [recalculateFaces=true] - Whether or not to recalculate the tile faces after the diff --git a/v3/src/gameobjects/tilemap/components/SetCollisionBetween.js b/v3/src/gameobjects/tilemap/components/SetCollisionBetween.js index 58c731592..e0e9f510e 100644 --- a/v3/src/gameobjects/tilemap/components/SetCollisionBetween.js +++ b/v3/src/gameobjects/tilemap/components/SetCollisionBetween.js @@ -8,8 +8,8 @@ var SetLayerCollisionIndex = require('./SetLayerCollisionIndex'); * collision for tiles 10, 11, 12, 13 and 14. The `collides` parameter controls if collision will be * enabled (true) or disabled (false). * - * @param {number} start - The first index of the tile to be set for collision. - * @param {number} stop - The last index of the tile to be set for collision. + * @param {integer} start - The first index of the tile to be set for collision. + * @param {integer} stop - The last index of the tile to be set for collision. * @param {boolean} [collides=true] - If true it will enable collision. If false it will clear * collision. * @param {boolean} [recalculateFaces=true] - Whether or not to recalculate the tile faces after the diff --git a/v3/src/gameobjects/tilemap/components/SetCollisionByExclusion.js b/v3/src/gameobjects/tilemap/components/SetCollisionByExclusion.js index e93f02252..067d0e7a3 100644 --- a/v3/src/gameobjects/tilemap/components/SetCollisionByExclusion.js +++ b/v3/src/gameobjects/tilemap/components/SetCollisionByExclusion.js @@ -7,7 +7,7 @@ var SetLayerCollisionIndex = require('./SetLayerCollisionIndex'); * the given array. The `collides` parameter controls if collision will be enabled (true) or * disabled (false). * - * @param {array} indexes - An array of the tile indexes to not be counted for collision. + * @param {integer[]} indexes - An array of the tile indexes to not be counted for collision. * @param {boolean} [collides=true] - If true it will enable collision. If false it will clear * collision. * @param {boolean} [recalculateFaces=true] - Whether or not to recalculate the tile faces after the diff --git a/v3/src/gameobjects/tilemap/components/SetLayerCollisionIndex.js b/v3/src/gameobjects/tilemap/components/SetLayerCollisionIndex.js index d180c4d80..92c988e5e 100644 --- a/v3/src/gameobjects/tilemap/components/SetLayerCollisionIndex.js +++ b/v3/src/gameobjects/tilemap/components/SetLayerCollisionIndex.js @@ -2,7 +2,7 @@ * Internally used method to keep track of the tile indexes that collide within a layer. This * updates LayerData.collideIndexes to either contain or not contain the given `tileIndex`. * - * @param {number} tileIndex - [description] + * @param {integer} tileIndex - [description] * @param {boolean} [collides=true] - [description] * @param {LayerData} layer - [description] */ diff --git a/v3/src/gameobjects/tilemap/components/SetTileIndexCallback.js b/v3/src/gameobjects/tilemap/components/SetTileIndexCallback.js index 4b5fa3e6c..c054fecde 100644 --- a/v3/src/gameobjects/tilemap/components/SetTileIndexCallback.js +++ b/v3/src/gameobjects/tilemap/components/SetTileIndexCallback.js @@ -4,7 +4,7 @@ * will be replaced. Set the callback to null to remove it. If you want to set a callback for a tile * at a specific location on the map then see setTileLocationCallback. * - * @param {number|array} indexes - Either a single tile index, or an array of tile indexes to have a + * @param {integer|array} indexes - Either a single tile index, or an array of tile indexes to have a * collision callback set for. * @param {function} callback - The callback that will be invoked when the tile is collided with. * @param {object} callbackContext - The context under which the callback is called. diff --git a/v3/src/gameobjects/tilemap/components/SetTileLocationCallback.js b/v3/src/gameobjects/tilemap/components/SetTileLocationCallback.js index e537c0310..efe5ca809 100644 --- a/v3/src/gameobjects/tilemap/components/SetTileLocationCallback.js +++ b/v3/src/gameobjects/tilemap/components/SetTileLocationCallback.js @@ -5,10 +5,10 @@ var GetTilesWithin = require('./GetTilesWithin'); * If a callback is already set for the tile index it will be replaced. Set the callback to null to * remove it. * - * @param {number} [tileX=0] - [description] - * @param {number} [tileY=0] - [description] - * @param {number} [width=max width based on tileX] - [description] - * @param {number} [height=max height based on tileY] - [description] + * @param {integer} [tileX=0] - [description] + * @param {integer} [tileY=0] - [description] + * @param {integer} [width=max width based on tileX] - [description] + * @param {integer} [height=max height based on tileY] - [description] * @param {function} callback - The callback that will be invoked when the tile is collided with. * @param {object} callbackContext - The context under which the callback is called. * @param {LayerData} layer - [description] diff --git a/v3/src/gameobjects/tilemap/components/Shuffle.js b/v3/src/gameobjects/tilemap/components/Shuffle.js index 76039b94f..fa492c6cb 100644 --- a/v3/src/gameobjects/tilemap/components/Shuffle.js +++ b/v3/src/gameobjects/tilemap/components/Shuffle.js @@ -7,10 +7,10 @@ var ShuffleArray = require('../../../utils/array/Shuffle'); * appear to have changed! This method only modifies tile indexes and does not change collision * information. * - * @param {number} [tileX=0] - [description] - * @param {number} [tileY=0] - [description] - * @param {number} [width=max width based on tileX] - [description] - * @param {number} [height=max height based on tileY] - [description] + * @param {integer} [tileX=0] - [description] + * @param {integer} [tileY=0] - [description] + * @param {integer} [width=max width based on tileX] - [description] + * @param {integer} [height=max height based on tileY] - [description] * @param {LayerData} layer - [description] */ var Shuffle = function (tileX, tileY, width, height, layer) diff --git a/v3/src/gameobjects/tilemap/components/SwapByIndex.js b/v3/src/gameobjects/tilemap/components/SwapByIndex.js index f63cf388d..b5184d9b8 100644 --- a/v3/src/gameobjects/tilemap/components/SwapByIndex.js +++ b/v3/src/gameobjects/tilemap/components/SwapByIndex.js @@ -5,12 +5,12 @@ var GetTilesWithin = require('./GetTilesWithin'); * `indexA` and swaps then with `indexB`. This only modifies the index and does not change collision * information. * - * @param {number} tileA - First tile index. - * @param {number} tileB - Second tile index. - * @param {number} [tileX=0] - [description] - * @param {number} [tileY=0] - [description] - * @param {number} [width=max width based on tileX] - [description] - * @param {number} [height=max height based on tileY] - [description] + * @param {integer} tileA - First tile index. + * @param {integer} tileB - Second tile index. + * @param {integer} [tileX=0] - [description] + * @param {integer} [tileY=0] - [description] + * @param {integer} [width=max width based on tileX] - [description] + * @param {integer} [height=max height based on tileY] - [description] * @param {LayerData} layer - [description] */ var SwapByIndex = function (indexA, indexB, tileX, tileY, width, height, layer) diff --git a/v3/src/gameobjects/tilemap/components/TileToWorldX.js b/v3/src/gameobjects/tilemap/components/TileToWorldX.js index ec73dd770..6776e1a40 100644 --- a/v3/src/gameobjects/tilemap/components/TileToWorldX.js +++ b/v3/src/gameobjects/tilemap/components/TileToWorldX.js @@ -2,7 +2,7 @@ * Internally used method to convert from tile X coordinates to world X coordinates, factoring in * layer position, scale and scroll. * - * @param {number} tileX - [description] + * @param {integer} tileX - [description] * @param {Camera} [camera=main camera] - [description] * @param {LayerData} layer - [description] * @returns {number} diff --git a/v3/src/gameobjects/tilemap/components/TileToWorldY.js b/v3/src/gameobjects/tilemap/components/TileToWorldY.js index 351b3ddd1..d0a318e5c 100644 --- a/v3/src/gameobjects/tilemap/components/TileToWorldY.js +++ b/v3/src/gameobjects/tilemap/components/TileToWorldY.js @@ -2,7 +2,7 @@ * Internally used method to convert from tile Y coordinates to world Y coordinates, factoring in * layer position, scale and scroll. * - * @param {number} tileY - [description] + * @param {integer} tileY - [description] * @param {Camera} [camera=main camera] - [description] * @param {LayerData} layer - [description] * @returns {number} diff --git a/v3/src/gameobjects/tilemap/parsers/Parse.js b/v3/src/gameobjects/tilemap/parsers/Parse.js index 8b5fa2317..00161bba2 100644 --- a/v3/src/gameobjects/tilemap/parsers/Parse.js +++ b/v3/src/gameobjects/tilemap/parsers/Parse.js @@ -11,11 +11,11 @@ var Formats = require('../Formats'); * the map data. * * @param {string} name - The name of the tilemap, used to set the name on the MapData. - * @param {number} mapFormat - See ../Formats.js. - * @param {array|string|object} data - 2D array, CSV string or Tiled JSON object. - * @param {number} tileWidth - The width of a tile in pixels. Required for 2D array and CSV, but + * @param {integer} mapFormat - See ../Formats.js. + * @param {integer[][]|string|object} data - 2D array, CSV string or Tiled JSON object. + * @param {integer} tileWidth - The width of a tile in pixels. Required for 2D array and CSV, but * ignored for Tiled JSON. - * @param {number} tileHeight - The height of a tile in pixels. Required for 2D array and CSV, but + * @param {integer} tileHeight - The height of a tile in pixels. Required for 2D array and CSV, but * ignored for Tiled JSON. * @param {boolean} insertNull - Controls how empty tiles, tiles with an index of -1, in the map * data are handled. If `true`, empty locations will get a value of `null`. If `false`, empty diff --git a/v3/src/gameobjects/tilemap/parsers/Parse2DArray.js b/v3/src/gameobjects/tilemap/parsers/Parse2DArray.js index 4b6e53a05..6ccf9c158 100644 --- a/v3/src/gameobjects/tilemap/parsers/Parse2DArray.js +++ b/v3/src/gameobjects/tilemap/parsers/Parse2DArray.js @@ -7,9 +7,9 @@ var Tile = require('../Tile'); * Parses a 2D array of tile indexes into a new MapData object with a single layer. * * @param {string} name - The name of the tilemap, used to set the name on the MapData. - * @param {array} data - 2D array, CSV string or Tiled JSON object. - * @param {number} tileWidth - The width of a tile in pixels. - * @param {number} tileHeight - The height of a tile in pixels. + * @param {integer[][]} data - 2D array, CSV string or Tiled JSON object. + * @param {integer} tileWidth - The width of a tile in pixels. + * @param {integer} tileHeight - The height of a tile in pixels. * @param {boolean} insertNull - Controls how empty tiles, tiles with an index of -1, in the map * data are handled. If `true`, empty locations will get a value of `null`. If `false`, empty * location will get a Tile object with an index of -1. If you've a large sparsely populated map and diff --git a/v3/src/gameobjects/tilemap/parsers/ParseCSV.js b/v3/src/gameobjects/tilemap/parsers/ParseCSV.js index 6c143250c..df049eb9e 100644 --- a/v3/src/gameobjects/tilemap/parsers/ParseCSV.js +++ b/v3/src/gameobjects/tilemap/parsers/ParseCSV.js @@ -6,8 +6,8 @@ var Parse2DArray = require('./Parse2DArray'); * * @param {string} name - The name of the tilemap, used to set the name on the MapData. * @param {string} data - CSV string of tile indexes. - * @param {number} tileWidth - The width of a tile in pixels. - * @param {number} tileHeight - The height of a tile in pixels. + * @param {integer} tileWidth - The width of a tile in pixels. + * @param {integer} tileHeight - The height of a tile in pixels. * @param {boolean} insertNull - Controls how empty tiles, tiles with an index of -1, in the map * data are handled. If `true`, empty locations will get a value of `null`. If `false`, empty * location will get a Tile object with an index of -1. If you've a large sparsely populated map and From d6f8812f49f153bd457e9098062988a681063313 Mon Sep 17 00:00:00 2001 From: Michael Hadley Date: Wed, 29 Nov 2017 15:37:23 -0600 Subject: [PATCH 13/13] Jsdoc: Tile --- v3/src/gameobjects/tilemap/Tile.js | 314 +++++++++++++++++++++++++---- 1 file changed, 279 insertions(+), 35 deletions(-) diff --git a/v3/src/gameobjects/tilemap/Tile.js b/v3/src/gameobjects/tilemap/Tile.js index 1e825f6c4..fbc5acbff 100644 --- a/v3/src/gameobjects/tilemap/Tile.js +++ b/v3/src/gameobjects/tilemap/Tile.js @@ -11,35 +11,175 @@ var Tile = new Class({ initialize: + /** + * A Tile is a representation of a single tile within the Tilemap. This is a lightweight data + * representation, so it's position information is stored without factoring in scroll, layer + * scale or layer position. + * + * @class Tile + * @constructor + * + * @param {LayerData} layer - The LayerData object in the Tilemap that this tile belongs to. + * @param {integer} index - The unique index of this tile within the map. + * @param {integer} x - The x coordinate of this tile in tile coordinates. + * @param {integer} y - The y coordinate of this tile in tile coordinates. + * @param {integer} width - Width of the tile in pixels. + * @param {integer} height - Height of the tile in pixels. + */ function Tile (layer, index, x, y, width, height) { + /** + * The LayerData in the Tilemap data that this tile belongs to. + * @property {LayerData} layer + */ this.layer = layer; - this.index = index; - this.x = x; - this.y = y; - this.worldX = x * width; - this.worldY = y * height; - this.width = width; - this.height = height; - this.properties = {}; - this.rotation = 0; - this.collideLeft = false; - this.collideRight = false; - this.collideUp = false; - this.collideDown = false; - this.faceLeft = false; - this.faceRight = false; - this.faceTop = false; - this.faceBottom = false; - this.collisionCallback = null; - this.collisionCallbackContext = this; - this.scanned = false; - // Note: tint is currently a single color value instead of the 4 corner tint component - this.tint = 0xFFFFFF; + /** + * The index of this tile within the map data corresponding to the tileset, or -1 if this + * represents a blank tile. + * @property {integer} index + */ + this.index = index; + + /** + * The x map coordinate of this tile in tile units. + * @property {integer} x + */ + this.x = x; + + /** + * The y map coordinate of this tile in tile units. + * @property {integer} y + */ + this.y = y; + + /** + * The world x coordinate of this tile in pixels. This does not factor in camera scroll, + * layer scale or layer position. + * @property {number} x + */ + this.worldX = x * width; + + /** + * The world y coordinate of this tile in pixels. This does not factor in camera scroll, + * layer scale or layer position. + * @property {number} y + */ + this.worldY = y * height; + + /** + * The width of the tile in pixels. + * @property {integer} width + */ + this.width = width; + + /** + * The height of the tile in pixels. + * @property {integer} height + */ + this.height = height; + + /** + * Tile specific properties. These usually come from Tiled. + * @property {object} properties + */ + this.properties = {}; + + /** + * The rotation angle of this tile. + * @property {number} rotation + */ + this.rotation = 0; + + /** + * Whether the tile should collide with any object on the left side. + * @property {boolean} collideLeft + */ + this.collideLeft = false; + + /** + * Whether the tile should collide with any object on the right side. + * @property {boolean} collideRight + */ + this.collideRight = false; + + /** + * Whether the tile should collide with any object on the top side. + * @property {boolean} collideUp + */ + this.collideUp = false; + + /** + * Whether the tile should collide with any object on the bottom side. + * @property {boolean} collideDown + */ + this.collideDown = false; + + /** + * Whether the tile's left edge is interesting for collisions. + * @property {boolean} faceLeft + */ + this.faceLeft = false; + + /** + * Whether the tile's right edge is interesting for collisions. + * @property {boolean} faceRight + */ + this.faceRight = false; + + /** + * Whether the tile's top edge is interesting for collisions. + * @property {boolean} faceTop + */ + this.faceTop = false; + + /** + * Whether the tile's bottom edge is interesting for collisions. + * @property {boolean} faceBottom + */ + this.faceBottom = false; + + /** + * Tile collision callback. + * @property {function} collisionCallback + */ + this.collisionCallback = null; + + /** + * The context in which the collision callback will be called. + * @property {object} collisionCallbackContext + */ + this.collisionCallbackContext = this; + + /** + * The tint to apply to this tile. Note: tint is currently a single color value instead of + * the 4 corner tint component on other GameObjects. + * @property {number} Tint + * @default + */ + this.tint = 0xffffff; }, - // Copy everything except position & interesting faces + /** + * Check if the given x and y world coordinates are within this Tile. This does not factor in + * camera scroll, layer scale or layer position. + * + * @param {number} x - The x coordinate to test. + * @param {number} y - The y coordinate to test. + * @return {boolean} True if the coordinates are within this Tile, otherwise false. + */ + containsPoint: function (x, y) + { + return !(x < this.worldX || y < this.worldY || x > this.right || y > this.bottom); + }, + + /** + * Copies the tile data & properties from the given tile to this tile. This copies everything + * except for position and interesting faces. + * + * @param {Tile} tile - The tile to copy from. + * @returns {this} + */ copy: function (tile) { this.index = tile.index; @@ -59,12 +199,9 @@ var Tile = new Class({ return this; }, - // Does not factor in scroll offset or tilemap layer position - containsPoint: function (x, y) - { - return !(x < this.worldX || y < this.worldY || x > this.right || y > this.bottom); - }, - + /** + * Clean up memory. + */ destroy: function () { this.collisionCallback = undefined; @@ -72,12 +209,33 @@ var Tile = new Class({ this.properties = undefined; }, - // Does not factor in scroll offset or tilemap layer position + /** + * Check for intersection with this tile. This does not factor in camera scroll, layer scale or + * layer position. + * + * @param {number} x - The x axis in pixels. + * @param {number} y - The y axis in pixels. + * @param {number} right - The right point. + * @param {number} bottom - The bottom point. + * @return {boolean} + */ intersects: function (x, y, right, bottom) { - return !(right <= this.worldX || bottom <= this.worldY || x >= this.right || y >= this.bottom); + return !( + right <= this.worldX || bottom <= this.worldY || + x >= this.right || y >= this.bottom + ); }, + /** + * Checks if the tile is interesting. + * + * @param {boolean} collides - If true, will consider the tile interesting if it collides on any + * side. + * @param {boolean} faces - If true, will consider the tile interesting if it has an interesting + * face. + * @returns {boolean} True if the Tile is interesting, otherwise false. + */ isInteresting: function (collides, faces) { if (collides && faces) { return (this.canCollide || this.hasInterestingFace); } @@ -86,6 +244,11 @@ var Tile = new Class({ return false; }, + /** + * Reset collision status flags. + * + * @returns {this} + */ resetCollision: function () { this.collideLeft = false; @@ -97,8 +260,19 @@ var Tile = new Class({ this.faceBottom = false; this.faceLeft = false; this.faceRight = false; + + return this; }, + /** + * Sets the collision flags for each side of this tile and updates the interesting faces list. + * + * @param {boolean} left - Indicating collide with any object on the left. + * @param {boolean} right - Indicating collide with any object on the right. + * @param {boolean} up - Indicating collide with any object on the top. + * @param {boolean} down - Indicating collide with any object on the bottom. + * @returns {this} + */ setCollision: function (left, right, up, down) { if (right === undefined) { right = left; } @@ -114,11 +288,22 @@ var Tile = new Class({ this.faceRight = right; this.faceTop = up; this.faceBottom = down; + + return this; }, + /** + * Set a callback to be called when this tile is hit by an object. The callback must true for + * collision processing to take place. + * + * @param {function} callback - Callback function. + * @param {object} context - Callback will be called within this context. + * @returns {this} + */ setCollisionCallback: function (callback, context) { - if (callback === null) { + if (callback === null) + { this.collisionCallback = undefined; this.collisionCallbackContext = undefined; } @@ -127,17 +312,32 @@ var Tile = new Class({ this.collisionCallback = callback; this.collisionCallbackContext = context; } + + return this; }, + /** + * Sets the size of the tile and updates its worldX and worldY. + * + * @param {integer} tileWidth - The width of the tile in pixels. + * @param {integer} tileHeight - The height of the tile in pixels. + * @returns {this} + */ setSize: function (tileWidth, tileHeight) { this.worldX = this.x * tileWidth; this.worldY = this.y * tileHeight; this.width = tileWidth; this.height = tileHeight; + + return this; }, - // True if this tile can collide on any of its faces or has a collision callback set. + /** + * True if this tile can collide on any of its faces or has a collision callback set. + * @property {boolean} canCollide + * @readonly + */ canCollide: { get: function () { @@ -145,7 +345,11 @@ var Tile = new Class({ } }, - // True if this tile can collide on any of its faces. + /** + * True if this tile can collide on any of its faces. + * @property {boolean} canCollide + * @readonly + */ collides: { get: function () { @@ -153,7 +357,11 @@ var Tile = new Class({ } }, - // True if this tile has any interesting faces + /** + * True if this tile has any interesting faces. + * @property {boolean} canCollide + * @readonly + */ hasInterestingFace: { get: function () { @@ -161,6 +369,12 @@ var Tile = new Class({ } }, + /** + * The world position of the left side of the tile. This does not factor in camera scroll, layer + * scale or layer position. + * @property {integer} left + * @readonly + */ left: { get: function () { @@ -168,6 +382,12 @@ var Tile = new Class({ } }, + /** + * The world position of the right side of the tile. This does not factor in camera scroll, + * layer scale or layer position. + * @property {integer} right + * @readonly + */ right: { get: function () { @@ -175,6 +395,12 @@ var Tile = new Class({ } }, + /** + * The world position of the top side of the tile. This does not factor in camera scroll, + * layer scale or layer position. + * @property {integer} top + * @readonly + */ top: { get: function () { @@ -182,6 +408,12 @@ var Tile = new Class({ } }, + /** + * The world position of the bottom side of the tile. This does not factor in camera scroll, + * layer scale or layer position. + * @property {integer} bottom + * @readonly + */ bottom: { get: function () { @@ -189,6 +421,12 @@ var Tile = new Class({ } }, + /** + * The x world position of the center of the tile. This does not factor in camera scroll, layer + * scale or layer position. + * @property {integer} centerX + * @readonly + */ centerX: { get: function () { @@ -196,6 +434,12 @@ var Tile = new Class({ } }, + /** + * The y world position of the center of the tile. This does not factor in camera scroll, layer + * scale or layer position. + * @property {integer} centerY + * @readonly + */ centerY: { get: function () {