Skip to content

Commit

Permalink
Now no longer directly removing keys from the map when removing used …
Browse files Browse the repository at this point in the history
…variables from the unused set (#67)
  • Loading branch information
ghostlypi authored Jan 29, 2025
1 parent 5570f9e commit 13421ff
Showing 1 changed file with 11 additions and 4 deletions.
15 changes: 11 additions & 4 deletions src/main/java/tanks/tankson/Serializer.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,8 @@ public static Object parseObject(Map<String, Object> m)
if (m == null)
return null;
Object o = null;
Set<String> processed = new HashSet<>();
processed.add("obj_type");
switch ((String) m.get("obj_type"))
{
case "tank":
Expand All @@ -192,6 +194,7 @@ public static Object parseObject(Map<String, Object> m)
{
try
{
processed.add("bullet_type");
o = Game.registryBullet.getEntry((String) m.get("bullet_type")).bullet.newInstance();
}
catch (Exception e)
Expand All @@ -207,6 +210,7 @@ public static Object parseObject(Map<String, Object> m)
{
try
{
processed.add("item_type");
o = Game.registryItem.getEntry((String) m.get("item_type")).item.getConstructor().newInstance();
}
catch (Exception e)
Expand All @@ -217,6 +221,7 @@ public static Object parseObject(Map<String, Object> m)
}
case "item_stack":
{
processed.add("item");
Item i = (Item) parseObject((Map) m.get("item"));
o = (i.getStack(null));
break;
Expand All @@ -231,17 +236,19 @@ public static Object parseObject(Map<String, Object> m)
o = new Explosion();
break;
case "spawned_tank":
processed.add("tank");
processed.add("weight");
o = new TankAIControlled.SpawnedTankEntry((ITankField) parseObject((Map) m.get("tank")), (Double) m.get("weight"));
break;
case "tank_ref":
case "tank_ref": {
processed.add("tank");
o = new TankReference((String) m.get("tank"));
break;
}
default:
throw new RuntimeException("Bad object type: " + (String) m.get("obj_type"));
}

Set<String> processed = new HashSet<>();

for (Field f : o.getClass().getFields())
{
if (f.isAnnotationPresent(Property.class) && m.containsKey(getid(f)))
Expand Down Expand Up @@ -295,7 +302,7 @@ else if (o2 instanceof Boolean)
}
}

Set<String> unused = m.keySet();
Set<String> unused = new HashSet<>(m.keySet());
unused.removeAll(processed);
for (String k : unused) {
try {
Expand Down

0 comments on commit 13421ff

Please sign in to comment.