Skip to content

Commit

Permalink
Fix representation of the CRE V2.2 kit field
Browse files Browse the repository at this point in the history
  • Loading branch information
Argent77 committed Oct 31, 2024
1 parent 4e77bd8 commit 1139427
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 6 deletions.
3 changes: 2 additions & 1 deletion src/org/infinity/resource/cre/CreResource.java
Original file line number Diff line number Diff line change
Expand Up @@ -1266,7 +1266,8 @@ private int readIWD2(ByteBuffer buffer, int offset) throws Exception {
addField(new DecNumber(buffer, offset + 612, 1, CRE_MORALE));
addField(new DecNumber(buffer, offset + 613, 1, CRE_MORALE_BREAK));
addField(new DecNumber(buffer, offset + 614, 2, CRE_MORALE_RECOVERY));
addField(new KitIdsBitmap(buffer, offset + 616, CRE_KIT));
addField(new Flag(buffer, offset + 616, 4, CRE_KIT,
IdsMapCache.getUpdatedIdsFlags(new String[] { "No Kit", "" }, "KIT.IDS", 4, true, true)));
addField(new ResourceRef(buffer, offset + 620, CRE_SCRIPT_OVERRIDE, "BCS"));
addField(new ResourceRef(buffer, offset + 628, CRE_SCRIPT_SPECIAL_2, "BCS", "BS"));
addField(new ResourceRef(buffer, offset + 636, CRE_SCRIPT_COMBAT, "BCS"));
Expand Down
16 changes: 11 additions & 5 deletions src/org/infinity/util/IdsMapCache.java
Original file line number Diff line number Diff line change
Expand Up @@ -202,8 +202,8 @@ public static boolean isCaseSensitiveMatch(String idsRef) {
* @param overwrite If {@code true}, then static flag label will be overwritten with entries from the IDS resource. If
* {@code false}, then entries from IDS resource will be used only for missing or empty entries in
* the {@code flags} array.
* @param prettify Indicates whether to improve readability of flag names. The operation includes: - a capitalized
* first letter - lowercased remaining letters - underscores are replaced by space
* @param prettify Indicates whether to improve readability of flag names. The operation includes a capitalized
* first letter of each word, lowercased remaining letters, underscores are replaced by space.
* @return The updated list of flag names.
*/
public static String[] getUpdatedIdsFlags(String[] flags, String idsFile, int size, boolean overwrite,
Expand Down Expand Up @@ -253,15 +253,21 @@ public static String[] getUpdatedIdsFlags(String[] flags, String idsFile, int si
}

/**
* Improves readability of given string by capitalizing first letter, lowercasing remaining characters and replacing
* underscores by space.
* Improves readability of given string by capitalizing first letter of each word, lowercasing remaining characters
* and replacing underscores by space.
*/
private static String prettifyName(String name) {
if (name == null || name.trim().isEmpty()) {
return name;
}

String retVal = name.replace("_", " ").toLowerCase(Locale.ENGLISH);
retVal = Character.toUpperCase(retVal.charAt(0)) + retVal.substring(1);
final String[] items = retVal.split(" ");
for (int i = 0; i < items.length; i++) {
items[i] = Character.toUpperCase(items[i].charAt(0)) + items[i].substring(1);
}
retVal = String.join(" ", items);

return retVal;
}

Expand Down

0 comments on commit 1139427

Please sign in to comment.