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

ktx.ashley.families.kt Maven / Gradle / Ivy

The newest version!
package ktx.ashley

import com.badlogic.ashley.core.Component
import com.badlogic.ashley.core.Family
import com.badlogic.ashley.core.Family.Builder
import kotlin.reflect.KClass

/**
 * @param components matches [entities][com.badlogic.ashley.core.Entity] with at least one of the specified components.
 * @return a new [Builder] for a [Family].
 */
fun oneOf(vararg components: KClass): Builder = Family.one(*toJavaClassArray(components))

/**
 * @param components matches [entities][com.badlogic.ashley.core.Entity] with all of the specified components.
 * @return a new [Builder] for a [Family].
 */
fun allOf(vararg components: KClass): Builder = Family.all(*toJavaClassArray(components))

/**
 * @param components does not match [entities][com.badlogic.ashley.core.Entity] with any of the specified components.
 * @return a new [Builder] for a [Family].
 */
fun exclude(vararg components: KClass): Builder = Family.exclude(*toJavaClassArray(components))

/**
 * @receiver the [Builder] for creating a [Family].
 * @param components matches [entities][com.badlogic.ashley.core.Entity] with at least one of the specified components.
 * @return the received [Builder] for the [Family].
 */
fun Builder.oneOf(vararg components: KClass): Builder = one(*toJavaClassArray(components))

/**
 * @receiver the [Builder] for creating a [Family].
 * @param components matches [entities][com.badlogic.ashley.core.Entity] with all of the specified components.
 * @return the received [Builder] for the [Family].
 */
fun Builder.allOf(vararg components: KClass): Builder = all(*toJavaClassArray(components))

/**
 * @receiver the [Builder] for creating a [Family].
 * @param components does not match [entities][com.badlogic.ashley.core.Entity] with any of the specified components.
 * @return the received [Builder] for the [Family].
 */
fun Builder.exclude(vararg components: KClass): Builder = exclude(*toJavaClassArray(components))

private fun toJavaClassArray(components: Array>): Array> =
  Array(components.size) { index -> components[index].java }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy