Update to use a centralized fetcher

This commit is contained in:
downthecrop 2025-11-14 23:20:00 -08:00
parent 6adc5135bc
commit 03a205f64b
9 changed files with 169 additions and 128 deletions

View file

@ -23,6 +23,7 @@ import KondoKit.plugin.Companion.playerXPMultiplier
import KondoKit.plugin.Companion.primaryColor
import KondoKit.plugin.Companion.secondaryColor
import KondoKit.plugin.StateManager.focusedView
import KondoKit.util.JsonParser
import plugin.api.API
import java.awt.*
import java.awt.image.BufferedImage
@ -43,20 +44,10 @@ object XPTrackerView : View, OnUpdateCallback, OnXPUpdateCallback {
val npcHitpointsMap: Map<Int, Int> = try {
val json = Helpers.readResourceText("res/npc_hitpoints_map.json") ?: "{}"
val pairs = json.trim().removeSurrounding("{", "}").split(",")
val map = mutableMapOf<Int, Int>()
for (pair in pairs) {
val keyValue = pair.split(":")
val id = keyValue[0].trim().trim('\"').toIntOrNull()
val hitpoints = keyValue[1].trim()
if (id != null && hitpoints.isNotEmpty()) {
map[id] = hitpoints.toIntOrNull() ?: 0
}
}
map
val parsed: Map<String, Int> = JsonParser.fromJson(json)
parsed.mapNotNull { (key, value) ->
key.toIntOrNull()?.let { it to value }
}.toMap()
} catch (e: Exception) {
println("XPTracker Error parsing NPC HP: ${e.message}")
emptyMap()