Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 26 additions & 4 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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) {
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -860,6 +881,7 @@ function TmxObject() {
this.ellipse = false;
this.polygon = null;
this.polyline = null;
this.text = {};
}

function Terrain() {
Expand Down