17,428
edits
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. | ["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 | local html = mw.html.create('table') | ||
: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 | ||
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 | 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) | ||
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 | 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 | ||
cell:wikitext(Icons.Icon({item.name, type='item', size=25, notext=true})) | |||
:addClass('table-img') | |||
elseif colID == "ItemName" then | elseif colID == "ItemName" then | ||
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 | ||
cell:attr('data-sort-value', item.name) | |||
end | end | ||
elseif colID == 'SkillLevel' then | elseif colID == 'SkillLevel' then | ||
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 | ||
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) | ||
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 | ||
cell:wikitext(table.concat(matArray, ' ')) | |||
elseif colID == 'SkillXPSec' then | elseif colID == 'SkillXPSec' then | ||
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 | ||
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) | ||
cell:wikitext(Icons._Currency(saleCurrency, barVal)) | |||
:attr('data-sort-value', tostring(barVal)) | |||
else | else | ||
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 | ||
cell:wikitext(descrip) | |||
end | end | ||
end | end | ||
Line 641: | Line 667: | ||
end | end | ||
end | end | ||
return tostring(html) | |||
return | |||
end | end | ||