aboutsummaryrefslogtreecommitdiff
path: root/src/compat/moulconfig/java/ProcessedEditableOptionFirm.kt
blob: e1ad21791c2f693a4b04c9245c7e944278e0933b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
package moe.nea.firmament.compat.moulconfig

import io.github.notenoughupdates.moulconfig.Config
import io.github.notenoughupdates.moulconfig.common.text.StructuredText
import io.github.notenoughupdates.moulconfig.platform.MoulConfigPlatform
import moe.nea.firmament.gui.config.ManagedOption
import moe.nea.firmament.util.ErrorUtil

abstract class ProcessedEditableOptionFirm<T : Any>(
	val managedOption: ManagedOption<T>,
	categoryAccordionId: Int,
	configObject: Config,
) : ProcessedOptionFirm(categoryAccordionId, configObject) {
	val managedConfig = managedOption.element
	override fun getDebugDeclarationLocation(): String {
		return "FirmamentOption:${managedConfig.name}:${managedOption.propertyName}"
	}

	override fun getName(): StructuredText {
		return MoulConfigPlatform.wrap(managedOption.labelText)
	}

	override fun getDescription(): StructuredText {
		return MoulConfigPlatform.wrap(managedOption.labelDescription)
	}

	abstract fun fromT(t: T): Any
	abstract fun toT(any: Any?): T?

	final override fun get(): Any {
		return fromT(managedOption.value)
	}

	final override fun set(p0: Any?): Boolean {
		managedOption.value = toT(p0) ?: run {
			ErrorUtil.softError("Failed to set value p0 in $this")
			return false
		}
		managedConfig.markDirty()
		return true
	}

	override fun explicitNotifyChange() {
		managedConfig.markDirty()
	}
}