local function init_optim_ui(storage, ref)
assert(
type(storage) == "table",
string.format("optim_ui: storage is a \"%s\", not a \"table\".", storage)
)
return setmetatable({}, {
__index = function (_, ui_method) -- ui_method should be like switch, slider etc
return function (name, ...)
local ui_obj = ref[ui_method](ref, name, ...) -- ref:ui_method(name, ...) / ref is in first argument because it is a thiscall
ui_obj:set_callback(function (self)
storage[name] = self:get()
end, true)
return ui_obj
end
end
})
end
-- Example
local example_storage = {
["Anti-aim"] = {}, ["Rage"] = {}
}
local anti_aim_ref = init_optim_ui(example_storage["Anti-aim"], ui.create("Anti-aim"))
local rage_ref = init_optim_ui(example_storage["Rage"], ui.create("Rage"))
anti_aim_ref.switch("Some toggle")
rage_ref.switch("Another toggle")
local slider = rage_ref.slider("Slider", 0, 100, 50)
slider:name("Edited slider!")
events.render:set(function ()
print(example_storage["Rage"]["Slider"])
end)