mirror of
https://github.com/RDCN-Community-Developers/rdkt.git
synced 2026-09-05 01:35:31 +08:00
Fixed events using custom serializers don't serialize base properties.
This commit is contained in:
@@ -55,4 +55,14 @@ public sealed class AbstractEvent: Event {
|
|||||||
override var tag: String? = null
|
override var tag: String? = null
|
||||||
|
|
||||||
override var runTag: Boolean = false
|
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
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -9,6 +9,11 @@ import kotlinx.serialization.Serializable
|
|||||||
@Serializable
|
@Serializable
|
||||||
public sealed class SoundEvent : AbstractEvent(), YSpecificEvent {
|
public sealed class SoundEvent : AbstractEvent(), YSpecificEvent {
|
||||||
override var y: Int = 0
|
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)
|
BeatSpecificEvent.requireBeatInBound(value)
|
||||||
field = 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
|
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
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
@@ -60,11 +60,11 @@ public data class PulseFreeTimeBeatEvent @JvmOverloads constructor(
|
|||||||
|
|
||||||
public object Serializer : TransformSerializer<PulseFreeTimeBeatEvent, Serializer.Data>(Data.serializer()) {
|
public object Serializer : TransformSerializer<PulseFreeTimeBeatEvent, Serializer.Data>(Data.serializer()) {
|
||||||
override fun toData(value: PulseFreeTimeBeatEvent): Data {
|
override fun toData(value: PulseFreeTimeBeatEvent): Data {
|
||||||
return Data(
|
return Data.fromBase(value).apply {
|
||||||
action = value.action.action,
|
action = value.action.action
|
||||||
hold = value.hold,
|
hold = value.hold
|
||||||
customPulse = (value.action as? Action.Custom)?.pulse,
|
customPulse = (value.action as? Action.Custom)?.pulse
|
||||||
)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fromData(data: Data): PulseFreeTimeBeatEvent {
|
override fun fromData(data: Data): PulseFreeTimeBeatEvent {
|
||||||
@@ -78,7 +78,7 @@ public data class PulseFreeTimeBeatEvent @JvmOverloads constructor(
|
|||||||
return PulseFreeTimeBeatEvent(
|
return PulseFreeTimeBeatEvent(
|
||||||
action = action,
|
action = action,
|
||||||
hold = data.hold,
|
hold = data.hold,
|
||||||
)
|
).apply { copyBaseFrom(data) }
|
||||||
}
|
}
|
||||||
|
|
||||||
@RDKTInternalAPI
|
@RDKTInternalAPI
|
||||||
@@ -87,6 +87,12 @@ public data class PulseFreeTimeBeatEvent @JvmOverloads constructor(
|
|||||||
var action: String = "Increment",
|
var action: String = "Increment",
|
||||||
var hold: Int = 0,
|
var hold: Int = 0,
|
||||||
var customPulse: Int? = null,
|
var customPulse: Int? = null,
|
||||||
)
|
) : RowEvent() {
|
||||||
|
public companion object {
|
||||||
|
public fun fromBase(other: RowEvent): Data {
|
||||||
|
return Data().apply { copyBaseFrom(other) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -142,7 +142,9 @@ public data class SetRowXsEvent(
|
|||||||
|
|
||||||
public object Serializer : TransformSerializer<SetRowXsEvent, Serializer.Data>(Data.serializer()) {
|
public object Serializer : TransformSerializer<SetRowXsEvent, Serializer.Data>(Data.serializer()) {
|
||||||
override fun toData(value: SetRowXsEvent): Data {
|
override fun toData(value: SetRowXsEvent): Data {
|
||||||
return Data(pattern = value.pattern).apply {
|
return Data.fromBase(value).apply {
|
||||||
|
pattern = value.pattern
|
||||||
|
|
||||||
val synco = value.synco
|
val synco = value.synco
|
||||||
syncoBeat = synco.beat
|
syncoBeat = synco.beat
|
||||||
if (synco !is SyncoSettings.Enabled) {
|
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
|
@Serializable
|
||||||
@@ -196,6 +198,12 @@ public data class SetRowXsEvent(
|
|||||||
var syncoStyle: String = "Chirp",
|
var syncoStyle: String = "Chirp",
|
||||||
var syncoPlayModifierSound: Boolean = true,
|
var syncoPlayModifierSound: Boolean = true,
|
||||||
var syncoPlayModifierOffSound: Boolean = true,
|
var syncoPlayModifierOffSound: Boolean = true,
|
||||||
)
|
) : RowEvent() {
|
||||||
|
public companion object {
|
||||||
|
public fun fromBase(other: RowEvent): Data {
|
||||||
|
return Data().apply { copyBaseFrom(other) }
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user