This is busted, should be removed.

Should be removed as not working for external resources.
It will work in the bridge itself but could lead to bloat/misuse and we shouldn't be responsible.
This commit is contained in:
MrNewb committed 2025-08-20 16:59:04 -04:00
1 parent 75f431e3ac
commit 718214d135
1 file changed
+105 -105
+105 -105
View File
@@ -1,117 +1,117 @@
ItemsBuilder = ItemsBuilder or {} -- ItemsBuilder = ItemsBuilder or {}
ItemsBuilder = {} -- ItemsBuilder = {}
---This will generate the items in the formats of qb_core, qb_core_old and ox_inventory. It will then build a lua file in the generateditems folder of the community_bridge. -- ---This will generate the items in the formats of qb_core, qb_core_old and ox_inventory. It will then build a lua file in the generateditems folder of the community_bridge.
---@param invoking string -- ---@param invoking string
---@param itemsTable table -- ---@param itemsTable table
ItemsBuilder.Generate = function(invoking, outputPrefix, itemsTable, useQB) -- ItemsBuilder.Generate = function(invoking, outputPrefix, itemsTable, useQB)
if not itemsTable then return end -- if not itemsTable then return end
invoking = invoking or GetInvokingResource() or GetCurrentResourceName() or "community_bridge" -- invoking = invoking or GetInvokingResource() or GetCurrentResourceName() or "community_bridge"
local resourcePath = string.format("%s/%s/", GetResourcePath(invoking), outputPrefix or "generated_items") -- local resourcePath = string.format("%s/%s/", GetResourcePath(invoking), outputPrefix or "generated_items")
-- remove any doubles slashes after initial double slash -- -- remove any doubles slashes after initial double slash
-- resourcePath = resourcePath:gsub("//", "/") -- -- resourcePath = resourcePath:gsub("//", "/")
-- check if directory exists -- -- check if directory exists
local folder = io.open(resourcePath, "r") -- local folder = io.open(resourcePath, "r")
if not folder then -- if not folder then
local createDirectoryCMD = string.format("if not exist \"%s\" mkdir \"%s\"", resourcePath, resourcePath) -- local createDirectoryCMD = string.format("if not exist \"%s\" mkdir \"%s\"", resourcePath, resourcePath)
local returned, err = io.popen(createDirectoryCMD) -- local returned, err = io.popen(createDirectoryCMD)
if not returned then -- if not returned then
print("🌮 Failed to create directory: ", err) -- print("🌮 Failed to create directory: ", err)
return -- return
end -- end
returned:close() -- returned:close()
print("🌮 Created Directory: ", resourcePath) -- print("🌮 Created Directory: ", resourcePath)
else -- else
folder:close() -- folder:close()
end -- end
local qbOld = {} -- local qbOld = {}
local qbNew = {} -- local qbNew = {}
local oxInventory = {} -- local oxInventory = {}
if useQB then -- if useQB then
for key, item in pairs(itemsTable) do -- for key, item in pairs(itemsTable) do
qbOld[key] = string.format( -- qbOld[key] = string.format(
"['%s'] = {name = '%s', label = '%s', weight = %s, type = 'item', image = '%s', unique = %s, useable = %s, shouldClose = %s, description = '%s'},", -- "['%s'] = {name = '%s', label = '%s', weight = %s, type = 'item', image = '%s', unique = %s, useable = %s, shouldClose = %s, description = '%s'},",
key, key, item.label, item.weight, item.image or key .. 'png', item.unique, item.useable, item.shouldClose, item.description -- key, key, item.label, item.weight, item.image or key .. 'png', item.unique, item.useable, item.shouldClose, item.description
) -- )
qbNew[key] = string.format( -- qbNew[key] = string.format(
"['%s'] = {['name'] = '%s', ['label'] = '%s', ['weight'] = %s, ['type'] = 'item',['image'] = '%s', ['unique'] = %s, ['useable'] = %s, ['shouldClose'] = %s, ['description'] = '%s'},", -- "['%s'] = {['name'] = '%s', ['label'] = '%s', ['weight'] = %s, ['type'] = 'item',['image'] = '%s', ['unique'] = %s, ['useable'] = %s, ['shouldClose'] = %s, ['description'] = '%s'},",
key, key, item.label, item.weight, item.image or key .. 'png', item.unique, item.useable, item.shouldClose, item.description -- key, key, item.label, item.weight, item.image or key .. 'png', item.unique, item.useable, item.shouldClose, item.description
) -- )
imagewithoutpng = item?.image and item.image:gsub(".png", "") -- imagewithoutpng = item?.image and item.image:gsub(".png", "")
shouldRenderImage = imagewithoutpng and imagewithoutpng ~= key -- shouldRenderImage = imagewithoutpng and imagewithoutpng ~= key
oxInventory[key] = string.format( -- oxInventory[key] = string.format(
[[ -- [[
["%s"] = { -- ["%s"] = {
label = "%s", -- label = "%s",
description = "%s", -- description = "%s",
weight = %s, -- weight = %s,
stack = %s, -- stack = %s,
close = %s, -- close = %s,
%s -- %s
}, ]], -- }, ]],
key, item.label, item.description, item.weight, not item.unique, item.shouldClose, -- key, item.label, item.description, item.weight, not item.unique, item.shouldClose,
shouldRenderImage and item.image and string.format([[client = { -- shouldRenderImage and item.image and string.format([[client = {
image = '%s' -- image = '%s'
}]], item.image) or "" -- }]], item.image) or ""
) -- )
end -- end
else -- else
for key, item in pairs(itemsTable) do -- for key, item in pairs(itemsTable) do
-- ['peanut_butter'] = {['name'] = 'peanut_butter',['label'] = 'Peanut Butter',['weight'] = 1000,['type'] = 'item',['image'] = 'peanut_butter.png',['unique'] = false,['useable'] = false,['shouldClose'] = true,['combinable'] = nil,['description'] = 'A cooking ingredient'}, -- -- ['peanut_butter'] = {['name'] = 'peanut_butter',['label'] = 'Peanut Butter',['weight'] = 1000,['type'] = 'item',['image'] = 'peanut_butter.png',['unique'] = false,['useable'] = false,['shouldClose'] = true,['combinable'] = nil,['description'] = 'A cooking ingredient'},
qbOld[key] = string.format( -- qbOld[key] = string.format(
"['%s'] = {name = '%s', label = '%s', weight = %s, type = 'item', image = '%s', unique = %s, useable = %s, shouldClose = %s, description = '%s'},", -- "['%s'] = {name = '%s', label = '%s', weight = %s, type = 'item', image = '%s', unique = %s, useable = %s, shouldClose = %s, description = '%s'},",
key, key, item.label, item.weight, item?.client?.image or key .. 'png', not item.stack, true, item.close, item.description -- key, key, item.label, item.weight, item?.client?.image or key .. 'png', not item.stack, true, item.close, item.description
) -- )
qbNew[key] = string.format( -- qbNew[key] = string.format(
"['%s'] = {['name'] = '%s', ['label'] = '%s', ['weight'] = %s, ['type'] = 'item', ['image'] = '%s', ['unique'] = %s, ['useable'] = %s, ['shouldClose'] = %s, ['description'] = '%s'},", -- "['%s'] = {['name'] = '%s', ['label'] = '%s', ['weight'] = %s, ['type'] = 'item', ['image'] = '%s', ['unique'] = %s, ['useable'] = %s, ['shouldClose'] = %s, ['description'] = '%s'},",
key, key, item.label, item.weight, item?.client?.image or key .. 'png', not item.stack, true, item.close, item.description -- key, key, item.label, item.weight, item?.client?.image or key .. 'png', not item.stack, true, item.close, item.description
) -- )
imagewithoutpng = item?.client?.image and item.client.image:gsub(".png", "") -- imagewithoutpng = item?.client?.image and item.client.image:gsub(".png", "")
shouldRenderImage = imagewithoutpng and imagewithoutpng ~= key -- shouldRenderImage = imagewithoutpng and imagewithoutpng ~= key
oxInventory[key] = string.format( -- oxInventory[key] = string.format(
[[ -- [[
["%s"] = { -- ["%s"] = {
label = "%s", -- label = "%s",
description = "%s", -- description = "%s",
weight = %s, -- weight = %s,
stack = %s, -- stack = %s,
close = %s, -- close = %s,
%s -- %s
}, ]], -- }, ]],
key, item.label, item.description, item.weight, item.stack, item.close, -- key, item.label, item.description, item.weight, item.stack, item.close,
shouldRenderImage and item?.client?.image and string.format( [[client = { -- shouldRenderImage and item?.client?.image and string.format( [[client = {
image = '%s' -- image = '%s'
}]], item.client.image) or "" -- }]], item.client.image) or ""
) -- )
end -- end
end -- end
local function write(fileName, content) -- local function write(fileName, content)
local filePath = resourcePath .. fileName -- local filePath = resourcePath .. fileName
local file = io.open(filePath, "w") -- local file = io.open(filePath, "w")
if file then -- if file then
for key, value in pairs(content) do -- for key, value in pairs(content) do
file:write(string.format("%s\n", value)) -- file:write(string.format("%s\n", value))
end -- end
file:close() -- file:close()
print("🌮 Items File Created: " .. filePath) -- print("🌮 Items File Created: " .. filePath)
else -- else
print("🌮 Something Broke for: " .. filePath) -- print("🌮 Something Broke for: " .. filePath)
end -- end
end -- end
write(invoking.."(".."qb_core_old).lua", qbOld) -- write(invoking.."(".."qb_core_old).lua", qbOld)
write(invoking.."(".."qb_core_new).lua", qbNew) -- write(invoking.."(".."qb_core_new).lua", qbNew)
write(invoking.."(".."ox_inventory).lua", oxInventory) -- write(invoking.."(".."ox_inventory).lua", oxInventory)
end -- end
exports('ItemsBuilder', ItemsBuilder) -- exports('ItemsBuilder', ItemsBuilder)
return ItemsBuilder -- return ItemsBuilder