From 6eb085f4e2ba69e98934ffa9489c8679ba23d244 Mon Sep 17 00:00:00 2001 From: Thunderblade73 <85900443+Thunderblade73@users.noreply.github.com> Date: Sun, 23 Jun 2024 20:06:17 +0200 Subject: Feature: Reforge helper (#1437) Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Co-authored-by: hannibal2 <24389977+hannibal002@users.noreply.github.com> Co-authored-by: Cal Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com> --- .../data/jsonobjects/repo/neu/NeuReforgeJson.kt | 67 ++++++++++++++++++++++ .../jsonobjects/repo/neu/NeuReforgeStoneJson.kt | 63 -------------------- 2 files changed, 67 insertions(+), 63 deletions(-) create mode 100644 src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/neu/NeuReforgeJson.kt delete mode 100644 src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/neu/NeuReforgeStoneJson.kt (limited to 'src/main/java/at/hannibal2/skyhanni/data/jsonobjects') diff --git a/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/neu/NeuReforgeJson.kt b/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/neu/NeuReforgeJson.kt new file mode 100644 index 000000000..a8c8f3fe4 --- /dev/null +++ b/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/neu/NeuReforgeJson.kt @@ -0,0 +1,67 @@ +package at.hannibal2.skyhanni.data.jsonobjects.repo.neu + +import at.hannibal2.skyhanni.data.model.SkyblockStatList +import at.hannibal2.skyhanni.utils.LorenzRarity +import at.hannibal2.skyhanni.utils.NEUInternalName +import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.asInternalName +import at.hannibal2.skyhanni.utils.NEUItems +import com.google.gson.annotations.Expose +import com.google.gson.annotations.SerializedName +import net.minecraft.item.Item + +data class NeuReforgeJson( + @Expose val internalName: NEUInternalName?, + @Expose val reforgeName: String, + @Expose @SerializedName("itemTypes") val rawItemTypes: Any, + @Expose val requiredRarities: List, + @Expose val reforgeCosts: Map?, + @Expose val reforgeStats: Map?, + @Expose @SerializedName("reforgeAbility") val rawReforgeAbility: Any?, +) { + + private lateinit var reforgeAbilityField: Map + private lateinit var itemTypeField: Pair> + + val reforgeAbility + get() = if (this::reforgeAbilityField.isInitialized) reforgeAbilityField + else { + reforgeAbilityField = when (this.rawReforgeAbility) { + is String -> { + this.requiredRarities.associateWith { this.rawReforgeAbility } + } + + is Map<*, *> -> (this.rawReforgeAbility as? Map)?.mapKeys { + LorenzRarity.valueOf( + it.key.uppercase().replace(" ", "_"), + ) + } ?: emptyMap() + + else -> emptyMap() + } + reforgeAbilityField + } + + val itemType: Pair> + get() = if (this::itemTypeField.isInitialized) itemTypeField + else run { + val any = this.rawItemTypes + return when (any) { + is String -> { + any.replace("/", "_AND_").uppercase() to emptyList() + } + + is Map<*, *> -> { + val type = "SPECIAL_ITEMS" + val map = any as? Map> ?: return type to emptyList() + val internalNames = map["internalName"]?.map { it.asInternalName() } ?: emptyList() + val itemType = map["itemid"]?.map { + NEUItems.getInternalNamesForItemId(Item.getByNameOrId(it)) + }?.flatten() ?: emptyList() + type to (internalNames + itemType) + } + + else -> throw IllegalStateException() + } + } +} + diff --git a/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/neu/NeuReforgeStoneJson.kt b/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/neu/NeuReforgeStoneJson.kt deleted file mode 100644 index 8ebe2dea6..000000000 --- a/src/main/java/at/hannibal2/skyhanni/data/jsonobjects/repo/neu/NeuReforgeStoneJson.kt +++ /dev/null @@ -1,63 +0,0 @@ -package at.hannibal2.skyhanni.data.jsonobjects.repo.neu - -import at.hannibal2.skyhanni.utils.LorenzRarity -import at.hannibal2.skyhanni.utils.NEUInternalName -import com.google.gson.annotations.Expose -import com.google.gson.annotations.SerializedName - -data class NeuReforgeStoneJson( - @Expose val internalName: NEUInternalName, - @Expose val reforgeName: String, - @Expose @SerializedName("itemTypes") val rawItemTypes: Any, - @Expose val requiredRarities: List, - @Expose val reforgeCosts: Map, - @Expose val reforgeStats: Map>, - @Expose @SerializedName("reforgeAbility") val rawReforgeAbility: Any?, -) { - - private lateinit var reforgeAbilityField: Map - - val reforgeAbility - get() = if (this::reforgeAbilityField.isInitialized) reforgeAbilityField - else { - reforgeAbilityField = when (this.rawReforgeAbility) { - is String -> { - this.requiredRarities.associateWith { this.rawReforgeAbility } - } - - is Map<*, *> -> (this.rawReforgeAbility as? Map)?.mapKeys { - LorenzRarity.valueOf( - it.key.uppercase().replace(" ", "_") - ) - } ?: emptyMap() - - else -> emptyMap() - } - reforgeAbilityField - } - - /* used in ReforgeAPI which isn't in beta yet - val itemType: Pair> by lazy { - val any = this.rawItemTypes - return@lazy when (any) { - is String -> { - any.replace("/", "_AND_").uppercase() to emptyList() - } - - is Map<*, *> -> { - val type = "SPECIAL_ITEMS" - val map = any as? Map> ?: return@lazy type to emptyList() - val internalNames = map["internalName"]?.map { it.asInternalName() } ?: emptyList() - val itemType = map["itemid"]?.map { - NEUItems.getInternalNamesForItemId(Item.getByNameOrId(it)) - }?.flatten() - ?: emptyList() - type to (internalNames + itemType) - } - - else -> throw IllegalStateException() - } - } -*/ -} - -- cgit