Skip to content

Generic Entity Config

Marko Koschak edited this page May 3, 2024 · 10 revisions

KorGE-Fleks contains some generic entity config classes which can be used to ease build up of more complex game objects. The existing entity config classess can be found in korlibs.korge.fleks.entity.config. These classes contain 4 sections as shown below:

data class MyEntityConfig(
    override val name: String,  // (1)

    // (2)
    val <property>: String,
    ...

) : EntityConfig {

    // The actual (anonymous) configure function as a value object
    private val configureEntity = fun(world: World, entity: Entity) : Entity = with(world) {
        val entityConfig = AssetStore.getEntityConfig<Config>(config.name)
        entity.configure {
            // (3)
            it += SomeComponent(<property> = this@MyEntityConnfig.<property>)
            ...
        }
        return entity
    }

    // (4) Init block which registers the entity config in the EntityFactory
    init {
        EntityFactory.register(this)
    }
Clone this wiki locally