Skip to content

Commit

Permalink
Update EntityConfigs and assets hotreload config
Browse files Browse the repository at this point in the history
  • Loading branch information
jobe-m committed Jul 31, 2024
1 parent c0bcfb6 commit 2dc020c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import kotlinx.serialization.*
@Serializable @SerialName("AssetModel")
data class AssetModel(
val folder: String = "",
val hotReloading: Boolean = false,
val sounds: MutableMap<String, String> = mutableMapOf(),
val backgrounds: MutableMap<String, ParallaxConfig> = mutableMapOf(),
val images: MutableMap<String, ImageDataConfig> = mutableMapOf(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,32 +100,32 @@ class AssetStore {
else error("AssetStore: Cannot find font '$name'!")
}

suspend fun loadAssets(type: AssetType, assetConfig: AssetModel, hotReloading: Boolean) {
suspend fun loadAssets(type: AssetType, assetConfig: AssetModel) {
var assetLoaded = false
val atlas = when (type) {
AssetType.COMMON -> {
prepareCurrentAssets(type, assetConfig, commonAssetConfig, hotReloading)?.also { config ->
prepareCurrentAssets(type, assetConfig, commonAssetConfig)?.also { config ->
commonAssetConfig = config
assetLoaded = true
}
commonAtlas
}
AssetType.WORLD -> {
prepareCurrentAssets(type, assetConfig, currentWorldAssetConfig, hotReloading)?.also { config ->
prepareCurrentAssets(type, assetConfig, currentWorldAssetConfig)?.also { config ->
currentWorldAssetConfig = config
assetLoaded = true
}
worldAtlas
}
AssetType.LEVEL -> {
prepareCurrentAssets(type, assetConfig, currentLevelAssetConfig, hotReloading)?.also { config ->
prepareCurrentAssets(type, assetConfig, currentLevelAssetConfig)?.also { config ->
currentLevelAssetConfig = config
assetLoaded = true
}
levelAtlas
}
AssetType.SPECIAL -> {
prepareCurrentAssets(type, assetConfig, specialAssetConfig, hotReloading)?.also { config ->
prepareCurrentAssets(type, assetConfig, specialAssetConfig)?.also { config ->
specialAssetConfig = config
assetLoaded = true
}
Expand Down Expand Up @@ -175,22 +175,22 @@ class AssetStore {

println("Assets: Loaded resources in ${sw.elapsed}")

if (hotReloading) {
if (assetConfig.hotReloading) {
configureResourceDirWatcher {
addAssetWatcher(type) {}
}
}
}
}

private fun prepareCurrentAssets(type: AssetType, newAssetConfig: AssetModel, currentAssetConfig: AssetModel, hotReloading: Boolean): AssetModel? =
private fun prepareCurrentAssets(type: AssetType, newAssetConfig: AssetModel, currentAssetConfig: AssetModel): AssetModel? =
when (currentAssetConfig.folder) {
"" -> {
// Just load new assets
newAssetConfig
}
newAssetConfig.folder -> {
if (hotReloading) {
if (newAssetConfig.hotReloading) {
// removeAssets(newAssetConfig.type)
println("INFO: Reload $type assets '${newAssetConfig.folder}'.")
newAssetConfig
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ import kotlinx.serialization.*
* Entity config for a dialog box which appears on the dialog layer in front of any game play.
* Dialog Box is rendered on indexLayer 100 - 102 in foreground on [FG_DIALOGS][RenderLayerTag.FG_DIALOGS] layer.
*/
@Serializable @SerialName("DialogBox")
@Serializable @SerialName("DialogBoxConfig")
data class DialogBoxConfig(
override val name: String,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import korlibs.korge.fleks.assets.*
import korlibs.korge.fleks.components.*
import korlibs.korge.fleks.entity.*
import korlibs.korge.fleks.tags.*
import kotlinx.serialization.Serializable
import kotlinx.serialization.*


/**
Expand All @@ -15,7 +15,7 @@ import kotlinx.serialization.Serializable
*
* Logo can be centered on the screen and additionally an offset can be specified.
*/
@Serializable
@Serializable @SerialName("LogoEntityConfig")
data class LogoEntityConfig(
override val name: String,

Expand Down

0 comments on commit 2dc020c

Please sign in to comment.