2,875
edits
(Add total value of inputs and outputs) |
(Add items table) |
||
Line 29: | Line 29: | ||
return name | return name | ||
end | |||
local function getErrorDiv(message) | |||
return mw.html.create('div') | |||
:css('color', 'red') | |||
:wikitext(message) | |||
:done() | |||
end | |||
local function getItemIcon(iconName) | |||
return icons.Icon({iconName, type='item', notext=true}) | |||
end | end | ||
Line 121: | Line 132: | ||
-- @param items (table) A table containing items | -- @param items (table) A table containing items | ||
-- @return (string) The HTML representation of the item table section. | -- @return (string) The HTML representation of the item table section. | ||
local function buildItemTable(items) | local function buildItemTable(itemSet) | ||
if itemSet == nil or itemSet.Items == nil or #itemSet.Items == 0 then | |||
return nil | |||
end | |||
-- Create table with header for items | |||
local tbl = mw.html.create('table') | |||
tbl:addClass('wikitable sortable text-align-center') | |||
:attr('style', 'font-size: 1em; width: calc(100% + 2px); margin: -1px') | |||
:tag('tr') | |||
:tag('th') | |||
:addClass('unsortable') | |||
:tag('th'):wikitext('Item') | |||
:tag('th'):wikitext('Quantity') | |||
:tag('th'):wikitext('Value') | |||
:done() | |||
-- Create individual rows for items | |||
for _, i in pairs(itemSet.Items) do | |||
local row = mw.html.create('tr') | |||
local imgCell = mw.html.create('td') | |||
:wikitext(getItemIcon(i.name)) | |||
:done() | |||
local itemCell = mw.html.create('td') | |||
:css('text-align','left') | |||
:wikitext(string.format('[[%s]]', i.name)) | |||
:done() | |||
local qtyCell = mw.html.create('td') | |||
if i.amount == nil then | |||
qtyCell:node(getErrorDiv("Unable to parse quantity for item: " .. i.name)) | |||
else | |||
qtyCell:wikitext(i.amount) | |||
end | |||
qtyCell:done() | |||
local valCell = mw.html.create('td') | |||
if i.value == nil then | |||
valCell:node(getErrorDiv("Unable to get value for item: " .. i.name)) | |||
else | |||
local tot = i.value * (i.amount or 0) | |||
valCell:wikitext(icons.GP(tot)) | |||
end | |||
valCell:done() | |||
-- Add all cells to row, and row to table. | |||
row:node(imgCell):node(itemCell):node(qtyCell):node(valCell):done() | |||
tbl:node(row) | |||
end | |||
return tbl:done() | |||
end | end | ||
Line 131: | Line 194: | ||
for _, skillLine in pairs(skills) do | for _, skillLine in pairs(skills) do | ||
local hasInvalidExp = false | local hasInvalidExp = false | ||
local span = | local span = nil | ||
if skillLine.exp == nil or skillLine.exp <= 0 then | if skillLine.exp == nil or skillLine.exp <= 0 then | ||
Line 140: | Line 203: | ||
if hasInvalidExp then | if hasInvalidExp then | ||
span | span = getErrorDiv("Skill in parameter " .. skillLine.prmNumber .. " has an invalid experience value.") | ||
else | else | ||
span:wikitext(skillIcon) | span = mw.html.create('div') | ||
:wikitext(skillIcon) | |||
:done() | |||
end | end | ||
Line 236: | Line 300: | ||
:tag("tr") | :tag("tr") | ||
:tag("td") | :tag("td") | ||
local inputsTable = buildItemTable(pInputs) | |||
if inputsTable ~= nil then | |||
html:node(inputsTable) | |||
else | |||
html:wikitext("None") | |||
end | |||
html = html | |||
:tag("td") | :tag("td") | ||
local outputsTable = buildItemTable(pOutputs) | |||
if outputsTable ~= nil then | |||
html:node(outputsTable) | |||
else | |||
html:wikitext("None") | |||
end | |||
html = html | |||
:done() | |||
:done() | |||
return tostring(tbl) | return tostring(tbl) | ||
end | end |
edits