rename data model, and experiment with K-mmp classes
This commit is contained in:
parent
3a33062cd4
commit
8e94a20a79
6 changed files with 167 additions and 8 deletions
|
|
@ -1,8 +0,0 @@
|
|||
plugins {
|
||||
id("dev.adamko.factoriowebmap.archetype.kotlin-js")
|
||||
}
|
||||
|
||||
val projectId: String by project.extra
|
||||
val buildDir: Directory = layout.buildDirectory.dir(projectId).get()
|
||||
val nodeModulesDir: Directory by project.extra
|
||||
|
||||
46
modules/factorio-events-data-model/build.gradle.kts
Normal file
46
modules/factorio-events-data-model/build.gradle.kts
Normal file
|
|
@ -0,0 +1,46 @@
|
|||
plugins {
|
||||
id("dev.adamko.factoriowebmap.archetype.base")
|
||||
kotlin("multiplatform")
|
||||
}
|
||||
|
||||
val projectId: String by project.extra
|
||||
val buildDir: Directory = layout.buildDirectory.dir(projectId).get()
|
||||
val nodeModulesDir: Directory by project.extra
|
||||
|
||||
kotlin {
|
||||
|
||||
js(IR) {
|
||||
binaries.executable()
|
||||
// browser {
|
||||
// commonWebpackConfig {
|
||||
// cssSupport.enabled = true
|
||||
// }
|
||||
// }
|
||||
|
||||
nodejs()
|
||||
useCommonJs()
|
||||
|
||||
compilations["main"].apply {
|
||||
packageJson {
|
||||
customField(
|
||||
"scripts",
|
||||
mapOf(
|
||||
"build" to "tstl",
|
||||
"dev" to "tstl --watch",
|
||||
)
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
jvm {
|
||||
compilations.all {
|
||||
kotlinOptions.jvmTarget = "11"
|
||||
}
|
||||
testRuns["test"].executionTask.configure {
|
||||
useJUnitPlatform()
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,63 @@
|
|||
package dev.adamko.factorioevents.model
|
||||
|
||||
import kotlin.js.JsExport
|
||||
import kotlin.jvm.JvmInline
|
||||
|
||||
//expect sealed interface JsonPrimitive {
|
||||
// value class JsonString(val string: String) : JsonPrimitive
|
||||
// value class JsonNumber(val number: Number) : JsonPrimitive
|
||||
// value class JsonBoolean(val boolean: Boolean) : JsonPrimitive
|
||||
//}
|
||||
|
||||
sealed interface JsonPrimitive {
|
||||
@JvmInline
|
||||
value class JsonString(val string: String) : JsonPrimitive
|
||||
@JvmInline
|
||||
value class JsonNumber(val number: Number) : JsonPrimitive
|
||||
@JvmInline
|
||||
value class JsonBoolean(val boolean: Boolean) : JsonPrimitive
|
||||
}
|
||||
|
||||
class JsonArray<T : JsonPrimitive?>(
|
||||
private val list: MutableList<T> = mutableListOf()
|
||||
) : MutableList<T> by list
|
||||
|
||||
|
||||
sealed interface JsonTableValue {
|
||||
@JvmInline
|
||||
value class JsonPrimitiveTV(val primitive: JsonPrimitive) : JsonTableValue
|
||||
@JvmInline
|
||||
value class JsonArrayTV<T : JsonPrimitive?>(val array: JsonArray<T>) : JsonTableValue
|
||||
@JvmInline
|
||||
value class JsonTableTV<T : JsonTable?>(val array: JsonTable) : JsonTableValue
|
||||
}
|
||||
|
||||
//expect class JsonNumber() : JsonPrimitiveType
|
||||
|
||||
//expect class JsonArray<T : JsonPrimitive?>
|
||||
|
||||
//expect open class JsonTable<K : JsonPrimitive.JsonString, V : JsonTableValue?>
|
||||
|
||||
open class JsonTable(
|
||||
protected val map: MutableMap<JsonPrimitive.JsonString, JsonTableValue?> = mutableMapOf()
|
||||
) : MutableMap<JsonPrimitive.JsonString, JsonTableValue?> by map {
|
||||
|
||||
inline fun <reified T> get2(key: String): T? {
|
||||
|
||||
val jKey = JsonPrimitive.JsonString(key)
|
||||
|
||||
return when {
|
||||
T::class is Number -> ((get(jKey) as? JsonTableValue.JsonPrimitiveTV)?.primitive as? JsonPrimitive.JsonNumber)?.number as? T
|
||||
else -> return get(jKey) as? T
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//@JsExport
|
||||
class FactorioEvent : JsonTable() {
|
||||
val tick: UInt?
|
||||
get() = get2("tick")
|
||||
// set(value) = map.put("tick", value)
|
||||
}
|
||||
|
|
@ -0,0 +1,31 @@
|
|||
package dev.adamko.factorioevents.model
|
||||
|
||||
|
||||
//actual sealed interface JsonPrimitive {
|
||||
// actual value class JsonString(val string: String) : JsonPrimitive
|
||||
// actual value class JsonNumber(val number: Number) : JsonPrimitive
|
||||
// actual value class JsonBoolean(val boolean: Boolean) : JsonPrimitive
|
||||
//}
|
||||
|
||||
//actual class JsonArray<T : JsonPrimitive?>(
|
||||
// private val list: MutableList<T> = mutableListOf()
|
||||
//) : MutableList<T> by list
|
||||
|
||||
//actual sealed interface JsonTableValue {
|
||||
// actual value class JsonPrimitiveTV(val primitive: JsonPrimitive) : JsonTableValue
|
||||
// actual value class JsonArrayTV<T : JsonPrimitive?>(val array: JsonArray<T>) : JsonTableValue
|
||||
//}
|
||||
|
||||
|
||||
//actual open class JsonTable<K : JsonPrimitive.JsonString, V: JsonTableValue?>(
|
||||
// private val map: MutableMap<K, V> = mutableMapOf()
|
||||
//) : MutableMap<K, V> by map
|
||||
|
||||
|
||||
fun printMap() {
|
||||
val f = JsonPrimitive.JsonString("test")
|
||||
|
||||
println(f.string)
|
||||
println(f)
|
||||
|
||||
}
|
||||
|
|
@ -0,0 +1,27 @@
|
|||
package dev.adamko.factorioevents.model
|
||||
|
||||
|
||||
//actual sealed interface JsonPrimitive {
|
||||
// @JvmInline
|
||||
// actual value class JsonString(val string: String) : JsonPrimitive
|
||||
// @JvmInline
|
||||
// actual value class JsonNumber(val number: Number) : JsonPrimitive
|
||||
// @JvmInline
|
||||
// actual value class JsonBoolean(val boolean: Boolean) : JsonPrimitive
|
||||
//}
|
||||
|
||||
//actual class JsonArray<T : JsonPrimitive?>(
|
||||
// private val list: MutableList<T> = mutableListOf()
|
||||
//) : MutableList<T> by list
|
||||
|
||||
//actual sealed interface JsonTableValue {
|
||||
// @JvmInline
|
||||
// actual value class JsonPrimitiveTV(val primitive: JsonPrimitive) : JsonTableValue
|
||||
// @JvmInline
|
||||
// actual value class JsonArrayTV<T : JsonPrimitive?>(val array: JsonArray<T>) : JsonTableValue
|
||||
//}
|
||||
|
||||
//actual open class JsonTable<K : JsonPrimitive.JsonString, V: JsonTableValue?>(
|
||||
// private val map: MutableMap<K, V> = mutableMapOf()
|
||||
//) : MutableMap<K, V> by map
|
||||
|
||||
Loading…
Add table
Add a link
Reference in a new issue