Removed lots of redundant code and tidied up bad formatting.

This commit is contained in:
Richard Davey 2016-07-20 19:27:32 +01:00
parent 7645e773dc
commit ca6985e2f2

View file

@ -140,58 +140,41 @@ Phaser.TilemapParser = {
*/
getEmptyData: function (tileWidth, tileHeight, width, height) {
var map = {};
map.width = 0;
map.height = 0;
map.tileWidth = 0;
map.tileHeight = 0;
if (typeof tileWidth !== 'undefined' && tileWidth !== null) { map.tileWidth = tileWidth; }
if (typeof tileHeight !== 'undefined' && tileHeight !== null) { map.tileHeight = tileHeight; }
if (typeof width !== 'undefined' && width !== null) { map.width = width; }
if (typeof height !== 'undefined' && height !== null) { map.height = height; }
map.orientation = 'orthogonal';
map.version = '1';
map.properties = {};
map.widthInPixels = 0;
map.heightInPixels = 0;
var layers = [];
var layer = {
name: 'layer',
x: 0,
y: 0,
width: 0,
height: 0,
return {
width: (width !== undefined && width !== null) ? width : 0,
height: (height !== undefined && height !== null) ? height : 0,
tileWidth: (tileWidth !== undefined && tileWidth !== null) ? tileWidth : 0,
tileHeight: (tileHeight !== undefined && tileHeight !== null) ? tileHeight : 0,
orientation: 'orthogonal',
version: '1',
properties: {},
widthInPixels: 0,
heightInPixels: 0,
alpha: 1,
visible: true,
properties: {},
indexes: [],
callbacks: [],
bodies: [],
data: []
layers: [
{
name: 'layer',
x: 0,
y: 0,
width: 0,
height: 0,
widthInPixels: 0,
heightInPixels: 0,
alpha: 1,
visible: true,
properties: {},
indexes: [],
callbacks: [],
bodies: [],
data: []
}
],
images: [],
objects: {},
collision: {},
tilesets: [],
tiles: []
};
// fill with nulls?
layers.push(layer);
map.layers = layers;
map.images = [];
map.objects = {};
map.collision = {};
map.tilesets = [];
map.tiles = [];
return map;
},
/**
@ -209,18 +192,18 @@ Phaser.TilemapParser = {
}
// Map data will consist of: layers, objects, images, tilesets, sizes
var map = {};
map.width = json.width;
map.height = json.height;
map.tileWidth = json.tilewidth;
map.tileHeight = json.tileheight;
map.orientation = json.orientation;
map.format = Phaser.Tilemap.TILED_JSON;
map.version = json.version;
map.properties = json.properties;
map.widthInPixels = map.width * map.tileWidth;
map.heightInPixels = map.height * map.tileHeight;
var map = {
width: json.width,
height: json.height,
tileWidth: json.tilewidth,
tileHeight: json.tileheight,
orientation: json.orientation,
format: Phaser.Tilemap.TILED_JSON,
version: json.version,
properties: json.properties,
widthInPixels: json.width * json.tileWidth,
heightInPixels: json.height * json.tileHeight
};
// Tile Layers
var layers = [];
@ -236,27 +219,35 @@ Phaser.TilemapParser = {
// Base64 decode data if necessary
// NOTE: uncompressed base64 only.
if (!curl.compression && curl.encoding && curl.encoding === "base64") {
var binaryString = window.atob(curl.data);
if (!curl.compression && curl.encoding && curl.encoding === 'base64')
{
var binaryString = window.atob(curl.data);
var len = binaryString.length;
var bytes = new Array( len );
var bytes = new Array(len);
// Interpret binaryString as an array of bytes representing
// little-endian encoded uint32 values.
for (var j = 0; j < len; j+=4) {
bytes[j/4] = (binaryString.charCodeAt(j) |
binaryString.charCodeAt(j+1) << 8 |
binaryString.charCodeAt(j+2) << 16 |
binaryString.charCodeAt(j+3) << 24) >>> 0;
for (var j = 0; j < len; j+=4)
{
bytes[j / 4] = (
binaryString.charCodeAt(j) |
binaryString.charCodeAt(j + 1) << 8 |
binaryString.charCodeAt(j + 2) << 16 |
binaryString.charCodeAt(j + 3) << 24
) >>> 0;
}
curl.data = bytes;
delete curl.encoding;
}
else if(curl.compression){
else if (curl.compression)
{
console.warn('TilemapParser.parseTiledJSON - Layer compression is unsupported, skipping layer \'' + curl.name + '\'');
continue;
}
var layer = {
name: curl.name,
@ -326,28 +317,34 @@ Phaser.TilemapParser = {
switch (flippedVal)
{
case 5:
rotation = Math.PI/2;
rotation = Math.PI / 2;
break;
case 6:
rotation = Math.PI;
break;
case 3:
rotation = 3*Math.PI/2;
rotation = 3 * Math.PI / 2;
break;
case 4:
rotation = 0;
flipped = true;
break;
case 7:
rotation = Math.PI/2;
rotation = Math.PI / 2;
flipped = true;
break;
case 2:
rotation = Math.PI;
flipped = true;
break;
case 1:
rotation = 3*Math.PI/2;
rotation = 3 * Math.PI / 2;
flipped = true;
break;
}
@ -385,7 +382,6 @@ Phaser.TilemapParser = {
layer.data = output;
layers.push(layer);
}
map.layers = layers;
@ -558,15 +554,14 @@ Phaser.TilemapParser = {
// polygon
else if (curo.objects[v].polygon)
{
var object = slice(curo.objects[v],
["name", "type", "x", "y", "visible", "rotation", "properties" ]);
var object = slice(curo.objects[v], ['name', 'type', 'x', 'y', 'visible', 'rotation', 'properties']);
// Parse the polygon into an array
object.polygon = [];
for (var p = 0; p < curo.objects[v].polygon.length; p++)
{
object.polygon.push([ curo.objects[v].polygon[p].x, curo.objects[v].polygon[p].y ]);
object.polygon.push([curo.objects[v].polygon[p].x, curo.objects[v].polygon[p].y]);
}
objects[curo.name].push(object);
@ -575,15 +570,13 @@ Phaser.TilemapParser = {
// ellipse
else if (curo.objects[v].ellipse)
{
var object = slice(curo.objects[v],
["name", "type", "ellipse", "x", "y", "width", "height", "visible", "rotation", "properties" ]);
var object = slice(curo.objects[v], ['name', 'type', 'ellipse', 'x', 'y', 'width', 'height', 'visible', 'rotation', 'properties']);
objects[curo.name].push(object);
}
// otherwise it's a rectangle
else
{
var object = slice(curo.objects[v],
["name", "type", "x", "y", "width", "height", "visible", "rotation", "properties" ]);
var object = slice(curo.objects[v], ['name', 'type', 'x', 'y', 'width', 'height', 'visible', 'rotation', 'properties']);
object.rectangle = true;
objects[curo.name].push(object);
}