From f5413f92ffe386131779c231d6f048263d3ebccb Mon Sep 17 00:00:00 2001 From: NoMathExpectation <85624722+NoMathExpectation@users.noreply.github.com> Date: Sun, 8 Mar 2026 01:10:05 +0800 Subject: [PATCH] Fixed events using custom serializers don't serialize base properties. --- .../cn/rdlevel/rdkt/core/events/Event.kt | 10 ++++++++++ .../cn/rdlevel/rdkt/core/events/EventTabs.kt | 17 ++++++++++++++++ .../core/events/PulseFreeTimeBeatEvent.kt | 20 ++++++++++++------- .../rdlevel/rdkt/core/events/SetRowXsEvent.kt | 14 ++++++++++--- 4 files changed, 51 insertions(+), 10 deletions(-) diff --git a/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/Event.kt b/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/Event.kt index 438ecb1..e788cee 100644 --- a/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/Event.kt +++ b/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/Event.kt @@ -55,4 +55,14 @@ public sealed class AbstractEvent: Event { override var tag: String? = null override var runTag: Boolean = false + + /** + * Copies base properties from another [AbstractEvent] to this event. This is mainly for serialization and deserialization that uses custom serializers. + */ + protected fun copyBaseFrom(other: AbstractEvent) { + this.bar = other.bar + this.active = other.active + this.tag = other.tag + this.runTag = other.runTag + } } \ No newline at end of file diff --git a/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/EventTabs.kt b/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/EventTabs.kt index cd2579c..0982fb9 100644 --- a/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/EventTabs.kt +++ b/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/EventTabs.kt @@ -9,6 +9,11 @@ import kotlinx.serialization.Serializable @Serializable public sealed class SoundEvent : AbstractEvent(), YSpecificEvent { override var y: Int = 0 + + protected fun copyBaseFrom(other: SoundEvent) { + super.copyBaseFrom(other) + this.y = other.y + } } /** @@ -21,6 +26,11 @@ public sealed class BeatSpecificSoundEvent : BeatSpecificEvent, SoundEvent() { BeatSpecificEvent.requireBeatInBound(value) field = value } + + protected fun copyBaseFrom(other: BeatSpecificSoundEvent) { + super.copyBaseFrom(other) + this.beat = other.beat + } } /** @@ -46,6 +56,13 @@ public sealed class RowEvent : AbstractEvent(), BeatSpecificEvent, RowSpecificEv */ override var y: Int = 0 + protected fun copyBaseFrom(other: RowEvent) { + super.copyBaseFrom(other) + this.beat = other.beat + this.rowId = other.rowId + this.y = other.y + } + } /** diff --git a/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/PulseFreeTimeBeatEvent.kt b/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/PulseFreeTimeBeatEvent.kt index 4a693a2..18cde95 100644 --- a/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/PulseFreeTimeBeatEvent.kt +++ b/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/PulseFreeTimeBeatEvent.kt @@ -60,11 +60,11 @@ public data class PulseFreeTimeBeatEvent @JvmOverloads constructor( public object Serializer : TransformSerializer(Data.serializer()) { override fun toData(value: PulseFreeTimeBeatEvent): Data { - return Data( - action = value.action.action, - hold = value.hold, - customPulse = (value.action as? Action.Custom)?.pulse, - ) + return Data.fromBase(value).apply { + action = value.action.action + hold = value.hold + customPulse = (value.action as? Action.Custom)?.pulse + } } override fun fromData(data: Data): PulseFreeTimeBeatEvent { @@ -78,7 +78,7 @@ public data class PulseFreeTimeBeatEvent @JvmOverloads constructor( return PulseFreeTimeBeatEvent( action = action, hold = data.hold, - ) + ).apply { copyBaseFrom(data) } } @RDKTInternalAPI @@ -87,6 +87,12 @@ public data class PulseFreeTimeBeatEvent @JvmOverloads constructor( var action: String = "Increment", var hold: Int = 0, var customPulse: Int? = null, - ) + ) : RowEvent() { + public companion object { + public fun fromBase(other: RowEvent): Data { + return Data().apply { copyBaseFrom(other) } + } + } + } } } \ No newline at end of file diff --git a/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/SetRowXsEvent.kt b/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/SetRowXsEvent.kt index 8f4edca..c436f9e 100644 --- a/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/SetRowXsEvent.kt +++ b/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/SetRowXsEvent.kt @@ -142,7 +142,9 @@ public data class SetRowXsEvent( public object Serializer : TransformSerializer(Data.serializer()) { override fun toData(value: SetRowXsEvent): Data { - return Data(pattern = value.pattern).apply { + return Data.fromBase(value).apply { + pattern = value.pattern + val synco = value.synco syncoBeat = synco.beat if (synco !is SyncoSettings.Enabled) { @@ -182,7 +184,7 @@ public data class SetRowXsEvent( } } } - return SetRowXsEvent(pattern = data.pattern, synco = synco) + return SetRowXsEvent(pattern = data.pattern, synco = synco).apply { copyBaseFrom(data) } } @Serializable @@ -196,6 +198,12 @@ public data class SetRowXsEvent( var syncoStyle: String = "Chirp", var syncoPlayModifierSound: Boolean = true, var syncoPlayModifierOffSound: Boolean = true, - ) + ) : RowEvent() { + public companion object { + public fun fromBase(other: RowEvent): Data { + return Data().apply { copyBaseFrom(other) } + } + } + } } } \ No newline at end of file