Skip to content

Generic Entity Config

Marko Koschak edited this page Mar 14, 2024 · 10 revisions

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

object <EntityConfig> {

    // Config data classes
    data class Config(
        val <property>: String,
        ...
    ) : ConfigBase

    // Identifiers for invokable functions
    val <configureEntity> = Identifier("<configureEntity>")

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

    // Init block which registers the configure function and its Identifier to the Invokable object store
    init {
        Invokable.register(<configureEntity>, <configureEntityFct>)
    }
Clone this wiki locally