Module:ItemData: Difference between revisions

added spirit scaling function (WIP)
added raw variable to get_type for non-localized item_type return
Line 55: Line 55:
-- @param      {string}
-- @param      {string}
-- @return    {string}
-- @return    {string}
local function get_type(item_name)
--- Get type/slot/category of an item
-- @function  get_type
-- @param      {string} item_name
-- @param      {boolean} raw (optional)
-- @return    {string}
local function get_type(item_name, raw)
local item = get_json_item(item_name)
local item = get_json_item(item_name)
if(item == nil) then return "<span style=\"color:red;\">Item Not Found.</span>" end
if(item == nil) then return "<span style=\"color:red;\">Item Not Found.</span>" end
 
if (item["Slot"] == "Weapon") then
local slot = item["Slot"]
if not slot then return nil end
 
if raw then
-- Return raw slot immediately, skipping localization
return slot
end
 
-- Otherwise, return localized string based on slot value
if (slot == "Weapon") then
return lang.get_string('CitadelCategoryWeapon')
return lang.get_string('CitadelCategoryWeapon')
elseif (item["Slot"] == "Armor") then
elseif (slot == "Armor") then
return lang.get_string('CitadelCategoryArmor')
return lang.get_string('CitadelCategoryArmor')
elseif (item["Slot"] == "Tech") then
elseif (slot == "Tech") then
return lang.get_string('CitadelCategoryTech')
return lang.get_string('CitadelCategoryTech')
else  
else  
return nil
return nil
end
end
end


end


---------------------------------------- Invocable functions
---------------------------------------- Invocable functions
Line 88: Line 103:
p.get_type = function(frame)
p.get_type = function(frame)
local item_name = frame.args[1]
local item_name = frame.args[1]
return get_type(item_name)
-- Accept 'raw' as string "true" (case sensitive)
local raw = frame.args['raw'] == 'true'
return get_type(item_name, raw)
end
end