-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Swap to kotlinx.io for multiplatform paths
feat: Allow loading paths from jar resources on JVM
- Loading branch information
Showing
16 changed files
with
276 additions
and
162 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
14 changes: 11 additions & 3 deletions
14
addons/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/PrefabPath.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,16 @@ | ||
package com.mineinabyss.geary.prefabs | ||
|
||
import okio.Path | ||
import kotlinx.io.Source | ||
import kotlinx.io.files.Path | ||
|
||
class PrefabPath( | ||
data class PrefabPath( | ||
val namespace: String, | ||
val get: () -> Sequence<Path>, | ||
val paths: () -> Sequence<Path> = { emptySequence() }, | ||
val sources: () -> Sequence<PrefabSource> = { emptySequence() }, | ||
) | ||
|
||
data class PrefabSource( | ||
val source: Source, | ||
val key: PrefabKey, | ||
val formatExt: String, | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
65 changes: 30 additions & 35 deletions
65
addons/geary-prefabs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/PrefabsModule.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,52 +1,47 @@ | ||
package com.mineinabyss.geary.prefabs | ||
|
||
import com.mineinabyss.geary.addons.Namespaced | ||
import com.mineinabyss.geary.addons.dsl.Addon | ||
import com.mineinabyss.geary.addons.dsl.GearyDSL | ||
import com.mineinabyss.geary.addons.dsl.createAddon | ||
import com.mineinabyss.geary.prefabs.configuration.systems.* | ||
import com.mineinabyss.geary.prefabs.systems.createInheritPrefabsOnLoadListener | ||
import com.mineinabyss.geary.prefabs.systems.createTrackPrefabsByKeyListener | ||
import com.mineinabyss.geary.serialization.FileSystem | ||
import com.mineinabyss.geary.serialization.SerializableComponents | ||
|
||
interface PrefabsModule { | ||
val manager: PrefabManager | ||
val loader: PrefabLoader | ||
} | ||
data class PrefabsModule( | ||
val manager: PrefabManager, | ||
val loader: PrefabLoader, | ||
) | ||
|
||
class PrefabsBuilder { | ||
val paths: MutableList<PrefabPath> = mutableListOf() | ||
class PrefabSources { | ||
val paths = mutableListOf<PrefabPath>() | ||
} | ||
|
||
val Prefabs | ||
get() = createAddon<PrefabsBuilder, PrefabsModule>("Prefabs", { PrefabsBuilder() }) { | ||
val formats = geary.getAddon(SerializableComponents).formats | ||
val module = object : PrefabsModule { | ||
override val manager = PrefabManager() | ||
override val loader: PrefabLoader = PrefabLoader(geary, formats, logger) | ||
} | ||
|
||
configuration.paths.forEach { module.loader.addSource(it) } | ||
|
||
systems { | ||
createInheritPrefabsOnLoadListener() | ||
createParseChildOnPrefabListener() | ||
createParseChildrenOnPrefabListener() | ||
createParseInstancesOnPrefabListener() | ||
createParseRelationOnPrefabListener() | ||
createParseRelationWithDataListener() | ||
createTrackPrefabsByKeyListener() | ||
createCopyToInstancesSystem() | ||
reEmitEvent() | ||
} | ||
val Prefabs = createAddon<PrefabSources, PrefabsModule>("Prefabs", { | ||
install(SerializableComponents) | ||
PrefabSources() | ||
}) { | ||
val formats = geary.getAddon(SerializableComponents).formats | ||
val module = PrefabsModule(PrefabManager(), PrefabLoader(configuration, geary, formats, logger)) | ||
|
||
systems { | ||
createInheritPrefabsOnLoadListener() | ||
createParseChildOnPrefabListener() | ||
createParseChildrenOnPrefabListener() | ||
createParseInstancesOnPrefabListener() | ||
createParseRelationOnPrefabListener() | ||
createParseRelationWithDataListener() | ||
createTrackPrefabsByKeyListener() | ||
createCopyToInstancesSystem() | ||
reEmitEvent() | ||
} | ||
|
||
entities { | ||
module.loader.loadOrUpdatePrefabs() | ||
} | ||
module | ||
entities { | ||
module.loader.loadOrUpdatePrefabs() | ||
} | ||
module | ||
} | ||
|
||
@GearyDSL | ||
fun Namespaced.prefabs(configure: PrefabsDSL.() -> Unit): Addon<PrefabsBuilder, PrefabsModule> = | ||
setup.install(Prefabs) { PrefabsDSL(this, setup.geary.getConfiguration(FileSystem), this@prefabs).configure() } | ||
fun Namespaced.prefabs(configure: PrefabsDSL.() -> Unit) = | ||
setup.install(Prefabs) { PrefabsDSL(this, this@prefabs).configure() } |
2 changes: 1 addition & 1 deletion
2
...bs/src/commonMain/kotlin/com/mineinabyss/geary/prefabs/configuration/components/Prefab.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.