Added in BuildFromConfig support for Static and Dynamic Tilemaps.

This commit is contained in:
photonstorm 2017-06-26 13:16:27 +01:00
parent fe835266fd
commit c5242004c4
7 changed files with 71 additions and 12 deletions

View file

@ -1,4 +1,4 @@
var CHECKSUM = {
build: '1146c000-5865-11e7-a80a-994e778896fe'
build: '2e773640-5a69-11e7-ad23-414a67d4aeba'
};
module.exports = CHECKSUM;

View file

@ -0,0 +1,26 @@
var Tilemap = require('./Tilemap');
var GetValue = require('../../../utils/object/GetValue');
var BuildGameObject = require('../../BuildGameObject');
var BuildFromConfig = function (state, config)
{
var mapData = GetValue(config, 'map.data', null);
var mapWidth = GetValue(config, 'map.width', 1);
var mapHeight = GetValue(config, 'map.height', 1);
var x = GetValue(config, 'x', 0);
var y = GetValue(config, 'y', 0);
var tileWidth = GetValue(config, 'tile.width', 16);
var tileHeight = GetValue(config, 'tile.height', 16);
var tileTexture = GetValue(config, 'tile.texture', null);
var tileFrame = GetValue(config, 'tile.frame', null);
var map = new Tilemap(state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileTexture, tileFrame);
BuildGameObject(state, map, config);
return map;
};
module.exports = BuildFromConfig;

View file

@ -60,7 +60,7 @@ var Tilemap = new Class({
{
var tileArray = this.tileArray;
var mapData = this.mapData;
var frame = this.frame;
// var frame = this.frame;
var tileWidth = this.tileWidth;
var tileHeight = this.tileHeight;
var width = this.texture.source[0].width;
@ -112,6 +112,7 @@ var Tilemap = new Class({
var cameraH = camera.height;
culledTiles.length = 0;
for (var index = 0; index < length; ++index)
{
var tile = tiles[index];
@ -144,20 +145,24 @@ var Tilemap = new Class({
var iy = (y|0);
var tiles = this.tileArray;
var index = iy * this.mapWidth + ix;
if (index < tiles.length)
{
return tiles[index];
}
return null;
},
getTileAtIndex: function (index)
{
var tiles = this.tileArray;
if (index < tiles.length)
{
return tiles[index];
}
return null;
}

View file

@ -1,5 +1,6 @@
var Tilemap = require('./Tilemap');
var BuildFromConfig = require('./BuildFromConfig');
var FactoryContainer = require('../../../gameobjects/FactoryContainer');
var TilemapFactory = {
@ -11,9 +12,9 @@ var TilemapFactory = {
return this.children.add(new Tilemap(this.state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, texture, frame));
},
make: function (mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, texture, frame)
make: function (config)
{
return new Tilemap(this.state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, texture, frame);
return BuildFromConfig(this.state, config);
}
};

View file

@ -0,0 +1,26 @@
var StaticTilemap = require('./StaticTilemap');
var GetValue = require('../../../utils/object/GetValue');
var BuildGameObject = require('../../BuildGameObject');
var BuildFromConfig = function (state, config)
{
var mapData = GetValue(config, 'map.data', null);
var mapWidth = GetValue(config, 'map.width', 1);
var mapHeight = GetValue(config, 'map.height', 1);
var x = GetValue(config, 'x', 0);
var y = GetValue(config, 'y', 0);
var tileWidth = GetValue(config, 'tile.width', 16);
var tileHeight = GetValue(config, 'tile.height', 16);
var tileTexture = GetValue(config, 'tile.texture', null);
var tileFrame = GetValue(config, 'tile.frame', null);
var map = new StaticTilemap(state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileTexture, tileFrame);
BuildGameObject(state, map, config);
return map;
};
module.exports = BuildFromConfig;

View file

@ -1,5 +1,6 @@
var StaticTilemap = require('./StaticTilemap');
var BuildFromConfig = require('./BuildFromConfig');
var FactoryContainer = require('../../../gameobjects/FactoryContainer');
var StaticTilemapFactory = {
@ -11,9 +12,9 @@ var StaticTilemapFactory = {
return this.children.add(new StaticTilemap(this.state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, texture, frame));
},
make: function (mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, texture, frame)
make: function (config)
{
return new StaticTilemap(this.state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, texture, frame);
return BuildFromConfig(this.state, config);
}
};