Skip to content

Commit c524200

Browse files
committed
Added in BuildFromConfig support for Static and Dynamic Tilemaps.
1 parent fe83526 commit c524200

7 files changed

Lines changed: 71 additions & 12 deletions

File tree

v3/src/checksum.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
var CHECKSUM = {
2-
build: '1146c000-5865-11e7-a80a-994e778896fe'
2+
build: '2e773640-5a69-11e7-ad23-414a67d4aeba'
33
};
44
module.exports = CHECKSUM;
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
var Tilemap = require('./Tilemap');
2+
var GetValue = require('../../../utils/object/GetValue');
3+
var BuildGameObject = require('../../BuildGameObject');
4+
5+
var BuildFromConfig = function (state, config)
6+
{
7+
var mapData = GetValue(config, 'map.data', null);
8+
var mapWidth = GetValue(config, 'map.width', 1);
9+
var mapHeight = GetValue(config, 'map.height', 1);
10+
11+
var x = GetValue(config, 'x', 0);
12+
var y = GetValue(config, 'y', 0);
13+
14+
var tileWidth = GetValue(config, 'tile.width', 16);
15+
var tileHeight = GetValue(config, 'tile.height', 16);
16+
var tileTexture = GetValue(config, 'tile.texture', null);
17+
var tileFrame = GetValue(config, 'tile.frame', null);
18+
19+
var map = new Tilemap(state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileTexture, tileFrame);
20+
21+
BuildGameObject(state, map, config);
22+
23+
return map;
24+
};
25+
26+
module.exports = BuildFromConfig;

v3/src/gameobjects/tilemap/dynamic/Tilemap.js

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ var Tilemap = new Class({
4646
this.buildTilemap();
4747
},
4848

49-
getTotalTileCount: function ()
49+
getTotalTileCount: function ()
5050
{
5151
return this.tileArray.length;
5252
},
@@ -56,11 +56,11 @@ var Tilemap = new Class({
5656
return this.cull(camera).length;
5757
},
5858

59-
buildTilemap: function ()
59+
buildTilemap: function ()
6060
{
6161
var tileArray = this.tileArray;
6262
var mapData = this.mapData;
63-
var frame = this.frame;
63+
// var frame = this.frame;
6464
var tileWidth = this.tileWidth;
6565
var tileHeight = this.tileHeight;
6666
var width = this.texture.source[0].width;
@@ -76,8 +76,8 @@ var Tilemap = new Class({
7676
for (var x = 0; x < mapWidth; ++x)
7777
{
7878
var tileId = mapData[y * mapWidth + x];
79-
var halfTileWidth = (tileWidth) * 0.5;
80-
var halfTileHeight = (tileHeight) * 0.5;
79+
var halfTileWidth = (tileWidth) * 0.5;
80+
var halfTileHeight = (tileHeight) * 0.5;
8181
var rectx = (((tileId % setWidth)|0) * tileWidth) + halfTileWidth;
8282
var recty = (((tileId / setWidth)|0) * tileHeight) + halfTileHeight;
8383
var tx = x * tileWidth;
@@ -112,6 +112,7 @@ var Tilemap = new Class({
112112
var cameraH = camera.height;
113113

114114
culledTiles.length = 0;
115+
115116
for (var index = 0; index < length; ++index)
116117
{
117118
var tile = tiles[index];
@@ -144,21 +145,25 @@ var Tilemap = new Class({
144145
var iy = (y|0);
145146
var tiles = this.tileArray;
146147
var index = iy * this.mapWidth + ix;
148+
147149
if (index < tiles.length)
148150
{
149151
return tiles[index];
150152
}
153+
151154
return null;
152155
},
153156

154157
getTileAtIndex: function (index)
155158
{
156159
var tiles = this.tileArray;
160+
157161
if (index < tiles.length)
158162
{
159163
return tiles[index];
160164
}
161-
return null;
165+
166+
return null;
162167
}
163168

164169
});

v3/src/gameobjects/tilemap/dynamic/TilemapFactory.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
var Tilemap = require('./Tilemap');
3+
var BuildFromConfig = require('./BuildFromConfig');
34
var FactoryContainer = require('../../../gameobjects/FactoryContainer');
45

56
var TilemapFactory = {
@@ -11,9 +12,9 @@ var TilemapFactory = {
1112
return this.children.add(new Tilemap(this.state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, texture, frame));
1213
},
1314

14-
make: function (mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, texture, frame)
15+
make: function (config)
1516
{
16-
return new Tilemap(this.state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, texture, frame);
17+
return BuildFromConfig(this.state, config);
1718
}
1819

1920
};

v3/src/gameobjects/tilemap/dynamic/TilemapWebGLRenderer.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ var TilemapWebGLRenderer = function (renderer, gameObject, interpolationPercenta
2727
texture,
2828
x + tile.x, y + tile.y, tile.width, tile.height, alpha * tile.alpha, tile.tint,
2929
scrollFactorX, scrollFactorY,
30-
textureWidth, textureHeight,
30+
textureWidth, textureHeight,
3131
tile.frameX, tile.frameY, tile.frameWidth, tile.frameHeight,
3232
camera,
3333
renderTarget
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
var StaticTilemap = require('./StaticTilemap');
2+
var GetValue = require('../../../utils/object/GetValue');
3+
var BuildGameObject = require('../../BuildGameObject');
4+
5+
var BuildFromConfig = function (state, config)
6+
{
7+
var mapData = GetValue(config, 'map.data', null);
8+
var mapWidth = GetValue(config, 'map.width', 1);
9+
var mapHeight = GetValue(config, 'map.height', 1);
10+
11+
var x = GetValue(config, 'x', 0);
12+
var y = GetValue(config, 'y', 0);
13+
14+
var tileWidth = GetValue(config, 'tile.width', 16);
15+
var tileHeight = GetValue(config, 'tile.height', 16);
16+
var tileTexture = GetValue(config, 'tile.texture', null);
17+
var tileFrame = GetValue(config, 'tile.frame', null);
18+
19+
var map = new StaticTilemap(state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, tileTexture, tileFrame);
20+
21+
BuildGameObject(state, map, config);
22+
23+
return map;
24+
};
25+
26+
module.exports = BuildFromConfig;

v3/src/gameobjects/tilemap/static/StaticTilemapFactory.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11

22
var StaticTilemap = require('./StaticTilemap');
3+
var BuildFromConfig = require('./BuildFromConfig');
34
var FactoryContainer = require('../../../gameobjects/FactoryContainer');
45

56
var StaticTilemapFactory = {
@@ -11,9 +12,9 @@ var StaticTilemapFactory = {
1112
return this.children.add(new StaticTilemap(this.state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, texture, frame));
1213
},
1314

14-
make: function (mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, texture, frame)
15+
make: function (config)
1516
{
16-
return new StaticTilemap(this.state, mapData, x, y, tileWidth, tileHeight, mapWidth, mapHeight, texture, frame);
17+
return BuildFromConfig(this.state, config);
1718
}
1819

1920
};

0 commit comments

Comments
 (0)