All Downloads are FREE. Search and download functionalities are using the official Maven repository.

ktx.artemis.world.kt Maven / Gradle / Ivy

Go to download

Artemis-odb entity component system utilities for Kotlin libGDX applications.

The newest version!
package ktx.artemis

import com.artemis.BaseSystem
import com.artemis.World
import com.badlogic.gdx.utils.GdxRuntimeException
import kotlin.reflect.KClass

/**
 * Retrieves a system from the [World].
 *
 * @receiver the [World].
 * @param T type of the system to retrieve.
 * @return the [BaseSystem] of the given type.
 * @throws MissingBaseSystemException if no system under [T] type is registered.
 */
inline fun  World.getSystem(): T =
  getSystem(T::class.java) ?: throw MissingBaseSystemException(T::class.java)

/**
 * Retrieves a system from the [World].
 *
 * @receiver the [World].
 * @param type type of the system to retrieve.
 * @return the [BaseSystem] of the given type. May be null if it does not exist.
 */
operator fun  World.get(type: KClass): T? = getSystem(type.java)

/**
 * Thrown when accessing an [BaseSystem] via [getSystem] that does not exist in the [World].
 */
class MissingBaseSystemException(type: Class) : GdxRuntimeException(
  "Could not access system of type ${type.simpleName} - is it added to the world?",
)




© 2015 - 2024 Weber Informatics LLC | Privacy Policy