Skip to content

Commit

Permalink
use new versioning for ChangedChatErrors
Browse files Browse the repository at this point in the history
  • Loading branch information
CalMWolfs committed Dec 25, 2024
1 parent bdd12e9 commit e1d862b
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 17 deletions.
2 changes: 1 addition & 1 deletion root.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ allprojects {
* The version of the project.
* Major version
* Minor version
* Patch version
* Beta version
*/
version = "1.0.0"

Expand Down
2 changes: 1 addition & 1 deletion src/main/java/at/hannibal2/skyhanni/SkyHanniMod.kt
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ class SkyHanniMod {

const val MODID = "skyhanni"

private val modVersion: ModVersion by lazy {
val modVersion: ModVersion by lazy {
ModVersion.fromString(Loader.instance().indexedModList[MODID]!!.version)
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,20 @@
package at.hannibal2.skyhanni.data.jsonobjects.repo

import at.hannibal2.skyhanni.utils.system.ModVersion
import com.google.gson.annotations.Expose
import com.google.gson.annotations.SerializedName

data class RepoErrorJson(
data class ChangedChatErrorsJson(
@Expose @SerializedName("changed_error_messages") val changedErrorMessages: List<RepoErrorData>,
)

data class RepoErrorData(
@Expose @SerializedName("message_exact") private var rawMessageExact: List<String>?,
@Expose @SerializedName("message_starts_with") private var rawMessageStartsWith: List<String>?,
@Expose @SerializedName("replace_message") var replaceMessage: String?,
@Expose @SerializedName("custom_message") var customMessage: String?,
@Expose @SerializedName("affected_versions") var affectedVersions: List<String> = listOf(),
@Expose @SerializedName("message_exact") private val rawMessageExact: List<String>?,
@Expose @SerializedName("message_starts_with") private val rawMessageStartsWith: List<String>?,
@Expose @SerializedName("replace_message") val replaceMessage: String?,
@Expose @SerializedName("custom_message") val customMessage: String?,
@Expose @SerializedName("affected_versions") val affectedVersions: List<String> = listOf(),
@Expose @SerializedName("fixed_in") val fixedIn: ModVersion?,
) {
val messageExact get() = rawMessageExact.orEmpty()
val messageStartsWith get() = rawMessageStartsWith.orEmpty()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package at.hannibal2.skyhanni.test.command

import at.hannibal2.skyhanni.SkyHanniMod
import at.hannibal2.skyhanni.data.jsonobjects.repo.ChangedChatErrorsJson
import at.hannibal2.skyhanni.data.jsonobjects.repo.RepoErrorData
import at.hannibal2.skyhanni.data.jsonobjects.repo.RepoErrorJson
import at.hannibal2.skyhanni.events.RepositoryReloadEvent
import at.hannibal2.skyhanni.skyhannimodule.SkyHanniModule
import at.hannibal2.skyhanni.utils.ChatUtils
Expand Down Expand Up @@ -205,10 +205,10 @@ object ErrorManager {

@SubscribeEvent
fun onRepoReload(event: RepositoryReloadEvent) {
val data = event.getConstant<RepoErrorJson>("ChangedChatErrors")
val version = SkyHanniMod.version
val data = event.getConstant<ChangedChatErrorsJson>("ChangedChatErrors")
val version = SkyHanniMod.modVersion

repoErrors = data.changedErrorMessages.filter { version in it.affectedVersions }
repoErrors = data.changedErrorMessages.filter { it.fixedIn == null || version < it.fixedIn }
}

private fun buildExtraDataString(extraData: Array<out Pair<String, Any?>>): String {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import at.hannibal2.skyhanni.utils.LorenzRarity
import at.hannibal2.skyhanni.utils.LorenzVec
import at.hannibal2.skyhanni.utils.NEUInternalName
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.json.SkyHanniTypeAdapters.registerTypeAdapter
import at.hannibal2.skyhanni.utils.system.ModVersion
import at.hannibal2.skyhanni.utils.tracker.SkyHanniTracker
import com.google.gson.GsonBuilder
import io.github.notenoughupdates.moulconfig.observer.PropertyTypeAdapterFactory
Expand All @@ -29,6 +29,7 @@ object BaseGsonBuilder {
.registerTypeAdapter(NEUInternalName::class.java, SkyHanniTypeAdapters.INTERNAL_NAME.nullSafe())
.registerTypeAdapter(LorenzRarity::class.java, SkyHanniTypeAdapters.RARITY.nullSafe())
.registerTypeAdapter(IslandType::class.java, SkyHanniTypeAdapters.ISLAND_TYPE.nullSafe())
.registerTypeAdapter(ModVersion::class.java, SkyHanniTypeAdapters.MOD_VERSION.nullSafe())
.registerTypeAdapter(
SkyHanniTracker.DefaultDisplayMode::class.java,
SkyHanniTypeAdapters.TRACKER_DISPLAY_MODE.nullSafe(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import at.hannibal2.skyhanni.utils.NEUInternalName.Companion.toInternalName
import at.hannibal2.skyhanni.utils.NEUItems
import at.hannibal2.skyhanni.utils.SimpleTimeMark
import at.hannibal2.skyhanni.utils.SimpleTimeMark.Companion.asTimeMark
import at.hannibal2.skyhanni.utils.system.ModVersion
import at.hannibal2.skyhanni.utils.tracker.SkyHanniTracker
import com.google.gson.GsonBuilder
import com.google.gson.TypeAdapter
Expand Down Expand Up @@ -82,6 +83,11 @@ object SkyHanniTypeAdapters {
{ SkyblockStat.getValue(this.uppercase()) },
)

val MOD_VERSION: TypeAdapter<ModVersion> = SimpleStringTypeAdapter(
{ asString },
{ ModVersion.fromString(this) },
)

val TRACKER_DISPLAY_MODE = SimpleStringTypeAdapter.forEnum<SkyHanniTracker.DefaultDisplayMode>()
val ISLAND_TYPE = SimpleStringTypeAdapter.forEnum<IslandType>()
val RARITY = SimpleStringTypeAdapter.forEnum<LorenzRarity>()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package at.hannibal2.skyhanni.utils.system

data class ModVersion(val major: Int, val minor: Int, val patch: Int) {
data class ModVersion(val major: Int, val minor: Int, val beta: Int) {

companion object {
fun fromString(version: String): ModVersion {
Expand All @@ -14,20 +14,20 @@ data class ModVersion(val major: Int, val minor: Int, val patch: Int) {
}
}

val isBeta = patch != 0
val isBeta = beta != 0

val asString: String
get() = toString()

override fun toString(): String {
return "$major.$minor.$patch"
return "$major.$minor.$beta"
}

operator fun compareTo(other: ModVersion): Int {
return when {
major != other.major -> major.compareTo(other.major)
minor != other.minor -> minor.compareTo(other.minor)
else -> patch.compareTo(other.patch)
else -> beta.compareTo(other.beta)
}
}
}

0 comments on commit e1d862b

Please sign in to comment.