diff --git a/assets/Data/macro/jobs.json b/assets/Data/macro/jobs.json new file mode 100644 index 00000000..96a260a6 --- /dev/null +++ b/assets/Data/macro/jobs.json @@ -0,0 +1,6 @@ +{ + "jobs": [ + ], + "files": [ + ] +} \ No newline at end of file diff --git a/docs/src/progress/renderertodo.md b/docs/src/progress/renderertodo.md index 71335477..a6ca26e5 100644 --- a/docs/src/progress/renderertodo.md +++ b/docs/src/progress/renderertodo.md @@ -2030,6 +2030,8 @@ Fix client LOD component re-enabling physics positioning Debug rendering of server physics objects Server LOD component properly attaches physics bodies when the entity comes in range Fix physics destruction on server via ServerLODComponent +More job data scaffolding +Config class cleanup diff --git a/src/main/java/electrosphere/data/Config.java b/src/main/java/electrosphere/data/Config.java index ca598f2d..273eeae4 100644 --- a/src/main/java/electrosphere/data/Config.java +++ b/src/main/java/electrosphere/data/Config.java @@ -20,6 +20,7 @@ import electrosphere.data.entity.foliage.FoliageTypeMap; import electrosphere.data.entity.item.ItemDataMap; import electrosphere.data.entity.item.source.ItemSourcingMap; import electrosphere.data.entity.projectile.ProjectileTypeHolder; +import electrosphere.data.macro.job.CharaJobDataLoader; import electrosphere.data.macro.struct.StructureDataLoader; import electrosphere.data.macro.units.UnitDefinitionFile; import electrosphere.data.macro.units.UnitLoader; @@ -41,83 +42,102 @@ public class Config { /** * Top level user settings object */ - UserSettings userSettings; + private UserSettings userSettings; /** * Optional config that can be included alongside engine to inject a default network to populate on the multiplayer screens */ - NetConfig netConfig; + private NetConfig netConfig; /** * The container for all creature definitions */ - CreatureTypeLoader creatureTypeLoader; + private CreatureTypeLoader creatureTypeLoader; /** * The container for all item definitions */ - ItemDataMap itemMap; + private ItemDataMap itemMap; /** * The container for all foliage definitions */ - FoliageTypeLoader foliageMap; + private FoliageTypeLoader foliageMap; + /** + * The object type loader + */ + private CommonEntityMap objectTypeLoader; - CommonEntityMap objectTypeLoader; - SymbolMap symbolMap; + /** + * The symbol map + */ + private SymbolMap symbolMap; /** * The race data */ - RaceMap raceMap; - ProjectileTypeHolder projectileTypeHolder; + private RaceMap raceMap; - //data about every voxel type - VoxelData voxelData; + /** + * The projectile data holder + */ + private ProjectileTypeHolder projectileTypeHolder; + + /** + * data about every voxel type + */ + private VoxelData voxelData; /** * The block data */ - BlockData blockData; + private BlockData blockData; - //the hints that are defined - HintDefinition hintData; + /** + * the hints that are defined + */ + private HintDefinition hintData; /** * The surface audio definitions */ - SurfaceAudioCollection surfaceAudioCollection; + private SurfaceAudioCollection surfaceAudioCollection; /** * The unit loader */ - UnitLoader unitLoader; + private UnitLoader unitLoader; /** * The crafting recipe map */ - RecipeDataMap recipeMap; + private RecipeDataMap recipeMap; /** * The biome map */ - BiomeTypeMap biomeMap; + private BiomeTypeMap biomeMap; /** * The list of sampler definitions */ - List samplerDefinitions; + private List samplerDefinitions; /** * The structure data */ - StructureDataLoader structureData; + private StructureDataLoader structureData; /** * The item sourcing map for items */ - ItemSourcingMap itemSourcingMap; + private ItemSourcingMap itemSourcingMap; + + /** + * Definitions for job types + */ + private CharaJobDataLoader charaJobs; /** * Loads the default data @@ -145,6 +165,7 @@ public class Config { config.biomeMap = BiomeTypeMap.loadBiomeFile("Data/game/biomes.json"); config.samplerDefinitions = SamplerFile.readSamplerDefinitionFiles("Data/game/voxel"); config.structureData = StructureDataLoader.loadStructureFiles("Data/game/structure.json"); + config.charaJobs = CharaJobDataLoader.loadJobFiles("Data/macro/jobs.json"); //create procedural item types ItemDataMap.loadSpawnItems(config.itemMap, config.recipeMap, config.objectTypeLoader); @@ -175,7 +196,7 @@ public class Config { * @param filename The filename * @return The list of entities in the file */ - static List recursiveReadEntityLoader(String filename){ + private static List recursiveReadEntityLoader(String filename){ List typeList = new LinkedList(); CommonEntityLoader loaderFile = FileUtils.loadObjectFromAssetPath(filename, CommonEntityLoader.class); //push the types from this file @@ -197,7 +218,7 @@ public class Config { * @param initialPath The initial path to recurse from * @return The common entity defintion interface */ - static CommonEntityMap loadCommonEntityTypes(String initialPath) { + private static CommonEntityMap loadCommonEntityTypes(String initialPath) { CommonEntityMap rVal = new CommonEntityMap(); List typeList = recursiveReadEntityLoader(initialPath); for(CommonEntityType type : typeList){ @@ -211,7 +232,7 @@ public class Config { * @param filename The filename * @return The list of creatures in the file */ - static List readCreatureTypeFile(String filename){ + private static List readCreatureTypeFile(String filename){ List typeList = new LinkedList(); CreatureTypeMap typeMap = FileUtils.loadObjectFromAssetPath(filename, CreatureTypeMap.class); //push the types from this file @@ -233,7 +254,7 @@ public class Config { * @param initialPath The initial path to recurse from * @return The creature defintion interface */ - static CreatureTypeLoader loadCreatureTypes(String initialPath) { + private static CreatureTypeLoader loadCreatureTypes(String initialPath) { CreatureTypeLoader loader = new CreatureTypeLoader(); List typeList = Config.readCreatureTypeFile(initialPath); for(CreatureData type : typeList){ @@ -256,7 +277,7 @@ public class Config { * @param filename The filename * @return The list of foliage in the file */ - static List readFoliageTypeFile(String filename){ + private static List readFoliageTypeFile(String filename){ List typeList = new LinkedList(); FoliageTypeMap typeMap = FileUtils.loadObjectFromAssetPath(filename, FoliageTypeMap.class); //push the types from this file @@ -278,7 +299,7 @@ public class Config { * @param initialPath The initial path to recurse from * @return The creature defintion interface */ - static FoliageTypeLoader loadFoliageTypes(String initialPath) { + private static FoliageTypeLoader loadFoliageTypes(String initialPath) { FoliageTypeLoader loader = new FoliageTypeLoader(); List typeList = Config.readFoliageTypeFile(initialPath); for(FoliageType type : typeList){ @@ -438,5 +459,13 @@ public class Config { public NetConfig getNetConfig(){ return netConfig; } + + /** + * Gets the job definitions + * @return The job definitions + */ + public CharaJobDataLoader getJobDefinitions(){ + return charaJobs; + } } diff --git a/src/main/java/electrosphere/data/macro/job/CharaJobDataFile.java b/src/main/java/electrosphere/data/macro/job/CharaJobDataFile.java new file mode 100644 index 00000000..d62c1cf4 --- /dev/null +++ b/src/main/java/electrosphere/data/macro/job/CharaJobDataFile.java @@ -0,0 +1,52 @@ +package electrosphere.data.macro.job; + +import java.util.List; + +/** + * A file that stores job data + */ +public class CharaJobDataFile { + + /** + * The list of job definitions + */ + List data; + + /** + * All child files of this one + */ + List files; + + /** + * Gets the job data in this file + * @return The job data in this file + */ + public List getData() { + return data; + } + + /** + * Sets the job data in this file + * @param data The job data in this file + */ + public void setData(List data) { + this.data = data; + } + + /** + * Gets all child files of this one + * @return All child files of this one + */ + public List getFiles() { + return files; + } + + /** + * Sets all child files of this one + * @param files All child files of this one + */ + public void setFiles(List files) { + this.files = files; + } + +} diff --git a/src/main/java/electrosphere/data/macro/job/CharaJobDataLoader.java b/src/main/java/electrosphere/data/macro/job/CharaJobDataLoader.java new file mode 100644 index 00000000..54b4f171 --- /dev/null +++ b/src/main/java/electrosphere/data/macro/job/CharaJobDataLoader.java @@ -0,0 +1,112 @@ +package electrosphere.data.macro.job; + +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; + +/** + * The job type loader + */ +public class CharaJobDataLoader { + + /** + * The map of job name -> job data + */ + Map idTypeMap = new HashMap(); + + /** + * Map of java file object -> job data file at that path + */ + Map fileMap = new HashMap(); + + /** + * Adds job data to the loader + * @param name The id of the job + * @param type The job data + */ + public void putType(String name, CharaJob type){ + idTypeMap.put(name,type); + } + + /** + * Gets job data from the id of the type + * @param id The id of the type + * @return The job data if it exists, null otherwise + */ + public CharaJob getType(String id){ + return idTypeMap.get(id); + } + + /** + * Gets the collection of all job data + * @return the collection of all job data + */ + public Collection getTypes(){ + return idTypeMap.values(); + } + + /** + * Gets the set of all job data id's stored in the loader + * @return the set of all job data ids + */ + public Set getTypeIds(){ + return idTypeMap.keySet(); + } + + /** + * Reads a child job defintion file + * @param loader The loader that is loading all the files + * @param filename The filename + * @return The list of job in the file + */ + static List recursiveReadJobLoader(CharaJobDataLoader loader, String filename){ + List typeList = new LinkedList(); + CharaJobDataFile loaderFile = FileUtils.loadObjectFromAssetPath(filename, CharaJobDataFile.class); + loader.fileMap.put(FileUtils.getAssetFile(filename),loaderFile); + //push the types from this file + for(CharaJob type : loaderFile.getData()){ + typeList.add(type); + } + //push types from any other files + if(loaderFile.getFiles() != null){ + for(String filepath : loaderFile.getFiles()){ + List parsedTypeList = CharaJobDataLoader.recursiveReadJobLoader(loader, filepath); + for(CharaJob type : parsedTypeList){ + typeList.add(type); + } + } + } + return typeList; + } + + /** + * Loads all job definition files recursively + * @param initialPath The initial path to recurse from + * @return The job defintion interface + */ + public static CharaJobDataLoader loadJobFiles(String initialPath) { + CharaJobDataLoader rVal = new CharaJobDataLoader(); + List typeList = CharaJobDataLoader.recursiveReadJobLoader(rVal, initialPath); + for(CharaJob type : typeList){ + rVal.putType(type.getName(), 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()); + } + } + +}