id collision validation
All checks were successful
studiorailgun/Renderer/pipeline/head This commit looks good

This commit is contained in:
austin 2025-05-13 13:53:18 -04:00
parent 46d526a26d
commit 595dac8e4b
2 changed files with 42 additions and 0 deletions

View File

@ -1742,6 +1742,7 @@ Fix character bug with loading into level
Multiple loot pool support
Crops replace loot pool on completion of growth
Display name for all common entity data
Enitity id collision validation

View File

@ -1,7 +1,9 @@
package electrosphere.data;
import java.util.HashMap;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import electrosphere.data.common.CommonEntityType;
@ -33,6 +35,45 @@ public class ConfigValidator {
for(CommonEntityType type : allData){
CommonEntityValidator.validate(type);
}
ConfigValidator.checkIdCollisions(config);
}
/**
* Checks if there are any id collisions
* @param config The config
*/
private static void checkIdCollisions(Config config){
//check for id collisions
Map<String,Boolean> occupancyMap = new HashMap<String,Boolean>();
for(CommonEntityType type : config.getObjectTypeMap().getTypes()){
if(occupancyMap.containsKey(type.getId())){
throw new Error("Entity id collision: " + type.getId());
} else {
occupancyMap.put(type.getId(),true);
}
}
for(CommonEntityType type : config.getCreatureTypeLoader().getTypes()){
if(occupancyMap.containsKey(type.getId())){
throw new Error("Entity id collision: " + type.getId());
} else {
occupancyMap.put(type.getId(),true);
}
}
for(CommonEntityType type : config.getFoliageMap().getTypes()){
if(occupancyMap.containsKey(type.getId())){
throw new Error("Entity id collision: " + type.getId());
} else {
occupancyMap.put(type.getId(),true);
}
}
for(CommonEntityType type : config.getItemMap().getTypes()){
if(occupancyMap.containsKey(type.getId())){
throw new Error("Entity id collision: " + type.getId());
} else {
occupancyMap.put(type.getId(),true);
}
}
}
}