Module:StoreTableHeader: Difference between revisions

From Discord Dungeons Wiki
Jump to navigation Jump to search
(Created page with "local p = {} local params = require('Module:Paramtest') local yesno = require('Module:Yesno') local var = mw.ext.VariablesLua function p.main(frame) local args = frame:getParent().args local currency,namenotes,smw,hideimage,hidebuy,hidesell,hidecaption = params.defaults{ {args.currency,'Gold'}, {args.namenotes,''}, {args.smw,'yes'}, {args.hideimage,'no'}, {args.hidebuy,'no'}, {args.hidesell,'no'}, {args.hidecaption,'no'} } var.vardefine('Curr...")
 
No edit summary
Line 7: Line 7:
function p.main(frame)
function p.main(frame)
     local args = frame:getParent().args
     local args = frame:getParent().args
     local currency,namenotes,smw,hideimage,hidebuy,hidesell,hidecaption = params.defaults{
     local currency,namenotes,smw,hideimage,hidebuy,hidesell = params.defaults{
{args.currency,'Gold'},
{args.currency,'Gold'},
{args.namenotes,''},
{args.namenotes,''},
Line 14: Line 14:
{args.hidebuy,'no'},
{args.hidebuy,'no'},
{args.hidesell,'no'},
{args.hidesell,'no'},
{args.hidecaption,'no'}
}
}
     var.vardefine('Currency', currency)
     var.vardefine('Currency', currency)
     var.vardefine('NameNotes', namenotes)
     var.vardefine('NameNotes', namenotes)
    var.vardefine('Delta', delta)
     var.vardefine('smw', smw)
     var.vardefine('smw', smw)
     var.vardefine('hideImage', hideimage)
     var.vardefine('hideImage', hideimage)
Line 25: Line 23:
      
      
     local ret = mw.html.create('')
     local ret = mw.html.create('')
    if not(yesno(hidecaption)) then
 
        ret:tag('caption')
            :css('white-space','nowrap')
            :wikitext(string.format('Sells at: [[Store sell ratio::%.1f]]%% • Buys at: [[Store buy ratio::%.1f]]%% • Change per: [[Store price delta::%.1f]]%%',sellmultiplier/10,buymultiplier/10,delta/10))
            :done()
    end
     ret:tag('tr')
     ret:tag('tr')
     local colspan = yesno(hideimage) and 1 or 2
     local colspan = yesno(hideimage) and 1 or 2
     ret:tag('th'):attr('colspan', colspan):wikitext('Item'):done()
     ret:tag('th'):attr('colspan', colspan):wikitext('Item'):done()
    if not(yesno(hidestock)) then
        ret:tag('th'):attr('data-sort-type', 'number'):wikitext('Number<br>in stock'):done()
    end
    if not(yesno(hiderestock)) then
        ret:tag('th'):attr('data-sort-type', 'number'):wikitext('Restock<br/>time'):done()
    end
     if not(yesno(hidesell)) then
     if not(yesno(hidesell)) then
         ret:tag('th'):attr('data-sort-type', 'number'):wikitext('Price<br>sold at'):done()
         ret:tag('th'):attr('data-sort-type', 'number'):wikitext('Price<br>sold at'):done()
Line 45: Line 32:
     if not(yesno(hidebuy)) then
     if not(yesno(hidebuy)) then
         ret:tag('th'):attr('data-sort-type', 'number'):wikitext('Price<br>bought at'):done()
         ret:tag('th'):attr('data-sort-type', 'number'):wikitext('Price<br>bought at'):done()
    end
    if not(yesno(hidege)) then
        ret:tag('th'):attr('data-sort-type', 'number'):wikitext('[[Grand Exchange|GE <br>price]]'):done()
     end
     end
     local i = 1
     local i = 1

Revision as of 12:45, 3 April 2022

Documentation for this module may be created at Module:StoreTableHeader/doc

local p = {}

local params = require('Module:Paramtest')
local yesno = require('Module:Yesno')
local var = mw.ext.VariablesLua

function p.main(frame)
    local args = frame:getParent().args
    local currency,namenotes,smw,hideimage,hidebuy,hidesell = params.defaults{
		{args.currency,'Gold'},
		{args.namenotes,''},
		{args.smw,'yes'},
		{args.hideimage,'no'},
		{args.hidebuy,'no'},
		{args.hidesell,'no'},
	}
    var.vardefine('Currency', currency)
    var.vardefine('NameNotes', namenotes)
    var.vardefine('smw', smw)
    var.vardefine('hideImage', hideimage)
    var.vardefine('hideBuy', hidebuy)
    var.vardefine('hideSell', hidesell)
    
    local ret = mw.html.create('')

    ret:tag('tr')
    local colspan = yesno(hideimage) and 1 or 2
    ret:tag('th'):attr('colspan', colspan):wikitext('Item'):done()
    if not(yesno(hidesell)) then
        ret:tag('th'):attr('data-sort-type', 'number'):wikitext('Price<br>sold at'):done()
    end
    if not(yesno(hidebuy)) then
        ret:tag('th'):attr('data-sort-type', 'number'):wikitext('Price<br>bought at'):done()
    end
    local i = 1
    while args['column' .. i] do
        ret:tag('th'):attr('data-sort-type', 'number'):wikitext(args['column' .. i]):done()
        i = i+1
    end
    ret:done()
    return '<table class="wikitable sortable" style="text-align:center; margin:0;" cellpadding="2" cellspacing="0">' .. tostring(ret)
end
    
return p