Module:ItemData: Difference between revisions

Jump to navigation Jump to search
LVL (talk | contribs)
Added most item stats that I know are percentages. Could be some others missing though.
LVL (talk | contribs)
Improved item lookup logic to prioritize active items, fixing issues with disabled duplicate entries.
Line 96: Line 96:
---------------------------------------- Utility functions
---------------------------------------- Utility functions


-- Returns the table of a specific item
-- Returns the table of a specific item.
-- Prioritizes active (non-disabled) items if multiple entries share the same name.
-- @function  get_json_item
-- @function  get_json_item
-- @param      {string}
-- @param      {string}
-- @return    {table}
-- @return    {table}
local function get_json_item(name)  
local function get_json_item(name)
-- First, try to find an active item. This handles cases where a disabled item
-- with the same name exists in the data (e.g., old versions).
for _, v in pairs(data) do
if (v["Name"] == name and (v["IsDisabled"] == false or v["IsDisabled"] == nil)) then
return v -- Return the active item immediately
end
end
 
-- If no active item was found, fall back to finding any item with the name.
-- This preserves functionality for items that are intentionally disabled.
for _, v in pairs(data) do
for _, v in pairs(data) do
if (v["Name"] == name) then
if (v["Name"] == name) then
Line 106: Line 117:
end
end
end
end
return nil
return nil -- Return nil if no item was found at all
end
end


Line 298: Line 310:
end
end


--get codename of the item--
   
-- Gets the codename (the key in the JSON data) for a given item's display name.
-- Prioritizes active items to handle cases where disabled duplicates exist.
p.get_codename = function(frame)
p.get_codename = function(frame)
local name = frame.args[1]
local name = frame.args[1]
-- Exception for "Extended Magazine"
    if name == "Extended Magazine" then
-- First, try to find an active item.
        return "upgrade_clip_size"
for k, v in pairs(data) do
    end
if (v["Name"] == name and (v["IsDisabled"] == false or v["IsDisabled"] == nil)) then
 
return k -- Return the codename of the active item
end
end
-- If no active item was found, fall back to finding any item with the name.
for k, v in pairs(data) do
for k, v in pairs(data) do
if v["Name"] == name then
if (v["Name"] == name) then
return k -- returning the key (i.e., name of the table entry)
return k
end
end
end
end
return nil -- return nil if not found
return nil -- Return nil if no item was found at all
end
end
 


return p
return p