Changed createshop to registershop

dont forget to update

usibg cache system for clothing
This commit is contained in:
gononono64 committed 2025-05-24 22:10:39 -05:00
1 parent 13e0d0bb98
commit ba111f1b52
14 files changed
+139 -15

No files matched your search

+23 -5
View File
@@ -13,7 +13,10 @@
---@field Get fun(name:string): any ---@field Get fun(name:string): any
---@field OnChange fun(name:string, onChange:fun(new:any, old:any)) ---@field OnChange fun(name:string, onChange:fun(new:any, old:any))
---@field Remove fun(name:string) ---@field Remove fun(name:string)
local Cache = {} ---@type CacheModule Cache = Cache or {} ---@type CacheModule -- <-- we use Cache as a global variable so that if we dont required it more than once
Table = Table or Require('lib/utility/shared/tables.lua')
Id = Id or Require('lib/utility/shared/ids.lua')
local Config = Require("settings/sharedConfig.lua") local Config = Require("settings/sharedConfig.lua")
local max = 5000 local max = 5000
@@ -54,9 +57,9 @@ local function processCacheEntry(now, cache)
if remaining <= 0 then if remaining <= 0 then
local oldValue = cache.Value local oldValue = cache.Value
cache.Value = cache.Compare() cache.Value = cache.Compare()
if cache.Value ~= oldValue and cache.OnChange then if not Table.Compare(cache.Value, oldValue) and cache.OnChange then
for i, onChange in ipairs(cache.OnChange) do for i, onChange in pairs(cache.OnChange) do
onChange(cache.Value, oldValue) onChange(cache.Value, oldValue)
end end
end end
@@ -212,11 +215,12 @@ function Cache.OnChange(name, onChange)
local cache = Cache.Caches[_name] local cache = Cache.Caches[_name]
assert(cache, "Cache with name '" .. _name .. "' does not exist.") assert(cache, "Cache with name '" .. _name .. "' does not exist.")
local id = Id.CreateUniqueId(Cache.Caches[_name]?.OnChange)
-- Figure out which resource is trying to register this callback -- Figure out which resource is trying to register this callback
local invokingResource = GetInvokingResource() local invokingResource = GetInvokingResource()
if not invokingResource then return end if not invokingResource then return end
-- Add the new callback to our list -- Add the new callback to our list
local callbackIndex = #cache.OnChange + 1 local callbackIndex = id
cache.OnChange[callbackIndex] = onChange cache.OnChange[callbackIndex] = onChange
-- Track the callback with its resource -- Track the callback with its resource
@@ -226,6 +230,20 @@ function Cache.OnChange(name, onChange)
}) })
debugPrint(("Added new OnChange callback to cache '%s' from resource '%s'"):format(_name, invokingResource)) debugPrint(("Added new OnChange callback to cache '%s' from resource '%s'"):format(_name, invokingResource))
return callbackIndex
end
function Cache.RemoveOnChange(name, id)
assert(name, "Cache name is required.")
local _name = tostring(name)
local cache = Cache.Caches[_name]
assert(cache, "Cache with name '" .. _name .. "' does not exist.")
if cache.OnChange[id] then
cache.OnChange[id] = nil
debugPrint("Removed OnChange callback from cache '" .. _name .. "' with ID: " .. id)
else
debugPrint("No OnChange callback found with ID: " .. id .. " in cache '" .. _name .. "'")
end
end end
---@param name string ---@param name string
View File
Whitespace-only changes.
+11
View File
@@ -115,5 +115,16 @@ Table.Shuffle = function(tbl)
return tbl return tbl
end end
Table.Compare = function(a, b)
if type(a) == "table" then
for k, v in pairs(a) do
if not Table.Compare(v, b[k]) then return false end
end
return true
else
return a == b
end
end
exports("Table", Table) exports("Table", Table)
return Table return Table
+93
View File
@@ -5,6 +5,8 @@ Clothing = Clothing or {}
ClothingBackup = {} ClothingBackup = {}
Callback = Callback or Require("lib/utility/shared/callbacks.lua") Callback = Callback or Require("lib/utility/shared/callbacks.lua")
Ultility = Utility or Require('lib/utility/client/utility.lua') Ultility = Utility or Require('lib/utility/client/utility.lua')
Cache = Cache or Require('lib/cache/shared/cache.lua')
function Clothing.IsMale() function Clothing.IsMale()
local ped = PlayerPedId() local ped = PlayerPedId()
@@ -75,6 +77,95 @@ Clothing.UpdateAppearanceBackup = function(data)
ClothingBackup = data ClothingBackup = data
end end
Clothing.RunningDebug = false
Clothing.Cache = nil -- maybe change this to the actual cache system???!? For future not lazy me
Cache.Create('Clothing', function()
local ped = Cache.Get('Ped')
local appearance = Clothing.GetAppearance(ped)
if Table.Compare(Clothing.Cache, appearance) then
return false
end
return appearance
end, 1000)
local onChange = nil
Clothing.ToggleDebugging = function()
if Clothing.RunningDebug then
Clothing.RunningDebug = false
print("Clothing Debugging Disabled")
return Cache.RemoveOnChange('Clothing', onChange)
end
Clothing.RunningDebug = true
print("Clothing Debugging Enabled")
if Clothing.OpenMenu then
Clothing.OpenMenu()
end
onChange = Cache.OnChange('Clothing', function(new, old)
print("Clothing Debugging", new)
for k, v in pairs(old.components) do
if v.component_id then
if new.components[k].drawable ~= v.drawable or new.components[k].texture ~= v.texture then
print("Component ID: " .. v.component_id .. " Drawable: " .. new.components[k].drawable .. " Texture: " .. new.components[k].texture)
end
end
end
for k, v in pairs(old.props) do
if v.prop_id then
if new.props[k].drawable ~= v.drawable or new.props[k].texture ~= v.texture then
print("Prop ID: " .. v.prop_id .. " Drawable: " .. new.props[k].drawable .. " Texture: " .. new.props[k].texture)
end
end
end
end)
-- CreateThread(function()
-- while Clothing.RunningDebug do
-- Wait(3)
-- local ped = PlayerPedId()
-- if ped then
-- if not Clothing.Cache then
-- Clothing.Cache = Clothing.GetAppearance(ped)
-- end
-- for k, v in pairs(Clothing.Cache.components) do
-- if v.component_id then
-- local drawable = GetPedDrawableVariation(ped, v.component_id)
-- local texture = GetPedTextureVariation(ped, v.component_id)
-- if drawable ~= v.drawable or texture ~= v.texture then
-- print("Component ID: " .. v.component_id .. " Drawable: " .. drawable .. " Texture: " .. texture)
-- Clothing.Cache.components[k].drawable = drawable
-- Clothing.Cache.components[k].texture = texture
-- end
-- end
-- end
-- for k, v in pairs(Clothing.Cache.props) do
-- if v.prop_id then
-- local drawable = GetPedPropIndex(ped, v.prop_id)
-- local texture = GetPedPropTextureIndex(ped, v.prop_id)
-- if drawable ~= v.drawable or texture ~= v.texture then
-- print("Prop ID: " .. v.prop_id .. " Drawable: " .. drawable .. " Texture: " .. texture)
-- Clothing.Cache.props[k].drawable = drawable
-- Clothing.Cache.props[k].texture = texture
-- end
-- end
-- end
-- end
-- -- esc key to exit
-- if IsControlJustPressed(0, 177) then
-- Clothing.RunningDebug = false
-- print("Clothing Debugging Disabled")
-- end
-- end
-- Clothing.Cache = nil
-- end)
end
RegisterCommand("clothing:enabledebug", function(source, args, rawCommand)
Clothing.ToggleDebugging()
end)
RegisterNetEvent('community_bridge:client:SetAppearance', function(data) RegisterNetEvent('community_bridge:client:SetAppearance', function(data)
Clothing.SetAppearance(PlayerPedId(), data) Clothing.SetAppearance(PlayerPedId(), data)
end) end)
@@ -91,4 +182,6 @@ RegisterCommand("clothing:copy", function(source, args, rawCommand)
Clothing.CopyAppearanceToClipboard() Clothing.CopyAppearanceToClipboard()
end) end)
return Clothing return Clothing
+1 -1
View File
@@ -135,7 +135,7 @@ end
-- @param shopInventory table -- @param shopInventory table
-- @param shopCoords table -- @param shopCoords table
-- @param shopGroups table -- @param shopGroups table
Inventory.CreateShop = function(shopTitle, shopInventory, shopCoords, shopGroups) Inventory.RegisterShop = function(shopTitle, shopInventory, shopCoords, shopGroups)
return false, Prints.Error("This Inventory Has Not Been Bridged For A CreateShop Feature.") return false, Prints.Error("This Inventory Has Not Been Bridged For A CreateShop Feature.")
end end
+1 -1
View File
@@ -186,7 +186,7 @@ end
-- @param shopInventory table -- @param shopInventory table
-- @param shopCoords table -- @param shopCoords table
-- @param shopGroups table -- @param shopGroups table
Inventory.CreateShop = function(shopTitle, shopInventory, shopCoords, shopGroups) Inventory.RegisterShop = function(shopTitle, shopInventory, shopCoords, shopGroups)
return true, print("Unable to Create Shop for codem-inventory, I do not have access to a copy of this inventory to bridge the feature.") return true, print("Unable to Create Shop for codem-inventory, I do not have access to a copy of this inventory to bridge the feature.")
end end
+1 -1
View File
@@ -244,7 +244,7 @@ end
-- @param shopInventory table -- @param shopInventory table
-- @param shopCoords table -- @param shopCoords table
-- @param shopGroups table -- @param shopGroups table
Inventory.CreateShop = function(shopTitle, shopInventory, shopCoords, shopGroups) Inventory.RegisterShop = function(shopTitle, shopInventory, shopCoords, shopGroups)
return false, print("Unable to open shop for core_inventory, I do not have access to a copy of this inventory to bridge the feature.") return false, print("Unable to open shop for core_inventory, I do not have access to a copy of this inventory to bridge the feature.")
end end
+3 -1
View File
@@ -77,6 +77,8 @@ Inventory.OpenStash = function(src, id)
TriggerClientEvent('community_bridge:client:jpr-inventory:openStash', src, id, { weight = stash.weight, slots = stash.slots }) TriggerClientEvent('community_bridge:client:jpr-inventory:openStash', src, id, { weight = stash.weight, slots = stash.slots })
end end
---This will register a stash ---This will register a stash
---@param id number||string ---@param id number||string
---@param label string ---@param label string
@@ -154,7 +156,7 @@ end
-- @param shopInventory table -- @param shopInventory table
-- @param shopCoords table -- @param shopCoords table
-- @param shopGroups table -- @param shopGroups table
Inventory.CreateShop = function(shopTitle, shopInventory, shopCoords, shopGroups) Inventory.RegisterShop = function(shopTitle, shopInventory, shopCoords, shopGroups)
if not shopTitle or not shopInventory or not shopCoords then return end if not shopTitle or not shopInventory or not shopCoords then return end
if registeredShops[shopTitle] then return true end if registeredShops[shopTitle] then return true end
@@ -191,7 +191,7 @@ end
-- @param shopInventory table -- @param shopInventory table
-- @param shopCoords table -- @param shopCoords table
-- @param shopGroups table -- @param shopGroups table
Inventory.CreateShop = function(shopTitle, shopInventory, shopCoords, shopGroups) Inventory.RegisterShop = function(shopTitle, shopInventory, shopCoords, shopGroups)
return true, print("Currently runtime shops are not supported in origen_inventory") return true, print("Currently runtime shops are not supported in origen_inventory")
end end
+1 -1
View File
@@ -171,7 +171,7 @@ end
-- @param shopInventory table -- @param shopInventory table
-- @param shopCoords table -- @param shopCoords table
-- @param shopGroups table -- @param shopGroups table
Inventory.CreateShop = function(shopTitle, shopInventory, shopCoords, shopGroups) Inventory.RegisterShop = function(shopTitle, shopInventory, shopCoords, shopGroups)
if registeredShops[shopTitle] then return true end if registeredShops[shopTitle] then return true end
registeredShops[shopTitle] = true registeredShops[shopTitle] = true
ox_inventory:RegisterShop(shopTitle, { name = shopTitle, inventory = shopInventory, groups = shopGroups, }) ox_inventory:RegisterShop(shopTitle, { name = shopTitle, inventory = shopInventory, groups = shopGroups, })
+1 -1
View File
@@ -174,7 +174,7 @@ end
-- @param shopInventory table -- @param shopInventory table
-- @param shopCoords table -- @param shopCoords table
-- @param shopGroups table -- @param shopGroups table
Inventory.CreateShop = function(src, shopTitle, shopInventory, shopCoords, shopGroups) Inventory.RegisterShop = function(src, shopTitle, shopInventory, shopCoords, shopGroups)
if not shopTitle or not shopInventory or not shopCoords then return end if not shopTitle or not shopInventory or not shopCoords then return end
if registeredShops[shopTitle] then return true end if registeredShops[shopTitle] then return true end
+1 -1
View File
@@ -196,7 +196,7 @@ end
-- @param shopInventory table -- @param shopInventory table
-- @param shopCoords table -- @param shopCoords table
-- @param shopGroups table -- @param shopGroups table
Inventory.CreateShop = function(shopTitle, shopInventory, shopCoords, shopGroups) Inventory.RegisterShop = function(shopTitle, shopInventory, shopCoords, shopGroups)
if not shopTitle or not shopInventory then return end if not shopTitle or not shopInventory then return end
if registeredShops[shopTitle] then return true end if registeredShops[shopTitle] then return true end
registeredShops[shopTitle] = true registeredShops[shopTitle] = true
+1 -1
View File
@@ -197,7 +197,7 @@ end
-- @param shopInventory table -- @param shopInventory table
-- @param shopCoords table -- @param shopCoords table
-- @param shopGroups table -- @param shopGroups table
Inventory.CreateShop = function(shopTitle, shopInventory, shopCoords, shopGroups) Inventory.RegisterShop = function(shopTitle, shopInventory, shopCoords, shopGroups)
return false, print("Currently qs shop is not bridged") return false, print("Currently qs shop is not bridged")
end end
@@ -186,7 +186,7 @@ end
-- @param shopInventory table -- @param shopInventory table
-- @param shopCoords table -- @param shopCoords table
-- @param shopGroups table -- @param shopGroups table
Inventory.CreateShop = function(shopTitle, shopInventory, shopCoords, shopGroups) Inventory.RegisterShop = function(shopTitle, shopInventory, shopCoords, shopGroups)
return false, print("Currently tgiann-inventory is not bridged for shops") return false, print("Currently tgiann-inventory is not bridged for shops")
end end