265 lines
8.7 KiB
Java
265 lines
8.7 KiB
Java
package electrosphere.game.data;
|
|
|
|
import java.util.LinkedList;
|
|
import java.util.List;
|
|
|
|
import electrosphere.game.data.audio.SurfaceAudioCollection;
|
|
import electrosphere.game.data.common.CommonEntityLoader;
|
|
import electrosphere.game.data.common.CommonEntityMap;
|
|
import electrosphere.game.data.common.CommonEntityType;
|
|
import electrosphere.game.data.creature.type.CreatureData;
|
|
import electrosphere.game.data.creature.type.CreatureTypeLoader;
|
|
import electrosphere.game.data.creature.type.attack.AttackMoveResolver;
|
|
import electrosphere.game.data.creature.type.model.CreatureTypeMap;
|
|
import electrosphere.game.data.foliage.type.model.FoliageTypeMap;
|
|
import electrosphere.game.data.item.type.model.ItemTypeMap;
|
|
import electrosphere.game.data.particle.ParticleDefinition;
|
|
import electrosphere.game.data.projectile.ProjectileTypeHolder;
|
|
import electrosphere.game.data.tutorial.HintDefinition;
|
|
import electrosphere.game.data.units.UnitDefinitionFile;
|
|
import electrosphere.game.data.units.UnitLoader;
|
|
import electrosphere.game.data.voxel.VoxelData;
|
|
import electrosphere.game.server.race.model.RaceMap;
|
|
import electrosphere.game.server.symbolism.model.SymbolMap;
|
|
import electrosphere.util.FileUtils;
|
|
|
|
/**
|
|
* Current configuration for the data of the game
|
|
*/
|
|
public class Config {
|
|
|
|
CreatureTypeLoader creatureTypeLoader;
|
|
ItemTypeMap itemMap;
|
|
FoliageTypeMap foliageMap;
|
|
CommonEntityMap objectTypeLoader;
|
|
SymbolMap symbolMap;
|
|
RaceMap raceMap;
|
|
ProjectileTypeHolder projectileTypeHolder;
|
|
|
|
//data about every voxel type
|
|
VoxelData voxelData;
|
|
|
|
//the hints that are defined
|
|
HintDefinition hintData;
|
|
|
|
/**
|
|
* The surface audio definitions
|
|
*/
|
|
SurfaceAudioCollection surfaceAudioCollection;
|
|
|
|
/**
|
|
* The particle definition
|
|
*/
|
|
ParticleDefinition particleDefinition;
|
|
|
|
/**
|
|
* The unit loader
|
|
*/
|
|
UnitLoader unitLoader;
|
|
|
|
/**
|
|
* Loads the default data
|
|
* @return The config
|
|
*/
|
|
public static Config loadDefaultConfig(){
|
|
Config config = new Config();
|
|
config.creatureTypeLoader = loadCreatureTypes("Data/entity/creatures.json");
|
|
config.itemMap = FileUtils.loadObjectFromAssetPath("Data/entity/items.json", ItemTypeMap.class);
|
|
config.foliageMap = FileUtils.loadObjectFromAssetPath("Data/entity/foliage.json", FoliageTypeMap.class);
|
|
config.objectTypeLoader = loadCommonEntityTypes("Data/entity/objects.json");
|
|
config.symbolMap = FileUtils.loadObjectFromAssetPath("Data/game/symbolism.json", SymbolMap.class);
|
|
config.raceMap = FileUtils.loadObjectFromAssetPath("Data/game/races.json", RaceMap.class);
|
|
config.voxelData = FileUtils.loadObjectFromAssetPath("Data/game/voxelTypes.json", VoxelData.class);
|
|
config.projectileTypeHolder = FileUtils.loadObjectFromAssetPath("Data/entity/projectile.json", ProjectileTypeHolder.class);
|
|
config.hintData = FileUtils.loadObjectFromAssetPath("Data/tutorial/hints.json", HintDefinition.class);
|
|
config.surfaceAudioCollection = FileUtils.loadObjectFromAssetPath("Data/audio/surface.json", SurfaceAudioCollection.class);
|
|
config.particleDefinition = FileUtils.loadObjectFromAssetPath("Data/entity/particles.json", ParticleDefinition.class);
|
|
config.projectileTypeHolder.init();
|
|
config.unitLoader = UnitLoader.create(FileUtils.loadObjectFromAssetPath("Data/game/units/units.json", UnitDefinitionFile.class));
|
|
|
|
//validate
|
|
ConfigValidator.valdiate(config);
|
|
|
|
|
|
return config;
|
|
}
|
|
|
|
/**
|
|
* Reads a child entity defintion file
|
|
* @param filename The filename
|
|
* @return The list of entities in the file
|
|
*/
|
|
static List<CommonEntityType> recursiveReadEntityLoader(String filename){
|
|
List<CommonEntityType> typeList = new LinkedList<CommonEntityType>();
|
|
CommonEntityLoader loaderFile = FileUtils.loadObjectFromAssetPath(filename, CommonEntityLoader.class);
|
|
//push the types from this file
|
|
for(CommonEntityType type : loaderFile.getEntities()){
|
|
typeList.add(type);
|
|
}
|
|
//push types from any other files
|
|
for(String filepath : loaderFile.getFiles()){
|
|
List<CommonEntityType> parsedTypeList = recursiveReadEntityLoader(filepath);
|
|
for(CommonEntityType type : parsedTypeList){
|
|
typeList.add(type);
|
|
}
|
|
}
|
|
return typeList;
|
|
}
|
|
|
|
/**
|
|
* Loads all common entity definition files recursively
|
|
* @param initialPath The initial path to recurse from
|
|
* @return The common entity defintion interface
|
|
*/
|
|
static CommonEntityMap loadCommonEntityTypes(String initialPath) {
|
|
CommonEntityMap rVal = new CommonEntityMap();
|
|
List<CommonEntityType> typeList = recursiveReadEntityLoader(initialPath);
|
|
for(CommonEntityType type : typeList){
|
|
rVal.putType(type.getId(), type);
|
|
}
|
|
return rVal;
|
|
}
|
|
|
|
/**
|
|
* Reads a child creature defintion file
|
|
* @param filename The filename
|
|
* @return The list of creatures in the file
|
|
*/
|
|
static List<CreatureData> readCreatureTypeFile(String filename){
|
|
List<CreatureData> typeList = new LinkedList<CreatureData>();
|
|
CreatureTypeMap typeMap = FileUtils.loadObjectFromAssetPath(filename, CreatureTypeMap.class);
|
|
//push the types from this file
|
|
for(CreatureData type : typeMap.getCreatures()){
|
|
typeList.add(type);
|
|
}
|
|
//push types from any other files
|
|
for(String filepath : typeMap.getFiles()){
|
|
List<CreatureData> parsedTypeList = readCreatureTypeFile(filepath);
|
|
for(CreatureData type : parsedTypeList){
|
|
typeList.add(type);
|
|
}
|
|
}
|
|
return typeList;
|
|
}
|
|
|
|
/**
|
|
* Loads all creature definition files recursively
|
|
* @param initialPath The initial path to recurse from
|
|
* @return The creature defintion interface
|
|
*/
|
|
static CreatureTypeLoader loadCreatureTypes(String initialPath) {
|
|
CreatureTypeLoader loader = new CreatureTypeLoader();
|
|
List<CreatureData> typeList = readCreatureTypeFile(initialPath);
|
|
for(CreatureData type : typeList){
|
|
if(type.getAttackMoves() != null){
|
|
type.setAttackMoveResolver(new AttackMoveResolver(type.getAttackMoves()));
|
|
}
|
|
loader.putType(type.getId(), type);
|
|
//loop through all creatures and add ones with PLAYABLE token to list of playable races
|
|
for(String token : type.getTokens()){
|
|
if(token.contains("PLAYABLE")){
|
|
loader.putPlayableRace(type.getId());
|
|
}
|
|
}
|
|
}
|
|
return loader;
|
|
}
|
|
|
|
/**
|
|
* Gets the interface for creature definitions loaded into memory
|
|
* @return The interface
|
|
*/
|
|
public CreatureTypeLoader getCreatureTypeLoader() {
|
|
return creatureTypeLoader;
|
|
}
|
|
|
|
/**
|
|
* Gets the data on all item types in memory
|
|
* @return the data on all items
|
|
*/
|
|
public ItemTypeMap getItemMap() {
|
|
return itemMap;
|
|
}
|
|
|
|
/**
|
|
* Gets the data on all foliage types in memory
|
|
* @return The foliage data
|
|
*/
|
|
public FoliageTypeMap getFoliageMap() {
|
|
return foliageMap;
|
|
}
|
|
|
|
/**
|
|
* Gets the symbolism map
|
|
* @return The symbolism map
|
|
*/
|
|
public SymbolMap getSymbolMap() {
|
|
return symbolMap;
|
|
}
|
|
|
|
/**
|
|
* Gets the data that defines all creature races in the engine
|
|
* @return The data on all races
|
|
*/
|
|
public RaceMap getRaceMap() {
|
|
return raceMap;
|
|
}
|
|
|
|
/**
|
|
* Gets the definitions of all object entities in memory
|
|
* @return The objects
|
|
*/
|
|
public CommonEntityMap getObjectTypeMap() {
|
|
return objectTypeLoader;
|
|
}
|
|
|
|
/**
|
|
* Gets the definitions all projectiles
|
|
* @return the projectile data
|
|
*/
|
|
public ProjectileTypeHolder getProjectileMap(){
|
|
return projectileTypeHolder;
|
|
}
|
|
|
|
/**
|
|
* Gets the voxel data
|
|
* @return The voxel data
|
|
*/
|
|
public VoxelData getVoxelData(){
|
|
return voxelData;
|
|
}
|
|
|
|
/**
|
|
* The tutorial hints data
|
|
* @return The hints
|
|
*/
|
|
public HintDefinition getHintData(){
|
|
return hintData;
|
|
}
|
|
|
|
/**
|
|
* Gets the surface audio collection
|
|
* @return The surface audio collection
|
|
*/
|
|
public SurfaceAudioCollection getSurfaceAudioCollection(){
|
|
return this.surfaceAudioCollection;
|
|
}
|
|
|
|
/**
|
|
* Gets the particle definition
|
|
* @return The particle definition
|
|
*/
|
|
public ParticleDefinition getParticleDefinition(){
|
|
return particleDefinition;
|
|
}
|
|
|
|
/**
|
|
* Gets the unit loader
|
|
* @return The unit loader
|
|
*/
|
|
public UnitLoader getUnitLoader(){
|
|
return unitLoader;
|
|
}
|
|
|
|
}
|