Skip to content

Commit

Permalink
Add LDtk level map component
Browse files Browse the repository at this point in the history
  • Loading branch information
jobe-m committed Feb 2, 2024
1 parent 14dde39 commit 15a3b09
Show file tree
Hide file tree
Showing 5 changed files with 30 additions and 12 deletions.
3 changes: 3 additions & 0 deletions korge-fleks/kproject.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,7 @@ dependencies:
- https://github.com/korlibs/korge-parallax/tree/2f5fa9be09b52c343d9160fe29dc683aa86e22e8/korge-parallax
#- ../../korge-parallax/korge-parallax
- ../../korge-asset-manager/korge-asset-manager
#- https://github.com/korlibs/korge-ldtk/tree/3cc31bddd707037084f8e0d764a9706cc99f0bfb/korge-ldtk
- ../../korge-ldtk/korge-ldtk
- https://github.com/korlibs/korge-tiled/tree/a54e3b2cacf24e0a0eb87e2580f69f8c81d083ce/korge-tiled
targets: [jvm, android]
Original file line number Diff line number Diff line change
Expand Up @@ -18,21 +18,31 @@ import kotlinx.serialization.Serializable
* in the Korge specific systems.
*/
@Serializable
@SerialName("TileMap")
data class TileMap(
@SerialName("TiledMap")
data class TiledMap(
var assetName: String = "",
) : Component<TileMap>, SerializeBase {
override fun type(): ComponentType<TileMap> = TileMap
companion object : ComponentType<TileMap>() {
) : Component<TiledMap>, SerializeBase {
override fun type(): ComponentType<TiledMap> = TiledMap
companion object : ComponentType<TiledMap>() {
/**
* Hint: How you should read "Component Hook"
*
* A component listener creates and initializes the internal object(s) with all parameters of the component.
* This initialization can only use data from one component. Thus, it must be self-containable regarding the
* save-state of an object. But this is often not the case -> check FamilyHooks.
*/
fun onComponentAdded(entity: Entity, component: TileMap) {}
fun onComponentAdded(entity: Entity, component: TiledMap) {}

fun onComponentRemoved(entity: Entity, component: TileMap) {}
fun onComponentRemoved(entity: Entity, component: TiledMap) {}
}
}

@Serializable
@SerialName("LdtkTileMap")
data class LdtkTileMap(
var assetName: String = "",

) : Component<LdtkTileMap>, SerializeBase {
override fun type(): ComponentType<LdtkTileMap> = LdtkTileMap
companion object : ComponentType<LdtkTileMap>()
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import korlibs.korge.assetmanager.ConfigBase
import korlibs.korge.fleks.components.Appearance
import korlibs.korge.fleks.components.Drawable
import korlibs.korge.fleks.components.PositionShape
import korlibs.korge.fleks.components.TileMap
import korlibs.korge.fleks.components.TiledMap
import korlibs.korge.fleks.utils.Identifier


Expand All @@ -27,10 +27,10 @@ object TiledMapBackground {
/**
* This function creates a tiled map background entity which is used for various backgrounds in the game and intro.
*/
private val configureTileMapFct = fun(world: World, entity: Entity, config: Identifier) = with(world) {
private val configureTiledMapFct = fun(world: World, entity: Entity, config: Identifier) = with(world) {
val tileMapConfig = AssetStore.getEntityConfig<Config>(config.name)
entity.configure {
it += TileMap(
it += TiledMap(
assetName = tileMapConfig.assetName
)
it += PositionShape(
Expand All @@ -48,6 +48,6 @@ object TiledMapBackground {
}

init {
Invokable.register(configureTileMap, configureTileMapFct)
Invokable.register(configureTileMap, configureTiledMapFct)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,12 @@ val onDrawableFamilyAdded: FamilyHook = { entity ->
//
// TiledMapView(assets.getTiledMap(entity[TiledMap].assetName), smoothing = false, showShapes = false)
// }
/*
entity has LdtkTileMap -> {
tileMap
}
*/
entity has Parallax -> {
val parallax = entity[Parallax]
val parallaxConfig = AssetStore.getBackground(parallax.config.name)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ internal val internalModule = SerializersModule {
subclass(SubEntities::class)
subclass(Text::class)
subclass(MultiLineText::class)
subclass(TileMap::class)
subclass(TiledMap::class)
}
// Data class hierarchy used for AnimationScript component
polymorphic(TweenBase::class) {
Expand Down

0 comments on commit 15a3b09

Please sign in to comment.