From 395aa7d1c312e495517701be11c21425d9a5838e Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Sun, 26 Oct 2025 17:25:13 -0700 Subject: Checkpoint --- .../src/commonMain/kotlin/coffee/liz/ecs/Entity.kt | 28 ++++++---------------- 1 file changed, 7 insertions(+), 21 deletions(-) (limited to 'composeApp/src/commonMain/kotlin/coffee/liz/ecs/Entity.kt') 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, Component>() /** - * Add a component to this entity. + * Add [Component]. */ fun 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 remove(type: KClass): Entity { components.remove(type) @@ -25,29 +25,22 @@ class Entity(val id: Int) { } /** - * Get a component by type. + * Get [Component] */ @Suppress("UNCHECKED_CAST") - fun get(type: KClass): T? { - return components[type] as? T + fun get(type: KClass): T { + return components[type] as T } /** - * Check if entity has a component. + * Has [Component] */ fun has(type: KClass): Boolean { return components.containsKey(type) } /** - * Check if entity has all specified components. - */ - fun hasAll(vararg types: KClass): Boolean { - return types.all { components.containsKey(it) } - } - - /** - * Get all component types on this entity. + * [Component]s of this entity. */ fun componentTypes(): Set> { 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 Entity.get(): T? = get(T::class) -inline fun Entity.has(): Boolean = has(T::class) -inline fun Entity.remove(): Entity = remove(T::class) -- cgit v1.2.3-70-g09d2