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