From 58af3882438a7194cb3787a8fed2257e307d418d Mon Sep 17 00:00:00 2001 From: austin Date: Mon, 2 May 2022 20:26:43 -0400 Subject: [PATCH] Flesh out requesting playable races --- .gitignore | 1 + assets/Data/creatures/human.json | 3 ++- src/main/java/electrosphere/game/data/Config.java | 6 ++++++ .../game/data/creature/type/CreatureTypeLoader.java | 13 +++++++++++++ .../net/server/protocol/LoreProtocol.java | 8 +++++++- src/main/java/electrosphere/util/Utilities.java | 11 ++++++++++- 6 files changed, 39 insertions(+), 3 deletions(-) diff --git a/.gitignore b/.gitignore index ea85bc2d..983976e1 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,4 @@ #docs backup files /docs/~$NetworkFlow.drawio.bkp +/docs/~$NetworkFlow.drawio.dtmp diff --git a/assets/Data/creatures/human.json b/assets/Data/creatures/human.json index 1cea7c88..a3b12199 100644 --- a/assets/Data/creatures/human.json +++ b/assets/Data/creatures/human.json @@ -57,7 +57,8 @@ "TARGETABLE", "CAN_EQUIP", "INVENTORY", - "OUTLINE" + "OUTLINE", + "PLAYABLE" ], "visualAttributes" : [ { diff --git a/src/main/java/electrosphere/game/data/Config.java b/src/main/java/electrosphere/game/data/Config.java index 4d10e68c..c49583ca 100644 --- a/src/main/java/electrosphere/game/data/Config.java +++ b/src/main/java/electrosphere/game/data/Config.java @@ -66,6 +66,12 @@ public class Config { type.setAttackMoveResolver(new AttackMoveResolver(type.getAttackMoves())); } loader.putCreature(type.getCreatureId(), type); + //loop through all creatures and add ones with PLAYABLE token to list of playable races + for(String token : type.getTokens()){ + if(token.contains("PLAYABLE")){ + loader.putPlayableRace(type.getCreatureId()); + } + } } return loader; } diff --git a/src/main/java/electrosphere/game/data/creature/type/CreatureTypeLoader.java b/src/main/java/electrosphere/game/data/creature/type/CreatureTypeLoader.java index 81e08e70..24e5cb3f 100644 --- a/src/main/java/electrosphere/game/data/creature/type/CreatureTypeLoader.java +++ b/src/main/java/electrosphere/game/data/creature/type/CreatureTypeLoader.java @@ -1,18 +1,31 @@ package electrosphere.game.data.creature.type; import java.util.HashMap; +import java.util.LinkedList; +import java.util.List; import java.util.Map; public class CreatureTypeLoader { Map creatureMap = new HashMap(); + List playableRaceNames = new LinkedList(); + public void putCreature(String name, CreatureType type){ creatureMap.put(name,type); } + public void putPlayableRace(String name){ + playableRaceNames.add(name); + } + public CreatureType getCreature(String name){ return creatureMap.get(name); } + public List getPlayableRaces(){ + return playableRaceNames; + } + + } diff --git a/src/main/java/electrosphere/net/server/protocol/LoreProtocol.java b/src/main/java/electrosphere/net/server/protocol/LoreProtocol.java index e92aae31..241e7e3c 100644 --- a/src/main/java/electrosphere/net/server/protocol/LoreProtocol.java +++ b/src/main/java/electrosphere/net/server/protocol/LoreProtocol.java @@ -1,7 +1,11 @@ package electrosphere.net.server.protocol; +import java.util.List; + +import electrosphere.main.Globals; import electrosphere.net.parser.net.message.LoreMessage; import electrosphere.net.server.ServerConnectionHandler; +import electrosphere.util.Utilities; public class LoreProtocol { @@ -14,7 +18,9 @@ public class LoreProtocol { //TODO break; case REQUESTRACES: - //TODO + List playableRaces = Globals.gameConfigCurrent.getCreatureTypeLoader().getPlayableRaces(); + String returnData = Utilities.stringify(playableRaces); + connectionHandler.addMessagetoOutgoingQueue(LoreMessage.constructResponseRacesMessage(returnData)); break; case RESPONSEDATA: diff --git a/src/main/java/electrosphere/util/Utilities.java b/src/main/java/electrosphere/util/Utilities.java index 705595f7..0b133e1d 100644 --- a/src/main/java/electrosphere/util/Utilities.java +++ b/src/main/java/electrosphere/util/Utilities.java @@ -36,8 +36,12 @@ import static org.lwjgl.opengl.GL30.glGenVertexArrays; * @author awhoove */ public class Utilities { + + static { + gson = new Gson(); + } - + static Gson gson; public static Matrix4f convertAIMatrix(AIMatrix4x4 mat){ Matrix4f rVal = new Matrix4f(); @@ -120,4 +124,9 @@ public class Utilities { System.exit(1); } } + + public static String stringify(Object object){ + return gson.toJson(object); + } + }