config saving, structure saving
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2025-05-18 12:22:06 -04:00
parent 48c5a3bcf3
commit c18a7a0d8a
3 changed files with 33 additions and 3 deletions

View File

@ -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

View File

@ -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

View File

@ -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<String,StructureData> idTypeMap = new HashMap<String,StructureData>();
/**
* Map of java file object -> structure data file at that path
*/
Map<File,StructureDataFile> fileMap = new HashMap<File,StructureDataFile>();
/**
* 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<StructureData> recursiveReadStructureLoader(String filename){
static List<StructureData> recursiveReadStructureLoader(StructureDataLoader loader, String filename){
List<StructureData> typeList = new LinkedList<StructureData>();
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<StructureData> parsedTypeList = StructureDataLoader.recursiveReadStructureLoader(filepath);
List<StructureData> 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<StructureData> typeList = StructureDataLoader.recursiveReadStructureLoader(initialPath);
List<StructureData> 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<File,StructureDataFile> pair : this.fileMap.entrySet()){
FileUtils.serializeObjectToFilePath(pair.getKey(), pair.getValue());
}
}
}