diff --git a/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/CustomEvent.kt b/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/CustomEvent.kt new file mode 100644 index 0000000..cca02db --- /dev/null +++ b/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/CustomEvent.kt @@ -0,0 +1,17 @@ +package cn.rdlevel.rdkt.core.events + +import cn.rdlevel.rdkt.core.RDLevel + +/** + * An event that can be customized by the developers. + * Developers are encouraged to use this interface to create their own custom events. + */ +public abstract class CustomEvent : AbstractEvent() { + /** + * Applies this event to the given level. + * This method should be overridden by custom events to define how they affect the level. + * + * @param level The level to apply this event to. + */ + public abstract fun applyToLevel(level: RDLevel) +} \ No newline at end of file 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 7a55f46..91fed97 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 @@ -1,4 +1,57 @@ package cn.rdlevel.rdkt.core.events -public interface Event { +import kotlinx.serialization.SerialName +import kotlinx.serialization.Serializable + +/** + * A base event interface. Custom levels use events to perform actions. + */ +@Serializable +public sealed interface Event { + /** + * The bar the event is in. + */ + public var bar: Int + + /** + * The beat the event is in. + * Note that this is immutable by default. See [BeatSpecificEvent] for the mutable version. + */ + public val beat: Double + get() = 1.0 + + /** + * Whether the event will be executed or not. + */ + public var active: Boolean + + /** + * The tag of the event. + * Can be used to group events together. + */ + @SerialName("Tag") + public var tag: String? + + /** + * Whether the event should be run on its position even when a [tag] is set. + * By default, tagged events are not run on their position. + */ + public var runTag: Boolean +} + +/** + * An abstraction of an [Event] that provides default implementations for some properties. + */ +public sealed class AbstractEvent: Event { + override var bar: Int = 1 + set(value) { + require(value >= 1) { "Bar must be greater than or equal to 1." } + field = value + } + + override var active: Boolean = true + + override var tag: String? = null + + override var runTag: Boolean = false } \ 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 new file mode 100644 index 0000000..cf3ad74 --- /dev/null +++ b/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/EventProperties.kt @@ -0,0 +1,33 @@ +package cn.rdlevel.rdkt.core.events + +/** + * An [Event] that can specify a beat manually. + */ +public interface BeatSpecificEvent : Event { + /** + * The beat the event is in. + * This property is mutable, allowing the beat to be set directly. + */ + override var beat: Double +} + +/** + * An [Event] that is specific to a Y position, aka the row position in the editor. + */ +public interface YSpecificEvent : Event { + /** + * The Y position the event is in. + * Setting this to negative values will hide the event from the editor. + */ + public var y: Int +} + +/** + * An [Event] that has a duration, meaning it lasts for a certain number of beats. + */ +public interface DurationSpecificEvent : Event { + /** + * The duration of the event in beats. + */ + public var duration: Double +} \ 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 new file mode 100644 index 0000000..6f97eb2 --- /dev/null +++ b/core/src/commonMain/kotlin/cn/rdlevel/rdkt/core/events/EventTabs.kt @@ -0,0 +1,28 @@ +package cn.rdlevel.rdkt.core.events + +/** + * An event that belongs to the sounds tab. + */ +public sealed class SoundEvent : AbstractEvent(), YSpecificEvent { + override var y: Int = 0 +} + +/** + * An event that belongs to the rows tab. + */ +public sealed class RowEvent : AbstractEvent() + +/** + * An event that belongs to the actions tab. + */ +public sealed class ActionEvent : AbstractEvent() + +/** + * An event that belongs to the rooms tab. + */ +public sealed class RoomEvent : AbstractEvent() + +/** + * An event that belongs to the decorations tab. + */ +public sealed class DecorationEvent : AbstractEvent() \ No newline at end of file