Created
June 17, 2017 15:55
-
-
Save anonymous/c3689d7f99605712b4db3e2b3e0ca79c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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