mirror of
https://github.com/Oarcinae/FactorioScenarioMultiplayerSpawn.git
synced 2025-01-22 03:08:49 +02:00
Mod settings are mostly hooked up to GUI tab now. Not all may be functional though.
This commit is contained in:
parent
394148813a
commit
173c4c8f11
@ -1,5 +1,48 @@
|
||||
-- This file is used to validate the config.lua file and handle any mod conflicts.
|
||||
|
||||
---Provides a way to look up the config settings key from the mod settings key.
|
||||
---@alias OarcSettingsLookup { mod_key: string, ocfg_keys: table<integer, string>, type: string }
|
||||
|
||||
---@type table<string, OarcSettingsLookup>
|
||||
OCFG_KEYS =
|
||||
{
|
||||
["server_info.server_msg"] = {mod_key = "oarc-mod-server-msg" , ocfg_keys = {"server_info", "server_msg"}, type = "string"},
|
||||
["server_info.welcome_msg_title"] = {mod_key = "oarc-mod-welcome-msg-title" , ocfg_keys = {"server_info", "welcome_msg_title"}, type = "string"},
|
||||
["server_info.welcome_msg"] = {mod_key = "oarc-mod-welcome-msg" , ocfg_keys = {"server_info", "welcome_msg"}, type = "string"},
|
||||
|
||||
["gameplay.enable_main_team"] = {mod_key = "oarc-mod-enable-main-team" , ocfg_keys = {"gameplay", "enable_main_team"}, type = "boolean"},
|
||||
["gameplay.enable_separate_teams"] = {mod_key = "oarc-mod-enable-separate-teams" , ocfg_keys = {"gameplay", "enable_separate_teams"}, type = "boolean"},
|
||||
["gameplay.enable_spawning_on_other_surfaces"] = {mod_key = "oarc-mod-enable-spawning-on-other-surfaces" , ocfg_keys = {"gameplay", "enable_spawning_on_other_surfaces"}, type = "boolean"},
|
||||
["gameplay.allow_moats_around_spawns"] = {mod_key = "oarc-mod-allow-moats-around-spawns" , ocfg_keys = {"gameplay", "allow_moats_around_spawns"}, type = "boolean"},
|
||||
["gameplay.enable_moat_bridging"] = {mod_key = "oarc-mod-enable-moat-bridging" , ocfg_keys = {"gameplay", "enable_moat_bridging"}, type = "boolean"},
|
||||
["gameplay.minimum_distance_to_existing_chunks"] = {mod_key = "oarc-mod-minimum-distance-to-existing-chunks" , ocfg_keys = {"gameplay", "minimum_distance_to_existing_chunks"}, type = "integer"},
|
||||
["gameplay.near_spawn_min_distance"] = {mod_key = "oarc-mod-near-spawn-min-distance" , ocfg_keys = {"gameplay", "near_spawn_min_distance"}, type = "integer"},
|
||||
["gameplay.near_spawn_max_distance"] = {mod_key = "oarc-mod-near-spawn-max-distance" , ocfg_keys = {"gameplay", "near_spawn_max_distance"}, type = "integer"},
|
||||
["gameplay.far_spawn_min_distance"] = {mod_key = "oarc-mod-far-spawn-min-distance" , ocfg_keys = {"gameplay", "far_spawn_min_distance"}, type = "integer"},
|
||||
["gameplay.far_spawn_max_distance"] = {mod_key = "oarc-mod-far-spawn-max-distance" , ocfg_keys = {"gameplay", "far_spawn_max_distance"}, type = "integer"},
|
||||
|
||||
["gameplay.enable_buddy_spawn"] = {mod_key = "oarc-mod-enable-buddy-spawn" , ocfg_keys = {"gameplay", "enable_buddy_spawn"}, type = "boolean"},
|
||||
["gameplay.enable_offline_protection"] = {mod_key = "oarc-mod-enable-offline-protection" , ocfg_keys = {"gameplay", "enable_offline_protection"}, type = "boolean"},
|
||||
["gameplay.enable_shared_team_vision"] = {mod_key = "oarc-mod-enable-shared-team-vision" , ocfg_keys = {"gameplay", "enable_shared_team_vision"}, type = "boolean"},
|
||||
["gameplay.enable_shared_team_chat"] = {mod_key = "oarc-mod-enable-shared-team-chat" , ocfg_keys = {"gameplay", "enable_shared_team_chat"}, type = "boolean"},
|
||||
["gameplay.enable_shared_spawns"] = {mod_key = "oarc-mod-enable-shared-spawns" , ocfg_keys = {"gameplay", "enable_shared_spawns"}, type = "boolean"},
|
||||
["gameplay.number_of_players_per_shared_spawn"] = {mod_key = "oarc-mod-number-of-players-per-shared-spawn" , ocfg_keys = {"gameplay", "number_of_players_per_shared_spawn"}, type = "integer"},
|
||||
["gameplay.enable_friendly_fire"] = {mod_key = "oarc-mod-enable-friendly-fire" , ocfg_keys = {"gameplay", "enable_friendly_fire"}, type = "boolean"},
|
||||
|
||||
["gameplay.main_force_name"] = {mod_key = "oarc-mod-main-force-name" , ocfg_keys = {"gameplay", "main_force_name"}, type = "string"},
|
||||
["gameplay.default_surface"] = {mod_key = "oarc-mod-default-surface" , ocfg_keys = {"gameplay", "default_surface"}, type = "string"},
|
||||
|
||||
["gameplay.scale_resources_around_spawns"] = {mod_key = "oarc-mod-scale-resources-around-spawns" , ocfg_keys = {"gameplay", "scale_resources_around_spawns"}, type = "boolean"},
|
||||
["gameplay.modified_enemy_spawning"] = {mod_key = "oarc-mod-modified-enemy-spawning" , ocfg_keys = {"gameplay", "modified_enemy_spawning"}, type = "boolean"},
|
||||
|
||||
["gameplay.minimum_online_time"] = {mod_key = "oarc-mod-minimum-online-time" , ocfg_keys = {"gameplay", "minimum_online_time"}, type = "integer"},
|
||||
["gameplay.respawn_cooldown_min"] = {mod_key = "oarc-mod-respawn-cooldown-min" , ocfg_keys = {"gameplay", "respawn_cooldown_min"}, type = "integer"},
|
||||
|
||||
["regrowth.enable_regrowth"] = {mod_key = "oarc-mod-enable-regrowth" , ocfg_keys = {"regrowth", "enable_regrowth"}, type = "boolean"},
|
||||
["regrowth.enable_world_eater"] = {mod_key = "oarc-mod-enable-world-eater" , ocfg_keys = {"regrowth", "enable_world_eater"}, type = "boolean"},
|
||||
["regrowth.enable_abandoned_base_cleanup"] = {mod_key = "oarc-mod-enable-abandoned-base-cleanup" , ocfg_keys = {"regrowth", "enable_abandoned_base_cleanup"}, type = "boolean"},
|
||||
}
|
||||
|
||||
function ValidateAndLoadConfig()
|
||||
|
||||
-- Save the config into the global table.
|
||||
@ -10,7 +53,6 @@ function ValidateAndLoadConfig()
|
||||
|
||||
GetScenarioOverrideSettings()
|
||||
|
||||
|
||||
-- Validate enable_main_team and enable_separate_teams.
|
||||
-- Force enable_main_team if both are disabled.
|
||||
if (not global.ocfg.gameplay.enable_main_team and not global.ocfg.gameplay.enable_separate_teams) then
|
||||
@ -18,6 +60,16 @@ function ValidateAndLoadConfig()
|
||||
global.ocfg.gameplay.enable_main_team = true
|
||||
end
|
||||
|
||||
-- Validate minimum is less than maximums
|
||||
if (global.ocfg.gameplay.near_spawn_min_distance >= global.ocfg.gameplay.near_spawn_max_distance) then
|
||||
log("Near spawn min distance is greater than or equal to near spawn max distance! Please check your mod settings or config!")
|
||||
global.ocfg.gameplay.near_spawn_max_distance = global.ocfg.gameplay.near_spawn_min_distance
|
||||
end
|
||||
if (global.ocfg.gameplay.far_spawn_min_distance >= global.ocfg.gameplay.far_spawn_max_distance) then
|
||||
log("Far spawn min distance is greater than or equal to far spawn max distance! Please check your mod settings or config!")
|
||||
global.ocfg.gameplay.far_spawn_max_distance = global.ocfg.gameplay.far_spawn_min_distance
|
||||
end
|
||||
|
||||
-- TODO: Vanilla spawn point are not implemented yet.
|
||||
-- Validate enable_shared_spawns and enable_buddy_spawn.
|
||||
-- if (global.ocfg.enable_vanilla_spawns) then
|
||||
@ -36,41 +88,46 @@ function CacheModSettings()
|
||||
-- settings.global["oarc-mod-number-of-vanilla-spawn-points"].value
|
||||
-- settings.global["oarc-mod-vanilla-spawn-point-spacing"].value
|
||||
|
||||
-- Copy in the global settings from the mod settings.
|
||||
global.ocfg.server_info.welcome_msg_title = settings.global["oarc-mod-welcome-msg-title"].value --[[@as string]]
|
||||
global.ocfg.server_info.welcome_msg = settings.global["oarc-mod-welcome-msg"].value --[[@as string]]
|
||||
global.ocfg.server_info.server_msg = settings.global["oarc-mod-server-msg"].value --[[@as string]]
|
||||
-- Copy the global settings from the mod settings.
|
||||
-- Find the matching OARC setting and update it.
|
||||
for _,entry in pairs(OCFG_KEYS) do
|
||||
SetGlobalOarcConfigUsingKeyTable(entry.ocfg_keys, settings.global[entry.mod_key].value)
|
||||
end
|
||||
|
||||
global.ocfg.gameplay.enable_main_team = settings.global["oarc-mod-enable-main-team"].value --[[@as boolean]]
|
||||
global.ocfg.gameplay.enable_separate_teams = settings.global["oarc-mod-enable-separate-teams"].value --[[@as boolean]]
|
||||
global.ocfg.gameplay.enable_spawning_on_other_surfaces = settings.global["oarc-mod-enable-spawning-on-other-surfaces"].value --[[@as boolean]]
|
||||
-- global.ocfg.server_info.welcome_msg_title = settings.global["oarc-mod-welcome-msg-title"].value --[[@as string]]
|
||||
-- global.ocfg.server_info.welcome_msg = settings.global["oarc-mod-welcome-msg"].value --[[@as string]]
|
||||
-- global.ocfg.server_info.server_msg = settings.global["oarc-mod-server-msg"].value --[[@as string]]
|
||||
|
||||
global.ocfg.gameplay.allow_moats_around_spawns = settings.global["oarc-mod-allow-moats-around-spawns"].value --[[@as boolean]]
|
||||
global.ocfg.gameplay.enable_moat_bridging = settings.global["oarc-mod-enable-moat-bridging"].value --[[@as boolean]]
|
||||
global.ocfg.gameplay.minimum_distance_to_existing_chunks = settings.global["oarc-mod-minimum-distance-to-existing-chunks"].value --[[@as integer]]
|
||||
global.ocfg.gameplay.near_spawn_min_distance = settings.global["oarc-mod-near-spawn-min-distance"].value --[[@as integer]]
|
||||
global.ocfg.gameplay.near_spawn_max_distance = settings.global["oarc-mod-near-spawn-max-distance"].value --[[@as integer]]
|
||||
global.ocfg.gameplay.far_spawn_min_distance = settings.global["oarc-mod-far-spawn-min-distance"].value --[[@as integer]]
|
||||
global.ocfg.gameplay.far_spawn_max_distance = settings.global["oarc-mod-far-spawn-max-distance"].value --[[@as integer]]
|
||||
-- global.ocfg.gameplay.enable_main_team = settings.global["oarc-mod-enable-main-team"].value --[[@as boolean]]
|
||||
-- global.ocfg.gameplay.enable_separate_teams = settings.global["oarc-mod-enable-separate-teams"].value --[[@as boolean]]
|
||||
-- global.ocfg.gameplay.enable_spawning_on_other_surfaces = settings.global["oarc-mod-enable-spawning-on-other-surfaces"].value --[[@as boolean]]
|
||||
|
||||
global.ocfg.gameplay.enable_buddy_spawn = settings.global["oarc-mod-enable-buddy-spawn"].value --[[@as boolean]]
|
||||
global.ocfg.gameplay.enable_offline_protection = settings.global["oarc-mod-enable-offline-protection"].value --[[@as boolean]]
|
||||
global.ocfg.gameplay.enable_shared_team_vision = settings.global["oarc-mod-enable-shared-team-vision"].value --[[@as boolean]]
|
||||
global.ocfg.gameplay.enable_shared_team_chat = settings.global["oarc-mod-enable-shared-team-chat"].value --[[@as boolean]]
|
||||
global.ocfg.gameplay.enable_shared_spawns = settings.global["oarc-mod-enable-shared-spawns"].value --[[@as boolean]]
|
||||
global.ocfg.gameplay.number_of_players_per_shared_spawn = settings.global["oarc-mod-number-of-players-per-shared-spawn"].value --[[@as integer]]
|
||||
global.ocfg.gameplay.enable_friendly_fire = settings.global["oarc-mod-enable-friendly-fire"].value --[[@as boolean]]
|
||||
-- global.ocfg.gameplay.allow_moats_around_spawns = settings.global["oarc-mod-allow-moats-around-spawns"].value --[[@as boolean]]
|
||||
-- global.ocfg.gameplay.enable_moat_bridging = settings.global["oarc-mod-enable-moat-bridging"].value --[[@as boolean]]
|
||||
-- global.ocfg.gameplay.minimum_distance_to_existing_chunks = settings.global["oarc-mod-minimum-distance-to-existing-chunks"].value --[[@as integer]]
|
||||
-- global.ocfg.gameplay.near_spawn_min_distance = settings.global["oarc-mod-near-spawn-min-distance"].value --[[@as integer]]
|
||||
-- global.ocfg.gameplay.near_spawn_max_distance = settings.global["oarc-mod-near-spawn-max-distance"].value --[[@as integer]]
|
||||
-- global.ocfg.gameplay.far_spawn_min_distance = settings.global["oarc-mod-far-spawn-min-distance"].value --[[@as integer]]
|
||||
-- global.ocfg.gameplay.far_spawn_max_distance = settings.global["oarc-mod-far-spawn-max-distance"].value --[[@as integer]]
|
||||
|
||||
global.ocfg.gameplay.main_force_name = settings.global["oarc-mod-main-force-name"].value --[[@as string]]
|
||||
global.ocfg.gameplay.default_surface = settings.global["oarc-mod-default-surface"].value --[[@as string]]
|
||||
global.ocfg.gameplay.scale_resources_around_spawns = settings.global["oarc-mod-scale-resources-around-spawns"].value --[[@as boolean]]
|
||||
global.ocfg.gameplay.modified_enemy_spawning = settings.global["oarc-mod-modified-enemy-spawning"].value --[[@as boolean]]
|
||||
global.ocfg.gameplay.minimum_online_time = settings.global["oarc-mod-minimum-online-time"].value --[[@as integer]]
|
||||
global.ocfg.gameplay.respawn_cooldown_min = settings.global["oarc-mod-respawn-cooldown-min"].value --[[@as integer]]
|
||||
-- global.ocfg.gameplay.enable_buddy_spawn = settings.global["oarc-mod-enable-buddy-spawn"].value --[[@as boolean]]
|
||||
-- global.ocfg.gameplay.enable_offline_protection = settings.global["oarc-mod-enable-offline-protection"].value --[[@as boolean]]
|
||||
-- global.ocfg.gameplay.enable_shared_team_vision = settings.global["oarc-mod-enable-shared-team-vision"].value --[[@as boolean]]
|
||||
-- global.ocfg.gameplay.enable_shared_team_chat = settings.global["oarc-mod-enable-shared-team-chat"].value --[[@as boolean]]
|
||||
-- global.ocfg.gameplay.enable_shared_spawns = settings.global["oarc-mod-enable-shared-spawns"].value --[[@as boolean]]
|
||||
-- global.ocfg.gameplay.number_of_players_per_shared_spawn = settings.global["oarc-mod-number-of-players-per-shared-spawn"].value --[[@as integer]]
|
||||
-- global.ocfg.gameplay.enable_friendly_fire = settings.global["oarc-mod-enable-friendly-fire"].value --[[@as boolean]]
|
||||
|
||||
global.ocfg.regrowth.enable_regrowth = settings.global["oarc-mod-enable-regrowth"].value --[[@as boolean]]
|
||||
global.ocfg.regrowth.enable_world_eater = settings.global["oarc-mod-enable-world-eater"].value --[[@as string]]
|
||||
global.ocfg.regrowth.enable_abandoned_base_cleanup = settings.global["oarc-mod-enable-abandoned-base-cleanup"].value --[[@as boolean]]
|
||||
-- global.ocfg.gameplay.main_force_name = settings.global["oarc-mod-main-force-name"].value --[[@as string]]
|
||||
-- global.ocfg.gameplay.default_surface = settings.global["oarc-mod-default-surface"].value --[[@as string]]
|
||||
-- global.ocfg.gameplay.scale_resources_around_spawns = settings.global["oarc-mod-scale-resources-around-spawns"].value --[[@as boolean]]
|
||||
-- global.ocfg.gameplay.modified_enemy_spawning = settings.global["oarc-mod-modified-enemy-spawning"].value --[[@as boolean]]
|
||||
-- global.ocfg.gameplay.minimum_online_time = settings.global["oarc-mod-um-online-time"].value --[[@as integer]]
|
||||
-- global.ocfg.gameplay.respawn_cooldown_min = settings.global["oarc-mod-respawn-cooldown-min"].value --[[@as integer]]
|
||||
|
||||
-- global.ocfg.regrowth.enable_regrowth = settings.global["oarc-mod-enable-regrowth"].value --[[@as boolean]]
|
||||
-- global.ocfg.regrowth.enable_world_eater = settings.global["oarc-mod-enable-world-eater"].value--[[@as boolean]]
|
||||
-- global.ocfg.regrowth.enable_abandoned_base_cleanup = settings.global["oarc-mod-enable-abandoned-base-cleanup"].value --[[@as boolean]]
|
||||
end
|
||||
|
||||
function GetScenarioOverrideSettings()
|
||||
@ -96,65 +153,52 @@ function RuntimeModSettingChanged(event)
|
||||
|
||||
log("on_runtime_mod_setting_changed" .. event.setting)
|
||||
|
||||
if (event.setting == "oarc-mod-welcome-msg-title") then
|
||||
global.ocfg.server_info.welcome_msg_title = settings.global["oarc-mod-welcome-msg-title"].value --[[@as string]]
|
||||
elseif (event.setting == "oarc-mod-welcome-msg") then
|
||||
global.ocfg.server_info.welcome_msg = settings.global["oarc-mod-welcome-msg"].value --[[@as string]]
|
||||
elseif (event.setting == "oarc-mod-server-msg") then
|
||||
global.ocfg.server_info.server_msg = settings.global["oarc-mod-server-msg"].value --[[@as string]]
|
||||
elseif (event.setting == "oarc-mod-enable-main-team") then
|
||||
global.ocfg.gameplay.enable_main_team = settings.global["oarc-mod-enable-main-team"].value --[[@as boolean]]
|
||||
elseif (event.setting == "oarc-mod-enable-separate-teams") then
|
||||
global.ocfg.gameplay.enable_separate_teams = settings.global["oarc-mod-enable-separate-teams"].value --[[@as boolean]]
|
||||
elseif (event.setting == "oarc-mod-enable-spawning-on-other-surfaces") then
|
||||
global.ocfg.gameplay.enable_spawning_on_other_surfaces = settings.global["oarc-mod-enable-spawning-on-other-surfaces"].value --[[@as boolean]]
|
||||
elseif (event.setting == "oarc-mod-allow-moats-around-spawns") then
|
||||
global.ocfg.gameplay.allow_moats_around_spawns = settings.global["oarc-mod-allow-moats-around-spawns"].value --[[@as boolean]]
|
||||
elseif (event.setting == "oarc-mod-enable-moat-bridging") then
|
||||
global.ocfg.gameplay.enable_moat_bridging = settings.global["oarc-mod-enable-moat-bridging"].value --[[@as boolean]]
|
||||
elseif (event.setting == "oarc-mod-minimum-distance-to-existing-chunks") then
|
||||
global.ocfg.gameplay.minimum_distance_to_existing_chunks = settings.global["oarc-mod-minimum-distance-to-existing-chunks"].value --[[@as integer]]
|
||||
elseif (event.setting == "oarc-mod-near-spawn-min-distance") then
|
||||
global.ocfg.gameplay.near_spawn_min_distance = settings.global["oarc-mod-near-spawn-min-distance"].value --[[@as integer]]
|
||||
elseif (event.setting == "oarc-mod-near-spawn-max-distance") then
|
||||
global.ocfg.gameplay.near_spawn_max_distance = settings.global["oarc-mod-near-spawn-max-distance"].value --[[@as integer]]
|
||||
elseif (event.setting == "oarc-mod-far-spawn-min-distance") then
|
||||
global.ocfg.gameplay.far_spawn_min_distance = settings.global["oarc-mod-far-spawn-min-distance"].value --[[@as integer]]
|
||||
elseif (event.setting == "oarc-mod-far-spawn-max-distance") then
|
||||
global.ocfg.gameplay.far_spawn_max_distance = settings.global["oarc-mod-far-spawn-max-distance"].value --[[@as integer]]
|
||||
elseif (event.setting == "oarc-mod-enable-buddy-spawn") then
|
||||
global.ocfg.gameplay.enable_buddy_spawn = settings.global["oarc-mod-enable-buddy-spawn"].value --[[@as boolean]]
|
||||
elseif (event.setting == "oarc-mod-enable-offline-protection") then
|
||||
global.ocfg.gameplay.enable_offline_protection = settings.global["oarc-mod-enable-offline-protection"].value --[[@as boolean]]
|
||||
elseif (event.setting == "oarc-mod-enable-shared-team-vision") then
|
||||
global.ocfg.gameplay.enable_shared_team_vision = settings.global["oarc-mod-enable-shared-team-vision"].value --[[@as boolean]]
|
||||
elseif (event.setting == "oarc-mod-enable-shared-team-chat") then
|
||||
global.ocfg.gameplay.enable_shared_team_chat = settings.global["oarc-mod-enable-shared-team-chat"].value --[[@as boolean]]
|
||||
elseif (event.setting == "oarc-mod-enable-shared-spawns") then
|
||||
global.ocfg.gameplay.enable_shared_spawns = settings.global["oarc-mod-enable-shared-spawns"].value --[[@as boolean]]
|
||||
elseif (event.setting == "oarc-mod-number-of-players-per-shared-spawn") then
|
||||
global.ocfg.gameplay.number_of_players_per_shared_spawn = settings.global["oarc-mod-number-of-players-per-shared-spawn"].value --[[@as integer]]
|
||||
elseif (event.setting == "oarc-mod-enable-friendly-fire") then
|
||||
global.ocfg.gameplay.enable_friendly_fire = settings.global["oarc-mod-enable-friendly-fire"].value --[[@as boolean]]
|
||||
elseif (event.setting == "oarc-mod-main-force-name") then
|
||||
global.ocfg.gameplay.main_force_name = settings.global["oarc-mod-main-force-name"].value --[[@as string]]
|
||||
elseif (event.setting == "oarc-mod-default-surface") then
|
||||
global.ocfg.gameplay.default_surface = settings.global["oarc-mod-default-surface"].value --[[@as string]]
|
||||
elseif (event.setting == "oarc-mod-scale-resources-around-spawns") then
|
||||
global.ocfg.gameplay.scale_resources_around_spawns = settings.global["oarc-mod-scale-resources-around-spawns"].value --[[@as boolean]]
|
||||
elseif (event.setting == "oarc-mod-modified-enemy-spawning") then
|
||||
global.ocfg.gameplay.modified_enemy_spawning = settings.global["oarc-mod-modified-enemy-spawning"].value --[[@as boolean]]
|
||||
elseif (event.setting == "oarc-mod-minimum-online-time") then
|
||||
global.ocfg.gameplay.minimum_online_time = settings.global["oarc-mod-minimum-online-time"].value --[[@as integer]]
|
||||
elseif (event.setting == "oarc-mod-respawn-cooldown-min") then
|
||||
global.ocfg.gameplay.respawn_cooldown_min = settings.global["oarc-mod-respawn-cooldown-min"].value --[[@as integer]]
|
||||
elseif (event.setting == "oarc-mod-enable-regrowth") then
|
||||
global.ocfg.regrowth.enable_regrowth = settings.global["oarc-mod-enable-regrowth"].value --[[@as boolean]]
|
||||
elseif (event.setting == "oarc-mod-enable-world-eater") then
|
||||
global.ocfg.regrowth.enable_world_eater = settings.global["oarc-mod-enable-world-eater"].value --[[@as string]]
|
||||
elseif (event.setting == "oarc-mod-enable-abandoned-base-cleanup") then
|
||||
global.ocfg.regrowth.enable_abandoned_base_cleanup = settings.global["oarc-mod-enable-abandoned-base-cleanup"].value --[[@as boolean]]
|
||||
else
|
||||
-- Find the matching OARC setting and update it.
|
||||
local found_setting = false
|
||||
for _,entry in pairs(OCFG_KEYS) do
|
||||
if (event.setting == entry.mod_key) then
|
||||
SetGlobalOarcConfigUsingKeyTable(entry.ocfg_keys, settings.global[entry.mod_key].value)
|
||||
found_setting = true
|
||||
goto LOOP_BREAK
|
||||
end
|
||||
end
|
||||
::LOOP_BREAK::
|
||||
|
||||
if (not found_setting) then
|
||||
error("Unknown oarc-mod setting changed: " .. event.setting)
|
||||
end
|
||||
end
|
||||
|
||||
---A probably quit stupid function to let me lookup and set the global.ocfg entries using a key table.
|
||||
---@param key_table table<integer, string>
|
||||
---@param value any
|
||||
function SetGlobalOarcConfigUsingKeyTable(key_table, value)
|
||||
local number_of_keys = #key_table
|
||||
|
||||
if (number_of_keys == 1) then
|
||||
global.ocfg[key_table[1]] = value
|
||||
elseif (number_of_keys == 2) then
|
||||
global.ocfg[key_table[1]][key_table[2]] = value
|
||||
elseif (number_of_keys == 3) then
|
||||
global.ocfg[key_table[1]][key_table[2]][key_table[3]] = value
|
||||
else
|
||||
error("Invalid key_table length: " .. number_of_keys .. "\n" .. serpent.block(key_table))
|
||||
end
|
||||
end
|
||||
|
||||
---An equally stupid function to let me lookup the global.ocfg entries using a key table.
|
||||
---@param key_table table<integer, string>
|
||||
---@return any
|
||||
function GetGlobalOarcConfigUsingKeyTable(key_table)
|
||||
local number_of_keys = #key_table
|
||||
|
||||
if (number_of_keys == 1) then
|
||||
return global.ocfg[key_table[1]]
|
||||
elseif (number_of_keys == 2) then
|
||||
return global.ocfg[key_table[1]][key_table[2]]
|
||||
elseif (number_of_keys == 3) then
|
||||
return global.ocfg[key_table[1]][key_table[2]][key_table[3]]
|
||||
else
|
||||
error("Invalid key_table length: " .. number_of_keys .. "\n" .. serpent.block(key_table))
|
||||
end
|
||||
end
|
@ -10,12 +10,15 @@ function CreateSettingsControlsTab(tab_container, player)
|
||||
AddLabel(tab_container, nil, { "oarc-settings-tab-admin-warning" }, my_warning_style)
|
||||
end
|
||||
|
||||
AddTextfieldSetting(tab_container, "welcome_msg_title", { "mod-setting-name.oarc-mod-welcome-msg-title" },
|
||||
global.ocfg.server_info.welcome_msg_title, player.admin, { "mod-setting-description.oarc-mod-welcome-msg-title" })
|
||||
|
||||
AddCheckboxSetting(tab_container, "enable_main_team", { "mod-setting-name.oarc-mod-enable-main-team" },
|
||||
global.ocfg.gameplay.enable_main_team, player.admin, { "mod-setting-description.oarc-mod-enable-main-team" })
|
||||
|
||||
for index,entry in pairs(OCFG_KEYS) do
|
||||
if (entry.type == "boolean") then
|
||||
AddCheckboxSetting(tab_container, index, entry, player.admin)
|
||||
elseif (entry.type == "string") then
|
||||
AddTextfieldSetting(tab_container, index, entry, player.admin)
|
||||
elseif (entry.type == "integer") then
|
||||
AddIntegerSetting(tab_container, index, entry, player.admin)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---Handles the click event for the tab used by AddOarcGuiTab
|
||||
@ -23,54 +26,107 @@ end
|
||||
---@return nil
|
||||
function SettingsControlsTabGuiClick(event)
|
||||
if not (event.element.valid) then return end
|
||||
|
||||
local gui_elem = event.element
|
||||
-- local player = game.players[event.player_index]
|
||||
|
||||
if (gui_elem.tags.action ~= "oarc_settings_tab") then return end
|
||||
|
||||
local setting_name = gui_elem.tags.setting
|
||||
|
||||
if (setting_name == "enable_main_team") then
|
||||
log("enable_main_team: " .. tostring(gui_elem.state))
|
||||
global.ocfg.gameplay.enable_main_team = gui_elem.state
|
||||
settings.global["oarc-mod-enable-main-team"] = { value = gui_elem.state }
|
||||
for index,entry in pairs(OCFG_KEYS) do
|
||||
if (index == setting_name) then
|
||||
if (entry.type == "boolean") then
|
||||
SetGlobalOarcConfigUsingKeyTable(entry.ocfg_keys, gui_elem.state)
|
||||
settings.global[entry.mod_key] = { value = gui_elem.state }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---Creates a checkbox setting in the tab used by AddOarcGuiTab
|
||||
---@param tab_container LuaGuiElement
|
||||
---@param setting_name string
|
||||
---@param setting_caption LocalisedString
|
||||
---@param setting_state boolean
|
||||
---@param enabled boolean
|
||||
---@param tooltip LocalisedString
|
||||
---Handles the text entry event for the tab used by AddOarcGuiTab
|
||||
---@param event EventData.on_gui_text_changed
|
||||
---@return nil
|
||||
function AddCheckboxSetting(tab_container, setting_name, setting_caption, setting_state, enabled, tooltip)
|
||||
tab_container.add {
|
||||
function SettingsControlsTabGuiTextChanged(event)
|
||||
if not (event.element.valid) then return end
|
||||
|
||||
local gui_elem = event.element
|
||||
if (gui_elem.tags.action ~= "oarc_settings_tab") then return end
|
||||
local setting_name = gui_elem.tags.setting
|
||||
|
||||
for index,entry in pairs(OCFG_KEYS) do
|
||||
if (index == setting_name) then
|
||||
if (entry.type == "string") or (entry.type == "integer") then
|
||||
SetGlobalOarcConfigUsingKeyTable(entry.ocfg_keys, gui_elem.text)
|
||||
settings.global[entry.mod_key] = { value = gui_elem.text }
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
---Creates a checkbox setting
|
||||
---@param tab_container LuaGuiElement
|
||||
---@param index string
|
||||
---@param entry OarcSettingsLookup
|
||||
---@param enabled boolean
|
||||
---@return nil
|
||||
function AddCheckboxSetting(tab_container, index, entry, enabled)
|
||||
tab_container.add{
|
||||
type = "checkbox",
|
||||
caption = setting_caption,
|
||||
state = setting_state,
|
||||
caption = { "mod-setting-name."..entry.mod_key },
|
||||
state = GetGlobalOarcConfigUsingKeyTable(entry.ocfg_keys),
|
||||
enabled = enabled,
|
||||
tooltip = tooltip,
|
||||
tags = { action = "oarc_settings_tab", setting = setting_name },
|
||||
tooltip = { "mod-setting-description."..entry.mod_key },
|
||||
tags = { action = "oarc_settings_tab", setting = index },
|
||||
}
|
||||
end
|
||||
|
||||
---Creates a textfield setting in the tab used by AddOarcGuiTab
|
||||
---Creates a textfield setting
|
||||
---@param tab_container LuaGuiElement
|
||||
---@param setting_name string
|
||||
---@param setting_caption LocalisedString
|
||||
---@param setting_string string
|
||||
---@param index string
|
||||
---@param entry OarcSettingsLookup
|
||||
---@param enabled boolean
|
||||
---@param tooltip LocalisedString
|
||||
---@return nil
|
||||
function AddTextfieldSetting(tab_container, setting_name, setting_caption, setting_string, enabled, tooltip)
|
||||
tab_container.add {
|
||||
function AddTextfieldSetting(tab_container, index, entry, enabled)
|
||||
local horizontal_flow = tab_container.add {
|
||||
type = "flow",
|
||||
direction = "horizontal",
|
||||
}
|
||||
horizontal_flow.add {
|
||||
type = "label",
|
||||
caption = { "mod-setting-name."..entry.mod_key },
|
||||
tooltip = { "mod-setting-description."..entry.mod_key },
|
||||
}
|
||||
horizontal_flow.add {
|
||||
type = "textfield",
|
||||
caption = setting_caption,
|
||||
text = setting_string,
|
||||
caption = { "mod-setting-name."..entry.mod_key },
|
||||
text = GetGlobalOarcConfigUsingKeyTable(entry.ocfg_keys),
|
||||
enabled = enabled,
|
||||
tooltip = tooltip,
|
||||
tags = { action = "oarc_settings_tab", setting = setting_name },
|
||||
tooltip = { "mod-setting-description."..entry.mod_key },
|
||||
tags = { action = "oarc_settings_tab", setting = index },
|
||||
}
|
||||
end
|
||||
|
||||
---Creates an integer setting
|
||||
---@param tab_container LuaGuiElement
|
||||
---@param index string
|
||||
---@param entry OarcSettingsLookup
|
||||
---@param enabled boolean
|
||||
---@return nil
|
||||
function AddIntegerSetting(tab_container, index, entry, enabled)
|
||||
local horizontal_flow = tab_container.add {
|
||||
type = "flow",
|
||||
direction = "horizontal",
|
||||
}
|
||||
horizontal_flow.add {
|
||||
type = "label",
|
||||
caption = { "mod-setting-name."..entry.mod_key },
|
||||
tooltip = { "mod-setting-description."..entry.mod_key },
|
||||
}
|
||||
horizontal_flow.add {
|
||||
type = "textfield",
|
||||
numeric = true,
|
||||
caption = { "mod-setting-name."..entry.mod_key },
|
||||
text = GetGlobalOarcConfigUsingKeyTable(entry.ocfg_keys),
|
||||
enabled = enabled,
|
||||
tooltip = { "mod-setting-description."..entry.mod_key },
|
||||
tags = { action = "oarc_settings_tab", setting = index },
|
||||
}
|
||||
end
|
@ -20,12 +20,12 @@ OARC_REGROWTH_CTRL_TAB_NAME = "Regrowth"
|
||||
OARC_CONFIG_CTRL_TAB_NAME = "Settings"
|
||||
|
||||
|
||||
local OARC_GUI_TAB_CONTENT_FUNCTIONS = {}
|
||||
OARC_GUI_TAB_CONTENT_FUNCTIONS["Server Info"] = CreateServerInfoTab
|
||||
OARC_GUI_TAB_CONTENT_FUNCTIONS["Spawn Controls"] = CreateSpawnControlsTab
|
||||
OARC_GUI_TAB_CONTENT_FUNCTIONS["Regrowth"] = CreateRegrowthControlsTab
|
||||
OARC_GUI_TAB_CONTENT_FUNCTIONS["Settings"] = CreateSettingsControlsTab
|
||||
|
||||
local OARC_GUI_TAB_CONTENT_FUNCTIONS = {
|
||||
["Server Info"] = CreateServerInfoTab,
|
||||
["Spawn Controls"] = CreateSpawnControlsTab,
|
||||
["Regrowth"] = CreateRegrowthControlsTab,
|
||||
["Settings"] = CreateSettingsControlsTab,
|
||||
}
|
||||
|
||||
---@param player LuaPlayer
|
||||
---@return nil
|
||||
|
@ -25,8 +25,7 @@ REGROWTH_FLAG_PERMANENT = -2
|
||||
REGROWTH_ACTIVE_AREA_AROUND_PLAYER = 4
|
||||
|
||||
---The removal list contains chunks that are marked for removal. Each entry is a table with the following fields:
|
||||
---{ pos = { x = number, y = number }, force = boolean, surface = string }
|
||||
---@class RemovalListEntry : table<ChunkPosition, boolean, string>
|
||||
---@alias RemovalListEntry { pos : ChunkPosition, force: boolean, surface: string }
|
||||
|
||||
|
||||
---Init globals for regrowth
|
||||
@ -38,7 +37,7 @@ function RegrowthInit()
|
||||
global.rg.force_removal_flag = -2000 -- Set to a negative number to disable it by default
|
||||
global.rg.timeout_ticks = REGROWTH_TIMEOUT_TICKS
|
||||
|
||||
global.rrent_surface = nil -- The current surface we are iterating through
|
||||
global.rg.current_surface = nil -- The current surface we are iterating through
|
||||
global.rg.current_surface_index = 1
|
||||
global.rg.active_surfaces = {} -- List of all surfaces with regrowth enabled
|
||||
global.rg.chunk_iter = nil -- We only iterate through onface at a time
|
||||
@ -48,7 +47,7 @@ function RegrowthInit()
|
||||
global.rg.we_current_surface = nil
|
||||
global.rg.we_current_surface_index = 1
|
||||
|
||||
---@type table<RemovalListEntry>
|
||||
---@type table<integer, RemovalListEntry>
|
||||
global.rg.removal_list = {}
|
||||
|
||||
for surface_name,_ in pairs(game.surfaces) do
|
||||
@ -98,9 +97,10 @@ function InitSurface(surface_name)
|
||||
-- This is a 2D array of chunk positions and their last tick updated / status
|
||||
global.rg[surface_name].map = {}
|
||||
|
||||
-- Set the current surface to the first one found
|
||||
-- Set the current surface tone found
|
||||
if (global.rg.current_surface == nil) then
|
||||
global.rg.current_surface = surface_name
|
||||
global.rg.we_current_surface = surface_name
|
||||
end
|
||||
|
||||
table.insert(global.rg.active_surfaces, surface_name)
|
||||
@ -137,9 +137,11 @@ function GetNextPlayerIndex()
|
||||
return global.rg.player_refresh_index
|
||||
end
|
||||
|
||||
---@alias ActiveSurfaceInfo { surface : string, index : integer }
|
||||
|
||||
---Sets the current surface to the next active surface. This is used to loop through surfaces.
|
||||
---@param current_index integer - The current index in the active surfaces list
|
||||
---@return table<string, integer> - The new current surface name and index
|
||||
---@return ActiveSurfaceInfo - The new current surface name and index
|
||||
function GetNextActiveSurface(current_index)
|
||||
|
||||
local count = #(global.rg.active_surfaces)
|
||||
@ -495,8 +497,6 @@ end
|
||||
function WorldEaterSingleStep()
|
||||
local current_surface = global.rg.we_current_surface
|
||||
|
||||
log("RegrowthSingleStepArray: Switching to next surface: " .. global.rg.current_surface)
|
||||
|
||||
-- Make sure we have a valid iterator!
|
||||
if (not global.rg.world_eater_iter or not global.rg.world_eater_iter.valid) then
|
||||
global.rg.world_eater_iter = game.surfaces[current_surface].get_chunks()
|
||||
@ -514,10 +514,15 @@ function WorldEaterSingleStep()
|
||||
global.rg.we_current_surface_index = next_surface_info.index
|
||||
current_surface = global.rg.we_current_surface
|
||||
|
||||
log("WorldEaterSingleStep: Switching to next surface: " .. global.rg.we_current_surface)
|
||||
-- log("WorldEaterSingleStep: Switching to next surface: " .. global.rg.we_current_surface)
|
||||
|
||||
global.rg.world_eater_iter = game.surfaces[current_surface].get_chunks()
|
||||
next_chunk = global.rg.world_eater_iter()
|
||||
|
||||
-- Possible that there are no chunks in this surface?
|
||||
if (not next_chunk) then
|
||||
return
|
||||
end
|
||||
end
|
||||
|
||||
-- Do we have it in our map?
|
||||
|
@ -1387,4 +1387,4 @@ BUDDY_SPAWN_CHOICE = {
|
||||
---@alias OarcBuddySpawnOptsTable table<string, OarcBuddySpawnOpts>
|
||||
|
||||
---Table of players in the "waiting room" for a buddy spawn.
|
||||
---@alias OarcWaitingBuddiesTable table<string>
|
||||
---@alias OarcWaitingBuddiesTable table<integer, string>
|
||||
|
Loading…
x
Reference in New Issue
Block a user