Skip to content

Instantly share code, notes, and snippets.

Created June 17, 2017 15:55
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 anonymous/c3689d7f99605712b4db3e2b3e0ca79c to your computer and use it in GitHub Desktop.
Save anonymous/c3689d7f99605712b4db3e2b3e0ca79c to your computer and use it in GitHub Desktop.
var gatherMapConfig = function (mapPath) {
var buffer = fse.readFileSync(mapPath),
map = JSON.parse(buffer),
properties = ['dataLength', 'width', 'height', 'tilewidth', 'tileheight'],
prefix = 'Octos.config.map.',
result = [];
// iterate over each desired property
for (var i = 0; i < properties.length; i++) {
var value;
// if we need to calculate the maximum length of data, do so
if (properties[i] === 'dataLength') {
var data = [];
for (var j = 0; j < map.layers.length; j++) {
// if there is no data object, give up
if (typeof map.layers[j].data === 'undefined') { continue; }
// if the current data is bigger than the stored data...
if (map.layers[j].data.length > data.length) {
// store that sweet, sweet big data.
data = map.layers[j].data;
}
}
value = data.length;
} else {
value = map[properties[i]];
}
// shove the properly formatted into the result
result.push(prefix + properties[i] + ' = ' + value + ';');
}
return result.join('\n');
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment