From a8e5e723b7e1891c9b352261a3ee4c3d3563e8cf Mon Sep 17 00:00:00 2001 From: Elizabeth Hunt Date: Sun, 26 Oct 2025 21:38:22 -0700 Subject: Checkpoint two --- .../src/commonMain/kotlin/coffee/liz/ecs/Entity.kt | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 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 fcc39fb..0ee604c 100644 --- a/composeApp/src/commonMain/kotlin/coffee/liz/ecs/Entity.kt +++ b/composeApp/src/commonMain/kotlin/coffee/liz/ecs/Entity.kt @@ -5,7 +5,9 @@ import kotlin.reflect.KClass /** * An entity is a unique identifier with a collection of components. */ -class Entity(val id: Int) { +class Entity( + val id: Int, +) { private val components = mutableMapOf, Component>() /** @@ -28,29 +30,25 @@ class Entity(val id: Int) { * Get [Component] */ @Suppress("UNCHECKED_CAST") - fun get(type: KClass): T { - return components[type] as T - } + fun get(type: KClass): T = components[type] as T /** * Has [Component] */ - fun has(type: KClass): Boolean { - return components.containsKey(type) - } + fun has(type: KClass): Boolean = components.containsKey(type) /** * [Component]s of this entity. */ - fun componentTypes(): Set> { - return components.keys.toSet() - } + fun componentTypes(): Set> = components.keys.toSet() override fun equals(other: Any?): Boolean { if (this === other) return true if (other !is Entity) return false return id == other.id } + override fun hashCode(): Int = id + override fun toString(): String = "Entity($id)" } -- cgit v1.2.3-70-g09d2