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:
1 parent
fa9ea6e6eb
commit
5abebe13c6
4 files changed
+30
-10
No files matched your search
@@ -36,6 +36,10 @@ Inventory.GetImagePath = function(item)
|
|||||||
return "https://avatars.githubusercontent.com/u/47620135"
|
return "https://avatars.githubusercontent.com/u/47620135"
|
||||||
end
|
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)
|
Inventory.StripPNG = function(item)
|
||||||
if string.find(item, ".png") then
|
if string.find(item, ".png") then
|
||||||
item = string.gsub(item, ".png", "")
|
item = string.gsub(item, ".png", "")
|
||||||
@@ -43,6 +47,10 @@ Inventory.StripPNG = function(item)
|
|||||||
return item
|
return item
|
||||||
end
|
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)
|
Inventory.StripWebp = function(item)
|
||||||
if string.find(item, ".webp") then
|
if string.find(item, ".webp") then
|
||||||
item = string.gsub(item, ".webp", "")
|
item = string.gsub(item, ".webp", "")
|
||||||
|
|||||||
@@ -193,6 +193,17 @@ Inventory.StripPNG = function(item)
|
|||||||
return item
|
return item
|
||||||
end
|
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)
|
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.")
|
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
|
end
|
||||||
|
|||||||
@@ -10,13 +10,14 @@ Inventory = Inventory or {}
|
|||||||
Inventory.GetItemInfo = function(item)
|
Inventory.GetItemInfo = function(item)
|
||||||
local itemData = tgiann:GetItemList()
|
local itemData = tgiann:GetItemList()
|
||||||
if not itemData[item] then return {} end
|
if not itemData[item] then return {} end
|
||||||
|
itemData = itemData[item]
|
||||||
return {
|
return {
|
||||||
name = itemData.name or "Missing Name",
|
name = itemData.name or "Missing Name",
|
||||||
label = itemData.label or "Missing Label",
|
label = itemData.label or "Missing Label",
|
||||||
stack = itemData.unique or "false",
|
stack = itemData.unique or "false",
|
||||||
weight = itemData.weight or "0",
|
weight = itemData.weight or "0",
|
||||||
description = itemData.description or "none",
|
description = itemData.description or "none",
|
||||||
image = itemData.image or Inventory.GetImagePath(item),
|
image = Inventory.GetImagePath(item),
|
||||||
}
|
}
|
||||||
end
|
end
|
||||||
|
|
||||||
@@ -41,9 +42,9 @@ end
|
|||||||
Inventory.GetImagePath = function(item)
|
Inventory.GetImagePath = function(item)
|
||||||
local pngItem = Inventory.StripPNG(item)
|
local pngItem = Inventory.StripPNG(item)
|
||||||
local webpItem = Inventory.StripWebp(item)
|
local webpItem = Inventory.StripWebp(item)
|
||||||
local pngPath = LoadResourceFile("inventory_images", string.format("html/images/%s.png", pngItem))
|
local pngPath = LoadResourceFile("inventory_images", string.format("/images/%s.png", pngItem))
|
||||||
local webpPath = LoadResourceFile("inventory_images", string.format("html/images/%s.webp", webpItem))
|
local webpPath = LoadResourceFile("inventory_images", string.format("/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 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"
|
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|||||||
@@ -200,18 +200,18 @@ Inventory.ClearStash = function(id, _type)
|
|||||||
return true
|
return true
|
||||||
end
|
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
|
---@param item string
|
||||||
---@return string
|
---@return string
|
||||||
Inventory.GetImagePath = function(item)
|
Inventory.GetImagePath = function(item)
|
||||||
item = Inventory.StripPNG(item)
|
local pngItem = Inventory.StripPNG(item)
|
||||||
local pngPath = LoadResourceFile("inventory_images", string.format("html/images/%s.png", item))
|
local webpItem = Inventory.StripWebp(item)
|
||||||
local webpPath = LoadResourceFile("inventory_images", string.format("html/images/%s.webp", item))
|
local pngPath = LoadResourceFile("inventory_images", string.format("/images/%s.png", pngItem))
|
||||||
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 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"
|
return imagePath or "https://avatars.githubusercontent.com/u/47620135"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
---UNUSED:
|
---UNUSED:
|
||||||
---This will return generic item data from the specified inventory, with the items total count.
|
---This will return generic item data from the specified inventory, with the items total count.
|
||||||
---
|
---
|
||||||
|
|||||||
Reference in new issue
Block a user