mirror of
https://github.com/CommunityOx/ox_lib.git
synced 2026-08-17 06:56:03 +01:00
refactor(init): minor tweaks
Remove dead table (lib.exports) and annotate server-side lib.notify.
This commit is contained in:
15
init.lua
15
init.lua
@@ -78,7 +78,6 @@ end
|
|||||||
lib = setmetatable({
|
lib = setmetatable({
|
||||||
name = ox_lib,
|
name = ox_lib,
|
||||||
context = context,
|
context = context,
|
||||||
exports = {},
|
|
||||||
onCache = function(key, cb)
|
onCache = function(key, cb)
|
||||||
AddEventHandler(('ox_lib:cache:%s'):format(key), cb)
|
AddEventHandler(('ox_lib:cache:%s'):format(key), cb)
|
||||||
end
|
end
|
||||||
@@ -147,6 +146,7 @@ end
|
|||||||
-----------------------------------------------------------------------------------------------
|
-----------------------------------------------------------------------------------------------
|
||||||
|
|
||||||
cache = { game = GetGameName(), resource = GetCurrentResourceName() }
|
cache = { game = GetGameName(), resource = GetCurrentResourceName() }
|
||||||
|
local notify = ('__ox_notify_%s'):format(cache.resource)
|
||||||
|
|
||||||
if context == 'client' then
|
if context == 'client' then
|
||||||
setmetatable(cache, {
|
setmetatable(cache, {
|
||||||
@@ -159,7 +159,7 @@ if context == 'client' then
|
|||||||
end,
|
end,
|
||||||
})
|
})
|
||||||
|
|
||||||
RegisterNetEvent(('__ox_notify_%s'):format(cache.resource), function(data)
|
RegisterNetEvent(notify, function(data)
|
||||||
if locale then
|
if locale then
|
||||||
if data.title then
|
if data.title then
|
||||||
data.title = locale(data.title) or data.title
|
data.title = locale(data.title) or data.title
|
||||||
@@ -176,9 +176,12 @@ if context == 'client' then
|
|||||||
cache.playerId = PlayerId()
|
cache.playerId = PlayerId()
|
||||||
cache.serverId = GetPlayerServerId(cache.playerId)
|
cache.serverId = GetPlayerServerId(cache.playerId)
|
||||||
else
|
else
|
||||||
local notify = ('__ox_notify_%s'):format(cache.resource)
|
---Trigger a notification on the target playerId from the server.\
|
||||||
|
---If locales are loaded, the title and description will be formatted automatically.\
|
||||||
function lib.notify(source, data)
|
---Note: No support for locale placeholders when using this function.
|
||||||
TriggerClientEvent(notify, source, data)
|
---@param playerId number
|
||||||
|
---@param data NotifyProps
|
||||||
|
function lib.notify(playerId, data)
|
||||||
|
TriggerClientEvent(notify, playerId, data)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|||||||
Reference in New Issue
Block a user