Module:Skills/Artisan: Difference between revisions

_getRecipeTable: Use mw.html & style amends
No edit summary
(_getRecipeTable: Use mw.html & style amends)
Line 442: Line 442:
function p.getRunecraftingTable(frame)
function p.getRunecraftingTable(frame)
local category = frame.args ~= nil and frame.args[1] or frame
local category = frame.args ~= nil and frame.args[1] or frame
return p._getRecipeTable('Runecrafting', category, {'ItemImage', 'ItemName', 'SkillLevel', 'SkillXP', 'Currency', 'Ingredients', 'SkillXPSec', 'CurrencySec'})
return p._getRecipeTable('Runecrafting', category, {'ItemImage', 'ItemName', 'DLC', 'SkillLevel', 'SkillXP', 'Currency', 'Ingredients', 'SkillXPSec', 'CurrencySec'})
end
end


function p.getFletchingTable(frame)
function p.getFletchingTable(frame)
local category = frame.args ~= nil and frame.args[1] or frame
local category = frame.args ~= nil and frame.args[1] or frame
return p._getRecipeTable('Fletching', category, {'ItemImage', 'ItemName', 'SkillLevel', 'SkillXP', 'Currency', 'Ingredients'})
return p._getRecipeTable('Fletching', category, {'ItemImage', 'ItemName', 'DLC', 'SkillLevel', 'SkillXP', 'Currency', 'Ingredients'})
end
end


function p.getCraftingTable(frame)
function p.getCraftingTable(frame)
local category = frame.args ~= nil and frame.args[1] or frame
local category = frame.args ~= nil and frame.args[1] or frame
local columns = {'ItemImage', 'ItemName', 'SkillLevel', 'SkillXP', 'Currency', 'Ingredients'}
local columns = {'ItemImage', 'ItemName', 'DLC', 'SkillLevel', 'SkillXP', 'Currency', 'Ingredients'}
if category == 'Rings' or category == 'Necklaces' then
if category == 'Rings' or category == 'Necklaces' then
table.insert(columns, "Description")
table.insert(columns, "Description")
Line 461: Line 461:
function p.getSmithingTable(frame)
function p.getSmithingTable(frame)
local category = frame.args ~= nil and frame.args[1] or frame
local category = frame.args ~= nil and frame.args[1] or frame
local columns = {'ItemImage', 'ItemName', 'SkillLevel', 'SkillXP', 'Currency', 'Ingredients'}
local columns = {'ItemImage', 'ItemName', 'DLC', 'SkillLevel', 'SkillXP', 'Currency', 'Ingredients'}
if category ~= 'Bars' and category ~= 'Abyssal Bars' then
if category ~= 'Bars' and category ~= 'Abyssal Bars' then
table.insert(columns, 'CurrencyBar')
table.insert(columns, 'CurrencyBar')
Line 502: Line 502:
return Shared.printError('No such category ' .. categoryName .. ' for skill ' .. skillName .. ', the following are available: ' .. table.concat(catNames, ', '))
return Shared.printError('No such category ' .. categoryName .. ' for skill ' .. skillName .. ', the following are available: ' .. table.concat(catNames, ', '))
end
end
local categoryRealm = category.realm or 'melvorD:Melvor'
local actionInterval = SkillData[skillName].baseInterval / 1000
local actionInterval = SkillData[skillName].baseInterval / 1000


Line 516: Line 517:
["ItemImage"] = {["header"] = 'Item', ["altRepeat"] = false},
["ItemImage"] = {["header"] = 'Item', ["altRepeat"] = false},
["ItemName"] = {["header"] = 'Name', ["altRepeat"] = true},
["ItemName"] = {["header"] = 'Name', ["altRepeat"] = true},
["SkillLevel"] = {["header"] = Icons.Icon({skillName, type='skill', notext=true}) .. ' Level', ["altRepeat"] = false},
["SkillLevel"] = {["header"] = Icons._SkillRealmIcon(skillName, categoryRealm) .. ' Level', ["altRepeat"] = false},
["DLC"] = {["header"] = '[[DLC]]', ["altRepeat"] = false},
["SkillXP"] = {["header"] = 'XP', ["altRepeat"] = false},
["SkillXP"] = {["header"] = 'XP', ["altRepeat"] = false},
["Currency"] = {["header"] = 'Value', ["altRepeat"] = true},
["Currency"] = {["header"] = 'Value', ["altRepeat"] = true},
Line 526: Line 528:
}
}
-- Build the table header while we're here
-- Build the table header while we're here
local resultPart, barIDList = {}, {}
local html = mw.html.create('table')
table.insert(resultPart, '{| class="wikitable sortable stickyHeader"\r\n|- class="headerRow-0"')
:addClass('wikitable sortable stickyHeader')
 
local header = html:tag('tr')
:addClass('headerRow-0')
 
local barIDList = {}
for i, colID in ipairs(columnList) do
for i, colID in ipairs(columnList) do
if columnDef[colID] == nil then
if columnDef[colID] == nil then
return Shared.printError('Invalid column ' .. colID .. ' requested')
return Shared.printError('Invalid column ' .. colID .. ' requested')
else
else
table.insert(resultPart, '\r\n! ' .. columnDef[colID].header)
header:tag('th'):wikitext(columnDef[colID].header)
if colID == 'CurrencyBar' then
if colID == 'CurrencyBar' then
-- For Smithing, a currency value per bar column is included. If this
-- For Smithing, a currency value per bar column is included. If this
Line 549: Line 556:
return ''
return ''
end
end
table.sort(recipeList, function(a, b) return a.level < b.level end)
table.sort(recipeList, function(a, b) return Skills.standardRecipeSort(skillName, a, b) end)


-- Build rows based on recipes
-- Build rows based on recipes
Line 568: Line 575:
-- Build one row per element within costList
-- Build one row per element within costList
for recipeRow, costDef in ipairs(costList) do
for recipeRow, costDef in ipairs(costList) do
local rowspanAmt = nil
if recipeRow == 1 and costCount > 1 then
rowspanAmt = costCount
end
local rowspanStr = (recipeRow == 1 and costCount > 1 and 'rowspan="' .. costCount .. '" ') or ''
local rowspanStr = (recipeRow == 1 and costCount > 1 and 'rowspan="' .. costCount .. '" ') or ''
local qty = (costDef.quantityMultiplier or 1) * (recipe.baseQuantity or 1)
local qty = (costDef.quantityMultiplier or 1) * (recipe.baseQuantity or 1)
table.insert(resultPart, '\n|-')
local row = html:tag('tr')
for j, colID in ipairs(columnList) do
for j, colID in ipairs(columnList) do
local altRepeat = columnDef[colID].altRepeat
local altRepeat = columnDef[colID].altRepeat
Line 576: Line 587:
-- for subsequent rows only columns marked as altRepeat = true are generated
-- for subsequent rows only columns marked as altRepeat = true are generated
if recipeRow == 1 or altRepeat then
if recipeRow == 1 or altRepeat then
local spanStr = (not altRepeat and rowspanStr) or ''
local spanAmt = (not altRepeat and rowspanStr) or ''
local cell = row:tag('td')
if not altRepeat and rowspanAmt ~= nil then
cell:attr('rowspan', tostring(rowspanAmt))
end
if colID == 'ItemImage' then
if colID == 'ItemImage' then
table.insert(resultPart, '\n|' .. spanStr .. 'class="table-img"| ' .. Icons.Icon({item.name, type='item', size='50', notext=true}))
cell:wikitext(Icons.Icon({item.name, type='item', size=25, notext=true}))
:addClass('table-img')
elseif colID == "ItemName" then
elseif colID == "ItemName" then
local namePrefix = spanStr
cell:wikitext((qty > 1 and '<b>' .. qty .. 'x</b> ' or '') .. Icons.Icon({item.name, type='item', noicon=true}))
if qty > 1 then
if qty > 1 then
namePrefix = namePrefix .. 'data-sort-value="' .. item.name .. '"'
cell:attr('data-sort-value', item.name)
end
end
table.insert(resultPart, '\n|'.. (namePrefix ~= '' and namePrefix .. '| ' or ' ') .. Icons.getExpansionIcon(item.id) .. (qty > 1 and '<b>' .. qty .. 'x</b> ' or '') .. Icons.Icon({item.name, type='item', noicon=true}))
elseif colID == 'SkillLevel' then
elseif colID == 'SkillLevel' then
table.insert(resultPart, '\n|' .. spanStr .. 'style="text-align:right"| ' .. level)
cell:wikitext(level)
:css('text-align', 'right')
elseif colID == 'DLC' then
cell:wikitext(Icons.getDLCColumnIcon(recipe.id))
:attr('data-sort-value', Icons.getExpansionID(recipe.id))
:css('text-align', 'center')
elseif colID == 'SkillXP' then
elseif colID == 'SkillXP' then
table.insert(resultPart, '\n|' .. spanStr .. 'data-sort-value="' .. baseXP ..'" style="text-align:right"| ' .. Num.formatnum(baseXP))
cell:wikitext(Num.formatnum(baseXP))
:css('text-align', 'right')
:attr('data-sort-value', tostring(baseXP))
elseif colID == 'Currency' then
elseif colID == 'Currency' then
local val = math.floor(item.sellsFor)
local val = math.floor(item.sellsFor)
table.insert(resultPart, '\n|' .. spanStr .. 'data-sort-value="' .. (val * qty) .. '"| ' .. Items.getValueText(item) .. (qty > 1 and ' (x' .. qty .. ')' or ''))
cell:wikitext(Items.getValueText(item) .. (qty > 1 and ' (x' .. qty .. ')' or ''))
:attr('data-sort-value', tostring(val * qty))
elseif colID == 'Ingredients' then
elseif colID == 'Ingredients' then
local matArray = {}
local matArray = {}
local currCost = { ["items"] = {}, ["currencies"] = recipe.currencyCosts }
local currCost = { ["items"] = {}, ["currencies"] = recipe.currencyCosts }
local currText = Common.getCostString(currCost, nil, nil, ', ')
local currText = Common.getCostString(currCost, nil, nil, ' ')
if currText ~= nil then
if currText ~= nil then
table.insert(matArray, currText)
table.insert(matArray, currText)
Line 606: Line 629:
end
end
end
end
table.insert(resultPart, '\n|' .. (spanStr ~= '' and spanStr .. '| ' or ' ') .. table.concat(matArray, ', '))
cell:wikitext(table.concat(matArray, ' '))
elseif colID == 'SkillXPSec' then
elseif colID == 'SkillXPSec' then
table.insert(resultPart, '\n|' .. spanStr .. 'style="text-align:right"| ' .. string.format('%.2f', recipe.baseExperience / actionInterval))
cell:wikitext(string.format('%.2f', recipe.baseExperience / actionInterval))
:css('text-align', 'right')
elseif colID == 'CurrencySec' then
elseif colID == 'CurrencySec' then
local saleCurrency = item.sellsForCurrency or 'melvorD:GP'
local saleCurrency = item.sellsForCurrency or 'melvorD:GP'
local val = math.floor(item.sellsFor) * qty / actionInterval
local val = math.floor(item.sellsFor) * qty / actionInterval
table.insert(resultPart, '\n|' .. spanStr .. 'data-sort-value="' .. val .. '"| ' .. Icons._Currency(saleCurrency, string.format('%.2f', val)))
cell:wikitext(Icons._Currency(saleCurrency, string.format('%.2f', val)))
:attr('data-sort-value', tostring(val))
elseif colID == 'CurrencyBar' then
elseif colID == 'CurrencyBar' then
local barQty = 0
local barQty = 0
Line 623: Line 648:
local saleCurrency = item.sellsForCurrency or 'melvorD:GP'
local saleCurrency = item.sellsForCurrency or 'melvorD:GP'
local barVal = Num.round(math.floor(item.sellsFor) * qty / barQty, 1, 1)
local barVal = Num.round(math.floor(item.sellsFor) * qty / barQty, 1, 1)
table.insert(resultPart, '\n|' .. spanStr .. 'data-sort-value="' .. barVal .. '"| ' .. Icons._Currency(saleCurrency, barVal))
cell:wikitext(Icons._Currency(saleCurrency, barVal))
:attr('data-sort-value', tostring(barVal))
else
else
table.insert(resultPart, '\n|' .. spanStr .. 'data-sort-value="0" class="table-na"| N/A')
cell:wikitext('N/A')
:addClass('table-na')
:attr('data-sort-value', '0')
end
end
elseif colID == 'Description' then
elseif colID == 'Description' then
Line 632: Line 660:
descrip = Modifiers.getModifiersText(item.modifiers, false)
descrip = Modifiers.getModifiersText(item.modifiers, false)
end
end
table.insert(resultPart, '\n| '..spanStr..'|'..descrip)
cell:wikitext(descrip)
else
table.insert(resultPart, '\n| ')
end
end
end
end
Line 641: Line 667:
end
end
end
end
table.insert(resultPart, '\n|}')
return tostring(html)
return table.concat(resultPart)
end
end