Merge pull request #7947 from deathbeam/convert-item-stats-to-ids

Convert item stats mapping to use item ids instead of names
This commit is contained in:
Tomas Slusny
2019-02-27 09:19:13 +00:00
committed by GitHub
3 changed files with 11 additions and 10 deletions

View File

@@ -204,11 +204,12 @@ public class ItemClient
} }
} }
public Map<String, ItemStats> getStats() throws IOException public Map<Integer, ItemStats> getStats() throws IOException
{ {
HttpUrl.Builder urlBuilder = RuneLiteAPI.getStaticBase().newBuilder() HttpUrl.Builder urlBuilder = RuneLiteAPI.getStaticBase().newBuilder()
.addPathSegment("item") .addPathSegment("item")
.addPathSegment("stats.min.json"); // TODO: Change this to stats.min.json later after release is undeployed
.addPathSegment("stats.ids.min.json");
HttpUrl url = urlBuilder.build(); HttpUrl url = urlBuilder.build();
@@ -227,7 +228,7 @@ public class ItemClient
} }
InputStream in = response.body().byteStream(); InputStream in = response.body().byteStream();
final Type typeToken = new TypeToken<Map<String, ItemStats>>() final Type typeToken = new TypeToken<Map<Integer, ItemStats>>()
{ {
}.getType(); }.getType();
return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in), typeToken); return RuneLiteAPI.GSON.fromJson(new InputStreamReader(in), typeToken);

View File

@@ -84,7 +84,7 @@ public class ItemManager
private final ItemClient itemClient = new ItemClient(); private final ItemClient itemClient = new ItemClient();
private Map<Integer, ItemPrice> itemPrices = Collections.emptyMap(); private Map<Integer, ItemPrice> itemPrices = Collections.emptyMap();
private Map<String, ItemStats> itemStats = Collections.emptyMap(); private Map<Integer, ItemStats> itemStats = Collections.emptyMap();
private final LoadingCache<ImageKey, AsyncBufferedImage> itemImages; private final LoadingCache<ImageKey, AsyncBufferedImage> itemImages;
private final LoadingCache<Integer, ItemComposition> itemCompositions; private final LoadingCache<Integer, ItemComposition> itemCompositions;
private final LoadingCache<OutlineKey, BufferedImage> itemOutlines; private final LoadingCache<OutlineKey, BufferedImage> itemOutlines;
@@ -226,7 +226,7 @@ public class ItemManager
{ {
try try
{ {
final Map<String, ItemStats> stats = itemClient.getStats(); final Map<Integer, ItemStats> stats = itemClient.getStats();
if (stats != null) if (stats != null)
{ {
itemStats = ImmutableMap.copyOf(stats); itemStats = ImmutableMap.copyOf(stats);
@@ -307,16 +307,16 @@ public class ItemManager
* @return item stats * @return item stats
*/ */
@Nullable @Nullable
public ItemStats getItemStats(int itemId) public ItemStats getItemStats(int itemId, boolean allowNote)
{ {
ItemComposition itemComposition = getItemComposition(itemId); ItemComposition itemComposition = getItemComposition(itemId);
if (itemComposition == null || itemComposition.getName() == null) if (itemComposition == null || itemComposition.getName() == null || (!allowNote && itemComposition.getNote() != -1))
{ {
return null; return null;
} }
return itemStats.get(itemComposition.getName()); return itemStats.get(canonicalize(itemId));
} }
/** /**

View File

@@ -139,7 +139,7 @@ public class ItemStatOverlay extends Overlay
if (config.equipmentStats()) if (config.equipmentStats())
{ {
final ItemStats stats = itemManager.getItemStats(itemId); final ItemStats stats = itemManager.getItemStats(itemId, false);
if (stats != null) if (stats != null)
{ {
@@ -205,7 +205,7 @@ public class ItemStatOverlay extends Overlay
final Item item = items[slot]; final Item item = items[slot];
if (item != null) if (item != null)
{ {
other = itemManager.getItemStats(item.getId()); other = itemManager.getItemStats(item.getId(), false);
} }
} }