SHARE
TWEET

Rage MapConverter

Leon1337 Oct 3rd, 2019 11 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. const fs = require('fs');
  2. const path = require('path');
  3.  
  4. function getPaths(dir, done)
  5. {
  6.     let results = [];
  7.     fs.readdir(dir, function(err, list)
  8.     {
  9.         if(err) return done(err);
  10.         let pending = list.length;
  11.         if(!pending) return done(null, results);
  12.         list.forEach(function(file)
  13.         {
  14.             file = path.resolve(dir, file);
  15.             fs.stat(file, function(err, stat)
  16.             {
  17.                 if(stat && stat.isDirectory())
  18.                 {
  19.                     results.push(file);
  20.                     getPaths(file, function(err, res)
  21.                     {
  22.                         results = results.concat(res);
  23.                         if(!--pending) done(null, results);
  24.                     });
  25.                 }
  26.                 else
  27.                 {
  28.                     results.push(file);
  29.                     if(!--pending) done(null, results);
  30.                 }
  31.             });
  32.         });
  33.     });
  34. };
  35.  
  36. getPaths(__dirname + "/maps", (error, data) =>
  37. {
  38.     if(error) return console.log(error);
  39.     let len = data.length;;
  40.     for(let i = 0; i < len; i++)
  41.     {
  42.         let map = JSON.parse(fs.readFileSync(data[i]));
  43.         if(map["Map"]) continue;
  44.         map["Map"] = {};
  45.         map["Map"]["Objects"] = {};
  46.         map["Map"]["Objects"]["MapObjects"] = map["Objects"];
  47.         delete map["Objects"];
  48.         fs.writeFileSync(data[i], JSON.stringify(map));
  49.     }
  50.     console.log(`Converted ${len} maps`);
  51.     process.exit(0);
  52. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top