inventorysetups: Fixed old setups not being imported on boot (#2257)
* raids: Fix !layout command & update RaidOverlay * raids: Fixed an uncommon ArrayOutOfBoundsException in RotationSolver * raids: Refactored the RotationSolver logic * inventorysetups: Fixed old setups not being imported (blame Kyle)
This commit is contained in:
@@ -0,0 +1,15 @@
|
|||||||
|
package net.runelite.client.plugins.inventorysetups;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import lombok.AccessLevel;
|
||||||
|
import lombok.AllArgsConstructor;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@AllArgsConstructor
|
||||||
|
public class InventorySetupOld
|
||||||
|
{
|
||||||
|
@Getter(AccessLevel.PUBLIC)
|
||||||
|
private List<InventorySetupItem> inventory;
|
||||||
|
@Getter(AccessLevel.PUBLIC)
|
||||||
|
private List<InventorySetupItem> equipment;
|
||||||
|
}
|
||||||
@@ -77,6 +77,9 @@ import java.awt.datatransfer.StringSelection;
|
|||||||
import java.awt.image.BufferedImage;
|
import java.awt.image.BufferedImage;
|
||||||
import java.lang.reflect.Type;
|
import java.lang.reflect.Type;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Comparator;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
@PluginDescriptor(
|
@PluginDescriptor(
|
||||||
name = "Inventory Setups",
|
name = "Inventory Setups",
|
||||||
@@ -712,7 +715,38 @@ public class InventorySetupPlugin extends Plugin
|
|||||||
catch (Exception e)
|
catch (Exception e)
|
||||||
{
|
{
|
||||||
inventorySetups = new ArrayList<>();
|
inventorySetups = new ArrayList<>();
|
||||||
|
|
||||||
|
//Populate with old inventorysetups
|
||||||
|
final Gson gson = new Gson();
|
||||||
|
Type type = new TypeToken<HashMap<String, InventorySetupOld>>()
|
||||||
|
{
|
||||||
|
}.getType();
|
||||||
|
|
||||||
|
HashMap<String, InventorySetupOld> oldSetups = new HashMap<>();
|
||||||
|
oldSetups.putAll(gson.fromJson(json, type));
|
||||||
|
|
||||||
|
for (String name : oldSetups.keySet())
|
||||||
|
{
|
||||||
|
InventorySetup newSetup = new InventorySetup(
|
||||||
|
new ArrayList<>(oldSetups.get(name).getInventory()),
|
||||||
|
new ArrayList<>(oldSetups.get(name).getEquipment()),
|
||||||
|
null,
|
||||||
|
name,
|
||||||
|
this.highlightColor,
|
||||||
|
this.highlightStackDifference,
|
||||||
|
this.highlightVariationDifference,
|
||||||
|
this.highlightDifference,
|
||||||
|
this.bankFilter,
|
||||||
|
this.highlightUnorderedDifference);
|
||||||
|
|
||||||
|
inventorySetups.add(newSetup);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inventorySetups = new ArrayList<>(inventorySetups.stream()
|
||||||
|
.sorted(Comparator.comparing(InventorySetup::getName, String::compareToIgnoreCase))
|
||||||
|
.collect(Collectors.toList()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -721,6 +755,10 @@ public class InventorySetupPlugin extends Plugin
|
|||||||
SwingUtilities.invokeLater(() ->
|
SwingUtilities.invokeLater(() ->
|
||||||
{
|
{
|
||||||
inventorySetups.add(newSetup);
|
inventorySetups.add(newSetup);
|
||||||
|
inventorySetups = new ArrayList<>(inventorySetups.stream()
|
||||||
|
.sorted(Comparator.comparing(InventorySetup::getName, String::compareToIgnoreCase))
|
||||||
|
.collect(Collectors.toList()));
|
||||||
|
|
||||||
panel.rebuild();
|
panel.rebuild();
|
||||||
|
|
||||||
updateJsonConfig();
|
updateJsonConfig();
|
||||||
|
|||||||
@@ -27,6 +27,7 @@ package net.runelite.client.plugins.raids.solver;
|
|||||||
import com.google.common.collect.ImmutableList;
|
import com.google.common.collect.ImmutableList;
|
||||||
import net.runelite.client.plugins.raids.RaidRoom;
|
import net.runelite.client.plugins.raids.RaidRoom;
|
||||||
import net.runelite.client.plugins.raids.RoomType;
|
import net.runelite.client.plugins.raids.RoomType;
|
||||||
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import static net.runelite.client.plugins.raids.RaidRoom.GUARDIANS;
|
import static net.runelite.client.plugins.raids.RaidRoom.GUARDIANS;
|
||||||
import static net.runelite.client.plugins.raids.RaidRoom.MUTTADILES;
|
import static net.runelite.client.plugins.raids.RaidRoom.MUTTADILES;
|
||||||
@@ -55,7 +56,7 @@ public class RotationSolver
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
List<RaidRoom> match = null;
|
List<ImmutableList<RaidRoom>> matches = new ArrayList<>();
|
||||||
Integer start = null;
|
Integer start = null;
|
||||||
Integer index = null;
|
Integer index = null;
|
||||||
int known = 0;
|
int known = 0;
|
||||||
@@ -85,52 +86,49 @@ public class RotationSolver
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (List rotation : ROTATIONS)
|
//Iterate over each rotation
|
||||||
|
for (ImmutableList<RaidRoom> rotation : ROTATIONS)
|
||||||
{
|
{
|
||||||
COMPARE:
|
//Determine the index of the first known combat room in this rotation
|
||||||
for (int i = 0; i < rotation.size(); i++)
|
int rotationStart = rotation.indexOf(rooms[start]);
|
||||||
|
|
||||||
|
//Iterate over each room (except the starting room) and determine whether or not the rotation still matches
|
||||||
|
int roomStep = 1;
|
||||||
|
boolean doesNotMatch = false;
|
||||||
|
while (roomStep < rooms.length && !doesNotMatch)
|
||||||
{
|
{
|
||||||
if (rooms[start] == rotation.get(i))
|
var roomIndex = (start + roomStep) % rooms.length;
|
||||||
|
var rotationRoomIndex = (rotationStart + roomStep) % rotation.size();
|
||||||
|
if (rooms[roomIndex] != UNKNOWN_COMBAT && rooms[roomIndex] != rotation.get(rotationRoomIndex))
|
||||||
{
|
{
|
||||||
for (int j = start + 1; j < rooms.length; j++)
|
doesNotMatch = true;
|
||||||
{
|
|
||||||
if (rooms[j].getType() != RoomType.COMBAT || rooms[j] == UNKNOWN_COMBAT)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
|
|
||||||
if (rooms[j] != rotation.get((i + j - start) % rotation.size()))
|
|
||||||
{
|
|
||||||
break COMPARE;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (match != null && match.equals(rotation))
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
index = i - start;
|
|
||||||
match = rotation;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
++roomStep;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!doesNotMatch)
|
||||||
|
{
|
||||||
|
//Found a matching rotation!
|
||||||
|
matches.add(rotation);
|
||||||
|
index = rotationStart - start;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (match == null)
|
if (matches.size() != 1)
|
||||||
{
|
{
|
||||||
|
//Could not find a unique match!
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
List<RaidRoom> match = matches.get(0);
|
||||||
|
|
||||||
|
|
||||||
for (int i = 0; i < rooms.length; i++)
|
for (int i = 0; i < rooms.length; i++)
|
||||||
{
|
{
|
||||||
if (rooms[i] == null)
|
if (rooms[i].getType() != RoomType.COMBAT || rooms[i] == UNKNOWN_COMBAT)
|
||||||
{
|
{
|
||||||
continue;
|
rooms[i] = match.get(Math.floorMod((index + i), match.size()));
|
||||||
}
|
|
||||||
|
|
||||||
if ((rooms[i].getType() != RoomType.COMBAT || rooms[i] == UNKNOWN_COMBAT))
|
|
||||||
{
|
|
||||||
rooms[i] = match.get((index + i + match.size()) % match.size());
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|||||||
Reference in New Issue
Block a user