mirror of
https://github.com/photonstorm/phaser
synced 2024-11-10 15:14:47 +00:00
Updated ParseTilesets function to handle Tiled 1.2 and 1.1 formats
This commit is contained in:
parent
8cc7650f8c
commit
bed4abc8ed
3 changed files with 70 additions and 29 deletions
|
@ -11,11 +11,11 @@
|
|||
* `debugConvexHullColor` is a new Matter Physics debug option that lets you set the color of the convex hull, if being drawn to the debug Graphic.
|
||||
* `debugShowSleeping` is a new Matter Physics debug option that lets you draw sleeping bodies at 50% opacity.
|
||||
* Static Tilemap Layers now support tile rotation and flipping. Previously this was a feature only for Dynamic Tilemap Layers, but now both have it. Close #4037 (thanks @thisredone)
|
||||
* `ParseTilesets` has been rewritten so it will convert the new data structures of Tiled 1.2 into the format expected by Phaser, allowing you to use either Tiled 1.2.x or Tiled 1.1 JSON exports. Fix #3998 (thanks @martin-pabst @halgorithm)
|
||||
|
||||
### Updates
|
||||
|
||||
* The Loader has been updated to handle the impact of you destroying the game instance while still processing files. It will no longer throw cache and texture related errors. Fix #4049 (thanks @pantoninho)
|
||||
* `TileSet.getTileData()` has been updated so it will return tile data from either Tiled 1.1.x or the new Tiled 1.2.x JSON structure. Fix #3998 (thanks @martin-pabst @halgorithm)
|
||||
* `Polygon.setTo` can now take a string of space separated numbers when creating the polygon data, i.e.: `'40 0 40 20 100 20 100 80 40 80 40 100 0 50'`. This update also impacts the Polygon Shape object, which can now also take this format as well.
|
||||
* The `poly-decomp` library, as used by Matter.js, has been updated to 0.3.0.
|
||||
* `Matter.verts`, available via `this.matter.verts` from within a Scene, is a quick way of accessing the Matter Vertices functions.
|
||||
|
|
|
@ -223,17 +223,7 @@ var Tileset = new Class({
|
|||
{
|
||||
if (!this.containsTileIndex(tileIndex)) { return null; }
|
||||
|
||||
if (!this.tileIndexMap)
|
||||
{
|
||||
this.tileIndexMap = {};
|
||||
|
||||
for (var i = 0; i < this.tileData.length; i++)
|
||||
{
|
||||
this.tileIndexMap[this.tileData[i]['id']] = this.tileData[i];
|
||||
}
|
||||
}
|
||||
|
||||
return this.tileIndexMap[tileIndex - this.firstgid];
|
||||
return this.tileData[tileIndex - this.firstgid];
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
|
@ -38,27 +38,78 @@ var ParseTilesets = function (json)
|
|||
{
|
||||
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)
|
||||
if (json.version > 1)
|
||||
{
|
||||
newSet.tileProperties = set.tileproperties;
|
||||
}
|
||||
// Tiled 1.2+
|
||||
|
||||
// Object & terrain shapes stored per-tile in object with string indexes starting at "0"
|
||||
if (set.tiles)
|
||||
{
|
||||
newSet.tileData = set.tiles;
|
||||
|
||||
// Parse the objects into Phaser format to match handling of other Tiled objects
|
||||
for (stringID in newSet.tileData)
|
||||
if (Array.isArray(set.tiles))
|
||||
{
|
||||
var objectGroup = newSet.tileData[stringID].objectgroup;
|
||||
if (objectGroup && objectGroup.objects)
|
||||
var tiles = {};
|
||||
var props = {};
|
||||
|
||||
for (var t = 0; t < set.tiles.length; t++)
|
||||
{
|
||||
var parsedObjects = objectGroup.objects.map(
|
||||
function (obj) { return ParseObject(obj); }
|
||||
);
|
||||
newSet.tileData[stringID].objectgroup.objects = parsedObjects;
|
||||
var tile = set.tiles[t];
|
||||
|
||||
// Convert tileproperties
|
||||
if (tile.properties)
|
||||
{
|
||||
var newPropData = {};
|
||||
|
||||
tile.properties.forEach(function (propData)
|
||||
{
|
||||
newPropData[propData['name']] = propData['value'];
|
||||
});
|
||||
|
||||
props[tile.id] = newPropData;
|
||||
}
|
||||
|
||||
// Convert objectgroup
|
||||
if (tile.objectgroup)
|
||||
{
|
||||
tiles[tile.id] = { objectgroup: tile.objectgroup };
|
||||
|
||||
if (tile.objectgroup.objects)
|
||||
{
|
||||
var parsedObjects2 = tile.objectgroup.objects.map(
|
||||
function (obj) { return ParseObject(obj); }
|
||||
);
|
||||
|
||||
tiles[tile.id].objectgroup.objects = parsedObjects2;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
newSet.tileData = tiles;
|
||||
newSet.tileProperties = props;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
// Tiled 1
|
||||
|
||||
// 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 indexes starting at "0"
|
||||
if (set.tiles)
|
||||
{
|
||||
newSet.tileData = set.tiles;
|
||||
|
||||
// Parse the objects into Phaser format to match handling of other Tiled objects
|
||||
for (stringID in newSet.tileData)
|
||||
{
|
||||
var objectGroup = newSet.tileData[stringID].objectgroup;
|
||||
if (objectGroup && objectGroup.objects)
|
||||
{
|
||||
var parsedObjects1 = objectGroup.objects.map(
|
||||
function (obj) { return ParseObject(obj); }
|
||||
);
|
||||
newSet.tileData[stringID].objectgroup.objects = parsedObjects1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue