Skip to content

Commit

Permalink
removed known class names from json
Browse files Browse the repository at this point in the history
  • Loading branch information
Jan Fic committed Apr 21, 2022
1 parent a3007a9 commit 68248a6
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -234,15 +234,15 @@ public int hashCode() {
@Override
public void write(Json json) {
json.writeValue("color", color);
json.writeValue("position", "" + x + " " + y);
json.writeValue("x", x);
json.writeValue("y", y);
}

@Override
public void read(Json json, JsonValue jv) {
this.color = json.readValue("color", Integer.class, jv);
String[] position = json.readValue("position", String.class, jv).split(" ");
this.x = Integer.parseInt(position[0]);
this.y = Integer.parseInt(position[1]);
this.x = json.readValue("x", Integer.class, jv);
this.y = json.readValue("y", Integer.class, jv);
this.textureName = colorToTextureName.get(this.color);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,17 @@ public Deck getActiveDeck() {

@Override
public void write(Json json) {
json.setTypeName("class");
json.writeType(this.getClass());
json.writeValue("uid", uid);
json.writeValue("deck", deck);
json.writeValue("uid", uid, String.class);
//json.writeValue("deck", deck);
json.setTypeName(null);
}

@Override
public void read(Json json, JsonValue jsonData) {
this.uid = json.readValue("uid", String.class, jsonData);
this.deck = json.readValue("deck", Deck.class, jsonData);
//this.deck = json.readValue("deck", Deck.class, jsonData);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,7 @@ public List<Component> getComponentsAsList() {

@Override
public void write(Json json) {
json.setTypeName(null);
json.writeValue("players", players, List.class);
json.writeValue("currentPlayerMove", currentPlayerMove, Player.class);
json.writeValue("activeEntities", activeEntities, Map.class);
Expand All @@ -397,17 +398,29 @@ public void write(Json json) {
}
assert (board.length() == 64);
json.writeValue("componentBoard", board);
json.setTypeName("class");
}

@Override
public void read(Json json, JsonValue jsonData) {
this.players = json.readValue("players", List.class, jsonData);
this.currentPlayerMove = json.readValue("currentPlayerMove", String.class, jsonData);
json.setTypeName("class");
this.players = json.readValue("players", List.class, Player.class, jsonData);
json.setTypeName(null);
this.isGameOver = json.readValue("isGameOver", boolean.class, jsonData);
this.winner = json.readValue("winner", String.class, jsonData);
this.activeEntities = json.readValue("activeEntities", HashMap.class, List.class, jsonData);
this.computers = json.readValue("computers", HashMap.class, Card.class, jsonData);
this.currentPlayerMove = json.readValue("currentPlayerMove", String.class, jsonData);
this.decks = json.readValue("decks", HashMap.class, Deck.class, jsonData);
HashMap<String, List<JsonValue>> v = json.readValue("activeEntities", HashMap.class, List.class, jsonData);
this.activeEntities = new HashMap<>();
for (String string : v.keySet()) {
List<Card> cards = new ArrayList<>();
for (JsonValue jsonValue : v.get(string)) {
Card c = json.readValue(Card.class, jsonValue);
cards.add(c);
}
activeEntities.put(string, cards);
}
this.computers = json.readValue("computers", HashMap.class, Card.class, jsonData);
String boardString = json.readValue("componentBoard", String.class, jsonData);
componentBoard = new Component[8][8];
assert (boardString.length() == 64);
Expand All @@ -420,6 +433,7 @@ public void read(Json json, JsonValue jsonData) {
e.printStackTrace();
}
}
json.setTypeName("class");
}

public int countComponents(ComponentFilter filter, Move move) {
Expand Down

0 comments on commit 68248a6

Please sign in to comment.