code tidy

This commit is contained in:
Adam 2022-02-24 22:17:00 +01:00
parent 066f68ff4d
commit 93e02e852a
2 changed files with 2 additions and 63 deletions

View file

@ -3,7 +3,6 @@ export namespace EventDataCache {
declare const global: {
cache: LuaTable<string, CacheEntry<FactorioEventUpdateType>>,
// cache: Map<string, CacheEntry<FactorioEventUpdateType>>,
defaultCacheDurationTicks: Record<FactorioEventUpdateType | "default", uint>,
}
@ -94,7 +93,6 @@ export namespace EventDataCache {
countExpired++
expiredData.push(entry.data)
global.cache.delete(key)
}
}
log(`cache expired items count: ${countExpired}, total: ${countTotal}`)
@ -106,7 +104,6 @@ export namespace EventDataCache {
key: CacheKey<TYPE>
): CacheEntry<TYPE> | undefined {
const hash = game.encode_string(game.table_to_json(key))!!
// const value: CacheEntry<any> | undefined = global.cache.get(hash)
if (!global.cache.has(hash)) {
return undefined
}
@ -140,16 +137,12 @@ export namespace EventDataCache {
TYPE extends "ENTITY" ? EntityUpdate :
never
type ConvertToUpdateKey<TYPE extends FactorioEventUpdateType> =
TYPE extends "PLAYER" ? PlayerUpdateKey :
TYPE extends "MAP_CHUNK" ? MapChunkUpdateKey :
TYPE extends "ENTITY" ? EntityUpdateKey :
never
// type ConvertToUpdateData<TYPE extends FactorioEventUpdateType> =
// TYPE extends "PLAYER" ? PlayerUpdateData :
// TYPE extends "MAP_CHUNK" ? MapChunkUpdateData :
// TYPE extends "ENTITY" ? EntityUpdateData :
// never
/** Make `updateType` specific */

View file

@ -32,19 +32,13 @@ sealed interface FactorioEventUpdateKey {
}
//sealed interface FactorioEventUpdateData {
// val updateType: FactorioEventUpdateType
// val event: String?
//}
@Serializable(with = FactorioEventUpdate.Companion.JsonSerializer::class)
sealed class FactorioEventUpdate : FactorioEventUpdateKey {
@EncodeDefault
abstract override val updateType: FactorioEventUpdateType
@Contextual
abstract val events: List<String>?
abstract val events: List<String>? // TODO change this to Map<String, UInt>
@Serializable
enum class FactorioEventUpdateType {
@ -97,34 +91,6 @@ 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?
//}
@Serializable
data class PlayerUpdate(
override val index: PlayerIndex,
@ -172,17 +138,6 @@ 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?
//}
@Serializable
data class EntityUpdate(
@ -217,15 +172,6 @@ sealed interface MapChunkUpdateKey : FactorioEventUpdateKey {
}
//sealed interface MapChunkUpdateData : FactorioEventUpdateData {
// val player: PlayerIndex?
// val robot: EntityIdentifiers?
// val force: ForceIndex?
// val tiles: List<MapTile>?
// val isDeleted: Boolean?
//}
@Serializable
data class MapChunkUpdate(
override val chunkPosition: MapChunkPosition,