mirror of
https://github.com/RDCN-Community-Developers/rdkt.git
synced 2026-09-05 17:55:32 +08:00
Rename SelectedRoomsAndTopLayer to RoomsAndTopLayer.
This commit is contained in:
+97
-97
@@ -1,5 +1,5 @@
|
|||||||
@file:OptIn(RDKTInternalAPI::class)
|
@file:OptIn(RDKTInternalAPI::class)
|
||||||
@file:JvmName("SelectedRoomUtil")
|
@file:JvmName("RoomsAndTopLayerUtil")
|
||||||
|
|
||||||
package cn.rdlevel.rdkt.core.data
|
package cn.rdlevel.rdkt.core.data
|
||||||
|
|
||||||
@@ -19,8 +19,8 @@ import kotlin.reflect.KClass
|
|||||||
* All implementations of this interface must contain at least one room, or the top layer.
|
* All implementations of this interface must contain at least one room, or the top layer.
|
||||||
* Failing to do so will result in an exception.
|
* Failing to do so will result in an exception.
|
||||||
*/
|
*/
|
||||||
@Serializable(SelectedRoomsAndTopLayer.Serializer::class)
|
@Serializable(RoomsAndTopLayer.Serializer::class)
|
||||||
public sealed interface SelectedRoomsAndTopLayer {
|
public sealed interface RoomsAndTopLayer {
|
||||||
/**
|
/**
|
||||||
* The room IDs that are selected.
|
* The room IDs that are selected.
|
||||||
*/
|
*/
|
||||||
@@ -42,11 +42,11 @@ public sealed interface SelectedRoomsAndTopLayer {
|
|||||||
return TOP_LAYER in rooms
|
return TOP_LAYER in rooms
|
||||||
}
|
}
|
||||||
|
|
||||||
public operator fun plus(other: SelectedRoomsAndTopLayer): SelectedRoomsAndTopLayer {
|
public operator fun plus(other: RoomsAndTopLayer): RoomsAndTopLayer {
|
||||||
return of(rooms + other.rooms)
|
return of(rooms + other.rooms)
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Impl(override val rooms: Set<Int>) : AbstractSelectedRoomsAndTopLayer(), SelectedRoomsAndTopLayer {
|
private class Impl(override val rooms: Set<Int>) : AbstractRoomsAndTopLayer(), RoomsAndTopLayer {
|
||||||
init {
|
init {
|
||||||
requireNotEmpty()
|
requireNotEmpty()
|
||||||
requireAllRoomsOrTopLayer()
|
requireAllRoomsOrTopLayer()
|
||||||
@@ -55,68 +55,68 @@ public sealed interface SelectedRoomsAndTopLayer {
|
|||||||
|
|
||||||
public companion object {
|
public companion object {
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of [SelectedRoomsAndTopLayer].
|
* Creates a new instance of [RoomsAndTopLayer].
|
||||||
*
|
*
|
||||||
* @param rooms The set of selected room IDs.
|
* @param rooms The set of selected room IDs.
|
||||||
* @return A new instance of [SelectedRoomsAndTopLayer] with the specified room IDs.
|
* @return A new instance of [RoomsAndTopLayer] with the specified room IDs.
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
public fun of(rooms: Set<Int>): SelectedRoomsAndTopLayer {
|
public fun of(rooms: Set<Int>): RoomsAndTopLayer {
|
||||||
return Impl(rooms)
|
return Impl(rooms)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of [SelectedRoomsAndTopLayer] with the specified room IDs.
|
* Creates a new instance of [RoomsAndTopLayer] with the specified room IDs.
|
||||||
*
|
*
|
||||||
* @param room The ID of the first selected room.
|
* @param room The ID of the first selected room.
|
||||||
* @param rooms Additional room IDs to include in the selection.
|
* @param rooms Additional room IDs to include in the selection.
|
||||||
* @return A new instance of [SelectedRoomsAndTopLayer] containing the specified room IDs.
|
* @return A new instance of [RoomsAndTopLayer] containing the specified room IDs.
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
public fun of(room: Int, vararg rooms: Int): SelectedRoomsAndTopLayer {
|
public fun of(room: Int, vararg rooms: Int): RoomsAndTopLayer {
|
||||||
return of(setOf(room) + rooms.toSet())
|
return of(setOf(room) + rooms.toSet())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public object Serializer :
|
public object Serializer :
|
||||||
TransformSerializer<SelectedRoomsAndTopLayer, Set<Int>>(
|
TransformSerializer<RoomsAndTopLayer, Set<Int>>(
|
||||||
"SelectedRoomsAndTopLayer",
|
"SelectedRoomsAndTopLayer",
|
||||||
kotlinx.serialization.serializer()
|
kotlinx.serialization.serializer()
|
||||||
) {
|
) {
|
||||||
override fun toData(value: SelectedRoomsAndTopLayer): Set<Int> {
|
override fun toData(value: RoomsAndTopLayer): Set<Int> {
|
||||||
return value.rooms
|
return value.rooms
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fromData(data: Set<Int>): SelectedRoomsAndTopLayer {
|
override fun fromData(data: Set<Int>): RoomsAndTopLayer {
|
||||||
return of(data)
|
return of(data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public operator fun SelectedRoomsAndTopLayer.contains(id: Int): Boolean {
|
public operator fun RoomsAndTopLayer.contains(id: Int): Boolean {
|
||||||
return containsRoom(id)
|
return containsRoom(id)
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun SelectedRoomsAndTopLayer.requireNotEmpty() {
|
private fun RoomsAndTopLayer.requireNotEmpty() {
|
||||||
require(rooms.isNotEmpty()) { "Selected rooms must not be empty." }
|
require(rooms.isNotEmpty()) { "Selected rooms must not be empty." }
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun SelectedRoomsAndTopLayer.requireAllRoomsOrTopLayer() {
|
private fun RoomsAndTopLayer.requireAllRoomsOrTopLayer() {
|
||||||
require(rooms.all { it in ROOM1..TOP_LAYER }) {
|
require(rooms.all { it in ROOM1..TOP_LAYER }) {
|
||||||
"Selected rooms must only contain room IDs from 0 to 3 or the top layer."
|
"Selected rooms must only contain room IDs from 0 to 3 or the top layer."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private fun SelectedRoomsAndTopLayer.requireAllRooms() {
|
private fun RoomsAndTopLayer.requireAllRooms() {
|
||||||
require(rooms.all { it in ROOM1..ROOM4 }) {
|
require(rooms.all { it in ROOM1..ROOM4 }) {
|
||||||
"Selected rooms must only contain room IDs from 0 to 3."
|
"Selected rooms must only contain room IDs from 0 to 3."
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private sealed class AbstractSelectedRoomsAndTopLayer : SelectedRoomsAndTopLayer {
|
private sealed class AbstractRoomsAndTopLayer : RoomsAndTopLayer {
|
||||||
override operator fun equals(other: Any?): Boolean {
|
override operator fun equals(other: Any?): Boolean {
|
||||||
if (this === other) return true
|
if (this === other) return true
|
||||||
if (other !is SelectedRoomsAndTopLayer) return false
|
if (other !is RoomsAndTopLayer) return false
|
||||||
return rooms == other.rooms
|
return rooms == other.rooms
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,18 +132,18 @@ private sealed class AbstractSelectedRoomsAndTopLayer : SelectedRoomsAndTopLayer
|
|||||||
/**
|
/**
|
||||||
* Represents a collection of either normal rooms or the top layer.
|
* Represents a collection of either normal rooms or the top layer.
|
||||||
*/
|
*/
|
||||||
@Serializable(SelectedRoomsOrTopLayer.Serializer::class)
|
@Serializable(RoomsOrTopLayer.Serializer::class)
|
||||||
public sealed interface SelectedRoomsOrTopLayer : SelectedRoomsAndTopLayer {
|
public sealed interface RoomsOrTopLayer : RoomsAndTopLayer {
|
||||||
public object Serializer :
|
public object Serializer :
|
||||||
TransformSerializer<SelectedRoomsOrTopLayer, Set<Int>>(
|
TransformSerializer<RoomsOrTopLayer, Set<Int>>(
|
||||||
"SelectedRoomsOrTopLayer",
|
"SelectedRoomsOrTopLayer",
|
||||||
SetSerializer(Int.serializer())
|
SetSerializer(Int.serializer())
|
||||||
) {
|
) {
|
||||||
override fun toData(value: SelectedRoomsOrTopLayer): Set<Int> {
|
override fun toData(value: RoomsOrTopLayer): Set<Int> {
|
||||||
return value.rooms
|
return value.rooms
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fromData(data: Set<Int>): SelectedRoomsOrTopLayer {
|
override fun fromData(data: Set<Int>): RoomsOrTopLayer {
|
||||||
return roomsOf(data)
|
return roomsOf(data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -152,8 +152,8 @@ public sealed interface SelectedRoomsOrTopLayer : SelectedRoomsAndTopLayer {
|
|||||||
/**
|
/**
|
||||||
* Represents a collection of either a normal room or the top layer.
|
* Represents a collection of either a normal room or the top layer.
|
||||||
*/
|
*/
|
||||||
@Serializable(SingleSelectedRoomOrTopLayer.Serializer::class)
|
@Serializable(SingleRoomOrTopLayer.Serializer::class)
|
||||||
public sealed interface SingleSelectedRoomOrTopLayer : SelectedRoomsOrTopLayer {
|
public sealed interface SingleRoomOrTopLayer : RoomsOrTopLayer {
|
||||||
/**
|
/**
|
||||||
* The single selected room ID.
|
* The single selected room ID.
|
||||||
*/
|
*/
|
||||||
@@ -171,15 +171,15 @@ public sealed interface SingleSelectedRoomOrTopLayer : SelectedRoomsOrTopLayer {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public object Serializer :
|
public object Serializer :
|
||||||
TransformSerializer<SingleSelectedRoomOrTopLayer, Set<Int>>(
|
TransformSerializer<SingleRoomOrTopLayer, Set<Int>>(
|
||||||
"SingleSelectedRoomOrTopLayer",
|
"SingleSelectedRoomOrTopLayer",
|
||||||
SetSerializer(Int.serializer())
|
SetSerializer(Int.serializer())
|
||||||
) {
|
) {
|
||||||
override fun toData(value: SingleSelectedRoomOrTopLayer): Set<Int> {
|
override fun toData(value: SingleRoomOrTopLayer): Set<Int> {
|
||||||
return value.rooms
|
return value.rooms
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fromData(data: Set<Int>): SingleSelectedRoomOrTopLayer {
|
override fun fromData(data: Set<Int>): SingleRoomOrTopLayer {
|
||||||
return roomsOf(data)
|
return roomsOf(data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -188,13 +188,13 @@ public sealed interface SingleSelectedRoomOrTopLayer : SelectedRoomsOrTopLayer {
|
|||||||
/**
|
/**
|
||||||
* Represents a collection of selected rooms, not including the top layer.
|
* Represents a collection of selected rooms, not including the top layer.
|
||||||
*/
|
*/
|
||||||
@Serializable(SelectedRooms.Serializer::class)
|
@Serializable(Rooms.Serializer::class)
|
||||||
public sealed interface SelectedRooms : SelectedRoomsOrTopLayer {
|
public sealed interface Rooms : RoomsOrTopLayer {
|
||||||
public operator fun plus(other: SelectedRooms): SelectedRooms {
|
public operator fun plus(other: Rooms): Rooms {
|
||||||
return of(rooms + other.rooms)
|
return of(rooms + other.rooms)
|
||||||
}
|
}
|
||||||
|
|
||||||
private class Impl(override val rooms: Set<Int>) : AbstractSelectedRoomsAndTopLayer(), SelectedRooms {
|
private class Impl(override val rooms: Set<Int>) : AbstractRoomsAndTopLayer(), Rooms {
|
||||||
init {
|
init {
|
||||||
requireNotEmpty()
|
requireNotEmpty()
|
||||||
requireAllRooms()
|
requireAllRooms()
|
||||||
@@ -203,36 +203,36 @@ public sealed interface SelectedRooms : SelectedRoomsOrTopLayer {
|
|||||||
|
|
||||||
public companion object {
|
public companion object {
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of [SelectedRooms].
|
* Creates a new instance of [Rooms].
|
||||||
*
|
*
|
||||||
* @param rooms The set of selected room IDs.
|
* @param rooms The set of selected room IDs.
|
||||||
* @return A new instance of [SelectedRooms] with the specified room IDs.
|
* @return A new instance of [Rooms] with the specified room IDs.
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
public fun of(rooms: Set<Int>): SelectedRooms {
|
public fun of(rooms: Set<Int>): Rooms {
|
||||||
return Impl(rooms)
|
return Impl(rooms)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of [SelectedRooms] with the specified room IDs.
|
* Creates a new instance of [Rooms] with the specified room IDs.
|
||||||
*
|
*
|
||||||
* @param room The ID of the first selected room.
|
* @param room The ID of the first selected room.
|
||||||
* @param rooms Additional room IDs to include in the selection.
|
* @param rooms Additional room IDs to include in the selection.
|
||||||
* @return A new instance of [SelectedRooms] containing the specified room IDs.
|
* @return A new instance of [Rooms] containing the specified room IDs.
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
public fun of(room: Int, vararg rooms: Int): SelectedRooms {
|
public fun of(room: Int, vararg rooms: Int): Rooms {
|
||||||
return of(setOf(room) + rooms.toSet())
|
return of(setOf(room) + rooms.toSet())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public object Serializer :
|
public object Serializer :
|
||||||
TransformSerializer<SelectedRooms, Set<Int>>("SelectedRooms", SetSerializer(Int.serializer())) {
|
TransformSerializer<Rooms, Set<Int>>("SelectedRooms", SetSerializer(Int.serializer())) {
|
||||||
override fun toData(value: SelectedRooms): Set<Int> {
|
override fun toData(value: Rooms): Set<Int> {
|
||||||
return value.rooms
|
return value.rooms
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fromData(data: Set<Int>): SelectedRooms {
|
override fun fromData(data: Set<Int>): Rooms {
|
||||||
return of(data)
|
return of(data)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -241,32 +241,32 @@ public sealed interface SelectedRooms : SelectedRoomsOrTopLayer {
|
|||||||
/**
|
/**
|
||||||
* Represents the selected top layer.
|
* Represents the selected top layer.
|
||||||
*/
|
*/
|
||||||
@Serializable(SelectedTopLayer.Serializer::class)
|
@Serializable(TopLayer.Serializer::class)
|
||||||
public sealed interface SelectedTopLayer : SingleSelectedRoomOrTopLayer {
|
public sealed interface TopLayer : SingleRoomOrTopLayer {
|
||||||
override val room: Int
|
override val room: Int
|
||||||
get() = TOP_LAYER
|
get() = TOP_LAYER
|
||||||
|
|
||||||
private object Impl : AbstractSelectedRoomsAndTopLayer(), SelectedTopLayer
|
private object Impl : AbstractRoomsAndTopLayer(), TopLayer
|
||||||
|
|
||||||
public companion object {
|
public companion object {
|
||||||
/**
|
/**
|
||||||
* Gets the instance of [SelectedTopLayer].
|
* Gets the instance of [TopLayer].
|
||||||
*
|
*
|
||||||
* @return The instance of [SelectedTopLayer].
|
* @return The instance of [TopLayer].
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
public fun of(): SelectedTopLayer {
|
public fun of(): TopLayer {
|
||||||
return Impl
|
return Impl
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public object Serializer :
|
public object Serializer :
|
||||||
TransformSerializer<SelectedTopLayer, Set<Int>>("SelectedTopLayer", SetSerializer(Int.serializer())) {
|
TransformSerializer<TopLayer, Set<Int>>("SelectedTopLayer", SetSerializer(Int.serializer())) {
|
||||||
override fun toData(value: SelectedTopLayer): Set<Int> {
|
override fun toData(value: TopLayer): Set<Int> {
|
||||||
return value.rooms
|
return value.rooms
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fromData(data: Set<Int>): SelectedTopLayer {
|
override fun fromData(data: Set<Int>): TopLayer {
|
||||||
require(TOP_LAYER in data && data.size == 1) { "SelectedTopLayer must be created with the top layer ID." }
|
require(TOP_LAYER in data && data.size == 1) { "SelectedTopLayer must be created with the top layer ID." }
|
||||||
return of()
|
return of()
|
||||||
}
|
}
|
||||||
@@ -276,9 +276,9 @@ public sealed interface SelectedTopLayer : SingleSelectedRoomOrTopLayer {
|
|||||||
/**
|
/**
|
||||||
* Represents a single selected room, not including the top layer.
|
* Represents a single selected room, not including the top layer.
|
||||||
*/
|
*/
|
||||||
@Serializable(SingleSelectedRoom.Serializer::class)
|
@Serializable(SingleRoom.Serializer::class)
|
||||||
public sealed interface SingleSelectedRoom : SingleSelectedRoomOrTopLayer, SelectedRooms {
|
public sealed interface SingleRoom : SingleRoomOrTopLayer, Rooms {
|
||||||
private class Impl(override val room: Int) : AbstractSelectedRoomsAndTopLayer(), SingleSelectedRoom {
|
private class Impl(override val room: Int) : AbstractRoomsAndTopLayer(), SingleRoom {
|
||||||
init {
|
init {
|
||||||
requireAllRooms()
|
requireAllRooms()
|
||||||
}
|
}
|
||||||
@@ -286,24 +286,24 @@ public sealed interface SingleSelectedRoom : SingleSelectedRoomOrTopLayer, Selec
|
|||||||
|
|
||||||
public companion object {
|
public companion object {
|
||||||
/**
|
/**
|
||||||
* Creates a new instance of [SingleSelectedRoom].
|
* Creates a new instance of [SingleRoom].
|
||||||
*
|
*
|
||||||
* @param room The ID of the selected room.
|
* @param room The ID of the selected room.
|
||||||
* @return A new instance of [SingleSelectedRoom] with the specified room ID.
|
* @return A new instance of [SingleRoom] with the specified room ID.
|
||||||
*/
|
*/
|
||||||
@JvmStatic
|
@JvmStatic
|
||||||
public fun of(room: Int): SingleSelectedRoom {
|
public fun of(room: Int): SingleRoom {
|
||||||
return Impl(room)
|
return Impl(room)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public object Serializer :
|
public object Serializer :
|
||||||
TransformSerializer<SingleSelectedRoom, Set<Int>>("SingleSelectedRoom", SetSerializer(Int.serializer())) {
|
TransformSerializer<SingleRoom, Set<Int>>("SingleSelectedRoom", SetSerializer(Int.serializer())) {
|
||||||
override fun toData(value: SingleSelectedRoom): Set<Int> {
|
override fun toData(value: SingleRoom): Set<Int> {
|
||||||
return value.rooms
|
return value.rooms
|
||||||
}
|
}
|
||||||
|
|
||||||
override fun fromData(data: Set<Int>): SingleSelectedRoom {
|
override fun fromData(data: Set<Int>): SingleRoom {
|
||||||
require(data.size == 1) { "SingleSelectedRoom must contain exactly one room." }
|
require(data.size == 1) { "SingleSelectedRoom must contain exactly one room." }
|
||||||
return of(data.first())
|
return of(data.first())
|
||||||
}
|
}
|
||||||
@@ -336,44 +336,44 @@ public const val ROOM4: Int = 3
|
|||||||
public const val TOP_LAYER: Int = 4
|
public const val TOP_LAYER: Int = 4
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an instance of [SelectedRoomsAndTopLayer] based on the provided [KClass] and set of room IDs.
|
* Creates an instance of [RoomsAndTopLayer] based on the provided [KClass] and set of room IDs.
|
||||||
*
|
*
|
||||||
* @param T The type of [SelectedRoomsAndTopLayer] to create.
|
* @param T The type of [RoomsAndTopLayer] to create.
|
||||||
* @param kClass The [KClass] of the type to create.
|
* @param kClass The [KClass] of the type to create.
|
||||||
* @param rooms The set of room IDs to include in the selection.
|
* @param rooms The set of room IDs to include in the selection.
|
||||||
* @return An instance of [SelectedRoomsAndTopLayer] of the specified type.
|
* @return An instance of [RoomsAndTopLayer] of the specified type.
|
||||||
*/
|
*/
|
||||||
@JvmSynthetic
|
@JvmSynthetic
|
||||||
@RDKTInternalAPI
|
@RDKTInternalAPI
|
||||||
public fun <T : SelectedRoomsAndTopLayer> roomsOf(kClass: KClass<T>, rooms: Set<Int>): T {
|
public fun <T : RoomsAndTopLayer> roomsOf(kClass: KClass<T>, rooms: Set<Int>): T {
|
||||||
@Suppress("UNCHECKED_CAST")
|
@Suppress("UNCHECKED_CAST")
|
||||||
return when (kClass) {
|
return when (kClass) {
|
||||||
SelectedRoomsAndTopLayer::class -> SelectedRoomsAndTopLayer.of(rooms)
|
RoomsAndTopLayer::class -> RoomsAndTopLayer.of(rooms)
|
||||||
SelectedRoomsOrTopLayer::class -> {
|
RoomsOrTopLayer::class -> {
|
||||||
when {
|
when {
|
||||||
TOP_LAYER in rooms && rooms.size > 1 -> error("Cannot have both top layer and other rooms selected.")
|
TOP_LAYER in rooms && rooms.size > 1 -> error("Cannot have both top layer and other rooms selected.")
|
||||||
TOP_LAYER in rooms -> SelectedTopLayer.of()
|
TOP_LAYER in rooms -> TopLayer.of()
|
||||||
else -> SelectedRooms.of(rooms)
|
else -> Rooms.of(rooms)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SingleSelectedRoomOrTopLayer::class -> {
|
SingleRoomOrTopLayer::class -> {
|
||||||
require(rooms.size == 1) { "SingleSelectedRoomOrTopLayer must contain exactly one room or the top layer." }
|
require(rooms.size == 1) { "SingleSelectedRoomOrTopLayer must contain exactly one room or the top layer." }
|
||||||
when {
|
when {
|
||||||
TOP_LAYER in rooms -> SelectedTopLayer.of()
|
TOP_LAYER in rooms -> TopLayer.of()
|
||||||
else -> SingleSelectedRoom.of(rooms.first())
|
else -> SingleRoom.of(rooms.first())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
SelectedRooms::class -> SelectedRooms.of(rooms)
|
Rooms::class -> Rooms.of(rooms)
|
||||||
SelectedTopLayer::class -> {
|
TopLayer::class -> {
|
||||||
require(rooms.size == 1 && TOP_LAYER in rooms) { "SelectedTopLayer must contain only the top layer." }
|
require(rooms.size == 1 && TOP_LAYER in rooms) { "SelectedTopLayer must contain only the top layer." }
|
||||||
SelectedTopLayer.of()
|
TopLayer.of()
|
||||||
}
|
}
|
||||||
|
|
||||||
SingleSelectedRoom::class -> {
|
SingleRoom::class -> {
|
||||||
require(rooms.size == 1) { "SingleSelectedRoom must contain exactly one room." }
|
require(rooms.size == 1) { "SingleSelectedRoom must contain exactly one room." }
|
||||||
SingleSelectedRoom.of(rooms.first())
|
SingleRoom.of(rooms.first())
|
||||||
}
|
}
|
||||||
|
|
||||||
else -> error("Unsupported type: ${kClass.simpleName}")
|
else -> error("Unsupported type: ${kClass.simpleName}")
|
||||||
@@ -381,67 +381,67 @@ public fun <T : SelectedRoomsAndTopLayer> roomsOf(kClass: KClass<T>, rooms: Set<
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an instance of [SelectedRoomsAndTopLayer] based on the provided [KClass] and a single room ID.
|
* Creates an instance of [RoomsAndTopLayer] based on the provided [KClass] and a single room ID.
|
||||||
*
|
*
|
||||||
* @param T The type of [SelectedRoomsAndTopLayer] to create.
|
* @param T The type of [RoomsAndTopLayer] to create.
|
||||||
* @param kClass The [KClass] of the type to create.
|
* @param kClass The [KClass] of the type to create.
|
||||||
* @param room The ID of the room to include in the selection.
|
* @param room The ID of the room to include in the selection.
|
||||||
* @param rooms Additional room IDs to include in the selection.
|
* @param rooms Additional room IDs to include in the selection.
|
||||||
* @return An instance of [SelectedRoomsAndTopLayer] of the specified type.
|
* @return An instance of [RoomsAndTopLayer] of the specified type.
|
||||||
*/
|
*/
|
||||||
@JvmSynthetic
|
@JvmSynthetic
|
||||||
@RDKTInternalAPI
|
@RDKTInternalAPI
|
||||||
public fun <T : SelectedRoomsAndTopLayer> roomsOf(kClass: KClass<T>, room: Int, vararg rooms: Int): T {
|
public fun <T : RoomsAndTopLayer> roomsOf(kClass: KClass<T>, room: Int, vararg rooms: Int): T {
|
||||||
return roomsOf(kClass, setOf(room) + rooms.toSet())
|
return roomsOf(kClass, setOf(room) + rooms.toSet())
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an instance of [SingleSelectedRoomOrTopLayer] based on the provided [KClass] and a single room ID.
|
* Creates an instance of [SingleRoomOrTopLayer] based on the provided [KClass] and a single room ID.
|
||||||
*
|
*
|
||||||
* @param T The type of [SingleSelectedRoomOrTopLayer] to create.
|
* @param T The type of [SingleRoomOrTopLayer] to create.
|
||||||
* @param kClass The [KClass] of the type to create.
|
* @param kClass The [KClass] of the type to create.
|
||||||
* @param room The ID of the room to include in the selection.
|
* @param room The ID of the room to include in the selection.
|
||||||
* @return An instance of [SingleSelectedRoomOrTopLayer] of the specified type.
|
* @return An instance of [SingleRoomOrTopLayer] of the specified type.
|
||||||
*/
|
*/
|
||||||
@JvmSynthetic
|
@JvmSynthetic
|
||||||
@RDKTInternalAPI
|
@RDKTInternalAPI
|
||||||
public fun <T : SingleSelectedRoomOrTopLayer> singleRoomOf(kClass: KClass<T>, room: Int): T {
|
public fun <T : SingleRoomOrTopLayer> singleRoomOf(kClass: KClass<T>, room: Int): T {
|
||||||
return roomsOf(kClass, room)
|
return roomsOf(kClass, room)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an instance of [SelectedRoomsAndTopLayer] based on the provided set of room IDs.
|
* Creates an instance of [RoomsAndTopLayer] based on the provided set of room IDs.
|
||||||
*
|
*
|
||||||
* @param T The type of [SelectedRoomsAndTopLayer] to create.
|
* @param T The type of [RoomsAndTopLayer] to create.
|
||||||
* @param rooms The set of room IDs to include in the selection.
|
* @param rooms The set of room IDs to include in the selection.
|
||||||
* @return An instance of [SelectedRoomsAndTopLayer] of the specified type.
|
* @return An instance of [RoomsAndTopLayer] of the specified type.
|
||||||
*/
|
*/
|
||||||
@JvmName("of")
|
@JvmName("of")
|
||||||
public inline fun <reified T : SelectedRoomsAndTopLayer> roomsOf(rooms: Set<Int>): T {
|
public inline fun <reified T : RoomsAndTopLayer> roomsOf(rooms: Set<Int>): T {
|
||||||
return roomsOf(T::class, rooms)
|
return roomsOf(T::class, rooms)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an instance of [SelectedRoomsAndTopLayer] based on the provided room ID and additional room IDs.
|
* Creates an instance of [RoomsAndTopLayer] based on the provided room ID and additional room IDs.
|
||||||
*
|
*
|
||||||
* @param T The type of [SelectedRoomsAndTopLayer] to create.
|
* @param T The type of [RoomsAndTopLayer] to create.
|
||||||
* @param room The ID of the first selected room.
|
* @param room The ID of the first selected room.
|
||||||
* @param rooms Additional room IDs to include in the selection.
|
* @param rooms Additional room IDs to include in the selection.
|
||||||
* @return An instance of [SelectedRoomsAndTopLayer] of the specified type.
|
* @return An instance of [RoomsAndTopLayer] of the specified type.
|
||||||
*/
|
*/
|
||||||
@JvmName("of")
|
@JvmName("of")
|
||||||
public inline fun <reified T : SelectedRoomsAndTopLayer> roomsOf(room: Int, vararg rooms: Int): T {
|
public inline fun <reified T : RoomsAndTopLayer> roomsOf(room: Int, vararg rooms: Int): T {
|
||||||
return roomsOf(T::class, room, *rooms)
|
return roomsOf(T::class, room, *rooms)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates an instance of [SingleSelectedRoomOrTopLayer] based on the provided room ID.
|
* Creates an instance of [SingleRoomOrTopLayer] based on the provided room ID.
|
||||||
*
|
*
|
||||||
* @param T The type of [SingleSelectedRoomOrTopLayer] to create.
|
* @param T The type of [SingleRoomOrTopLayer] to create.
|
||||||
* @param room The ID of the selected room.
|
* @param room The ID of the selected room.
|
||||||
* @return An instance of [SingleSelectedRoomOrTopLayer] of the specified type.
|
* @return An instance of [SingleRoomOrTopLayer] of the specified type.
|
||||||
*/
|
*/
|
||||||
@JvmName("ofSingle")
|
@JvmName("ofSingle")
|
||||||
public inline fun <reified T : SingleSelectedRoomOrTopLayer> singleRoomOf(room: Int): T {
|
public inline fun <reified T : SingleRoomOrTopLayer> singleRoomOf(room: Int): T {
|
||||||
return singleRoomOf(T::class, room)
|
return singleRoomOf(T::class, room)
|
||||||
}
|
}
|
||||||
@@ -68,68 +68,68 @@ public interface RoomsAndTopLayerSpecificEvent : Event {
|
|||||||
/**
|
/**
|
||||||
* The rooms or the top layer the event is specifying.
|
* The rooms or the top layer the event is specifying.
|
||||||
*/
|
*/
|
||||||
public val rooms: SelectedRoomsAndTopLayer
|
public val rooms: RoomsAndTopLayer
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The mutable version of [RoomsAndTopLayerSpecificEvent].
|
* The mutable version of [RoomsAndTopLayerSpecificEvent].
|
||||||
*/
|
*/
|
||||||
public interface MutableRoomsAndTopLayerSpecificEvent : RoomsAndTopLayerSpecificEvent {
|
public interface MutableRoomsAndTopLayerSpecificEvent : RoomsAndTopLayerSpecificEvent {
|
||||||
override var rooms: SelectedRoomsAndTopLayer
|
override var rooms: RoomsAndTopLayer
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An [Event] that is specific to rooms or the top layer.
|
* An [Event] that is specific to rooms or the top layer.
|
||||||
*/
|
*/
|
||||||
public interface RoomsOrTopLayerSpecificEvent : RoomsAndTopLayerSpecificEvent {
|
public interface RoomsOrTopLayerSpecificEvent : RoomsAndTopLayerSpecificEvent {
|
||||||
override val rooms: SelectedRoomsOrTopLayer
|
override val rooms: RoomsOrTopLayer
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The mutable version of [RoomsOrTopLayerSpecificEvent].
|
* The mutable version of [RoomsOrTopLayerSpecificEvent].
|
||||||
*/
|
*/
|
||||||
public interface MutableRoomsOrTopLayerSpecificEvent : RoomsOrTopLayerSpecificEvent {
|
public interface MutableRoomsOrTopLayerSpecificEvent : RoomsOrTopLayerSpecificEvent {
|
||||||
override var rooms: SelectedRoomsOrTopLayer
|
override var rooms: RoomsOrTopLayer
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An [Event] that is specific to a single room or the top layer.
|
* An [Event] that is specific to a single room or the top layer.
|
||||||
*/
|
*/
|
||||||
public interface SingleRoomOrTopLayerSpecificEvent : RoomsOrTopLayerSpecificEvent {
|
public interface SingleRoomOrTopLayerSpecificEvent : RoomsOrTopLayerSpecificEvent {
|
||||||
override val rooms: SingleSelectedRoomOrTopLayer
|
override val rooms: SingleRoomOrTopLayer
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The mutable version of [SingleRoomOrTopLayerSpecificEvent].
|
* The mutable version of [SingleRoomOrTopLayerSpecificEvent].
|
||||||
*/
|
*/
|
||||||
public interface MutableSingleRoomOrTopLayerSpecificEvent : SingleRoomOrTopLayerSpecificEvent {
|
public interface MutableSingleRoomOrTopLayerSpecificEvent : SingleRoomOrTopLayerSpecificEvent {
|
||||||
override var rooms: SingleSelectedRoomOrTopLayer
|
override var rooms: SingleRoomOrTopLayer
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An [Event] that is specific to rooms.
|
* An [Event] that is specific to rooms.
|
||||||
*/
|
*/
|
||||||
public interface RoomsSpecificEvent : RoomsOrTopLayerSpecificEvent {
|
public interface RoomsSpecificEvent : RoomsOrTopLayerSpecificEvent {
|
||||||
override val rooms: SelectedRooms
|
override val rooms: Rooms
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The mutable version of [RoomsSpecificEvent].
|
* The mutable version of [RoomsSpecificEvent].
|
||||||
*/
|
*/
|
||||||
public interface MutableRoomsSpecificEvent : RoomsSpecificEvent {
|
public interface MutableRoomsSpecificEvent : RoomsSpecificEvent {
|
||||||
override var rooms: SelectedRooms
|
override var rooms: Rooms
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* An [Event] that is specific to a single room.
|
* An [Event] that is specific to a single room.
|
||||||
*/
|
*/
|
||||||
public interface SingleRoomSpecificEvent : SingleRoomOrTopLayerSpecificEvent, RoomsSpecificEvent {
|
public interface SingleRoomSpecificEvent : SingleRoomOrTopLayerSpecificEvent, RoomsSpecificEvent {
|
||||||
override val rooms: SingleSelectedRoom
|
override val rooms: SingleRoom
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The mutable version of [SingleRoomSpecificEvent].
|
* The mutable version of [SingleRoomSpecificEvent].
|
||||||
*/
|
*/
|
||||||
public interface MutableSingleRoomSpecificEvent : SingleRoomSpecificEvent {
|
public interface MutableSingleRoomSpecificEvent : SingleRoomSpecificEvent {
|
||||||
override var rooms: SingleSelectedRoom
|
override var rooms: SingleRoom
|
||||||
}
|
}
|
||||||
@@ -4,7 +4,7 @@ package cn.rdlevel.rdkt.core.events
|
|||||||
|
|
||||||
import cn.rdlevel.rdkt.core.annotations.RDKTInternalAPI
|
import cn.rdlevel.rdkt.core.annotations.RDKTInternalAPI
|
||||||
import cn.rdlevel.rdkt.core.data.ROOM1
|
import cn.rdlevel.rdkt.core.data.ROOM1
|
||||||
import cn.rdlevel.rdkt.core.data.SelectedRooms
|
import cn.rdlevel.rdkt.core.data.Rooms
|
||||||
import cn.rdlevel.rdkt.core.data.action.Theme
|
import cn.rdlevel.rdkt.core.data.action.Theme
|
||||||
import cn.rdlevel.rdkt.core.data.roomsOf
|
import cn.rdlevel.rdkt.core.data.roomsOf
|
||||||
import cn.rdlevel.rdkt.core.serialization.Flatten
|
import cn.rdlevel.rdkt.core.serialization.Flatten
|
||||||
@@ -23,7 +23,7 @@ import kotlinx.serialization.*
|
|||||||
public data class SetThemeEvent(
|
public data class SetThemeEvent(
|
||||||
@Flatten
|
@Flatten
|
||||||
var theme: Theme,
|
var theme: Theme,
|
||||||
override var rooms: SelectedRooms = roomsOf(ROOM1),
|
override var rooms: Rooms = roomsOf(ROOM1),
|
||||||
) : ActionEvent(), MutableRoomsSpecificEvent {
|
) : ActionEvent(), MutableRoomsSpecificEvent {
|
||||||
public object Serializer : KSerializer<SetThemeEvent> by generatedSerializer().flatten()
|
public object Serializer : KSerializer<SetThemeEvent> by generatedSerializer().flatten()
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user