-
Notifications
You must be signed in to change notification settings - Fork 1
/
global_config.lua
56 lines (51 loc) · 1.51 KB
/
global_config.lua
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
local json = require("extlibs.json.json-beautify")
local global_config = {}
local settings = {}
local profile = require("game_handler.profile")
local config = require("config")
local path = "config.json"
local function save()
local file = love.filesystem.openFile(path, "w")
file:write(json.beautify(settings))
file:close()
end
---open the config file
function global_config.init()
if not love.filesystem.getInfo(path) then
global_config.set_game_profile("default")
global_config.set_settings_profile("default")
save()
else
local file = love.filesystem.openFile(path, "r")
settings = json.decode(file:read())
file:close()
config.open_profile(settings.settings_profile)
profile.open_or_new(settings.game_profile)
end
end
---set the current settings profile (creates it if it doesn't exist)
---@param name string
function global_config.set_settings_profile(name)
local profiles = config.list_profiles()
local has_profile = false
for i = 1, #profiles do
if profiles[i] == name then
has_profile = true
break
end
end
if not has_profile then
config.create_profile(name)
end
config.open_profile(name)
settings.settings_profile = name
save()
end
---sets the current game profile (creates it if it doesn't exist)
---@param name string
function global_config.set_game_profile(name)
profile.open_or_new(name)
settings.game_profile = name
save()
end
return global_config