diff --git a/modules/events-mod/src/main/resources/mod-data/locale/en/locale.cfg b/modules/events-mod/src/main/resources/mod-data/locale/en/locale.cfg new file mode 100644 index 0000000..0fa9177 --- /dev/null +++ b/modules/events-mod/src/main/resources/mod-data/locale/en/locale.cfg @@ -0,0 +1,20 @@ +[mod-setting-name] + +kafkatorio_event-cache_default-expiration-duration-seconds_PLAYER=Kafkatorio: Player update rate (seconds) +kafkatorio_event-cache_default-expiration-duration-seconds_MAP_CHUNK=Kafkatorio: Map update rate (seconds) +kafkatorio_event-cache_default-expiration-duration-seconds_ENTITY=Kafkatorio: Entity update rate (seconds) + + +[mod-setting-description] + +kafkatorio_event-cache_default-expiration-duration-seconds_PLAYER=How frequently Player updates are sent to the Kafkatorio server, in seconds. Lower means updates are sent more frequently, which may cause network congestion or reduce performance. The default (0.25 seconds) is probably fine! +kafkatorio_event-cache_default-expiration-duration-seconds_MAP_CHUNK=How frequently Map updates are sent to the Kafkatorio server, in seconds. Lower means updates are sent more frequently, which may cause network congestion or reduce performance. The default (30 seconds) is probably fine! +kafkatorio_event-cache_default-expiration-duration-seconds_ENTITY=How frequently Entity updates are sent to the Kafkatorio server, in seconds. Lower means updates are sent more frequently, which may cause network congestion or reduce performance. The default (5 seconds) is probably fine! + + +[string-mod-setting] +#-= + + +[string-mod-setting-description] +#-= diff --git a/modules/events-mod/src/main/typescript/control.ts b/modules/events-mod/src/main/typescript/control.ts index 40c1b21..18e9161 100644 --- a/modules/events-mod/src/main/typescript/control.ts +++ b/modules/events-mod/src/main/typescript/control.ts @@ -1,6 +1,7 @@ import {emitConfigurationUpdate} from "./main/config-update/handleConfigurationUpdate"; import {emitPrototypes} from "./main/config-update/prototypes"; import {initGlobal} from "./main/global-init"; +import KafkatorioSettings from "./main/settings/KafkatorioSettings"; require("./main/events/registerHandlers") require("./main/events/onMapChunkEventListeners") @@ -12,6 +13,7 @@ script.on_configuration_changed((data: ConfigurationChangedData) => { // runs whenever the version of the base game, or a mod, changes initGlobal(true) + KafkatorioSettings.loadSettings() emitConfigurationUpdate(data) emitPrototypes() }) @@ -20,4 +22,5 @@ script.on_configuration_changed((data: ConfigurationChangedData) => { script.on_init(() => { // runs only once (when the mod is first added to the save) initGlobal(true) + KafkatorioSettings.loadSettings() }) diff --git a/modules/events-mod/src/main/typescript/generated/kafkatorio-schema/prototype.d.ts b/modules/events-mod/src/main/typescript/generated/kafkatorio-schema/prototype.d.ts index a18dd09..01d4958 100644 --- a/modules/events-mod/src/main/typescript/generated/kafkatorio-schema/prototype.d.ts +++ b/modules/events-mod/src/main/typescript/generated/kafkatorio-schema/prototype.d.ts @@ -6,6 +6,12 @@ interface FactorioPrototype { prototypeObjectName: PrototypeObjectName; } +interface FactorioPrototypes extends KafkatorioPacket { + modVersion: string; + packetType: PacketType; + prototypes: FactorioPrototype[]; +} + interface MapTilePrototype extends FactorioPrototype { canBeMined: boolean; collisionMasks: string[]; @@ -15,9 +21,3 @@ interface MapTilePrototype extends FactorioPrototype { order: string; prototypeObjectName: PrototypeObjectName; } - -interface FactorioPrototypes extends KafkatorioPacket { - modVersion: string; - packetType: PacketType; - prototypes: FactorioPrototype[]; -} diff --git a/modules/events-mod/src/main/typescript/generated/kafkatorio-schema/schema.d.ts b/modules/events-mod/src/main/typescript/generated/kafkatorio-schema/schema.d.ts index d60941b..7091073 100644 --- a/modules/events-mod/src/main/typescript/generated/kafkatorio-schema/schema.d.ts +++ b/modules/events-mod/src/main/typescript/generated/kafkatorio-schema/schema.d.ts @@ -7,6 +7,14 @@ interface KafkatorioPacket { packetType: PacketType; } +interface FactorioEvent extends KafkatorioPacket { + data: FactorioObjectData; + eventType: string; + modVersion: string; + packetType: PacketType; + tick: uint; +} + interface MapEntityPosition { x: double; y: double; @@ -46,14 +54,6 @@ interface MapTile { y: int; } -interface FactorioEvent extends KafkatorioPacket { - data: FactorioObjectData; - eventType: string; - modVersion: string; - packetType: PacketType; - tick: uint; -} - interface EntityIdentifiers { name: string; type: string; diff --git a/modules/events-mod/src/main/typescript/main/cache/EventDataCache.ts b/modules/events-mod/src/main/typescript/main/cache/EventDataCache.ts index ed59119..8a0b89b 100644 --- a/modules/events-mod/src/main/typescript/main/cache/EventDataCache.ts +++ b/modules/events-mod/src/main/typescript/main/cache/EventDataCache.ts @@ -1,133 +1,162 @@ -export namespace EventDataCache { +import KafkatorioSettings from "../settings/KafkatorioSettings"; + +export namespace EventUpdates { declare const global: { cache: LuaTable>, - defaultCacheDurationTicks: Record, } - export function init(force?: boolean) { + export class Manager { - const isAnythingUndefined = global.cache == undefined || - global.defaultCacheDurationTicks == undefined - log(`Initialising EventDataCache (force=${force}, isAnythingUndefined=${isAnythingUndefined})...`) + init(force?: boolean) { - if (force == true || isAnythingUndefined) { - log("Initialising global.cache") - global.cache = new LuaTable>() + const isAnythingUndefined = global.cache == undefined - log("Initialising global.DEFAULT_CACHE_DURATION_TICKS") - global.defaultCacheDurationTicks = { - "PLAYER": 15, // 0.25 seconds - "MAP_CHUNK": 60 * 30, // 30 seconds - "ENTITY": 60 * 2, // 2 seconds - "default": 60 * 5, // 5 seconds + log(`Initialising EventDataCache (force=${force}, isAnythingUndefined=${isAnythingUndefined})...`) + + if (force == true || isAnythingUndefined) { + log("Initialising global.cache") + global.cache = new LuaTable>() + } + log(`Finished initialising EventDataCache`) + } + + + /** + * Update the cache data without restarting the 'time-to-emit' countdown, so that the data won't + * be emitted more than once per {@link CacheEntry.expirationDurationTicks}. + */ + public throttle( + key: CacheKey, + mutate: CacheDataMutator, + ) { + this.update(key, mutate, false) + } + + + /** + * Update the cache data and reset the 'time-to-emit' countdown, so the data won't be emitted + * until there's an inactivity gap of {@link CacheEntry.expirationDurationTicks}. + */ + public debounce( + key: CacheKey, + mutate: CacheDataMutator, + ) { + this.update(key, mutate, true) + } + + + private update( + key: CacheKey, + mutate: CacheDataMutator, + resetLastUpdated: boolean, + ) { + const entry = this.getCacheEntry(key) ?? this.createCacheEntry(key, mutate) + mutate(entry.data) + if (resetLastUpdated) { + entry.lastUpdatedTick = game.tick } } - log(`Finished initialising EventDataCache`) - } - /** - * Update the cache data without restarting the 'time-to-emit' countdown, so that the data won't - * be emitted more than once per {@link CacheEntry.expirationDurationTicks}. - */ - export function throttle( - key: CacheKey, - mutate: CacheDataMutator, - ) { - update(key, mutate, false) - } - - - /** - * Update the cache data and reset the 'time-to-emit' countdown, so the data won't be emitted - * until there's an inactivity gap of {@link CacheEntry.expirationDurationTicks}. - */ - export function debounce( - key: CacheKey, - mutate: CacheDataMutator, - ) { - update(key, mutate, true) - } - - - function update( - key: CacheKey, - mutate: CacheDataMutator, - resetLastUpdated: boolean, - ) { - const entry = getCacheEntry(key) ?? createCacheEntry(key, mutate) - mutate(entry.data) - if (resetLastUpdated) { - entry.lastUpdatedTick = game.tick - } - } - - - /** - * Usage example: If an urgent update comes in, then the expiration can be reduced so that - * it's transmitted sooner. - */ - export function setExpiration( - key: CacheKey, - expirationDurationTicks: uint, - ) { - const entry = getCacheEntry(key) - if (entry != undefined) { - entry.expirationDurationTicks = expirationDurationTicks - } - } - - - export function extractExpired(): Array { - let countExpired = 0 - let countTotal = 0 - const expiredData: Array = [] - for (let [key, entry] of global.cache) { - countTotal++ - if (isExpired(entry)) { - countExpired++ - expiredData.push(entry.data) - global.cache.delete(key) + /** + * Usage example: If an urgent update comes in, then the expiration can be reduced so that + * it's transmitted sooner. + */ + public setExpiration( + key: CacheKey, + expirationDurationTicks: uint, + ) { + const entry = this.getCacheEntry(key) + if (entry != undefined) { + entry.expirationDurationTicks = expirationDurationTicks } } - if (countExpired + countTotal > 0) { - log(`cache expired items count: ${countExpired}, total: ${countTotal}`) + + + public extractExpired(): Array { + let countExpired = 0 + let countTotal = 0 + const expiredData: Array = [] + for (let [key, entry] of global.cache) { + countTotal++ + if (this.isExpired(entry)) { + countExpired++ + expiredData.push(entry.data) + global.cache.delete(key) + } + } + if (countExpired + countTotal > 0) { + log(`cache expired items count: ${countExpired}, total: ${countTotal}`) + } + return expiredData } - return expiredData - } - function getCacheEntry( - key: CacheKey - ): CacheEntry | undefined { - const hash = game.encode_string(game.table_to_json(key))!! - if (!global.cache.has(hash)) { - return undefined + private getCacheEntry( + key: CacheKey + ): CacheEntry | undefined { + const hash = game.encode_string(game.table_to_json(key))!! + if (!global.cache.has(hash)) { + return undefined + } + const value: CacheEntry = global.cache.get(hash) + if (this.isEntryInstanceOf(value, key.updateType)) { + return value + } else { + // Type mismatch. This shouldn't happen... + return undefined + } } - const value: CacheEntry = global.cache.get(hash) - if (isEntryInstanceOf(value, key.updateType)) { - return value - } else { - // Type mismatch. This shouldn't happen... - return undefined + + + private createCacheEntry( + key: CacheKey, + mutate: CacheDataMutator, + ): CacheEntry { + const data: CacheData = >{...key} + mutate(data) + let entry: CacheEntry = new CacheEntry(data) + const hash = game.encode_string(game.table_to_json(key))!! + global.cache.set(hash, entry) + return entry } - } - function createCacheEntry( - key: CacheKey, - mutate: CacheDataMutator, - ): CacheEntry { - const data: CacheData = >{...key} - mutate(data) - let entry: CacheEntry = new CacheEntry(data) - const hash = game.encode_string(game.table_to_json(key))!! - global.cache.set(hash, entry) - return entry + isExpired(entry: CacheEntry): boolean { + const expiryDuration = entry.expirationDurationTicks + ?? + KafkatorioSettings.getEventCacheExpirationTicks(entry.data.updateType) + return game.tick - entry.lastUpdatedTick > expiryDuration + } + + + isEntryInstanceOf( + entry: CacheEntry | undefined, + updateType: TYPE, + ): entry is CacheEntry { + return this.isDataInstanceOf(entry?.data, updateType) + } + + + isDataInstanceOf( + data: CacheData | undefined, + updateType: TYPE, + ): data is CacheData { + return data != undefined && data.updateType == updateType + } + + + // function isKeyInstanceOf( + // key: CacheKey | undefined, + // updateType: TYPE, + // ): key is CacheKey { + // return key != undefined && key.updateType == updateType + // } + } @@ -184,34 +213,7 @@ export namespace EventDataCache { } - function isExpired(entry: CacheEntry): boolean { - const expiryDuration = - entry.expirationDurationTicks ?? global.defaultCacheDurationTicks[entry.data.updateType] - return game.tick - entry.lastUpdatedTick > expiryDuration - } - - - function isEntryInstanceOf( - entry: CacheEntry | undefined, - updateType: TYPE, - ): entry is CacheEntry { - return isDataInstanceOf(entry?.data, updateType) - } - - - function isDataInstanceOf( - data: CacheData | undefined, - updateType: TYPE, - ): data is CacheData { - return data != undefined && data.updateType == updateType - } - - - // function isKeyInstanceOf( - // key: CacheKey | undefined, - // updateType: TYPE, - // ): key is CacheKey { - // return key != undefined && key.updateType == updateType - // } - } + +const EventUpdatesManager = new EventUpdates.Manager() +export default EventUpdatesManager diff --git a/modules/events-mod/src/main/typescript/main/cache/cacheChecker.ts b/modules/events-mod/src/main/typescript/main/cache/cacheChecker.ts index 3a3f7ab..2edcb1e 100644 --- a/modules/events-mod/src/main/typescript/main/cache/cacheChecker.ts +++ b/modules/events-mod/src/main/typescript/main/cache/cacheChecker.ts @@ -1,9 +1,9 @@ -import {EventDataCache} from "./EventDataCache"; import {emitPacket} from "../emitKafkatorioPacket"; +import EventCacheService from "./EventDataCache"; /** Every 0.1 seconds */ script.on_nth_tick(6, (nthTick: NthTickEventData) => { - const cachedEvents: Array = EventDataCache.extractExpired() + const cachedEvents: Array = EventCacheService.extractExpired() if (cachedEvents.length > 0) { log(`nth tick ${nthTick.tick} has ${cachedEvents.length} events`) diff --git a/modules/events-mod/src/main/typescript/main/events/handlers.ts b/modules/events-mod/src/main/typescript/main/events/handlers.ts index 5fffc85..cb6f485 100644 --- a/modules/events-mod/src/main/typescript/main/events/handlers.ts +++ b/modules/events-mod/src/main/typescript/main/events/handlers.ts @@ -78,31 +78,31 @@ export function handleChunkUpdate( emitEvent(mapChunk, tick, eventType) } -export function handleTilesUpdate( - tick: uint, - eventType: string, - surfaceIndex: uint, - newTileType: LuaTilePrototype, - updatedTiles: OldTileAndPosition[], -) { - - if (!newTileType.collision_mask["ground-tile"] && !newTileType.collision_mask["water-tile"]) { - return - } else { - - let convertedTiles: MapTile[] = updatedTiles.map((it) => { - return { - x: it.position.x, - y: it.position.y, - proto: newTileType.name - } - }) - - let mapTiles: MapTiles = createMapTiles(surfaceIndex, convertedTiles) - - emitEvent(mapTiles, tick, eventType) - } -} +// export function handleTilesUpdate( +// tick: uint, +// eventType: string, +// surfaceIndex: uint, +// newTileType: LuaTilePrototype, +// updatedTiles: OldTileAndPosition[], +// ) { +// +// if (!newTileType.collision_mask["ground-tile"] && !newTileType.collision_mask["water-tile"]) { +// return +// } else { +// +// let convertedTiles: MapTile[] = updatedTiles.map((it) => { +// return { +// x: it.position.x, +// y: it.position.y, +// proto: newTileType.name +// } +// }) +// +// let mapTiles: MapTiles = createMapTiles(surfaceIndex, convertedTiles) +// +// emitEvent(mapTiles, tick, eventType) +// } +// } function createMapTiles( surfaceIndex: uint, diff --git a/modules/events-mod/src/main/typescript/main/events/onMapChunkEventListeners.ts b/modules/events-mod/src/main/typescript/main/events/onMapChunkEventListeners.ts index 9ec0d13..3b2284e 100644 --- a/modules/events-mod/src/main/typescript/main/events/onMapChunkEventListeners.ts +++ b/modules/events-mod/src/main/typescript/main/events/onMapChunkEventListeners.ts @@ -1,8 +1,8 @@ -import {EventDataCache} from "../cache/EventDataCache"; import {isEventType} from "./eventTypeCheck"; import {Converters} from "./converters"; -import CacheKey = EventDataCache.CacheKey; -import CacheData = EventDataCache.CacheData; +import EventUpdatesManager, {EventUpdates} from "../cache/EventDataCache"; +import CacheKey = EventUpdates.CacheKey; +import CacheData = EventUpdates.CacheData; type MapChunkUpdater = (data: CacheData<"MAP_CHUNK">) => void @@ -37,7 +37,7 @@ function mapTilesUpdateDebounce( updateType: "MAP_CHUNK", } - EventDataCache.debounce<"MAP_CHUNK">( + EventUpdatesManager.debounce<"MAP_CHUNK">( key, data => { data.tileDictionary ??= { @@ -242,14 +242,14 @@ script.on_event( updateType: "MAP_CHUNK", } - EventDataCache.debounce<"MAP_CHUNK">( + EventUpdatesManager.debounce<"MAP_CHUNK">( key, data => { data.isDeleted = true } ) // deletion is important - emit ASAP - EventDataCache.setExpiration(key, 0) + EventUpdatesManager.setExpiration(key, 0) } } ) diff --git a/modules/events-mod/src/main/typescript/main/events/onPlayerEventListeners.ts b/modules/events-mod/src/main/typescript/main/events/onPlayerEventListeners.ts index f844ec3..1f2f6bf 100644 --- a/modules/events-mod/src/main/typescript/main/events/onPlayerEventListeners.ts +++ b/modules/events-mod/src/main/typescript/main/events/onPlayerEventListeners.ts @@ -1,6 +1,7 @@ -import {EventDataCache} from "../cache/EventDataCache"; import {Converters} from "./converters"; -import CacheData = EventDataCache.CacheData; +import EventUpdatesManager, {EventUpdates} from "../cache/EventDataCache"; +import CacheData = EventUpdates.CacheData; + type PlayerUpdater = (player: LuaPlayer, data: CacheData<"PLAYER">) => void @@ -9,9 +10,9 @@ function playerUpdateThrottle( eventName: string, mutate: PlayerUpdater, ) { - EventDataCache.throttle<"PLAYER">( + EventUpdatesManager.throttle<"PLAYER">( {index: playerIndex, updateType: "PLAYER"}, - (data => { + data => { const player = game.players[playerIndex] if (player != undefined) { mutate(player, data) @@ -21,19 +22,19 @@ function playerUpdateThrottle( data.eventCounts = {} } data.eventCounts[eventName] = ((data.eventCounts ?? {}) [eventName] ?? 0) + 1 - }) + } ) } -function playerUpdateDebounce(playerIndex: uint, mutate: PlayerUpdater) { - EventDataCache.debounce<"PLAYER">( - {index: playerIndex, updateType: "PLAYER"}, - (data => { - const player = game.players[playerIndex] - mutate(player, data) - }) - ) -} +// function playerUpdateDebounce(playerIndex: uint, mutate: PlayerUpdater) { +// EventUpdatesManager.debounce<"PLAYER">( +// {index: playerIndex, updateType: "PLAYER"}, +// data => { +// const player = game.players[playerIndex] +// mutate(player, data) +// } +// ) +// } function playerOnlineInfo(player: LuaPlayer, data: CacheData<"PLAYER">) { data.lastOnline = player.last_online diff --git a/modules/events-mod/src/main/typescript/main/events/registerHandlers.ts b/modules/events-mod/src/main/typescript/main/events/registerHandlers.ts index 61a1138..a5781b4 100644 --- a/modules/events-mod/src/main/typescript/main/events/registerHandlers.ts +++ b/modules/events-mod/src/main/typescript/main/events/registerHandlers.ts @@ -7,6 +7,7 @@ import { import {Queue} from "../queue/queue"; import {isEventType} from "./eventTypeCheck"; import {Converters} from "./converters"; +import KafkatorioSettings from "../settings/KafkatorioSettings"; script.on_event( @@ -46,22 +47,22 @@ script.on_event( // } } - if (e.tick % 30 == 0) { - let events: EventData[] = Queue.dequeueValues(1) - - if (events.length > 0) { - log(`[${e.tick}] dequed ${events.length} events, current size: ${Queue.size()}`) - - for (const event of events) { - if (isEventType(event, defines.events.on_chunk_generated)) { - let eName = Converters.eventNameString(event.name) - - log(`[${e.tick}] dequed event ${eName}`) - handleChunkUpdate(e.tick, eName, event.surface.index, event.position, event.area) - } - } - } - } + // if (e.tick % 30 == 0) { + // let events: EventData[] = Queue.dequeueValues(1) + // + // if (events.length > 0) { + // log(`[${e.tick}] dequed ${events.length} events, current size: ${Queue.size()}`) + // + // for (const event of events) { + // if (isEventType(event, defines.events.on_chunk_generated)) { + // let eName = Converters.eventNameString(event.name) + // + // log(`[${e.tick}] dequed event ${eName}`) + // handleChunkUpdate(e.tick, eName, event.surface.index, event.position, event.area) + // } + // } + // } + // } } ) @@ -80,3 +81,11 @@ script.on_event( // defines.events.on_robot_built_tile, ], (builtTilesEvent) => { handleTilesUpdate( // builtTilesEvent.tick, mapEventIdToName.get(builtTilesEvent.name), builtTilesEvent.surface_index, // builtTilesEvent.tile, builtTilesEvent.tiles, ) } ) + +script.on_event( + defines.events.on_runtime_mod_setting_changed, + (e: OnRuntimeModSettingChangedEvent) => { + print(`Settings changed ${e.setting_type}, ${e.player_index}, ${e.setting}, ${e.mod_name}`) + KafkatorioSettings.loadSettings() + } +) diff --git a/modules/events-mod/src/main/typescript/main/global-init.ts b/modules/events-mod/src/main/typescript/main/global-init.ts index 920549b..9670afb 100644 --- a/modules/events-mod/src/main/typescript/main/global-init.ts +++ b/modules/events-mod/src/main/typescript/main/global-init.ts @@ -1,5 +1,5 @@ import {Queue} from "./queue/queue"; -import {EventDataCache} from "./cache/EventDataCache"; +import EventUpdatesManager from "./cache/EventDataCache"; export function initGlobal(force: boolean = false) { @@ -9,7 +9,7 @@ export function initGlobal(force: boolean = false) { global.FACTORIO_VERSION = script.active_mods["base"] Queue.init(true) - EventDataCache.init(true) + EventUpdatesManager.init(true) log("Finished initialising Kafkatorio Global variables") } diff --git a/modules/events-mod/src/main/typescript/main/settings/KafkatorioSettings.ts b/modules/events-mod/src/main/typescript/main/settings/KafkatorioSettings.ts new file mode 100644 index 0000000..31aee02 --- /dev/null +++ b/modules/events-mod/src/main/typescript/main/settings/KafkatorioSettings.ts @@ -0,0 +1,70 @@ +import {Data, DoubleSettingDefinition} from "typed-factorio/settings/types" + +export class KafkatorioSettingsConfig { + + + private static eventCacheExpirationDefaultSeconds: Record = { + "PLAYER": 0.25, + "MAP_CHUNK": 30, + "ENTITY": 5, + } + + + private eventCacheExpirationTicks: Record = { + "PLAYER": KafkatorioSettingsConfig.eventCacheExpirationDefaultSeconds["PLAYER"], + "MAP_CHUNK": KafkatorioSettingsConfig.eventCacheExpirationDefaultSeconds["MAP_CHUNK"], + "ENTITY": KafkatorioSettingsConfig.eventCacheExpirationDefaultSeconds["ENTITY"], + } + + + public getEventCacheExpirationTicks(type: FactorioEventUpdateType): uint { + return this.eventCacheExpirationTicks[type] + } + + + loadSettings(): void { + const types: FactorioEventUpdateType[] = ["PLAYER", "MAP_CHUNK", "ENTITY"] + for (const type of types) { + const seconds: double = settings.global[KafkatorioSettingsConfig.cacheDurationSettingName(type)].value as double + this.eventCacheExpirationTicks[type] = seconds * 60 // convert ticks to seconds + } + } + + + initialiseSettings(data: Data): void { + data.extend( + [ + this.createDefaultCacheDuration("PLAYER"), + this.createDefaultCacheDuration("MAP_CHUNK"), + this.createDefaultCacheDuration("ENTITY"), + ] + ) + } + + + private createDefaultCacheDuration( + type: FactorioEventUpdateType, + defaultExpirationSeconds: uint = KafkatorioSettingsConfig.eventCacheExpirationDefaultSeconds[type], + ): DoubleSettingDefinition { + return { + type: "double-setting", + name: KafkatorioSettingsConfig.cacheDurationSettingName(type), + setting_type: "runtime-global", + default_value: defaultExpirationSeconds, + // min: 0.25 seconds, max: 2 minutes + minimum_value: 0.25, + maximum_value: 120, + } + } + + + private static cacheDurationSettingName(type: FactorioEventUpdateType): string { + return `kafkatorio_event-cache_default-expiration-duration-seconds_${type}` + } + + +} + + +const KafkatorioSettings = new KafkatorioSettingsConfig() +export default KafkatorioSettings diff --git a/modules/events-mod/src/main/typescript/package-lock.json b/modules/events-mod/src/main/typescript/package-lock.json index 12bc07a..cf4979b 100644 --- a/modules/events-mod/src/main/typescript/package-lock.json +++ b/modules/events-mod/src/main/typescript/package-lock.json @@ -80,9 +80,9 @@ "integrity": "sha512-/iLa916Cw33vC6wgmCb4cPLjmvUA2zVviTx/vy80iEvpOHjoNkuHkGSsmvss1aItwUKUlHaLi3k0fK5OPiw1iA==" }, "typescript": { - "version": "4.5.5", - "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.5.5.tgz", - "integrity": "sha512-TCTIul70LyWe6IJWT8QSYeA54WQe8EjQFU4wY52Fasj5UKx88LNYKCgBEHcOMOrFF1rKGbD8v/xcNWVUq9SymA==" + "version": "4.6.2", + "resolved": "https://registry.npmjs.org/typescript/-/typescript-4.6.2.tgz", + "integrity": "sha512-HM/hFigTBHZhLXshn9sN37H085+hQGeJHJ/X7LpBWLID/fbc2acUMfU+lGD98X81sKP+pFa9f0DZmCwB9GnbAg==" }, "typescript-to-lua": { "version": "1.3.4", diff --git a/modules/events-mod/src/main/typescript/package.json b/modules/events-mod/src/main/typescript/package.json index c477325..f8f8ea1 100644 --- a/modules/events-mod/src/main/typescript/package.json +++ b/modules/events-mod/src/main/typescript/package.json @@ -15,7 +15,7 @@ "lua-types": "^2.11.0", "typescript-to-lua": "1.3.4", "typed-factorio": "0.19.1", - "typescript": "4.5.5" + "typescript": "4.6.2" }, "// @types/node": "^12.0.8", "license": "UNLICENSED", diff --git a/modules/events-mod/src/main/typescript/settings.ts b/modules/events-mod/src/main/typescript/settings.ts new file mode 100644 index 0000000..5a65e74 --- /dev/null +++ b/modules/events-mod/src/main/typescript/settings.ts @@ -0,0 +1,7 @@ +import {Data, Mods} from "typed-factorio/settings/types" +import KafkatorioSettings from "./main/settings/KafkatorioSettings"; + +declare const data: Data +declare const mods: Mods + +KafkatorioSettings.initialiseSettings(data)