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:
Im2be
2020-01-16 21:08:38 +01:00
committed by Kyle
parent 47dcb4ba2a
commit 9baab7a499
3 changed files with 84 additions and 33 deletions

View File

@@ -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;
}

View File

@@ -77,6 +77,9 @@ import java.awt.datatransfer.StringSelection;
import java.awt.image.BufferedImage;
import java.lang.reflect.Type;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.HashMap;
import java.util.stream.Collectors;
@PluginDescriptor(
name = "Inventory Setups",
@@ -712,7 +715,38 @@ public class InventorySetupPlugin extends Plugin
catch (Exception e)
{
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(() ->
{
inventorySetups.add(newSetup);
inventorySetups = new ArrayList<>(inventorySetups.stream()
.sorted(Comparator.comparing(InventorySetup::getName, String::compareToIgnoreCase))
.collect(Collectors.toList()));
panel.rebuild();
updateJsonConfig();

View File

@@ -27,6 +27,7 @@ package net.runelite.client.plugins.raids.solver;
import com.google.common.collect.ImmutableList;
import net.runelite.client.plugins.raids.RaidRoom;
import net.runelite.client.plugins.raids.RoomType;
import java.util.ArrayList;
import java.util.List;
import static net.runelite.client.plugins.raids.RaidRoom.GUARDIANS;
import static net.runelite.client.plugins.raids.RaidRoom.MUTTADILES;
@@ -55,7 +56,7 @@ public class RotationSolver
return false;
}
List<RaidRoom> match = null;
List<ImmutableList<RaidRoom>> matches = new ArrayList<>();
Integer start = null;
Integer index = null;
int known = 0;
@@ -85,52 +86,49 @@ public class RotationSolver
return true;
}
for (List rotation : ROTATIONS)
//Iterate over each rotation
for (ImmutableList<RaidRoom> rotation : ROTATIONS)
{
COMPARE:
for (int i = 0; i < rotation.size(); i++)
//Determine the index of the first known combat room in this rotation
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++)
{
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;
doesNotMatch = true;
}
++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;
}
List<RaidRoom> match = matches.get(0);
for (int i = 0; i < rooms.length; i++)
{
if (rooms[i] == null)
if (rooms[i].getType() != RoomType.COMBAT || rooms[i] == UNKNOWN_COMBAT)
{
continue;
}
if ((rooms[i].getType() != RoomType.COMBAT || rooms[i] == UNKNOWN_COMBAT))
{
rooms[i] = match.get((index + i + match.size()) % match.size());
rooms[i] = match.get(Math.floorMod((index + i), match.size()));
}
}
return true;