From 5cc5ea5bc9dcd35651d3d489254cd9c715fa699d Mon Sep 17 00:00:00 2001 From: austin Date: Wed, 14 May 2025 15:50:56 -0400 Subject: [PATCH] recipe validation, loot pool validation, data fix --- assets/Data/entity/foliage/crops.json | 12 +------ assets/Data/entity/foliage/trees.json | 2 +- assets/Data/game/recipes/voxelrecipes.json | 10 +++--- assets/Data/game/recipes/weapons.json | 32 ------------------- .../electrosphere/data/ConfigValidator.java | 8 ++++- .../data/common/CommonEntityValidator.java | 24 +++++++++++++- .../data/crafting/RecipeValidator.java | 31 ++++++++++++++++++ 7 files changed, 68 insertions(+), 51 deletions(-) create mode 100644 src/main/java/electrosphere/data/crafting/RecipeValidator.java diff --git a/assets/Data/entity/foliage/crops.json b/assets/Data/entity/foliage/crops.json index 23919cde..4d233f7e 100644 --- a/assets/Data/entity/foliage/crops.json +++ b/assets/Data/entity/foliage/crops.json @@ -46,17 +46,7 @@ }, "healthSystem" : { "maxHealth" : 5, - "onDamageIFrames" : 0, - "lootPool" : { - "tickets" : [ - { - "itemId" : "mat:Rock", - "rarity" : 1.0, - "minQuantity" : 1, - "maxQuantity" : 1 - } - ] - } + "onDamageIFrames" : 0 } } diff --git a/assets/Data/entity/foliage/trees.json b/assets/Data/entity/foliage/trees.json index d8d39097..fc270f4d 100644 --- a/assets/Data/entity/foliage/trees.json +++ b/assets/Data/entity/foliage/trees.json @@ -203,7 +203,7 @@ "maxQuantity" : 5 }, { - "itemId" : "block:wood", + "itemId" : "block:Wood", "rarity" : 0.8, "minQuantity" : 0, "maxQuantity" : 5 diff --git a/assets/Data/game/recipes/voxelrecipes.json b/assets/Data/game/recipes/voxelrecipes.json index 3115c825..1dc4567b 100644 --- a/assets/Data/game/recipes/voxelrecipes.json +++ b/assets/Data/game/recipes/voxelrecipes.json @@ -1,7 +1,7 @@ { "recipes": [ { - "displayName": "Refiend Wood", + "displayName": "Refined Wood", "craftingTag" : "HAND", "ingredients": [ { @@ -11,7 +11,7 @@ ], "products": [ { - "itemType": "block:refined_wood", + "itemType": "block:Wood (Refined)", "count": 16 } ] @@ -27,7 +27,7 @@ ], "products": [ { - "itemType": "block:brick_fant", + "itemType": "block:Brick (Fantasy)", "count": 16 } ] @@ -37,13 +37,13 @@ "craftingTag" : "HAND", "ingredients": [ { - "itemType": "vox:rock_shale", + "itemType": "vox:Rock (Shale)", "count": 1 } ], "products": [ { - "itemType": "block:brick_fant", + "itemType": "block:Brick (Fantasy)", "count": 16 } ] diff --git a/assets/Data/game/recipes/weapons.json b/assets/Data/game/recipes/weapons.json index f9c81a20..5e0879b7 100644 --- a/assets/Data/game/recipes/weapons.json +++ b/assets/Data/game/recipes/weapons.json @@ -1,37 +1,5 @@ { "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": [ diff --git a/src/main/java/electrosphere/data/ConfigValidator.java b/src/main/java/electrosphere/data/ConfigValidator.java index a7eb5baf..c2da9d95 100644 --- a/src/main/java/electrosphere/data/ConfigValidator.java +++ b/src/main/java/electrosphere/data/ConfigValidator.java @@ -8,6 +8,7 @@ import java.util.stream.Collectors; import electrosphere.data.common.CommonEntityType; import electrosphere.data.common.CommonEntityValidator; +import electrosphere.data.crafting.RecipeValidator; import electrosphere.data.creature.CreatureData; import electrosphere.data.creature.CreatureDataValidator; import electrosphere.data.creature.CreatureTypeLoader; @@ -27,15 +28,20 @@ public class ConfigValidator { for(CreatureData creatureData : creatureTypeLoader.getTypes()){ CreatureDataValidator.validate(creatureData); } + + //validate common entity data List allData = new LinkedList(); 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.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())); for(CommonEntityType type : allData){ - CommonEntityValidator.validate(type); + CommonEntityValidator.validate(config, type); } + //validate recipes + RecipeValidator.validate(config); + ConfigValidator.checkIdCollisions(config); } diff --git a/src/main/java/electrosphere/data/common/CommonEntityValidator.java b/src/main/java/electrosphere/data/common/CommonEntityValidator.java index 9528c7b5..4a7af681 100644 --- a/src/main/java/electrosphere/data/common/CommonEntityValidator.java +++ b/src/main/java/electrosphere/data/common/CommonEntityValidator.java @@ -1,5 +1,8 @@ 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; /** @@ -9,9 +12,10 @@ public class CommonEntityValidator { /** * Validates a common entity + * @param config The config * @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){ String message = "Id undefined for entity type!"; LoggerInterface.loggerEngine.WARNING(message); @@ -21,6 +25,24 @@ public class CommonEntityValidator { String message = "Display name undefined for entity type " + data.getId(); 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()); + } + } } } diff --git a/src/main/java/electrosphere/data/crafting/RecipeValidator.java b/src/main/java/electrosphere/data/crafting/RecipeValidator.java new file mode 100644 index 00000000..500cd959 --- /dev/null +++ b/src/main/java/electrosphere/data/crafting/RecipeValidator.java @@ -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()); + } + } + } + } + +}