From 83f7609b2f98d5b07b6bdfc2d4d809bf50a7f686 Mon Sep 17 00:00:00 2001 From: austin Date: Wed, 9 Feb 2022 19:33:37 -0500 Subject: [PATCH] Recursive creature type parsing --- assets/Data/creatures.json | 201 +----------------- assets/Data/creatures/human.json | 184 ++++++++++++++++ .../entity/types/creature/CreatureUtils.java | 2 +- .../java/electrosphere/game/data/Config.java | 39 +++- .../creature/type/CreatureTypeLoader.java | 18 ++ .../creature/type/model/CreatureTypeMap.java | 16 +- .../java/electrosphere/renderer/Mesh.java | 4 +- 7 files changed, 250 insertions(+), 214 deletions(-) create mode 100644 assets/Data/creatures/human.json create mode 100644 src/main/java/electrosphere/game/data/creature/type/CreatureTypeLoader.java diff --git a/assets/Data/creatures.json b/assets/Data/creatures.json index 589f2344..47fbef0f 100644 --- a/assets/Data/creatures.json +++ b/assets/Data/creatures.json @@ -4,197 +4,6 @@ - { - "creatureId" : "human", - "bodyParts" : [ - { - "name" : "Head", - "type" : "Head" - }, - { - "name" : "Torso", - "type" : "Torso" - }, - { - "name" : "ArmLeft", - "type" : "Arm" - }, - { - "name" : "ArmRight", - "type" : "Arm" - }, - { - "name" : "LegLeft", - "type" : "Leg" - }, - { - "name" : "LegRight", - "type" : "Leg" - } - ], - "hitboxes" : [ - { - "type": "hurt", - "bone": "Bone.031", - "radius": 0.04 - }, - { - "type": "hurt", - "bone": "Bone.012", - "radius": 0.04 - }, - { - "type": "hurt", - "bone": "Bone.003", - "radius": 0.04 - }, - { - "type": "hurt", - "bone": "Bone.010", - "radius": 0.06 - }, - { - "type": "hurt", - "bone": "Bone.001", - "radius": 0.06 - }, - { - "type": "hurt", - "bone": "Bone.014", - "radius": 0.06 - }, - { - "type": "hurt", - "bone": "Bone", - "radius": 0.08 - }, - { - "type": "hurt", - "bone": "Bone.014", - "radius": 0.06 - }, - { - "type": "hurt", - "bone": "Bone.019", - "radius": 0.04 - } - ], - "tokens" : [ - "BLENDER_TRANSFORM", - "SENTIENT", - "ATTACKER", - "GRAVITY", - "TARGETABLE", - "CAN_EQUIP" - ], - "movementSystems" : [ - { - "type" : "GROUND", - "acceleration" : 16.0, - "maxVelocity" : 3.0, - "animationStartup" : { - "name" : "Armature|WalkStart", - "length" : 1, - "loops" : false - }, - "animationLoop" : { - "name" : "Armature|Walk", - "length" : 1, - "loops" : false - }, - "animationWindDown" : { - "name" : "Armature|WalkStart", - "length" : 1, - "loops" : false - }, - "sprintSystem" : { - "maxVelocity" : 5.8, - "staminaMax" : 500, - "animationStartUp" : { - "name" : "SprintStart", - "length" : 1, - "loops" : false - }, - "animationMain" : { - "name" : "Sprint", - "length" : 1, - "loops" : false - } - } - } - ], - "rotatorSystem" : { - "rotatorItems" : [ - { - "boneName" : "myTorsoBone", - "constraints" : [ - { - "followsView" : true, - "followsBone" : false, - "parentBone" : "", - "allowedMargin" : 0.2 - } - ] - }, - { - "boneName" : "myLeftLegBone", - "constraints" : [ - { - "followsView" : false, - "followsBone" : true, - "parentBone" : "myTorsoBone", - "allowedMargin" : 0.2 - } - ] - }, - { - "boneName" : "myRightLegBone", - "constraints" : [ - { - "followsView" : false, - "followsBone" : true, - "parentBone" : "myTorsoBone", - "allowedMargin" : 0.2 - } - ] - } - ] - }, - "collidable" : { - "type" : "CYLINDER", - "dimension1" : 0.1, - "dimension2" : 0.45, - "dimension3" : 0.1, - "offsetX" : 0, - "offsetY" : 0.45, - "offsetZ" : 0 - }, - "attackMoves" : [ - { - "type" : "MELEE_WEAPON_SWING_ONE_HAND", - "animationName" : "Armature|SwingWeapon", - "damageStartFrame" : 30, - "damageEndFrame" : 60 - } - ], - "healthSystem" : { - "maxHealth" : 100, - "onDamageIFrames" : 30 - }, - "modelPath" : "Models/baseman.fbx" - }, - - - - - - - - - - - - { "creatureId" : "goblin", @@ -446,12 +255,8 @@ } - - - - - - - + ], + "files" : [ + "Data/creatures/human.json" ] } diff --git a/assets/Data/creatures/human.json b/assets/Data/creatures/human.json new file mode 100644 index 00000000..4a18932c --- /dev/null +++ b/assets/Data/creatures/human.json @@ -0,0 +1,184 @@ +{ + "creatures" : [ + { + "creatureId" : "human", + "bodyParts" : [ + { + "name" : "Head", + "type" : "Head" + }, + { + "name" : "Torso", + "type" : "Torso" + }, + { + "name" : "ArmLeft", + "type" : "Arm" + }, + { + "name" : "ArmRight", + "type" : "Arm" + }, + { + "name" : "LegLeft", + "type" : "Leg" + }, + { + "name" : "LegRight", + "type" : "Leg" + } + ], + "hitboxes" : [ + { + "type": "hurt", + "bone": "Bone.031", + "radius": 0.04 + }, + { + "type": "hurt", + "bone": "Bone.012", + "radius": 0.04 + }, + { + "type": "hurt", + "bone": "Bone.003", + "radius": 0.04 + }, + { + "type": "hurt", + "bone": "Bone.010", + "radius": 0.06 + }, + { + "type": "hurt", + "bone": "Bone.001", + "radius": 0.06 + }, + { + "type": "hurt", + "bone": "Bone.014", + "radius": 0.06 + }, + { + "type": "hurt", + "bone": "Bone", + "radius": 0.08 + }, + { + "type": "hurt", + "bone": "Bone.014", + "radius": 0.06 + }, + { + "type": "hurt", + "bone": "Bone.019", + "radius": 0.04 + } + ], + "tokens" : [ + "BLENDER_TRANSFORM", + "SENTIENT", + "ATTACKER", + "GRAVITY", + "TARGETABLE", + "CAN_EQUIP" + ], + "movementSystems" : [ + { + "type" : "GROUND", + "acceleration" : 16.0, + "maxVelocity" : 3.0, + "animationStartup" : { + "name" : "Armature|WalkStart", + "length" : 1, + "loops" : false + }, + "animationLoop" : { + "name" : "Armature|Walk", + "length" : 1, + "loops" : false + }, + "animationWindDown" : { + "name" : "Armature|WalkStart", + "length" : 1, + "loops" : false + }, + "sprintSystem" : { + "maxVelocity" : 5.8, + "staminaMax" : 500, + "animationStartUp" : { + "name" : "SprintStart", + "length" : 1, + "loops" : false + }, + "animationMain" : { + "name" : "Sprint", + "length" : 1, + "loops" : false + } + } + } + ], + "rotatorSystem" : { + "rotatorItems" : [ + { + "boneName" : "myTorsoBone", + "constraints" : [ + { + "followsView" : true, + "followsBone" : false, + "parentBone" : "", + "allowedMargin" : 0.2 + } + ] + }, + { + "boneName" : "myLeftLegBone", + "constraints" : [ + { + "followsView" : false, + "followsBone" : true, + "parentBone" : "myTorsoBone", + "allowedMargin" : 0.2 + } + ] + }, + { + "boneName" : "myRightLegBone", + "constraints" : [ + { + "followsView" : false, + "followsBone" : true, + "parentBone" : "myTorsoBone", + "allowedMargin" : 0.2 + } + ] + } + ] + }, + "collidable" : { + "type" : "CYLINDER", + "dimension1" : 0.1, + "dimension2" : 0.45, + "dimension3" : 0.1, + "offsetX" : 0, + "offsetY" : 0.45, + "offsetZ" : 0 + }, + "attackMoves" : [ + { + "type" : "MELEE_WEAPON_SWING_ONE_HAND", + "animationName" : "Armature|SwingWeapon", + "damageStartFrame" : 30, + "damageEndFrame" : 60 + } + ], + "healthSystem" : { + "maxHealth" : 100, + "onDamageIFrames" : 30 + }, + "modelPath" : "Models/baseman.fbx" + } + ], + "files" : [] +} \ No newline at end of file diff --git a/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java b/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java index 5350e398..69b1c191 100644 --- a/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java +++ b/src/main/java/electrosphere/entity/types/creature/CreatureUtils.java @@ -64,7 +64,7 @@ public class CreatureUtils { // } public static Entity spawnBasicCreature(String type){ - CreatureType rawType = Globals.gameConfigCurrent.getCreatureMap().getCreature(type); + CreatureType rawType = Globals.gameConfigCurrent.getCreatureTypeLoader().getCreature(type); Entity rVal = EntityUtils.spawnDrawableEntity(rawType.getModelPath()); for(HitboxData hitboxdata : rawType.getHitboxes()){ if(hitboxdata.getType().equals("hit")){ diff --git a/src/main/java/electrosphere/game/data/Config.java b/src/main/java/electrosphere/game/data/Config.java index 22d04efc..18d07c0f 100644 --- a/src/main/java/electrosphere/game/data/Config.java +++ b/src/main/java/electrosphere/game/data/Config.java @@ -1,5 +1,10 @@ package electrosphere.game.data; +import java.util.LinkedList; +import java.util.List; + +import electrosphere.game.data.creature.type.CreatureType; +import electrosphere.game.data.creature.type.CreatureTypeLoader; import electrosphere.game.data.creature.type.model.CreatureTypeMap; import electrosphere.game.data.foliage.type.model.FoliageTypeMap; import electrosphere.game.data.item.type.model.ItemTypeMap; @@ -14,7 +19,7 @@ import electrosphere.util.FileUtils; */ public class Config { - CreatureTypeMap creatureMap; + CreatureTypeLoader creatureTypeLoader; StructureTypeMap structureTypeMap; ItemTypeMap itemMap; FoliageTypeMap foliageMap; @@ -23,7 +28,7 @@ public class Config { public static Config loadDefaultConfig(){ Config config = new Config(); - config.creatureMap = FileUtils.loadObjectFromAssetPath("Data/creatures.json", CreatureTypeMap.class); + config.creatureTypeLoader = loadCreatureTypes("Data/creatures.json"); config.itemMap = FileUtils.loadObjectFromAssetPath("Data/items.json", ItemTypeMap.class); config.structureTypeMap = FileUtils.loadObjectFromAssetPath("Data/structures.json", StructureTypeMap.class); config.foliageMap = FileUtils.loadObjectFromAssetPath("Data/foliage.json", FoliageTypeMap.class); @@ -32,8 +37,34 @@ public class Config { return config; } - public CreatureTypeMap getCreatureMap() { - return creatureMap; + static List readCreatureTypeFile(String filename){ + List typeList = new LinkedList(); + CreatureTypeMap typeMap = FileUtils.loadObjectFromAssetPath(filename, CreatureTypeMap.class); + //push the types from this file + for(CreatureType type : typeMap.getCreatures()){ + typeList.add(type); + } + //push types from any other files + for(String filepath : typeMap.getFiles()){ + List parsedTypeList = readCreatureTypeFile(filepath); + for(CreatureType type : parsedTypeList){ + typeList.add(type); + } + } + return typeList; + } + + static CreatureTypeLoader loadCreatureTypes(String initialPath) { + CreatureTypeLoader loader = new CreatureTypeLoader(); + List typeList = readCreatureTypeFile(initialPath); + for(CreatureType type : typeList){ + loader.putCreature(type.getCreatureId(), type); + } + return loader; + } + + public CreatureTypeLoader getCreatureTypeLoader() { + return creatureTypeLoader; } public StructureTypeMap getStructureTypeMap() { diff --git a/src/main/java/electrosphere/game/data/creature/type/CreatureTypeLoader.java b/src/main/java/electrosphere/game/data/creature/type/CreatureTypeLoader.java new file mode 100644 index 00000000..81e08e70 --- /dev/null +++ b/src/main/java/electrosphere/game/data/creature/type/CreatureTypeLoader.java @@ -0,0 +1,18 @@ +package electrosphere.game.data.creature.type; + +import java.util.HashMap; +import java.util.Map; + +public class CreatureTypeLoader { + + Map creatureMap = new HashMap(); + + public void putCreature(String name, CreatureType type){ + creatureMap.put(name,type); + } + + public CreatureType getCreature(String name){ + return creatureMap.get(name); + } + +} diff --git a/src/main/java/electrosphere/game/data/creature/type/model/CreatureTypeMap.java b/src/main/java/electrosphere/game/data/creature/type/model/CreatureTypeMap.java index cd148c56..745ff3b4 100644 --- a/src/main/java/electrosphere/game/data/creature/type/model/CreatureTypeMap.java +++ b/src/main/java/electrosphere/game/data/creature/type/model/CreatureTypeMap.java @@ -6,16 +6,14 @@ import java.util.List; public class CreatureTypeMap { List creatures; + List files; - public CreatureType getCreature(String name){ - CreatureType rVal = null; - for(CreatureType type : creatures){ - if(type.getCreatureId().equals(name)){ - rVal = type; - break; - } - } - return rVal; + public List getCreatures(){ + return creatures; + } + + public List getFiles(){ + return files; } } diff --git a/src/main/java/electrosphere/renderer/Mesh.java b/src/main/java/electrosphere/renderer/Mesh.java index cf50ac4c..dc36aebd 100644 --- a/src/main/java/electrosphere/renderer/Mesh.java +++ b/src/main/java/electrosphere/renderer/Mesh.java @@ -834,8 +834,8 @@ public class Mesh { currentMat.get(bufferarray); GL20.glUniformMatrix4fv(glGetUniformLocation(Globals.renderingEngine.getActiveShader().shaderProgram, currentUniform), false, bufferarray); } else { - System.out.println("Bonename: " + boneName); - System.exit(1); + // System.out.println("Bonename: " + boneName); + // System.exit(1); GL20.glUniformMatrix4fv(glGetUniformLocation(Globals.renderingEngine.getActiveShader().shaderProgram, currentUniform), false, new float[16]); } incrementer++;