Read named grant keys and signed values from new COBJECTS JSON
Grant pair lists now carry name strings ("HLR-021", "Unarmed Combat")
instead of integer hashes, so they are stored as name -> value maps.
Unresolved hashes are kept as their decimal string and logged.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
b56d4ee243
commit
1ac5a248db
5 files changed
+52
-32
No files matched your search
+33
-8
@@ -121,8 +121,6 @@ public class CacheParserUtil {
|
||||
}
|
||||
|
||||
// [{keyName: "Strength", valueName: 40}, ...] -> enum map
|
||||
// Negative values are stored unsigned in the JSON (-5 is 4294967291),
|
||||
// so values are read as long and wrapped to int.
|
||||
|
||||
public static <E extends Enum<E>> EnumMap<E, Integer> readEnumValueMap(Class<E> enumClass, JSONArray entriesJson,
|
||||
String keyName, String valueName,
|
||||
@@ -137,7 +135,7 @@ public class CacheParserUtil {
|
||||
enumValue = readEnum(enumClass, entry.getString(keyName), templateId, fieldName);
|
||||
|
||||
if (enumValue != null)
|
||||
enumMap.put(enumValue, (int) entry.getLong(valueName));
|
||||
enumMap.put(enumValue, entry.getInt(valueName));
|
||||
}
|
||||
|
||||
return enumMap;
|
||||
@@ -176,7 +174,7 @@ public class CacheParserUtil {
|
||||
return enumMap;
|
||||
}
|
||||
|
||||
// Values are read as long and wrapped to int so unsigned 32-bit hashes survive.
|
||||
// Hash and flag fields are still unsigned in the JSON; read as long and wrapped to int.
|
||||
|
||||
public static int[] readIntArray(JSONArray valuesJson) {
|
||||
|
||||
@@ -258,7 +256,34 @@ public class CacheParserUtil {
|
||||
return userPowerActions;
|
||||
}
|
||||
|
||||
public static ArrayList<PowerGrant> readPowerGrants(JSONArray grantsJson) {
|
||||
// [[key, value], ...] -> map in file order. Keys are names when the exporter
|
||||
// knows the hash, otherwise the raw hash, which is kept as its decimal string.
|
||||
|
||||
public static LinkedHashMap<String, Integer> readGrantPairs(JSONArray pairsJson, int templateId, String fieldName) {
|
||||
|
||||
LinkedHashMap<String, Integer> grantPairs = new LinkedHashMap<>();
|
||||
JSONArray pair;
|
||||
Object key;
|
||||
String keyName;
|
||||
|
||||
for (int i = 0; i < pairsJson.length(); i++) {
|
||||
pair = pairsJson.getJSONArray(i);
|
||||
key = pair.get(0);
|
||||
|
||||
if (key instanceof String) {
|
||||
keyName = (String) key;
|
||||
} else {
|
||||
keyName = Long.toString(pair.getLong(0));
|
||||
Logger.warn(templateId + ": " + fieldName + " has unresolved hash " + keyName);
|
||||
}
|
||||
|
||||
grantPairs.put(keyName, pair.getInt(1));
|
||||
}
|
||||
|
||||
return grantPairs;
|
||||
}
|
||||
|
||||
public static ArrayList<PowerGrant> readPowerGrants(JSONArray grantsJson, int templateId) {
|
||||
|
||||
ArrayList<PowerGrant> powerGrants = new ArrayList<>();
|
||||
JSONObject entry;
|
||||
@@ -270,9 +295,9 @@ public class CacheParserUtil {
|
||||
|
||||
powerGrant.power_type = entry.getString("power_type");
|
||||
powerGrant.power_value = entry.getInt("power_value");
|
||||
powerGrant.power_granted_attrs = entry.getJSONArray("power_granted_attrs");
|
||||
powerGrant.power_granted_skills.addAll(readIntArrays(entry.getJSONArray("power_granted_skills")));
|
||||
powerGrant.power_granted_powers.addAll(readIntArrays(entry.getJSONArray("power_granted_powers")));
|
||||
powerGrant.power_granted_attrs.putAll(readGrantPairs(entry.getJSONArray("power_granted_attrs"), templateId, "power_granted_attrs"));
|
||||
powerGrant.power_granted_skills.putAll(readGrantPairs(entry.getJSONArray("power_granted_skills"), templateId, "power_granted_skills"));
|
||||
powerGrant.power_granted_powers.putAll(readGrantPairs(entry.getJSONArray("power_granted_powers"), templateId, "power_granted_powers"));
|
||||
powerGrant.power_monster_types = entry.getJSONArray("power_monster_types");
|
||||
|
||||
powerGrants.add(powerGrant);
|
||||
|
||||
Reference in new issue
Block a user