Difference between revisions of "Module:Silent1/sandbox"

From Idlescape Wiki
Jump to navigation Jump to search
m
m
 
(42 intermediate revisions by the same user not shown)
Line 1: Line 1:
 
local p = {}
 
local p = {}
local args = {}
 
local origArgs = {}
 
local root
 
local side
 
local rowh
 
local rowd
 
local empty_row_categories = {}
 
local category_in_empty_row_pattern = '%[%[%s*[Cc][Aa][Tt][Ee][Gg][Oo][Rr][Yy]%s*:[^]]*]]'
 
local has_rows = false
 
  
local function fixChildBoxes(sval, tt)
+
local data_module_names = {
local function notempty( s ) return s and s:match( '%S' ) end
+
item = 'Module:Items/data',
+
enchantment = 'Module:Enchantment/data',
if notempty(sval) then
+
location = 'Module:Location/data',
local marker = '<span class=special_infobox_marker>'
+
craftaug = 'Module:CraftingAugmenting/data',
local s = sval
+
farming = 'Module:Farming/data'
-- start moving templatestyles and categories inside of table rows
+
}
local slast = ''
+
 
while slast ~= s do
+
local loaded_data_modules = {}
slast = s
+
 
s = mw.ustring.gsub(s, '(</[Tt][Rr]%s*>%s*)(%[%[%s*[Cc][Aa][Tt][Ee][Gg][Oo][Rr][Yy]%s*:[^]]*%]%])', '%2%1')
+
local headerCount = 1
s = mw.ustring.gsub(s, '(</[Tt][Rr]%s*>%s*)(\127[^\127]*UNIQ%-%-templatestyles%-%x+%-QINU[^\127]*\127)', '%2%1')
+
local labelCount = 1
end
+
local dataCount = 1
-- end moving templatestyles and categories inside of table rows
+
 
s = mw.ustring.gsub(s, '(<%s*[Tt][Rr])', marker .. '%1')
+
local function h()
s = mw.ustring.gsub(s, '(</[Tt][Rr]%s*>)', '%1' .. marker)
+
local s = "header" .. headerCount
if s:match(marker) then
+
headerCount = headerCount + 1
s = mw.ustring.gsub(s, marker .. '%s*' .. marker, '')
+
labelCount = headerCount
s = mw.ustring.gsub(s, '([\r\n]|-[^\r\n]*[\r\n])%s*' .. marker, '%1')
+
dataCount = headerCount
s = mw.ustring.gsub(s, marker .. '%s*([\r\n]|-)', '%1')
+
return s
s = mw.ustring.gsub(s, '(</[Cc][Aa][Pp][Tt][Ii][Oo][Nn]%s*>%s*)' .. marker, '%1')
 
s = mw.ustring.gsub(s, '(<%s*[Tt][Aa][Bb][Ll][Ee][^<>]*>%s*)' .. marker, '%1')
 
s = mw.ustring.gsub(s, '^(%{|[^\r\n]*[\r\n]%s*)' .. marker, '%1')
 
s = mw.ustring.gsub(s, '([\r\n]%{|[^\r\n]*[\r\n]%s*)' .. marker, '%1')
 
s = mw.ustring.gsub(s, marker .. '(%s*</[Tt][Aa][Bb][Ll][Ee]%s*>)', '%1')
 
s = mw.ustring.gsub(s, marker .. '(%s*\n|%})', '%1')
 
end
 
if s:match(marker) then
 
local subcells = mw.text.split(s, marker)
 
s = ''
 
for k = 1, #subcells do
 
if k == 1 then
 
s = s .. subcells[k] .. '</' .. tt .. '></tr>'
 
elseif k == #subcells then
 
local rowstyle = ' style="display:none"'
 
if notempty(subcells[k]) then rowstyle = '' end
 
s = s .. '<tr' .. rowstyle ..'><' .. tt .. ' colspan=2>\n' ..
 
subcells[k]
 
elseif notempty(subcells[k]) then
 
if (k % 2) == 0 then
 
s = s .. subcells[k]
 
else
 
s = s .. '<tr><' .. tt .. ' colspan=2>\n' ..
 
subcells[k] .. '</' .. tt .. '></tr>'
 
end
 
end
 
end
 
end
 
-- the next two lines add a newline at the end of lists for the PHP parser
 
-- [[Special:Diff/849054481]]
 
-- remove when [[:phab:T191516]] is fixed or OBE
 
s = mw.ustring.gsub(s, '([\r\n][%*#;:][^\r\n]*)$', '%1\n')
 
s = mw.ustring.gsub(s, '^([%*#;:][^\r\n]*)$', '%1\n')
 
s = mw.ustring.gsub(s, '^([%*#;:])', '\n%1')
 
s = mw.ustring.gsub(s, '^(%{%|)', '\n%1')
 
return s
 
else
 
return sval
 
end
 
 
end
 
end
  
-- Cleans empty tables
+
local function sbreak()
local function cleanInfobox()
+
local s = "sbreak" .. headerCount
root = tostring(root)
+
headerCount = headerCount + 1
if has_rows == false then
+
labelCount = headerCount
root = mw.ustring.gsub(root, '<table[^<>]*>%s*</table>', '')
+
dataCount = headerCount
end
+
return s
 
end
 
end
  
-- Returns the union of the values of two tables, as a sequence.
+
local function l()
local function union(t1, t2)
+
local s = "label" .. labelCount
 +
dataCount = labelCount
 +
labelCount = labelCount + 1
 +
headerCount = labelCount
 +
return s
 +
end
  
local vals = {}
+
local function d()  
for k, v in pairs(t1) do
+
local s = "data" .. dataCount
vals[v] = true
+
dataCount = dataCount + 1
end
+
headerCount = dataCount
for k, v in pairs(t2) do
+
labelCount = dataCount
vals[v] = true
+
return s
end
 
local ret = {}
 
for k, v in pairs(vals) do
 
table.insert(ret, k)
 
end
 
return ret
 
 
end
 
end
  
-- Returns a table containing the numbers of the arguments that exist
+
local function sl()
-- for the specified prefix. For example, if the prefix was 'data', and
+
local s = "s" .. l()
-- 'data1', 'data2', and 'data5' exist, it would return {1, 2, 5}.
+
return s
local function getArgNums(prefix)
 
local nums = {}
 
for k, v in pairs(args) do
 
local num = tostring(k):match('^' .. prefix .. '([1-9]%d*)$')
 
if num then table.insert(nums, tonumber(num)) end
 
end
 
table.sort(nums)
 
return nums
 
 
end
 
end
  
-- Adds a row to the infobox, with either a header cell
+
local function sd()
-- or a label/data cell combination.
+
local s = "s" .. d()
local function addRow(rowArgs)
+
return s
+
end
if rowArgs.header and rowArgs.header ~= '_BLANK_' then
 
has_rows = true
 
root
 
:tag('tr')
 
:addClass(rowArgs.rowclass)
 
:cssText(rowArgs.rowstyle)
 
:tag('th')
 
:attr('colspan', '2')
 
:addClass('infobox-header')
 
:addClass(rowArgs.class)
 
:addClass(args.headerclass)
 
-- @deprecated next; target .infobox-<name> .infobox-header
 
:cssText(args.headerstyle)
 
:cssText(rowArgs.rowcellstyle)
 
:wikitext(fixChildBoxes(rowArgs.header, 'th'))
 
if rowArgs.data then
 
root:wikitext(
 
'[[Category:Pages using infobox templates with ignored data cells]]'
 
)
 
end
 
elseif rowArgs.data and rowArgs.data:gsub(
 
category_in_empty_row_pattern, ''
 
):match('^%S') then
 
has_rows = true
 
local row = root:tag('tr')
 
row:addClass(rowArgs.rowclass)
 
row:cssText(rowArgs.rowstyle)
 
if rowArgs.label then
 
row
 
:tag('th')
 
:attr('scope', 'row')
 
:addClass('infobox-label')
 
-- @deprecated next; target .infobox-<name> .infobox-label
 
:cssText(args.labelstyle)
 
:cssText(rowArgs.rowcellstyle)
 
:wikitext(rowArgs.label)
 
:done()
 
end
 
  
local dataCell = row:tag('td')
+
function p.loadData(data_type)  
dataCell
+
local module_name = data_module_names[data_type]
:attr('colspan', not rowArgs.label and '2' or nil)
+
if loaded_data_modules[module_name] == nil then
:addClass(not rowArgs.label and 'infobox-full-data' or 'infobox-data')
+
loaded_data_modules[module_name] = mw.loadData(module_name)
:addClass(rowArgs.class)
 
-- @deprecated next; target .infobox-<name> .infobox(-full)-data
 
:cssText(rowArgs.datastyle)
 
:cssText(rowArgs.rowcellstyle)
 
:wikitext(fixChildBoxes(rowArgs.data, 'td'))
 
else
 
table.insert(empty_row_categories, rowArgs.data or '')
 
 
end
 
end
 +
 +
return loaded_data_modules[module_name]
 
end
 
end
  
-- Adds a nested table to a row in the infobox, 
+
local function findItem(name)
-- with a label row and a data cell row.
+
local lname = name:lower()
local function addSideRows(rowArgs)
 
--Create references to the new rows
 
if side == nil then
 
local dataCell = root:tag('tr'):tag('td')
 
dataCell
 
:attr('colspan', '2')
 
:addClass('infobox-subheader')
 
side = dataCell:tag('table')
 
side
 
:addClass('fullWidth-table')
 
:addClass(args.bodyclass)
 
:cssText(args.bodystyle)
 
rowh = side:tag('tr')
 
rowh:addClass(args['rowclass' .. tostring(num)])
 
rowh:cssText(args['rowstyle' .. tostring(num)])
 
rowd = side:tag('tr')
 
rowd:addClass(args['rowclass' .. tostring(num)])
 
rowd:cssText(args['rowstyle' .. tostring(num)])
 
end
 
 
 
--Add label and data to the rows
+
--Remove leading and trailing spaces.
if rowArgs.sdata and rowArgs.sdata:gsub(
+
lname = lname:gsub('^%s*(.-)%s*$', '%1')
category_in_empty_row_pattern, ''
+
for key, item in pairs(p.loadData("item")) do
):match('^%S') then
+
if lname == item.name:lower() then
rowh
+
return item
:tag('th')
+
end
:attr('scope', 'row')
 
:addClass('infobox-slabel')
 
:cssText(args.labelstyle)
 
:cssText(rowArgs.rowcellstyle)
 
:wikitext(rowArgs.slabel)
 
:done()
 
 
 
rowd
 
:tag('td')
 
:addClass('infobox-sdata')
 
:addClass(rowArgs.class)
 
:cssText(rowArgs.datastyle)
 
:cssText(rowArgs.rowcellstyle)
 
:wikitext(fixChildBoxes(rowArgs.sdata, 'td'))
 
:done()
 
 
end
 
end
 +
return 0
 
end
 
end
  
local function renderTitle()
+
local function getItem(id)
if not args.title then return end
+
return p.loadData("item")[tostring(id)]
 +
end
  
has_rows = true
+
local function getEnchantmentName(id)
root
+
return p.loadData("enchantment")[tostring(id)].name
:tag('caption')
 
:addClass('infobox-title')
 
:addClass(args.titleclass)
 
-- @deprecated next; target .infobox-<name> .infobox-title
 
:cssText(args.titlestyle)
 
:wikitext(args.title)
 
 
end
 
end
  
local function renderAboveRow()
+
local function getItemName(id)
if not args.above then return end
+
return p.loadData("item")[tostring(id)].name
 +
end
  
has_rows = true
+
local function getCraftAug(id)
root
+
return p.loadData("craftaug")[tostring(id)]
:tag('tr')
 
:tag('th')
 
:attr('colspan', '2')
 
:addClass('infobox-above')
 
:addClass(args.aboveclass)
 
-- @deprecated next; target .infobox-<name> .infobox-above
 
:cssText(args.abovestyle)
 
:wikitext(fixChildBoxes(args.above,'th'))
 
 
end
 
end
  
local function renderBelowRow()
+
local function fullUrl(url)
if not args.below then return end
+
local newUrl = url
 +
if url:sub(1,5) == "https" then
 +
return newUrl
 +
end
 +
 +
if url:sub(1,1) ~= "/" then
 +
newUrl = "/" .. newUrl
 +
end
 +
 +
newUrl = "https://www.play.idlescape.com" .. newUrl
 +
return newUrl
 +
end
  
has_rows = true
+
local function icon(name, url, word)
root
+
local s = fullUrl(url)
:tag('tr')
+
s = "[[" .. name .. "|<img src=\"" .. s
:tag('td')
+
s = s .. "\" alt=\""  .. name .. "\" width=\"20\">"
:attr('colspan', '2')
+
if word then
:addClass('infobox-below')
+
s = s .. name
:addClass(args.belowclass)
+
end
-- @deprecated next; target .infobox-<name> .infobox-below
+
s = s .. "]]"
:cssText(args.belowstyle)
+
return s
:wikitext(fixChildBoxes(args.below,'td'))
 
 
end
 
end
  
local function addSubheaderRow(subheaderArgs)
+
local function itemImage(id, word)
if subheaderArgs.data and
+
local item = p.loadData("item")[tostring(id)]
subheaderArgs.data:gsub(category_in_empty_row_pattern, ''):match('^%S') then
+
local url = ""
has_rows = true
+
if item.itemIcon then
local row = root:tag('tr')
+
url = item.itemIcon
row:addClass(subheaderArgs.rowclass)
 
 
 
local dataCell = row:tag('td')
 
dataCell
 
:attr('colspan', '2')
 
:addClass('infobox-subheader')
 
:addClass(subheaderArgs.class)
 
:cssText(subheaderArgs.datastyle)
 
:cssText(subheaderArgs.rowcellstyle)
 
:wikitext(fixChildBoxes(subheaderArgs.data, 'td'))
 
 
else
 
else
table.insert(empty_row_categories, subheaderArgs.data or '')
+
url = item.itemImage
 
end
 
end
 +
return icon(item.name, url, word)
 
end
 
end
  
local function renderSubheaders()
+
local function locationImage(id, word)
if args.subheader then
+
local loc = p.loadData("location")[tostring(id)]
args.subheader1 = args.subheader
+
local url = ""
end
+
if loc.locationImage then
if args.subheaderrowclass then
+
url = loc.locationImage
args.subheaderrowclass1 = args.subheaderrowclass
+
else
end
+
return "[[" .. loc.name .. "]]"
local subheadernums = getArgNums('subheader')
 
for k, num in ipairs(subheadernums) do
 
addSubheaderRow({
 
data = args['subheader' .. tostring(num)],
 
-- @deprecated next; target .infobox-<name> .infobox-subheader
 
datastyle = args.subheaderstyle,
 
rowcellstyle = args['subheaderstyle' .. tostring(num)],
 
class = args.subheaderclass,
 
rowclass = args['subheaderrowclass' .. tostring(num)]
 
})
 
 
end
 
end
 +
return icon(loc.name, url, word)
 
end
 
end
  
local function addImageRow(imageArgs)
+
local function img(id)
 
+
local url = ""
if imageArgs.data and
+
if item.itemIcon then
imageArgs.data:gsub(category_in_empty_row_pattern, ''):match('^%S') then
+
url = item.itemIcon
 
 
has_rows = true
 
local row = root:tag('tr')
 
row:addClass(imageArgs.rowclass)
 
 
 
local dataCell = row:tag('td')
 
dataCell
 
:attr('colspan', '2')
 
:addClass('infobox-image')
 
:addClass(imageArgs.class)
 
:cssText(imageArgs.datastyle)
 
:wikitext(fixChildBoxes(imageArgs.data, 'td'))
 
 
else
 
else
table.insert(empty_row_categories, imageArgs.data or '')
+
url = item.itemImage
 
end
 
end
 +
return fullUrl(url)
 
end
 
end
  
local function renderImages()
+
local function addSeparator(num)
if args.image then
+
return tostring(tonumber(num)):reverse():gsub("(%d%d%d)","%1,"):gsub(",(%-?)$","%1"):reverse()
args.image1 = args.image
 
end
 
if args.caption then
 
args.caption1 = args.caption
 
end
 
local imagenums = getArgNums('image')
 
for k, num in ipairs(imagenums) do
 
local caption = args['caption' .. tostring(num)]
 
local data = mw.html.create():wikitext(args['image' .. tostring(num)])
 
if caption then
 
data
 
:tag('div')
 
:addClass('infobox-caption')
 
-- @deprecated next; target .infobox-<name> .infobox-caption
 
:cssText(args.captionstyle)
 
:wikitext(caption)
 
end
 
addImageRow({
 
data = tostring(data),
 
-- @deprecated next; target .infobox-<name> .infobox-image
 
datastyle = args.imagestyle,
 
class = args.imageclass,
 
rowclass = args['imagerowclass' .. tostring(num)]
 
})
 
end
 
 
end
 
end
  
-- When autoheaders are turned on, preprocesses the rows
+
local function gatheringSource(id)
local function preprocessRows()
+
local s = ""
if not args.autoheaders then return end
+
for key, loc in pairs(p.loadData('location')) do
+
if loc.loot then
local rownums = union(union(getArgNums('header'), getArgNums('data')), getArgNums('sdata'))
+
for key2, loot in pairs(loc.loot) do
table.sort(rownums)
+
if id == loot.id then
local lastheader
+
s = s .. locationImage(loc.locID, true)
for k, num in ipairs(rownums) do
+
s = s .. "<br>"
if args['header' .. tostring(num)] then
+
end
if lastheader then
 
args['header' .. tostring(lastheader)] = nil
 
 
end
 
end
lastheader = num
 
elseif (args['data' .. tostring(num)] and
 
args['data' .. tostring(num)]:gsub(category_in_empty_row_pattern, ''):match('^%S')) or
 
(args['sdata' .. tostring(num)] and
 
args['sdata' .. tostring(num)]:gsub(category_in_empty_row_pattern, ''):match('^%S')) then
 
--local data = args['data' .. tostring(num)]
 
--if data:gsub(category_in_empty_row_pattern, ''):match('%S') then
 
lastheader = nil
 
--end
 
 
end
 
end
 
end
 
end
if lastheader then
+
return s
args['header' .. tostring(lastheader)] = nil
 
end
 
 
end
 
end
  
-- Gets the union of the header and data argument numbers,
+
-- local function farmingSource(id)
-- and renders them all in order
+
-- local s = ""
local function renderRows()
+
 +
-- for key, item in pairs(p.loadData('item')) do
 +
-- if item.farmingStats then
 +
-- for key2, yield in pairs(item.farmingStats.yield) do
 +
-- if id == yield.id then
 +
-- s = s .. itemImage(item.id, true)
 +
-- s = s .. "<br>"
 +
-- end
 +
-- end
 +
-- end
 +
-- end
 +
-- return s
 +
-- end
  
local rownums = union(union(getArgNums('header'), getArgNums('data')), getArgNums('sdata'))
+
local function smithingSource(id)
table.sort(rownums)
+
local s = ""
for k, num in ipairs(rownums) do
+
local item = getItem(id)
+
if item.skill == "smithing" and item.name ~= 'Ichor' then
if args['sdata' .. tostring(num)] then
+
s = '[[Smithing]]<br>'
addSideRows({
 
slabel = args['slabel' .. tostring(num)],
 
sdata = args['sdata' .. tostring(num)],
 
datastyle = args.datastyle,
 
class = args['class' .. tostring(num)],
 
rowclass = args['rowclass' .. tostring(num)],
 
-- @deprecated next; target .infobox-<name> rowclass
 
rowstyle = args['rowstyle' .. tostring(num)],
 
rowcellstyle = args['rowcellstyle' .. tostring(num)]
 
})
 
else
 
side = nil
 
 
addRow({
 
header = args['header' .. tostring(num)],
 
label = args['label' .. tostring(num)],
 
data = args['data' .. tostring(num)],
 
datastyle = args.datastyle,
 
class = args['class' .. tostring(num)],
 
rowclass = args['rowclass' .. tostring(num)],
 
-- @deprecated next; target .infobox-<name> rowclass
 
rowstyle = args['rowstyle' .. tostring(num)],
 
rowcellstyle = args['rowcellstyle' .. tostring(num)]
 
})
 
end
 
 
end
 
end
 +
return s
 
end
 
end
  
local function renderNavBar()
+
local function cookingSource(id)
if not args.name then return end
+
local s = ""
 +
local item = getItem(id)
 +
if (item.class == "cooking-ingredient" and not item.ingredientTags) or item.class == 'cookedFish' or item.name=='Ashes' then
 +
s = '[[Cooking]]<br>'
 +
end
 +
return s
 +
end
  
has_rows = true
+
local function runecraftingSource(id)
root
+
local s = ""
:tag('tr')
+
local item = getItem(id)
:tag('td')
+
if item.class == "cloth" or (item.class == 'rune' and item.requiredResources) then
:attr('colspan', '2')
+
s = '[[Runecrafting]]<br>'
:addClass('infobox-navbar')
+
end
:wikitext(require('Module:Navbar')._navbar{
+
return s
args.name,
 
mini = 1,
 
})
 
 
end
 
end
  
local function renderItalicTitle()
+
local function scrollcraftingSource(id)
local italicTitle = args['italic title'] and mw.ustring.lower(args['italic title'])
+
local s = ""
if italicTitle == '' or italicTitle == 'force' or italicTitle == 'yes' then
+
local item = getItem(id)
root:wikitext(mw.getCurrentFrame():expandTemplate({title = 'italic title'}))
+
if item.class == "enchanted-scroll" and item.level and item.level < 100 then
 +
s = '[[Scrollcrafting]]<br>'
 
end
 
end
 +
return s
 
end
 
end
  
-- Categories in otherwise empty rows are collected in empty_row_categories.
+
 
-- This function adds them to the module output. It is not affected by
+
local function craftingSource(id)
-- args.decat because this module should not prevent module-external categories
+
local s = ""
-- from rendering.
+
local item = getItem(id)
local function renderEmptyRowCategories()
+
if item.craftable then
for _, s in ipairs(empty_row_categories) do
+
s = '[[Crafting]]<br>'
root:wikitext(s)
 
 
end
 
end
 +
return s
 
end
 
end
  
-- Render tracking categories. args.decat == turns off tracking categories.
+
local function findSource(id)
local function renderTrackingCategories()
+
local s = ""
if args.decat == 'yes' then return end
+
s = s .. gatheringSource(id)
if args.child == 'yes' then
+
-- s = s .. farmingSource(id)
if args.title then
+
s = s .. scrollcraftingSource(id)
root:wikitext(
+
s = s .. runecraftingSource(id)
'[[Category:Pages using embedded infobox templates with the title parameter]]'
+
s = s .. smithingSource(id)
)
+
s = s .. craftingSource(id)
end
+
s = s .. cookingSource(id)
elseif #(getArgNums('data')) == 0 and mw.title.getCurrentTitle().namespace == 0 then
+
if s:len() > 4 then  
root:wikitext('[[Category:Articles using infobox templates with no data rows]]')
+
s = s:sub(1,s:len()-4)
 
end
 
end
 +
return s
 
end
 
end
  
--[=[
+
local function createInfobox(item)
Loads the templatestyles for the infobox.
+
local args = {}
 
+
local url = ""
TODO: FINISH loading base templatestyles here rather than in
+
local s = ""
MediaWiki:Common.css. There are 4-5000 pages with 'raw' infobox tables.
+
args.autoheaders = "y"
See [[Mediawiki_talk:Common.css/to_do#Infobox]] and/or come help :).
+
args.subbox = "no"
When we do this we should clean up the inline CSS below too.
+
args.bodystyle = " "
Will have to do some bizarre conversion category like with sidebar.
+
args.title = item.name
 
+
]=]
+
if item.itemIcon then
local function loadTemplateStyles()
+
url = item.itemIcon
local frame = mw.getCurrentFrame()
+
else
 +
url = item.itemImage
 +
end
 +
args.image = "<img src=\"" .. fullUrl(url) .. "\" width=\"150\">"
 +
 +
if item.value then
 +
args[l()] = icon('Gold', "/images/gold_coin.png")
 +
args[d()] = addSeparator(item.value)
 +
end
 +
 +
if item.tradeable then
 +
args[l()] = icon('Market', "/images/ui/marketplace_icon.png")
 +
local market = require("Module:Market")["_price"]({item.name, 1, 1})
 +
if market then
 +
args[d()] = addSeparator(market)
 +
else
 +
args[d()] = "Yes"
 +
end
 +
end
 
 
-- See function description
+
if item.requiredLevel then
local base_templatestyles = frame:extensionTag{
+
s = ""
name = 'templatestyles', args = { src = 'Module:Infobox/styles.css' }
+
for skill, level in pairs(item.requiredLevel) do
}
+
s = s .. level .. " " .. skill .. "<br>"
 
+
end
local templatestyles = ''
+
s = s:sub(1,s:len()-4)
if args['templatestyles'] then templatestyles = frame:extensionTag{
+
args[l()] = "Level Required"
name = 'templatestyles', args = { src = args['templatestyles'] }
+
args[d()] = s
}
 
 
end
 
end
 
 
local child_templatestyles = ''
+
args[l()] = "Source"
if args['child templatestyles'] then child_templatestyles = frame:extensionTag{
+
args[d()] = findSource(item.id)
name = 'templatestyles', args = { src = args['child templatestyles'] }
+
}
+
if item.heat then
 +
args[l()] = itemImage(2)
 +
args[d()] = addSeparator(item.heat)
 
end
 
end
 
 
local grandchild_templatestyles = ''
+
local stats = item.equipmentStats
if args['grandchild templatestyles'] then grandchild_templatestyles = frame:extensionTag{
+
if stats then
name = 'templatestyles', args = { src = args['grandchild templatestyles'] }
+
args[l()] = "Slot"
}
+
args[d()] = stats.slot
 +
 +
if item.enchantmentTier then
 +
args[l()] = "Enchantment Slots"
 +
args[d()] = item.enchantmentTier
 +
end
 +
 +
if item.forcedEnchant then
 +
args[l()] = "Enchantments"
 +
args[d()] = "[[" .. getEnchantmentName(item.forcedEnchant) .. "]]"
 +
end
 +
 +
if stats.toolBoost then
 +
s = ""
 +
for key, stat in pairs(stats.toolBoost) do
 +
s = s .. stat.boost .. " "
 +
s = s .. stat.skill .. "<br>"
 +
end
 +
s = s:sub(1,s:len()-4)
 +
args[l()] = "Stats"
 +
args[d()] = s
 +
end
 +
 +
if stats.oneHanded == false then
 +
args[l()] = "Two-handed"
 +
args[d()] = "Yes"
 +
end
 +
 +
if stats.attackSpeed then
 +
args[l()] = "Attack Speed"
 +
args[d()] = stats.attackSpeed
 +
end
 +
 +
 +
args[h()] = "Offensive Stats"
 +
 +
stat = stats.offensiveCritical
 +
if stat then
 +
args[l()] = "Crit Chance"
 +
args[d()] = stat.chance
 +
args[l()] = "Crit Multiplier"
 +
args[d()] = stat.damageMultiplier
 +
end
 +
 +
stat = stats.weaponBonus
 +
if stat then
 +
args[sl()] = "Str"
 +
args[sd()] = stat.strength
 +
args[sl()] = "Int"
 +
args[sd()] = stat.intellect
 +
args[sl()] = "Dex"
 +
args[sd()] = stat.dexterity
 +
end
 +
 +
args[h()] = "Offensive Affinity"
 +
stat = stats.offensiveDamageAffinity
 +
if stat then
 +
args[sl()] = "Melee"
 +
args[sd()] = stat.Melee and stat.Melee * 100 .. "%"
 +
args[sl()] = "Magic"
 +
args[sd()] = stat.Magic and stat.Magic * 100 .. "%"
 +
args[sl()] = "Range"
 +
args[sd()] = stat.Range and stat.Range * 100 .. "%"
 +
args[sbreak()] = "yes"
 +
 +
args[sl()] = "Piercing"
 +
args[sd()] = stat.Piercing and stat.Piercing * 100 .. "%"
 +
args[sl()] = "Blunt"
 +
args[sd()] = stat.Blunt and stat.Blunt * 100 .. "%"
 +
args[sl()] = "Slashing"
 +
args[sd()] = stat.Slashing and stat.Slashing * 100 .. "%"
 +
args[sl()] = "Fire"
 +
args[sd()] = stat.Fire and stat.Fire * 100 .. "%"
 +
args[sl()] = "Ice"
 +
args[sd()] = stat.Ice and stat.Ice * 100 .. "%"
 +
args[sl()] = "Nature"
 +
args[sd()] = stat.Nature and stat.Nature * 100 .. "%"
 +
args[sl()] = "Chaos"
 +
args[sd()] = stat.Chaos and stat.Chaos * 100 .. "%"
 +
args[sbreak()] = "yes"
 +
end
 +
 +
args[h()] = "Accuracy"
 +
stat = stats.offensiveAccuracyAffinityRating
 +
if stat then
 +
args[sl()] = "Melee"
 +
args[sd()] = stat.Melee
 +
args[sl()] = "Magic"
 +
args[sd()] = stat.Magic
 +
args[sl()] = "Range"
 +
args[sd()] = stat.Range
 +
args[sbreak()] = "yes"
 +
 +
args[sl()] = "Piercing"
 +
args[sd()] = stat.Piercing
 +
args[sl()] = "Blunt"
 +
args[sd()] = stat.Blunt
 +
args[sl()] = "Slashing"
 +
args[sd()] = stat.Slashing
 +
args[sl()] = "Fire"
 +
args[sd()] = stat.Fire
 +
args[sl()] = "Ice"
 +
args[sd()] = stat.Ice
 +
args[sl()] = "Nature"
 +
args[sd()] = stat.Nature
 +
args[sl()] = "Chaos"
 +
args[sd()] = stat.Chaos
 +
args[sbreak()] = "yes"
 +
end
 +
 +
args[h()] = "Defensive Stats"
 +
 +
stat = stats.defensiveCritical
 +
if stat then
 +
args[l()] = "Crit Avoidance"
 +
args[d()] = stat.chance
 +
args[l()] = "Crit Reduction"
 +
args[d()] = stat.damageMultiplier
 +
end
 +
 +
stat = stats.armorBonus
 +
if stat then
 +
args[sl()] = "Protection"
 +
args[sd()] = stat.protection
 +
args[sl()] = "Resistance"
 +
args[sd()] = stat.resistance
 +
args[sl()] = "Agility"
 +
args[sd()] = stat.agility
 +
args[sl()] = "Stamina"
 +
args[sd()] = stat.stamina
 +
end
 +
 +
args[h()] = "Defensive Affinity"
 +
stat = stats.defensiveDamageAffinity
 +
if stat then
 +
args[sl()] = "Melee"
 +
args[sd()] = stat.Melee and stat.Melee * 100 .. "%"
 +
args[sl()] = "Magic"
 +
args[sd()] = stat.Magic and stat.Magic * 100 .. "%"
 +
args[sl()] = "Range"
 +
args[sd()] = stat.Range and stat.Range * 100 .. "%"
 +
args[sbreak()] = "yes"
 +
 +
args[sl()] = "Piercing"
 +
args[sd()] = stat.Piercing and stat.Piercing * 100 .. "%"
 +
args[sl()] = "Blunt"
 +
args[sd()] = stat.Blunt and stat.Blunt * 100 .. "%"
 +
args[sl()] = "Slashing"
 +
args[sd()] = stat.Slashing and stat.Slashing * 100 .. "%"
 +
args[sl()] = "Fire"
 +
args[sd()] = stat.Fire and stat.Fire * 100 .. "%"
 +
args[sl()] = "Ice"
 +
args[sd()] = stat.Ice and stat.Ice * 100 .. "%"
 +
args[sl()] = "Nature"
 +
args[sd()] = stat.Nature and stat.Nature * 100 .. "%"
 +
args[sl()] = "Chaos"
 +
args[sd()] = stat.Chaos and stat.Chaos * 100 .. "%"
 +
args[sbreak()] = "yes"
 +
end
 
end
 
end
  
return table.concat({
+
local ammoStat = item.ammunitionMults
base_templatestyles, -- see function description
 
templatestyles,
 
child_templatestyles,
 
grandchild_templatestyles
 
})
 
end
 
 
 
-- common functions between the child and non child cases
 
local function structure_infobox_common()
 
renderSubheaders()
 
renderImages()
 
preprocessRows()
 
renderRows()
 
renderBelowRow()
 
-- renderNavBar()
 
renderItalicTitle()
 
renderEmptyRowCategories()
 
renderTrackingCategories()
 
cleanInfobox()
 
end
 
 
 
-- Specify the overall layout of the infobox, with special settings if the
 
-- infobox is used as a 'child' inside another infobox.
 
local function _infobox()
 
if args.child ~= 'yes' then
 
root = mw.html.create('table')
 
 
 
root
 
:addClass(args.subbox == 'yes' and 'infobox-subbox' or 'infobox')
 
:addClass(args.bodyclass)
 
-- @deprecated next; target .infobox-<name>
 
:cssText(args.bodystyle)
 
 
 
renderTitle()
 
renderAboveRow()
 
else
 
root = mw.html.create()
 
  
root
+
if ammoStat then
:wikitext(args.title)
+
args[h()] = "Ammo Stats"
 +
args[sl()] = 'Type'
 +
args[sd()] = ammoStat.style
 +
args[sl()] = 'Damage'
 +
args[sd()] = ammoStat.damageMult .. 'x'
 +
args[sl()] = 'Accuracy'
 +
args[sd()] = ammoStat.accuracyMult .. 'x'
 
end
 
end
structure_infobox_common()
 
 
 
-- return loadTemplateStyles() .. root
+
args[h()] = "Augment"
return root
+
local craftAug = getCraftAug(item.id)
end
+
 
+
if craftAug and craftAug.augmenting then
-- If the argument exists and isn't blank, add it to the argument table.
+
if item.equipmentStats then
-- Blank arguments are treated as nil to match the behaviour of ParserFunctions.
+
s = ""
local function preprocessSingleArg(argName)
+
for key, bonus in pairs(item.equipmentStats.augmentationBonus) do
if origArgs[argName] and origArgs[argName] ~= '' then
+
s = s .. "+" .. bonus.value .. " "
args[argName] = origArgs[argName]
+
s = s .. bonus.stat:sub(bonus.stat:find('%.')+1,bonus.stat:len()) .. "<br>"
 +
end
 +
s = s:sub(1,s:len()-4)
 +
args[sl()] = "Aug Bonus"
 +
args[sd()] = s
 +
end
 +
 +
s = ""
 +
for key, cost in pairs(craftAug.augmenting) do
 +
s = s .. cost .. " "
 +
s = s .. itemImage(key, true) .. "<br>"
 +
end
 +
s = s:sub(1,s:len()-4)
 +
args[sl()] = "Aug Cost"
 +
args[sd()] = s
 
end
 
end
end
+
 
+
args[h()] = "Cooking"
-- Assign the parameters with the given prefixes to the args table, in order, in
+
-- batches of the step size specified. This is to prevent references etc. from
+
if item.size then
-- appearing in the wrong order. The prefixTable should be an array containing
+
args[l()] = "Size"
-- tables, each of which has two possible fields, a "prefix" string and a
+
args[d()] = item.size
-- "depend" table. The function always parses parameters containing the "prefix"
 
-- string, but only parses parameters in the "depend" table if the prefix
 
-- parameter is present and non-blank.
 
local function preprocessArgs(prefixTable, step)
 
if type(prefixTable) ~= 'table' then
 
error("Non-table value detected for the prefix table", 2)
 
 
end
 
end
if type(step) ~= 'number' then
+
error("Invalid step value detected", 2)
+
if item.difficulty then
 +
args[l()] = "Difficulty"
 +
args[d()] = item.difficulty
 
end
 
end
 
+
-- Get arguments without a number suffix, and check for bad input.
+
if item.ingredientTags then
for i,v in ipairs(prefixTable) do
+
s = ""
if type(v) ~= 'table' or type(v.prefix) ~= "string" or
+
for key, tag in pairs(item.ingredientTags) do
(v.depend and type(v.depend) ~= 'table') then
+
s = s .. tag .. "<br>"
error('Invalid input detected to preprocessArgs prefix table', 2)
 
 
end
 
end
preprocessSingleArg(v.prefix)
+
s = s:sub(1,s:len()-4)
-- Only parse the depend parameter if the prefix parameter is present
+
args[l()] = "Category"
-- and not blank.
+
args[d()] = s
if args[v.prefix] and v.depend then
+
end
for j, dependValue in ipairs(v.depend) do
+
if type(dependValue) ~= 'string' then
+
if item.cookingEnchantment then
error('Invalid "depend" parameter value detected in preprocessArgs')
+
args[l()] = "Buff"
 +
args[d()] = getEnchantmentName(item.cookingEnchantment)
 +
end
 +
 +
args[h()] = "Seeds"
 +
 +
local farming = item.farmingStats
 +
if farming then
 +
local farmingData = p.loadData('farming')
 +
local seedData = farmingData[item.id]
 +
if seedData then
 +
s = ""
 +
for key, yield in pairs(seedData) do
 +
s = s .. yield.min .. "-" .. yield.max .. " "
 +
s = s .. itemImage(yield.id, true)
 +
if yield.chance ~= 1 then
 +
s = s .. " " .. tonumber(string.format('%.2f', yield.chance * 100)) .. "%"
 
end
 
end
preprocessSingleArg(dependValue)
+
s = s .. "<br>"
 
end
 
end
 +
s = s:sub(1,s:len()-4)
 +
args[l()] = "Level Required"
 +
args[d()] = farming.requiredLevel
 +
args[l()] = "Experience"
 +
args[d()] = addSeparator(farming.experience)
 +
args[l()] = "Plot Size"
 +
args[d()] = farming.height .. "x" .. farming.width
 +
args[l()] = "Harvest Time"
 +
args[d()] = farming.time .. " minutes"
 +
args[l()] = "Yield"
 +
args[d()] = s
 
end
 
end
 
end
 
end
 
+
-- Get arguments with number suffixes.
+
local args2 = {}
local a = 1 -- Counter variable.
+
local moreArgumentsExist = true
+
args2.subbox = "yes"
while moreArgumentsExist == true do
+
args2.bodystyle = "padding: 0.5em; margin:auto; font-style:italic; font-size:110%; text-align: center"
moreArgumentsExist = false
+
args2.data1 = item.extraTooltipInfo
for i = a, a + step - 1 do
+
args[h()] = "Tooltip"
for j,v in ipairs(prefixTable) do
+
args[d()] = require('Module:Infobox').infobox(args2)
local prefixArgName = v.prefix .. tostring(i)
+
if origArgs[prefixArgName] then
+
for key, data in pairs(args) do
-- Do another loop if any arguments are found, even blank ones.
+
if string.find(key, "data") then
moreArgumentsExist = true
+
args[key] = tostring(data)
preprocessSingleArg(prefixArgName)
 
end
 
-- Process the depend table if the prefix argument is present
 
-- and not blank, or we are processing "prefix1" and "prefix" is
 
-- present and not blank, and if the depend table is present.
 
if v.depend and (args[prefixArgName] or (i == 1 and args[v.prefix])) then
 
for j,dependValue in ipairs(v.depend) do
 
local dependArgName = dependValue .. tostring(i)
 
preprocessSingleArg(dependArgName)
 
end
 
end
 
end
 
 
end
 
end
a = a + step
 
 
end
 
end
 +
 +
return require('Module:Infobox').infobox(args)
 
end
 
end
  
-- Parse the data parameters in the same order that the old {{infobox}} did, so
+
function p.item(frame)
-- that references etc. will display in the expected places. Parameters that
+
local args = frame:getParent().args
-- depend on another parameter are only processed if that parameter is present,
+
return p._item(args)
-- to avoid phantom references appearing in article reference lists.
 
local function parseDataParameters()
 
 
 
preprocessSingleArg('autoheaders')
 
preprocessSingleArg('child')
 
preprocessSingleArg('bodyclass')
 
preprocessSingleArg('subbox')
 
preprocessSingleArg('bodystyle')
 
preprocessSingleArg('title')
 
preprocessSingleArg('titleclass')
 
preprocessSingleArg('titlestyle')
 
preprocessSingleArg('above')
 
preprocessSingleArg('aboveclass')
 
preprocessSingleArg('abovestyle')
 
preprocessArgs({
 
{prefix = 'subheader', depend = {'subheaderstyle', 'subheaderrowclass'}}
 
}, 10)
 
preprocessSingleArg('subheaderstyle')
 
preprocessSingleArg('subheaderclass')
 
preprocessArgs({
 
{prefix = 'image', depend = {'caption', 'imagerowclass'}}
 
}, 10)
 
preprocessSingleArg('captionstyle')
 
preprocessSingleArg('imagestyle')
 
preprocessSingleArg('imageclass')
 
preprocessArgs({
 
{prefix = 'header'},
 
{prefix = 'data', depend = {'label'}},
 
{prefix = 'sdata', depend = {'slabel'}},
 
{prefix = 'rowclass'},
 
{prefix = 'rowstyle'},
 
{prefix = 'rowcellstyle'},
 
{prefix = 'class'}
 
}, 50)
 
preprocessSingleArg('headerclass')
 
preprocessSingleArg('headerstyle')
 
preprocessSingleArg('labelstyle')
 
preprocessSingleArg('datastyle')
 
preprocessSingleArg('below')
 
preprocessSingleArg('belowclass')
 
preprocessSingleArg('belowstyle')
 
preprocessSingleArg('name')
 
-- different behaviour for italics if blank or absent
 
args['italic title'] = origArgs['italic title']
 
preprocessSingleArg('decat')
 
preprocessSingleArg('templatestyles')
 
preprocessSingleArg('child templatestyles')
 
preprocessSingleArg('grandchild templatestyles')
 
 
end
 
end
  
-- If called via #invoke, use the args passed into the invoking template.
+
function p._item(args)
-- Otherwise, for testing purposes, assume args are being passed directly in.
+
local name = ""
function p.infobox(frame)
+
local item = 0
if frame == mw.getCurrentFrame() then
+
local infobox = ""
origArgs = frame:getParent().args
+
 +
if args[1] then
 +
name = args[1]
 
else
 
else
origArgs = frame
+
name = mw.title.getCurrentTitle().text
 
end
 
end
 
 
parseDataParameters()
+
item = findItem(name)
 +
 +
if item == 0 then
 +
return "<div style=\"color:red\"> No item named '" .. name .. "'</div>. The Module:Items/data maybe outdated."
 +
end
 
 
return _infobox()
+
infobox = createInfobox(item)
 +
return infobox
 
end
 
end
  
-- For calling via #invoke within a template
 
function p.infoboxTemplate(frame)
 
origArgs = {}
 
for k,v in pairs(frame.args) do origArgs[k] = mw.text.trim(v) end
 
 
parseDataParameters()
 
 
return _infobox()
 
end
 
 
return p
 
return p

Latest revision as of 09:46, 5 July 2024

Documentation for this module may be created at Module:Silent1/sandbox/doc

local p = {}

local data_module_names = {
	item = 'Module:Items/data',
	enchantment = 'Module:Enchantment/data',
	location = 'Module:Location/data',
	craftaug = 'Module:CraftingAugmenting/data',
	farming = 'Module:Farming/data'
}

local loaded_data_modules = {}

local headerCount = 1
local labelCount = 1
local dataCount = 1

local function h()
	local s = "header" .. headerCount
	headerCount = headerCount + 1
	labelCount = headerCount
	dataCount = headerCount
	return s
end

local function sbreak()
	local s = "sbreak" .. headerCount
	headerCount = headerCount + 1
	labelCount = headerCount
	dataCount = headerCount
	return s
end

local function l()
	local s = "label" .. labelCount
	dataCount = labelCount
	labelCount = labelCount + 1
	headerCount = labelCount
	return s
end

local function d() 
	local s = "data" .. dataCount
	dataCount = dataCount + 1
	headerCount = dataCount
	labelCount = dataCount
	return s
end

local function sl()
	local s = "s" .. l()
	return s
end

local function sd()
	local s = "s" .. d()
	return s
end

function p.loadData(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
		
	return loaded_data_modules[module_name]
end

local function findItem(name)
	local lname = name:lower()
	
	 --Remove leading and trailing spaces.
	lname = lname:gsub('^%s*(.-)%s*$', '%1')
	for key, item in pairs(p.loadData("item")) do
		if lname == item.name:lower() then
			return item
		end
	end
	return 0
end

local function getItem(id)
	return p.loadData("item")[tostring(id)]
end

local function getEnchantmentName(id)
	return p.loadData("enchantment")[tostring(id)].name
end

local function getItemName(id)
	return p.loadData("item")[tostring(id)].name
end

local function getCraftAug(id)
	return p.loadData("craftaug")[tostring(id)]
end

local function fullUrl(url)
	local newUrl = url
	if url:sub(1,5) == "https" then
		return newUrl
	end
	
	if url:sub(1,1) ~= "/" then
		newUrl = "/" .. newUrl
	end
	
	newUrl = "https://www.play.idlescape.com" .. newUrl
	return newUrl
end

local function icon(name, url, word)
	local s = fullUrl(url)
	s = "[[" .. name .. "|<img src=\"" .. s
	s = s .. "\" alt=\""  .. name .. "\" width=\"20\">"
	if word then
		s = s .. name
	end
	s = s .. "]]"
	return s
end

local function itemImage(id, word)
	local item = p.loadData("item")[tostring(id)]
	local url = ""
	if item.itemIcon then
		url = item.itemIcon
	else
		url = item.itemImage
	end
	return icon(item.name, url, word)
end

local function locationImage(id, word)
	local loc = p.loadData("location")[tostring(id)]
	local url = ""
	if loc.locationImage then
		url = loc.locationImage
	else
		return "[[" .. loc.name .. "]]"
	end
	return icon(loc.name, url, word)
end

local function img(id)
	local url = ""
	if item.itemIcon then
		url = item.itemIcon
	else
		url = item.itemImage
	end
	return fullUrl(url)
end

local function addSeparator(num)
	return tostring(tonumber(num)):reverse():gsub("(%d%d%d)","%1,"):gsub(",(%-?)$","%1"):reverse()
end

local function gatheringSource(id)
	local s = ""
	for key, loc in pairs(p.loadData('location')) do
		if loc.loot then
			for key2, loot in pairs(loc.loot) do
				if id == loot.id then
					s = s .. locationImage(loc.locID, true)
					s = s .. "<br>"
				end
			end
		end
	end
	return s
end

-- local function farmingSource(id)
-- 	local s = ""
	
-- 	for key, item in pairs(p.loadData('item')) do
-- 		if item.farmingStats then
-- 			for key2, yield in pairs(item.farmingStats.yield) do
-- 				if id == yield.id then
-- 					s = s .. itemImage(item.id, true)
-- 					s = s .. "<br>"
-- 				end
-- 			end
-- 		end
-- 	end
-- 	return s
-- end

local function smithingSource(id)
	local s = ""
	local item = getItem(id)
	if item.skill == "smithing" and item.name ~= 'Ichor' then
		s = '[[Smithing]]<br>'
	end
	return s
end

local function cookingSource(id)
	local s = ""
	local item = getItem(id)
	if (item.class == "cooking-ingredient" and not item.ingredientTags) or item.class == 'cookedFish' or item.name=='Ashes' then
		s = '[[Cooking]]<br>'
	end
	return s
end

local function runecraftingSource(id)
	local s = ""
	local item = getItem(id)
	if item.class == "cloth" or (item.class == 'rune' and item.requiredResources) then
		s = '[[Runecrafting]]<br>'
	end
	return s
end

local function scrollcraftingSource(id)
	local s = ""
	local item = getItem(id)
	if item.class == "enchanted-scroll" and item.level and item.level < 100 then
		s = '[[Scrollcrafting]]<br>'
	end
	return s
end


local function craftingSource(id)
	local s = ""
	local item = getItem(id)
	if item.craftable then
		s = '[[Crafting]]<br>'
	end
	return s
end

local function findSource(id)
	local s = ""
	s = s .. gatheringSource(id)
	-- s = s .. farmingSource(id)
	s = s .. scrollcraftingSource(id)
	s = s .. runecraftingSource(id)
	s = s .. smithingSource(id)
	s = s .. craftingSource(id)
	s = s .. cookingSource(id)
	if s:len() > 4 then 
		s = s:sub(1,s:len()-4)
	end
	return s	
end

local function createInfobox(item)
	local args = {}	
	local url = ""
	local s = ""
	args.autoheaders = "y"
	args.subbox = "no"
	args.bodystyle = " "
	args.title = item.name
	
	if item.itemIcon then
		url = item.itemIcon
	else
		url = item.itemImage
	end
	args.image = "<img src=\"" .. fullUrl(url) .. "\" width=\"150\">"
	
	if item.value then
		args[l()] = icon('Gold', "/images/gold_coin.png")
		args[d()] = addSeparator(item.value)
	end
	
	if item.tradeable then
		args[l()] = icon('Market', "/images/ui/marketplace_icon.png")
		local market = require("Module:Market")["_price"]({item.name, 1, 1})
		if market then
			args[d()] = addSeparator(market)
		else
			args[d()] = "Yes"
		end
	end
	
	if item.requiredLevel then
		s = ""
		for skill, level in pairs(item.requiredLevel) do
			s = s .. level .. " " .. skill .. "<br>"
		end
		s = s:sub(1,s:len()-4)
		args[l()] = "Level Required"
		args[d()] = s
	end
	
	args[l()] = "Source"
	args[d()] = findSource(item.id)
	
	if item.heat then
		args[l()] = itemImage(2)
		args[d()] = addSeparator(item.heat)
	end
	
	local stats = item.equipmentStats
	if stats then
		args[l()] = "Slot"
		args[d()] = stats.slot
		
		if item.enchantmentTier then
			args[l()] = "Enchantment Slots"
			args[d()] = item.enchantmentTier
		end
		
		if item.forcedEnchant then
			args[l()] = "Enchantments"
			args[d()] = "[[" .. getEnchantmentName(item.forcedEnchant) .. "]]"
		end
		
		if stats.toolBoost then
			s = ""
			for key, stat in pairs(stats.toolBoost) do
				s = s .. stat.boost .. " "
				s = s .. stat.skill .. "<br>"
			end
			s = s:sub(1,s:len()-4)
			args[l()] = "Stats"
			args[d()] = s
		end
		
		if stats.oneHanded == false then
			args[l()] = "Two-handed"
			args[d()] = "Yes"
		end
		
		if stats.attackSpeed then
			args[l()] = "Attack Speed"
			args[d()] = stats.attackSpeed
		end
		
		
		args[h()] = "Offensive Stats"
		
		stat = stats.offensiveCritical
		if stat then
			args[l()] = "Crit Chance"
			args[d()] = stat.chance
			args[l()] = "Crit Multiplier"
			args[d()] = stat.damageMultiplier
		end
		
		stat = stats.weaponBonus
		if stat then
			args[sl()] = "Str"
			args[sd()] = stat.strength
			args[sl()] = "Int"
			args[sd()] = stat.intellect
			args[sl()] = "Dex"
			args[sd()] = stat.dexterity
		end
		
		args[h()] = "Offensive Affinity"
		stat = stats.offensiveDamageAffinity
		if stat then
			args[sl()] = "Melee"
			args[sd()] = stat.Melee and stat.Melee * 100 .. "%"
			args[sl()] = "Magic"
			args[sd()] = stat.Magic and stat.Magic * 100 .. "%"
			args[sl()] = "Range"
			args[sd()] = stat.Range and stat.Range * 100 .. "%"
			args[sbreak()] = "yes"
			
			args[sl()] = "Piercing"
			args[sd()] = stat.Piercing and stat.Piercing * 100 .. "%"
			args[sl()] = "Blunt"
			args[sd()] = stat.Blunt and stat.Blunt * 100 .. "%"
			args[sl()] = "Slashing"
			args[sd()] = stat.Slashing and stat.Slashing * 100 .. "%"			
			args[sl()] = "Fire"
			args[sd()] = stat.Fire and stat.Fire * 100 .. "%"
			args[sl()] = "Ice"
			args[sd()] = stat.Ice and stat.Ice * 100 .. "%"
			args[sl()] = "Nature"
			args[sd()] = stat.Nature and stat.Nature * 100 .. "%"
			args[sl()] = "Chaos"
			args[sd()] = stat.Chaos and stat.Chaos * 100 .. "%"
			args[sbreak()] = "yes"
		end
		
		args[h()] = "Accuracy"
		stat = stats.offensiveAccuracyAffinityRating
		if stat then
			args[sl()] = "Melee"
			args[sd()] = stat.Melee
			args[sl()] = "Magic"
			args[sd()] = stat.Magic
			args[sl()] = "Range"
			args[sd()] = stat.Range
			args[sbreak()] = "yes"
			
			args[sl()] = "Piercing"
			args[sd()] = stat.Piercing
			args[sl()] = "Blunt"
			args[sd()] = stat.Blunt
			args[sl()] = "Slashing"
			args[sd()] = stat.Slashing			
			args[sl()] = "Fire"
			args[sd()] = stat.Fire
			args[sl()] = "Ice"
			args[sd()] = stat.Ice
			args[sl()] = "Nature"
			args[sd()] = stat.Nature
			args[sl()] = "Chaos"
			args[sd()] = stat.Chaos
			args[sbreak()] = "yes"
		end
		
		args[h()] = "Defensive Stats"
		
		stat = stats.defensiveCritical
		if stat then
			args[l()] = "Crit Avoidance"
			args[d()] = stat.chance
			args[l()] = "Crit Reduction"
			args[d()] = stat.damageMultiplier
		end
		
		stat = stats.armorBonus
		if stat then
			args[sl()] = "Protection"
			args[sd()] = stat.protection
			args[sl()] = "Resistance"
			args[sd()] = stat.resistance
			args[sl()] = "Agility"
			args[sd()] = stat.agility
			args[sl()] = "Stamina"
			args[sd()] = stat.stamina
		end
		
		args[h()] = "Defensive Affinity"
		stat = stats.defensiveDamageAffinity
		if stat then
			args[sl()] = "Melee"
			args[sd()] = stat.Melee and stat.Melee * 100 .. "%"
			args[sl()] = "Magic"
			args[sd()] = stat.Magic and stat.Magic * 100 .. "%"
			args[sl()] = "Range"
			args[sd()] = stat.Range and stat.Range * 100 .. "%"
			args[sbreak()] = "yes"
			
			args[sl()] = "Piercing"
			args[sd()] = stat.Piercing and stat.Piercing * 100 .. "%"
			args[sl()] = "Blunt"
			args[sd()] = stat.Blunt and stat.Blunt * 100 .. "%"
			args[sl()] = "Slashing"
			args[sd()] = stat.Slashing and stat.Slashing * 100 .. "%"			
			args[sl()] = "Fire"
			args[sd()] = stat.Fire and stat.Fire * 100 .. "%"
			args[sl()] = "Ice"
			args[sd()] = stat.Ice and stat.Ice * 100 .. "%"
			args[sl()] = "Nature"
			args[sd()] = stat.Nature and stat.Nature * 100 .. "%"
			args[sl()] = "Chaos"
			args[sd()] = stat.Chaos and stat.Chaos * 100 .. "%"
			args[sbreak()] = "yes"
		end
	end

	local ammoStat = item.ammunitionMults

	if ammoStat then
		args[h()] = "Ammo Stats"
		args[sl()] = 'Type'
		args[sd()] = ammoStat.style
		args[sl()] = 'Damage'
		args[sd()] = ammoStat.damageMult .. 'x'
		args[sl()] = 'Accuracy'
		args[sd()] = ammoStat.accuracyMult .. 'x'
	end
	
	args[h()] = "Augment"
	local craftAug = getCraftAug(item.id)
		
	if craftAug and craftAug.augmenting then
		if item.equipmentStats then
			s = ""
			for key, bonus in pairs(item.equipmentStats.augmentationBonus) do
				s = s .. "+" .. bonus.value .. " "
				s = s .. bonus.stat:sub(bonus.stat:find('%.')+1,bonus.stat:len()) .. "<br>"
			end
			s = s:sub(1,s:len()-4)
			args[sl()] = "Aug Bonus"
			args[sd()] = s
		end
			
			s = ""
		for key, cost in pairs(craftAug.augmenting) do
			s = s .. cost .. " "
			s = s .. itemImage(key, true) .. "<br>"
		end
		s = s:sub(1,s:len()-4)
		args[sl()] = "Aug Cost"
		args[sd()] = s
	end
	
	args[h()] = "Cooking"
	
	if item.size then
		args[l()] = "Size"
		args[d()] = item.size
	end
	
	if item.difficulty then
		args[l()] = "Difficulty"
		args[d()] = item.difficulty
	end
	
	if item.ingredientTags then
		s = ""
		for key, tag in pairs(item.ingredientTags) do
			s = s .. tag .. "<br>"
		end
		s = s:sub(1,s:len()-4)
		args[l()] = "Category"
		args[d()] = s
	end	
	
	if item.cookingEnchantment then
		args[l()] = "Buff"
		args[d()] = getEnchantmentName(item.cookingEnchantment)
	end
	
	args[h()] = "Seeds"
	
	local farming = item.farmingStats
	if farming then
		local farmingData = p.loadData('farming')
		local seedData = farmingData[item.id]
		if seedData then
			s = ""
			for key, yield in pairs(seedData) do
				s = s .. yield.min .. "-" .. yield.max .. " "
				s = s .. itemImage(yield.id, true)
				if yield.chance ~= 1 then
					s = s .. " " .. tonumber(string.format('%.2f', yield.chance * 100)) .. "%"
				end
				s = s .. "<br>"
			end
			s = s:sub(1,s:len()-4)
			args[l()] = "Level Required"
			args[d()] = farming.requiredLevel
			args[l()] = "Experience"
			args[d()] = addSeparator(farming.experience)
			args[l()] = "Plot Size"
			args[d()] = farming.height .. "x" .. farming.width
			args[l()] = "Harvest Time"
			args[d()] = farming.time .. " minutes"
			args[l()] = "Yield"
			args[d()] = s
		end
	end
	
	local args2 = {}
	
	args2.subbox = "yes"
	args2.bodystyle = "padding: 0.5em; margin:auto; font-style:italic; font-size:110%; text-align: center"
	args2.data1 = item.extraTooltipInfo
	args[h()] = "Tooltip"
	args[d()] = require('Module:Infobox').infobox(args2)
	
	for key, data in pairs(args) do
		if string.find(key, "data") then
			args[key] = tostring(data)
		end
	end
	
	return require('Module:Infobox').infobox(args)
end

function p.item(frame)
	local args = frame:getParent().args
	return p._item(args)
end

function p._item(args)
	local name = ""
	local item = 0
	local infobox = ""
	
	if args[1] then
		name = args[1]
	else
		name = mw.title.getCurrentTitle().text
	end
	
	item = findItem(name)
		
	if item == 0 then
		return "<div style=\"color:red\"> No item named '" .. name .. "'</div>. The Module:Items/data maybe outdated."
	end
	
	infobox = createInfobox(item)
	return infobox
end

return p