-
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.
feat: instances component for creating prefab instances in config
chore: Use inner serializer for InheritPrefabs fix: not resetting delegated status in forEach call, resulting in incorrect entities returned in queries.
- Loading branch information
Showing
8 changed files
with
89 additions
and
7 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
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
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
15 changes: 11 additions & 4 deletions
15
...ommonMain/kotlin/com/mineinabyss/geary/prefabs/configuration/components/InheritPrefabs.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,16 +1,23 @@ | ||
package com.mineinabyss.geary.prefabs.configuration.components | ||
|
||
import com.mineinabyss.geary.prefabs.PrefabKey | ||
import kotlinx.serialization.SerialName | ||
import com.mineinabyss.geary.serialization.serializers.InnerSerializer | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.builtins.SetSerializer | ||
|
||
/** | ||
* > geary:inherit | ||
* | ||
* Will make this entity an instance of all entities defined in [from] | ||
*/ | ||
@Serializable | ||
@SerialName("geary:inherit") | ||
@Serializable(with = InheritPrefabs.Serializer::class) | ||
class InheritPrefabs( | ||
val from: Set<PrefabKey> | ||
) | ||
) { | ||
class Serializer : InnerSerializer<Set<PrefabKey>, InheritPrefabs>( | ||
"geary:inherit", | ||
SetSerializer(PrefabKey.serializer()), | ||
{ InheritPrefabs(it) }, | ||
{ it.from } | ||
) | ||
} |
29 changes: 29 additions & 0 deletions
29
...onMain/kotlin/com/mineinabyss/geary/prefabs/configuration/components/InstancesOnPrefab.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 |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.mineinabyss.geary.prefabs.configuration.components | ||
|
||
import com.mineinabyss.geary.components.EntityName | ||
import com.mineinabyss.geary.datatypes.Component | ||
import com.mineinabyss.geary.serialization.serializers.InnerSerializer | ||
import com.mineinabyss.geary.serialization.serializers.PolymorphicListAsMapSerializer | ||
import kotlinx.serialization.Polymorphic | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.builtins.MapSerializer | ||
import kotlinx.serialization.builtins.serializer | ||
|
||
/** | ||
* > geary:children | ||
* | ||
* A component that will add a list of named children to this entity. | ||
* | ||
* The keys will be used to set an extra [EntityName] component. | ||
*/ | ||
@Serializable(with = InstancesOnPrefab.Serializer::class) | ||
class InstancesOnPrefab( | ||
val nameToComponents: Map<String, List<@Polymorphic Component>> | ||
) { | ||
class Serializer : InnerSerializer<Map<String, List<Component>>, InstancesOnPrefab>( | ||
"geary:instances", | ||
MapSerializer(String.serializer(), PolymorphicListAsMapSerializer.ofComponents()), | ||
{ InstancesOnPrefab(it) }, | ||
{ it.nameToComponents }, | ||
) | ||
} |
28 changes: 28 additions & 0 deletions
28
...Main/kotlin/com/mineinabyss/geary/prefabs/configuration/systems/ParseInstancesOnPrefab.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 |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.mineinabyss.geary.prefabs.configuration.systems | ||
|
||
import com.mineinabyss.geary.components.relations.NoInherit | ||
import com.mineinabyss.geary.helpers.entity | ||
import com.mineinabyss.geary.modules.GearyModule | ||
import com.mineinabyss.geary.prefabs.PrefabKey | ||
import com.mineinabyss.geary.prefabs.configuration.components.InstancesOnPrefab | ||
import com.mineinabyss.geary.prefabs.configuration.components.Prefab | ||
import com.mineinabyss.geary.systems.builders.listener | ||
import com.mineinabyss.geary.systems.query.ListenerQuery | ||
|
||
fun GearyModule.createParseInstancesOnPrefabListener() = listener(object : ListenerQuery() { | ||
val instances by get<InstancesOnPrefab>() | ||
val prefabKey by get<PrefabKey>() | ||
override fun ensure() = event.anyFirstSet(::instances, ::prefabKey) | ||
}).exec { | ||
entity.addRelation<NoInherit, InstancesOnPrefab>() | ||
instances.nameToComponents.forEach { (name, components) -> | ||
entity { | ||
set(PrefabKey.of(prefabKey.namespace, name)) | ||
set(Prefab()) | ||
extend(entity) | ||
addRelation<NoInherit, Prefab>() | ||
setAll(components) | ||
} | ||
logger.d("Created instance $name of prefab $prefabKey") | ||
} | ||
} |
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
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