Anonymous

Module:Items: Difference between revisions

From Melvor Idle
269 bytes removed ,  3 February 2022
Don't clone items, as all items have IDs from game data anyway (and hope nowhere else is attempting to modify them)
m (Accidental reversion, oops)
(Don't clone items, as all items have IDs from game data anyway (and hope nowhere else is attempting to modify them))
Line 68: Line 68:


function p.getItemByID(ID)
function p.getItemByID(ID)
local result = Shared.clone(ItemData.Items[ID + 1])
return ItemData.Items[ID + 1]
if result ~= nil then
result.id = ID
end
return result
end
end


function p.getItem(name)
function p.getItem(name)
local result = nil
name = string.gsub(name, "%%27", "'")
name = string.gsub(name, "%%27", "'")
name = string.gsub(name, "'", "'")
name = string.gsub(name, "'", "'")
Line 82: Line 77:
local itemName = string.gsub(item.name, '#', '')
local itemName = string.gsub(item.name, '#', '')
if name == itemName then
if name == itemName then
result = Shared.clone(item)
return p.getItemByID(i - 1)
--Make sure every item has an id, and account for Lua being 1-index
result.id = i - 1
break
end
end
end
end
return result
return nil
end
end


Line 95: Line 87:
for i, item in pairs(ItemData.Items) do
for i, item in pairs(ItemData.Items) do
if checkFunc(item) then
if checkFunc(item) then
local newItem = Shared.clone(item)
table.insert(result, item)
newItem.id = i - 1
table.insert(result, newItem)
end
end
end
end