model updates, and fix tests
This commit is contained in:
parent
e0b9ef9788
commit
dd45bece53
6 changed files with 90 additions and 31 deletions
|
|
@ -1,12 +1,25 @@
|
|||
// Generated by TypeScriptGenerator - do not edit this file manually
|
||||
|
||||
type PacketType = "EVENT" | "CONFIG" | "PROTOTYPES";
|
||||
type PacketType = "EVENT" | "CONFIG" | "PROTOTYPES" | "UPDATE";
|
||||
|
||||
interface KafkatorioPacket {
|
||||
modVersion: string;
|
||||
packetType: PacketType;
|
||||
}
|
||||
|
||||
type FactorioEventUpdateType = "PLAYER" | "MAP_CHUNK" | "ENTITY";
|
||||
|
||||
interface FactorioEventUpdate {
|
||||
updateType: FactorioEventUpdateType;
|
||||
}
|
||||
|
||||
interface FactorioEventUpdatePacket extends KafkatorioPacket {
|
||||
modVersion: string;
|
||||
packetType: PacketType;
|
||||
tick: uint;
|
||||
update: FactorioEventUpdate;
|
||||
}
|
||||
|
||||
interface FactorioEvent extends KafkatorioPacket {
|
||||
data: FactorioObjectData;
|
||||
eventType: string;
|
||||
|
|
@ -80,33 +93,39 @@ interface MapTile {
|
|||
prototypeName: string;
|
||||
}
|
||||
|
||||
type FactorioEventUpdateType = "PLAYER" | "MAP_CHUNK" | "ENTITY";
|
||||
|
||||
interface FactorioEventUpdate {
|
||||
updateType: FactorioEventUpdateType;
|
||||
interface EntityIdentifiers {
|
||||
name: string;
|
||||
type: string;
|
||||
unitNumber: uint | null;
|
||||
}
|
||||
|
||||
interface PlayerUpdate extends FactorioEventUpdate {
|
||||
afkTime: uint | null;
|
||||
bannedReason: string | null;
|
||||
characterUnitNumber: uint | null;
|
||||
chatColour: Colour | null;
|
||||
colour: Colour | null;
|
||||
diedCause: EntityIdentifiers | null;
|
||||
disconnectReason: string | null;
|
||||
forceIndex: uint | null;
|
||||
index: uint;
|
||||
isAdmin: boolean | null;
|
||||
isConnected: boolean | null;
|
||||
isRemoved: boolean | null;
|
||||
isShowOnMap: boolean | null;
|
||||
isSpectator: boolean | null;
|
||||
kickedReason: string | null;
|
||||
lastOnline: uint | null;
|
||||
name: string | null;
|
||||
onlineTime: uint | null;
|
||||
position: MapEntityPosition | null;
|
||||
surfaceIndex: uint | null;
|
||||
tag: string | null;
|
||||
ticksToRespawn: uint | null;
|
||||
updateType: FactorioEventUpdateType;
|
||||
}
|
||||
|
||||
interface EntityUpdate extends FactorioEventUpdate {
|
||||
interface EntityUpdate extends FactorioEventUpdate, EntityIdentifiers {
|
||||
chunkPosition: MapChunkPosition | null;
|
||||
graphicsVariation: number | null;
|
||||
health: float | null;
|
||||
|
|
@ -115,17 +134,20 @@ interface EntityUpdate extends FactorioEventUpdate {
|
|||
lastUser: int | null;
|
||||
localisedDescription: string | null;
|
||||
localisedName: string | null;
|
||||
name: string | null;
|
||||
name: string;
|
||||
prototype: string | null;
|
||||
type: string | null;
|
||||
type: string;
|
||||
unitNumber: uint;
|
||||
updateType: FactorioEventUpdateType;
|
||||
}
|
||||
|
||||
interface MapChunkUpdate extends FactorioEventUpdate {
|
||||
chunkPosition: MapChunkPosition;
|
||||
force: uint | null;
|
||||
isDeleted: boolean | null;
|
||||
player: uint | null;
|
||||
robot: EntityIdentifiers | null;
|
||||
surfaceIndex: uint;
|
||||
tiles: MapTiles | null;
|
||||
tiles: Map<MapTilePosition, string> | null;
|
||||
updateType: FactorioEventUpdateType;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -101,3 +101,10 @@ data class MapTile(
|
|||
val prototypeName: PrototypeName,
|
||||
val position: MapTilePosition,
|
||||
)
|
||||
|
||||
|
||||
interface EntityIdentifiers {
|
||||
val unitNumber: UnitNumber?
|
||||
val name: String
|
||||
val type: String
|
||||
}
|
||||
|
|
|
|||
|
|
@ -10,6 +10,18 @@ import kotlinx.serialization.json.jsonObject
|
|||
import kotlinx.serialization.json.jsonPrimitive
|
||||
|
||||
|
||||
@Serializable
|
||||
class FactorioEventUpdatePacket(
|
||||
override val modVersion: String,
|
||||
/** game time */
|
||||
val tick: Tick,
|
||||
val update: FactorioEventUpdate,
|
||||
) : KafkatorioPacket() {
|
||||
@EncodeDefault
|
||||
override val packetType: PacketType = PacketType.UPDATE
|
||||
}
|
||||
|
||||
|
||||
@Serializable(with = FactorioEventUpdate.Companion.JsonSerializer::class)
|
||||
sealed class FactorioEventUpdate {
|
||||
|
||||
|
|
@ -68,7 +80,8 @@ data class PlayerUpdate(
|
|||
val colour: Colour? = null,
|
||||
val name: String? = null,
|
||||
|
||||
val disconnectReason: String? = null,
|
||||
val afkTime: Tick? = null,
|
||||
val ticksToRespawn: Tick? = null,
|
||||
val forceIndex: ForceIndex? = null,
|
||||
val isAdmin: Boolean? = null,
|
||||
val isConnected: Boolean? = null,
|
||||
|
|
@ -79,6 +92,13 @@ data class PlayerUpdate(
|
|||
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 */
|
||||
val isRemoved: Boolean? = null,
|
||||
) : FactorioEventUpdate() {
|
||||
@EncodeDefault
|
||||
override val updateType: FactorioEventUpdateType = FactorioEventUpdateType.PLAYER
|
||||
|
|
@ -87,14 +107,11 @@ data class PlayerUpdate(
|
|||
|
||||
@Serializable
|
||||
data class EntityUpdate(
|
||||
/**
|
||||
* A [unitNumber] is required for caching, else the Entity Update should be emitted without
|
||||
* debouncing/throttling
|
||||
*/
|
||||
val unitNumber: UnitNumber,
|
||||
/** A [unitNumber] is required for caching */
|
||||
override val unitNumber: UnitNumber,
|
||||
override val name: String,
|
||||
override val type: String,
|
||||
|
||||
val name: String? = null,
|
||||
val type: String? = null,
|
||||
val chunkPosition: MapChunkPosition? = null,
|
||||
val graphicsVariation: UShort? = null,
|
||||
val health: Float? = null,
|
||||
|
|
@ -104,7 +121,7 @@ data class EntityUpdate(
|
|||
val localisedDescription: String? = null,
|
||||
val localisedName: String? = null,
|
||||
val prototype: PrototypeName? = null,
|
||||
) : FactorioEventUpdate() {
|
||||
) : FactorioEventUpdate(), EntityIdentifiers {
|
||||
@EncodeDefault
|
||||
override val updateType: FactorioEventUpdateType = FactorioEventUpdateType.ENTITY
|
||||
}
|
||||
|
|
@ -115,8 +132,12 @@ data class MapChunkUpdate(
|
|||
val chunkPosition: MapChunkPosition,
|
||||
val surfaceIndex: SurfaceIndex,
|
||||
|
||||
val player: PlayerIndex? = null,
|
||||
val robot: EntityIdentifiers? = null,
|
||||
val force: ForceIndex? = null,
|
||||
|
||||
/** Might be a partial list of updated tiles */
|
||||
val tiles: MapTiles? = null,
|
||||
val tiles: Map<MapTilePosition, PrototypeName>? = null,
|
||||
val isDeleted: Boolean? = null,
|
||||
) : FactorioEventUpdate() {
|
||||
@EncodeDefault
|
||||
|
|
|
|||
|
|
@ -21,6 +21,7 @@ sealed class KafkatorioPacket {
|
|||
EVENT,
|
||||
CONFIG,
|
||||
PROTOTYPES,
|
||||
UPDATE,
|
||||
;
|
||||
|
||||
companion object {
|
||||
|
|
@ -51,6 +52,7 @@ object KafkatorioPacketJsonSerializer : JsonContentPolymorphicSerializer<Kafkato
|
|||
KafkatorioPacket.PacketType.EVENT -> FactorioEvent.serializer()
|
||||
KafkatorioPacket.PacketType.CONFIG -> FactorioConfigurationUpdate.serializer()
|
||||
KafkatorioPacket.PacketType.PROTOTYPES -> FactorioPrototypes.serializer()
|
||||
KafkatorioPacket.PacketType.UPDATE -> FactorioEventUpdatePacket.serializer()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,6 +15,8 @@ class FactorioEventTest : FunSpec({
|
|||
{
|
||||
"data": {
|
||||
"objectName": "LuaPlayer",
|
||||
"force": 1,
|
||||
"surface": 1,
|
||||
"name": "fredthedeadhead",
|
||||
"characterUnitNumber": 1,
|
||||
"associatedCharactersUnitNumbers": {},
|
||||
|
|
@ -145,7 +147,8 @@ class FactorioEventTest : FunSpec({
|
|||
"active": true,
|
||||
"health": 250,
|
||||
"healthRatio": 1,
|
||||
"surfaceIndex": 1,
|
||||
"surface": 1,
|
||||
"force": 1,
|
||||
"unitNumber": 1,
|
||||
"position": {
|
||||
"x": 37.5,
|
||||
|
|
@ -251,19 +254,19 @@ class FactorioEventTest : FunSpec({
|
|||
surfaceIndex = SurfaceIndex(1u),
|
||||
tiles = listOf(
|
||||
MapTile(
|
||||
prototypeName = "refined-concrete",
|
||||
prototypeName = PrototypeName("refined-concrete"),
|
||||
position = MapTilePosition(-65, 10)
|
||||
),
|
||||
MapTile(
|
||||
prototypeName = "red-earth",
|
||||
prototypeName = PrototypeName("red-earth"),
|
||||
position = MapTilePosition(-65, 11)
|
||||
),
|
||||
MapTile(
|
||||
prototypeName = "blue-cheese",
|
||||
prototypeName = PrototypeName("blue-cheese"),
|
||||
position = MapTilePosition(-64, 10)
|
||||
),
|
||||
MapTile(
|
||||
prototypeName = "refined-concrete",
|
||||
prototypeName = PrototypeName("refined-concrete"),
|
||||
position = MapTilePosition(-64, 11)
|
||||
),
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2,6 +2,7 @@ package dev.adamko.kafkatorio.processor.topology
|
|||
|
||||
import dev.adamko.kafkatorio.events.schema.FactorioConfigurationUpdate
|
||||
import dev.adamko.kafkatorio.events.schema.FactorioEvent
|
||||
import dev.adamko.kafkatorio.events.schema.FactorioEventUpdatePacket
|
||||
import dev.adamko.kafkatorio.events.schema.FactorioPrototypes
|
||||
import dev.adamko.kafkatorio.events.schema.KafkatorioPacket
|
||||
import dev.adamko.kafkatorio.processor.KafkatorioTopology
|
||||
|
|
@ -49,13 +50,16 @@ fun splitFactorioServerPacketStream(
|
|||
)
|
||||
) { _: FactorioServerId, value: KafkatorioPacket, _: RecordContext ->
|
||||
// println("[$key] sending event:${value.eventType} to topic:${value.data.objectName()}")
|
||||
when (value) {
|
||||
is FactorioEvent ->
|
||||
"kafkatorio.${value.packetType.name}.${value.data.objectName.name}"
|
||||
is FactorioConfigurationUpdate ->
|
||||
"kafkatorio.${value.packetType.name}.FactorioConfigurationUpdate"
|
||||
is FactorioPrototypes ->
|
||||
"kafkatorio.${value.packetType.name}.all"
|
||||
|
||||
val base = "kafkatorio.${value.packetType.name}"
|
||||
|
||||
val type: String = when (value) {
|
||||
is FactorioEvent -> value.data.objectName.name
|
||||
is FactorioConfigurationUpdate -> "FactorioConfigurationUpdate"
|
||||
is FactorioPrototypes -> "all"
|
||||
is FactorioEventUpdatePacket -> "all"
|
||||
}
|
||||
|
||||
"$base.$type"
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue