mirror of
https://github.com/photonstorm/phaser
synced 2024-11-30 16:39:34 +00:00
Removed lots of redundant code and tidied up bad formatting.
This commit is contained in:
parent
7645e773dc
commit
ca6985e2f2
1 changed files with 75 additions and 82 deletions
|
@ -140,58 +140,41 @@ Phaser.TilemapParser = {
|
||||||
*/
|
*/
|
||||||
getEmptyData: function (tileWidth, tileHeight, width, height) {
|
getEmptyData: function (tileWidth, tileHeight, width, height) {
|
||||||
|
|
||||||
var map = {};
|
return {
|
||||||
|
width: (width !== undefined && width !== null) ? width : 0,
|
||||||
map.width = 0;
|
height: (height !== undefined && height !== null) ? height : 0,
|
||||||
map.height = 0;
|
tileWidth: (tileWidth !== undefined && tileWidth !== null) ? tileWidth : 0,
|
||||||
map.tileWidth = 0;
|
tileHeight: (tileHeight !== undefined && tileHeight !== null) ? tileHeight : 0,
|
||||||
map.tileHeight = 0;
|
orientation: 'orthogonal',
|
||||||
|
version: '1',
|
||||||
if (typeof tileWidth !== 'undefined' && tileWidth !== null) { map.tileWidth = tileWidth; }
|
properties: {},
|
||||||
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,
|
|
||||||
widthInPixels: 0,
|
widthInPixels: 0,
|
||||||
heightInPixels: 0,
|
heightInPixels: 0,
|
||||||
alpha: 1,
|
layers: [
|
||||||
visible: true,
|
{
|
||||||
properties: {},
|
name: 'layer',
|
||||||
indexes: [],
|
x: 0,
|
||||||
callbacks: [],
|
y: 0,
|
||||||
bodies: [],
|
width: 0,
|
||||||
data: []
|
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
|
// Map data will consist of: layers, objects, images, tilesets, sizes
|
||||||
var map = {};
|
var map = {
|
||||||
|
width: json.width,
|
||||||
map.width = json.width;
|
height: json.height,
|
||||||
map.height = json.height;
|
tileWidth: json.tilewidth,
|
||||||
map.tileWidth = json.tilewidth;
|
tileHeight: json.tileheight,
|
||||||
map.tileHeight = json.tileheight;
|
orientation: json.orientation,
|
||||||
map.orientation = json.orientation;
|
format: Phaser.Tilemap.TILED_JSON,
|
||||||
map.format = Phaser.Tilemap.TILED_JSON;
|
version: json.version,
|
||||||
map.version = json.version;
|
properties: json.properties,
|
||||||
map.properties = json.properties;
|
widthInPixels: json.width * json.tileWidth,
|
||||||
map.widthInPixels = map.width * map.tileWidth;
|
heightInPixels: json.height * json.tileHeight
|
||||||
map.heightInPixels = map.height * map.tileHeight;
|
};
|
||||||
|
|
||||||
// Tile Layers
|
// Tile Layers
|
||||||
var layers = [];
|
var layers = [];
|
||||||
|
@ -236,27 +219,35 @@ Phaser.TilemapParser = {
|
||||||
|
|
||||||
// Base64 decode data if necessary
|
// Base64 decode data if necessary
|
||||||
// NOTE: uncompressed base64 only.
|
// 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 len = binaryString.length;
|
||||||
var bytes = new Array( len );
|
var bytes = new Array(len);
|
||||||
|
|
||||||
// Interpret binaryString as an array of bytes representing
|
// Interpret binaryString as an array of bytes representing
|
||||||
// little-endian encoded uint32 values.
|
// little-endian encoded uint32 values.
|
||||||
for (var j = 0; j < len; j+=4) {
|
for (var j = 0; j < len; j+=4)
|
||||||
bytes[j/4] = (binaryString.charCodeAt(j) |
|
{
|
||||||
binaryString.charCodeAt(j+1) << 8 |
|
bytes[j / 4] = (
|
||||||
binaryString.charCodeAt(j+2) << 16 |
|
binaryString.charCodeAt(j) |
|
||||||
binaryString.charCodeAt(j+3) << 24) >>> 0;
|
binaryString.charCodeAt(j + 1) << 8 |
|
||||||
|
binaryString.charCodeAt(j + 2) << 16 |
|
||||||
|
binaryString.charCodeAt(j + 3) << 24
|
||||||
|
) >>> 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
curl.data = bytes;
|
curl.data = bytes;
|
||||||
|
|
||||||
delete curl.encoding;
|
delete curl.encoding;
|
||||||
}
|
}
|
||||||
else if(curl.compression){
|
else if (curl.compression)
|
||||||
|
{
|
||||||
console.warn('TilemapParser.parseTiledJSON - Layer compression is unsupported, skipping layer \'' + curl.name + '\'');
|
console.warn('TilemapParser.parseTiledJSON - Layer compression is unsupported, skipping layer \'' + curl.name + '\'');
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
var layer = {
|
var layer = {
|
||||||
|
|
||||||
name: curl.name,
|
name: curl.name,
|
||||||
|
@ -326,28 +317,34 @@ Phaser.TilemapParser = {
|
||||||
switch (flippedVal)
|
switch (flippedVal)
|
||||||
{
|
{
|
||||||
case 5:
|
case 5:
|
||||||
rotation = Math.PI/2;
|
rotation = Math.PI / 2;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 6:
|
case 6:
|
||||||
rotation = Math.PI;
|
rotation = Math.PI;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 3:
|
case 3:
|
||||||
rotation = 3*Math.PI/2;
|
rotation = 3 * Math.PI / 2;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 4:
|
case 4:
|
||||||
rotation = 0;
|
rotation = 0;
|
||||||
flipped = true;
|
flipped = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 7:
|
case 7:
|
||||||
rotation = Math.PI/2;
|
rotation = Math.PI / 2;
|
||||||
flipped = true;
|
flipped = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 2:
|
case 2:
|
||||||
rotation = Math.PI;
|
rotation = Math.PI;
|
||||||
flipped = true;
|
flipped = true;
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case 1:
|
case 1:
|
||||||
rotation = 3*Math.PI/2;
|
rotation = 3 * Math.PI / 2;
|
||||||
flipped = true;
|
flipped = true;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -385,7 +382,6 @@ Phaser.TilemapParser = {
|
||||||
layer.data = output;
|
layer.data = output;
|
||||||
|
|
||||||
layers.push(layer);
|
layers.push(layer);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
map.layers = layers;
|
map.layers = layers;
|
||||||
|
@ -558,15 +554,14 @@ Phaser.TilemapParser = {
|
||||||
// polygon
|
// polygon
|
||||||
else if (curo.objects[v].polygon)
|
else if (curo.objects[v].polygon)
|
||||||
{
|
{
|
||||||
var object = slice(curo.objects[v],
|
var object = slice(curo.objects[v], ['name', 'type', 'x', 'y', 'visible', 'rotation', 'properties']);
|
||||||
["name", "type", "x", "y", "visible", "rotation", "properties" ]);
|
|
||||||
|
|
||||||
// Parse the polygon into an array
|
// Parse the polygon into an array
|
||||||
object.polygon = [];
|
object.polygon = [];
|
||||||
|
|
||||||
for (var p = 0; p < curo.objects[v].polygon.length; p++)
|
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);
|
objects[curo.name].push(object);
|
||||||
|
@ -575,15 +570,13 @@ Phaser.TilemapParser = {
|
||||||
// ellipse
|
// ellipse
|
||||||
else if (curo.objects[v].ellipse)
|
else if (curo.objects[v].ellipse)
|
||||||
{
|
{
|
||||||
var object = slice(curo.objects[v],
|
var object = slice(curo.objects[v], ['name', 'type', 'ellipse', 'x', 'y', 'width', 'height', 'visible', 'rotation', 'properties']);
|
||||||
["name", "type", "ellipse", "x", "y", "width", "height", "visible", "rotation", "properties" ]);
|
|
||||||
objects[curo.name].push(object);
|
objects[curo.name].push(object);
|
||||||
}
|
}
|
||||||
// otherwise it's a rectangle
|
// otherwise it's a rectangle
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
var object = slice(curo.objects[v],
|
var object = slice(curo.objects[v], ['name', 'type', 'x', 'y', 'width', 'height', 'visible', 'rotation', 'properties']);
|
||||||
["name", "type", "x", "y", "width", "height", "visible", "rotation", "properties" ]);
|
|
||||||
object.rectangle = true;
|
object.rectangle = true;
|
||||||
objects[curo.name].push(object);
|
objects[curo.name].push(object);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue