Skip to content

Commit

Permalink
chore: update ox_lib and oxmysql to the latest available version
Browse files Browse the repository at this point in the history
  • Loading branch information
bitpredator committed Sep 19, 2024
1 parent 8f8d17e commit 894cf1b
Show file tree
Hide file tree
Showing 18 changed files with 3,621 additions and 3,662 deletions.
2 changes: 1 addition & 1 deletion server-data/resources/[ox]/ox_lib/fxmanifest.lua
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ rdr3_warning 'I acknowledge that this is a prerelease build of RedM, and I am aw

name 'ox_lib'
author 'Overextended'
version '3.24.0'
version '3.26.0'
license 'LGPL-3.0-or-later'
repository 'https://github.com/overextended/ox_lib'
description 'A library of shared functions to utilise in other resources.'
Expand Down
17 changes: 13 additions & 4 deletions server-data/resources/[ox]/ox_lib/imports/addKeybind/client.lua
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,10 @@ if cache.game == 'redm' then return end
---@class CKeybind : KeybindProps
---@field currentKey string
---@field disabled boolean
---@field isPressed boolean
---@field hash number
---@field getCurrentKey fun(): string
---@field isControlPressed fun(): boolean

local keybinds = {}

Expand All @@ -24,6 +26,7 @@ local GetControlInstructionalButton = GetControlInstructionalButton

local keybind_mt = {
disabled = false,
isPressed = false,
defaultKey = '',
defaultMapper = 'keyboard',
}
Expand All @@ -36,6 +39,10 @@ function keybind_mt:getCurrentKey()
return GetControlInstructionalButton(0, self.hash, true):sub(3)
end

function keybind_mt:isControlPressed()
return self.isPressed
end

function keybind_mt:disable(toggle)
self.disabled = toggle
end
Expand All @@ -48,13 +55,15 @@ function lib.addKeybind(data)
keybinds[data.name] = setmetatable(data, keybind_mt)

RegisterCommand('+' .. data.name, function()
if not data.onPressed or data.disabled or IsPauseMenuActive() then return end
data:onPressed()
if data.disabled or IsPauseMenuActive() then return end
data.isPressed = true
if data.onPressed then data:onPressed() end
end)

RegisterCommand('-' .. data.name, function()
if not data.onReleased or data.disabled or IsPauseMenuActive() then return end
data:onReleased()
if data.disabled or IsPauseMenuActive() then return end
data.isPressed = false
if data.onReleased then data:onReleased() end
end)

RegisterKeyMapping('+' .. data.name, data.description, data.defaultMapper, data.defaultKey)
Expand Down
40 changes: 19 additions & 21 deletions server-data/resources/[ox]/ox_lib/imports/array/shared.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
---@class Array : OxClass
local Array = lib.class('Array')
lib.array = lib.class('Array')

---@alias ArrayLike<T> Array | { [number]: T }

---@private
function Array:constructor(...)
function lib.array:constructor(...)
local arr = { ... }

for i = 1, #arr do
Expand All @@ -13,15 +13,15 @@ function Array:constructor(...)
end

---@private
function Array:__newindex(index, value)
function lib.array:__newindex(index, value)
if type(index) ~= 'number' then error(("Cannot insert non-number index '%s' into an array."):format(index)) end

rawset(self, index, value)
end

---Create a new array containing the elements from two arrays.
---@param arr ArrayLike
function Array:merge(arr)
function lib.array:merge(arr)
local newArr = table.clone(self)
local length = #self

Expand All @@ -30,12 +30,12 @@ function Array:merge(arr)
newArr[length] = arr[i]
end

return Array:new(table.unpack(newArr))
return lib.array:new(table.unpack(newArr))
end

---Tests if all elements in an array succeed in passing the provided test function.
---@param testFn fun(element: unknown): boolean
function Array:every(testFn)
function lib.array:every(testFn)
for i = 1, #self do
if not testFn(self[i]) then
return false
Expand All @@ -47,7 +47,7 @@ end

---Creates a new array containing the elements from an array thtat pass the test of the provided function.
---@param testFn fun(element: unknown): boolean
function Array:filter(testFn)
function lib.array:filter(testFn)
local newArr = {}
local length = 0

Expand All @@ -60,13 +60,13 @@ function Array:filter(testFn)
end
end

return Array:new(table.unpack(newArr))
return lib.array:new(table.unpack(newArr))
end

---Returns the first or last element of an array that passes the provided test function.
---@param testFn fun(element: unknown): boolean
---@param last? boolean
function Array:find(testFn, last)
function lib.array:find(testFn, last)
local a = last and #self or 1
local b = last and 1 or #self
local c = last and -1 or 1
Expand All @@ -83,7 +83,7 @@ end
---Returns the first or last index of the first element of an array that passes the provided test function.
---@param testFn fun(element: unknown): boolean
---@param last? boolean
function Array:findIndex(testFn, last)
function lib.array:findIndex(testFn, last)
local a = last and #self or 1
local b = last and 1 or #self
local c = last and -1 or 1
Expand All @@ -100,7 +100,7 @@ end
---Returns the first or last index of the first element of an array that matches the provided value.
---@param value unknown
---@param last? boolean
function Array:indexOf(value, last)
function lib.array:indexOf(value, last)
local a = last and #self or 1
local b = last and 1 or #self
local c = last and -1 or 1
Expand All @@ -116,26 +116,26 @@ end

---Executes the provided function for each element in an array.
---@param cb fun(element: unknown)
function Array:forEach(cb)
function lib.array:forEach(cb)
for i = 1, #self do
cb(self[i])
end
end

---Concatenates all array elements into a string, seperated by commas or the specified seperator.
---@param seperator? string
function Array:join(seperator)
function lib.array:join(seperator)
return table.concat(self, seperator or ',')
end

---Removes the last element from an array and returns the removed element.
function Array:pop()
function lib.array:pop()
return table.remove(self)
end

---Adds the given elements to the end of an array and returns the new array length.
---@param ... any
function Array:push(...)
function lib.array:push(...)
local elements = { ... }
local length = #self

Expand All @@ -148,7 +148,7 @@ function Array:push(...)
end

---Removes the first element from an array and returns the removed element.
function Array:shift()
function lib.array:shift()
return table.remove(self, 1)
end

Expand All @@ -158,7 +158,7 @@ end
---@param reducer fun(accumulator: T, currentValue: T, index?: number): T
---@param initialValue? T
---@return T
function Array:reduce(reducer, initialValue)
function lib.array:reduce(reducer, initialValue)
local initialIndex = initialValue and 1 or 2
local accumulator = initialValue or self[1]

Expand All @@ -172,18 +172,16 @@ end
---Returns true if the given table is an instance of array or an array-like table.
---@param tbl ArrayLike
---@return boolean
function Array.isArray(tbl)
function lib.array.isArray(tbl)
if not type(tbl) == 'table' then return false end

local tableType = table.type(tbl)

if tableType == 'array' or tableType == 'empty' or Array.instanceOf(tbl, Array) then
if tableType == 'array' or tableType == 'empty' or lib.array.instanceOf(tbl, lib.array) then
return true
end

return false
end

lib.array = Array

return lib.array
8 changes: 3 additions & 5 deletions server-data/resources/[ox]/ox_lib/imports/class/shared.lua
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
---@diagnostic disable: invisible
local getinfo = debug.getinfo

if not getinfo(1, 'S').source:match('^@@ox_lib') then
lib.print.warn('ox_lib\'s class module is experimental and may break without warning.')
end

---Ensure the given argument or property has a valid type, otherwise throwing an error.
---@param id number | string
---@param var any
Expand Down Expand Up @@ -132,8 +128,10 @@ end

---Creates a new class.
---@generic S : OxClass
---@param name string
---@generic T : string
---@param name `T`
---@param super? S
---@return `T`
function lib.class(name, super)
assertType(1, name, 'string')

Expand Down
28 changes: 23 additions & 5 deletions server-data/resources/[ox]/ox_lib/init.lua
Original file line number Diff line number Diff line change
Expand Up @@ -91,9 +91,6 @@ end
local lib = setmetatable({
name = ox_lib,
context = context,
onCache = function(key, cb)
AddEventHandler(('ox_lib:cache:%s'):format(key), cb)
end
}, {
__index = call,
__call = call,
Expand Down Expand Up @@ -173,14 +170,27 @@ end
---Caches the result of a function, optionally clearing it after timeout ms.
function cache(key, func, timeout) end

local cacheEvents = {}

local cache = setmetatable({ game = GetGameName(), resource = resourceName }, {
__index = context == 'client' and function(self, key)
__index = function(self, key)
cacheEvents[key] = {}

AddEventHandler(('ox_lib:cache:%s'):format(key), function(value)
local oldValue = self[key]
local events = cacheEvents[key]

for i = 1, #events do
Citizen.CreateThreadNow(function()
events[i](value, oldValue)
end)
end

self[key] = value
end)

return rawset(self, key, export.cache(nil, key) or false)[key]
end or nil,
end,

__call = function(self, key, func, timeout)
local value = rawget(self, key)
Expand All @@ -197,6 +207,14 @@ local cache = setmetatable({ game = GetGameName(), resource = resourceName }, {
end,
})

function lib.onCache(key, cb)
if not cacheEvents[key] then
getmetatable(cache).__index(cache, key)
end

table.insert(cacheEvents[key], cb)
end

_ENV.cache = cache

local notifyEvent = ('__ox_notify_%s'):format(cache.resource)
Expand Down
34 changes: 34 additions & 0 deletions server-data/resources/[ox]/ox_lib/locales/ro.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"language": "Română",
"settings": "Setări",
"ui": {
"cancel": "Anulează",
"close": "Închide",
"confirm": "Confirmă",
"more": "Mai multe...",
"settings": {
"locale": "Schimbă limba",
"locale_description": "Limba actuală: ${language} (%s)",
"notification_audio": "Audio notificări",
"notification_position": "Poziţie notificări"
},
"position": {
"bottom": "Jos",
"bottom-left": "Jos-stânga",
"bottom-right": "Jos-dreapta",
"center-left": "Centru-stânga",
"center-right": "Centru-dreapta",
"top": "Sus",
"top-left": "Sus-stânga",
"top-right": "Sus-dreapta"
}
},
"open_radial_menu": "Deschide meniul radial",
"cancel_progress": "Anuleaza bara de progres actuala",
"txadmin_announcement": "Anunţ de server dat de %s",
"txadmin_dm": "Mesaj Direct de la %s",
"txadmin_warn": "Ai fost avertizat de %s",
"txadmin_warn_content": "%s \nID Acţiune: %s",
"txadmin_scheduledrestart": "Restart Programat"
}

Loading

0 comments on commit 894cf1b

Please sign in to comment.