depctrl global config: don't be stupid

no longer rewrites the entire config below the existing one(!)
added forgotten local variables, removed unnecessary ones
fixed a typo
This commit is contained in:
garret 2022-11-23 20:42:05 +00:00
parent 9a260cb6d2
commit 74feac83bb
1 changed files with 9 additions and 7 deletions

View File

@ -1,7 +1,7 @@
script_name="DepCtrl Global Config" script_name="DepCtrl Global Config"
script_description="the future is now" script_description="the future is now"
script_author = "garret" script_author = "garret"
script_version = "1.0.1" script_version = "1.1.0"
script_namespace = "garret.depctrl_config" script_namespace = "garret.depctrl_config"
local DependencyControl = require("l0.DependencyControl") local DependencyControl = require("l0.DependencyControl")
@ -35,7 +35,7 @@ local function seconds_to_human(seconds)
local days = math.floor((seconds % 31536000) / 86400) local days = math.floor((seconds % 31536000) / 86400)
local hours = math.floor(((seconds % 31536000) % 86400) / 3600) local hours = math.floor(((seconds % 31536000) % 86400) / 3600)
local minutes = math.floor((((seconds % 31536000) % 86400) % 3600) / 60) local minutes = math.floor((((seconds % 31536000) % 86400) % 3600) / 60)
local seconds = (((seconds % 31536000) % 86400) % 3600) % 60 seconds = (((seconds % 31536000) % 86400) % 3600) % 60
--return years, days, hours, minutes, seconds --return years, days, hours, minutes, seconds
local timestamp = "" local timestamp = ""
if years ~= 0 then timestamp = timestamp..years.."y" end if years ~= 0 then timestamp = timestamp..years.."y" end
@ -46,7 +46,7 @@ local function seconds_to_human(seconds)
return timestamp return timestamp
end end
function human_to_seconds(human) local function human_to_seconds(human)
-- im sure this is hideously inefficient -- im sure this is hideously inefficient
local years = (tonumber(human:match("(%d*)y")) or 0) * 31536000 local years = (tonumber(human:match("(%d*)y")) or 0) * 31536000
local days = (tonumber(human:match("(%d*)d")) or 0) * 86400 local days = (tonumber(human:match("(%d*)d")) or 0) * 86400
@ -159,15 +159,17 @@ local function main()
data_path = data_path:gsub(script_namespace, "l0.DependencyControl") data_path = data_path:gsub(script_namespace, "l0.DependencyControl")
aegisub.log(4, "config file: "..data_path.."\n") aegisub.log(4, "config file: "..data_path.."\n")
data_file = io.open(data_path, "r+") local data_file = io.open(data_path, "r")
data = json.decode(data_file:read()) local data = json.decode(data_file:read())
data_file:close()
data.config = get_config(data) data.config = get_config(data)
local data_str = json.encode(data)
data_str = json.encode(data) data_file = io.open(data_path, "w")
data_file:write(data_str) data_file:write(data_str)
data_file:close() data_file:close()
aegisub.log(3, "Done. You'll need to rescan your automation directory, or restart aegisub, for the changes to take effect.") aegisub.log(3, "Done. You'll need to rescan your automation directory, or restart aegisub, for the changes to take effect.")
end end
depctrl:registerMacro("DependencyControl/Global Configuration", "Lets you change DepedencyControl settings.", main) depctrl:registerMacro("DependencyControl/Global Configuration", "Lets you change DependencyControl settings.", main)