Added some templates for events.

This commit is contained in:
2025-06-24 14:35:09 +08:00
parent c57eb97da2
commit e8bd46ffd9
4 changed files with 132 additions and 1 deletions
@@ -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)
}
@@ -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
}
@@ -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
}
@@ -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()