-
Notifications
You must be signed in to change notification settings - Fork 50
Expand file tree
/
Copy pathimport.lua
More file actions
154 lines (124 loc) · 4.38 KB
/
Copy pathimport.lua
File metadata and controls
154 lines (124 loc) · 4.38 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
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
---@meta
---This file was based on ox_lib init.lua file.
---ox_lib <https://github.com/overextended/ox_lib>
---Copyright (C) 2021 Linden <https://github.com/thelindat>
---LGPL-3.0-or-later <https://www.gnu.org/licenses/lgpl-3.0.en.html>
local resourceName = GetCurrentResourceName()
local prpBridge = "prp-bridge"
if resourceName == prpBridge then
exports("GetConfig", function()
return BridgeConfig
end)
else
BridgeConfig = exports[prpBridge]:GetConfig()
end
if GetResourceState(prpBridge) ~= "started" and resourceName ~= prpBridge then
error("^1prp-bridge must be started before this resource.^0", 0)
end
if not lib then
error("^1prp-bridge requires ox_lib to be started.^0", 0)
end
local LoadResourceFile = LoadResourceFile
local context = IsDuplicityVersion() and "server" or "client"
local function noop() end
local disabledModule = setmetatable({}, {
__index = function()
return noop
end,
})
local moduleToDependency = {
fw = BridgeConfig.FrameWork,
inv = BridgeConfig.Inventory,
phone = BridgeConfig.Phone,
target = BridgeConfig.Target,
dispatch = BridgeConfig.Dispatch,
medical = BridgeConfig.Medical,
minigames = BridgeConfig.Minigames,
vkeys = BridgeConfig.VehicleKeys,
vfuel = BridgeConfig.VehicleFuel,
appearance = BridgeConfig.Appearance,
voice = BridgeConfig.Voice,
}
local function loadModule(self, module)
local dir = ("modules/%s"):format(module)
local targetDependency = moduleToDependency[module]
if targetDependency == false then
lib.print.debug("Skipping disabled module", module)
self[module] = disabledModule
return self[module]
end
local chunk, shared = nil, nil
if not targetDependency then
chunk = LoadResourceFile(prpBridge, ("%s/%s.lua"):format(dir, context))
shared = LoadResourceFile(prpBridge, ("%s/shared.lua"):format(dir))
else
chunk = LoadResourceFile(prpBridge, ("%s/%s/%s.lua"):format(dir, targetDependency, context))
shared = LoadResourceFile(prpBridge, ("%s/%s/shared.lua"):format(dir, targetDependency))
end
lib.print.debug("Loading module", module, dir, targetDependency, context)
if shared then
chunk = (chunk and ("%s\n%s"):format(shared, chunk)) or shared
end
if chunk then
local fn, err = load(chunk, ("@@prp-bridge/modules/%s/%s.lua"):format(module, context))
if not fn or err then
return error(("\n^1Error importing module (%s): %s^0"):format(dir, err), 3)
end
local result = fn()
if module == "fw" and context == "client" and type(result) == "table" then
local pedStatusChunk = LoadResourceFile(prpBridge, "modules/fw/shared/pedStatus.lua")
if pedStatusChunk then
local pedFn, pedErr = load(pedStatusChunk, "@@prp-bridge/modules/fw/shared/pedStatus.lua")
if pedFn then
local pedGetters = pedFn()
if pedGetters then
for key, getter in pairs(pedGetters) do
if result[key] == nil then
result[key] = getter
end
end
end
elseif pedErr then
lib.print.error("Failed to load fw pedStatus:", pedErr)
end
end
end
self[module] = result or noop
return self[module]
end
end
local function call(self, index, ...)
local module = rawget(self, index)
if not module then
self[index] = noop
module = loadModule(self, index)
end
return module
end
local bridge = setmetatable({
context = context,
name = prpBridge,
currentResource = resourceName,
usedInv = BridgeConfig.Inventory,
usedFw = BridgeConfig.FrameWork,
}, {
__index = call,
__call = call,
})
---@type Bridge
_ENV.bridge = bridge
Citizen.CreateThreadNow(function()
for module, _ in pairs(moduleToDependency) do
loadModule(bridge, module)
end
end)
if resourceName == prpBridge or context == "client" then return end
if BridgeConfig.VersionCheck == true then
CreateThread(function()
Wait(1000)
local version = GetResourceMetadata(resourceName, 'version', 0)
if version and version ~= "" then
exports[prpBridge]:CheckVersion(resourceName)
end
end)
end