diff --git a/data/core/config.lua b/data/core/config.lua index ecdcfdb5..fc5da98a 100644 --- a/data/core/config.lua +++ b/data/core/config.lua @@ -1,3 +1,5 @@ +local common = require "core.common" + local config = {} config.fps = 60 @@ -55,13 +57,47 @@ config.max_clicks = 3 -- set as true to be able to test non supported plugins config.skip_plugins_version = false +-- holds the plugins real config table +local plugins_config = {} + +-- virtual representation of plugins config table config.plugins = {} --- Allow you to set plugin configs even if we haven't seen the plugin before. + +-- allows virtual access to the plugins config table setmetatable(config.plugins, { - __index = function(t, k) - local v = rawget(t, k) - if v == true or v == nil then v = {} rawset(t, k, v) end - return v + __index = function(_, k) + if not plugins_config[k] then + plugins_config[k] = { enabled = true, config = {} } + end + if plugins_config[k].enabled ~= false then + return plugins_config[k].config + end + return false + end, + __newindex = function(_, k, v) + if not plugins_config[k] then + plugins_config[k] = { enabled = nil, config = {} } + end + if v == false and package.loaded["plugins."..k] then + local core = require "core" + core.warn("[%s] is already enabled, restart the editor for the change to take effect", k) + return + elseif plugins_config[k].enabled == false and v ~= false then + plugins_config[k].enabled = true + end + if v == false then + plugins_config[k].enabled = false + elseif type(v) == "table" then + plugins_config[k].enabled = true + plugins_config[k].config = common.merge(plugins_config[k].config, v) + end + end, + __pairs = function() + return coroutine.wrap(function() + for name, status in pairs(plugins_config) do + coroutine.yield(name, status.config) + end + end) end })