Cleanup and placeable_object replacement

Added cleaned up and improved functionality for placeable object.
Example is in unit tests.

Cleanup whitespace and removed accessibility as not used/not documented and doesnt appear to be useful with our current work flow
This commit is contained in:
gononono64 committed 2025-06-04 15:29:21 -05:00
1 parent b5dd8c018c
commit 3fa933fab1
24 files changed
+698 -903

No files matched your search

-212
View File
@@ -1,212 +0,0 @@
local colourblind = GetResourceKvpString('colourblind') or "default"
local QB = false
if (BridgeClientConfig.MenuSystem == "auto" and GetResourceState("qb-menu") ~= "started") or (BridgeClientConfig.MenuSystem ~= "auto" and BridgeClientConfig.MenuSystem == "qb-menu") then
QB = true
end
Accessibility = Accessibility or {}
RegisterCommand(locale("accessibility.cb_command"), function()
Accessibility.updatecolourblindness()
end, false)
Accessibility.updatecolourblindness = function()
local currentCB = locale("accessibility.cb_"..colourblind.."_title")
local cbIcon = "fas fa-eye-low-vision"
Menu.Open({
id = 'colourblind_update',
title = locale("accessibility.cb_title"),
options = {
{
title = locale("accessibility.cb_title"),
description = locale("accessibility.cb_desc"):format(currentCB),
disabled = true,
},
{
title = locale("accessibility.cb_default_title"),
description = locale("accessibility.cb_default_desc"),
icon = "fas fa-eye",
onSelect = function()
colourblind = "default"
SetResourceKvp('colourblind', colourblind)
Notify.SendNotify(locale("accessibility.cb_updated"):format(locale("accessibility.cb_"..colourblind.."_title")), 'success', 3000)
end
},
{
title = locale("accessibility.cb_protanomaly_title"),
description = locale("accessibility.cb_protanomaly_desc"),
icon = cbIcon,
onSelect = function()
colourblind = "protanomaly"
SetResourceKvp('colourblind', colourblind)
Notify.SendNotify(locale("accessibility.cb_updated"):format(locale("accessibility.cb_"..colourblind.."_title")), 'success', 3000)
end
},
{
title = locale("accessibility.cb_deuteranomaly_title"),
description = locale("accessibility.cb_deuteranomaly_desc"),
icon = cbIcon,
onSelect = function()
colourblind = "deuteranomaly"
SetResourceKvp('colourblind', colourblind)
Notify.SendNotify(locale("accessibility.cb_updated"):format(locale("accessibility.cb_"..colourblind.."_title")), 'success', 3000)
end
},
{
title = locale('accessibility.cb_dual_title'),
description = locale("accessibility.cb_dual_desc"),
icon = cbIcon,
onSelect = function()
colourblind = "dual"
SetResourceKvp('colourblind', colourblind)
Notify.SendNotify(locale("accessibility.cb_updated"):format(locale("accessibility.cb_"..colourblind.."_title")), 'success', 3000)
end
},
{
title = locale("accessibility.cb_tritanopia_title"),
description = locale("accessibility.cb_tritanopia_desc"),
icon = cbIcon,
onSelect = function()
colourblind = "tritanopia"
SetResourceKvp('colourblind', colourblind)
Notify.SendNotify(locale("accessibility.cb_updated"):format(locale("accessibility.cb_"..colourblind.."_title")), 'success', 3000)
end
},
{
title = locale("accessibility.cb_tritanomaly_title"),
description = locale("accessibility.cb_tritanomaly_desc"),
icon = cbIcon,
onSelect = function()
colourblind = "tritanomaly"
SetResourceKvp('colourblind', colourblind)
Notify.SendNotify(locale("accessibility.cb_updated"):format(locale("accessibility.cb_"..colourblind.."_title")), 'success', 3000)
end
},
}},QB)
end
Accessibility.hexToRgb = function(hex)
hex = hex:gsub("#", "")
local r,g,b = tonumber("0x" .. hex:sub(1, 2)),tonumber("0x" .. hex:sub(3, 4)),tonumber("0x" .. hex:sub(5, 6))
return r, g, b
end
Accessibility.rgbToHex = function(r, g, b)
return string.format("#%02x%02x%02x", r, g, b)
end
Accessibility.rgbToHsl = function(r, g, b)
r = r / 255
g = g / 255
b = b / 255
local max = math.max(r, g, b)
local min = math.min(r, g, b)
local h, s, l = 0, 0, (max + min) / 2
if max == min then
h, s = 0, 0 -- achromatic
else
local d = max - min
s = l > 0.5 and d / (2 - max - min) or d / (max + min)
if max == r then
h = (g - b) / d + (g < b and 6 or 0)
elseif max == g then
h = (b - r) / d + 2
elseif max == b then
h = (r - g) / d + 4
end
h = h / 6
end
return h, s, l
end
Accessibility.hslToRgb = function(h, s, l)
local r, g, b
if s == 0 then
r, g, b = l, l, l -- achromatic
else
local function hue2rgb(p, q, t)
if t < 0 then t = t + 1 end
if t > 1 then t = t - 1 end
if t < 1 / 6 then return p + (q - p) * 6 * t end
if t < 1 / 2 then return q end
if t < 2 / 3 then return p + (q - p) * (2 / 3 - t) * 6 end
return p
end
local q = l < 0.5 and l * (1 + s) or l + s - l * s
local p = 2 * l - q
r = hue2rgb(p, q, h + 1 / 3)
g = hue2rgb(p, q, h)
b = hue2rgb(p, q, h - 1 / 3)
end
return math.floor(r * 255), math.floor(g * 255), math.floor(b * 255)
end
Accessibility.adjustColourForColourblindness = function(num, returnAsRGB)
local r, g, b
if type(num) ~= "table" and num:match("^#%x%x%x%x%x%x$") then
r, g, b = Accessibility.hexToRgb(num) -- Convert hex to RGB
else
r, g, b = num.r, num.g, num.b -- If it's already RGB, use it directly
end
local h, s, l = Accessibility.rgbToHsl(r, g, b) -- Convert RGB to HSL
-- Adjust hue values based on colourblindness type
if colourblind == "protanomaly" then -- Red-blind
-- Shift towards blue/cyan
h = (h + 0.5) % 1 -- Shift by 180 degrees
elseif colourblind == "deuteranomaly" then -- Green-blind
-- Shift towards blue/magenta
h = (h + 0.33) % 1 -- Shift by 120 degrees
elseif colourblind == "dual" then -- Protanopia and Deuteranopia (Red-Green blind)
-- More significant shift towards blue/yellow
-- This is a more drastic shift to maximize contrast
if h < 0.166 then -- Reddish hues
h = 0.66 -- Shift to blue
elseif h < 0.5 then -- Greenish hues
h = 0.166 -- Shift to yellow
else
h = h -- Leave blue/purple hues alone
end
-- Increase saturation and lightness to make colours more distinct
s = math.min(s * 1.5, 1)
l = math.min(l * 1.2, 1)
elseif colourblind == "tritanopia" then -- Blue-blind
-- Shift towards red/yellow
h = (h + 0.16) % 1 -- Shift by 60 degrees
elseif colourblind == "tritanomaly" then
h = (h + 0.08) % 1
end
-- Convert back to RGB
r, g, b = Accessibility.hslToRgb(h, s, l)
if returnAsRGB then
return {r = r, g = g, b = b}
else
-- Convert back to HEX
local newHex = Accessibility.rgbToHex(r, g, b)
return newHex
end
end
---@returns a colour adjusted for colourblindness in HEX if variable `returnAsRGB` is false
---@param colourName string Colour name in HEX format or RGB format
-- This is the trigger function for altering colours for colourblindness :D
Accessibility.getAdjustedColour = function(colourName, returnAsRGB)
local originalHex = colourName
if originalHex then
if colourblind == "default" then
if type(colourName) == "table" and not returnAsRGB then
return Accessibility.rgbToHex(colourName.r, colourName.g, colourName.b)
else
return originalHex
end
else
return Accessibility.adjustColourForColourblindness(originalHex, returnAsRGB)
end
else
Prints.Error("Invalid Colour Name^0] [^3"..colourName.."^0")
return "#FFFFFF" -- Default to white if the colour name is invalid
end
end
return Accessibility
+13 -13
View File
@@ -11,28 +11,28 @@ ESX = ESX or exports['es_extended']:getSharedObject()
--- @return table|nil The player's full appearance data or nil if not found
function Clothing.GetFullAppearanceData(src)
src = src and tonumber(src)
assert(src, "src is nil")
assert(src, "src is nil")
local Player = ESX.GetPlayerFromId(src)
if not Player then return end
local citId = Player.identifier
if not citId then return end
if Clothing.Players[citId] then return Clothing.Players[citId] end
local result = MySQL.query.await('SELECT skin FROM users WHERE identifier = ?', { citId})
if result[1] == nil then return end
local model = GetEntityModel(GetPlayerPed(src))
local skinData = json.decode(result[1].skin)
local converted = Clothing.ConvertToDefault(skinData)
-- Store complete data in the cache
Clothing.Players[citId] = {
model = model,
skin = skinData,
converted = converted
skin = skinData,
converted = converted
}
return Clothing.Players[citId]
end
@@ -81,16 +81,16 @@ function Clothing.SetAppearance(src, data, updateBackup, save)
local model = GetEntityModel(GetPlayerPed(src))
if not model then return end
local converted = Clothing.ConvertFromDefault(data)
-- Get full appearance data
local currentClothing = Clothing.GetFullAppearanceData(src)
if not currentClothing then return end
local currentSkin = currentClothing.skin
for k, v in pairs(converted) do
currentSkin[k] = v
end
if not Clothing.Players[citId].backup or updateBackup then
Clothing.Players[citId].backup = currentClothing.converted
@@ -100,7 +100,7 @@ function Clothing.SetAppearance(src, data, updateBackup, save)
Clothing.Players[citId].skin = currentSkin
Clothing.Players[citId].model = model
Clothing.Players[citId].converted = Clothing.ConvertToDefault(currentSkin)
if save then
if save then
local encodedSkin = json.encode(currentSkin)
-- saving 1 sql call by adding the query here instead of calling save
MySQL.update.await('UPDATE users SET skin = ? WHERE identifier = ?', {
@@ -137,7 +137,7 @@ end
function Clothing.OpenMenu(src)
src = src and tonumber(src)
assert(src, "src is nil")
assert(src, "src is nil")
TriggerClientEvent('esx_skin:openMenu', src)
end
+44 -18
View File
@@ -11,28 +11,28 @@ QBCore = QBCore or exports['qb-core']:GetCoreObject()
--- @return table|nil The player's full appearance data or nil if not found
function Clothing.GetFullAppearanceData(src)
src = src and tonumber(src)
assert(src, "src is nil")
assert(src, "src is nil")
local Player = QBCore.Functions.GetPlayer(src)
if not Player then return end
local citId = Player.PlayerData.citizenid
if not citId then return end
if Clothing.Players[citId] then return Clothing.Players[citId] end
local result = MySQL.query.await('SELECT * FROM playerskins WHERE citizenid = ? AND active = ?', { citId, 1 })
if result[1] == nil then return end
local model = Player.PlayerData.model
local skinData = json.decode(result[1].skin)
local converted = Clothing.ConvertToDefault(skinData)
-- Store complete data in the cache
Clothing.Players[citId] = {
model = model,
skin = skinData,
converted = converted
Clothing.Players[citId] = {
model = model,
skin = skinData,
converted = converted
}
return Clothing.Players[citId]
end
@@ -64,16 +64,16 @@ function Clothing.SetAppearance(src, data, updateBackup, save)
local model = GetEntityModel(GetPlayerPed(src))
if not model then return end
local converted = Clothing.ConvertFromDefault(data)
-- Get full appearance data
local currentClothing = Clothing.GetFullAppearanceData(src)
if not currentClothing then return end
local currentSkin = currentClothing.skin
for k, v in pairs(converted) do
currentSkin[k] = v
end
if not Clothing.Players[citId].backup or updateBackup then
Clothing.Players[citId].backup = currentClothing.converted
end
@@ -118,7 +118,7 @@ end
function Clothing.OpenMenu(src)
src = src and tonumber(src)
assert(src, "src is nil")
assert(src, "src is nil")
TriggerClientEvent('qb-clothing:client:openMenu', src)
end
@@ -131,7 +131,7 @@ AddEventHandler('community_bridge:Server:OnPlayerLoaded', function(src)
if not Player then return end
local citId = Player.PlayerData.citizenid
if not citId then return end
-- Use GetFullAppearanceData to cache the complete appearance
Clothing.GetFullAppearanceData(src)
end)
@@ -208,6 +208,32 @@ RegisterCommand('clothing:openmenu', function(source, args, rawCommand)
end, false)
RegisterCommand('clothing:crowley', function(source, args, rawCommand)
local src = source
end, false)
-- RegisterCommand('clothing:crowley', function(source, args, rawCommand)
-- local src = source
-- Clothing.SetAppearance(src, {
-- components = {
-- {drawable = 0, texture = 0, component_id = 0},
-- {drawable = 0, texture = 0, component_id = 1},
-- {drawable = 19, texture = 0, component_id = 2},
-- {drawable = 6, texture = 0, component_id = 3},
-- {drawable = 0, texture = 0, component_id = 4},
-- {drawable = 0, texture = 0, component_id = 5},
-- {drawable = 0, texture = 0, component_id = 6},
-- {drawable = 0, texture = 0, component_id = 7},
-- {drawable = 23, texture = 0, component_id = 8},
-- {drawable = 0, texture = 0, component_id = 9},
-- {drawable = 0, texture = 0, component_id = 10},
-- {drawable = 4, texture = 2, component_id = 11}
-- },
-- props = {
-- {drawable = 27, prop_id = 0, texture = 0},
-- {drawable = 0, prop_id = 1, texture = 0},
-- {drawable = 0, prop_id = 2, texture = 0},
-- {drawable = 0, prop_id = 3, texture = 0},
-- {drawable = 0, prop_id = 4, texture = 0},
-- {drawable = 0, prop_id = 5, texture = 0},
-- -- {drawable = 0, prop_id = 6, texture = 0},
-- -- {drawable = 0, prop_id = 7, texture = 0},
-- }
-- }, false, true)
-- end, false)
+14 -1
View File
@@ -58,7 +58,7 @@ Target.AddGlobalVehicle = function(options)
ox_target:addGlobalVehicle(options)
end
---This will remove target options from all vehicles.
---This will remove target options from all vehicles.
---@param options table
Target.RemoveGlobalVehicle = function(options)
local assembledLables = {}
@@ -96,6 +96,18 @@ Target.RemoveModel = function(model)
ox_target:removeModel(model)
end
-- Target.DisableTargeting = function(bool)
-- ox_target:disableTargeting(bool)
-- end
-- Target.Refresh = function()
-- ox_target:disableTargeting(true)
-- Wait(10)
-- ox_target:disableTargeting(false)
-- end
---This will add a box zone to the target system. This is useful for when you want to add target options to a specific area.
---@param name string
---@param coords table
@@ -104,6 +116,7 @@ end
---@param options table
Target.AddBoxZone = function(name, coords, size, heading, options, debug)
options = Target.FixOptions(options or {})
if not next(options) then return end
local target = ox_target:addBoxZone({
coords = coords,
size = size,
+12
View File
@@ -110,6 +110,17 @@ Target.RemoveModel = function(model)
qb_target:RemoveTargetModel(model)
end
-- Target.DisableTargeting = function(bool)
-- qb_target:AllowTargeting(bool)
-- end
-- Target.Refresh = function()
-- qb_target:AllowTargeting(false)
-- Wait(10)
-- qb_target:AllowTargeting(true)
-- end
---This will add a box zone to the target system. This is useful for when you want to add target options to a specific area.
---@param name string
---@param coords table
@@ -118,6 +129,7 @@ end
---@param options table
Target.AddBoxZone = function(name, coords, size, heading, options, debug)
options = Target.FixOptions(options)
if not next(options) then return end
qb_target:AddBoxZone(name, coords, size.x, size.y, {
name = name,
debugPoly = debug or targetDebug,
@@ -127,6 +127,17 @@ Target.RemoveZone = function(name)
end
end
-- Target.DisableTargeting = function(bool)
-- sleepless_interact:disableInteract(bool)
-- end
-- Target.Refresh = function()
-- sleepless_interact:disableInteract(false)
-- Wait(10)
-- sleepless_interact:disableInteract(true)
-- end
AddEventHandler('onResourceStop', function(resource)
if resource == GetCurrentResourceName() then
for _, target in pairs(targetZones) do