RMMV: new map at runtime

● ARCHIVED · READ-ONLY
Started by Rehwihola 3 posts View original ↗
  1. I think I found a way to generate new maps at runtime. =)

    Code:
                //generate a new map
                nextMapId = $dataMapInfos.length;
                console.log("mapEdgeTransfer generating: ",nextMapName," id: ",nextMapId);
                newMap  =   {"id":nextMapId,"expanded":true,"name":nextMapName,"order":nextMapId,"parentId":0,"scrollX":1716,"scrollY":1048.3636363636365};
                $dataMapInfos.push(newMap);
                //map data file
                var path = require('path');
                var fs = require('fs');
                var sourceFile = path.dirname(process.mainModule.filename)+"/data/Map"+String(nextMapId-1).padZero(3)+".json";
                var targetFile = path.dirname(process.mainModule.filename)+"/data/Map"+String(nextMapId).padZero(3)+".json";
                fs.createReadStream(sourceFile).pipe(fs.createWriteStream(targetFile));
  2. I noticed that $dataMapInfos gets reset when I save & quit & continue. I had to save it too:

    Code:
                //generate a new map
                nextMapId = $dataMapInfos.length;
                console.log("mapEdgeTransfer generating: ",nextMapName," id: ",nextMapId);
                newMap  =   {"id":nextMapId,"expanded":true,"name":nextMapName,"order":nextMapId,"parentId":0,"scrollX":1716,"scrollY":1048.3636363636365};
                $dataMapInfos.push(newMap);
                //copy map file
                var path = require('path');
                var fs = require('fs');
                var sourceFile = path.dirname(process.mainModule.filename)+"/data/Map"+String(nextMapId-1).padZero(3)+".json";
                var targetFile = path.dirname(process.mainModule.filename)+"/data/Map"+String(nextMapId).padZero(3)+".json";
                fs.createReadStream(sourceFile).pipe(fs.createWriteStream(targetFile));
                //save $dataMapInfos file
                targetFile = path.dirname(process.mainModule.filename)+"/data/MapInfos.json";
                fs.writeFileSync(targetFile, JSON.stringify($dataMapInfos));