This repository was archived by the owner on Jan 8, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBangHUD.lua
More file actions
87 lines (75 loc) · 2.33 KB
/
BangHUD.lua
File metadata and controls
87 lines (75 loc) · 2.33 KB
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
BangHUD = BangHUD or {}
if not BangHUD.setup then
BangHUD._path = ModPath
BangHUD._lua_path = ModPath .. "Lua/"
BangHUD._data_path = SavePath .. "BangHUD.json"
BangHUD._data = {}
BangHUD._hook_files = {
["lib/managers/menumanager"] = "MenuManager",
["lib/managers/localizationmanager"] = "LocalizationManager",
["lib/managers/hudmanagerpd2"] = "HUDManagerPD2",
["lib/managers/group_ai_states/groupaistatebase"] = "GroupAIStateBase",
["lib/units/beings/player/playerdamage"] = "PlayerDamage"
}
function BangHUD:Save()
local file = io.open(self._data_path, "w+")
if file then
file:write(json.encode(self._data))
file:close()
end
end
function BangHUD:Load()
self:LoadDefaults()
local file = io.open(self._data_path, "r")
if file then
local configt = json.decode(file:read("*all"))
file:close()
for k,v in pairs(configt) do
self._data[k] = v
end
end
self:Save()
end
function BangHUD:GetOption(id)
return self._data[id]
end
function BangHUD:OptionChanged()
self:Save()
if managers and managers.hud and managers.hud._hud_banghud then
managers.hud._hud_banghud:update()
end
end
function BangHUD:LoadDefaults()
local default_file = io.open(self._path .. "default_values.json")
self._data = json.decode(default_file:read("*all"))
default_file:close()
end
function BangHUD:DoLuaFile(fileName)
dofile(BangHUD._lua_path .. fileName .. ".lua")
end
function BangHUD:createDirectory(path)
local current = ""
path = Application:nice_path(path, true):gsub("\\", "/")
for folder in string.gmatch(path, "([^/]*)/") do
current = Application:nice_path(current .. folder, true)
if not file.DirectoryExists(current) then
if SystemFS and SystemFS.make_dir then
SystemFS:make_dir(current) -- windows
elseif file and file.CreateDirectory then
file.CreateDirectory(current) -- linux
end
end
end
end
for _, update in pairs(BLT.Mods:GetMod("BangHUD"):GetUpdates()) do
BangHUD:createDirectory(update:GetInstallDirectory() .. "/" .. update:GetInstallFolder())
end
BangHUD:Load()
BangHUD.setup = true
end
if RequiredScript then
local requiredScript = RequiredScript:lower()
if BangHUD._hook_files[requiredScript] then
BangHUD:DoLuaFile(BangHUD._hook_files[requiredScript])
end
end