Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.