diff options
author | Linnea Gräf <nea@nea.moe> | 2024-01-15 00:32:43 +0100 |
---|---|---|
committer | Linnea Gräf <nea@nea.moe> | 2024-01-17 21:10:51 +0100 |
commit | ac151c8ebc4c5546795cdbf5b0c179183e2c71d1 (patch) | |
tree | 52141110008ba6809d0dde5bc4456fc37e6a665a /src/main/kotlin/moe/nea/firmament/util/MoulConfigUtils.kt | |
parent | c49b65835d37266508561e60782bda36275fb8ae (diff) | |
download | firmament-ac151c8ebc4c5546795cdbf5b0c179183e2c71d1.tar.gz firmament-ac151c8ebc4c5546795cdbf5b0c179183e2c71d1.tar.bz2 firmament-ac151c8ebc4c5546795cdbf5b0c179183e2c71d1.zip |
Add Pristine Profit Tracker
Diffstat (limited to 'src/main/kotlin/moe/nea/firmament/util/MoulConfigUtils.kt')
-rw-r--r-- | src/main/kotlin/moe/nea/firmament/util/MoulConfigUtils.kt | 52 |
1 files changed, 51 insertions, 1 deletions
diff --git a/src/main/kotlin/moe/nea/firmament/util/MoulConfigUtils.kt b/src/main/kotlin/moe/nea/firmament/util/MoulConfigUtils.kt index bea3bc6..9ca0a73 100644 --- a/src/main/kotlin/moe/nea/firmament/util/MoulConfigUtils.kt +++ b/src/main/kotlin/moe/nea/firmament/util/MoulConfigUtils.kt @@ -8,10 +8,60 @@ package moe.nea.firmament.util import io.github.moulberry.moulconfig.common.MyResourceLocation import io.github.moulberry.moulconfig.gui.GuiContext +import io.github.moulberry.moulconfig.xml.ChildCount +import io.github.moulberry.moulconfig.xml.XMLContext +import io.github.moulberry.moulconfig.xml.XMLGuiLoader import io.github.moulberry.moulconfig.xml.XMLUniverse +import javax.xml.namespace.QName +import me.shedaniel.math.Color +import org.w3c.dom.Element +import moe.nea.firmament.gui.BarComponent object MoulConfigUtils { - val universe = XMLUniverse.getDefaultUniverse() + val firmUrl = "http://nea.moe/Firmament" + val universe = XMLUniverse.getDefaultUniverse().also { uni -> + uni.registerMapper(java.awt.Color::class.java) { + if (it.startsWith("#")) { + val hexString = it.substring(1) + val hex = hexString.toInt(16) + if (hexString.length == 6) { + return@registerMapper java.awt.Color(hex) + } + if (hexString.length == 8) { + return@registerMapper java.awt.Color(hex, true) + } + error("Hexcolor $it needs to be exactly 6 or 8 hex digits long") + } + return@registerMapper java.awt.Color(it.toInt(), true) + } + uni.registerMapper(Color::class.java) { + val color = uni.mapXMLObject(it, java.awt.Color::class.java) + Color.ofRGBA(color.red, color.green, color.blue, color.alpha) + } + uni.registerLoader(object : XMLGuiLoader<BarComponent> { + override fun getName(): QName { + return QName(firmUrl, "Bar") + } + + override fun createInstance(context: XMLContext<*>, element: Element): BarComponent { + return BarComponent( + context.getPropertyFromAttribute(element, QName("progress"), Double::class.java)!!, + context.getPropertyFromAttribute(element, QName("total"), Double::class.java)!!, + context.getPropertyFromAttribute(element, QName("fillColor"), Color::class.java)!!.get(), + context.getPropertyFromAttribute(element, QName("emptyColor"), Color::class.java)!!.get(), + ) + } + + override fun getChildCount(): ChildCount { + return ChildCount.NONE + } + + override fun getAttributeNames(): Map<String, Boolean> { + return mapOf("progress" to true, "total" to true, "emptyColor" to true, "fillColor" to true) + } + }) + } + fun loadGui(name: String, bindTo: Any): GuiContext { return GuiContext(universe.load(bindTo, MyResourceLocation("firmament", "gui/$name.xml"))) } |