feat: Load mining islands from repo

This commit is contained in:
Linnea Gräf
2025-03-06 20:24:25 +01:00
parent 877edf7539
commit ebd2f270c3
7 changed files with 115 additions and 41 deletions

View File

@@ -31,6 +31,10 @@ object SBData {
val hypixelTimeZone = ZoneId.of("US/Eastern")
private var hasReceivedProfile = false
var locraw: Locraw? = null
/**
* The current server location the player is in. This will be null outside of SkyBlock.
*/
val skyblockLocation: SkyBlockIsland? get() = locraw?.skyblockLocation
val hasValidLocraw get() = locraw?.server !in listOf("limbo", null)
val isOnSkyblock get() = locraw?.gametype == "SKYBLOCK"

View File

@@ -1,4 +1,3 @@
package moe.nea.firmament.util
import kotlinx.serialization.KSerializer
@@ -13,33 +12,40 @@ import moe.nea.firmament.repo.RepoManager
@Serializable(with = SkyBlockIsland.Serializer::class)
class SkyBlockIsland
private constructor(
val locrawMode: String,
val locrawMode: String,
) {
object Serializer : KSerializer<SkyBlockIsland> {
override val descriptor: SerialDescriptor
get() = PrimitiveSerialDescriptor("SkyBlockIsland", PrimitiveKind.STRING)
object Serializer : KSerializer<SkyBlockIsland> {
override val descriptor: SerialDescriptor
get() = PrimitiveSerialDescriptor("SkyBlockIsland", PrimitiveKind.STRING)
override fun deserialize(decoder: Decoder): SkyBlockIsland {
return forMode(decoder.decodeString())
}
override fun deserialize(decoder: Decoder): SkyBlockIsland {
return forMode(decoder.decodeString())
}
override fun serialize(encoder: Encoder, value: SkyBlockIsland) {
encoder.encodeString(value.locrawMode)
}
}
companion object {
private val allIslands = mutableMapOf<String, SkyBlockIsland>()
fun forMode(mode: String): SkyBlockIsland = allIslands.computeIfAbsent(mode, ::SkyBlockIsland)
val HUB = forMode("hub")
val PRIVATE_ISLAND = forMode("dynamic")
val RIFT = forMode("rift")
val MINESHAFT = forMode("mineshaft")
val GARDEN = forMode("garden")
val DUNGEON = forMode("dungeon")
}
override fun serialize(encoder: Encoder, value: SkyBlockIsland) {
encoder.encodeString(value.locrawMode)
}
}
val userFriendlyName
get() = RepoManager.neuRepo.constants.islands.areaNames
.getOrDefault(locrawMode, locrawMode)
companion object {
private val allIslands = mutableMapOf<String, SkyBlockIsland>()
fun forMode(mode: String): SkyBlockIsland = allIslands.computeIfAbsent(mode, ::SkyBlockIsland)
val HUB = forMode("hub")
val DWARVEN_MINES = forMode("dwarven_mines")
val CRYSTAL_HOLLOWS = forMode("crystal_hollows")
val CRIMSON_ISLE = forMode("crimson_isle")
val PRIVATE_ISLAND = forMode("dynamic")
val RIFT = forMode("rift")
val MINESHAFT = forMode("mineshaft")
val GARDEN = forMode("garden")
val DUNGEON = forMode("dungeon")
}
val hasCustomMining
get() = RepoManager.miningData.customMiningAreas[this]?.isSpecialMining ?: false
val userFriendlyName
get() = RepoManager.neuRepo.constants.islands.areaNames
.getOrDefault(locrawMode, locrawMode)
}