-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make LevelMap support Tiled and LDtk editor formats
- Loading branch information
Showing
2 changed files
with
58 additions
and
53 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
korge-fleks/src/commonMain/kotlin/korlibs/korge/fleks/entity/config/LevelMap.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
53 changes: 0 additions & 53 deletions
53
korge-fleks/src/commonMain/kotlin/korlibs/korge/fleks/entity/config/TiledMapBackground.kt
This file was deleted.
Oops, something went wrong.