From 44963d7825a8a6680371e347dc221b26c43a9c82 Mon Sep 17 00:00:00 2001 From: vuphan365 Date: Sun, 17 Jan 2021 00:01:15 +0700 Subject: [PATCH 1/2] feat: Support tag --- index.js | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index a51b544..3434dad 100644 --- a/index.js +++ b/index.js @@ -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() { From 378ed16180433818d9a2c9b26627a7e40aa6ef54 Mon Sep 17 00:00:00 2001 From: vuphan365 Date: Sun, 17 Jan 2021 00:40:20 +0700 Subject: [PATCH 2/2] feat: Allow to change settings of sax parser for trim text --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 3434dad..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;