Skip to content

Instantly share code, notes, and snippets.

@LeonMrBonnie
Created October 3, 2019 21:18
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 LeonMrBonnie/8bdd17e10bf453fad5a0ea0464d64dfa to your computer and use it in GitHub Desktop.
Save LeonMrBonnie/8bdd17e10bf453fad5a0ea0464d64dfa to your computer and use it in GitHub Desktop.
RageMP Map Converter
const fs = require('fs');
const path = require('path');
function getPaths(dir, done)
{
let results = [];
fs.readdir(dir, function(err, list)
{
if(err) return done(err);
let pending = list.length;
if(!pending) return done(null, results);
list.forEach(function(file)
{
file = path.resolve(dir, file);
fs.stat(file, function(err, stat)
{
if(stat && stat.isDirectory())
{
results.push(file);
getPaths(file, function(err, res)
{
results = results.concat(res);
if(!--pending) done(null, results);
});
}
else
{
results.push(file);
if(!--pending) done(null, results);
}
});
});
});
};
getPaths(__dirname + "/maps", (error, data) =>
{
if(error) return console.log(error);
let len = data.length;;
for(let i = 0; i < len; i++)
{
let map = JSON.parse(fs.readFileSync(data[i]));
if(map["Map"]) continue;
map["Map"] = {};
map["Map"]["Objects"] = {};
map["Map"]["Objects"]["MapObjects"] = map["Objects"];
delete map["Objects"];
fs.writeFileSync(data[i], JSON.stringify(map));
}
console.log(`Converted ${len} maps`);
process.exit(0);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment