recipe validation, loot pool validation, data fix
Some checks failed
studiorailgun/Renderer/pipeline/head There was a failure building this commit

This commit is contained in:
austin 2025-05-14 15:50:56 -04:00
parent 6c6efbebf6
commit 5cc5ea5bc9
7 changed files with 68 additions and 51 deletions

View File

@ -46,17 +46,7 @@
}, },
"healthSystem" : { "healthSystem" : {
"maxHealth" : 5, "maxHealth" : 5,
"onDamageIFrames" : 0, "onDamageIFrames" : 0
"lootPool" : {
"tickets" : [
{
"itemId" : "mat:Rock",
"rarity" : 1.0,
"minQuantity" : 1,
"maxQuantity" : 1
}
]
}
} }
} }

View File

@ -203,7 +203,7 @@
"maxQuantity" : 5 "maxQuantity" : 5
}, },
{ {
"itemId" : "block:wood", "itemId" : "block:Wood",
"rarity" : 0.8, "rarity" : 0.8,
"minQuantity" : 0, "minQuantity" : 0,
"maxQuantity" : 5 "maxQuantity" : 5

View File

@ -1,7 +1,7 @@
{ {
"recipes": [ "recipes": [
{ {
"displayName": "Refiend Wood", "displayName": "Refined Wood",
"craftingTag" : "HAND", "craftingTag" : "HAND",
"ingredients": [ "ingredients": [
{ {
@ -11,7 +11,7 @@
], ],
"products": [ "products": [
{ {
"itemType": "block:refined_wood", "itemType": "block:Wood (Refined)",
"count": 16 "count": 16
} }
] ]
@ -27,7 +27,7 @@
], ],
"products": [ "products": [
{ {
"itemType": "block:brick_fant", "itemType": "block:Brick (Fantasy)",
"count": 16 "count": 16
} }
] ]
@ -37,13 +37,13 @@
"craftingTag" : "HAND", "craftingTag" : "HAND",
"ingredients": [ "ingredients": [
{ {
"itemType": "vox:rock_shale", "itemType": "vox:Rock (Shale)",
"count": 1 "count": 1
} }
], ],
"products": [ "products": [
{ {
"itemType": "block:brick_fant", "itemType": "block:Brick (Fantasy)",
"count": 16 "count": 16
} }
] ]

View File

@ -1,37 +1,5 @@
{ {
"recipes": [ "recipes": [
{
"displayName": "Katana (Two Hand)",
"craftingTag" : "DEBUG",
"ingredients": [
{
"itemType": "katana2H",
"count": 1
}
],
"products": [
{
"itemType": "katana2H",
"count": 1
}
]
},
{
"displayName": "Katana (One Hand)",
"craftingTag" : "DEBUG",
"ingredients": [
{
"itemType": "katana",
"count": 1
}
],
"products": [
{
"itemType": "katana",
"count": 1
}
]
}
], ],
"files": [ "files": [

View File

@ -8,6 +8,7 @@ import java.util.stream.Collectors;
import electrosphere.data.common.CommonEntityType; import electrosphere.data.common.CommonEntityType;
import electrosphere.data.common.CommonEntityValidator; import electrosphere.data.common.CommonEntityValidator;
import electrosphere.data.crafting.RecipeValidator;
import electrosphere.data.creature.CreatureData; import electrosphere.data.creature.CreatureData;
import electrosphere.data.creature.CreatureDataValidator; import electrosphere.data.creature.CreatureDataValidator;
import electrosphere.data.creature.CreatureTypeLoader; import electrosphere.data.creature.CreatureTypeLoader;
@ -27,15 +28,20 @@ public class ConfigValidator {
for(CreatureData creatureData : creatureTypeLoader.getTypes()){ for(CreatureData creatureData : creatureTypeLoader.getTypes()){
CreatureDataValidator.validate(creatureData); CreatureDataValidator.validate(creatureData);
} }
//validate common entity data
List<CommonEntityType> allData = new LinkedList<CommonEntityType>(); List<CommonEntityType> allData = new LinkedList<CommonEntityType>();
allData.addAll(config.getCreatureTypeLoader().getTypeIds().stream().map((String id) -> {return config.getCreatureTypeLoader().getType(id);}).collect(Collectors.toList())); allData.addAll(config.getCreatureTypeLoader().getTypeIds().stream().map((String id) -> {return config.getCreatureTypeLoader().getType(id);}).collect(Collectors.toList()));
allData.addAll(config.getFoliageMap().getTypeIds().stream().map((String id) -> {return config.getFoliageMap().getType(id);}).collect(Collectors.toList())); allData.addAll(config.getFoliageMap().getTypeIds().stream().map((String id) -> {return config.getFoliageMap().getType(id);}).collect(Collectors.toList()));
allData.addAll(config.getItemMap().getTypeIds().stream().map((String id) -> {return config.getItemMap().getType(id);}).collect(Collectors.toList())); allData.addAll(config.getItemMap().getTypeIds().stream().map((String id) -> {return config.getItemMap().getType(id);}).collect(Collectors.toList()));
allData.addAll(config.getObjectTypeMap().getTypeIds().stream().map((String id) -> {return config.getObjectTypeMap().getType(id);}).collect(Collectors.toList())); allData.addAll(config.getObjectTypeMap().getTypeIds().stream().map((String id) -> {return config.getObjectTypeMap().getType(id);}).collect(Collectors.toList()));
for(CommonEntityType type : allData){ for(CommonEntityType type : allData){
CommonEntityValidator.validate(type); CommonEntityValidator.validate(config, type);
} }
//validate recipes
RecipeValidator.validate(config);
ConfigValidator.checkIdCollisions(config); ConfigValidator.checkIdCollisions(config);
} }

View File

@ -1,5 +1,8 @@
package electrosphere.data.common; package electrosphere.data.common;
import electrosphere.data.Config;
import electrosphere.data.common.life.loot.LootPool;
import electrosphere.data.common.life.loot.LootTicket;
import electrosphere.logger.LoggerInterface; import electrosphere.logger.LoggerInterface;
/** /**
@ -9,9 +12,10 @@ public class CommonEntityValidator {
/** /**
* Validates a common entity * Validates a common entity
* @param config The config
* @param data The data * @param data The data
*/ */
public static void validate(CommonEntityType data){ public static void validate(Config config, CommonEntityType data){
if(data.getId() == null || data.getId().length() == 0){ if(data.getId() == null || data.getId().length() == 0){
String message = "Id undefined for entity type!"; String message = "Id undefined for entity type!";
LoggerInterface.loggerEngine.WARNING(message); LoggerInterface.loggerEngine.WARNING(message);
@ -21,6 +25,24 @@ public class CommonEntityValidator {
String message = "Display name undefined for entity type " + data.getId(); String message = "Display name undefined for entity type " + data.getId();
LoggerInterface.loggerEngine.WARNING(message); LoggerInterface.loggerEngine.WARNING(message);
} }
//validate loot pool
if(data.getHealthSystem() != null && data.getHealthSystem().getLootPool() != null){
CommonEntityValidator.validateLootPool(config, data.getHealthSystem().getLootPool());
}
}
/**
* Validates a loot pool
* @param config The config
* @param data The loot pool
*/
private static void validateLootPool(Config config, LootPool data){
for(LootTicket ticket : data.getTickets()){
if(config.getItemMap().getItem(ticket.getItemId()) == null){
throw new Error("Loot pool has undefined item: " + ticket.getItemId());
}
}
} }
} }

View File

@ -0,0 +1,31 @@
package electrosphere.data.crafting;
import electrosphere.data.Config;
/**
* Validates recipes
*/
public class RecipeValidator {
/**
* Validates all recipes in a config
* @param config The config
*/
public static void validate(Config config){
for(RecipeData recipeData : config.getRecipeMap().getTypes()){
//validate that all reagents are items in the config
for(RecipeIngredientData reagent : recipeData.getIngredients()){
if(config.getItemMap().getType(reagent.getItemType()) == null){
throw new Error("Item does not exist: " + reagent.getItemType());
}
}
//validate that all products are items in the config
for(RecipeIngredientData reagent : recipeData.getProducts()){
if(config.getItemMap().getType(reagent.getItemType()) == null){
throw new Error("Item does not exist: " + reagent.getItemType());
}
}
}
}
}