forked from Crashic/treeofsavior-addons
-
Notifications
You must be signed in to change notification settings - Fork 0
/
loader.lua
95 lines (76 loc) · 2.8 KB
/
loader.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
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
88
89
90
91
92
93
94
95
-- ======================================================
-- begin
-- ======================================================
ui.SysMsg('=====================================');
_G["ADDON_LOADER"] = {};
local debugLoading = false;
local closeAfter = true;
local function trydofile(fullpath)
local f, error = io.open(fullpath,"r");
if (f ~= nil) then
io.close(f);
dofile(fullpath);
return true;
else
return false;
end
end
-- ======================================================
-- load_all function
-- ======================================================
_G["ADDON_LOAD_ALL"] = function()
ui.SysMsg('Opening addon folders...');
-- getting the current directory
local info = debug.getinfo(1,'S');
local directory = info.source:match[[^@?(.*[\/])[^\/]-$]];
-- iterating all folders
local i, addons, popen = 0, {}, io.popen;
for filename in popen('dir "'..directory..'" /b /ad'):lines() do
-- checking if there is {folder}/{folder}.lua inside it, and dofile-ing it if there is
if (debugLoading) then ui.SysMsg('- '..filename..' (lua)'); end
local fullpath = '../TaOSpls/modules/'..filename..'/'..filename..'.lua';
local loaded = trydofile(fullpath);
-- if there is, we'll store this folder
if (loaded) then
i = i + 1;
addons[i] = filename;
end
end
ui.SysMsg('Initializing addons...');
-- now, with all the folders that have a {folder}.lua file inside it
for i,filename in pairs(addons) do
if (debugLoading) then ui.SysMsg('- '..filename); end
-- we look for a hook on the ADDON_LOADER global
local fn = _G['ADDON_LOADER'][filename];
local ok = true;
-- and if there is one, we'll call it
if fn then ok = fn(); end
-- if the hook returned false, a error message should be shown
if (not ok) then ui.SysMsg('['..filename..'] failed.') end
end
ui.SysMsg('Addons loaded!');
end
-- ======================================================
-- calling it as soon as the game open this
-- ======================================================
_G['ADDON_LOAD_ALL']();
_G["ADDON_LOADER"]["LOADED"] = closeAfter;
-- ======================================================
-- showing the addonloader frame
-- ======================================================
local addonLoaderFrame = ui.GetFrame("addonloader");
addonLoaderFrame:Move(0, 0);
--addonLoaderFrame:SetOffset(1600, 320);
addonLoaderFrame:SetOffset(500,30);
addonLoaderFrame:ShowWindow(0);
-- ======================================================
-- hooking it on map-init
-- ======================================================
function initWithAddons()
if _G["ADDON_LOADER"]["LOADED"] then
local addonLoaderFrame = ui.GetFrame("addonloader");
addonLoaderFrame:ShowWindow(0);
end
end
cwAPI.events.on('MAP_ON_INIT',initWithAddons,1);
if (not closeAfter) then addonLoaderFrame:ShowWindow(1); end