diff --git a/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/CustomFlashEvent.kt b/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/CustomFlashEvent.kt new file mode 100644 index 0000000..6d9abcd --- /dev/null +++ b/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/CustomFlashEvent.kt @@ -0,0 +1,49 @@ +package cn.rdlevel.rdkt.core.events + + +import cn.rdlevel.rdkt.core.data.* +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +/** + * Emits a flash with custom settings. + * @property startColor The start color of the flash. + * @property startOpacity The start opacity of the flash. + * @property endColor The end color of the flash. + * @property endOpacity The end opacity of the flash. + * @property background Whether the flash should be a background flash or a foreground flash. + */ +@Serializable +@SerialName("CustomFlash") +public data class CustomFlashEvent( + var startColor: Color? = WHITE, + var startOpacity: Int? = 100, + var endColor: Color? = WHITE, + var endOpacity: Int? = 0, + var background: Boolean = false, + override var duration: Double = 2.0, + override var ease: Easing = Easing.LINEAR, + override var rooms: RoomsOrTopLayer = roomsOf(ROOM1), +) : ActionEvent(), MutableRoomsOrTopLayerSpecificEvent, DurationEaseSpecificEvent { + /** + * The start color and opacity converted into [ColorWithAlpha]. + * It will be null if either the color or the opacity is null. + */ + var start: ColorWithAlpha? + get() = startOpacity?.let { startColor?.withAlpha((it * 255 / 100).coerceIn(0, 255)) } + set(value) { + startColor = value + startOpacity = value?.alpha?.let { it * 100 / 255 } + } + + /** + * The end color and opacity converted into [ColorWithAlpha]. + * It will be null if either the color or the opacity is null. + */ + var end: ColorWithAlpha? + get() = endOpacity?.let { endColor?.withAlpha((it * 255 / 100).coerceIn(0, 255)) } + set(value) { + endColor = value + endOpacity = value?.alpha?.let { it * 100 / 255 } + } +} \ No newline at end of file diff --git a/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/EventProperties.kt b/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/EventProperties.kt index 5be580a..fbcb1c8 100644 --- a/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/EventProperties.kt +++ b/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/EventProperties.kt @@ -43,6 +43,21 @@ public interface DurationSpecificEvent : Event { public var duration: Double } +/** + * An [Event] that has an easing, meaning it can have a smooth transition over time. + */ +public interface EaseSpecificEvent : Event { + /** + * The easing of the event. + */ + public var ease: Easing +} + +/** + * An [Event] that both has a duration and an easing. + */ +public interface DurationEaseSpecificEvent : DurationSpecificEvent, EaseSpecificEvent + /** * An [Event] that is specific to a single row. */ 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 12bdf2e..d363b4f 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 @@ -25,7 +25,7 @@ public data class SetBackgroundColorEvent( @Flatten private var type: GroundType, var filter: RescaleFilter = RescaleFilter.NEAREST_NEIGHBOR, - override val rooms: RoomsOrTopLayer = roomsOf(ROOM1), -) : ActionEvent(), RoomsOrTopLayerSpecificEvent { + override var rooms: RoomsOrTopLayer = roomsOf(ROOM1), +) : ActionEvent(), MutableRoomsOrTopLayerSpecificEvent { 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 index 870fe25..86df9c3 100644 --- a/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/SetForegroundEvent.kt +++ b/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/SetForegroundEvent.kt @@ -11,13 +11,17 @@ import cn.rdlevel.rdkt.core.serialization.Flatten import cn.rdlevel.rdkt.core.serialization.flatten import kotlinx.serialization.* +/** + * Set foreground of rooms. + * @property type The type of the foreground. + */ @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 { + override var rooms: RoomsOrTopLayer = roomsOf(ROOM1), +) : ActionEvent(), MutableRoomsOrTopLayerSpecificEvent { public object Serializer : KSerializer by generatedSerializer().flatten() } diff --git a/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/SetSpeedEvent.kt b/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/SetSpeedEvent.kt index 54d256e..4cb896f 100644 --- a/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/SetSpeedEvent.kt +++ b/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/SetSpeedEvent.kt @@ -5,6 +5,12 @@ import cn.rdlevel.rdkt.core.data.Easing import kotlinx.serialization.SerialName import kotlinx.serialization.Serializable +/** + * Sets the speed of the level. Usually it will affect the speed of the event animations. + * @property speed The speed multiplier. 1.0 is the normal speed. + * @property duration The time to change to the target speed in beats. + * @property ease The easing function to use when changing the speed. + */ @Serializable @SerialName("SetSpeed") public data class SetSpeedEvent(