Update UI/library.lua
This commit is contained in:
+24
-8
@@ -61,7 +61,9 @@
|
|||||||
-- Library init
|
-- Library init
|
||||||
getgenv().library = {
|
getgenv().library = {
|
||||||
directory = "mirrorhack",
|
directory = "mirrorhack",
|
||||||
|
game_id = tostring(game.GameId),
|
||||||
folders = {
|
folders = {
|
||||||
|
"",
|
||||||
"/fonts",
|
"/fonts",
|
||||||
"/configs",
|
"/configs",
|
||||||
},
|
},
|
||||||
@@ -178,8 +180,16 @@
|
|||||||
|
|
||||||
library.__index = library
|
library.__index = library
|
||||||
|
|
||||||
for _, path in next, library.folders do
|
-- configs live in their own folder per game, so each game keeps its own saves
|
||||||
makefolder(library.directory .. path)
|
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
|
end
|
||||||
|
|
||||||
local flags = library.flags
|
local flags = library.flags
|
||||||
@@ -479,6 +489,10 @@
|
|||||||
end
|
end
|
||||||
|
|
||||||
local config_holder;
|
local config_holder;
|
||||||
|
function library:config_path(name)
|
||||||
|
return library.config_folder .. "/" .. name .. ".cfg"
|
||||||
|
end
|
||||||
|
|
||||||
function library:update_config_list()
|
function library:update_config_list()
|
||||||
if not config_holder then
|
if not config_holder then
|
||||||
return
|
return
|
||||||
@@ -486,9 +500,11 @@
|
|||||||
|
|
||||||
local list = {}
|
local list = {}
|
||||||
|
|
||||||
for idx, file in listfiles(library.directory .. "/configs") do
|
for _, file in next, listfiles(library.config_folder) do
|
||||||
local name = file:gsub(library.directory .. "/configs\\", ""):gsub(".cfg", ""):gsub(library.directory .. "\\configs\\", "")
|
if file:sub(-4) == ".cfg" then
|
||||||
list[#list + 1] = name
|
local name = file:match("[^/\\]+$")
|
||||||
|
list[#list + 1] = name:gsub("%.cfg$", "")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@@ -2570,9 +2586,9 @@
|
|||||||
local section = main:column({}):section({name = "Settings", size = 1, default = true})
|
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()
|
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"})
|
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 = "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.directory .. "/configs/" .. flags["config_name_text"] .. ".cfg")) 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.directory .. "/configs/" .. flags["config_name_text"] .. ".cfg") 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})
|
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})
|
section:keybind({name = "Menu bind", callback = function(bool) window.toggle_menu(bool) end, default = true})
|
||||||
|
|||||||
Reference in New Issue
Block a user