-
-
Notifications
You must be signed in to change notification settings - Fork 21
/
Copy pathinit.lua
158 lines (146 loc) · 4.82 KB
/
init.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
local DEFAULT_FRAMEWORK = 'ox'
Framework = setmetatable({}, {
__newindex = function(self, name, fn)
exports(name, function() return fn end)
rawset(self, name, fn)
end
})
local context = IsDuplicityVersion() and 'server' or 'client'
local requireLua = require -- when importing ox_core chunk, this gets overrides by ox_lib require, which loses stored data
local Utils = requireLua'utils'
local function format(str)
if not string.find(str, "'") then return str end
return str:gsub("'", "")
end
Config = {
convars = {
core = format(GetConvar('bl:framework', DEFAULT_FRAMEWORK)),
inventory = format(GetConvar('bl:inventory', DEFAULT_FRAMEWORK)),
context = format(GetConvar('bl:context', DEFAULT_FRAMEWORK)),
target = format(GetConvar('bl:target', DEFAULT_FRAMEWORK)),
progressbar = format(GetConvar('bl:progressbar', DEFAULT_FRAMEWORK)),
radial = format(GetConvar('bl:radial', DEFAULT_FRAMEWORK)),
notify = format(GetConvar('bl:notify', DEFAULT_FRAMEWORK)),
textui = format(GetConvar('bl:textui', DEFAULT_FRAMEWORK)),
},
resources = {
inventory = {
ox = 'ox_inventory',
qb = 'qb-inventory',
ps = 'ps-inventory',
esx = 'es_extended',
qs = 'qs-inventory'
},
core = {
nd = 'ND_Core',
qb = 'qb-core',
ox = 'ox_core',
qbx = 'qbx_core',
esx = 'es_extended'
},
context = {
qb = 'qb-menu',
ox = 'ox_lib'
},
progressbar = {
qb = 'progressbar',
ox = 'ox_lib'
},
radial = {
qb = 'qb-radialmenu',
ox = 'ox_lib'
},
target = {
qb = 'qb-target',
ox = 'ox_target',
},
notify = {
qb = 'none',
ox = 'ox_lib',
esx = 'none',
},
textui = {
ox = 'ox_lib',
qb = 'none',
esx = 'esx_textui',
}
},
client = {
dir = 'client',
moduleNames = {
"core",
"context",
"target",
"radial",
"notify",
"inventory",
"progressbar",
'textui',
},
all = {
inventory = true
},
},
server = {
dir = 'server',
moduleNames = {
"inventory",
"core",
"notify",
},
alternative = {
inventory = {
ps = 'qb'
}
},
}
}
---@param module string Module name
---@return string?
function GetFramework(module)
local moduleConfig = Config.resources[module]
if not moduleConfig then return end
return moduleConfig[Config.convars[module]]
end
exports('getFramework', GetFramework)
local function loadModule(dir, moduleName, framework, prefix)
local fomartedModule = ("%s.%s.%s"):format(dir, moduleName, framework)
local success, module = pcall(requireLua, fomartedModule)
if type(module) ~= "string" or not string.find(module, 'not found') then
if success then
Framework[moduleName] = module
print(("[%s] Loaded module %s"):format(prefix, moduleName))
else
error(("Error loading module %s: %s"):format(moduleName, module))
end
end
end
local modulesConfig = Config[context]
if context == 'server' then
Utils.register('UUID', function(_, num)
return Utils.UUID(num)
end)
end
for _, moduleName in ipairs(modulesConfig.moduleNames) do
local framework = Config.convars[moduleName]
if framework ~= 'none' then
local hasAlternative = modulesConfig.alternative and modulesConfig.alternative[moduleName]
local moduleForAll = modulesConfig.all and modulesConfig.all[moduleName] and 'all' or framework
local alternative = hasAlternative and hasAlternative[moduleForAll] or moduleForAll
local resourceName = Config.resources[moduleName] and Config.resources[moduleName][framework]
if not resourceName then
return error('there is no '..framework.. ' on module '..moduleName.. '!, please make sure you configured your convars on cfg!')
elseif resourceName == 'none' or GetResourceState(resourceName) == 'started' then
loadModule(modulesConfig.dir, moduleName, alternative, framework)
else
ExecuteCommand('ensure '..resourceName)
if Utils.waitFor(function()
if GetResourceState(resourceName) == 'started' then
return true
end
end, ('resource %s is not starting'):format(resourceName), 2000) then
loadModule(modulesConfig.dir, moduleName, alternative, framework)
end
end
end
end