diff --git a/index.js b/index.js index a51b544..d6d1e48 100644 --- a/index.js +++ b/index.js @@ -43,9 +43,9 @@ var STATE_TILE_DATA_B64_ZLIB = STATE_COUNT++; var STATE_TERRAIN_TYPES = STATE_COUNT++; var STATE_TERRAIN = STATE_COUNT++; -function parse(content, pathToFile, cb) { +function parse(content, pathToFile, cb, strict = false, options = {}) { var pathToDir = path.dirname(pathToFile); - var parser = sax.parser(); + var parser = sax.parser(strict, options); var map; var topLevelObject = null; var state = STATE_START; @@ -356,6 +356,9 @@ function parse(content, pathToFile, cb) { case 'PROPERTIES': collectProperties(object.properties); break; + case 'TEXT': + object.text = collectText(tag.attributes); + break; case 'ELLIPSE': object.ellipse = true; waitForClose(); @@ -376,9 +379,17 @@ function parse(content, pathToFile, cb) { } }, closetag: function(name) { - state = STATE_OBJECT_LAYER; + if (name === 'TEXT') { + state = STATE_OBJECT; + } else { + state = STATE_OBJECT_LAYER; + } }, - text: noop, + text: function(text) { + if (object.text) { + object.text.main = text + } + } }; states[STATE_TILE_OBJECT] = { opentag: function(tag) { @@ -608,6 +619,16 @@ function parse(content, pathToFile, cb) { state = STATE_COLLECT_PROPS; } + function collectText(tagAttributes) { + const text = {}; + for (const attributeName in tagAttributes) { + text[attributeName.toLowerCase()] = tagAttributes[attributeName] + }; + + return text; + } + + function collectAnimations(obj) { animationsObject = obj; animationsNextState = state; @@ -860,6 +881,7 @@ function TmxObject() { this.ellipse = false; this.polygon = null; this.polyline = null; + this.text = {}; } function Terrain() {