summaryrefslogtreecommitdiff
path: root/composeApp/src/commonMain/kotlin/coffee/liz/ecs/Entity.kt
diff options
context:
space:
mode:
authorElizabeth Hunt <me@liz.coffee>2025-10-26 21:38:22 -0700
committerElizabeth Hunt <me@liz.coffee>2025-10-26 21:39:58 -0700
commita8e5e723b7e1891c9b352261a3ee4c3d3563e8cf (patch)
tree853df79c877d37d7e5d25f52b301aedcc3d5db55 /composeApp/src/commonMain/kotlin/coffee/liz/ecs/Entity.kt
parent395aa7d1c312e495517701be11c21425d9a5838e (diff)
downloadabstraction-engine-kt-main.tar.gz
abstraction-engine-kt-main.zip
Checkpoint twoHEADmain
Diffstat (limited to 'composeApp/src/commonMain/kotlin/coffee/liz/ecs/Entity.kt')
-rw-r--r--composeApp/src/commonMain/kotlin/coffee/liz/ecs/Entity.kt18
1 files changed, 8 insertions, 10 deletions
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<KClass<out Component>, Component>()
/**
@@ -28,29 +30,25 @@ class Entity(val id: Int) {
* 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 = components[type] as T
/**
* Has [Component]
*/
- fun <T : Component> has(type: KClass<T>): Boolean {
- return components.containsKey(type)
- }
+ fun <T : Component> has(type: KClass<T>): Boolean = components.containsKey(type)
/**
* [Component]s of this entity.
*/
- fun componentTypes(): Set<KClass<out Component>> {
- return components.keys.toSet()
- }
+ fun componentTypes(): Set<KClass<out Component>> = 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)"
}