-
Notifications
You must be signed in to change notification settings - Fork 41
Expand file tree
/
Copy pathimport.lua
More file actions
117 lines (94 loc) · 3.21 KB
/
import.lua
File metadata and controls
117 lines (94 loc) · 3.21 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
---@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 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,
}
local function loadModule(self, module)
local dir = ("modules/%s"):format(module)
local targetDependency = moduleToDependency[module]
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()
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