summaryrefslogtreecommitdiff
path: root/composeApp/src/commonMain/kotlin/coffee/liz/ecs/Entity.kt
diff options
context:
space:
mode:
Diffstat (limited to 'composeApp/src/commonMain/kotlin/coffee/liz/ecs/Entity.kt')
-rw-r--r--composeApp/src/commonMain/kotlin/coffee/liz/ecs/Entity.kt28
1 files changed, 7 insertions, 21 deletions
diff --git a/composeApp/src/commonMain/kotlin/coffee/liz/ecs/Entity.kt b/composeApp/src/commonMain/kotlin/coffee/liz/ecs/Entity.kt
index 2ceac47..fcc39fb 100644
--- a/composeApp/src/commonMain/kotlin/coffee/liz/ecs/Entity.kt
+++ b/composeApp/src/commonMain/kotlin/coffee/liz/ecs/Entity.kt
@@ -9,7 +9,7 @@ class Entity(val id: Int) {
private val components = mutableMapOf<KClass<out Component>, Component>()
/**
- * Add a component to this entity.
+ * Add [Component].
*/
fun <T : Component> add(component: T): Entity {
components[component::class] = component
@@ -17,7 +17,7 @@ class Entity(val id: Int) {
}
/**
- * Remove a component from this entity.
+ * Remove [Component].
*/
fun <T : Component> remove(type: KClass<T>): Entity {
components.remove(type)
@@ -25,29 +25,22 @@ class Entity(val id: Int) {
}
/**
- * Get a component by type.
+ * Get [Component]
*/
@Suppress("UNCHECKED_CAST")
- fun <T : Component> get(type: KClass<T>): T? {
- return components[type] as? T
+ fun <T : Component> get(type: KClass<T>): T {
+ return components[type] as T
}
/**
- * Check if entity has a component.
+ * Has [Component]
*/
fun <T : Component> has(type: KClass<T>): Boolean {
return components.containsKey(type)
}
/**
- * Check if entity has all specified components.
- */
- fun hasAll(vararg types: KClass<out Component>): Boolean {
- return types.all { components.containsKey(it) }
- }
-
- /**
- * Get all component types on this entity.
+ * [Component]s of this entity.
*/
fun componentTypes(): Set<KClass<out Component>> {
return components.keys.toSet()
@@ -58,13 +51,6 @@ class Entity(val id: Int) {
if (other !is Entity) return false
return id == other.id
}
-
override fun hashCode(): Int = id
-
override fun toString(): String = "Entity($id)"
}
-
-// Convenience extensions for cleaner syntax
-inline fun <reified T : Component> Entity.get(): T? = get(T::class)
-inline fun <reified T : Component> Entity.has(): Boolean = has(T::class)
-inline fun <reified T : Component> Entity.remove(): Entity = remove(T::class)