aboutsummaryrefslogtreecommitdiff
path: root/src/main
diff options
context:
space:
mode:
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/ext/StringIdentifiable.java12
-rw-r--r--src/main/kotlin/moe/nea/firm/Codec.kt5
-rw-r--r--src/main/kotlin/moe/nea/firm/EnumRenderer.kt13
-rw-r--r--src/main/kotlin/moe/nea/firm/ManagedConfig.kt40
-rw-r--r--src/main/kotlin/moe/nea/firm/ManagedOption.kt10
-rw-r--r--src/main/kotlin/moe/nea/firm/User.kt14
6 files changed, 94 insertions, 0 deletions
diff --git a/src/main/java/ext/StringIdentifiable.java b/src/main/java/ext/StringIdentifiable.java
new file mode 100644
index 0000000..cc11c64
--- /dev/null
+++ b/src/main/java/ext/StringIdentifiable.java
@@ -0,0 +1,12 @@
+package ext;
+
+import moe.nea.firm.Codec;
+
+import java.util.function.Supplier;
+
+public interface StringIdentifiable {
+ static <E extends StringIdentifiable> Codec<E> createCodec(Supplier<E[]> supplier) {
+ return null;
+ }
+}
+
diff --git a/src/main/kotlin/moe/nea/firm/Codec.kt b/src/main/kotlin/moe/nea/firm/Codec.kt
new file mode 100644
index 0000000..1c19de4
--- /dev/null
+++ b/src/main/kotlin/moe/nea/firm/Codec.kt
@@ -0,0 +1,5 @@
+package moe.nea.firm
+
+interface Codec<T> {
+
+}
diff --git a/src/main/kotlin/moe/nea/firm/EnumRenderer.kt b/src/main/kotlin/moe/nea/firm/EnumRenderer.kt
new file mode 100644
index 0000000..3ffd6d3
--- /dev/null
+++ b/src/main/kotlin/moe/nea/firm/EnumRenderer.kt
@@ -0,0 +1,13 @@
+package moe.nea.firm
+
+interface EnumRenderer<E: Any> {
+ fun getName(option: ManagedOption<E>, value: E): String
+ companion object {
+ fun <E: Enum<E>> default() = object: EnumRenderer<E> {
+ override fun getName(option: ManagedOption<E>, value: E): String {
+ return value.name.lowercase()
+ }
+
+ }
+ }
+} \ No newline at end of file
diff --git a/src/main/kotlin/moe/nea/firm/ManagedConfig.kt b/src/main/kotlin/moe/nea/firm/ManagedConfig.kt
new file mode 100644
index 0000000..87d35cc
--- /dev/null
+++ b/src/main/kotlin/moe/nea/firm/ManagedConfig.kt
@@ -0,0 +1,40 @@
+package moe.nea.firm
+
+import ext.StringIdentifiable
+import kotlin.enums.enumEntries
+
+
+abstract class ManagedConfig(val identifier: String) {
+ protected fun <T : Any> option(
+ propertyName: String,
+ default: () -> T,
+// handler: OptionHandler<T>
+ ): ManagedOption<T> {
+ return TODO()
+ }
+
+ protected fun <E : Any> choice(
+ propertyName: String,
+ universe: List<E>,
+ codec: Codec<E>,
+ renderer: EnumRenderer<E>,
+ default: () -> E
+ ): ManagedOption<E> {
+ return option(propertyName, default,
+// ChoiceHandler(universe, codec, renderer)
+ )
+ }
+
+ protected inline fun <reified E> choice(
+ propertyName: String,
+ noinline default: () -> E
+ ): ManagedOption<E> where E : Enum<E>, E : StringIdentifiable {
+ return choice(
+ propertyName,
+ enumEntries<E>().toList(),
+ StringIdentifiable.createCodec { enumValues<E>() },
+ EnumRenderer.default(),
+ default
+ )
+ }
+}
diff --git a/src/main/kotlin/moe/nea/firm/ManagedOption.kt b/src/main/kotlin/moe/nea/firm/ManagedOption.kt
new file mode 100644
index 0000000..d51d693
--- /dev/null
+++ b/src/main/kotlin/moe/nea/firm/ManagedOption.kt
@@ -0,0 +1,10 @@
+package moe.nea.firm
+
+import kotlin.properties.ReadOnlyProperty
+import kotlin.reflect.KProperty
+
+class ManagedOption<T : Any> : ReadOnlyProperty<Any?, T> {
+ override fun getValue(thisRef: Any?, property: KProperty<*>): T {
+ return TODO()
+ }
+}
diff --git a/src/main/kotlin/moe/nea/firm/User.kt b/src/main/kotlin/moe/nea/firm/User.kt
new file mode 100644
index 0000000..4dfac0d
--- /dev/null
+++ b/src/main/kotlin/moe/nea/firm/User.kt
@@ -0,0 +1,14 @@
+package moe.nea.firm
+
+import ext.StringIdentifiable
+
+object User : ManagedConfig("test") {
+ val option by choice("name") { TestEnum.A }
+
+ enum class TestEnum : StringIdentifiable {
+ A, B, C;
+ }
+}
+fun main() {
+ User.option
+} \ No newline at end of file