Mutators: moved config to mod data
This commit is contained in:
parent
89d92c580e
commit
aeadb94343
2 changed files with 17 additions and 9 deletions
|
@ -73,6 +73,10 @@ VMFMod.is_mutator = function (self)
|
||||||
return self._data.is_mutator
|
return self._data.is_mutator
|
||||||
end
|
end
|
||||||
|
|
||||||
|
VMFMod.get_config = function (self)
|
||||||
|
return self._data.config
|
||||||
|
end
|
||||||
|
|
||||||
-- ####################################################################################################################
|
-- ####################################################################################################################
|
||||||
-- ##### VMF Initialization ###########################################################################################
|
-- ##### VMF Initialization ###########################################################################################
|
||||||
-- ####################################################################################################################
|
-- ####################################################################################################################
|
||||||
|
|
|
@ -5,9 +5,6 @@ local vmf = get_mod("VMF")
|
||||||
-- This is populated via vmf.register_mod_as_mutator
|
-- This is populated via vmf.register_mod_as_mutator
|
||||||
local _MUTATORS = {}
|
local _MUTATORS = {}
|
||||||
|
|
||||||
-- Table of mutators' configs by name
|
|
||||||
local _MUTATORS_CONFIG = {}
|
|
||||||
local _DEFAULT_CONFIG
|
|
||||||
|
|
||||||
-- This lists mutators and which ones should be enabled after them
|
-- This lists mutators and which ones should be enabled after them
|
||||||
-- This is populated via vmf.register_mod_as_mutator
|
-- This is populated via vmf.register_mod_as_mutator
|
||||||
|
@ -33,6 +30,8 @@ local _SET_LOBBY_DATA
|
||||||
|
|
||||||
local _MUTATORS_GUI
|
local _MUTATORS_GUI
|
||||||
|
|
||||||
|
local _DEFAULT_CONFIG
|
||||||
|
|
||||||
-- List of enabled mutators in case VMF is reloaded in the middle of the game
|
-- List of enabled mutators in case VMF is reloaded in the middle of the game
|
||||||
local _ENABLED_MUTATORS = vmf:persistent_table("enabled_mutators")
|
local _ENABLED_MUTATORS = vmf:persistent_table("enabled_mutators")
|
||||||
|
|
||||||
|
@ -318,7 +317,7 @@ end
|
||||||
-- Returns the config object for mutator from _MUTATORS_CONFIG
|
-- Returns the config object for mutator from _MUTATORS_CONFIG
|
||||||
-- M, G
|
-- M, G
|
||||||
function vmf.get_mutator_config(mutator)
|
function vmf.get_mutator_config(mutator)
|
||||||
return _MUTATORS_CONFIG[mutator:get_name()]
|
return mutator:get_config()
|
||||||
end
|
end
|
||||||
|
|
||||||
-- ##########
|
-- ##########
|
||||||
|
@ -327,15 +326,15 @@ end
|
||||||
|
|
||||||
-- Turns a mod into a mutator
|
-- Turns a mod into a mutator
|
||||||
function vmf.register_mod_as_mutator(mod, config)
|
function vmf.register_mod_as_mutator(mod, config)
|
||||||
if not config then config = {} end
|
|
||||||
|
config = config or {}
|
||||||
|
|
||||||
table.insert(_MUTATORS, mod)
|
table.insert(_MUTATORS, mod)
|
||||||
|
|
||||||
local mod_name = mod:get_name()
|
|
||||||
|
|
||||||
-- Save config
|
-- Save config
|
||||||
_MUTATORS_CONFIG[mod_name] = table.clone(_DEFAULT_CONFIG)
|
mod._data.config = table.clone(_DEFAULT_CONFIG)
|
||||||
local _config = _MUTATORS_CONFIG[mod_name]
|
|
||||||
|
local _config = mod:get_config()
|
||||||
for k, _ in pairs(_config) do
|
for k, _ in pairs(_config) do
|
||||||
if config[k] ~= nil then
|
if config[k] ~= nil then
|
||||||
_config[k] = config[k]
|
_config[k] = config[k]
|
||||||
|
@ -343,6 +342,11 @@ function vmf.register_mod_as_mutator(mod, config)
|
||||||
end
|
end
|
||||||
if _config.short_title == "" then _config.short_title = nil end
|
if _config.short_title == "" then _config.short_title = nil end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
local mod_name = mod:get_name()
|
||||||
|
|
||||||
|
-- @TODO: probably move these 2 blocks to the function of something like that
|
||||||
if config.enable_before_these then
|
if config.enable_before_these then
|
||||||
update_mutators_sequence(mod_name, config.enable_before_these)
|
update_mutators_sequence(mod_name, config.enable_before_these)
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Reference in a new issue