mod: try fixing settings not loading
This commit is contained in:
parent
610d559f79
commit
883ed897f5
4 changed files with 39 additions and 35 deletions
|
|
@ -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]
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
})
|
||||
|
|
|
|||
|
|
@ -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()
|
||||
}
|
||||
)
|
||||
|
|
|
|||
|
|
@ -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<KafkatorioKeyedPacketTypes, double> = {
|
||||
"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<KafkatorioKeyedPacketTypes, double> = {
|
||||
// "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(".", "-")}`
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue