This repository has been archived by the owner on Apr 13, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 893e7b6
Showing
17 changed files
with
968 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
# Auto detect text files and perform LF normalization | ||
* text=auto |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
fx_version 'cerulean' | ||
game 'gta5' | ||
use_experimental_fxv2_oal 'yes' | ||
lua54 'yes' | ||
|
||
author 'ZF Labo' | ||
description 'A library for FiveM developers to make their life easier when using QBCore & ESX.' | ||
version '1.2.0' | ||
|
||
dependencies { | ||
'/server:5848', | ||
'/onesync', | ||
} | ||
|
||
files { | ||
'init.lua', | ||
'imports/**/client.lua', | ||
'imports/**/shared.lua', | ||
} | ||
|
||
shared_script 'modules/init.lua' | ||
|
||
shared_scripts { | ||
'@ox_lib/init.lua', | ||
'@es_extended/imports.lua', | ||
|
||
'modules/**/shared.lua', | ||
'locales.lua', | ||
} | ||
|
||
client_scripts { | ||
'modules/**/client.lua', | ||
'modules/**/client/*.lua' | ||
} | ||
|
||
server_scripts { | ||
'modules/**/server.lua', | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
local loaded = {} | ||
|
||
package = { | ||
loaded = setmetatable({}, { | ||
__index = loaded, | ||
__newindex = noop, | ||
__metatable = false, | ||
}), | ||
path = './?.lua;' | ||
} | ||
|
||
local _require = require | ||
|
||
---Loads the given module inside the current resource, returning any values returned by the file or `true` when `nil`. | ||
---@param modname string | ||
---@return unknown? | ||
function zf.require(modname) | ||
if type(modname) ~= 'string' then return end | ||
|
||
local module = loaded[modname] | ||
|
||
if not module then | ||
if module == false then | ||
error(("^1circular-dependency occurred when loading module '%s'^0"):format(modname), 2) | ||
end | ||
|
||
local success, result = pcall(_require, modname) | ||
|
||
if success then | ||
loaded[modname] = result | ||
return result | ||
end | ||
|
||
local modpath = modname:gsub('%.', '/') | ||
|
||
for path in package.path:gmatch('[^;]+') do | ||
local scriptPath = path:gsub('?', modpath):gsub('%.+%/+', '') | ||
local resourceFile = LoadResourceFile(cache.resource, scriptPath) | ||
|
||
if resourceFile then | ||
loaded[modname] = false | ||
scriptPath = ('@@%s/%s'):format(cache.resource, scriptPath) | ||
|
||
local chunk, err = load(resourceFile, scriptPath) | ||
|
||
if err or not chunk then | ||
loaded[modname] = nil | ||
return error(err or ("unable to load module '%s'"):format(modname), 3) | ||
end | ||
|
||
module = chunk(modname) or true | ||
loaded[modname] = module | ||
|
||
return module | ||
end | ||
end | ||
|
||
return error(("module '%s' not found"):format(modname), 2) | ||
end | ||
|
||
return module | ||
end | ||
|
||
return zf.require |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,186 @@ | ||
local zflib = 'zf-lib' | ||
local export = exports[zflib] | ||
|
||
if not GetResourceState(zflib):find('start') then | ||
error('^1zf-lib should be started before this resource.^0', 2) | ||
end | ||
|
||
|
||
|
||
----------------------------------------------- | ||
--------------- Module handling --------------- | ||
----------------------------------------------- | ||
local LoadResourceFile = LoadResourceFile | ||
local context = IsDuplicityVersion() and 'server' or 'client' | ||
|
||
function noop() end | ||
|
||
local function loadModule(self, module) | ||
local dir = ('modules/%s'):format(module) | ||
local chunk = LoadResourceFile(zflib, ('%s/%s.lua'):format(dir, context)) | ||
local shared = LoadResourceFile(zflib, ('%s/shared.lua'):format(dir)) | ||
|
||
if shared then | ||
chunk = (chunk and ('%s\n%s'):format(shared, chunk)) or shared | ||
end | ||
|
||
if chunk then | ||
local fn, err = load(chunk, ('@@' .. zflib .. '/%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) | ||
|
||
if not module then | ||
local function method(...) | ||
return export[index](nil, ...) | ||
end | ||
|
||
if not ... then | ||
self[index] = method | ||
end | ||
|
||
return method | ||
end | ||
end | ||
|
||
return module | ||
end | ||
|
||
zf = setmetatable({ | ||
name = zflib, | ||
context = context | ||
}, { | ||
__index = call, | ||
__call = call, | ||
}) | ||
|
||
require = zf.require | ||
|
||
|
||
|
||
----------------------------------------------- | ||
------------- Locales from QBCore ------------- | ||
----------------------------------------------- | ||
Locale = {} | ||
Locale.__index = Locale | ||
|
||
local function translateKey(phrase, subs) | ||
if type(phrase) ~= 'string' then | ||
error('TypeError: translateKey function expects arg #1 to be a string') | ||
end | ||
|
||
if not subs then | ||
return phrase | ||
end | ||
|
||
local result = phrase | ||
|
||
for k, v in pairs(subs) do | ||
local templateToFind = '%%{' .. k .. '}' | ||
result = result:gsub(templateToFind, tostring(v)) -- string to allow all types | ||
end | ||
|
||
return result | ||
end | ||
|
||
function Locale.new(_, opts) | ||
local self = setmetatable({}, Locale) | ||
|
||
self.fallback = opts.fallbackLang and Locale:new({ | ||
warnOnMissing = false, | ||
phrases = opts.fallbackLang.phrases, | ||
}) or false | ||
|
||
self.warnOnMissing = type(opts.warnOnMissing) ~= 'boolean' and true or opts.warnOnMissing | ||
|
||
self.phrases = {} | ||
self:extend(opts.phrases or {}) | ||
|
||
return self | ||
end | ||
|
||
function Locale:extend(phrases, prefix) | ||
for key, phrase in pairs(phrases) do | ||
local prefixKey = prefix and ('%s.%s'):format(prefix, key) or key | ||
-- If this is a nested table, we need to go reeeeeeeeeeeecursive | ||
if type(phrase) == 'table' then | ||
self:extend(phrase, prefixKey) | ||
else | ||
self.phrases[prefixKey] = phrase | ||
end | ||
end | ||
end | ||
|
||
function Locale:clear() | ||
self.phrases = {} | ||
end | ||
|
||
function Locale:replace(phrases) | ||
phrases = phrases or {} | ||
self:clear() | ||
self:extend(phrases) | ||
end | ||
|
||
function Locale:locale(newLocale) | ||
if (newLocale) then | ||
self.currentLocale = newLocale | ||
end | ||
return self.currentLocale | ||
end | ||
|
||
function Locale:t(key, subs) | ||
local phrase, result | ||
subs = subs or {} | ||
|
||
if type(self.phrases[key]) == 'string' then | ||
phrase = self.phrases[key] | ||
else | ||
if self.warnOnMissing then | ||
print(('^3Warning: Missing phrase for key: "%s"'):format(key)) | ||
end | ||
if self.fallback then | ||
return self.fallback:t(key, subs) | ||
end | ||
result = key | ||
end | ||
|
||
if type(phrase) == 'string' then | ||
result = translateKey(phrase, subs) | ||
end | ||
|
||
return result | ||
end | ||
|
||
function Locale:has(key) | ||
return self.phrases[key] ~= nil | ||
end | ||
|
||
function Locale:delete(phraseTarget, prefix) | ||
if type(phraseTarget) == 'string' then | ||
self.phrases[phraseTarget] = nil | ||
else | ||
for key, phrase in pairs(phraseTarget) do | ||
local prefixKey = prefix and prefix .. '.' .. key or key | ||
|
||
if type(phrase) == 'table' then | ||
self:delete(phrase, prefixKey) | ||
else | ||
self.phrases[prefixKey] = nil | ||
end | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
Blips = {} | ||
JobBlips = {} | ||
GangBlips = {} | ||
|
||
function zf.registerBlip(coords, label, sprite, colour, scale, display) | ||
local res = GetInvokingResource() | ||
local blip = AddBlipForCoord(coords.x, coords.y, coords.z) | ||
SetBlipSprite(blip, sprite) | ||
SetBlipDisplay(blip, display) | ||
SetBlipScale(blip, scale) | ||
SetBlipColour(blip, colour) | ||
SetBlipAsShortRange(blip, true) | ||
BeginTextCommandSetBlipName("STRING") | ||
AddTextComponentString(label) | ||
EndTextCommandSetBlipName(blip) | ||
|
||
if Blips[res] and Blips[res].blips then | ||
Blips[res].blips[#Blips[res].blips + 1] = blip | ||
else | ||
Blips[res] = {} | ||
Blips[res].blips = {} | ||
Blips[res].blips[#Blips[res].blips + 1] = blip | ||
end | ||
end | ||
|
||
function zf.registerJobBlip(job, coords, label, sprite, colour, scale, display) | ||
end | ||
|
||
function zf.registerGangBlip(gang, coords, label, sprite, colour, scale, display) | ||
end | ||
|
||
local function removeJobBlip() | ||
end | ||
|
||
local function removeGangBlip() | ||
end | ||
|
||
local function removeResourceBlips(resname) | ||
if Blips[resname] and Blips[resname].blips then | ||
for id,blip in pairs(Blips[resname].blips) do | ||
RemoveBlip(blip) | ||
end | ||
Blips[resname] = {} | ||
end | ||
|
||
if JobBlips[resname] and JobBlips[resname].blips then | ||
for id,blip in pairs(JobBlips[resname].blips) do | ||
RemoveBlip(blip) | ||
end | ||
JobBlips[resname] = {} | ||
end | ||
|
||
if GangBlips[resname] and GangBlips[resname].blips then | ||
for id,blip in pairs(GangBlips[resname].blips) do | ||
RemoveBlip(blip) | ||
end | ||
GangBlips[resname] = {} | ||
end | ||
end | ||
|
||
AddEventHandler('onResourceStop', function(resname) | ||
if Blips[resname] or JobBlips[resname] or GangBlips[resname] then | ||
removeResourceBlips(resname) | ||
end | ||
end) |
Oops, something went wrong.