Skip to content

Commit

Permalink
refactor(config): move migration related classes to `config.migration…
Browse files Browse the repository at this point in the history
…` package
  • Loading branch information
rvbsm committed Apr 24, 2024
1 parent b014e5e commit ec0b6cd
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ package dev.rvbsm.fsit.config

import com.charleskorn.kaml.*
import dev.rvbsm.fsit.config.container.BlockContainer
import dev.rvbsm.fsit.config.migration.BooleanProperty
import dev.rvbsm.fsit.config.migration.ContainerProperty
import dev.rvbsm.fsit.config.migration.DoubleProperty
import dev.rvbsm.fsit.config.migration.LongProperty
import kotlinx.serialization.json.JsonElement
import kotlinx.serialization.json.jsonObject
import net.minecraft.block.Block
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package dev.rvbsm.fsit.config
package dev.rvbsm.fsit.config.migration

import com.charleskorn.kaml.YamlList
import com.charleskorn.kaml.YamlMap
Expand All @@ -15,7 +15,7 @@ internal class ContainerProperty<E : ItemConvertible, C : Container<E, *>>(
private val key: String,
private val type: Type,
internal var container: C? = null,
) : MigratedField {
) : MigratedProperty {
override fun toString() = key

override fun migrate(yamlMap: YamlMap): Boolean {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package dev.rvbsm.fsit.config
package dev.rvbsm.fsit.config.migration

import com.charleskorn.kaml.YamlMap
import kotlinx.serialization.json.JsonObject

internal interface MigratedField {
internal interface MigratedProperty {
override fun toString(): String

fun migrate(yamlMap: YamlMap): Boolean
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package dev.rvbsm.fsit.config
package dev.rvbsm.fsit.config.migration

import com.charleskorn.kaml.YamlMap
import com.charleskorn.kaml.YamlScalar
import dev.rvbsm.fsit.config.ModConfig
import kotlinx.serialization.json.*
import kotlin.reflect.KMutableProperty

Expand All @@ -13,7 +14,7 @@ internal sealed class PrimitiveProperty<T>(
private val fromYaml: (YamlScalar) -> T,
private val fromJson: (JsonPrimitive) -> T,
internal var config: ModConfig? = null,
) : MigratedField {
) : MigratedProperty {
private val property: KMutableProperty<T> get() = propertyProvider(config!!)

override fun toString() = key
Expand Down

0 comments on commit ec0b6cd

Please sign in to comment.