Skip to content

Commit

Permalink
#125: optimize EntityTag syntax
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon Klausner committed Nov 27, 2023
1 parent 3ba9640 commit ddaacd1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 4 deletions.
6 changes: 2 additions & 4 deletions src/commonMain/kotlin/com/github/quillraven/fleks/entity.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package com.github.quillraven.fleks

import com.github.quillraven.fleks.collection.*
import kotlinx.serialization.Serializable
import kotlin.jvm.JvmName

/**
* An entity of a [world][World]. It represents a unique identifier that is the combination
Expand Down Expand Up @@ -141,7 +140,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 @@ -153,8 +152,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 ddaacd1

Please sign in to comment.