Skip to content

Commit

Permalink
Make LevelMap support Tiled and LDtk editor formats
Browse files Browse the repository at this point in the history
  • Loading branch information
jobe-m committed Mar 14, 2024
1 parent 0d6a29f commit 8b361ff
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 53 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package korlibs.korge.fleks.entity.config

import com.github.quillraven.fleks.Entity
import com.github.quillraven.fleks.World
import korlibs.korge.assetmanager.AssetStore
import korlibs.korge.assetmanager.ConfigBase
import korlibs.korge.fleks.components.*
import korlibs.korge.fleks.utils.Identifier


object LevelMap {

// Config data class
data class Config(
val mapType: MapType,
val assetName: String = "",
val worldName: String = "",
val levelName: String = "",
val layerName: String,
val x: Double = 0.0,
val y: Double = 0.0,
val alpha: Double = 1.0
) : ConfigBase

enum class MapType { LDTK, TILED }

// Used in component properties to specify invokable function
val configureLevelMap = Identifier(name = "configureLevelMap")

/**
* This function creates a level map background entity which is used for various backgrounds in the game and intro.
*/
private val configureLevelMapFct = fun(world: World, entity: Entity, config: Identifier) = with(world) {
val levelMapConfig = AssetStore.getEntityConfig<Config>(config.name)
entity.configure {
when (levelMapConfig.mapType) {
MapType.LDTK -> it += LdtkLevelMapComponent(levelMapConfig.worldName, levelMapConfig.levelName)
MapType.TILED -> it += TiledMapComponent(levelMapConfig.assetName)
}
it += PositionShapeComponent(
x = levelMapConfig.x,
y = levelMapConfig.y
)
it += DrawableComponent(
drawOnLayer = levelMapConfig.layerName
)
it += AppearanceComponent(
alpha = levelMapConfig.alpha
)
}
entity
}

// Init block which registers the configure function and its Identifier to the Invokable object store
init {
Invokable.register(configureLevelMap, configureLevelMapFct)
}
}

This file was deleted.

0 comments on commit 8b361ff

Please sign in to comment.