diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index 53e8f2b5..f7aeecfa 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -1865,6 +1865,8 @@ Invert rotation calculation for fab cursor BlockFab io work File dialog support Editor structure tab uses file dialog to save fabs +Config saving +Structure data saving diff --git a/src/main/java/electrosphere/data/Config.java b/src/main/java/electrosphere/data/Config.java index 052fe5e8..bd3d5522 100644 --- a/src/main/java/electrosphere/data/Config.java +++ b/src/main/java/electrosphere/data/Config.java @@ -27,6 +27,7 @@ import electrosphere.data.units.UnitDefinitionFile; import electrosphere.data.units.UnitLoader; import electrosphere.data.voxel.VoxelData; import electrosphere.data.voxel.sampler.SamplerFile; +import electrosphere.logger.LoggerInterface; import electrosphere.net.config.NetConfig; import electrosphere.server.macro.race.RaceMap; import electrosphere.server.macro.symbolism.SymbolMap; @@ -155,6 +156,15 @@ public class Config { return config; } + /** + * Saves all edits made to the config + * @param config The config + */ + public static void save(Config config){ + LoggerInterface.loggerFileIO.WARNING("Warning! Creatures, items, objects, voxels, blocks are all unsupported currently!"); + config.structureData.save(); + } + /** * Reads a child entity defintion file * @param filename The filename diff --git a/src/main/java/electrosphere/data/struct/StructureDataLoader.java b/src/main/java/electrosphere/data/struct/StructureDataLoader.java index 526c4db7..f8741ec2 100644 --- a/src/main/java/electrosphere/data/struct/StructureDataLoader.java +++ b/src/main/java/electrosphere/data/struct/StructureDataLoader.java @@ -1,10 +1,12 @@ package electrosphere.data.struct; +import java.io.File; import java.util.Collection; import java.util.HashMap; import java.util.LinkedList; import java.util.List; import java.util.Map; +import java.util.Map.Entry; import java.util.Set; import electrosphere.util.FileUtils; @@ -19,6 +21,11 @@ public class StructureDataLoader { */ Map idTypeMap = new HashMap(); + /** + * Map of java file object -> structure data file at that path + */ + Map fileMap = new HashMap(); + /** * Adds structure data to the loader * @param name The id of the structure @@ -55,12 +62,14 @@ public class StructureDataLoader { /** * Reads a child structure defintion file + * @param loader The loader that is loading all the files * @param filename The filename * @return The list of structure in the file */ - static List recursiveReadStructureLoader(String filename){ + static List recursiveReadStructureLoader(StructureDataLoader loader, String filename){ List typeList = new LinkedList(); StructureDataFile loaderFile = FileUtils.loadObjectFromAssetPath(filename, StructureDataFile.class); + loader.fileMap.put(FileUtils.getAssetFile(filename),loaderFile); //push the types from this file for(StructureData type : loaderFile.getData()){ typeList.add(type); @@ -68,7 +77,7 @@ public class StructureDataLoader { //push types from any other files if(loaderFile.getFiles() != null){ for(String filepath : loaderFile.getFiles()){ - List parsedTypeList = StructureDataLoader.recursiveReadStructureLoader(filepath); + List parsedTypeList = StructureDataLoader.recursiveReadStructureLoader(loader, filepath); for(StructureData type : parsedTypeList){ typeList.add(type); } @@ -84,11 +93,20 @@ public class StructureDataLoader { */ public static StructureDataLoader loadStructureFiles(String initialPath) { StructureDataLoader rVal = new StructureDataLoader(); - List typeList = StructureDataLoader.recursiveReadStructureLoader(initialPath); + List typeList = StructureDataLoader.recursiveReadStructureLoader(rVal, initialPath); for(StructureData type : typeList){ rVal.putType(type.getId(), type); } return rVal; } + /** + * Saves the updated state of the loader + */ + public void save(){ + for(Entry pair : this.fileMap.entrySet()){ + FileUtils.serializeObjectToFilePath(pair.getKey(), pair.getValue()); + } + } + }