diff --git a/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/data/action/GroundType.kt b/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/data/action/GroundType.kt new file mode 100644 index 0000000..6cdc6f6 --- /dev/null +++ b/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/data/action/GroundType.kt @@ -0,0 +1,53 @@ +@file:OptIn(ExperimentalSerializationApi::class, RDKTInternalAPI::class) + +package cn.rdlevel.rdkt.core.data.action + +import cn.rdlevel.rdkt.core.annotations.RDKTInternalAPI +import cn.rdlevel.rdkt.core.data.ColorWithAlpha +import cn.rdlevel.rdkt.core.data.WHITE +import cn.rdlevel.rdkt.core.serialization.Flatten +import cn.rdlevel.rdkt.core.serialization.flatten +import kotlinx.serialization.* +import kotlinx.serialization.json.JsonClassDiscriminator + +/** + * Represents the type and the settings of the background. + */ +@Serializable +@JsonClassDiscriminator("backgroundType") +public sealed class GroundType { + /** + * The color of the background. + */ + public abstract var color: ColorWithAlpha + + /** + * Represents a pure color background. + */ + @SerialName("Color") + @Serializable + public data class Color(override var color: ColorWithAlpha = WHITE) : GroundType() + + /** + * Represents a background with images. + * + * @property image The images to be used. When there's none, it clears the image background. When there are multiple, they will be played in a loop. + * @property color The color filter to be applied on images. + * @property fps The speed of the image loop in frames per second when there are multiple images. + * @property contentMode The content mode of the images. + * @property tilingConfig The tiling configuration of the images when [contentMode] is [ContentMode.TILED]. + */ + @SerialName("Image") + @Serializable(Image.Serializer::class) + @KeepGeneratedSerializer + public data class Image( + var image: List = listOf(), + override var color: ColorWithAlpha = WHITE, + var fps: Double = 30.0, + var contentMode: ContentMode = ContentMode.SCALE_TO_FILL, + @Flatten + var tilingConfig: TilingConfig = TilingConfig() + ) : GroundType() { + public object Serializer : KSerializer by generatedSerializer().flatten() + } +} \ No newline at end of file diff --git a/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/SetBackgroundColorEvent.kt b/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/SetBackgroundColorEvent.kt index 3508812..12bdf2e 100644 --- a/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/SetBackgroundColorEvent.kt +++ b/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/SetBackgroundColorEvent.kt @@ -4,71 +4,28 @@ package cn.rdlevel.rdkt.core.events import cn.rdlevel.rdkt.core.annotations.RDKTInternalAPI -import cn.rdlevel.rdkt.core.data.* -import cn.rdlevel.rdkt.core.data.action.ContentMode +import cn.rdlevel.rdkt.core.data.ROOM1 +import cn.rdlevel.rdkt.core.data.RoomsOrTopLayer +import cn.rdlevel.rdkt.core.data.action.GroundType import cn.rdlevel.rdkt.core.data.action.RescaleFilter -import cn.rdlevel.rdkt.core.data.action.TilingConfig +import cn.rdlevel.rdkt.core.data.roomsOf import cn.rdlevel.rdkt.core.serialization.Flatten import cn.rdlevel.rdkt.core.serialization.flatten import kotlinx.serialization.* -import kotlinx.serialization.json.JsonClassDiscriminator /** * Sets the background of rooms. * @property type The type of the background. * @property filter How should the pixels' color of the background be when rescaled. */ -@ConsistentCopyVisibility @Serializable(SetBackgroundColorEvent.Serializer::class) @KeepGeneratedSerializer @SerialName("SetBackgroundColor") -public data class SetBackgroundColorEvent private constructor( +public data class SetBackgroundColorEvent( @Flatten - private var type: Type, + private var type: GroundType, var filter: RescaleFilter = RescaleFilter.NEAREST_NEIGHBOR, override val rooms: RoomsOrTopLayer = roomsOf(ROOM1), ) : ActionEvent(), RoomsOrTopLayerSpecificEvent { - /** - * Represents the type and the settings of the background. - */ - @Serializable - @JsonClassDiscriminator("backgroundType") - public sealed class Type { - /** - * The color of the background. - */ - public abstract var color: ColorWithAlpha - - /** - * Represents a pure color background. - */ - @SerialName("Color") - @Serializable - public data class Color(override var color: ColorWithAlpha = WHITE) : Type() - - /** - * Represents a background with images. - * - * @property image The images to be used. When there's none, it clears the image background. When there are multiple, they will be played in a loop. - * @property color The color filter to be applied on images. - * @property fps The speed of the image loop in frames per second when there are multiple images. - * @property contentMode The content mode of the images. - * @property tilingConfig The tiling configuration of the images when [contentMode] is [ContentMode.TILED]. - */ - @SerialName("Image") - @Serializable(Image.Serializer::class) - @KeepGeneratedSerializer - public data class Image( - var image: List = listOf(), - override var color: ColorWithAlpha = WHITE, - var fps: Double = 30.0, - var contentMode: ContentMode = ContentMode.SCALE_TO_FILL, - @Flatten - var tilingConfig: TilingConfig = TilingConfig() - ) : Type() { - public object Serializer : KSerializer by generatedSerializer().flatten() - } - } - public object Serializer : KSerializer by generatedSerializer().flatten() } \ No newline at end of file diff --git a/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/SetForegroundEvent.kt b/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/SetForegroundEvent.kt new file mode 100644 index 0000000..870fe25 --- /dev/null +++ b/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/SetForegroundEvent.kt @@ -0,0 +1,23 @@ +@file:OptIn(RDKTInternalAPI::class, ExperimentalSerializationApi::class) + +package cn.rdlevel.rdkt.core.events + +import cn.rdlevel.rdkt.core.annotations.RDKTInternalAPI +import cn.rdlevel.rdkt.core.data.ROOM1 +import cn.rdlevel.rdkt.core.data.RoomsOrTopLayer +import cn.rdlevel.rdkt.core.data.action.GroundType +import cn.rdlevel.rdkt.core.data.roomsOf +import cn.rdlevel.rdkt.core.serialization.Flatten +import cn.rdlevel.rdkt.core.serialization.flatten +import kotlinx.serialization.* + +@Serializable(SetForegroundEvent.Serializer::class) +@KeepGeneratedSerializer +@SerialName("SetForeground") +public data class SetForegroundEvent( + @Flatten + private var type: GroundType.Image, + override val rooms: RoomsOrTopLayer = roomsOf(ROOM1), +) : ActionEvent(), RoomsOrTopLayerSpecificEvent { + public object Serializer : KSerializer by generatedSerializer().flatten() +}