Skip to content

Commit

Permalink
#125: optimize EntityTag syntax (#126)
Browse files Browse the repository at this point in the history
#125: optimize EntityTag syntax
  • Loading branch information
Quillraven authored Nov 27, 2023
1 parent 3ba9640 commit 4d20d3d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/commonMain/kotlin/com/github/quillraven/fleks/entity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -154,7 +154,7 @@ open class EntityCreateContext(
* Sets all [tags][EntityTag] on the given [entity][Entity].
*/
@JvmName("plusAssignTags")
operator fun Entity.plusAssign(tags: List<UniqueId<*>>) {
operator fun Entity.plusAssign(tags: List<EntityTags>) {
tags.forEach { this += it }
}

Expand Down
18 changes: 18 additions & 0 deletions src/commonTest/kotlin/com/github/quillraven/fleks/EntityTagTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
}
*/
}

0 comments on commit 4d20d3d

Please sign in to comment.