VMF Mod Data: updated external change protection
This commit is contained in:
parent
b5a9699bd8
commit
a172f72c0a
4 changed files with 30 additions and 14 deletions
|
@ -338,7 +338,7 @@ local function initialize_mutator_config(mutator, _raw_config)
|
||||||
end
|
end
|
||||||
if raw_config.short_title == "" then raw_config.short_title = nil end
|
if raw_config.short_title == "" then raw_config.short_title = nil end
|
||||||
|
|
||||||
rawset(mutator._data, "mutator_config", {})
|
vmf.set_internal_data(mutator, "mutator_config", {})
|
||||||
|
|
||||||
local config = mutator:get_internal_data("mutator_config")
|
local config = mutator:get_internal_data("mutator_config")
|
||||||
|
|
||||||
|
|
|
@ -8,7 +8,7 @@ local _disabled_mods = vmf:get("disabled_mods_list") or {}
|
||||||
|
|
||||||
vmf.set_mod_state = function (mod, is_enabled, initial_call)
|
vmf.set_mod_state = function (mod, is_enabled, initial_call)
|
||||||
|
|
||||||
rawset(mod._data, "is_enabled", is_enabled)
|
vmf.set_internal_data(mod, "is_enabled", is_enabled)
|
||||||
|
|
||||||
if is_enabled then
|
if is_enabled then
|
||||||
mod:enable_all_hooks()
|
mod:enable_all_hooks()
|
||||||
|
|
|
@ -1,19 +1,35 @@
|
||||||
|
-- #####################################################################################################################
|
||||||
|
-- ##### Local functions ###############################################################################################
|
||||||
|
-- #####################################################################################################################
|
||||||
|
|
||||||
|
local function set_internal_data(mod, key, value)
|
||||||
|
getmetatable(mod._data).__index[key] = value
|
||||||
|
end
|
||||||
|
|
||||||
|
-- #####################################################################################################################
|
||||||
|
-- ##### VMFMod (not API) ##############################################################################################
|
||||||
|
-- #####################################################################################################################
|
||||||
|
|
||||||
-- Defining VMFMod class.
|
-- Defining VMFMod class.
|
||||||
VMFMod = class(VMFMod)
|
VMFMod = class(VMFMod)
|
||||||
|
|
||||||
-- Creating mod data table when object of VMFMod class is created.
|
-- Creating mod data table when object of VMFMod class is created.
|
||||||
function VMFMod:init(mod_name)
|
function VMFMod:init(mod_name)
|
||||||
self._data = {}
|
if mod_name == "VMF" then
|
||||||
setmetatable(self._data, {
|
self.set_internal_data = set_internal_data
|
||||||
|
end
|
||||||
|
|
||||||
|
self._data = setmetatable({}, {
|
||||||
|
__index = {},
|
||||||
__newindex = function(t_, k)
|
__newindex = function(t_, k)
|
||||||
self:warning("Attempt to change internal mod data value (\"%s\"). Changing internal mod data is forbidden.", k)
|
self:warning("Attempt to change internal mod data value (\"%s\"). Changing internal mod data is forbidden.", k)
|
||||||
end
|
end
|
||||||
})
|
})
|
||||||
rawset(self._data, "name", mod_name)
|
set_internal_data(self, "name", mod_name)
|
||||||
rawset(self._data, "readable_name", mod_name)
|
set_internal_data(self, "readable_name", mod_name)
|
||||||
rawset(self._data, "is_enabled", true)
|
set_internal_data(self, "is_enabled", true)
|
||||||
rawset(self._data, "is_togglable", false)
|
set_internal_data(self, "is_togglable", false)
|
||||||
rawset(self._data, "is_mutator", false)
|
set_internal_data(self, "is_mutator", false)
|
||||||
end
|
end
|
||||||
|
|
||||||
-- #####################################################################################################################
|
-- #####################################################################################################################
|
||||||
|
|
|
@ -109,11 +109,11 @@ function vmf.initialize_mod_data(mod, mod_data)
|
||||||
end
|
end
|
||||||
|
|
||||||
if mod_data.name then
|
if mod_data.name then
|
||||||
rawset(mod._data, "readable_name", mod_data.name)
|
vmf.set_internal_data(mod, "readable_name", mod_data.name)
|
||||||
end
|
end
|
||||||
rawset(mod._data, "description", mod_data.description)
|
vmf.set_internal_data(mod, "description", mod_data.description)
|
||||||
rawset(mod._data, "is_togglable", mod_data.is_togglable or mod_data.is_mutator)
|
vmf.set_internal_data(mod, "is_togglable", mod_data.is_togglable or mod_data.is_mutator)
|
||||||
rawset(mod._data, "is_mutator", mod_data.is_mutator)
|
vmf.set_internal_data(mod, "is_mutator", mod_data.is_mutator)
|
||||||
|
|
||||||
if mod_data.is_mutator then
|
if mod_data.is_mutator then
|
||||||
vmf.register_mod_as_mutator(mod, mod_data.mutator_settings)
|
vmf.register_mod_as_mutator(mod, mod_data.mutator_settings)
|
||||||
|
|
Loading…
Add table
Reference in a new issue