Module:Infobox Item
Jump to navigation
Jump to search
local p = {} local data_module_names = { itemData = 'Module:Items/data' } local loaded_data_modules = {} function p.loadItem (name, data_type) local module_name = data_module_names[data_type] if loaded_data_modules[module_name] == nil then loaded_data_modules[module_name] = mw.loadData(module_name) end for key, item in pairs(loaded_data_modules[module_name]) do if name == item["name"] then return item end end return 0 end function p.addSeparator(num) return tostring(num):reverse():gsub("(%d%d%d)","%1,"):gsub(",(%-?)$","%1"):reverse() end function p.fullUrl(url) local newUrl = "" if url:sub(1,5) ~= "https" then return url end if url:sub(1,1) ~= "/" then newUrl = "/" .. url end newUrl = "https://www.play.idlescape.com" .. newUrl return newUrl end function p.item(frame) local args = frame:getParent().args return p._item(args) end function p._item(args) local name = args[1] local item = 0 local infobox = "" item = p.loadItem (name, 'itemData') infobox = p.createInfobox(item) return infobox end function p.createInfobox(item) local s = "{{Infobox Item\n" local url = "" s = s .. "|title = {{PAGENAME}}\n" if item["itemIcon"] then url = item["itemIcon"] else url = item["itemImage"] end s = s .. "|image =" .. p.fullUrl(url) .. "\n" if item["value"] then s = s .. "|gold =" .. p.addSeparator(tonumber(item["value"])) .. "\n" end if item["craftable"] then s = s .. "|source = [[Crafting]]\n" end if item["requiredLevel"] then s = s .. "|level-req =" for skill, level in pairs(item["requiredLevel"]) do s = s .. level .. " " .. skill .. "\n" end end if item["heat"] then s = s .. "|heat =" .. p.addSeparator(tonumber(item["heat"])) .. "\n" end if item["size"] then s = s .. "|food-size =" .. item["size"] .. "\n" end if item["ingredientTags"] then s = s .. "|food-cat =" for key, tag in pairs(item["ingredientTags"]) do s = s .. tag .. "\n" end end return s end return p