Entity

@Serializable
value class Entity(val id: EntityId)

A wrapper around EntityId that gets inlined to just a long (no performance degradation since no boxing occurs).

Provides some useful functions so we aren't forced to go through Engine every time we want to do some things.

Constructors

Link copied to clipboard
constructor(id: EntityId)

Functions

Link copied to clipboard
inline fun <T : Component> add(noEvent: Boolean = false)

Adds the type T to this entity's type, setting no data.

fun add(component: ComponentId, noEvent: Boolean = false)

Adds a component to this entity's type, setting no data.

Link copied to clipboard
fun addAll(components: Collection<ComponentId>, noEvent: Boolean = false)

Adds a list of components to this entity's type, setting no data.

Link copied to clipboard
fun Entity.addChild(child: Entity)

Adds a child entity to this entity.

Link copied to clipboard
fun Entity.addChildren(children: Array<Entity>)

Adds a list of children entities to this entity.

Link copied to clipboard
fun Entity.addParent(parent: Entity)

Adds a parent entity to this entity.

Link copied to clipboard
fun Entity.addParents(parents: Array<Entity>)

Adds a list of parents entities to this entity.

Link copied to clipboard
inline fun <K : Any, T : Any> addRelation(noEvent: Boolean = false)
inline fun <K : Any> addRelation(target: Entity, noEvent: Boolean = false)
Link copied to clipboard
fun callEvent(event: Entity, source: Entity? = null)

Calls an event using a specific entity on this entity.

inline fun callEvent(source: Entity? = null, crossinline initEvent: Entity.() -> Unit)

Calls an event on this entity using a temporary entity that can be configured with initEvent.

fun callEvent(vararg components: Any, source: Entity? = null)

Calls an event with components attached to it and this entity as the target.

inline fun <T> callEvent(vararg components: Any, source: Entity? = null, crossinline result: (event: Entity) -> T): T

Calls an event with components attached to it and this entity as the target, calculating a result after all handlers have run.

inline fun <T> callEvent(crossinline init: Entity.() -> Unit, source: Entity? = null, crossinline result: (event: Entity) -> T): T

Calls an event on this entity using a temporary entity that can be configured with init, calculating a result after all handlers have run.

Link copied to clipboard
fun clear()

Clears all components on this entity.

Link copied to clipboard

Removes all of this entity's children, also unlinking this parent from them.

Link copied to clipboard

Removes all of this entity's parents, also unlinking this child from them.

Link copied to clipboard
operator fun component1(): EntityId
Link copied to clipboard
inline fun <T : Component> get(): T?

Gets a component of type T on this entity.

fun get(component: ComponentId): Component?

Gets a component which holds data from this entity. Use has if the component is not to hold data.

inline fun <T : Component> get(kClass: KClass<out T>): T?
Link copied to clipboard

Gets all the components on this entity, as well as relations in the form of RelationComponent.

Link copied to clipboard

Gets all non-persisting components on this entity.

Link copied to clipboard

Gets all persisting components on this entity.

Link copied to clipboard
inline fun <T : Component> getOrSet(kClass: KClass<out T> = T::class, default: () -> T): T

Gets a component of type T or sets a default if no component was present.

Link copied to clipboard
inline fun <T : Component> getOrSetPersisting(kClass: KClass<out T> = T::class, default: () -> T): T

Gets a persisting component of type T or adds a default if no component was present.

Link copied to clipboard
inline fun <K : Component, T : Component> getRelation(): K?

Gets the data stored under the relation of kind K and target T.

inline fun <K : Component> getRelation(target: Entity): K?

Gets the data stored under the relation of kind K and target target.

Link copied to clipboard
inline fun <K : Component?, T : Component?> getRelations(): List<Relation>

Queries for relations using the same format as AccessorOperations.getRelations.

Link copied to clipboard

Like getRelations, but reads appropriate data as requested and puts it in a RelationWithData object.

Link copied to clipboard
inline fun <T : Component> has(): Boolean

Checks whether this entity has a component of type T, regardless of it holding data.

fun has(component: ComponentId): Boolean

Checks whether this entity has a component, regardless of it holding data.

inline fun <T : Component> has(kClass: KClass<out T>): Boolean
Link copied to clipboard
fun hasAll(components: Collection<KClass<*>>): Boolean

Checks whether an entity has all of components set or added.

Link copied to clipboard
inline fun <K : Component, T : Component> hasRelation(): Boolean
inline fun <K : Component?> hasRelation(target: Entity): Boolean
Link copied to clipboard
fun instanceOf(entity: Entity): Boolean

Checks whether this entity is an instance of another entity (the other is the prefab this entity was made from).

Link copied to clipboard
inline fun <T : Component?> Entity.nullOrError(): T

Gets a component of type T from an entity, returning null if T is nullable, or an error otherwise.

Link copied to clipboard
inline fun Entity.onParent(parent: Entity? = this.parent, run: Entity.() -> Unit)

Runs code on the first parent of this entity.

Link copied to clipboard
inline fun <T : Component> remove(): Boolean

Removes a component of type T from this entity.

fun remove(component: ComponentId): Boolean

Removes a component with id component from this entity.

fun remove(kClass: KClass<*>): Boolean

Removes a component whose class is kClass from this entity.

Link copied to clipboard

Removes a list of components from this entity.

Link copied to clipboard

Removes a child, also unlinking this parent from that child.

Link copied to clipboard

Remove this entity from the ECS.

Link copied to clipboard

Removes a parent, also unlinking this child from that parent.

Link copied to clipboard

Removes a relation key of type K and value of type V.

inline fun <K : Any> removeRelation(target: Entity): Boolean
Link copied to clipboard
fun set(components: Collection<Component>)
fun set(component: Component, componentId: ComponentId, noEvent: Boolean = false)

inline fun <T : Component> set(component: T, kClass: KClass<out T> = T::class, noEvent: Boolean = false)

Sets a component that holds data for this entity

Link copied to clipboard
fun setAll(components: Collection<Component>, override: Boolean = true)

Sets components that hold data for this entity

Link copied to clipboard
fun setAllPersisting(components: Collection<Component>, override: Boolean = true, noEvent: Boolean = false)

Sets a list of persisting components on this entity.

Link copied to clipboard

inline fun <T : Component> setPersisting(component: T, kClass: KClass<out T> = T::class, noEvent: Boolean = false): T

Sets a persisting component on this entity, which will be serialized if possible.

Link copied to clipboard
inline fun <K : Any, T : Any> setRelation(data: K, noEvent: Boolean = false)
inline fun <K : Any> setRelation(data: K, target: Entity, noEvent: Boolean = false)
Link copied to clipboard
inline fun <R, T : Component?> Entity.with(let: (T) -> R): R?
inline fun <R, T : Component?, T2 : Component?> Entity.with(let: (T, T2) -> R): R?
inline fun <T : Component, T2 : Component, T3 : Component> Entity.with(let: (T, T2, T3) -> Unit): Unit?
inline fun <T : Component, T2 : Component, T3 : Component, T4 : Component> Entity.with(let: (T, T2, T3, T4) -> Unit): Unit?
inline fun <T : Component, T2 : Component, T3 : Component, T4 : Component, T5 : Component> Entity.with(let: (T, T2, T3, T4, T5) -> Unit): Unit?
inline fun <T : Component, T2 : Component, T3 : Component, T4 : Component, T5 : Component, T6 : Component> Entity.with(let: (T, T2, T3, T4, T5, T6) -> Unit): Unit?
inline fun <T : Component, T2 : Component, T3 : Component, T4 : Component, T5 : Component, T6 : Component, T7 : Component> Entity.with(let: (T, T2, T3, T4, T5, T6, T7) -> Unit): Unit?

Runs when an entity has all passed components present.

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Gets the first parent of this entity

Link copied to clipboard
Link copied to clipboard

Gets this entity's type (the ids of components added to it) or throws an error if it is no longer active on the koinGet().