aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt
diff options
context:
space:
mode:
authorThunderblade73 <85900443+Thunderblade73@users.noreply.github.com>2024-04-12 19:11:02 +0200
committerGitHub <noreply@github.com>2024-04-12 19:11:02 +0200
commit5ff579652ef80207a780a80399be376c345342b0 (patch)
tree6f80311a35d8fd6bb41d63b8ce2758891146d128 /src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt
parent7960d2ad27ac68ea9dcfaf848bd611b13db0af87 (diff)
downloadskyhanni-5ff579652ef80207a780a80399be376c345342b0.tar.gz
skyhanni-5ff579652ef80207a780a80399be376c345342b0.tar.bz2
skyhanni-5ff579652ef80207a780a80399be376c345342b0.zip
Backend: Remove Neu Constant (#1191)
Co-authored-by: CalMWolfs <94038482+CalMWolfs@users.noreply.github.com> Co-authored-by: hannibal2 <24389977+hannibal00212@users.noreply.github.com>
Diffstat (limited to 'src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt')
-rw-r--r--src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt32
1 files changed, 11 insertions, 21 deletions
diff --git a/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt b/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt
index 55384443f..bcbee1cad 100644
--- a/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt
+++ b/src/main/java/at/hannibal2/skyhanni/api/SkillAPI.kt
@@ -1,10 +1,11 @@
package at.hannibal2.skyhanni.api
import at.hannibal2.skyhanni.data.ProfileStorageData
+import at.hannibal2.skyhanni.data.jsonobjects.repo.neu.NeuSkillLevelJson
import at.hannibal2.skyhanni.events.ActionBarUpdateEvent
-import at.hannibal2.skyhanni.events.ConfigLoadEvent
import at.hannibal2.skyhanni.events.DebugDataCollectEvent
import at.hannibal2.skyhanni.events.InventoryFullyOpenedEvent
+import at.hannibal2.skyhanni.events.NeuRepositoryReloadEvent
import at.hannibal2.skyhanni.events.SecondPassedEvent
import at.hannibal2.skyhanni.events.SkillOverflowLevelupEvent
import at.hannibal2.skyhanni.features.skillprogress.SkillProgress
@@ -16,7 +17,6 @@ import at.hannibal2.skyhanni.features.skillprogress.SkillUtil.calculateOverFlow
import at.hannibal2.skyhanni.features.skillprogress.SkillUtil.getLevel
import at.hannibal2.skyhanni.features.skillprogress.SkillUtil.getLevelExact
import at.hannibal2.skyhanni.features.skillprogress.SkillUtil.getSkillInfo
-import at.hannibal2.skyhanni.features.skillprogress.SkillUtil.levelArray
import at.hannibal2.skyhanni.features.skillprogress.SkillUtil.xpRequiredForLevel
import at.hannibal2.skyhanni.utils.ChatUtils
import at.hannibal2.skyhanni.utils.ItemUtils.cleanName
@@ -30,11 +30,7 @@ import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.StringUtils.removeColor
import at.hannibal2.skyhanni.utils.TabListData
import at.hannibal2.skyhanni.utils.repopatterns.RepoPattern
-import com.google.gson.GsonBuilder
import com.google.gson.annotations.Expose
-import com.google.gson.reflect.TypeToken
-import io.github.moulberry.notenoughupdates.util.Constants
-import io.github.moulberry.notenoughupdates.util.Utils
import net.minecraft.command.CommandBase
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent
import java.util.LinkedList
@@ -69,6 +65,7 @@ object SkillAPI {
val storage get() = ProfileStorageData.profileSpecific?.skillData
var exactLevelingMap = mapOf<Int, Int>()
var levelingMap = mapOf<Int, Int>()
+ var levelArray = listOf<Int>()
var activeSkill: SkillType? = null
// TODO Use a map maxSkillLevel and move it into the repo
@@ -135,14 +132,10 @@ object SkillAPI {
}
@SubscribeEvent
- fun onConfigLoad(event: ConfigLoadEvent) {
- val gson = GsonBuilder().create()
- val xpList: List<Int> = gson.fromJson(
- Utils.getElement(Constants.LEVELING, "leveling_xp").asJsonArray.toString(),
- object : TypeToken<List<Int>>() {}.type
- )
- levelingMap = xpList.withIndex().associate { (index, xp) -> index to xp }
- exactLevelingMap = xpList.withIndex().associate { (index, xp) -> xp to index }
+ fun onNEURepoReload(event: NeuRepositoryReloadEvent) {
+ levelArray = event.readConstant<NeuSkillLevelJson>("leveling").levelingXp
+ levelingMap = levelArray.withIndex().associate { (index, xp) -> index to xp }
+ exactLevelingMap = levelArray.withIndex().associate { (index, xp) -> xp to index }
}
@SubscribeEvent
@@ -190,8 +183,7 @@ object SkillAPI {
val splitProgress = progress.split("/")
val currentXp = splitProgress.first().formatLong()
val neededXp = splitProgress.last().formatLong()
- val levelingArray = levelArray()
- val levelXp = calculateLevelXp(levelingArray, skillLevel - 1).toLong()
+ val levelXp = calculateLevelXp(skillLevel - 1).toLong()
skillInfo?.apply {
this.currentXp = currentXp
@@ -310,9 +302,8 @@ object SkillAPI {
}
val existingLevel = getSkillInfo(skillType) ?: SkillInfo()
val xpPercentage = matcher.group("progress").formatDouble()
- val levelingArray = levelArray()
- val levelXp = calculateLevelXp(levelingArray, existingLevel.level - 1)
- val nextLevelDiff = levelingArray[tablistLevel]?.asDouble ?: 7_600_000.0
+ val levelXp = calculateLevelXp(existingLevel.level - 1)
+ val nextLevelDiff = levelArray.getOrNull(tablistLevel)?.toDouble() ?: 7_600_000.0
val nextLevelProgress = nextLevelDiff * xpPercentage / 100
val totalXp = levelXp + nextLevelProgress
val (_, currentOverflow, currentMaxOverflow, totalOverflow) = getSkillInfo(
@@ -341,8 +332,7 @@ object SkillAPI {
val currentXp = matcher.group("current").formatLong()
val maxXp = matcher.group("needed").formatLong()
val level = getLevelExact(maxXp)
- val levelingArray = levelArray()
- val levelXp = calculateLevelXp(levelingArray, level - 1).toLong() + currentXp
+ val levelXp = calculateLevelXp(level - 1).toLong() + currentXp
val (currentLevel, currentOverflow, currentMaxOverflow, totalOverflow) = getSkillInfo(
level,
currentXp,