From 11e80f14286242fb2651abd2eb8d557e4d357957 Mon Sep 17 00:00:00 2001 From: 0ffz Date: Fri, 23 Dec 2022 01:42:30 -0500 Subject: [PATCH] Finalizing addon system, figuring out I/O on multiplatform --- geary-autoscan/build.gradle.kts | 1 + .../geary/autoscan/AutoScanAddon.kt | 139 ------------------ .../mineinabyss/geary/autoscan/AutoScanner.kt | 49 ++++++ .../geary/autoscan/AutoScannerDSL.kt | 85 +++++++++++ .../mineinabyss/geary/addons/Namespaced.kt | 6 +- .../mineinabyss/geary/addons/dsl/Aliases.kt | 2 +- .../geary/addons/dsl/GearyAddon.kt | 50 +------ .../dsl/{GearyDSLMarker.kt => GearyDSL.kt} | 2 +- .../geary/helpers/EngineHelpers.kt | 5 - .../mineinabyss/geary/modules/GearyModule.kt | 33 ++++- geary-prefabs/build.gradle.kts | 1 + .../mineinabyss/geary/prefabs/PrefabKey.kt | 1 - .../mineinabyss/geary/prefabs/PrefabLoader.kt | 15 +- .../geary/prefabs/PrefabManager.kt | 19 --- .../com/mineinabyss/geary/prefabs/Prefabs.kt | 22 ++- .../geary/prefabs/PrefabsConfiguration.kt | 26 ---- .../mineinabyss/geary/prefabs/PrefabsDSL.kt | 28 ++++ .../configuration/components/ChildOnPrefab.kt | 1 + .../components/ChildrenOnPrefab.kt | 1 + .../components/CopyToInstances.kt | 4 +- .../geary/prefabs/events/PrefabLoaded.kt | 2 +- .../geary/prefabs/modules/PrefabModule.kt | 14 -- geary-serialization/build.gradle.kts | 3 + .../serialization/SerializableComponents.kt | 84 ++++------- .../SerializableComponentsDSL.kt | 64 ++++++++ .../SerializableComponentsModule.kt | 11 -- .../serialization/formats/SimpleFormats.kt | 4 +- .../serialization/formats/YamlFormat.kt | 1 + platforms/papermc/build.gradle.kts | 1 + .../geary/papermc/plugin/GearyPluginImpl.kt | 38 +++-- 30 files changed, 345 insertions(+), 367 deletions(-) delete mode 100644 geary-autoscan/src/main/kotlin/com/mineinabyss/geary/autoscan/AutoScanAddon.kt create mode 100644 geary-autoscan/src/main/kotlin/com/mineinabyss/geary/autoscan/AutoScanner.kt create mode 100644 geary-autoscan/src/main/kotlin/com/mineinabyss/geary/autoscan/AutoScannerDSL.kt rename geary-core/src/commonMain/kotlin/com/mineinabyss/geary/addons/dsl/{GearyDSLMarker.kt => GearyDSL.kt} (86%) delete mode 100644 geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/PrefabsConfiguration.kt create mode 100644 geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/PrefabsDSL.kt delete mode 100644 geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/modules/PrefabModule.kt create mode 100644 geary-serialization/src/commonMain/kotlin/com/mineinabyss/geary/serialization/SerializableComponentsDSL.kt delete mode 100644 geary-serialization/src/commonMain/kotlin/com/mineinabyss/geary/serialization/SerializableComponentsModule.kt diff --git a/geary-autoscan/build.gradle.kts b/geary-autoscan/build.gradle.kts index 5122709a7..e1150fe5c 100644 --- a/geary-autoscan/build.gradle.kts +++ b/geary-autoscan/build.gradle.kts @@ -11,5 +11,6 @@ dependencies { implementation("com.mineinabyss:ding:1.0.0") compileOnly(libs.idofront.autoscan) compileOnly(project(":geary-core")) + compileOnly(project(":geary-serialization")) // compileOnly(project(":geary-prefabs")) } diff --git a/geary-autoscan/src/main/kotlin/com/mineinabyss/geary/autoscan/AutoScanAddon.kt b/geary-autoscan/src/main/kotlin/com/mineinabyss/geary/autoscan/AutoScanAddon.kt deleted file mode 100644 index d7874a901..000000000 --- a/geary-autoscan/src/main/kotlin/com/mineinabyss/geary/autoscan/AutoScanAddon.kt +++ /dev/null @@ -1,139 +0,0 @@ -package com.mineinabyss.geary.autoscan - -import com.mineinabyss.geary.addons.Namespaced -import com.mineinabyss.geary.addons.dsl.* -import com.mineinabyss.geary.addons.SerializationAddon -import com.mineinabyss.geary.datatypes.Component -import com.mineinabyss.geary.modules.GearyConfiguration -import com.mineinabyss.geary.modules.GearyModule -import com.mineinabyss.geary.modules.geary -import com.mineinabyss.geary.prefabs.PrefabKey -import com.mineinabyss.geary.systems.GearySystem -import com.mineinabyss.idofront.autoscan.AutoScanner -import kotlinx.serialization.InternalSerializationApi -import kotlinx.serialization.Serializable -import kotlinx.serialization.modules.polymorphic -import kotlinx.serialization.serializerOrNull -import org.reflections.Reflections -import org.reflections.util.ClasspathHelper -import org.reflections.util.ConfigurationBuilder -import kotlin.reflect.KClass -import kotlin.reflect.full.createInstance -import kotlin.reflect.full.hasAnnotation -import kotlin.reflect.full.isSubclassOf - -class AutoScanAddon( - pkg: String, - private val serializationAddon: SerializationAddon, -) { - private val logger get() = geary.logger - - @PublishedApi - internal val reflections: Reflections by lazy { - Reflections( - ConfigurationBuilder() - .addClassLoader(gearyAddon.classLoader) - .addUrls(ClasspathHelper.forPackage(pkg, gearyAddon.classLoader)) - ) - } - - /** - * Automatically scans for all annotated components - * - * @see autoScanComponents - * @see autoScanSystems - */ - fun Namespaced.all() { - components() - systems() - } - - /** - * Registers serializers for [Component]s on the classpath of [plugin]'s [ClassLoader]. - * - * @see AutoScanner - */ - fun Namespaced.components(): Unit = with(serializationAddon) { - reflections.getTypesAnnotatedWith(Serializable::class.java) - ?.registerSerializers(Component::class) { kClass, serializer -> - val serialName = serializer?.descriptor?.serialName ?: return@registerSerializers false - PrefabKey.ofOrNull(serialName) ?: return@registerSerializers false - component(kClass, serializer) - } - } - - /** - * Registers any systems (including event listeners) that are annotated with [AutoScanAddon]. - * - * Supports singletons or classes with no constructor parameters. - * - * @see AutoScanner - */ - fun systems(): Unit = with(serializationAddon) { - reflections - .getTypesAnnotatedWith(AutoScanAddon::class.java) - ?.asSequence() - ?.map { it.kotlin } - ?.filter { it.isSubclassOf(GearySystem::class) } - ?.mapNotNull { it.objectInstance ?: runCatching { it.createInstance() }.getOrNull() } - ?.filterIsInstance() - ?.toList() // Inline so we can use suspending function - ?.onEach { gearyAddon.system(it) } - ?.map { it::class.simpleName } - ?.joinToString() - ?.let { logger.info("Autoscan loaded singleton systems: $it") } - } - - /** - * Registers serializers for any type [T] on the classpath of [plugin]'s [ClassLoader]. - * - * @see AutoScanner - */ - inline fun custom( - noinline addSubclass: SerializerRegistry = { kClass, serializer -> - if (serializer != null) - subclass(kClass, serializer) - serializer != null - } - ) { - reflections.getSubTypesOf(T::class.java)?.registerSerializers(T::class, addSubclass) - } - - /** Helper function to register serializers via scanning for geary classes. */ - @OptIn(InternalSerializationApi::class) - fun Collection>.registerSerializers( - kClass: KClass, - addSubclass: SerializerRegistry = { subClass, serializer -> - if (serializer != null) - subclass(subClass, serializer) - serializer != null - }, - ): Unit = with(serializationAddon) { - module { - polymorphic(kClass) { - asSequence().map { it.kotlin } - .filter { !it.hasAnnotation() } - .filterIsInstance>() - .filter { kClass -> - runCatching { - this@polymorphic.addSubclass(kClass, kClass.serializerOrNull()) - }.onFailure { logger.severe("Failed to load serializer for class ${kClass.simpleName}") } - .getOrThrow() - } - .map { it.simpleName } - .joinToString() - .also { logger.info("Autoscan loaded serializers for class ${kClass.simpleName}: $it") } - } - } - } - - companion object Addon : GearyAddon { - override fun install(geary: GearyModule): AutoScanAddon { - AutoScanAddon() - } - - } -} - -@GearyDSLMarker -fun GearyConfiguration.autoscan(configure: AutoScanAddon.() -> Unit) = install(AutoScanAddon, configure) diff --git a/geary-autoscan/src/main/kotlin/com/mineinabyss/geary/autoscan/AutoScanner.kt b/geary-autoscan/src/main/kotlin/com/mineinabyss/geary/autoscan/AutoScanner.kt new file mode 100644 index 000000000..9badc2c35 --- /dev/null +++ b/geary-autoscan/src/main/kotlin/com/mineinabyss/geary/autoscan/AutoScanner.kt @@ -0,0 +1,49 @@ +package com.mineinabyss.geary.autoscan + +import com.mineinabyss.ding.DI +import com.mineinabyss.geary.addons.GearyPhase +import com.mineinabyss.geary.addons.Namespaced +import com.mineinabyss.geary.addons.dsl.GearyAddon +import com.mineinabyss.geary.addons.dsl.GearyAddonWithDefault +import com.mineinabyss.geary.addons.dsl.GearyDSL +import com.mineinabyss.geary.modules.geary +import com.mineinabyss.geary.systems.System +import kotlin.reflect.KClass +import kotlin.reflect.full.createInstance + +val autoScanner by DI.observe() + +interface AutoScanner { + val scannedComponents: MutableSet> + val scannedSystems: MutableSet> + + fun installSystems() + + companion object Addon : GearyAddonWithDefault { + override fun default() = object : AutoScanner { + private val logger = geary.logger + override val scannedComponents = mutableSetOf>() + override val scannedSystems = mutableSetOf>() + + override fun installSystems() { + scannedSystems.asSequence() + .mapNotNull { it.objectInstance ?: runCatching { it.createInstance() }.getOrNull() } + .filterIsInstance() + .onEach { geary.systems.add(it) } + .map { it::class.simpleName } + .joinToString() + .let { logger.i("Autoscan loaded singleton systems: $it") } + } + } + + override fun AutoScanner.install() { + geary.pipeline.intercept(GearyPhase.INIT_SYSTEMS) { + installSystems() + } + } + } +} + +@GearyDSL +fun Namespaced.autoscan(vararg limitToPackages: String, configure: AutoScannerDSL.() -> Unit) = + gearyConf.install(AutoScanner).also { AutoScannerDSL(this, limitToPackages.toList()).configure() } diff --git a/geary-autoscan/src/main/kotlin/com/mineinabyss/geary/autoscan/AutoScannerDSL.kt b/geary-autoscan/src/main/kotlin/com/mineinabyss/geary/autoscan/AutoScannerDSL.kt new file mode 100644 index 000000000..6d17a0d40 --- /dev/null +++ b/geary-autoscan/src/main/kotlin/com/mineinabyss/geary/autoscan/AutoScannerDSL.kt @@ -0,0 +1,85 @@ +package com.mineinabyss.geary.autoscan + +import com.mineinabyss.geary.addons.Namespaced +import com.mineinabyss.geary.datatypes.Component +import com.mineinabyss.geary.modules.geary +import com.mineinabyss.geary.serialization.serialization +import com.mineinabyss.geary.systems.System +import kotlinx.serialization.* +import kotlinx.serialization.modules.PolymorphicModuleBuilder +import org.reflections.Reflections +import org.reflections.util.ClasspathHelper +import org.reflections.util.ConfigurationBuilder +import kotlin.reflect.KClass +import kotlin.reflect.full.hasAnnotation +import kotlin.reflect.full.isSubclassOf + +class AutoScannerDSL( + val namespaced: Namespaced, + val limitTo: List +) { + val logger = geary.logger + + private val reflections: Reflections by lazy { + Reflections( + ConfigurationBuilder() + .addClassLoader(namespaced.currentClass.java.classLoader) + .apply { + limitTo.forEach { pkg -> + addUrls(ClasspathHelper.forPackage(pkg, namespaced.currentClass.java.classLoader)) + } + } + ) + } + + /** + * Automatically scans for all annotated components + * + * @see autoScanComponents + * @see autoScanSystems + */ + fun all() { + components() + systems() + } + + /** + * Registers serializers for [Component]s. + * + * @see AutoScanner + */ + fun components() { + val scanned = reflections + .getTypesAnnotatedWith(Serializable::class.java) + .asSequence() + .map { it.kotlin } + .filter { !it.hasAnnotation() } + + geary { + namespaced.serialization { + components { + scanned.forEach { component(it) } + } + } + } + logger.i("Autoscan found components: ${scanned.joinToString { it.simpleName!! }}") + + autoScanner.scannedComponents += scanned + } + + /** + * Registers any systems (including event listeners) that are annotated with [AutoScanner]. + * + * Supports singletons or classes with no constructor parameters. + * + * @see AutoScanner + */ + fun systems() { + val scanned = reflections.getTypesAnnotatedWith(AutoScan::class.java) + .asSequence() + .map { it.kotlin } + .filter { !it.hasAnnotation() && it.isSubclassOf(System::class) } + + autoScanner.scannedSystems += scanned + } +} diff --git a/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/addons/Namespaced.kt b/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/addons/Namespaced.kt index b5a722465..23d9d1e9a 100644 --- a/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/addons/Namespaced.kt +++ b/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/addons/Namespaced.kt @@ -1,6 +1,10 @@ package com.mineinabyss.geary.addons +import com.mineinabyss.geary.addons.dsl.GearyDSL +import com.mineinabyss.geary.modules.GearyConfiguration import com.mineinabyss.geary.modules.GearyModule +import kotlin.reflect.KClass -class Namespaced(val namespace: String) +@GearyDSL +class Namespaced(val namespace: String, val currentClass: KClass<*>, val gearyConf: GearyConfiguration) diff --git a/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/addons/dsl/Aliases.kt b/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/addons/dsl/Aliases.kt index e625c76e3..47eda1a5c 100644 --- a/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/addons/dsl/Aliases.kt +++ b/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/addons/dsl/Aliases.kt @@ -5,4 +5,4 @@ import kotlinx.serialization.modules.PolymorphicModuleBuilder import kotlin.reflect.KClass /** The polymorphic builder scope that allows registering subclasses. */ -typealias SerializerRegistry = PolymorphicModuleBuilder.(kClass: KClass, serializer: KSerializer?) -> Boolean +typealias SerializerRegistry = PolymorphicModuleBuilder.(kClass: KClass, serializer: KSerializer?) -> Unit diff --git a/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/addons/dsl/GearyAddon.kt b/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/addons/dsl/GearyAddon.kt index 4dd078b71..ccdb6ecb8 100644 --- a/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/addons/dsl/GearyAddon.kt +++ b/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/addons/dsl/GearyAddon.kt @@ -1,49 +1,9 @@ package com.mineinabyss.geary.addons.dsl -import com.mineinabyss.geary.modules.GearyModule - -/** - * The entry point for other plugins to hook into Geary. Allows registering serializable components, systems, actions, - * and more. - */ -//@GearyDSLMarker -//class GearyAddon( -// val namespace: String, -// val classLoader: ClassLoader -//) : GearyDSL { -// -// override fun system(system: GearySystem) { -// geary.systems.add(system) -// } -// -// override fun systems(vararg systems: GearySystem) { -// systems.forEach { system(it) } -// } -// -// override fun serialization(init: SerializationAddon.() -> Unit) = on(GearyLoadPhase.REGISTER_SERIALIZERS) { -// SerializationAddon(this@GearyAddon).init() -// } -// -// override fun formats(init: Formats.(SerializersModule) -> Unit) = on(GearyLoadPhase.REGISTER_FORMATS) { -// geary.formats.init(geary.serializers.module) -// } -// -// /** -// * Allows defining actions that should run at a specific phase during startup -// * -// * Within its context, invoke a [GearyLoadPhase] to run something during it, ex: -// * -// * ``` -// * GearyLoadPhase.ENABLE { -// * // run code here -// * } -// * ``` -// */ -// override fun on(phase: GearyLoadPhase, run: () -> Unit) { -// addons.manager.add(phase, run) -// } -//} -interface GearyAddon { +interface GearyAddonWithDefault: GearyAddon { fun default(): Module - fun Module.install(geary: GearyModule) +} + +interface GearyAddon { + fun Module.install() } diff --git a/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/addons/dsl/GearyDSLMarker.kt b/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/addons/dsl/GearyDSL.kt similarity index 86% rename from geary-core/src/commonMain/kotlin/com/mineinabyss/geary/addons/dsl/GearyDSLMarker.kt rename to geary-core/src/commonMain/kotlin/com/mineinabyss/geary/addons/dsl/GearyDSL.kt index 2f84975ad..1f981eff5 100644 --- a/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/addons/dsl/GearyDSLMarker.kt +++ b/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/addons/dsl/GearyDSL.kt @@ -5,4 +5,4 @@ package com.mineinabyss.geary.addons.dsl */ @DslMarker @Target(AnnotationTarget.CLASS, AnnotationTarget.TYPEALIAS, AnnotationTarget.TYPE, AnnotationTarget.FUNCTION) -annotation class GearyDSLMarker +annotation class GearyDSL diff --git a/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/helpers/EngineHelpers.kt b/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/helpers/EngineHelpers.kt index 96f17649d..02bd5ceb3 100644 --- a/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/helpers/EngineHelpers.kt +++ b/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/helpers/EngineHelpers.kt @@ -66,11 +66,6 @@ fun componentId(kClass: KClass): Nothing = /** Gets the [ComponentInfo] component from a component's id. */ fun ComponentId.getComponentInfo(): ComponentInfo? = this.toGeary().get() - -fun systems(vararg systems: GearySystem): List> { - return systems.map { geary.engine.async { geary.systems.add(it) } } -} - //@ExperimentalAsyncGearyAPI //public inline fun runSafely( // scope: CoroutineScope = globalContext.engine, diff --git a/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/modules/GearyModule.kt b/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/modules/GearyModule.kt index e3fb151b2..74e19d53c 100644 --- a/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/modules/GearyModule.kt +++ b/geary-core/src/commonMain/kotlin/com/mineinabyss/geary/modules/GearyModule.kt @@ -2,15 +2,16 @@ package com.mineinabyss.geary.modules import co.touchlab.kermit.Logger import com.mineinabyss.ding.DI -import com.mineinabyss.ding.DIContext +import com.mineinabyss.geary.addons.GearyPhase import com.mineinabyss.geary.addons.Namespaced import com.mineinabyss.geary.addons.dsl.GearyAddon -import com.mineinabyss.geary.addons.dsl.GearyDSLMarker +import com.mineinabyss.geary.addons.dsl.GearyAddonWithDefault +import com.mineinabyss.geary.addons.dsl.GearyDSL import com.mineinabyss.geary.engine.* val geary: GearyModule by DI.observe() -@GearyDSLMarker +@GearyDSL interface GearyModule { val logger: Logger val entityProvider: EntityProvider @@ -25,7 +26,6 @@ interface GearyModule { val engine: Engine val eventRunner: EventRunner - val addons: DIContext val pipeline: Pipeline fun inject() @@ -37,8 +37,29 @@ interface GearyModule { fun geary(configure: GearyConfiguration.() -> Unit) { } +@GearyDSL interface GearyConfiguration { - fun , Module, Conf> install(addon: T, configure: Conf.() -> Unit = {}) + fun , Module> install( + addon: T, + ) = install(addon, addon.default()) - fun namespace(namespace: String, configure: Namespaced.() -> Unit) = Namespaced(namespace).configure() + fun , Module> install( + addon: T, + module: Module, + ) + + fun namespace(namespace: String, configure: Namespaced.() -> Unit) = Namespaced(namespace, TODO(), this).configure() + + /** + * Allows defining actions that should run at a specific phase during startup + * + * Within its context, invoke a [GearyPhase] to run something during it, ex: + * + * ``` + * GearyLoadPhase.ENABLE { + * // run code here + * } + * ``` + */ + fun on(phase: GearyPhase, run: () -> Unit) } diff --git a/geary-prefabs/build.gradle.kts b/geary-prefabs/build.gradle.kts index 5ff516960..840de89b0 100644 --- a/geary-prefabs/build.gradle.kts +++ b/geary-prefabs/build.gradle.kts @@ -13,6 +13,7 @@ kotlin { commonMain { dependencies { compileOnly(mylibs.okio) + compileOnly(mylibs.uuid) compileOnly(libs.kotlinx.serialization.json) compileOnly(libs.kotlinx.serialization.cbor) diff --git a/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/PrefabKey.kt b/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/PrefabKey.kt index 44cf28a25..f5b0e119d 100644 --- a/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/PrefabKey.kt +++ b/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/PrefabKey.kt @@ -1,7 +1,6 @@ package com.mineinabyss.geary.prefabs import com.mineinabyss.geary.datatypes.Entity -import com.mineinabyss.geary.prefabs.modules.prefabs import com.mineinabyss.geary.prefabs.serializers.PrefabKeySerializer import kotlinx.serialization.Serializable diff --git a/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/PrefabLoader.kt b/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/PrefabLoader.kt index fddba2b62..511032cc7 100644 --- a/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/PrefabLoader.kt +++ b/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/PrefabLoader.kt @@ -1,18 +1,24 @@ package com.mineinabyss.geary.prefabs +import com.benasher44.uuid.Uuid +import com.benasher44.uuid.uuid4 import com.mineinabyss.geary.components.relations.DontInherit +import com.mineinabyss.geary.datatypes.Component import com.mineinabyss.geary.datatypes.Entity import com.mineinabyss.geary.helpers.entity import com.mineinabyss.geary.helpers.with import com.mineinabyss.geary.modules.geary import com.mineinabyss.geary.prefabs.configuration.components.Prefab import com.mineinabyss.geary.prefabs.helpers.inheritPrefabs +import com.mineinabyss.geary.serialization.serializableComponents import kotlinx.serialization.PolymorphicSerializer import kotlinx.serialization.builtins.ListSerializer +import okio.FileSystem import okio.Path class PrefabLoader { private val manager = prefabs.manager + private val formats = serializableComponents.formats private val logger = geary.logger private val readFiles = mutableListOf() @@ -44,17 +50,18 @@ class PrefabLoader { val name = path.name return runCatching { val serializer = ListSerializer(PolymorphicSerializer(Component::class)) - val ext = path.extension - val decoded = formats[ext]?.decodeFromFile(serializer, path.toOkioPath()) + val ext = path.name.substringAfterLast('.') + + val decoded = formats[ext]?.decodeFromFile(serializer, path) ?: error("Unknown file format $ext") val entity = writeTo ?: entity() entity.set(Prefab(path)) entity.addRelation() - entity.addRelation() + entity.addRelation() entity.setAll(decoded) val key = PrefabKey.of(namespace, name) - registerPrefab(key, entity) + manager.registerPrefab(key, entity) entity }.onFailure { logger.e("Can't read prefab $name from ${path}:") diff --git a/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/PrefabManager.kt b/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/PrefabManager.kt index 4a79521bd..7000c9a7a 100644 --- a/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/PrefabManager.kt +++ b/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/PrefabManager.kt @@ -1,29 +1,11 @@ package com.mineinabyss.geary.prefabs -import com.mineinabyss.geary.components.relations.DontInherit -import com.mineinabyss.geary.modules.geary -import com.mineinabyss.geary.datatypes.Component import com.mineinabyss.geary.datatypes.Entity -import com.mineinabyss.geary.helpers.entity -import com.mineinabyss.geary.helpers.with -import com.mineinabyss.geary.prefabs.configuration.components.Prefab -import com.mineinabyss.geary.prefabs.helpers.inheritPrefabs -import com.mineinabyss.geary.serialization.serialization -import kotlinx.serialization.PolymorphicSerializer -import kotlinx.serialization.builtins.ListSerializer -import okio.Path.Companion.toOkioPath -import java.nio.file.Path -import java.util.* -import kotlin.io.path.extension -import kotlin.io.path.nameWithoutExtension /** * Manages registered prefabs and accessing them via name. */ class PrefabManager { - private val formats get() = serialization.formats - private val logger get() = geary.logger - /** A list of registered [PrefabKey]s. */ val keys: List get() = keyToPrefab.keys.toList() @@ -46,5 +28,4 @@ class PrefabManager { internal fun clear() { keyToPrefab.clear() } - } diff --git a/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/Prefabs.kt b/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/Prefabs.kt index 125a3076d..2ea7759ff 100644 --- a/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/Prefabs.kt +++ b/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/Prefabs.kt @@ -1,32 +1,30 @@ package com.mineinabyss.geary.prefabs +import com.mineinabyss.ding.DI import com.mineinabyss.geary.addons.GearyPhase -import com.mineinabyss.geary.addons.dsl.GearyAddon -import com.mineinabyss.geary.addons.dsl.GearyDSLMarker -import com.mineinabyss.geary.modules.GearyConfiguration -import com.mineinabyss.geary.modules.GearyModule +import com.mineinabyss.geary.addons.Namespaced +import com.mineinabyss.geary.addons.dsl.GearyAddonWithDefault +import com.mineinabyss.geary.addons.dsl.GearyDSL import com.mineinabyss.geary.modules.geary import com.mineinabyss.geary.prefabs.configuration.systems.ParseChildOnPrefab import com.mineinabyss.geary.prefabs.configuration.systems.ParseChildrenOnPrefab import com.mineinabyss.geary.prefabs.configuration.systems.ParseRelationOnPrefab import com.mineinabyss.geary.prefabs.configuration.systems.ParseRelationWithDataSystem -val prefabs by geary.addons.observe() +val prefabs by DI.observe() interface Prefabs { val manager: PrefabManager val loader: PrefabLoader - companion object : GearyAddon { - private val logger = geary.logger - + companion object : GearyAddonWithDefault { override fun default() = object : Prefabs { override val manager = PrefabManager() override val loader: PrefabLoader = PrefabLoader() } - override fun Prefabs.install(geary: GearyModule) { + override fun Prefabs.install() { geary.systems.add( ParseChildOnPrefab(), ParseChildrenOnPrefab(), @@ -40,6 +38,6 @@ interface Prefabs { } } -@GearyDSLMarker -fun GearyConfiguration.prefabs(configure: Prefabs.() -> Unit) = - install(Prefabs, configure) +@GearyDSL +fun Namespaced.prefabs(configure: PrefabsDSL.() -> Unit) = + gearyConf.install(Prefabs).also { PrefabsDSL(this).configure() } diff --git a/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/PrefabsConfiguration.kt b/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/PrefabsConfiguration.kt deleted file mode 100644 index 3f79449f5..000000000 --- a/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/PrefabsConfiguration.kt +++ /dev/null @@ -1,26 +0,0 @@ -package com.mineinabyss.geary.prefabs - -import com.mineinabyss.geary.addons.Namespaced -import okio.Path - -class PrefabsConfiguration { - val loader = prefabs.loader - - /** Loads prefab entities from all files inside a [directory][from], into a given [namespace] */ - fun Namespaced.files( - vararg from: Path, - ) { - loader.addSource(PrefabPath(namespace) { from.asSequence() }) - } - - fun Namespaced.glob( - folder: Path, - glob: String = "**", - ) { - loader.addSource(PrefabPath(namespace) { - Files.newDirectoryStream(folder, glob) - .filter { it.isRegularFile() } - .asSequence() - }) - } -} diff --git a/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/PrefabsDSL.kt b/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/PrefabsDSL.kt new file mode 100644 index 000000000..5787dbb48 --- /dev/null +++ b/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/PrefabsDSL.kt @@ -0,0 +1,28 @@ +package com.mineinabyss.geary.prefabs + +import com.mineinabyss.geary.addons.Namespaced +import com.mineinabyss.geary.addons.dsl.GearyDSL +import com.mineinabyss.geary.serialization.serializableComponents +import okio.Path + +@GearyDSL +class PrefabsDSL( + private val namespaced: Namespaced +){ + private val loader = prefabs.loader + + /** Loads prefab entities from all files inside a [directory][from], into a given [namespace] */ + fun from( + vararg from: Path, + ) { + loader.addSource(PrefabPath(namespaced.namespace) { from.asSequence() }) + } + + fun fromRecursive(folder: Path) { + loader.addSource(PrefabPath(namespaced.namespace) { + serializableComponents.fileSystem + .listRecursively(folder, true) + .filter { it.name.endsWith(".yml") } + }) + } +} diff --git a/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/configuration/components/ChildOnPrefab.kt b/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/configuration/components/ChildOnPrefab.kt index 5b9fedeba..c9860343b 100644 --- a/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/configuration/components/ChildOnPrefab.kt +++ b/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/configuration/components/ChildOnPrefab.kt @@ -4,6 +4,7 @@ import com.mineinabyss.geary.datatypes.Component import kotlinx.serialization.Polymorphic import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +import kotlin.jvm.JvmInline /** * > geary:child diff --git a/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/configuration/components/ChildrenOnPrefab.kt b/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/configuration/components/ChildrenOnPrefab.kt index 4f37f2f15..550a08ab3 100644 --- a/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/configuration/components/ChildrenOnPrefab.kt +++ b/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/configuration/components/ChildrenOnPrefab.kt @@ -5,6 +5,7 @@ import com.mineinabyss.geary.datatypes.Component import kotlinx.serialization.Polymorphic import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +import kotlin.jvm.JvmInline /** * > geary:children diff --git a/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/configuration/components/CopyToInstances.kt b/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/configuration/components/CopyToInstances.kt index e0e83ceb2..2a55426a1 100644 --- a/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/configuration/components/CopyToInstances.kt +++ b/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/configuration/components/CopyToInstances.kt @@ -1,8 +1,8 @@ package com.mineinabyss.geary.prefabs.configuration.components -import com.mineinabyss.geary.modules.geary import com.mineinabyss.geary.datatypes.Component import com.mineinabyss.geary.datatypes.Entity +import com.mineinabyss.geary.serialization.serializableComponents import kotlinx.serialization.Polymorphic import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable @@ -22,7 +22,7 @@ data class CopyToInstances( private val temporary: Set<@Polymorphic Component> = setOf(), private val persisting: Set<@Polymorphic Component> = setOf(), ) { - val formats get() = geary.formats + val formats get() = serializableComponents.formats // This is the safest and cleanest way to deep-copy, even if a little performance intense. private val serializedComponents by lazy { formats.binaryFormat.encodeToByteArray(serializer(), this) } diff --git a/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/events/PrefabLoaded.kt b/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/events/PrefabLoaded.kt index f90b737df..f67737a8b 100644 --- a/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/events/PrefabLoaded.kt +++ b/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/events/PrefabLoaded.kt @@ -1,3 +1,3 @@ package com.mineinabyss.geary.prefabs.events -class PrefabLoaded +sealed class PrefabLoaded diff --git a/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/modules/PrefabModule.kt b/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/modules/PrefabModule.kt deleted file mode 100644 index 85de69286..000000000 --- a/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/modules/PrefabModule.kt +++ /dev/null @@ -1,14 +0,0 @@ -package com.mineinabyss.geary.prefabs.modules - -import com.mineinabyss.ding.DI -import com.mineinabyss.geary.prefabs.PrefabManager - -val prefabs: PrefabModule by DI.observe() - -interface PrefabModule { - val manager: PrefabManager - - fun inject() { - DI.add(this) - } -} diff --git a/geary-serialization/build.gradle.kts b/geary-serialization/build.gradle.kts index d38814335..642f9ab9c 100644 --- a/geary-serialization/build.gradle.kts +++ b/geary-serialization/build.gradle.kts @@ -9,6 +9,9 @@ kotlin { sourceSets { commonMain { dependencies { + compileOnly(mylibs.okio) + implementation(mylibs.uuid) + compileOnly(libs.kotlinx.serialization.json) compileOnly(libs.kotlinx.serialization.cbor) diff --git a/geary-serialization/src/commonMain/kotlin/com/mineinabyss/geary/serialization/SerializableComponents.kt b/geary-serialization/src/commonMain/kotlin/com/mineinabyss/geary/serialization/SerializableComponents.kt index d53484183..7646b03aa 100644 --- a/geary-serialization/src/commonMain/kotlin/com/mineinabyss/geary/serialization/SerializableComponents.kt +++ b/geary-serialization/src/commonMain/kotlin/com/mineinabyss/geary/serialization/SerializableComponents.kt @@ -1,67 +1,37 @@ package com.mineinabyss.geary.serialization -import com.mineinabyss.geary.addons.Namespaced +import com.mineinabyss.ding.DI +import com.mineinabyss.geary.addons.GearyPhase import com.mineinabyss.geary.addons.dsl.GearyAddon -import com.mineinabyss.geary.addons.dsl.GearyDSLMarker -import com.mineinabyss.geary.datatypes.Component -import com.mineinabyss.geary.modules.GearyConfiguration -import com.mineinabyss.geary.modules.GearyModule -import kotlinx.serialization.KSerializer -import kotlinx.serialization.modules.PolymorphicModuleBuilder -import kotlinx.serialization.modules.SerializersModule -import kotlinx.serialization.modules.SerializersModuleBuilder -import kotlinx.serialization.modules.polymorphic -import kotlin.reflect.KClass - -class SerializableComponents { - /** Adds a [SerializersModule] for polymorphic serialization of [Component]s within the ECS. */ - inline fun Namespaced.components(crossinline init: PolymorphicModuleBuilder.() -> Unit) { - module { polymorphic(Component::class) { init() } } - } - - - fun format(ext: String, format: (SerializersModule) -> PrefabFormat) { - serialization.formats.register(ext, format) - } - - /** - * Adds a serializable component and registers it with Geary to allow finding the appropriate class via - * component serial name. - */ - inline fun PolymorphicModuleBuilder.component(serializer: KSerializer) { - component(T::class, serializer) - } - - /** - * Adds a serializable component and registers it with Geary to allow finding the appropriate class via - * component serial name. - */ - fun PolymorphicModuleBuilder.component( - kClass: KClass, - serializer: KSerializer? - ): Boolean { - val serialName = serializer?.descriptor?.serialName ?: return false - if (!serializers.isRegistered(serialName)) { - serializers.registerSerialName(serialName, kClass) - subclass(kClass, serializer) - return true +import com.mineinabyss.geary.addons.dsl.GearyAddonWithDefault +import com.mineinabyss.geary.modules.geary +import com.mineinabyss.geary.serialization.formats.Formats +import com.mineinabyss.geary.serialization.formats.SimpleFormats +import okio.FileSystem + +val serializableComponents by DI.observe() + +interface SerializableComponents { + val serializers: Serializers + val formats: Formats + val fileSystem: FileSystem + + companion object Plugin : GearyAddonWithDefault { + override fun default(): SerializableComponents = object : SerializableComponents { + override val serializers = SerializersByMap() + override val formats = SimpleFormats() } - return false - } - /** Adds a [SerializersModule] to be used for polymorphic serialization within the ECS. */ - inline fun Namespaced.module(init: SerializersModuleBuilder.() -> Unit) { - serializers.addSerializersModule(namespace, SerializersModule { init() }) - } + override fun SerializableComponents.install() { + geary.pipeline.intercept(GearyPhase.INIT_COMPONENTS) { - companion object Plugin : GearyAddon { - override fun install(geary: GearyModule): SerializableComponents { - TODO("Not yet implemented") + } } - } } -@GearyDSLMarker -fun GearyConfiguration.serialization(configure: SerializableComponents.() -> Unit) = - install(SerializableComponents, configure) +object FileSystemAddon : GearyAddon { + override fun FileSystem.install() { + TODO("Not yet implemented") + } +} diff --git a/geary-serialization/src/commonMain/kotlin/com/mineinabyss/geary/serialization/SerializableComponentsDSL.kt b/geary-serialization/src/commonMain/kotlin/com/mineinabyss/geary/serialization/SerializableComponentsDSL.kt new file mode 100644 index 000000000..d49bf5791 --- /dev/null +++ b/geary-serialization/src/commonMain/kotlin/com/mineinabyss/geary/serialization/SerializableComponentsDSL.kt @@ -0,0 +1,64 @@ +package com.mineinabyss.geary.serialization + +import com.mineinabyss.geary.addons.Namespaced +import com.mineinabyss.geary.addons.dsl.GearyDSL +import com.mineinabyss.geary.datatypes.Component +import kotlinx.serialization.InternalSerializationApi +import kotlinx.serialization.KSerializer +import kotlinx.serialization.modules.PolymorphicModuleBuilder +import kotlinx.serialization.modules.SerializersModule +import kotlinx.serialization.modules.SerializersModuleBuilder +import kotlinx.serialization.modules.polymorphic +import kotlinx.serialization.serializerOrNull +import kotlin.reflect.KClass + +@GearyDSL +class SerializableComponentsDSL( + val namespaced: Namespaced +) { + val serializers = serializableComponents.serializers + + /** Adds a [SerializersModule] for polymorphic serialization of [Component]s within the ECS. */ + inline fun components(crossinline init: PolymorphicModuleBuilder.() -> Unit) { + module { polymorphic(Component::class) { init() } } + } + + + fun format(ext: String, format: (SerializersModule) -> PrefabFormat) { + serializableComponents.formats.register(ext, format) + } + + /** + * Adds a serializable component and registers it with Geary to allow finding the appropriate class via + * component serial name. + */ + inline fun PolymorphicModuleBuilder.component(serializer: KSerializer) { + component(T::class, serializer) + } + + /** + * Adds a serializable component and registers it with Geary to allow finding the appropriate class via + * component serial name. + */ + @OptIn(InternalSerializationApi::class) + fun PolymorphicModuleBuilder.component( + subclass: KClass, + serializer: KSerializer = subclass.serializerOrNull() + ?: error("No serializer found for $subclass while registering serializable component") + ) { + val serialName = serializer.descriptor.serialName + if (!serializers.isRegistered(serialName)) { + serializers.registerSerialName(serialName, subclass) + subclass(subclass, serializer) + } + } + + /** Adds a [SerializersModule] to be used for polymorphic serialization within the ECS. */ + inline fun module(init: SerializersModuleBuilder.() -> Unit) { + serializers.addSerializersModule(namespaced.namespace, SerializersModule { init() }) + } +} + +@GearyDSL +fun Namespaced.serialization(configure: SerializableComponentsDSL.() -> Unit) = + gearyConf.install(SerializableComponents).also { SerializableComponentsDSL().configure() } diff --git a/geary-serialization/src/commonMain/kotlin/com/mineinabyss/geary/serialization/SerializableComponentsModule.kt b/geary-serialization/src/commonMain/kotlin/com/mineinabyss/geary/serialization/SerializableComponentsModule.kt deleted file mode 100644 index d54431867..000000000 --- a/geary-serialization/src/commonMain/kotlin/com/mineinabyss/geary/serialization/SerializableComponentsModule.kt +++ /dev/null @@ -1,11 +0,0 @@ -package com.mineinabyss.geary.serialization - -import com.mineinabyss.geary.modules.geary -import com.mineinabyss.geary.serialization.formats.Formats - -val serialization by geary.addons.observe() - -interface SerializableComponentsModule { - val serializers: SerializersByMap - val formats: Formats -} diff --git a/geary-serialization/src/commonMain/kotlin/com/mineinabyss/geary/serialization/formats/SimpleFormats.kt b/geary-serialization/src/commonMain/kotlin/com/mineinabyss/geary/serialization/formats/SimpleFormats.kt index 7d3da7b7c..4062d3d68 100644 --- a/geary-serialization/src/commonMain/kotlin/com/mineinabyss/geary/serialization/formats/SimpleFormats.kt +++ b/geary-serialization/src/commonMain/kotlin/com/mineinabyss/geary/serialization/formats/SimpleFormats.kt @@ -3,7 +3,7 @@ package com.mineinabyss.geary.serialization.formats import com.mineinabyss.geary.modules.geary import com.mineinabyss.geary.datatypes.Component import com.mineinabyss.geary.serialization.PrefabFormat -import com.mineinabyss.geary.serialization.SerializableComponents +import com.mineinabyss.geary.serialization.serializableComponents import kotlinx.serialization.cbor.Cbor /** @@ -13,7 +13,7 @@ import kotlinx.serialization.cbor.Cbor * Will likely be converted into a service eventually. */ class SimpleFormats : Formats { - private val serializers = geary.addons.get() + private val serializers = serializableComponents.serializers private val formatMap = mutableMapOf() override val binaryFormat: Cbor by lazy { diff --git a/geary-serialization/src/jvmMain/kotlin/com/mineinabyss/serialization/formats/YamlFormat.kt b/geary-serialization/src/jvmMain/kotlin/com/mineinabyss/serialization/formats/YamlFormat.kt index 15b35a5bc..b68362bb5 100644 --- a/geary-serialization/src/jvmMain/kotlin/com/mineinabyss/serialization/formats/YamlFormat.kt +++ b/geary-serialization/src/jvmMain/kotlin/com/mineinabyss/serialization/formats/YamlFormat.kt @@ -6,6 +6,7 @@ import com.mineinabyss.geary.serialization.PrefabFormat import kotlinx.serialization.DeserializationStrategy import kotlinx.serialization.SerializationStrategy import kotlinx.serialization.modules.SerializersModule +import okio.FileSystem import okio.Path class YamlFormat( diff --git a/platforms/papermc/build.gradle.kts b/platforms/papermc/build.gradle.kts index 6f9884b4a..b6a8956c5 100644 --- a/platforms/papermc/build.gradle.kts +++ b/platforms/papermc/build.gradle.kts @@ -48,5 +48,6 @@ dependencies { implementation("io.ktor:ktor-server-netty:2.2.1") // Other plugins + implementation(mylibs.okio) compileOnly(mylibs.plugman) } diff --git a/platforms/papermc/src/main/kotlin/com/mineinabyss/geary/papermc/plugin/GearyPluginImpl.kt b/platforms/papermc/src/main/kotlin/com/mineinabyss/geary/papermc/plugin/GearyPluginImpl.kt index d88f5f4ac..cb18c2bbe 100644 --- a/platforms/papermc/src/main/kotlin/com/mineinabyss/geary/papermc/plugin/GearyPluginImpl.kt +++ b/platforms/papermc/src/main/kotlin/com/mineinabyss/geary/papermc/plugin/GearyPluginImpl.kt @@ -1,11 +1,6 @@ package com.mineinabyss.geary.papermc.plugin -import com.mineinabyss.geary.addon.* import com.mineinabyss.geary.addons.GearyPhase.ENABLE -import com.mineinabyss.geary.addons.dsl.AutoScan -import com.mineinabyss.geary.addons.dsl.serializers.* -import com.mineinabyss.geary.addons.namespace -import com.mineinabyss.geary.autoscan.AutoScanAddon import com.mineinabyss.geary.autoscan.autoscan import com.mineinabyss.geary.helpers.withSerialName import com.mineinabyss.geary.modules.GearyArchetypeModule @@ -14,6 +9,7 @@ import com.mineinabyss.geary.papermc.GearyPlugin import com.mineinabyss.geary.papermc.access.toGeary import com.mineinabyss.geary.papermc.modules.GearyPaperModule import com.mineinabyss.geary.prefabs.prefabs +import com.mineinabyss.geary.serialization.FileSystemAddon import com.mineinabyss.geary.serialization.serialization import com.mineinabyss.idofront.platforms.Platforms import com.mineinabyss.idofront.serialization.UUIDSerializer @@ -24,7 +20,7 @@ import io.ktor.server.engine.* import io.ktor.server.netty.* import io.ktor.server.response.* import io.ktor.server.routing.* -import io.ktor.util.* +import okio.FileSystem import org.bukkit.Bukkit import java.util.* import kotlin.io.path.isDirectory @@ -43,13 +39,12 @@ class GearyPluginImpl : GearyPlugin() { this ) module.inject() + geary { - install(AutoScanAddon) + install(FileSystemAddon, FileSystem.SYSTEM) + install(YamlFormat) + install(JsonFormat) namespace("geary") { - autoscan { - autoscan("com.mineinabyss", AutoScan::all) - all() - } serialization { format("yml", ::YamlFormat) @@ -57,19 +52,22 @@ class GearyPluginImpl : GearyPlugin() { component(UUID::class, UUIDSerializer.withSerialName("geary:uuid")) } } + autoscan("com.mineinabyss") { + components() + } } // Load prefabs in Geary folder, each subfolder is considered its own namespace - prefabs { - dataFolder.toPath().listDirectoryEntries() - .filter { it.isDirectory() } - .forEach { folder -> - namespace(folder.name) { - glob(folder) + dataFolder.toPath().listDirectoryEntries() + .filter { it.isDirectory() } + .forEach { folder -> + namespace(folder.name) { + prefabs { + fromRecursive(folder) } } - } - systems.add() - pipeline.intercept(ENABLE) { + } + + on(ENABLE) { Bukkit.getOnlinePlayers().forEach { it.toGeary() } } }