validate race data
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good
This commit is contained in:
parent
c18a7a0d8a
commit
4b85519e1a
@ -3,7 +3,10 @@
|
||||
{
|
||||
"raceId" : "human",
|
||||
"displayName" : "Human",
|
||||
"associatedCreatureId" : "human"
|
||||
"associatedCreatureId" : "human",
|
||||
"structureIds": [
|
||||
"defaultHouse"
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
@ -1,8 +1,9 @@
|
||||
{
|
||||
"data" : [
|
||||
{
|
||||
"id" : "test1",
|
||||
"fabPath" : "Data/fab/disjointedroom1.block",
|
||||
"id" : "defaultHouse",
|
||||
"displayName" : "Default House",
|
||||
"fabPath" : "Data/fab/defaultHouse.fab",
|
||||
"dimensions" : {
|
||||
"x" : 100,
|
||||
"y" : 100,
|
||||
|
||||
@ -1867,6 +1867,7 @@ File dialog support
|
||||
Editor structure tab uses file dialog to save fabs
|
||||
Config saving
|
||||
Structure data saving
|
||||
Validate race data
|
||||
|
||||
|
||||
|
||||
|
||||
@ -66,6 +66,10 @@ public class Config {
|
||||
|
||||
CommonEntityMap objectTypeLoader;
|
||||
SymbolMap symbolMap;
|
||||
|
||||
/**
|
||||
* The race data
|
||||
*/
|
||||
RaceMap raceMap;
|
||||
ProjectileTypeHolder projectileTypeHolder;
|
||||
|
||||
|
||||
@ -12,6 +12,7 @@ import electrosphere.data.crafting.RecipeValidator;
|
||||
import electrosphere.data.creature.CreatureData;
|
||||
import electrosphere.data.creature.CreatureDataValidator;
|
||||
import electrosphere.data.creature.CreatureTypeLoader;
|
||||
import electrosphere.server.macro.race.RaceValidator;
|
||||
|
||||
/**
|
||||
* Used to validate the config
|
||||
@ -42,6 +43,9 @@ public class ConfigValidator {
|
||||
//validate recipes
|
||||
RecipeValidator.validate(config);
|
||||
|
||||
//validate races
|
||||
RaceValidator.validate(config);
|
||||
|
||||
ConfigValidator.checkIdCollisions(config);
|
||||
}
|
||||
|
||||
|
||||
@ -12,6 +12,11 @@ public class StructureData {
|
||||
*/
|
||||
String id;
|
||||
|
||||
/**
|
||||
* The display name of the structure
|
||||
*/
|
||||
String displayName;
|
||||
|
||||
/**
|
||||
* The path to the fab for the structure
|
||||
*/
|
||||
@ -35,6 +40,22 @@ public class StructureData {
|
||||
return id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the display name of the structure
|
||||
* @return The display name
|
||||
*/
|
||||
public String getDisplayName(){
|
||||
return displayName;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets the display name of the structure
|
||||
* @param name The display name
|
||||
*/
|
||||
public void setDisplayName(String name){
|
||||
this.displayName = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the path to the fab for the structure
|
||||
* @return The path
|
||||
|
||||
@ -1,5 +1,7 @@
|
||||
package electrosphere.server.macro.race;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import electrosphere.server.macro.character.Character;
|
||||
import electrosphere.server.macro.character.data.CharacterData;
|
||||
import electrosphere.server.macro.character.data.CharacterDataStrings;
|
||||
@ -14,11 +16,21 @@ public class Race extends CharacterData {
|
||||
*/
|
||||
String raceId;
|
||||
|
||||
/**
|
||||
* Display name of the race
|
||||
*/
|
||||
String displayName;
|
||||
|
||||
/**
|
||||
* The associated creature for the race
|
||||
*/
|
||||
String associatedCreatureId;
|
||||
|
||||
/**
|
||||
* The list of structures that this race uses
|
||||
*/
|
||||
List<String> structureIds;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*/
|
||||
@ -41,6 +53,22 @@ public class Race extends CharacterData {
|
||||
public String getAssociatedCreature() {
|
||||
return associatedCreatureId;
|
||||
}
|
||||
|
||||
/**
|
||||
* The display name for the race
|
||||
* @return The display name
|
||||
*/
|
||||
public String getDisplayName() {
|
||||
return displayName;
|
||||
}
|
||||
|
||||
/**
|
||||
* The list of structure IDs that this race uses
|
||||
* @return The list of structure IDs
|
||||
*/
|
||||
public List<String> getStructureIds() {
|
||||
return structureIds;
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a race
|
||||
|
||||
@ -0,0 +1,30 @@
|
||||
package electrosphere.server.macro.race;
|
||||
|
||||
import electrosphere.data.Config;
|
||||
|
||||
/**
|
||||
* Validates race data
|
||||
*/
|
||||
public class RaceValidator {
|
||||
|
||||
/**
|
||||
* Validates a config
|
||||
* @param config The config
|
||||
*/
|
||||
public static void validate(Config config){
|
||||
for(Race race : config.getRaceMap().getRaces()){
|
||||
//check associated creature
|
||||
if(config.getCreatureTypeLoader().getType(race.getAssociatedCreature()) == null){
|
||||
throw new Error("Race " + race.raceId + " creature does not exist: " + race.getAssociatedCreature());
|
||||
}
|
||||
|
||||
//check associated structures
|
||||
for(String structureId : race.getStructureIds()){
|
||||
if(config.getStructureData().getType(structureId) == null){
|
||||
throw new Error("Race " + race.raceId + " structure id does not correspond to a structure: " + structureId);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Reference in New Issue
Block a user