From 4d20d3df6c62d728639c4a7d9960870714ea818a Mon Sep 17 00:00:00 2001 From: Simon Date: Mon, 27 Nov 2023 15:51:29 +0100 Subject: [PATCH] #125: optimize EntityTag syntax (#126) #125: optimize EntityTag syntax --- .../com/github/quillraven/fleks/entity.kt | 4 ++-- .../github/quillraven/fleks/EntityTagTest.kt | 18 ++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/src/commonMain/kotlin/com/github/quillraven/fleks/entity.kt b/src/commonMain/kotlin/com/github/quillraven/fleks/entity.kt index 1866269..cb3871f 100644 --- a/src/commonMain/kotlin/com/github/quillraven/fleks/entity.kt +++ b/src/commonMain/kotlin/com/github/quillraven/fleks/entity.kt @@ -141,7 +141,7 @@ open class EntityCreateContext( /** * Sets the [tag][EntityTag] to the [entity][Entity]. */ - operator fun Entity.plusAssign(tag: UniqueId<*>) { + operator fun Entity.plusAssign(tag: EntityTags) { compMasks[this.id].set(tag.id) // We need to remember used tags in order to correctly return and load them using // the snapshot functionality, because tags are not managed via ComponentHolder and @@ -154,7 +154,7 @@ open class EntityCreateContext( * Sets all [tags][EntityTag] on the given [entity][Entity]. */ @JvmName("plusAssignTags") - operator fun Entity.plusAssign(tags: List>) { + operator fun Entity.plusAssign(tags: List) { tags.forEach { this += it } } diff --git a/src/commonTest/kotlin/com/github/quillraven/fleks/EntityTagTest.kt b/src/commonTest/kotlin/com/github/quillraven/fleks/EntityTagTest.kt index ca079ac..fb1e2ce 100644 --- a/src/commonTest/kotlin/com/github/quillraven/fleks/EntityTagTest.kt +++ b/src/commonTest/kotlin/com/github/quillraven/fleks/EntityTagTest.kt @@ -154,4 +154,22 @@ class EntityTagTest { } } } + + /* + fun syntaxCheck() { + val world = configureWorld {} + world.entity { + it += TestTags.PLAYER + it += Visible + it += listOf(Visible) + it += TestTags.entries + it += listOf(Visible, TestTags.PLAYER) + + it += TestTagComponent() + it += listOf(TestTagComponent()) + + it += TestTagComponent // <-- should not compile + } + } + */ }