minor update
This commit is contained in:
@@ -13,7 +13,7 @@
|
|||||||
size='32' margin='0,0,10,15' gravity='bottom-right'
|
size='32' margin='0,0,10,15' gravity='bottom-right'
|
||||||
color='#FFFFFF50' hover-color='#FFFFFF10'/>
|
color='#FFFFFF50' hover-color='#FFFFFF10'/>
|
||||||
|
|
||||||
<image id="open_config" onclick='open_config()' interactive='true' src='gui/settings_icon'
|
<image id="open_config" enabled="false" onclick='open_config()' interactive='true' src='gui/settings_icon'
|
||||||
size='32' margin='0,0,52,15' gravity='bottom-right'
|
size='32' margin='0,0,52,15' gravity='bottom-right'
|
||||||
color='#FFFFFF50' hover-color='#FFFFFF10'/>
|
color='#FFFFFF50' hover-color='#FFFFFF10'/>
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,9 @@
|
|||||||
local packs_installed = {}
|
local packs_installed = {}
|
||||||
local pack_open = {}
|
local pack_open = {}
|
||||||
|
local parsers = {
|
||||||
|
toml = toml,
|
||||||
|
json = json
|
||||||
|
}
|
||||||
|
|
||||||
function on_open(params)
|
function on_open(params)
|
||||||
refresh()
|
refresh()
|
||||||
@@ -45,14 +49,14 @@ end
|
|||||||
local function create_checkbox(id, name, cheaked)
|
local function create_checkbox(id, name, cheaked)
|
||||||
document.configs:add(string.format(
|
document.configs:add(string.format(
|
||||||
"<checkbox id='%s' consumer='function(x) set_value(\"%s\", \"%s\", x) end' checked='%s'>%s</checkbox>",
|
"<checkbox id='%s' consumer='function(x) set_value(\"%s\", \"%s\", x) end' checked='%s'>%s</checkbox>",
|
||||||
id, name, id, cheaked, name
|
id, name, id, cheaked, name:gsub("^%l", string.upper)
|
||||||
))
|
))
|
||||||
end
|
end
|
||||||
|
|
||||||
local function create_textbox(id, name, text)
|
local function create_textbox(id, name, text)
|
||||||
document.configs:add(string.format(
|
document.configs:add(string.format(
|
||||||
"<label id='%s'>%s</label>",
|
"<label id='%s'>%s</label>",
|
||||||
id .. "_label", name
|
id .. "_label", name:gsub("^%l", string.upper)
|
||||||
))
|
))
|
||||||
document.configs:add(string.format(
|
document.configs:add(string.format(
|
||||||
"<textbox id='%s' consumer='function(x) set_value(\"%s\", \"%s\", x) end' hint='%s'>%s</textbox>",
|
"<textbox id='%s' consumer='function(x) set_value(\"%s\", \"%s\", x) end' hint='%s'>%s</textbox>",
|
||||||
@@ -63,7 +67,7 @@ end
|
|||||||
local function create_trackbar(id, name, val)
|
local function create_trackbar(id, name, val)
|
||||||
document.configs:add(string.format(
|
document.configs:add(string.format(
|
||||||
"<label id='%s'>%s (%s)</label>",
|
"<label id='%s'>%s (%s)</label>",
|
||||||
id .. "_label", name, val
|
id .. "_label", name:gsub("^%l", string.upper), val
|
||||||
))
|
))
|
||||||
document.configs:add(string.format(
|
document.configs:add(string.format(
|
||||||
"<trackbar id='%s' consumer='function(x) set_value(\"%s\", \"%s\", x) end' value='%s' min='0' max='1000' step='10'>%s</trackbar>",
|
"<trackbar id='%s' consumer='function(x) set_value(\"%s\", \"%s\", x) end' value='%s' min='0' max='1000' step='10'>%s</trackbar>",
|
||||||
@@ -79,30 +83,30 @@ local function create_label(id, text, color)
|
|||||||
))
|
))
|
||||||
else
|
else
|
||||||
document.configs:add(string.format(
|
document.configs:add(string.format(
|
||||||
"<label>%s</label>",
|
"<label color='%s'>%s</label>",
|
||||||
text
|
color, text
|
||||||
))
|
))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
local function create_config(i, config, name, path)
|
local function create_config(i, config, name, path)
|
||||||
create_label(name, '[' .. name .. ']', "#008000")
|
create_label(name, ('[' .. name .. ']'):upper(), "#FFFFFF")
|
||||||
pack_open[2][i] = {{}, path = path}
|
pack_open[2][i] = {elements = {}, path = path}
|
||||||
for _, a in ipairs(config.checkboxes) do
|
for _, a in ipairs(config.checkboxes) do
|
||||||
create_checkbox(i .. '_' .. a[1], a[1], a[2])
|
create_checkbox(i .. '_' .. a[1], a[1], a[2])
|
||||||
pack_open[2][i][1][a[1]] = type(a[2])
|
pack_open[2][i]["elements"][a[1]] = type(a[2])
|
||||||
end
|
end
|
||||||
create_label(nil, '', 0)
|
create_label(nil, '', 0)
|
||||||
for _, a in ipairs(config.trackbars) do
|
for _, a in ipairs(config.trackbars) do
|
||||||
create_trackbar(i .. '_' .. a[1], a[1], a[2])
|
create_trackbar(i .. '_' .. a[1], a[1], a[2])
|
||||||
create_label(nil, '', 0)
|
create_label(nil, '', 0)
|
||||||
pack_open[2][i][1][a[1]] = type(a[2])
|
pack_open[2][i]["elements"][a[1]] = type(a[2])
|
||||||
end
|
end
|
||||||
|
|
||||||
for _, a in ipairs(config.textboxes) do
|
for _, a in ipairs(config.textboxes) do
|
||||||
create_textbox(i .. '_' .. a[1], a[1], a[2])
|
create_textbox(i .. '_' .. a[1], a[1], a[2])
|
||||||
create_label(nil, '', 0)
|
create_label(nil, '', 0)
|
||||||
pack_open[2][i][1][a[1]] = type(a[2])
|
pack_open[2][i]["elements"][a[1]] = type(a[2])
|
||||||
end
|
end
|
||||||
create_label(nil, '', 0)
|
create_label(nil, '', 0)
|
||||||
end
|
end
|
||||||
@@ -115,12 +119,9 @@ local function load_config_file(path)
|
|||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local value = file.read(path)
|
if parsers[extension] then
|
||||||
|
local value = file.read(path)
|
||||||
if extension == "toml" then
|
return parsers[extension].parse(value), extension
|
||||||
return toml.parse(value), extension
|
|
||||||
elseif extension == "json" then
|
|
||||||
return json.parse(value), extension
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -150,23 +151,33 @@ local function load_config(path)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
local function valid_configs(path)
|
||||||
|
if file.exists(path) and file.isdir(path) then
|
||||||
|
for _, c in ipairs(file.list(path)) do
|
||||||
|
local extension = c:match("%.(%w+)$")
|
||||||
|
if parsers[extension] then
|
||||||
|
return true
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return false
|
||||||
|
end
|
||||||
|
|
||||||
function set_value(name, id, value)
|
function set_value(name, id, value)
|
||||||
local config_id = tonumber(id:match("^(%w+)_"))
|
local config_id = tonumber(id:match("^(%w+)_"))
|
||||||
local elem_id = id:match("^[^_]+_(.+)$")
|
local elem_id = id:match("^[^_]+_(.+)$")
|
||||||
local type_val = pack_open[2][config_id][1][elem_id]
|
local type_val = pack_open[2][config_id]["elements"][elem_id]
|
||||||
|
|
||||||
if type_val == 'number' then
|
if type_val == 'number' then
|
||||||
document[id .. '_label'].text = string.format("%s (%s)", elem_id, value)
|
document[id .. '_label'].text = string.format("%s (%s)", elem_id:gsub("^%l", string.upper), value)
|
||||||
end
|
end
|
||||||
|
|
||||||
local path = pack_open[2][config_id].path
|
local path = pack_open[2][config_id].path
|
||||||
local config, extension = load_config_file(path)
|
local config, extension = load_config_file(path)
|
||||||
config[name] = value
|
config[name] = value
|
||||||
|
|
||||||
if extension == "toml" then
|
if parsers[extension] then
|
||||||
file.write(path, toml.tostring(config))
|
file.write(path, parsers[extension].tostring(config))
|
||||||
elseif extension == "json" then
|
|
||||||
file.write(path, json.tostring(config))
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -176,6 +187,7 @@ function open_pack(id)
|
|||||||
|
|
||||||
document.configs.visible = false
|
document.configs.visible = false
|
||||||
document.content_info.visible = true
|
document.content_info.visible = true
|
||||||
|
if valid_configs("config:" .. id) then document.open_config.enabled = true else document.open_config.enabled = false end
|
||||||
|
|
||||||
if packinfo['dependencies'] == nil then document.dependencies.text = 'None' else document.dependencies.text = table.tostring(packinfo['dependencies']) end
|
if packinfo['dependencies'] == nil then document.dependencies.text = 'None' else document.dependencies.text = table.tostring(packinfo['dependencies']) end
|
||||||
if packinfo['creator'] == '' then document.author.text = 'None' else document.author.text = packinfo['creator'] end
|
if packinfo['creator'] == '' then document.author.text = 'None' else document.author.text = packinfo['creator'] end
|
||||||
@@ -185,13 +197,15 @@ end
|
|||||||
|
|
||||||
function open_config()
|
function open_config()
|
||||||
local id = pack_open[1]
|
local id = pack_open[1]
|
||||||
if (not document.configs.visible and id) and
|
local path = "config:" .. id
|
||||||
(file.exists("config:" .. id) and #file.list("config:" .. id) > 0) then
|
|
||||||
|
|
||||||
|
if (not document.configs.visible and id) and valid_configs(path) then
|
||||||
document.configs:clear()
|
document.configs:clear()
|
||||||
document.configs.visible = true
|
document.configs.visible = true
|
||||||
document.content_info.visible = false
|
document.content_info.visible = false
|
||||||
|
|
||||||
local configs = file.list("config:" .. id)
|
local configs = file.list("config:" .. id)
|
||||||
|
|
||||||
for i, c in ipairs(configs) do
|
for i, c in ipairs(configs) do
|
||||||
local name = c:match("([^/]+)$")
|
local name = c:match("([^/]+)$")
|
||||||
name = name:match("([^%.]+)")
|
name = name:match("([^%.]+)")
|
||||||
@@ -201,10 +215,10 @@ function open_config()
|
|||||||
create_config(i, config, name, c)
|
create_config(i, config, name, c)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
else
|
return
|
||||||
document.configs.visible = false
|
|
||||||
document.content_info.visible = true
|
|
||||||
end
|
end
|
||||||
|
document.configs.visible = false
|
||||||
|
document.content_info.visible = true
|
||||||
end
|
end
|
||||||
|
|
||||||
function refresh()
|
function refresh()
|
||||||
@@ -218,7 +232,7 @@ function refresh()
|
|||||||
local contents = document.contents
|
local contents = document.contents
|
||||||
contents:clear()
|
contents:clear()
|
||||||
|
|
||||||
for i,id in ipairs(packs_installed) do
|
for i, id in ipairs(packs_installed) do
|
||||||
local packinfo = pack.get_info(id)
|
local packinfo = pack.get_info(id)
|
||||||
|
|
||||||
packinfo.id = id
|
packinfo.id = id
|
||||||
|
|||||||
Reference in New Issue
Block a user