Mutators: added precalculated compatibility function
This commit is contained in:
parent
d8a84d2d76
commit
895bac9b96
3 changed files with 59 additions and 7 deletions
|
@ -317,7 +317,7 @@ local mutators_view = {
|
|||
|
||||
-- Creates and return text for checkbox tooltip
|
||||
generate_tooltip_for = function(self, mutator)
|
||||
local config = vmf.get_mutator_config(mutator)
|
||||
local config = mutator:get_config()
|
||||
local text = ""
|
||||
|
||||
-- Show supported difficulty when can't be enabled due to difficulty level
|
||||
|
|
|
@ -104,6 +104,55 @@ local function is_compatible(mutator, other_mutator)
|
|||
return compatible
|
||||
end
|
||||
|
||||
-- Creates 'compatibility' entry for the mutator, checks compatibility of given mutator with all other mutators.
|
||||
-- 'compatibility.mostly_compatible' is 'true' when mutator is not specifically set to be incompatible with
|
||||
-- all other mutators. All the incompatible mutators will be added to 'compatibility.except'. And vice versa,
|
||||
-- if 'mostly_compatible' is 'false', all the compatible mutators will be added to 'except'.
|
||||
local function update_compatibility(mutator)
|
||||
|
||||
-- Create default 'compatibility' entry
|
||||
local config = mutator:get_config()
|
||||
config.compatibility = {}
|
||||
local compatibility = config.compatibility
|
||||
compatibility.mostly_compatible = not config.incompatible_with_all
|
||||
compatibility.except = {}
|
||||
|
||||
local mostly_compatible = compatibility.mostly_compatible
|
||||
local except = compatibility.except
|
||||
|
||||
for _, other_mutator in ipairs(_MUTATORS) do
|
||||
|
||||
local other_config = other_mutator:get_config()
|
||||
local other_mostly_compatible = other_config.compatibility.mostly_compatible
|
||||
local other_except = other_config.compatibility.except
|
||||
|
||||
if is_compatible(mutator, other_mutator) then
|
||||
if not mostly_compatible then except[other_mutator] = true end
|
||||
if not other_mostly_compatible then other_except[mutator] = true end
|
||||
else
|
||||
if mostly_compatible then except[other_mutator] = true end
|
||||
if other_mostly_compatible then other_except[mutator] = true end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
function vmf.temp_show_mutator_compatibility()
|
||||
|
||||
print("MUTATORS COMPATIBILITY:")
|
||||
|
||||
for _, mutator in ipairs(_MUTATORS) do
|
||||
local compatibility = mutator:get_config().compatibility
|
||||
|
||||
print("\n" .. mutator:get_readable_name() .. (compatibility.mostly_compatible and "[+]" or "[-]") .. ":")
|
||||
|
||||
local ident = compatibility.mostly_compatible and " - " or " + "
|
||||
|
||||
for other_mutator in pairs(compatibility.except) do
|
||||
print(ident .. other_mutator:get_readable_name())
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- Called after mutator is enabled
|
||||
local function on_enabled(mutator)
|
||||
local config = mutator:get_config()
|
||||
|
@ -321,13 +370,9 @@ end
|
|||
-- Turns a mod into a mutator
|
||||
function vmf.register_mod_as_mutator(mod, config)
|
||||
|
||||
-- Form config
|
||||
config = config or {}
|
||||
|
||||
table.insert(_MUTATORS, mod)
|
||||
|
||||
-- Save config
|
||||
mod._data.config = table.clone(_DEFAULT_CONFIG)
|
||||
local _config = mod:get_config()
|
||||
local _config = table.clone(_DEFAULT_CONFIG)
|
||||
for k, _ in pairs(_config) do
|
||||
if config[k] ~= nil then
|
||||
_config[k] = config[k]
|
||||
|
@ -335,7 +380,10 @@ function vmf.register_mod_as_mutator(mod, config)
|
|||
end
|
||||
if _config.short_title == "" then _config.short_title = nil end
|
||||
|
||||
-- Save config inside the mod data
|
||||
mod._data.config = _config
|
||||
|
||||
update_compatibility(mod)
|
||||
|
||||
local mod_name = mod:get_name()
|
||||
|
||||
|
@ -350,6 +398,8 @@ function vmf.register_mod_as_mutator(mod, config)
|
|||
end
|
||||
end
|
||||
|
||||
table.insert(_MUTATORS, mod)
|
||||
|
||||
_MUTATORS_SORTED = false
|
||||
|
||||
_MUTATORS_VIEW:update_mutator_list()
|
||||
|
|
|
@ -60,6 +60,8 @@ return {
|
|||
object.vmf.create_network_dictionary()
|
||||
object.vmf.ping_vmf_users()
|
||||
|
||||
object.vmf.temp_show_mutator_compatibility()
|
||||
|
||||
object.vmf.all_mods_loaded_event()
|
||||
|
||||
object.vmf.all_mods_were_loaded = true
|
||||
|
|
Loading…
Add table
Reference in a new issue