Update UI/library.lua
This commit is contained in:
+32
-16
@@ -61,7 +61,9 @@
|
||||
-- Library init
|
||||
getgenv().library = {
|
||||
directory = "mirrorhack",
|
||||
game_id = tostring(game.GameId),
|
||||
folders = {
|
||||
"",
|
||||
"/fonts",
|
||||
"/configs",
|
||||
},
|
||||
@@ -178,8 +180,16 @@
|
||||
|
||||
library.__index = library
|
||||
|
||||
for _, path in next, library.folders do
|
||||
makefolder(library.directory .. path)
|
||||
-- configs live in their own folder per game, so each game keeps its own saves
|
||||
library.config_folder = library.directory .. "/configs/" .. library.game_id
|
||||
library.folders[#library.folders + 1] = "/configs/" .. library.game_id
|
||||
|
||||
-- ipairs, not next: the parent folder has to exist before the child
|
||||
for _, path in ipairs(library.folders) do
|
||||
local folder = library.directory .. path
|
||||
if not isfolder(folder) then
|
||||
makefolder(folder)
|
||||
end
|
||||
end
|
||||
|
||||
local flags = library.flags
|
||||
@@ -479,21 +489,27 @@
|
||||
end
|
||||
|
||||
local config_holder;
|
||||
function library:update_config_list()
|
||||
if not config_holder then
|
||||
return
|
||||
function library:config_path(name)
|
||||
return library.config_folder .. "/" .. name .. ".cfg"
|
||||
end
|
||||
|
||||
function library:update_config_list()
|
||||
if not config_holder then
|
||||
return
|
||||
end
|
||||
|
||||
|
||||
local list = {}
|
||||
|
||||
for idx, file in listfiles(library.directory .. "/configs") do
|
||||
local name = file:gsub(library.directory .. "/configs\\", ""):gsub(".cfg", ""):gsub(library.directory .. "\\configs\\", "")
|
||||
list[#list + 1] = name
|
||||
|
||||
for _, file in next, listfiles(library.config_folder) do
|
||||
if file:sub(-4) == ".cfg" then
|
||||
local name = file:match("[^/\\]+$")
|
||||
list[#list + 1] = name:gsub("%.cfg$", "")
|
||||
end
|
||||
end
|
||||
|
||||
|
||||
|
||||
config_holder.refresh_options(list)
|
||||
end
|
||||
end
|
||||
|
||||
function library:get_config()
|
||||
local Config = {}
|
||||
@@ -2570,9 +2586,9 @@
|
||||
local section = main:column({}):section({name = "Settings", size = 1, default = true})
|
||||
config_holder = section:dropdown({name = "Configs", options = {"Report", "This", "Error", "To", "Finobe"}, callback = function(option) if textbox then textbox.set(option) end end, flag = "config_name_list"}); library:update_config_list()
|
||||
textbox = section:textbox({name = "Config name:", flag = "config_name_text"})
|
||||
section:button({name = "Save", callback = function() writefile(library.directory .. "/configs/" .. flags["config_name_text"] .. ".cfg", library:get_config()) library:update_config_list() end})
|
||||
section:button({name = "Load", callback = function() library:load_config(readfile(library.directory .. "/configs/" .. flags["config_name_text"] .. ".cfg")) library:update_config_list() end})
|
||||
section:button({name = "Delete", callback = function() delfile(library.directory .. "/configs/" .. flags["config_name_text"] .. ".cfg") library:update_config_list() end})
|
||||
section:button({name = "Save", callback = function() writefile(library:config_path(flags["config_name_text"]), library:get_config()) library:update_config_list() end})
|
||||
section:button({name = "Load", callback = function() library:load_config(readfile(library:config_path(flags["config_name_text"]))) library:update_config_list() end})
|
||||
section:button({name = "Delete", callback = function() delfile(library:config_path(flags["config_name_text"])) library:update_config_list() end})
|
||||
|
||||
local section = main:column({}):section({name = "Other", size = 1, default = true})
|
||||
section:keybind({name = "Menu bind", callback = function(bool) window.toggle_menu(bool) end, default = true})
|
||||
@@ -2628,4 +2644,4 @@
|
||||
--
|
||||
--
|
||||
|
||||
return library, notifications
|
||||
return library, notifications
|
||||
Reference in New Issue
Block a user