From 8ff112b8026f0ba6e3a26af0085194a57cd76693 Mon Sep 17 00:00:00 2001 From: MagicBot Date: Sun, 18 Feb 2024 14:03:41 -0500 Subject: [PATCH] Fleshing out constructor --- src/engine/Enum.java | 2 +- src/engine/objects/ItemTemplate.java | 26 +++++++++++++++++++------- 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/src/engine/Enum.java b/src/engine/Enum.java index a171d4d9..79e38a3d 100644 --- a/src/engine/Enum.java +++ b/src/engine/Enum.java @@ -2327,7 +2327,7 @@ public class Enum { WAREHOUSE } - public enum ItemSlotType implements EnumBitSetHelper { + public enum ItemEquipSlotType { RHELD, LHELD, HELM, diff --git a/src/engine/objects/ItemTemplate.java b/src/engine/objects/ItemTemplate.java index 9615b3d0..9d164acb 100644 --- a/src/engine/objects/ItemTemplate.java +++ b/src/engine/objects/ItemTemplate.java @@ -8,11 +8,12 @@ package engine.objects; +import engine.Enum; import engine.math.Vector3fImmutable; import org.json.simple.JSONArray; import org.json.simple.JSONObject; -import java.util.ArrayList; +import java.util.EnumSet; import java.util.HashMap; @@ -30,7 +31,11 @@ public class ItemTemplate { public float combat_health_full; public HashMap combat_attack_resist = new HashMap<>(); - public ArrayList combatPowers; + public Enum.ItemType item_type; + public int item_eq_slots_value; + public boolean item_eq_slots_type; + public EnumSet item_eq_slots_or; + public EnumSet item_eq_slots_and; public ItemTemplate(JSONObject jsonObject) { @@ -63,13 +68,20 @@ public class ItemTemplate { combat_attack_resist.put((String) key, resist); } - // Reading arraylist of ints + // Parsing an enum - JSONArray combat_json = (JSONArray) jsonObject.get("combat_powers"); + item_type = Enum.ItemType.valueOf((String) jsonObject.get("item_type")); - if (combat_json.isEmpty() == false) - for (Object o : combat_json) - combatPowers.add(o); + item_eq_slots_value = ((Long) jsonObject.get("item_eq_slots_value")).intValue(); + item_eq_slots_type = (boolean) jsonObject.get("item_eq_slots_value"); + + // Parsing an enumset + + JSONArray eq_slots_or = (JSONArray) jsonObject.get("item_eq_slots_or"); + + if (eq_slots_or.isEmpty() == false) + for (Object o : eq_slots_or) + item_eq_slots_or.add(Enum.ItemEquipSlotType.valueOf((String) o)); } }