From 0295b0c169bc96273870aac07db977c867bf3b0c Mon Sep 17 00:00:00 2001 From: NathanSweet Date: Tue, 6 May 2014 19:15:48 +0200 Subject: [PATCH] Read new atlas format that has width and height for each page. --- spine-as3/spine-as3/src/spine/atlas/Atlas.as | 15 ++++++++------- spine-js/spine.js | 14 ++++++++------ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/spine-as3/spine-as3/src/spine/atlas/Atlas.as b/spine-as3/spine-as3/src/spine/atlas/Atlas.as index d54996487..d2fc0ab6e 100644 --- a/spine-as3/spine-as3/src/spine/atlas/Atlas.as +++ b/spine-as3/spine-as3/src/spine/atlas/Atlas.as @@ -68,7 +68,12 @@ public class Atlas { page = new AtlasPage(); page.name = line; - page.format = Format[reader.readValue()]; + if (reader.readTuple(tuple) == 2) { // size is only optional for an atlas packed with an old TexturePacker. + page.width = parseInt(tuple[0]); + page.height = parseInt(tuple[1]); + reader.readTuple(tuple); + } + page.format = Format[tuple[0]]; reader.readTuple(tuple); page.minFilter = TextureFilter[tuple[0]]; @@ -186,7 +191,7 @@ class Reader { return trim(line.substring(colon + 1)); } - /** Returns the number of tuple values read (2 or 4). */ + /** Returns the number of tuple values read (1, 2 or 4). */ public function readTuple (tuple:Array) : int { var line:String = readLine(); var colon:int = line.indexOf(":"); @@ -195,11 +200,7 @@ class Reader { var i:int = 0, lastMatch:int = colon + 1; for (; i < 3; i++) { var comma:int = line.indexOf(",", lastMatch); - if (comma == -1) { - if (i == 0) - throw new Error("Invalid line: " + line); - break; - } + if (comma == -1) break; tuple[i] = trim(line.substr(lastMatch, comma - lastMatch)); lastMatch = comma + 1; } diff --git a/spine-js/spine.js b/spine-js/spine.js index 1b6c4cdc8..4330330fb 100644 --- a/spine-js/spine.js +++ b/spine-js/spine.js @@ -1443,7 +1443,12 @@ spine.Atlas = function (atlasText, textureLoader) { page = new spine.AtlasPage(); page.name = line; - page.format = spine.Atlas.Format[reader.readValue()]; + if (reader.readTuple(tuple) == 2) { // size is only optional for an atlas packed with an old TexturePacker. + page.width = parseInt(tuple[0]); + page.height = parseInt(tuple[1]); + reader.readTuple(tuple); + } + page.format = spine.Atlas.Format[tuple[0]]; reader.readTuple(tuple); page.minFilter = spine.Atlas.TextureFilter[tuple[0]]; @@ -1617,7 +1622,7 @@ spine.AtlasReader.prototype = { if (colon == -1) throw "Invalid line: " + line; return this.trim(line.substring(colon + 1)); }, - /** Returns the number of tuple values read (2 or 4). */ + /** Returns the number of tuple values read (1, 2 or 4). */ readTuple: function (tuple) { var line = this.readLine(); var colon = line.indexOf(":"); @@ -1625,10 +1630,7 @@ spine.AtlasReader.prototype = { var i = 0, lastMatch = colon + 1; for (; i < 3; i++) { var comma = line.indexOf(",", lastMatch); - if (comma == -1) { - if (i == 0) throw "Invalid line: " + line; - break; - } + if (comma == -1) break; tuple[i] = this.trim(line.substr(lastMatch, comma - lastMatch)); lastMatch = comma + 1; }