Module:PotionList: Difference between revisions

Jump to navigation Jump to search
Content added Content deleted
(Undo revision 49590 by Artoire (talk): Sorting breaks up cells with rowspan)
Tag: Undo
m (Remove unused vars)
Line 1: Line 1:
require('strict')
require('Module:Mw.html extension')
require('Module:Mw.html extension')
local param = require( 'Module:Paramtest' )
local param = require( 'Module:Paramtest' )
local currency = require('Module:Currency')
local currency = require('Module:Currency')
local lang = mw.getContentLanguage()
local lang = mw.getContentLanguage()
require("Module:Mw.html extension")



local p = {}
local p = {}
Line 10: Line 9:
-- non dynamic module, no inputs
-- non dynamic module, no inputs
function p.main()
function p.main()

-- returns almost every parameter needed for the row, except buy values for reagents
-- returns almost every parameter needed for the row, except buy values for reagents
local query = {
local query = {
Line 53: Line 51:


-- iterate through potions
-- iterate through potions
for i, item in ipairs(results) do
for _, item in ipairs(results) do


--in case of single reagent potions, make table of 1 element
--in case of single reagent potions, make table of 1 element
Line 63: Line 61:
-- starting value 20 is for bottle
-- starting value 20 is for bottle
item.buy = 20
item.buy = 20
for j, reagent in ipairs(item.reagents) do
for _, reagent in ipairs(item.reagents) do


--shamelessley lifted from Module:Products
--shamelessley lifted from Module:Products
Line 76: Line 74:
item.buy = item.buy + shopPrice
item.buy = item.buy + shopPrice
end
end

-- sanitise data, set to 0 if its not there
local lvl = item.lvl or '?'
local buy = item.buy or 0
local sell = item.sell or 0
local brewXP = item.brewXP or 0
local prepXP = item.prepXP or 0
local brewKP = item.brewKP or 0
local prepKP = item.prepKP or 0
local brewDuration = item.brewDuration or 0
local prepDuration = item.prepDuration or 0


-- direct values
-- direct values
Line 111: Line 98:
-- make the table
-- make the table
function p.displayTable(results)
function p.displayTable(results)

local out = mw.html.create('table')
local out = mw.html.create('table')
:addClass('wikitable sortable')
:addClass('wikitable sortable')
Line 151: Line 137:
:done()
:done()
:done()
:done()


for i,item in ipairs(results) do

-- need to generate the text for the reagent cell before starting the row
local reagentCell = ''
for j, reagent in ipairs(item.reagents) do
reagentCell = reagentCell .. '[[File:' .. reagent .. '.png|30px|link=' .. reagent .. ']] [[' .. reagent .. ']]<br>'
end


local unknown_value_cell = mw.html.create('td')
local unknown_value_cell = mw.html.create('td')
Line 166: Line 143:
:wikitext("''unknown''")
:wikitext("''unknown''")


for i, item in ipairs(results) do
out
:tag('tr')
local row = out:tag('tr')
:IF(item.lvl)
:IF(item.lvl)
:tag('td')
:tag('td')
Line 181: Line 158:
:done()
:done()


:tag('td')
local reagentCell = row:tag('td')
:wikitext(reagentCell)
:done()


:wikitext(currency_cell(item.buy))
for j, reagent in ipairs(item.reagents) do
reagentCell:wikitext('[[File:' .. reagent .. '.png|30px|link=' .. reagent .. ']] [[' .. reagent .. ']]<br>')
end


row
:wikitext(currency_cell(item.buy))
:wikitext(currency_cell(item.sell))
:wikitext(currency_cell(item.sell))

:wikitext(currency_cell(item.profit))
:wikitext(currency_cell(item.profit))

:wikitext(currency_cell(item.profitPerHour))
:wikitext(currency_cell(item.profitPerHour))


Line 212: Line 189:


:done()
:done()

end
end