From 883ed897f5a251dfc14bed86dd2fb7d6bf322348 Mon Sep 17 00:00:00 2001 From: Adam <897017+aSemy@users.noreply.github.com> Date: Wed, 18 May 2022 19:38:32 +0200 Subject: [PATCH] mod: try fixing settings not loading --- .../resources/mod-data/locale/en/locale.cfg | 12 ++-- .../events-mod/src/main/typescript/control.ts | 5 +- .../main/events/registerHandlers.ts | 2 +- .../main/settings/KafkatorioSettings.ts | 55 ++++++++++--------- 4 files changed, 39 insertions(+), 35 deletions(-) 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 index 66fba27..491d391 100644 --- 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 @@ -1,15 +1,15 @@ [mod-setting-name] -kafkatorio_event-cache_default-expiration-duration-seconds_kafkatorio-packet-keyed-PlayerUpdate=Player update rate (seconds) -kafkatorio_event-cache_default-expiration-duration-seconds_kafkatorio-packet-keyed-MapChunkUpdate=Map update rate (seconds) -kafkatorio_event-cache_default-expiration-duration-seconds_kafkatorio-packet-keyed-EntityUpdate=Entity update rate (seconds) +kafkatorio:cache-expiration-seconds_kafkatorio-packet-keyed-PlayerUpdate=Player update rate (seconds) +kafkatorio:cache-expiration-seconds_kafkatorio-packet-keyed-MapChunkUpdate=Map update rate (seconds) +kafkatorio:cache-expiration-seconds_kafkatorio-packet-keyed-EntityUpdate=Entity update rate (seconds) [mod-setting-description] -kafkatorio_event-cache_default-expiration-duration-seconds_kafkatorio-packet-keyed-PlayerUpdate=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_kafkatorio-packet-keyed-MapChunkUpdate=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_kafkatorio-packet-keyed-EntityUpdate=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! +kafkatorio:cache-expiration-seconds_kafkatorio-packet-keyed-PlayerUpdate=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:cache-expiration-seconds_kafkatorio-packet-keyed-MapChunkUpdate=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:cache-expiration-seconds_kafkatorio-packet-keyed-EntityUpdate=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] diff --git a/modules/events-mod/src/main/typescript/control.ts b/modules/events-mod/src/main/typescript/control.ts index 3933383..abf359c 100644 --- a/modules/events-mod/src/main/typescript/control.ts +++ b/modules/events-mod/src/main/typescript/control.ts @@ -10,10 +10,11 @@ require("./main/events/EntityEvents") require("./main/commands/kafkatorioCommands") require("./main/cache/cacheChecker") + script.on_configuration_changed((data: ConfigurationChangedData) => { // runs whenever the version of the base game, or a mod, changes initGlobal(true) - KafkatorioSettings.loadSettings() + // KafkatorioSettings.loadSettings() emitConfigurationUpdate(data) emitPrototypes() }) @@ -22,6 +23,6 @@ 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() + // KafkatorioSettings.loadSettings() emitPrototypes() }) 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 b2d9aa3..f8b2aa7 100644 --- a/modules/events-mod/src/main/typescript/main/events/registerHandlers.ts +++ b/modules/events-mod/src/main/typescript/main/events/registerHandlers.ts @@ -64,6 +64,6 @@ 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() + // KafkatorioSettings.loadSettings() } ) diff --git a/modules/events-mod/src/main/typescript/main/settings/KafkatorioSettings.ts b/modules/events-mod/src/main/typescript/main/settings/KafkatorioSettings.ts index 299e04d..bb90bfb 100644 --- a/modules/events-mod/src/main/typescript/main/settings/KafkatorioSettings.ts +++ b/modules/events-mod/src/main/typescript/main/settings/KafkatorioSettings.ts @@ -1,6 +1,5 @@ import {Data, DoubleSettingDefinition} from "typed-factorio/settings/types" import {KafkatorioKeyedPacketData, KafkatorioKeyedPacketTypes} from "../types"; -import {KafkatorioPacketData} from "../../generated/kafkatorio-schema/kafkatorio-schema"; export class KafkatorioSettingsConfig { @@ -12,38 +11,42 @@ export class KafkatorioSettingsConfig { } - private eventCacheExpirationTicks: Record = { - "kafkatorio.packet.keyed.PlayerUpdate": - KafkatorioSettingsConfig.eventCacheExpirationDefaultSeconds[KafkatorioPacketData.Type.PlayerUpdate], - "kafkatorio.packet.keyed.MapChunkUpdate": - KafkatorioSettingsConfig.eventCacheExpirationDefaultSeconds[KafkatorioPacketData.Type.MapChunkUpdate], - "kafkatorio.packet.keyed.EntityUpdate": - KafkatorioSettingsConfig.eventCacheExpirationDefaultSeconds[KafkatorioPacketData.Type.EntityUpdate], - } + // private eventCacheExpirationTicks: Record = { + // "kafkatorio.packet.keyed.PlayerUpdate": + // KafkatorioSettingsConfig.eventCacheExpirationDefaultSeconds[KafkatorioPacketData.Type.PlayerUpdate], + // "kafkatorio.packet.keyed.MapChunkUpdate": + // KafkatorioSettingsConfig.eventCacheExpirationDefaultSeconds[KafkatorioPacketData.Type.MapChunkUpdate], + // "kafkatorio.packet.keyed.EntityUpdate": + // KafkatorioSettingsConfig.eventCacheExpirationDefaultSeconds[KafkatorioPacketData.Type.EntityUpdate], + // } public getEventCacheExpirationTicks(packet: KafkatorioKeyedPacketData): uint { - return this.eventCacheExpirationTicks[packet.type] + const settingName = KafkatorioSettingsConfig.cacheDurationSettingName(packet.type) + const seconds: double = settings.global[settingName].value as double + return seconds * 60 // convert ticks to seconds } - private static types: KafkatorioKeyedPacketTypes[] = [ - KafkatorioPacketData.Type.PlayerUpdate, - KafkatorioPacketData.Type.MapChunkUpdate, - KafkatorioPacketData.Type.EntityUpdate, - ] + // private static types: KafkatorioKeyedPacketTypes[] = [ + // KafkatorioPacketData.Type.PlayerUpdate, + // KafkatorioPacketData.Type.MapChunkUpdate, + // KafkatorioPacketData.Type.EntityUpdate, + // ] - public loadSettings(): void { - for (const type of KafkatorioSettingsConfig.types) { - const seconds: double = settings.global[KafkatorioSettingsConfig.cacheDurationSettingName(type)].value as double - this.eventCacheExpirationTicks[type] = seconds * 60 // convert ticks to seconds - } - } + // public loadSettings(): void { + // for (const type of KafkatorioSettingsConfig.types) { + // const settingName = KafkatorioSettingsConfig.cacheDurationSettingName(type) + // const seconds: double = settings.global[settingName].value as double + // this.eventCacheExpirationTicks[type] = seconds * 60 // convert ticks to seconds + // } + // } public initialiseSettings(data: Data): void { - const settings = KafkatorioSettingsConfig.types.map( - type => KafkatorioSettingsConfig.createDefaultCacheDuration(type) - ) - data.extend(settings) + for (const [type,] of pairs(KafkatorioSettingsConfig.eventCacheExpirationDefaultSeconds)) { + data.extend( + [ KafkatorioSettingsConfig.createDefaultCacheDuration(type)] + ) + } } @@ -64,7 +67,7 @@ export class KafkatorioSettingsConfig { private static cacheDurationSettingName(type: KafkatorioKeyedPacketTypes): string { - return `kafkatorio_event-cache_default-expiration-duration-seconds_${type.replaceAll(".", "-")}` + return `kafkatorio:cache-expiration-seconds_${type.replaceAll(".", "-")}` } }