Skip to content

Instantly share code, notes, and snippets.

@drhayes
Created October 3, 2016 19:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save drhayes/5e492f1966b9630a08fd3ef6cdea3e52 to your computer and use it in GitHub Desktop.
Save drhayes/5e492f1966b9630a08fd3ef6cdea3e52 to your computer and use it in GitHub Desktop.
var idableLayers = ['entities', 'switches']
module.exports = function(content) {
this.cacheable && this.cacheable();
var map = JSON.parse(content);
var pathBits = this.resourcePath.split('/');
var mapFilename = pathBits[pathBits.length - 1];
if (map.layers) {
map.layers.forEach(function(layer) {
if (idableLayers.indexOf(layer.name) === -1 ) {
return;
}
layer.objects.forEach(function(obj, i) {
obj.properties = obj.properties || {};
// Generate the ID.
var idPieces = [];
idPieces.push(mapFilename);
idPieces.push(layer.name);
idPieces.push(obj.name);
idPieces.push(i);
obj.properties.id = new Buffer(idPieces.join('|'), 'utf8').toString('base64');
});
});
}
return JSON.stringify(map);
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment