Module:Sandbox/User:Kelsey/StoreTableHead

From RuneRealm Wiki

This is the current revision of this page, as edited by Alex (talk | contribs) at 00:13, 17 October 2024 (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 buymultiplier,sellmultiplier,currency,namenotes,delta,smw,hideimage,hidege,hidebuy,hidesell,hidestock,hiderestock,hidecaption,shopversion,membersOverride,locationOverride = params.defaults{ {args.buymultiplier,1000}, {args.sellmultipl..."). The present address (URL) is a permanent link to this version.

(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
Module documentation
This documentation is transcluded from Template:Module sandbox/doc. [edit] [history] [purge]
Module:Sandbox/User:Kelsey/StoreTableHead requires Module:Paramtest.
Module:Sandbox/User:Kelsey/StoreTableHead requires Module:Yesno.

This module is a sandbox for Kelsey. It can be used to test changes to existing modules, prototype new modules, or just experimenting with lua features.

Invocations of this sandbox should be kept in userspace; if the module is intended for use in other namespaces, it should be moved out of the sandbox into a normal module and template.

This default documentation can be overridden by creating the /doc subpage of this module, as normal.

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 buymultiplier,sellmultiplier,currency,namenotes,delta,smw,hideimage,hidege,hidebuy,hidesell,hidestock,hiderestock,hidecaption,shopversion,membersOverride,locationOverride = params.defaults{
                    {args.buymultiplier,1000},
                    {args.sellmultiplier,1000},
                    {args.currency,'Coins'},
                    {args.namenotes,''},
                    {args.delta,0},
                    {args.smw,'yes'},
                    {args.hideimage,'no'},
                    {args.hidege,'no'},
                    {args.hidebuy,'no'},
                    {args.hidesell,'no'},
                    {args.hidestock,'no'},
                    {args.hiderestock,'no'},
                    {args.hidecaption,'no'},
                    {args.shopversion,''},
                    {args.members,''},
                    {args.location,''}
                }
    var.vardefine('BuyMultiplier', buymultiplier)
    var.vardefine('SellMultiplier', sellmultiplier)
    var.vardefine('Currency', currency)
    var.vardefine('NameNotes', namenotes)
    var.vardefine('Delta', delta)
    var.vardefine('smw', smw)
    var.vardefine('hideImage', hideimage)
    var.vardefine('hideGE', hidege)
    var.vardefine('hideBuy', hidebuy)
    var.vardefine('hideSell', hidesell)
    var.vardefine('hideStock', hidestock)
    var.vardefine('hideRestock', hiderestock)
    var.vardefine('ShopVersion', shopversion)
    var.vardefine('StoreTable_MembersOverride', membersOverride)
    var.vardefine('StoreTable_LocationOverride', locationOverride)
    
    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')
    local colspan = yesno(hideimage) and 1 or 2
    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
        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
    if not(yesno(hidege)) then
        ret:tag('th'):attr('data-sort-type', 'number'):wikitext('[[Grand Exchange|GE <br>price]]'):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;">' .. tostring(ret)
end
    
return p