refactor(imports/getCore): set constants and use new import files

This commit is contained in:
Linden
2022-05-04 05:14:53 +10:00
parent c5bdaaafe8
commit 96eabf5592

View File

@@ -1,3 +1,9 @@
local Core = {
Ox = 'ox_core',
QB = 'qb-core',
ESX = 'es_extended',
}
return function() return function()
local result local result
@@ -5,60 +11,58 @@ return function()
local framework = GetConvar('framework', '') local framework = GetConvar('framework', '')
if framework == '' then if framework == '' then
framework = GetResourceState('ox_core'):find('start') and 'ox_core' framework = GetResourceState(Core.Ox):find('start') and Core.Ox
or GetResourceState('qb-core'):find('start') and 'qb-core' or GetResourceState(Core.QB):find('start') and Core.QB
or GetResourceState('es_extended'):find('start') and 'es_extended' or GetResourceState(Core.ESX):find('start') and Core.ESX
if not framework then if not framework then
error('Unable to determine framework (convar is not set, or resource was renamed)') error('Unable to determine framework (convar is not set, or resource was renamed)')
end end
end end
local success, import local success
local import
local resource
if framework == 'qb-core' then if framework == Core.Ox then
import = exports[framework]:GetCoreObject()
elseif framework == 'es_extended' then
import = exports[framework]:getSharedObject()
end
if import then
import.resource = framework
else
if framework == 'ox_core' then
import = ('%s/import.lua'):format(lib.service) import = ('%s/import.lua'):format(lib.service)
resource = Core.Ox
else else
error('no loader exists for %s'):format(framework) import = ('imports/getCore/%s/%s.lua'):format(framework, lib.service)
resource = lib.name
end end
success, result = pcall(LoadResourceFile, framework, import) success, result = pcall(LoadResourceFile, resource, import)
if not result then if not result then
error(("Unable to load '@%s/%s'"):format(framework, import)) error(("Unable to load '@%s/%s'"):format(resource, import))
end end
if not success then if not success then
error(result and result or ("Unable to load '@%s/%s'"):format(framework, import), 0) error(result and result or ("Unable to load '@%s/%s'"):format(resource, import), 0)
end end
success, result = load(result, ('@@%s/%s'):format(framework, import)) success, result = load(result, ('@@%s/%s'):format(resource, import))
if not success then if not success then
error(result, 0) error(result, 0)
end end
success, result = pcall(success) success, result = pcall(success, framework)
if not success then error(result) end if not success then error(result) end
if framework == 'ox_core' then if framework == Core.Ox then
import = Ox result = Ox
end end
import.resource = framework if not result then
error(('no loader exists for %s'):format(framework))
elseif type(result) == 'function' then
result = result(framework)
end end
result = import result.resource = framework
end) end)
return result return result