Skip to content

Commit

Permalink
Add idea in comments for EntityConfig serialization
Browse files Browse the repository at this point in the history
  • Loading branch information
jobe-m committed Jul 17, 2024
1 parent 119ba89 commit aadb295
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,11 @@ object EntityFactory {
*/
interface EntityConfig {
val name: String
// TODO idea to make game object data serializable
//val data: Any

val configureEntity: (World, Entity) -> Entity
// TODO add possibility for a specific entityConfig at creation of the game object
// TODO - check if this is really needed - add possibility for a specific entityConfig at creation of the game object
//val configureEntity: (World, Entity, EntityConfig) -> Entity
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,18 @@ import korlibs.korge.fleks.entity.*
import korlibs.korge.fleks.entity.EntityFactory.EntityConfig
import korlibs.korge.fleks.tags.*
import korlibs.math.interpolation.*
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.
*/
data class DialogBoxConfig(
override val name: String,

// TODO
// override val data: Any,

val duration: Float,

// Position and size
Expand Down Expand Up @@ -45,6 +50,39 @@ data class DialogBoxConfig(

enum class AvatarPosition { LEFT_TOP, RIGHT_TOP /*, LEFT_BOTTOM, RIGHT_BOTTOM*/ }

// TODO idea to make game object data serializable
// Private local data for game object configuration
@Serializable @SerialName("DialogBoxConfig")
data class DialogBoxConfig(
val duration: Float,

// Position and size
val x: Float = 0f,
val y: Float = 0f,
val width: Float,
val height: Float,

// Color and alpha channel of text and graphics
val tint: RgbaComponent.Rgb = RgbaComponent.Rgb.WHITE,
val alpha: Float = 0f,

// Avatar
val avatarMoveX: Float = 10f,
val avatarName: String,
val avatarPosition: AvatarPosition,

// Text field
val textFieldName: String,

// Text
val text: String,
val textFontName: String,
val textRangeEnd: Int = 0, // initial value for drawing the text into the dialog
// TODO Add serializer
// val horizontalAlign: HorizontalAlign = HorizontalAlign.LEFT,
// val verticalAlign: VerticalAlign = VerticalAlign.TOP,
)

override val configureEntity = fun(world: World, entity: Entity) : Entity = with(world) {
val avatarLeftInitialX = x + 10f
val avatarRightInitialX = AppConfig.TARGET_VIRTUAL_WIDTH - 20f - 38f
Expand Down

0 comments on commit aadb295

Please sign in to comment.