fix typescript after updates

This commit is contained in:
Adam 2022-01-09 15:15:52 +01:00
parent 4d94e2f395
commit 4d2f574827
5 changed files with 20 additions and 20 deletions

View file

@ -6,14 +6,6 @@ interface FactorioObjectData {
objectName: ObjectName; objectName: ObjectName;
} }
interface FactorioEvent<T extends FactorioObjectData> extends KafkatorioPacket {
data: T;
eventType: string;
modVersion: string;
packetType: PacketType;
tick: uint;
}
interface PlayerData extends FactorioObjectData { interface PlayerData extends FactorioObjectData {
associatedCharactersUnitNumbers: uint[]; associatedCharactersUnitNumbers: uint[];
characterUnitNumber: uint | null; characterUnitNumber: uint | null;

View file

@ -3,7 +3,7 @@
type PrototypeObjectName = "LuaTilePrototype"; type PrototypeObjectName = "LuaTilePrototype";
interface FactorioPrototype { interface FactorioPrototype {
objectName: PrototypeObjectName; prototypeObjectName: PrototypeObjectName;
} }
interface FactorioMapTilePrototype extends FactorioPrototype { interface FactorioMapTilePrototype extends FactorioPrototype {
@ -12,6 +12,6 @@ interface FactorioMapTilePrototype extends FactorioPrototype {
layer: uint; layer: uint;
mapColor: Colour; mapColor: Colour;
name: string; name: string;
objectName: PrototypeObjectName;
order: string; order: string;
prototypeObjectName: PrototypeObjectName;
} }

View file

@ -7,6 +7,14 @@ interface KafkatorioPacket {
packetType: PacketType; packetType: PacketType;
} }
interface FactorioEvent extends KafkatorioPacket {
data: FactorioObjectData;
eventType: string;
modVersion: string;
packetType: PacketType;
tick: uint;
}
interface Colour { interface Colour {
alpha: float; alpha: float;
blue: float; blue: float;

View file

@ -10,10 +10,10 @@ export function convertPrototypes(): FactorioPrototype[] {
function getMapTilePrototypes(): FactorioMapTilePrototype[] { function getMapTilePrototypes(): FactorioMapTilePrototype[] {
let tiles: FactorioMapTilePrototype[] = [] let tiles: FactorioMapTilePrototype[] = []
for (let [_, tile] of pairs(game.tile_prototypes)) { for (let [, tile] of pairs(game.tile_prototypes)) {
tiles.push( tiles.push(
<FactorioMapTilePrototype>{ <FactorioMapTilePrototype>{
objectName: tile.object_name, prototypeObjectName: tile.object_name,
name: tile.name, name: tile.name,
order: tile.order, order: tile.order,
@ -29,7 +29,7 @@ function getMapTilePrototypes(): FactorioMapTilePrototype[] {
function convertCollisionMaskToNames(cm: CollisionMask): string[] { function convertCollisionMaskToNames(cm: CollisionMask): string[] {
let masks: string[] = [] let masks: string[] = []
for (let [name, _] of pairs(cm)) { for (let [name] of pairs(cm)) {
masks.push(name) masks.push(name)
} }
return masks return masks

View file

@ -13,9 +13,9 @@ import kotlinx.serialization.json.jsonPrimitive
@Serializable(with = FactorioPrototypeSerializer::class) @Serializable(with = FactorioPrototypeSerializer::class)
sealed class FactorioPrototype { sealed class FactorioPrototype {
@EncodeDefault @EncodeDefault
abstract val objectName: ObjectName abstract val prototypeObjectName: PrototypeObjectName
enum class ObjectName { enum class PrototypeObjectName {
LuaTilePrototype LuaTilePrototype
} }
} }
@ -23,7 +23,7 @@ sealed class FactorioPrototype {
object FactorioPrototypeSerializer : JsonContentPolymorphicSerializer<FactorioPrototype>( object FactorioPrototypeSerializer : JsonContentPolymorphicSerializer<FactorioPrototype>(
FactorioPrototype::class FactorioPrototype::class
) { ) {
private val key = FactorioPrototype::objectName.name private val key = FactorioPrototype::prototypeObjectName.name
override fun selectDeserializer(element: JsonElement): DeserializationStrategy<out FactorioPrototype> { override fun selectDeserializer(element: JsonElement): DeserializationStrategy<out FactorioPrototype> {
@ -32,12 +32,12 @@ object FactorioPrototypeSerializer : JsonContentPolymorphicSerializer<FactorioPr
?.jsonPrimitive ?.jsonPrimitive
?.contentOrNull ?.contentOrNull
?.let { json -> ?.let { json ->
FactorioPrototype.ObjectName.values().firstOrNull { it.name == json } FactorioPrototype.PrototypeObjectName.values().firstOrNull { it.name == json }
} }
return when (type) { return when (type) {
FactorioPrototype.ObjectName.LuaTilePrototype -> FactorioMapTilePrototype.serializer() FactorioPrototype.PrototypeObjectName.LuaTilePrototype -> FactorioMapTilePrototype.serializer()
null -> null ->
throw Exception("Unknown FactorioPrototype $key: '$type' ") throw Exception("Unknown FactorioPrototype $key: '$type' ")
} }
} }
@ -55,5 +55,5 @@ data class FactorioMapTilePrototype(
val canBeMined: Boolean, val canBeMined: Boolean,
) : FactorioPrototype() { ) : FactorioPrototype() {
@EncodeDefault @EncodeDefault
override val objectName: ObjectName = ObjectName.LuaTilePrototype override val prototypeObjectName: PrototypeObjectName = PrototypeObjectName.LuaTilePrototype
} }