- update data model: simplify key/data (by removing data)

This commit is contained in:
Adam 2022-02-23 17:56:56 +01:00
parent b82e3a1bbf
commit 8e7208ba08
8 changed files with 221 additions and 282 deletions

View file

@ -1,6 +1,7 @@
package dev.adamko.kafkatorio.events.schema
import dev.adamko.kafkatorio.events.schema.FactorioEventUpdate.FactorioEventUpdateType
import kotlinx.serialization.Contextual
import kotlinx.serialization.DeserializationStrategy
import kotlinx.serialization.EncodeDefault
import kotlinx.serialization.Serializable
@ -31,16 +32,19 @@ sealed interface FactorioEventUpdateKey {
}
sealed interface FactorioEventUpdateData {
val updateType: FactorioEventUpdateType
}
//sealed interface FactorioEventUpdateData {
// val updateType: FactorioEventUpdateType
// val event: String?
//}
@Serializable(with = FactorioEventUpdate.Companion.JsonSerializer::class)
sealed class FactorioEventUpdate : FactorioEventUpdateKey, FactorioEventUpdateData {
sealed class FactorioEventUpdate : FactorioEventUpdateKey {
@EncodeDefault
abstract override val updateType: FactorioEventUpdateType
@Contextual
abstract val events: List<String>?
@Serializable
enum class FactorioEventUpdateType {
@ -93,63 +97,66 @@ sealed interface PlayerUpdateKey : FactorioEventUpdateKey {
}
sealed interface PlayerUpdateData : FactorioEventUpdateData {
val characterUnitNumber: UnitNumber?
val chatColour: Colour?
val colour: Colour?
val name: String?
val afkTime: Tick?
val ticksToRespawn: Tick?
val forceIndex: ForceIndex?
val isAdmin: Boolean?
val isConnected: Boolean?
val isShowOnMap: Boolean?
val isSpectator: Boolean?
val lastOnline: Tick?
val onlineTime: Tick?
val position: MapEntityPosition?
val surfaceIndex: SurfaceIndex?
val tag: String?
val diedCause: EntityIdentifiers?
val bannedReason: String?
val kickedReason: String?
val disconnectReason: String?
/** `true` when a player is removed (deleted) from the game */
val isRemoved: Boolean?
}
//sealed interface PlayerUpdateData : FactorioEventUpdateData {
// val characterUnitNumber: UnitNumber?
// val chatColour: Colour?
// val colour: Colour?
// val name: String?
//
// val afkTime: Tick?
// val ticksToRespawn: Tick?
// val forceIndex: ForceIndex?
// val isAdmin: Boolean?
// val isConnected: Boolean?
// val isShowOnMap: Boolean?
// val isSpectator: Boolean?
// val lastOnline: Tick?
// val onlineTime: Tick?
// val position: MapEntityPosition?
// val surfaceIndex: SurfaceIndex?
// val tag: String?
// val diedCause: EntityIdentifiers?
//
// val bannedReason: String?
// val kickedReason: String?
// val disconnectReason: String?
// /** `true` when a player is removed (deleted) from the game */
// val isRemoved: Boolean?
//}
@Serializable
data class PlayerUpdate(
override val index: PlayerIndex,
override val characterUnitNumber: UnitNumber? = null,
override val chatColour: Colour? = null,
override val colour: Colour? = null,
override val name: String? = null,
@Contextual
override val events: List<String>? = null,
override val afkTime: Tick? = null,
override val ticksToRespawn: Tick? = null,
override val forceIndex: ForceIndex? = null,
override val isAdmin: Boolean? = null,
override val isConnected: Boolean? = null,
override val isShowOnMap: Boolean? = null,
override val isSpectator: Boolean? = null,
override val lastOnline: Tick? = null,
override val onlineTime: Tick? = null,
override val position: MapEntityPosition? = null,
override val surfaceIndex: SurfaceIndex? = null,
override val tag: String? = null,
override val diedCause: EntityIdentifiers? = null,
val characterUnitNumber: UnitNumber? = null,
val chatColour: Colour? = null,
val colour: Colour? = null,
val name: String? = null,
override val bannedReason: String? = null,
override val kickedReason: String? = null,
override val disconnectReason: String? = null,
val afkTime: Tick? = null,
val ticksToRespawn: Tick? = null,
val forceIndex: ForceIndex? = null,
val isAdmin: Boolean? = null,
val isConnected: Boolean? = null,
val isShowOnMap: Boolean? = null,
val isSpectator: Boolean? = null,
val lastOnline: Tick? = null,
val onlineTime: Tick? = null,
val position: MapEntityPosition? = null,
val surfaceIndex: SurfaceIndex? = null,
val tag: String? = null,
val diedCause: EntityIdentifiers? = null,
val bannedReason: String? = null,
val kickedReason: String? = null,
val disconnectReason: String? = null,
/** `true` when a player is removed (deleted) from the game */
override val isRemoved: Boolean? = null,
) : FactorioEventUpdate(), PlayerUpdateKey, PlayerUpdateData {
val isRemoved: Boolean? = null,
) : FactorioEventUpdate(), PlayerUpdateKey {
@EncodeDefault
override val updateType: FactorioEventUpdateType = FactorioEventUpdateType.PLAYER
}
@ -165,17 +172,17 @@ sealed interface EntityUpdateKey : EntityIdentifiers, FactorioEventUpdateKey {
override val type: String
}
sealed interface EntityUpdateData : FactorioEventUpdateData {
val chunkPosition: MapChunkPosition?
val graphicsVariation: UShort?
val health: Float?
val isActive: Boolean?
val isRotatable: Boolean?
val lastUser: UInt?
val localisedDescription: String?
val localisedName: String?
val prototype: PrototypeName?
}
//sealed interface EntityUpdateData : FactorioEventUpdateData {
// val chunkPosition: MapChunkPosition?
// val graphicsVariation: UShort?
// val health: Float?
// val isActive: Boolean?
// val isRotatable: Boolean?
// val lastUser: UInt?
// val localisedDescription: String?
// val localisedName: String?
// val prototype: PrototypeName?
//}
@Serializable
data class EntityUpdate(
@ -183,16 +190,19 @@ data class EntityUpdate(
override val name: String,
override val type: String,
override val chunkPosition: MapChunkPosition? = null,
override val graphicsVariation: UShort? = null,
override val health: Float? = null,
override val isActive: Boolean? = null,
override val isRotatable: Boolean? = null,
override val lastUser: UInt? = null,
override val localisedDescription: String? = null,
override val localisedName: String? = null,
override val prototype: PrototypeName? = null,
) : FactorioEventUpdate(), EntityIdentifiers, EntityUpdateKey, EntityUpdateData {
@Contextual
override val events: List<String>? = null,
val chunkPosition: MapChunkPosition? = null,
val graphicsVariation: UShort? = null,
val health: Float? = null,
val isActive: Boolean? = null,
val isRotatable: Boolean? = null,
val lastUser: UInt? = null,
val localisedDescription: String? = null,
val localisedName: String? = null,
val prototype: PrototypeName? = null,
) : FactorioEventUpdate(), EntityIdentifiers, EntityUpdateKey {
@EncodeDefault
override val updateType: FactorioEventUpdateType = FactorioEventUpdateType.ENTITY
}
@ -207,14 +217,13 @@ sealed interface MapChunkUpdateKey : FactorioEventUpdateKey {
}
sealed interface MapChunkUpdateData : FactorioEventUpdateData {
val player: PlayerIndex?
val robot: EntityIdentifiers?
val force: ForceIndex?
/** updated tiles - might be partial */
val tiles: List<MapTile>?
val isDeleted: Boolean?
}
//sealed interface MapChunkUpdateData : FactorioEventUpdateData {
// val player: PlayerIndex?
// val robot: EntityIdentifiers?
// val force: ForceIndex?
// val tiles: List<MapTile>?
// val isDeleted: Boolean?
//}
@Serializable
@ -222,14 +231,19 @@ data class MapChunkUpdate(
override val chunkPosition: MapChunkPosition,
override val surfaceIndex: SurfaceIndex,
override val player: PlayerIndex? = null,
override val robot: EntityIdentifiers? = null,
override val force: ForceIndex? = null,
@Contextual
override val events: List<String>? = null,
val player: PlayerIndex? = null,
val robot: EntityIdentifiers? = null,
val force: ForceIndex? = null,
/** updated tiles - might be partial */
// note: this must be a List, not a Map<Location, ProtoName>
// because JSON can't have non-string keys.
override val tiles: List<MapTile>? = null,
override val isDeleted: Boolean? = null,
) : FactorioEventUpdate(), MapChunkUpdateKey, MapChunkUpdateData {
@Contextual
val tiles: List<MapTile>? = null,
val isDeleted: Boolean? = null,
) : FactorioEventUpdate(), MapChunkUpdateKey {
@EncodeDefault
override val updateType: FactorioEventUpdateType = FactorioEventUpdateType.MAP_CHUNK
}

View file

@ -25,7 +25,7 @@ fun main(args: Array<String>) {
add(FactorioEventUpdatePacket::class)
addAll(FactorioEventUpdate::class.sealedSubclasses)
addAll(FactorioEventUpdateKey::class.sealedSubclasses)
addAll(FactorioEventUpdateData::class.sealedSubclasses)
// addAll(FactorioEventUpdateData::class.sealedSubclasses)
},
mappings = mapOf(