Skip to content

Commit

Permalink
Update for new inventory setups save format.
Browse files Browse the repository at this point in the history
Bump to 1.4.26
  • Loading branch information
geheur committed Mar 16, 2024
1 parent f2be25b commit 087dc5b
Show file tree
Hide file tree
Showing 6 changed files with 175 additions and 91 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ dependencies {
}

group = 'com.banktaglayouts'
version = '1.4.25'
version = '1.4.26'
sourceCompatibility = '1.8'

tasks.withType(JavaCompile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,18 +38,19 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import joptsimple.internal.Strings;
import java.util.Set;
import java.util.stream.Collectors;
import lombok.extern.slf4j.Slf4j;
import net.runelite.client.config.ConfigManager;

@Slf4j
public class InventorySetupsAdapter {

public static final String CONFIG_GROUP = "inventorysetups";
public static final String CONFIG_KEY_SETUPS = "setups";
public static final String CONFIG_KEY_SETUPS_V2 = "setupsV2";
public static final String CONFIG_KEY_SETUPS_MIGRATED_V2 = "migratedV2";
public static final String CONFIG_KEY_SETUPS_V3_PREFIX = "setupsV3_";
public static final String CONFIG_KEY_SETUPS_ORDER_V3 = "setupsOrderV3_";

private final BankTagLayoutsPlugin plugin;
private final BankTagLayoutsPlugin plugin;

private Gson gson;

Expand All @@ -60,58 +61,12 @@ public InventorySetupsAdapter(BankTagLayoutsPlugin plugin) {
// This method does not exist anywhere in inventory setups.
public InventorySetup getInventorySetup(String name)
{
if (gson == null) this.gson = plugin.gson.newBuilder().registerTypeAdapter(long.class, new LongTypeAdapter()).registerTypeAdapter(InventorySetupItemSerializable.class, new InventorySetupItemSerializableTypeAdapter()).create();
String hasMigratedToV2 = plugin.configManager.getConfiguration(CONFIG_GROUP, CONFIG_KEY_SETUPS_MIGRATED_V2);
if (!Strings.isNullOrEmpty(hasMigratedToV2)) {
Type setupTypeV2 = new TypeToken<ArrayList<InventorySetupSerializable>>() {}.getType();
List<InventorySetupSerializable> issList = new ArrayList<>(loadData(CONFIG_KEY_SETUPS_V2, setupTypeV2));
for (final InventorySetupSerializable iss : issList)
{
InventorySetup setup = InventorySetupSerializable.convertToInventorySetup(iss);
if (setup.getName().equals(name)) return setup;
}
return null;
}

try
{
Type setupType = new TypeToken<ArrayList<InventorySetup>>() {}.getType();
List<InventorySetup> inventorySetups = loadData(CONFIG_KEY_SETUPS, setupType);
return inventorySetups.stream()
.filter(s -> s.getName().equals(name))
.findAny().orElse(null);
}
catch (Exception e)
{
return null;
}
if (gson == null) this.gson = plugin.gson.newBuilder().registerTypeAdapter(long.class, new LongTypeAdapter()).registerTypeAdapter(InventorySetupItemSerializable.class, new InventorySetupItemSerializableTypeAdapter()).create();
return loadSetupByName(name);
}

private <T> List<T> loadData(final String configKey, Type type)
{
final String storedData = plugin.configManager.getConfiguration(CONFIG_GROUP, configKey);
if (Strings.isNullOrEmpty(storedData))
{
return new ArrayList<>();
}
else
{
try
{
// serialize the internal data structure from the json in the configuration
return plugin.gson.fromJson(storedData, type);
}
catch (Exception e)
{
log.error("Exception occurred while loading data", e);
return new ArrayList<>();
}
}
}

public boolean setupContainsItem(final InventorySetup setup, int itemID)
{
if (gson == null) this.gson = plugin.gson.newBuilder().registerTypeAdapter(long.class, new LongTypeAdapter()).registerTypeAdapter(InventorySetupItemSerializable.class, new InventorySetupItemSerializableTypeAdapter()).create();
// So place holders will show up in the bank.
itemID = plugin.itemManager.canonicalize(itemID);

Expand Down Expand Up @@ -188,4 +143,63 @@ private int getProcessedID(boolean isFuzzy, int itemId)
return itemId;
}

private InventorySetup loadV3Setup(String configKey)
{
final String storedData = plugin.configManager.getConfiguration(CONFIG_GROUP, configKey);
try
{
return InventorySetupSerializable.convertToInventorySetup(gson.fromJson(storedData, InventorySetupSerializable.class));
}
catch (Exception e)
{
log.error(String.format("Exception occurred while loading %s", configKey), e);
throw e;
}
}

private InventorySetup loadSetupByName(String name) {
final String wholePrefix = ConfigManager.getWholeKey(CONFIG_GROUP, null, CONFIG_KEY_SETUPS_V3_PREFIX);
final List<String> loadedSetupWholeKeys = plugin.configManager.getConfigurationKeys(wholePrefix);
Set<String> loadedSetupKeys = loadedSetupWholeKeys.stream().map(
key -> key.substring(wholePrefix.length() - CONFIG_KEY_SETUPS_V3_PREFIX.length())
).collect(Collectors.toSet());

Type setupsOrderType = new TypeToken<ArrayList<String>>()
{

}.getType();
final String setupsOrderJson = plugin.configManager.getConfiguration(CONFIG_GROUP, CONFIG_KEY_SETUPS_ORDER_V3);
List<String> setupsOrder = gson.fromJson(setupsOrderJson, setupsOrderType);
if (setupsOrder == null)
{
setupsOrder = new ArrayList<>();
}

List<InventorySetup> loadedSetups = new ArrayList<>();
for (final String configHash : setupsOrder)
{
final String configKey = CONFIG_KEY_SETUPS_V3_PREFIX + configHash;
if (loadedSetupKeys.remove(configKey))
{ // Handles if hash is present only in configOrder.
final InventorySetup setup = loadV3Setup(configKey);
if (name.equals(setup.getName())) {
return setup;
}
// loadedSetups.add(setup);
}
}
for (final String configKey : loadedSetupKeys)
{
// Load any remaining setups not present in setupsOrder. Useful if updateConfig crashes midway.
log.info("Loading setup that was missing from Order key: " + configKey);
final InventorySetup setup = loadV3Setup(configKey);
if (name.equals(setup.getName())) {
return setup;
}
// loadedSetups.add(setup);
}
return null;
// return loadedSetups;
}

}
9 changes: 5 additions & 4 deletions src/main/java/inventorysetupz/InventorySetupsItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,8 @@ public class InventorySetupsItem
@Setter
private String name;
@Getter
private final int quantity;
@Setter
private int quantity;
@Getter
@Setter
private boolean fuzzy;
Expand All @@ -59,9 +60,9 @@ public static boolean itemIsDummy(final InventorySetupsItem item)
{
// Don't use the name to compare
return item.getId() == -1 &&
item.getQuantity() == 0 &&
!item.isFuzzy() &&
(item.getStackCompare() == InventorySetupsStackCompareID.None || item.getStackCompare() == null);
item.getQuantity() == 0 &&
!item.isFuzzy() &&
(item.getStackCompare() == InventorySetupsStackCompareID.None || item.getStackCompare() == null);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

public enum InventorySetupsStackCompareID
{
Expand All @@ -43,7 +44,7 @@ public enum InventorySetupsStackCompareID

private final int type;

private static final ArrayList<InventorySetupsStackCompareID> VALUES;
private static final List<InventorySetupsStackCompareID> VALUES;

static
{
Expand All @@ -61,7 +62,7 @@ public int getType()
return type;
}

public static ArrayList<InventorySetupsStackCompareID> getValues()
public static List<InventorySetupsStackCompareID> getValues()
{
return VALUES;
}
Expand Down
126 changes: 97 additions & 29 deletions src/main/java/inventorysetupz/InventorySetupsVariationMapping.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@

import java.util.HashMap;
import java.util.Map;
import net.runelite.api.ItemID;
import static net.runelite.api.ItemID.*;
import static net.runelite.api.ItemID.AVERNIC_DEFENDER;
import static net.runelite.api.ItemID.GHOMMALS_AVERNIC_DEFENDER_5;
import static net.runelite.api.ItemID.GHOMMALS_AVERNIC_DEFENDER_5_L;
import static net.runelite.api.ItemID.GHOMMALS_AVERNIC_DEFENDER_6;
import static net.runelite.api.ItemID.GHOMMALS_AVERNIC_DEFENDER_6_L;
import static net.runelite.api.ItemID.GHRAZI_RAPIER;
import static net.runelite.api.ItemID.HOLY_GHRAZI_RAPIER;
import static net.runelite.api.ItemID.SANGUINESTI_STAFF;
import net.runelite.client.game.ItemVariationMapping;

public class InventorySetupsVariationMapping
Expand Down Expand Up @@ -32,48 +40,108 @@ public static int map(final Integer id)
mappings = new HashMap<>();

// Granite Cannonball -> Cannonball
mappings.put(ItemID.GRANITE_CANNONBALL, ItemID.CANNON_BALL);
mappings.put(GRANITE_CANNONBALL, CANNONBALL);

// Smith Gloves (i) act as ice gloves
mappings.put(SMITHS_GLOVES_I, ICE_GLOVES);

// Divine rune pouch -> Rune Pouch
mappings.put(DIVINE_RUNE_POUCH, RUNE_POUCH);

// Make god capes the same
final int itemIDGodCape = 1000000001;
mappings.put(ItemID.SARADOMIN_CAPE, itemIDGodCape);
mappings.put(ItemID.GUTHIX_CAPE, itemIDGodCape);
mappings.put(ItemID.ZAMORAK_CAPE, itemIDGodCape);
mappings.put(SARADOMIN_CAPE, itemIDGodCape);
mappings.put(GUTHIX_CAPE, itemIDGodCape);
mappings.put(ZAMORAK_CAPE, itemIDGodCape);
final int itemIDImbuedGodCape = 1000000002;
mappings.put(ItemID.IMBUED_SARADOMIN_CAPE, itemIDImbuedGodCape);
mappings.put(ItemID.IMBUED_GUTHIX_CAPE, itemIDImbuedGodCape);
mappings.put(ItemID.IMBUED_ZAMORAK_CAPE, itemIDImbuedGodCape);
mappings.put(IMBUED_SARADOMIN_CAPE, itemIDImbuedGodCape);
mappings.put(IMBUED_GUTHIX_CAPE, itemIDImbuedGodCape);
mappings.put(IMBUED_ZAMORAK_CAPE, itemIDImbuedGodCape);
final int itemIDGodMaxCape = 1000000003;
mappings.put(ItemID.SARADOMIN_MAX_CAPE, itemIDGodMaxCape);
mappings.put(ItemID.GUTHIX_MAX_CAPE, itemIDGodMaxCape);
mappings.put(ItemID.ZAMORAK_MAX_CAPE, itemIDGodMaxCape);
mappings.put(SARADOMIN_MAX_CAPE, itemIDGodMaxCape);
mappings.put(GUTHIX_MAX_CAPE, itemIDGodMaxCape);
mappings.put(ZAMORAK_MAX_CAPE, itemIDGodMaxCape);
final int itemIDImbuedGodMaxCape = 1000000004;
mappings.put(ItemID.IMBUED_SARADOMIN_MAX_CAPE, itemIDImbuedGodMaxCape);
mappings.put(ItemID.IMBUED_GUTHIX_MAX_CAPE, itemIDImbuedGodMaxCape);
mappings.put(ItemID.IMBUED_ZAMORAK_MAX_CAPE, itemIDImbuedGodMaxCape);
mappings.put(IMBUED_SARADOMIN_MAX_CAPE, itemIDImbuedGodMaxCape);
mappings.put(IMBUED_GUTHIX_MAX_CAPE, itemIDImbuedGodMaxCape);
mappings.put(IMBUED_ZAMORAK_MAX_CAPE, itemIDImbuedGodMaxCape);

// Make god d'hides the same
final int itemIDGodCoif = 1000000005;
mappings.put(ANCIENT_COIF, itemIDGodCoif);
mappings.put(ARMADYL_COIF, itemIDGodCoif);
mappings.put(BANDOS_COIF, itemIDGodCoif);
mappings.put(GUTHIX_COIF, itemIDGodCoif);
mappings.put(SARADOMIN_COIF, itemIDGodCoif);
mappings.put(ZAMORAK_COIF, itemIDGodCoif);

final int itemIDGodDhideBody = 1000000006;
mappings.put(ANCIENT_DHIDE_BODY, itemIDGodDhideBody);
mappings.put(ARMADYL_DHIDE_BODY, itemIDGodDhideBody);
mappings.put(BANDOS_DHIDE_BODY, itemIDGodDhideBody);
mappings.put(GUTHIX_DHIDE_BODY, itemIDGodDhideBody);
mappings.put(SARADOMIN_DHIDE_BODY, itemIDGodDhideBody);
mappings.put(ZAMORAK_DHIDE_BODY, itemIDGodDhideBody);

final int itemIDGodChaps = 1000000007;
mappings.put(ANCIENT_CHAPS, itemIDGodChaps);
mappings.put(ARMADYL_CHAPS, itemIDGodChaps);
mappings.put(BANDOS_CHAPS, itemIDGodChaps);
mappings.put(GUTHIX_CHAPS, itemIDGodChaps);
mappings.put(SARADOMIN_CHAPS, itemIDGodChaps);
mappings.put(ZAMORAK_CHAPS, itemIDGodChaps);

final int itemIDGodBracers = 1000000008;
mappings.put(ANCIENT_BRACERS, itemIDGodBracers);
mappings.put(ARMADYL_BRACERS, itemIDGodBracers);
mappings.put(BANDOS_BRACERS, itemIDGodBracers);
mappings.put(GUTHIX_BRACERS, itemIDGodBracers);
mappings.put(SARADOMIN_BRACERS, itemIDGodBracers);
mappings.put(ZAMORAK_BRACERS, itemIDGodBracers);

final int itemIDGodDhideBoots = 1000000009;
mappings.put(ANCIENT_DHIDE_BOOTS, itemIDGodDhideBoots);
mappings.put(ARMADYL_DHIDE_BOOTS, itemIDGodDhideBoots);
mappings.put(BANDOS_DHIDE_BOOTS, itemIDGodDhideBoots);
mappings.put(GUTHIX_DHIDE_BOOTS, itemIDGodDhideBoots);
mappings.put(SARADOMIN_DHIDE_BOOTS, itemIDGodDhideBoots);
mappings.put(ZAMORAK_DHIDE_BOOTS, itemIDGodDhideBoots);

final int itemIDGodDhideShield = 1000000010;
mappings.put(ANCIENT_DHIDE_SHIELD, itemIDGodDhideShield);
mappings.put(ARMADYL_DHIDE_SHIELD, itemIDGodDhideShield);
mappings.put(BANDOS_DHIDE_SHIELD, itemIDGodDhideShield);
mappings.put(GUTHIX_DHIDE_SHIELD, itemIDGodDhideShield);
mappings.put(SARADOMIN_DHIDE_SHIELD, itemIDGodDhideShield);
mappings.put(ZAMORAK_DHIDE_SHIELD, itemIDGodDhideShield);

// Twisted Ancestral -> Regular Ancestral
mappings.put(ItemID.TWISTED_ANCESTRAL_HAT, ItemID.ANCESTRAL_HAT);
mappings.put(ItemID.TWISTED_ANCESTRAL_ROBE_BOTTOM, ItemID.ANCESTRAL_ROBE_BOTTOM);
mappings.put(ItemID.TWISTED_ANCESTRAL_ROBE_TOP, ItemID.ANCESTRAL_ROBE_TOP);
mappings.put(TWISTED_ANCESTRAL_HAT, ANCESTRAL_HAT);
mappings.put(TWISTED_ANCESTRAL_ROBE_BOTTOM, ANCESTRAL_ROBE_BOTTOM);
mappings.put(TWISTED_ANCESTRAL_ROBE_TOP, ANCESTRAL_ROBE_TOP);

// Golden Prospectors -> Regular Prospectors
mappings.put(ItemID.GOLDEN_PROSPECTOR_BOOTS, ItemID.PROSPECTOR_BOOTS);
mappings.put(ItemID.GOLDEN_PROSPECTOR_HELMET, ItemID.PROSPECTOR_HELMET);
mappings.put(ItemID.GOLDEN_PROSPECTOR_JACKET, ItemID.PROSPECTOR_JACKET);
mappings.put(ItemID.GOLDEN_PROSPECTOR_LEGS, ItemID.PROSPECTOR_LEGS);
mappings.put(GOLDEN_PROSPECTOR_BOOTS, PROSPECTOR_BOOTS);
mappings.put(GOLDEN_PROSPECTOR_HELMET, PROSPECTOR_HELMET);
mappings.put(GOLDEN_PROSPECTOR_JACKET, PROSPECTOR_JACKET);
mappings.put(GOLDEN_PROSPECTOR_LEGS, PROSPECTOR_LEGS);

// Spirit Anglers -> Regular Anglers
mappings.put(ItemID.SPIRIT_ANGLER_BOOTS, ItemID.ANGLER_BOOTS);
mappings.put(ItemID.SPIRIT_ANGLER_HEADBAND, ItemID.ANGLER_HAT);
mappings.put(ItemID.SPIRIT_ANGLER_TOP, ItemID.ANGLER_TOP);
mappings.put(ItemID.SPIRIT_ANGLER_WADERS, ItemID.ANGLER_WADERS);
mappings.put(SPIRIT_ANGLER_BOOTS, ANGLER_BOOTS);
mappings.put(SPIRIT_ANGLER_HEADBAND, ANGLER_HAT);
mappings.put(SPIRIT_ANGLER_TOP, ANGLER_TOP);
mappings.put(SPIRIT_ANGLER_WADERS, ANGLER_WADERS);

// ToB ornament kits -> base version
mappings.put(ItemID.SANGUINE_SCYTHE_OF_VITUR, ItemID.SCYTHE_OF_VITUR);
mappings.put(ItemID.HOLY_SCYTHE_OF_VITUR, ItemID.SCYTHE_OF_VITUR);
mappings.put(ItemID.HOLY_SANGUINESTI_STAFF, ItemID.SANGUINESTI_STAFF);
mappings.put(ItemID.HOLY_GHRAZI_RAPIER, ItemID.GHRAZI_RAPIER);
mappings.put(SANGUINE_SCYTHE_OF_VITUR, SCYTHE_OF_VITUR);
mappings.put(HOLY_SCYTHE_OF_VITUR, SCYTHE_OF_VITUR);
mappings.put(HOLY_SANGUINESTI_STAFF, SANGUINESTI_STAFF);
mappings.put(HOLY_GHRAZI_RAPIER, GHRAZI_RAPIER);

mappings.put(GHOMMALS_AVERNIC_DEFENDER_5, AVERNIC_DEFENDER);
mappings.put(GHOMMALS_AVERNIC_DEFENDER_5_L, AVERNIC_DEFENDER);
mappings.put(GHOMMALS_AVERNIC_DEFENDER_6, AVERNIC_DEFENDER);
mappings.put(GHOMMALS_AVERNIC_DEFENDER_6_L, AVERNIC_DEFENDER);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ static public InventorySetupSerializable convertFromInventorySetup(final Invento
List<InventorySetupItemSerializable> bp = convertListFromInventorySetup(inventorySetup.getBoltPouch());

Map<Integer, InventorySetupItemSerializable> afi = null;
if (!inventorySetup.getAdditionalFilteredItems().isEmpty())
if (inventorySetup.getAdditionalFilteredItems() != null && !inventorySetup.getAdditionalFilteredItems().isEmpty())
{
afi = new HashMap<>();
for (final Integer key : inventorySetup.getAdditionalFilteredItems().keySet())
Expand All @@ -70,7 +70,7 @@ static public InventorySetupSerializable convertFromInventorySetup(final Invento
Boolean uh = inventorySetup.isUnorderedHighlight() ? Boolean.TRUE : null;
Integer sb = inventorySetup.getSpellBook() != 0 ? inventorySetup.getSpellBook() : null;
Boolean fv = inventorySetup.isFavorite() ? Boolean.TRUE : null;
Integer iId = inventorySetup.getIconID() <= 0 ? inventorySetup.getIconID() : null;
Integer iId = inventorySetup.getIconID() > 0 ? inventorySetup.getIconID() : null;

return new InventorySetupSerializable(inv, eq, rp, bp, afi, name, notes, hc, hd, dc, fb, uh, sb, fv, iId);
}
Expand Down

0 comments on commit 087dc5b

Please sign in to comment.