16,254
edits
(Limit height of itemrow to 32px) |
(Fix currency function calls) |
||
(18 intermediate revisions by one other user not shown) | |||
Line 6: | Line 6: | ||
local itemdb = require('Module:Items') | local itemdb = require('Module:Items') | ||
local icons = require('Module:Icons') | local icons = require('Module:Icons') | ||
local StringBuilder = require('Module:StringBuilder') | |||
-- Constants | -- Constants | ||
Line 18: | Line 19: | ||
aod = icons.AoD(), | aod = icons.AoD(), | ||
ita = icons.ItA() | ita = icons.ItA() | ||
} | |||
local SpecialItems = { | |||
['GP'] = 'Gold Pieces', | |||
['SC'] = 'Slayer Coins', | |||
} | |||
local SpecialIcons = { | |||
['Gold Pieces'] = icons._Currency('melvorD:GP'), | |||
['Slayer Coins'] = icons._Currency('melvorD:SlayerCoins'), | |||
} | } | ||
Line 32: | Line 43: | ||
local function formatItemName(name) | local function formatItemName(name) | ||
-- Special case to correctly format GP name. | -- Special case to correctly format GP name. | ||
if | if SpecialItems[name] then | ||
return SpecialItems[name] | |||
end | |||
-- Got to solve too many edge case swith this (like of and IV) | -- Got to solve too many edge case swith this (like of and IV) | ||
-- Better just make the user use the correct name instead. | -- Better just make the user use the correct name instead. | ||
Line 61: | Line 72: | ||
local function getItemIcon(iconName) | local function getItemIcon(iconName) | ||
if iconName | if SpecialIcons[iconName] then | ||
return | return SpecialIcons[iconName] | ||
end | end | ||
return icons.Icon({iconName, type='item', notext=true}) | return icons.Icon({iconName, type='item', notext=true}) | ||
end | end | ||
Line 75: | Line 86: | ||
return icon .. ' ' .. expValue | return icon .. ' ' .. expValue | ||
end | |||
local function parseProfitMargin(minProfit, maxProfit) | |||
-- Manually set maxProfit to numeric 0, only if it's nil. | |||
if maxProfit == nil then maxProfit = 0 end | |||
local min = tonumber(minProfit) | |||
local max = tonumber(maxProfit) | |||
if max == nil then | |||
error("maxProfit is not a valid number.") | |||
end | |||
local sb = StringBuilder:new() | |||
if min then | |||
sb :append(icons._Currency('melvorD:GP', num.round2(min))) | |||
:append(' to ') | |||
end | |||
sb :append(icons._Currency('melvorD:GP', num.round2(max))) | |||
:append(' per hour') | |||
return sb:toString() | |||
end | end | ||
Line 140: | Line 174: | ||
local pSkill = formatSkillName(args[skillPrefix]) | local pSkill = formatSkillName(args[skillPrefix]) | ||
local pExp = args[skillPrefix .. AmountSuffix] | local pExp = tonumber(args[skillPrefix .. AmountSuffix]) | ||
table.insert(skills, { | table.insert(skills, { | ||
prmNumber = i, | prmNumber = i, | ||
Line 152: | Line 182: | ||
end | end | ||
-- Return nil if there is no experience earned. | |||
-- Lets the parent table know to enter 'None' instead | |||
if #skills == 0 then | |||
return nil | |||
end | |||
return skills | return skills | ||
end | end | ||
Line 181: | Line 216: | ||
local imgCell = mw.html.create('td') | local imgCell = mw.html.create('td') | ||
:wikitext(getItemIcon(i.name)) | :wikitext(getItemIcon(i.name)) | ||
:css('height', ' | :css('height', '28px') | ||
:done() | :done() | ||
Line 193: | Line 228: | ||
qtyCell:node(getErrorDiv("Unable to parse quantity for item: " .. i.name)) | qtyCell:node(getErrorDiv("Unable to parse quantity for item: " .. i.name)) | ||
else | else | ||
local qty = i.amount | local qty = num.autoround(i.amount) | ||
qtyCell:wikitext(num.formatnum(qty)) | qtyCell:wikitext(num.formatnum(qty)) | ||
end | end | ||
Line 203: | Line 238: | ||
else | else | ||
local tot = i.value * (i.amount or 0) | local tot = i.value * (i.amount or 0) | ||
valCell:wikitext(icons.GP | valCell | ||
:css('text-align','right') | |||
:wikitext(icons._Currency('melvorD:GP', num.round2(tot))) | |||
:attr("data-sort-value", tot) | |||
end | end | ||
valCell:done() | valCell:done() | ||
Line 255: | Line 293: | ||
local pOutputs = parseItemInOut(args, 'output') | local pOutputs = parseItemInOut(args, 'output') | ||
local dlcIcons = p.getDLCIcons(args['dlc'], ' ') | local dlcIcons = p.getDLCIcons(args['dlc'], ' ') | ||
local minProfit = args['minimumProfit'] | |||
local maxProfit = pOutputs.TotalValue - pInputs.TotalValue | |||
local tbl = mw.html.create() | local tbl = mw.html.create() | ||
Line 264: | Line 304: | ||
:tag("td") | :tag("td") | ||
:attr("colspan", 2) | :attr("colspan", 2) | ||
:css('font-weight', 'bold') | |||
:wikitext(table.concat(dlcIcons) .. ' ') | :wikitext(table.concat(dlcIcons) .. ' ') | ||
:wikitext(args['guideName'] or '{{{guideName}}}') | :wikitext(args['guideName'] or '{{{guideName}}}') | ||
:tag("tr") | |||
:tag("td") | |||
:attr("colspan", 2) | |||
:wikitext(parseProfitMargin(minProfit, maxProfit)) | |||
:tag("tr") | :tag("tr") | ||
:tag("th") | :tag("th") | ||
Line 278: | Line 323: | ||
:tag("tr") | :tag("tr") | ||
:tag("td") | :tag("td") | ||
:addClass('mmg-no-list') | |||
:newline() | |||
:wikitext(paramtest.default_to(args['skills'], 'None')) | |||
:tag("td") | :tag("td") | ||
:addClass('mmg-no-list') | |||
:newline() | |||
:wikitext(paramtest.default_to(args['other'], 'None')) | |||
:tag('tr') | :tag('tr') | ||
:tag('th') | :tag('th') | ||
Line 288: | Line 337: | ||
:tag('tr') | :tag('tr') | ||
:tag('td') | :tag('td') | ||
:addClass('mmg-no-list') | |||
:newline() | |||
:wikitext(paramtest.default_to(args['items'], 'None')) | :wikitext(paramtest.default_to(args['items'], 'None')) | ||
:tag('td') | :tag('td') | ||
:addClass('mmg-no-list') | |||
:newline() | |||
:wikitext(paramtest.default_to(args['recommended'], 'None')) | :wikitext(paramtest.default_to(args['recommended'], 'None')) | ||
:tag("tr") | :tag("tr") | ||
Line 303: | Line 356: | ||
:tag("td") | :tag("td") | ||
if args['profit'] then | if args['profit'] then | ||
html:wikitext(icons.GP | html:wikitext(icons._Currency('melvorD:GP', num.round2(args['profit']))) | ||
else | else | ||
html:wikitext(icons.GP | html:wikitext(icons._Currency('melvorD:GP', num.round2(maxProfit))) | ||
end | end | ||
html = html | html = html | ||
Line 322: | Line 375: | ||
:wikitext("Inputs") | :wikitext("Inputs") | ||
if pInputs.TotalValue ~= 0 then | if pInputs.TotalValue ~= 0 then | ||
html:wikitext(" (" .. icons.GP | html:wikitext(" (" .. icons._Currency('melvorD:GP', num.round2(pInputs.TotalValue)) .. ")") | ||
end | end | ||
html = html | html = html | ||
Line 328: | Line 381: | ||
:wikitext("Outputs") | :wikitext("Outputs") | ||
if pOutputs.TotalValue ~= 0 then | if pOutputs.TotalValue ~= 0 then | ||
html:wikitext(" (" .. icons.GP | html:wikitext(" (" .. icons._Currency('melvorD:GP', num.round2(pOutputs.TotalValue)) .. ")") | ||
end | end | ||
html = html | html = html | ||
Line 384: | Line 437: | ||
end | end | ||
function p.test() | |||
local args = { | |||
guideName ='Mining Pure Crystal', | |||
category ='Non-combat', | |||
dlc ='aod, toth', | |||
skills =[[ | |||
*{{SkillReq|Mining|85}} | |||
*{{SkillReq|Herblore|53}}]], | |||
items =[=[ | |||
*{{ItemIcon|Mining Gloves}} | |||
*{{ItemIcon|Perfect Swing Potion IV}}]=], | |||
other =[=[ | |||
*{{ItemIcon|Pure Crystal|notext=true}}{{Icon|Mastery|notext=true}} Level 99 | |||
*{{UpgradeIcon|Dragon Pickaxe}} | |||
*[[Mining#Mastery Pool Checkpoints|95% Mining Mastery Pool Checkpoint]]]=], | |||
recommended =[=[ | |||
[[Money_Making/Mining_Pure_Crystal#Improves_GP_Rate|Bonusses that improve profit]]]=], | |||
} | |||
local t = p._buildMMGTable(args) | |||
mw.log(t) | |||
end | |||
-- function p.test() | -- function p.test() |