Module:MoneyMakingGuide: Difference between revisions

Fix styling issues with lists
No edit summary
(Fix styling issues with lists)
 
(17 intermediate revisions by the same 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 19: Line 20:
ita = icons.ItA()
ita = icons.ItA()
}
}
--- Possible fix to allow wikicode (especially tables) to be passed to the 'explanation'
--- parameter, and get parsed by the wiki parser on return.
-- Not used currently, because it might not be necessary at all.
local function processMarkup(str)
--return frame:preprocess(str)
end


--- Formats a given string to TitleCase.
--- Formats a given string to TitleCase.
-- @param name (string) String to format.
-- @param name (string) String to format.
-- @return (string) Formatted string, or the input if it's not a string.
-- @return (string) Formatted string, or the input if it's not a string.
local function formatName(name)
local function formatItemName(name)
-- Special case to correctly format GP name.
-- Special case to correctly format GP name.
if shared.compareString(name, 'Gold Pieces', true) or shared.compareString(name, 'GP', true) then
if shared.compareString(name, 'Gold Pieces', true) or shared.compareString(name, 'GP', true) then
Line 29: Line 37:
end
end
-- Got to solve too many edge case swith this (like of and IV)
-- Better just make the user use the correct name instead.
--if type(name) == 'string' then
-- return shared.titleCase(name)
--end
return name
end
local function formatSkillName(name)
if type(name) == 'string' then
if type(name) == 'string' then
return shared.titleCase(name)
return shared.titleCase(name)
Line 58: Line 76:
return icon .. ' ' .. expValue
return icon .. ' ' .. expValue
end
local function parseProfitMargin(minProfit, maxProfit)
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.GP(num.round2(min / 1000)))
:append('k/hr Minimum ~ ')
end
sb  :append(icons.GP(num.round2(max / 1000)))
:append('k/hr Maximum')
return sb:toString()
end
end


Line 76: Line 115:
end
end
local pName = formatName(args[numPrefix])
local pName = formatItemName(args[numPrefix])
local pAmount = args[numPrefix .. AmountSuffix]
local pAmount = args[numPrefix .. AmountSuffix]
local pValue = args[numPrefix .. ValueSuffix]
local pValue = args[numPrefix .. ValueSuffix]
Line 122: Line 161:
end
end
local pSkill = formatName(args[skillPrefix])
local pSkill = formatSkillName(args[skillPrefix])
local pExp = args[skillPrefix .. AmountSuffix]
local pExp = tonumber(args[skillPrefix .. AmountSuffix])


if paramtest.has_content(pExp) then
pExp = tonumber(pExp)
end
table.insert(skills, {
table.insert(skills, {
prmNumber = i,
prmNumber = i,
Line 135: Line 170:
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 164: Line 204:
local imgCell = mw.html.create('td')
local imgCell = mw.html.create('td')
:wikitext(getItemIcon(i.name))
:wikitext(getItemIcon(i.name))
:css('height', '28px')
:done()
:done()
Line 175: Line 216:
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 = num.round2(i.amount)
local qty = num.autoround(i.amount)
qtyCell:wikitext(num.formatnum(qty))
qtyCell:wikitext(num.formatnum(qty))
end
end
Line 185: Line 226:
else
else
local tot = i.value * (i.amount or 0)
local tot = i.value * (i.amount or 0)
valCell:wikitext(icons.GP(num.round2(tot)))
valCell
:css('text-align','right')
:wikitext(icons.GP(num.round2(tot)))
:attr("data-sort-value", tot)
end
end
valCell:done()
valCell:done()
Line 237: Line 281:
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 246: Line 292:
         :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 260: Line 311:
     :tag("tr")
     :tag("tr")
         :tag("td")
         :tag("td")
        :wikitext(paramtest.default_to(args['skills'], 'None'))  
        :addClass('mmg-no-list')
        :newline()
        :wikitext(paramtest.default_to(args['skills'], 'None'))  
     :tag("td")
     :tag("td")
        :wikitext(paramtest.default_to(args['other'], 'None'))  
            :addClass('mmg-no-list')
        :newline()
        :wikitext(paramtest.default_to(args['other'], 'None'))  
     :tag('tr')
     :tag('tr')
         :tag('th')
         :tag('th')
Line 270: Line 325:
     :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 287: Line 346:
         html:wikitext(icons.GP(num.round2(args['profit'])))
         html:wikitext(icons.GP(num.round2(args['profit'])))
         else
         else
         html:wikitext(icons.GP(num.round2(pOutputs.TotalValue - pInputs.TotalValue)))
         html:wikitext(icons.GP(num.round2(maxProfit)))
         end
         end
         html = html
         html = html
Line 365: Line 424:
error("Call a specific function rather than main.")
error("Call a specific function rather than main.")
end
end


function p.test()
function p.test()
local args = {
local args = {
guideName = "",
guideName       ='Mining Pure Crystal',
interval = "",
category        ='Non-combat',
skills = "",
dlc              ='aod, toth',
items = "",
skills          =[[
other = "",
*{{SkillReq|Mining|85}}
recommended = "",
*{{SkillReq|Herblore|53}}]],
skillExp1 = "Maagic",
items            =[=[
skillExp1amount = "-1000",
*{{ItemIcon|Mining Gloves}}
skillExp2 = "Mining",
*{{ItemIcon|Perfect Swing Potion IV}}]=],
skillExp2amount = "420",
other            =[=[
input1 = "nature rune",
*{{ItemIcon|Pure Crystal|notext=true}}{{Icon|Mastery|notext=true}} Level 99
input1amount = "5",
*{{UpgradeIcon|Dragon Pickaxe}}
input1value = "69",
*[[Mining#Mastery Pool Checkpoints|95% Mining Mastery Pool Checkpoint]]]=],
input2 = "Fire Rune",
recommended      =[=[
input2amount = "20",
[[Money_Making/Mining_Pure_Crystal#Improves_GP_Rate|Bonusses that improve profit]]]=],
output1 = "gp",
output1amount = "1050",
category = "",
dlc = "aod, toth",
intensity = "",
explanation = ""
}
}
mw.log(p._buildMMGTable(args))
local t = p._buildMMGTable(args)
mw.log(t)
end
end
-- function p.test()
-- local args = {
-- guideName = "",
-- interval = "",
-- skills = "",
-- items = "",
-- other = "",
-- recommended = "",
-- skillExp1 = "Maagic",
-- skillExp1amount = "-1000",
-- skillExp2 = "Mining",
-- skillExp2amount = "420",
-- input1 = "nature rune",
-- input1amount = "5",
-- input1value = "69",
-- input2 = "Fire Rune",
-- input2amount = "20",
-- output1 = "gp",
-- output1amount = "1050",
-- category = "",
-- dlc = "aod, toth",
-- intensity = "",
-- explanation = ""
-- }
--
-- mw.log(p._buildMMGTable(args))
-- end


return p
return p
918

edits