image pathing fixed on tgiann

this -- "nui://inventory_images/html/images/%s.png"
Is not the path, it its instead
nui://inventory_images/images/%s.png"

Also strip webp function added. And indexing itemdata was required.
This commit is contained in:
MrNewb committed 2025-08-03 16:23:19 -04:00
1 parent fa9ea6e6eb
commit 5abebe13c6
4 files changed
+30 -10

No files matched your search

+8
View File
@@ -36,6 +36,10 @@ Inventory.GetImagePath = function(item)
return "https://avatars.githubusercontent.com/u/47620135"
end
---This will remove the file extension from the item name if present.
---example: "item.png" will become "item"
---@param item string
---@return string
Inventory.StripPNG = function(item)
if string.find(item, ".png") then
item = string.gsub(item, ".png", "")
@@ -43,6 +47,10 @@ Inventory.StripPNG = function(item)
return item
end
---This will remove the file extension from the item name if present.
---example: "item.webp" will become "item"
---@param item string
---@return string
Inventory.StripWebp = function(item)
if string.find(item, ".webp") then
item = string.gsub(item, ".webp", "")
+11
View File
@@ -193,6 +193,17 @@ Inventory.StripPNG = function(item)
return item
end
---This will remove the file extension from the item name if present.
---example: "item.webp" will become "item"
---@param item string
---@return string
Inventory.StripWebp = function(item)
if string.find(item, ".webp") then
item = string.gsub(item, ".webp", "")
end
return item
end
Inventory.OpenPlayerInventory = function(src, targetSrc)
return false, Prints.Error("OpenPlayerInventory is not implemented in this inventory, because of this we dont have a way to open a players inventory.")
end
@@ -10,13 +10,14 @@ Inventory = Inventory or {}
Inventory.GetItemInfo = function(item)
local itemData = tgiann:GetItemList()
if not itemData[item] then return {} end
itemData = itemData[item]
return {
name = itemData.name or "Missing Name",
label = itemData.label or "Missing Label",
stack = itemData.unique or "false",
weight = itemData.weight or "0",
description = itemData.description or "none",
image = itemData.image or Inventory.GetImagePath(item),
image = Inventory.GetImagePath(item),
}
end
@@ -41,9 +42,9 @@ end
Inventory.GetImagePath = function(item)
local pngItem = Inventory.StripPNG(item)
local webpItem = Inventory.StripWebp(item)
local pngPath = LoadResourceFile("inventory_images", string.format("html/images/%s.png", pngItem))
local webpPath = LoadResourceFile("inventory_images", string.format("html/images/%s.webp", webpItem))
local imagePath = pngPath and string.format("nui://inventory_images/html/images/%s.png", pngItem) or webpPath and string.format("nui://inventory_images/html/images/%s.webp", webpItem)
local pngPath = LoadResourceFile("inventory_images", string.format("/images/%s.png", pngItem))
local webpPath = LoadResourceFile("inventory_images", string.format("/images/%s.webp", webpItem))
local imagePath = pngPath and string.format("nui://inventory_images/images/%s.png", pngItem) or webpPath and string.format("nui://inventory_images/images/%s.webp", webpItem)
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
end
@@ -200,18 +200,18 @@ Inventory.ClearStash = function(id, _type)
return true
end
---This will get the image path for an item, it is an alternate option to GetItemInfo. If a image isnt found will revert to community_bridge logo (useful for menus)
---This will get the image path for this item, if not found will return placeholder.
---@param item string
---@return string
Inventory.GetImagePath = function(item)
item = Inventory.StripPNG(item)
local pngPath = LoadResourceFile("inventory_images", string.format("html/images/%s.png", item))
local webpPath = LoadResourceFile("inventory_images", string.format("html/images/%s.webp", item))
local imagePath = pngPath and string.format("nui://inventory_images/html/images/%s.png", item) or webpPath and string.format("nui://inventory_images/html/images/%s.webp", item)
local pngItem = Inventory.StripPNG(item)
local webpItem = Inventory.StripWebp(item)
local pngPath = LoadResourceFile("inventory_images", string.format("/images/%s.png", pngItem))
local webpPath = LoadResourceFile("inventory_images", string.format("/images/%s.webp", webpItem))
local imagePath = pngPath and string.format("nui://inventory_images/images/%s.png", pngItem) or webpPath and string.format("nui://inventory_images/images/%s.webp", webpItem)
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
end
---UNUSED:
---This will return generic item data from the specified inventory, with the items total count.
---