diff --git a/modules/events-mod/src/main/typescript/generated/kafkatorio-schema/kafkatorio-schema.ts b/modules/events-mod/src/main/typescript/generated/kafkatorio-schema/kafkatorio-schema.ts index e215deb..16872e0 100644 --- a/modules/events-mod/src/main/typescript/generated/kafkatorio-schema/kafkatorio-schema.ts +++ b/modules/events-mod/src/main/typescript/generated/kafkatorio-schema/kafkatorio-schema.ts @@ -1,4 +1,4 @@ -// Generated by TypeScriptGenerator - do not edit this file manually +// Generated by kxs-ts-gen - do not edit this file manually export interface KafkatorioPacket2 { modVersion: string; diff --git a/modules/events-mod/src/main/typescript/package.json b/modules/events-mod/src/main/typescript/package.json index ea7c2fb..dc5d159 100644 --- a/modules/events-mod/src/main/typescript/package.json +++ b/modules/events-mod/src/main/typescript/package.json @@ -9,7 +9,8 @@ "engines": { "node": "~14.19.1" }, - "devDependencies": {}, + "devDependencies": { + }, "dependencies": { "lua-types": "^2.11.0", "typescript-to-lua": "1.4.3", @@ -18,7 +19,10 @@ }, "// @types/node": "^12.0.8", "license": "UNLICENSED", - "peerDependencies": {}, - "optionalDependencies": {}, - "bundledDependencies": [] + "peerDependencies": { + }, + "optionalDependencies": { + }, + "bundledDependencies": [ + ] } diff --git a/modules/events-schema/src/commonMain/kotlin/dev/adamko/kafkatorio/schema/events/kafkatorioPacket.kt b/modules/events-schema/src/commonMain/kotlin/dev/adamko/kafkatorio/schema/events/kafkatorioPacket.kt index 0809d9a..02413d8 100644 --- a/modules/events-schema/src/commonMain/kotlin/dev/adamko/kafkatorio/schema/events/kafkatorioPacket.kt +++ b/modules/events-schema/src/commonMain/kotlin/dev/adamko/kafkatorio/schema/events/kafkatorioPacket.kt @@ -1,68 +1,68 @@ package dev.adamko.kafkatorio.schema.events - -import dev.adamko.kafkatorio.schema.SerializerProvider -import dev.adamko.kafkatorio.schema.SerializerProviderDeserializer -import dev.adamko.kafkatorio.schema.common.Tick -import kotlin.reflect.KClass -import kotlin.reflect.KType -import kotlin.reflect.typeOf -import kotlinx.serialization.KSerializer -import kotlinx.serialization.Serializable - - +// +//import dev.adamko.kafkatorio.schema.SerializerProvider +//import dev.adamko.kafkatorio.schema.SerializerProviderDeserializer +//import dev.adamko.kafkatorio.schema.common.Tick +//import kotlin.reflect.KClass +//import kotlin.reflect.KType +//import kotlin.reflect.typeOf +//import kotlinx.serialization.KSerializer +//import kotlinx.serialization.Serializable +// +// +////@Serializable +////data class KafkatorioPacket( +//// val modVersion: String, +//// val tick: Tick, +//// val data: KafkatorioPacketData, +////) +// +// +//@Serializable(with = KafkatorioPacketData.JsonSerializer::class) +//sealed class KafkatorioPacketData { +// abstract val updateType: KafkatorioPacketDataType +// +// object JsonSerializer : SerializerProviderDeserializer( +// KafkatorioPacketData::class, +// KafkatorioPacketData::updateType.name, +// { json -> KafkatorioPacketDataType.entries.firstOrNull { it.name == json } } +// ) +//} +// +// +///** Discriminator for [KafkatorioPacketData] */ //@Serializable -//data class KafkatorioPacket( -// val modVersion: String, -// val tick: Tick, -// val data: KafkatorioPacketData, -//) - - -@Serializable(with = KafkatorioPacketData.JsonSerializer::class) -sealed class KafkatorioPacketData { - abstract val updateType: KafkatorioPacketDataType - - object JsonSerializer : SerializerProviderDeserializer( - KafkatorioPacketData::class, - KafkatorioPacketData::updateType.name, - { json -> KafkatorioPacketDataType.entries.firstOrNull { it.name == json } } - ) -} - - -/** Discriminator for [KafkatorioPacketData] */ -@Serializable -enum class KafkatorioPacketDataType( - override val serializer: KSerializer -) : SerializerProvider { - - // non-keyed - CONFIG(ConfigurationUpdate.serializer()), - CONSOLE_CHAT(ConsoleChatUpdate.serializer()), - CONSOLE_COMMAND(ConsoleCommandUpdate.serializer()), - PROTOTYPES(PrototypesUpdate.serializer()), - SURFACE(SurfaceUpdate.serializer()), - - // keyed - ENTITY(EntityUpdate.serializer()), - MAP_CHUNK(MapChunkUpdate.serializer()), - PLAYER(PlayerUpdate.serializer()), - ; - - companion object { - val entries: Set = values().toSet() - } -} - -//inline fun KafkatorioPacketDataType.isType (): KClass { -// return when (this) { -// KafkatorioPacketDataType.CONFIG -> ConfigurationUpdate::class -// KafkatorioPacketDataType.CONSOLE_CHAT -> ConsoleChatUpdate::class -// KafkatorioPacketDataType.CONSOLE_COMMAND -> ConsoleCommandUpdate::class -// KafkatorioPacketDataType.PROTOTYPES -> PrototypesUpdate::class -// KafkatorioPacketDataType.SURFACE -> SurfaceUpdate::class -// KafkatorioPacketDataType.ENTITY -> EntityUpdate::class -// KafkatorioPacketDataType.MAP_CHUNK -> MapChunkUpdate::class -// KafkatorioPacketDataType.PLAYER -> PlayerUpdate::class +//enum class KafkatorioPacketDataType( +// override val serializer: KSerializer +//) : SerializerProvider { +// +// // non-keyed +// CONFIG(ConfigurationUpdate.serializer()), +// CONSOLE_CHAT(ConsoleChatUpdate.serializer()), +// CONSOLE_COMMAND(ConsoleCommandUpdate.serializer()), +// PROTOTYPES(PrototypesUpdate.serializer()), +// SURFACE(SurfaceUpdate.serializer()), +// +// // keyed +// ENTITY(EntityUpdate.serializer()), +// MAP_CHUNK(MapChunkUpdate.serializer()), +// PLAYER(PlayerUpdate.serializer()), +// ; +// +// companion object { +// val entries: Set = values().toSet() // } //} +// +////inline fun KafkatorioPacketDataType.isType (): KClass { +//// return when (this) { +//// KafkatorioPacketDataType.CONFIG -> ConfigurationUpdate::class +//// KafkatorioPacketDataType.CONSOLE_CHAT -> ConsoleChatUpdate::class +//// KafkatorioPacketDataType.CONSOLE_COMMAND -> ConsoleCommandUpdate::class +//// KafkatorioPacketDataType.PROTOTYPES -> PrototypesUpdate::class +//// KafkatorioPacketDataType.SURFACE -> SurfaceUpdate::class +//// KafkatorioPacketDataType.ENTITY -> EntityUpdate::class +//// KafkatorioPacketDataType.MAP_CHUNK -> MapChunkUpdate::class +//// KafkatorioPacketDataType.PLAYER -> PlayerUpdate::class +//// } +////} diff --git a/modules/events-schema/src/commonMain/kotlin/dev/adamko/kafkatorio/schema/events/kafkatorioPacketInstant.kt b/modules/events-schema/src/commonMain/kotlin/dev/adamko/kafkatorio/schema/events/kafkatorioPacketInstant.kt index c86f507..6dc03cc 100644 --- a/modules/events-schema/src/commonMain/kotlin/dev/adamko/kafkatorio/schema/events/kafkatorioPacketInstant.kt +++ b/modules/events-schema/src/commonMain/kotlin/dev/adamko/kafkatorio/schema/events/kafkatorioPacketInstant.kt @@ -1,95 +1,95 @@ package dev.adamko.kafkatorio.schema.events - -import dev.adamko.kafkatorio.schema.common.PlayerIndex -import dev.adamko.kafkatorio.schema.common.SurfaceIndex -import dev.adamko.kafkatorio.schema.prototypes.FactorioPrototype -import kotlinx.serialization.EncodeDefault -import kotlinx.serialization.Serializable - - -/** No key, no caching. Must be sent instantly. */ -sealed class KafkatorioInstantPacketData : KafkatorioPacketData() - - -/* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ - - -@Serializable -data class ConfigurationUpdate( - val factorioData: ConfigurationUpdateGameData, - val allMods: List, - val modStartupSettingsChange: Boolean, - val migrationApplied: Boolean, -) : KafkatorioInstantPacketData() { - @EncodeDefault - override val updateType: KafkatorioPacketDataType = KafkatorioPacketDataType.CONFIG - - @Serializable - data class ConfigurationUpdateGameData( - val oldVersion: String? = null, - val newVersion: String? = null, - ) - - @Serializable - data class ConfigurationUpdateModData( - val modName: String, - val currentVersion: String? = null, - val previousVersion: String? = null, - ) -} - - -/* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ - - -@Serializable -data class ConsoleChatUpdate( - val authorPlayerIndex: PlayerIndex?, - val content: String, -) : KafkatorioInstantPacketData() { - @EncodeDefault - override val updateType: KafkatorioPacketDataType = KafkatorioPacketDataType.CONSOLE_CHAT -} - - -/* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ - - -@Serializable -data class ConsoleCommandUpdate( - val authorPlayerIndex: PlayerIndex?, - val command: String, - val parameters: String, -) : KafkatorioInstantPacketData() { - @EncodeDefault - override val updateType: KafkatorioPacketDataType = KafkatorioPacketDataType.CONSOLE_COMMAND -} - - -/* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ - - -@Serializable -data class PrototypesUpdate( - val prototypes: List, -) : KafkatorioInstantPacketData() { - @EncodeDefault - override val updateType: KafkatorioPacketDataType = KafkatorioPacketDataType.PROTOTYPES -} - - -/* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ - - -@Serializable -data class SurfaceUpdate( - val index: SurfaceIndex, - val daytime: Double, - val name: String, -) : KafkatorioInstantPacketData() { - @EncodeDefault - override val updateType: KafkatorioPacketDataType = KafkatorioPacketDataType.SURFACE -} - - -/* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ +// +//import dev.adamko.kafkatorio.schema.common.PlayerIndex +//import dev.adamko.kafkatorio.schema.common.SurfaceIndex +//import dev.adamko.kafkatorio.schema.prototypes.FactorioPrototype +//import kotlinx.serialization.EncodeDefault +//import kotlinx.serialization.Serializable +// +// +///** No key, no caching. Must be sent instantly. */ +//sealed class KafkatorioInstantPacketData : KafkatorioPacketData() +// +// +///* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ +// +// +//@Serializable +//data class ConfigurationUpdate( +// val factorioData: ConfigurationUpdateGameData, +// val allMods: List, +// val modStartupSettingsChange: Boolean, +// val migrationApplied: Boolean, +//) : KafkatorioInstantPacketData() { +// @EncodeDefault +// override val updateType: KafkatorioPacketDataType = KafkatorioPacketDataType.CONFIG +// +// @Serializable +// data class ConfigurationUpdateGameData( +// val oldVersion: String? = null, +// val newVersion: String? = null, +// ) +// +// @Serializable +// data class ConfigurationUpdateModData( +// val modName: String, +// val currentVersion: String? = null, +// val previousVersion: String? = null, +// ) +//} +// +// +///* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ +// +// +//@Serializable +//data class ConsoleChatUpdate( +// val authorPlayerIndex: PlayerIndex?, +// val content: String, +//) : KafkatorioInstantPacketData() { +// @EncodeDefault +// override val updateType: KafkatorioPacketDataType = KafkatorioPacketDataType.CONSOLE_CHAT +//} +// +// +///* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ +// +// +//@Serializable +//data class ConsoleCommandUpdate( +// val authorPlayerIndex: PlayerIndex?, +// val command: String, +// val parameters: String, +//) : KafkatorioInstantPacketData() { +// @EncodeDefault +// override val updateType: KafkatorioPacketDataType = KafkatorioPacketDataType.CONSOLE_COMMAND +//} +// +// +///* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ +// +// +//@Serializable +//data class PrototypesUpdate( +// val prototypes: List, +//) : KafkatorioInstantPacketData() { +// @EncodeDefault +// override val updateType: KafkatorioPacketDataType = KafkatorioPacketDataType.PROTOTYPES +//} +// +// +///* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ +// +// +//@Serializable +//data class SurfaceUpdate( +// val index: SurfaceIndex, +// val daytime: Double, +// val name: String, +//) : KafkatorioInstantPacketData() { +// @EncodeDefault +// override val updateType: KafkatorioPacketDataType = KafkatorioPacketDataType.SURFACE +//} +// +// +///* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ diff --git a/modules/events-schema/src/commonMain/kotlin/dev/adamko/kafkatorio/schema/events/kafkatorioPacketKeyed.kt b/modules/events-schema/src/commonMain/kotlin/dev/adamko/kafkatorio/schema/events/kafkatorioPacketKeyed.kt index 14d8551..236ac6e 100644 --- a/modules/events-schema/src/commonMain/kotlin/dev/adamko/kafkatorio/schema/events/kafkatorioPacketKeyed.kt +++ b/modules/events-schema/src/commonMain/kotlin/dev/adamko/kafkatorio/schema/events/kafkatorioPacketKeyed.kt @@ -1,135 +1,135 @@ package dev.adamko.kafkatorio.schema.events -import dev.adamko.kafkatorio.schema.common.Colour -import dev.adamko.kafkatorio.schema.common.EntityIdentifiers -import dev.adamko.kafkatorio.schema.common.EntityIdentifiersData -import dev.adamko.kafkatorio.schema.common.ForceIndex -import dev.adamko.kafkatorio.schema.common.MapChunkPosition -import dev.adamko.kafkatorio.schema.common.MapEntityPosition -import dev.adamko.kafkatorio.schema.common.MapTileDictionary -import dev.adamko.kafkatorio.schema.common.PlayerIndex -import dev.adamko.kafkatorio.schema.common.PrototypeName -import dev.adamko.kafkatorio.schema.common.SurfaceIndex -import dev.adamko.kafkatorio.schema.common.Tick -import dev.adamko.kafkatorio.schema.common.UnitNumber -import kotlinx.serialization.EncodeDefault -import kotlinx.serialization.Serializable - - -sealed interface KafkatorioKeyedPacketKey - - -/** Has a key, so it can be debounced */ -sealed class KafkatorioKeyedPacketData : KafkatorioPacketData() { - /** Count how many events this packet is aggregating data from */ - abstract val eventCounts: Map? -} - - -/* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ - - -sealed interface EntityUpdateKey : EntityIdentifiers, KafkatorioKeyedPacketKey { - /** A [unitNumber] is required for caching */ - override val unitNumber: UnitNumber - override val name: String - override val protoType: String -} - - -@Serializable -data class EntityUpdate( - override val unitNumber: UnitNumber, - override val name: String, - override val protoType: String, - - override val eventCounts: Map? = null, - - val chunkPosition: MapChunkPosition? = null, - val graphicsVariation: UByte? = 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, -) : KafkatorioKeyedPacketData(), EntityUpdateKey { - @EncodeDefault - override val updateType: KafkatorioPacketDataType = KafkatorioPacketDataType.ENTITY -} - - -/* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ - - -sealed interface MapChunkUpdateKey : KafkatorioKeyedPacketKey { - val chunkPosition: MapChunkPosition - val surfaceIndex: SurfaceIndex -} - - -@Serializable -data class MapChunkUpdate( - override val chunkPosition: MapChunkPosition, - override val surfaceIndex: SurfaceIndex, - - override val eventCounts: Map? = null, - - val player: PlayerIndex? = null, - val robot: EntityIdentifiersData? = null, - val force: ForceIndex? = null, - /** updated tiles - might be partial and not all tiles in the chunk */ - val tileDictionary: MapTileDictionary? = null, - val isDeleted: Boolean? = null, -) : KafkatorioKeyedPacketData(), MapChunkUpdateKey { - @EncodeDefault - override val updateType: KafkatorioPacketDataType = KafkatorioPacketDataType.MAP_CHUNK -} - - -/* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ - - -sealed interface PlayerUpdateKey : KafkatorioKeyedPacketKey { - val index: PlayerIndex -} - - -@Serializable -data class PlayerUpdate( - override val index: PlayerIndex, - - override val eventCounts: Map? = null, - - val characterUnitNumber: UnitNumber? = null, - val chatColour: Colour? = null, - val colour: Colour? = null, - val name: 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: EntityIdentifiersData? = 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, -) : KafkatorioKeyedPacketData(), PlayerUpdateKey { - @EncodeDefault - override val updateType: KafkatorioPacketDataType = KafkatorioPacketDataType.PLAYER -} - - -/* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ +//import dev.adamko.kafkatorio.schema.common.Colour +//import dev.adamko.kafkatorio.schema.common.EntityIdentifiers +//import dev.adamko.kafkatorio.schema.common.EntityIdentifiersData +//import dev.adamko.kafkatorio.schema.common.ForceIndex +//import dev.adamko.kafkatorio.schema.common.MapChunkPosition +//import dev.adamko.kafkatorio.schema.common.MapEntityPosition +//import dev.adamko.kafkatorio.schema.common.MapTileDictionary +//import dev.adamko.kafkatorio.schema.common.PlayerIndex +//import dev.adamko.kafkatorio.schema.common.PrototypeName +//import dev.adamko.kafkatorio.schema.common.SurfaceIndex +//import dev.adamko.kafkatorio.schema.common.Tick +//import dev.adamko.kafkatorio.schema.common.UnitNumber +//import kotlinx.serialization.EncodeDefault +//import kotlinx.serialization.Serializable +// +// +//sealed interface KafkatorioKeyedPacketKey +// +// +///** Has a key, so it can be debounced */ +//sealed class KafkatorioKeyedPacketData : KafkatorioPacketData() { +// /** Count how many events this packet is aggregating data from */ +// abstract val eventCounts: Map? +//} +// +// +///* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ +// +// +//sealed interface EntityUpdateKey : EntityIdentifiers, KafkatorioKeyedPacketKey { +// /** A [unitNumber] is required for caching */ +// override val unitNumber: UnitNumber +// override val name: String +// override val protoType: String +//} +// +// +//@Serializable +//data class EntityUpdate( +// override val unitNumber: UnitNumber, +// override val name: String, +// override val protoType: String, +// +// override val eventCounts: Map? = null, +// +// val chunkPosition: MapChunkPosition? = null, +// val graphicsVariation: UByte? = 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, +//) : KafkatorioKeyedPacketData(), EntityUpdateKey { +// @EncodeDefault +// override val updateType: KafkatorioPacketDataType = KafkatorioPacketDataType.ENTITY +//} +// +// +///* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ +// +// +//sealed interface MapChunkUpdateKey : KafkatorioKeyedPacketKey { +// val chunkPosition: MapChunkPosition +// val surfaceIndex: SurfaceIndex +//} +// +// +//@Serializable +//data class MapChunkUpdate( +// override val chunkPosition: MapChunkPosition, +// override val surfaceIndex: SurfaceIndex, +// +// override val eventCounts: Map? = null, +// +// val player: PlayerIndex? = null, +// val robot: EntityIdentifiersData? = null, +// val force: ForceIndex? = null, +// /** updated tiles - might be partial and not all tiles in the chunk */ +// val tileDictionary: MapTileDictionary? = null, +// val isDeleted: Boolean? = null, +//) : KafkatorioKeyedPacketData(), MapChunkUpdateKey { +// @EncodeDefault +// override val updateType: KafkatorioPacketDataType = KafkatorioPacketDataType.MAP_CHUNK +//} +// +// +///* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ +// +// +//sealed interface PlayerUpdateKey : KafkatorioKeyedPacketKey { +// val index: PlayerIndex +//} +// +// +//@Serializable +//data class PlayerUpdate( +// override val index: PlayerIndex, +// +// override val eventCounts: Map? = null, +// +// val characterUnitNumber: UnitNumber? = null, +// val chatColour: Colour? = null, +// val colour: Colour? = null, +// val name: 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: EntityIdentifiersData? = 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, +//) : KafkatorioKeyedPacketData(), PlayerUpdateKey { +// @EncodeDefault +// override val updateType: KafkatorioPacketDataType = KafkatorioPacketDataType.PLAYER +//} +// +// +///* *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** */ diff --git a/modules/events-schema/src/commonMain/kotlin/dev/adamko/kafkatorio/schema/prototypes/factorioPrototypes.kt b/modules/events-schema/src/commonMain/kotlin/dev/adamko/kafkatorio/schema/prototypes/factorioPrototypes.kt index 775b664..a65c77d 100644 --- a/modules/events-schema/src/commonMain/kotlin/dev/adamko/kafkatorio/schema/prototypes/factorioPrototypes.kt +++ b/modules/events-schema/src/commonMain/kotlin/dev/adamko/kafkatorio/schema/prototypes/factorioPrototypes.kt @@ -1,58 +1,58 @@ package dev.adamko.kafkatorio.schema.prototypes - -import dev.adamko.kafkatorio.schema.SerializerProvider -import dev.adamko.kafkatorio.schema.SerializerProviderDeserializer -import dev.adamko.kafkatorio.schema.common.Colour -import dev.adamko.kafkatorio.schema.common.PrototypeName -import dev.adamko.kafkatorio.schema.prototypes.FactorioPrototype.PrototypeObjectName -import kotlinx.serialization.Contextual -import kotlinx.serialization.DeserializationStrategy -import kotlinx.serialization.EncodeDefault -import kotlinx.serialization.KSerializer -import kotlinx.serialization.Serializable -import kotlinx.serialization.json.JsonContentPolymorphicSerializer -import kotlinx.serialization.json.JsonElement -import kotlinx.serialization.json.contentOrNull -import kotlinx.serialization.json.jsonObject -import kotlinx.serialization.json.jsonPrimitive - - -@Serializable(with = FactorioPrototype.JsonSerializer::class) -sealed class FactorioPrototype { - @EncodeDefault - abstract val prototypeObjectName: PrototypeObjectName - - enum class PrototypeObjectName( - override val serializer: KSerializer - ) : SerializerProvider { - LuaTilePrototype(MapTilePrototype.serializer()), - ; - - companion object { - val entries: Set = values().toSet() - } - } - - object JsonSerializer : SerializerProviderDeserializer( - FactorioPrototype::class, - FactorioPrototype::prototypeObjectName.name, - { json -> PrototypeObjectName.entries.firstOrNull { it.name == json } } - ) -} - - - -@Serializable -data class MapTilePrototype( - val name: PrototypeName, - val layer: UInt, - val mapColour: Colour, - @Contextual - val collisionMasks: List, - val order: String, - /** Can the tile be mined for resources? */ - val canBeMined: Boolean, -) : FactorioPrototype() { - @EncodeDefault - override val prototypeObjectName: PrototypeObjectName = PrototypeObjectName.LuaTilePrototype -} +// +//import dev.adamko.kafkatorio.schema.SerializerProvider +//import dev.adamko.kafkatorio.schema.SerializerProviderDeserializer +//import dev.adamko.kafkatorio.schema.common.Colour +//import dev.adamko.kafkatorio.schema.common.PrototypeName +//import dev.adamko.kafkatorio.schema.prototypes.FactorioPrototype.PrototypeObjectName +//import kotlinx.serialization.Contextual +//import kotlinx.serialization.DeserializationStrategy +//import kotlinx.serialization.EncodeDefault +//import kotlinx.serialization.KSerializer +//import kotlinx.serialization.Serializable +//import kotlinx.serialization.json.JsonContentPolymorphicSerializer +//import kotlinx.serialization.json.JsonElement +//import kotlinx.serialization.json.contentOrNull +//import kotlinx.serialization.json.jsonObject +//import kotlinx.serialization.json.jsonPrimitive +// +// +//@Serializable(with = FactorioPrototype.JsonSerializer::class) +//sealed class FactorioPrototype { +// @EncodeDefault +// abstract val prototypeObjectName: PrototypeObjectName +// +// enum class PrototypeObjectName( +// override val serializer: KSerializer +// ) : SerializerProvider { +// LuaTilePrototype(MapTilePrototype.serializer()), +// ; +// +// companion object { +// val entries: Set = values().toSet() +// } +// } +// +// object JsonSerializer : SerializerProviderDeserializer( +// FactorioPrototype::class, +// FactorioPrototype::prototypeObjectName.name, +// { json -> PrototypeObjectName.entries.firstOrNull { it.name == json } } +// ) +//} +// +// +// +//@Serializable +//data class MapTilePrototype( +// val name: PrototypeName, +// val layer: UInt, +// val mapColour: Colour, +// @Contextual +// val collisionMasks: List, +// val order: String, +// /** Can the tile be mined for resources? */ +// val canBeMined: Boolean, +//) : FactorioPrototype() { +// @EncodeDefault +// override val prototypeObjectName: PrototypeObjectName = PrototypeObjectName.LuaTilePrototype +//} diff --git a/modules/events-schema/src/commonMain/kotlin/dev/adamko/kafkatorio/schema2/kafkatorioPacketInstant2.kt b/modules/events-schema/src/commonMain/kotlin/dev/adamko/kafkatorio/schema2/kafkatorioPacketInstant2.kt index fe75146..0dd179d 100644 --- a/modules/events-schema/src/commonMain/kotlin/dev/adamko/kafkatorio/schema2/kafkatorioPacketInstant2.kt +++ b/modules/events-schema/src/commonMain/kotlin/dev/adamko/kafkatorio/schema2/kafkatorioPacketInstant2.kt @@ -2,7 +2,6 @@ package dev.adamko.kafkatorio.schema2 import dev.adamko.kafkatorio.schema.common.PlayerIndex import dev.adamko.kafkatorio.schema.common.SurfaceIndex -import dev.adamko.kafkatorio.schema.prototypes.FactorioPrototype import dev.adamko.kafkatorio.schema.prototypes.FactorioPrototype2 import kotlinx.serialization.Serializable diff --git a/modules/events-schema/src/jvmMain/kotlin/dev/adamko/kafkatorio/events/schema/kt2ts.kt b/modules/events-schema/src/jvmMain/kotlin/dev/adamko/kafkatorio/events/schema/kt2ts.kt index 22a3aef..eaf55a8 100644 --- a/modules/events-schema/src/jvmMain/kotlin/dev/adamko/kafkatorio/events/schema/kt2ts.kt +++ b/modules/events-schema/src/jvmMain/kotlin/dev/adamko/kafkatorio/events/schema/kt2ts.kt @@ -1,147 +1,147 @@ package dev.adamko.kafkatorio.events.schema -import dev.adamko.kafkatorio.schema.events.KafkatorioInstantPacketData -import dev.adamko.kafkatorio.schema.events.KafkatorioKeyedPacketData -import dev.adamko.kafkatorio.schema.events.KafkatorioKeyedPacketKey -//import dev.adamko.kafkatorio.schema.events.KafkatorioPacket -import dev.adamko.kafkatorio.schema.prototypes.FactorioPrototype -import kotlin.io.path.Path -import kotlin.io.path.createDirectories -import me.ntrrgc.tsGenerator.TypeScriptGenerator -import org.intellij.lang.annotations.Language - -/** - * Convert Kotlin classes to Typescript classes, using [TypeScriptGenerator] - */ -fun main(args: Array) { - - val gen = TypeScriptGenerator( - rootClasses = buildSet { -// add(KafkatorioPacket::class) -// addAll(KafkatorioPacket::class.sealedSubclasses) - - add(KafkatorioInstantPacketData::class) - addAll(KafkatorioInstantPacketData::class.sealedSubclasses) - - add(KafkatorioKeyedPacketData::class) - addAll(KafkatorioKeyedPacketData::class.sealedSubclasses) - addAll(KafkatorioKeyedPacketKey::class.sealedSubclasses) - - add(FactorioPrototype::class) - addAll(FactorioPrototype::class.sealedSubclasses) - }, - mappings = mapOf( - // builtin Factorio numeric types > `typed-factorio/generated/builtin-types.d.ts` - Float::class to "float", - Double::class to "double", - Int::class to "int", - Byte::class to "int8", - UInt::class to "uint", - UByte::class to "uint8", - UShort::class to "uint16", - ULong::class to "uint64", - ), - classTransformers = listOf( - ValueClassTransformer, -// PropertyNameTransformer, - ), -// voidType = VoidType.UNDEFINED, - ) - - val definitions = gen.definitionsText - - when (val filename = args.firstOrNull()) { - null -> println(definitions) - else -> { - val outPath = Path(filename) - outPath.createDirectories() - - splitDefinitions(definitions) - .forEach { (defFile, def) -> - val outFile = outPath.resolve(defFile).toFile() - outFile.printWriter().use { - it.println(kt2tsHeader) - it.print(def) - } - println("Generated file: $outFile") - } - - } - } -} - - -/** Split the TypeScript interfaces into different files */ -private fun splitDefinitions(definitions: String): Map { - return definitions - .split("\n\n") - .groupBy { def -> - - when { - def isInterface "KafkatorioPacket" - || def extendsAny listOf("KafkatorioPacket") - || def isType "KafkatorioPacketDataType" - -> "kafkatorio-packet.d.ts" - - def isInterface "KafkatorioInstantPacketData" - || def extends "KafkatorioInstantPacketData" - || def isType "KafkatorioInstantPacketDataType" - - || def isInterface "ConfigurationUpdateGameData" - || def isInterface "ConfigurationUpdateModData" - -> "kafkatorio-instant-packet.d.ts" - - def isInterface "KafkatorioKeyedPacket" - || def isInterface "KafkatorioKeyedPacketData" - || def extends "KafkatorioKeyedPacket" - || def isType "KafkatorioKeyedPacketDataType" - - || def isInterface "KafkatorioKeyedPacketKey" - -> "kafkatorio-keyed-packet.d.ts" - - def isInterface "FactorioPrototypes" - || def isInterface "FactorioPrototype" - || def extends "FactorioPrototype" - || def isType "PrototypeObjectName" - -> "prototype.d.ts" - - else -> "schema.d.ts" - } - } - .mapValues { (_, def) -> - def - .sorted() - .joinToString("\n\n", postfix = "\n") - .replace(" ", " ") - } -} - -@Language("TypeScript") -val kt2tsHeader = """ - |// Generated by TypeScriptGenerator - do not edit this file manually - | -""".trimMargin() - -private infix fun String.extends(types: String): Boolean = - contains(Regex(".+extends.*(${types})")) - -private infix fun String.extendsAny(types: List): Boolean = - extends(types.joinToString("|") { "$it,".replaceAfterLast(',', "") }) - -private infix fun String.isInterface(type: String): Boolean = - contains(Regex("interface $type.*")) - - -private infix fun String.isType(type: String): Boolean = - contains(Regex("type $type.*")) - - -//object PropertyNameTransformer : ClassTransformer { -// override fun transformPropertyName( -// propertyName: String, -// property: KProperty<*>, -// klass: KClass<*> -// ): String { -// return camelCaseToSnakeCase(propertyName) +//import dev.adamko.kafkatorio.schema.events.KafkatorioInstantPacketData +//import dev.adamko.kafkatorio.schema.events.KafkatorioKeyedPacketData +//import dev.adamko.kafkatorio.schema.events.KafkatorioKeyedPacketKey +////import dev.adamko.kafkatorio.schema.events.KafkatorioPacket +//import dev.adamko.kafkatorio.schema.prototypes.FactorioPrototype +//import kotlin.io.path.Path +//import kotlin.io.path.createDirectories +//import me.ntrrgc.tsGenerator.TypeScriptGenerator +//import org.intellij.lang.annotations.Language +// +///** +// * Convert Kotlin classes to Typescript classes, using [TypeScriptGenerator] +// */ +//fun main(args: Array) { +// +// val gen = TypeScriptGenerator( +// rootClasses = buildSet { +//// add(KafkatorioPacket::class) +//// addAll(KafkatorioPacket::class.sealedSubclasses) +// +// add(KafkatorioInstantPacketData::class) +// addAll(KafkatorioInstantPacketData::class.sealedSubclasses) +// +// add(KafkatorioKeyedPacketData::class) +// addAll(KafkatorioKeyedPacketData::class.sealedSubclasses) +// addAll(KafkatorioKeyedPacketKey::class.sealedSubclasses) +// +// add(FactorioPrototype::class) +// addAll(FactorioPrototype::class.sealedSubclasses) +// }, +// mappings = mapOf( +// // builtin Factorio numeric types > `typed-factorio/generated/builtin-types.d.ts` +// Float::class to "float", +// Double::class to "double", +// Int::class to "int", +// Byte::class to "int8", +// UInt::class to "uint", +// UByte::class to "uint8", +// UShort::class to "uint16", +// ULong::class to "uint64", +// ), +// classTransformers = listOf( +// ValueClassTransformer, +//// PropertyNameTransformer, +// ), +//// voidType = VoidType.UNDEFINED, +// ) +// +// val definitions = gen.definitionsText +// +// when (val filename = args.firstOrNull()) { +// null -> println(definitions) +// else -> { +// val outPath = Path(filename) +// outPath.createDirectories() +// +// splitDefinitions(definitions) +// .forEach { (defFile, def) -> +// val outFile = outPath.resolve(defFile).toFile() +// outFile.printWriter().use { +// it.println(kt2tsHeader) +// it.print(def) +// } +// println("Generated file: $outFile") +// } +// +// } // } //} +// +// +///** Split the TypeScript interfaces into different files */ +//private fun splitDefinitions(definitions: String): Map { +// return definitions +// .split("\n\n") +// .groupBy { def -> +// +// when { +// def isInterface "KafkatorioPacket" +// || def extendsAny listOf("KafkatorioPacket") +// || def isType "KafkatorioPacketDataType" +// -> "kafkatorio-packet.d.ts" +// +// def isInterface "KafkatorioInstantPacketData" +// || def extends "KafkatorioInstantPacketData" +// || def isType "KafkatorioInstantPacketDataType" +// +// || def isInterface "ConfigurationUpdateGameData" +// || def isInterface "ConfigurationUpdateModData" +// -> "kafkatorio-instant-packet.d.ts" +// +// def isInterface "KafkatorioKeyedPacket" +// || def isInterface "KafkatorioKeyedPacketData" +// || def extends "KafkatorioKeyedPacket" +// || def isType "KafkatorioKeyedPacketDataType" +// +// || def isInterface "KafkatorioKeyedPacketKey" +// -> "kafkatorio-keyed-packet.d.ts" +// +// def isInterface "FactorioPrototypes" +// || def isInterface "FactorioPrototype" +// || def extends "FactorioPrototype" +// || def isType "PrototypeObjectName" +// -> "prototype.d.ts" +// +// else -> "schema.d.ts" +// } +// } +// .mapValues { (_, def) -> +// def +// .sorted() +// .joinToString("\n\n", postfix = "\n") +// .replace(" ", " ") +// } +//} +// +//@Language("TypeScript") +//val kt2tsHeader = """ +// |// Generated by TypeScriptGenerator - do not edit this file manually +// | +//""".trimMargin() +// +//private infix fun String.extends(types: String): Boolean = +// contains(Regex(".+extends.*(${types})")) +// +//private infix fun String.extendsAny(types: List): Boolean = +// extends(types.joinToString("|") { "$it,".replaceAfterLast(',', "") }) +// +//private infix fun String.isInterface(type: String): Boolean = +// contains(Regex("interface $type.*")) +// +// +//private infix fun String.isType(type: String): Boolean = +// contains(Regex("type $type.*")) +// +// +////object PropertyNameTransformer : ClassTransformer { +//// override fun transformPropertyName( +//// propertyName: String, +//// property: KProperty<*>, +//// klass: KClass<*> +//// ): String { +//// return camelCaseToSnakeCase(propertyName) +//// } +////} diff --git a/modules/events-schema/src/jvmMain/kotlin/dev/adamko/kafkatorio/events/schema/kt2ts2.kt b/modules/events-schema/src/jvmMain/kotlin/dev/adamko/kafkatorio/events/schema/kt2ts2.kt index 38b03e3..6976f5b 100644 --- a/modules/events-schema/src/jvmMain/kotlin/dev/adamko/kafkatorio/events/schema/kt2ts2.kt +++ b/modules/events-schema/src/jvmMain/kotlin/dev/adamko/kafkatorio/events/schema/kt2ts2.kt @@ -10,6 +10,7 @@ import dev.adamko.kxstsgen.core.TsTypeRef import kotlin.io.path.Path import kotlin.io.path.createDirectories import kotlinx.serialization.builtins.serializer +import org.intellij.lang.annotations.Language @ExperimentalUnsignedTypes @@ -53,3 +54,9 @@ fun main(args: Array) { } } } + +@Language("TypeScript") +val kt2tsHeader = """ + |// Generated by kxs-ts-gen - do not edit this file manually + | +""".trimMargin() diff --git a/modules/events-server/src/main/kotlin/dev/adamko/kafkatorio/processor/topology/prototypes.kt b/modules/events-server/src/main/kotlin/dev/adamko/kafkatorio/processor/topology/prototypes.kt index 3ab14fc..96c055a 100644 --- a/modules/events-server/src/main/kotlin/dev/adamko/kafkatorio/processor/topology/prototypes.kt +++ b/modules/events-server/src/main/kotlin/dev/adamko/kafkatorio/processor/topology/prototypes.kt @@ -5,7 +5,6 @@ import dev.adamko.kafkatorio.schema.common.ColourHex import dev.adamko.kafkatorio.schema.common.MapTile import dev.adamko.kafkatorio.schema.common.toHex import dev.adamko.kafkatorio.schema.prototypes.FactorioPrototype2 -import dev.adamko.kafkatorio.schema.prototypes.MapTilePrototype import dev.adamko.kafkatorio.schema2.PrototypesUpdate import dev.adamko.kotka.extensions.materializedAs import dev.adamko.kotka.extensions.streams.filter @@ -21,7 +20,6 @@ import org.apache.kafka.streams.kstream.KTable @JvmInline @Serializable value class TileProtoHashCode private constructor(val code: Int) { - constructor(prototype: MapTilePrototype) : this(prototype.name.hashCode()) constructor(tile: MapTile) : this(tile.proto.hashCode()) constructor(tile: FactorioPrototype2.MapTile) : this(tile.name.hashCode()) }