This commit is contained in:
parent
e3b507b435
commit
c70d05af54
52
impl.lua
52
impl.lua
|
@ -41,42 +41,6 @@ function Class:extend(obj)
|
||||||
return self:new(...)
|
return self:new(...)
|
||||||
end
|
end
|
||||||
|
|
||||||
--[[ -- allow for getters and setters
|
|
||||||
mt.__index = function(table, key)
|
|
||||||
local val = rawget(table._, key)
|
|
||||||
--print(key, type(val))
|
|
||||||
if val and type(val) == "table" and (rawget(val, '__cfx_functionReference') == nil) and (val.get ~= nil or val.value ~= nil) then
|
|
||||||
if val.get then
|
|
||||||
if type(val.get) == "function" then
|
|
||||||
return val.get(table, val.value)
|
|
||||||
else
|
|
||||||
return val.get
|
|
||||||
end
|
|
||||||
elseif val.value then
|
|
||||||
return val.value
|
|
||||||
end
|
|
||||||
else
|
|
||||||
return val
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
mt.__newindex = function(table, key, value)
|
|
||||||
local val = rawget(table._, key)
|
|
||||||
if val and type(val) == "table" and (rawget(val, '__cfx_functionReference') == nil) and ((val.set ~= nil and val._ == nil) or val.value ~= nil) then
|
|
||||||
local v = value
|
|
||||||
if val.set then
|
|
||||||
if type(val.set) == "function" then
|
|
||||||
v = val.set(table, value, val.value)
|
|
||||||
else
|
|
||||||
v = val.set
|
|
||||||
end
|
|
||||||
end
|
|
||||||
val.value = v
|
|
||||||
if val and val.afterSet then val.afterSet(table, v) end
|
|
||||||
else
|
|
||||||
table._[key] = value
|
|
||||||
end
|
|
||||||
end ]]
|
|
||||||
|
|
||||||
setmetatable(obj, mt)
|
setmetatable(obj, mt)
|
||||||
|
|
||||||
|
@ -304,13 +268,25 @@ end
|
||||||
---Create a new Implemented class
|
---Create a new Implemented class
|
||||||
---@param name string
|
---@param name string
|
||||||
---@return Impl
|
---@return Impl
|
||||||
function NewImpl(name)
|
function NewImpl(name, sync)
|
||||||
---@type Impl
|
---@type Impl
|
||||||
local impl = Impl:extend({
|
local impl = Impl:extend({
|
||||||
name = name,
|
name = name,
|
||||||
config = Config[name] or {},
|
config = Config[name] or {},
|
||||||
implType = "impl"
|
implType = sync and "syncImpl" or "impl"
|
||||||
})
|
})
|
||||||
main:RegisterImpl(name, impl)
|
main:RegisterImpl(name, impl)
|
||||||
return impl
|
return impl
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function NewSyncImpl(name)
|
||||||
|
local impl = Impl:extend({
|
||||||
|
name = name,
|
||||||
|
config = Config[name] or {},
|
||||||
|
implType = sync and "syncImpl" or "impl",
|
||||||
|
})
|
||||||
|
impl.start = function()
|
||||||
|
main.initializedImpls[name] = impl(main)
|
||||||
|
end
|
||||||
|
return impl
|
||||||
|
end
|
||||||
|
|
49
main.lua
49
main.lua
|
@ -49,8 +49,9 @@ function Main:Init()
|
||||||
o:Thread1()
|
o:Thread1()
|
||||||
else
|
else
|
||||||
o.ClientImpls = {}
|
o.ClientImpls = {}
|
||||||
|
if Config.ClientLazyLoad then
|
||||||
for k, v in pairs(Config.EnableModules) do
|
for k, v in pairs(Config.EnableModules) do
|
||||||
if v then
|
if v and v.client then
|
||||||
local path = "client/impl/" .. k .. ".impl.lua"
|
local path = "client/impl/" .. k .. ".impl.lua"
|
||||||
local source = LoadResourceFile(ResourceName, path)
|
local source = LoadResourceFile(ResourceName, path)
|
||||||
if source == nil then
|
if source == nil then
|
||||||
|
@ -66,9 +67,11 @@ function Main:Init()
|
||||||
return o.ClientImpls[implName]
|
return o.ClientImpls[implName]
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
end
|
||||||
o:Exports()
|
o:Exports()
|
||||||
o:RegisterCommands()
|
o:RegisterCommands()
|
||||||
o:RegisterEvents()
|
o:RegisterEvents()
|
||||||
|
o:LogInfo("Main initialized")
|
||||||
return o
|
return o
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -164,21 +167,21 @@ function Main:RegisterEvents()
|
||||||
end
|
end
|
||||||
|
|
||||||
function Main:LogError(msg, ...)
|
function Main:LogError(msg, ...)
|
||||||
print(("[^1ERROR^0] " .. msg):format(...))
|
print(("[^1ERROR^0] " .. ("[%s] "):format(GetGameTimer()) .. msg):format(...))
|
||||||
end
|
end
|
||||||
|
|
||||||
function Main:LogWarning(msg, ...)
|
function Main:LogWarning(msg, ...)
|
||||||
print(("[^3WARNING^0] " .. msg):format(...))
|
print(("[^3WARNING^0] " .. ("[%s] "):format(GetGameTimer()) .. msg):format(...))
|
||||||
end
|
end
|
||||||
|
|
||||||
function Main:LogSuccess(msg, ...)
|
function Main:LogSuccess(msg, ...)
|
||||||
if not Config.Debug then return end
|
if not Config.Debug then return end
|
||||||
print(("[^2INFO^0] " .. msg):format(...))
|
print(("[^2INFO^0] " .. ("[%s] "):format(GetGameTimer()) .. msg):format(...))
|
||||||
end
|
end
|
||||||
|
|
||||||
function Main:LogInfo(msg, ...)
|
function Main:LogInfo(msg, ...)
|
||||||
if not Config.Debug then return end
|
if not Config.Debug then return end
|
||||||
print(("[^5INFO^0] " .. msg):format(...))
|
print(("[^5INFO^0] " .. ("[%s] "):format(GetGameTimer()) .. msg):format(...))
|
||||||
end
|
end
|
||||||
|
|
||||||
function Main:CheckValidImpl(name, impl)
|
function Main:CheckValidImpl(name, impl)
|
||||||
|
@ -194,6 +197,9 @@ function Main:CheckValidImpl(name, impl)
|
||||||
end
|
end
|
||||||
|
|
||||||
function Main:RegisterImpl(name, impl)
|
function Main:RegisterImpl(name, impl)
|
||||||
|
if impl.implType == "syncImpl" then
|
||||||
|
return
|
||||||
|
end
|
||||||
if impl.implType == "impl" and (Config.EnableModules[name] == nil or not Config.EnableModules[name].enabled) then
|
if impl.implType == "impl" and (Config.EnableModules[name] == nil or not Config.EnableModules[name].enabled) then
|
||||||
self:LogWarning("Impl %s not enabled", name)
|
self:LogWarning("Impl %s not enabled", name)
|
||||||
return
|
return
|
||||||
|
@ -357,6 +363,16 @@ function Main:Exports()
|
||||||
end)
|
end)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
function Main:ToggleUI(state)
|
||||||
|
self.showUI = state
|
||||||
|
if Config.Nui then
|
||||||
|
SendNUIMessage({
|
||||||
|
event = "main:setShow",
|
||||||
|
data = state
|
||||||
|
})
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
main = Main:Init()
|
main = Main:Init()
|
||||||
AddEventHandler(("%s:onReady"):format(GetCurrentResourceName()), function(handler)
|
AddEventHandler(("%s:onReady"):format(GetCurrentResourceName()), function(handler)
|
||||||
local invokingResource = GetInvokingResource()
|
local invokingResource = GetInvokingResource()
|
||||||
|
@ -364,25 +380,7 @@ AddEventHandler(("%s:onReady"):format(GetCurrentResourceName()), function(handle
|
||||||
main:ListenOnReady(handler)
|
main:ListenOnReady(handler)
|
||||||
end)
|
end)
|
||||||
|
|
||||||
--[[ local origAddEventHandler = AddEventHandler
|
|
||||||
function AddEventHandler(eventName, ...)
|
|
||||||
if RegisteredEvents[eventName] then
|
|
||||||
main:LogWarning("Event %s already registered. Removing", eventName)
|
|
||||||
RemoveEventHandler(RegisteredEvents[eventName])
|
|
||||||
end
|
|
||||||
RegisteredEvents[eventName] = origAddEventHandler(eventName, ...)
|
|
||||||
return RegisteredEvents[eventName]
|
|
||||||
end
|
|
||||||
|
|
||||||
local origRegisterNetEvent = RegisterNetEvent
|
|
||||||
function RegisterNetEvent(eventName, ...)
|
|
||||||
if RegisteredEvents[eventName] then
|
|
||||||
main:LogWarning("Event %s already registered. Removing", eventName)
|
|
||||||
RemoveEventHandler(RegisteredEvents[eventName])
|
|
||||||
end
|
|
||||||
RegisteredEvents[eventName] = origRegisterNetEvent(eventName, ...)
|
|
||||||
return RegisteredEvents[eventName]
|
|
||||||
end ]]
|
|
||||||
|
|
||||||
Citizen.CreateThread(function()
|
Citizen.CreateThread(function()
|
||||||
while GetGameTimer() < main.lastTimeImplRegistered + 1000 do
|
while GetGameTimer() < main.lastTimeImplRegistered + 1000 do
|
||||||
|
@ -417,6 +415,11 @@ Citizen.CreateThread(function()
|
||||||
Wait(100)
|
Wait(100)
|
||||||
player = Framework.Functions.GetPlayerData()
|
player = Framework.Functions.GetPlayerData()
|
||||||
end
|
end
|
||||||
|
elseif Config.Framework == 'ProjectStarboy' then
|
||||||
|
while not CORE.PlayerData.loaded do
|
||||||
|
Wait(100)
|
||||||
|
main:LogInfo("Waiting for player loaded")
|
||||||
|
end
|
||||||
end
|
end
|
||||||
while not NuiReady and Config.Nui do
|
while not NuiReady and Config.Nui do
|
||||||
Wait(100)
|
Wait(100)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user