Module:SS Upgrade

-- This module serves as the code for Template:SS Upgrade local p = {} local cargo = mw.ext.cargo local Term = require("Module:Term")

-- Fetches and display all the upgrades for the given base item function p._FetchAndDisplayFromBaseItem(frame) local args = frame.args return p.FetchAndDisplayFromBaseItem(args["base"]) end

function p.FetchAndDisplayFromBaseItem(base) local upgrades = p.GetUpgradesFromBase(base) local result = mw.html.create('div'):done result:node(p.CreateDesktopTable(upgrades)) result:node(p.CreateMobileTable(upgrades)) return result end

function p.GetUpgradesFromBase(base) local tables = 'SSUpgrades' local fields = 'item, description, materials, cost, location' local queryArgs = { where = 'base = "' .. base .. '"' }   return cargo.query( tables, fields, queryArgs ) end

function p.CreateDesktopTable(upgrades) local resultDiv = mw.html.create('div') :addClass('no-mobile'):done local resultTable = mw.html.create('table') :addClass('wikitable'):done local header = mw.html.create('tr'):done local headerText = mw.html.create('th') :wikitext('Upgrade'):done header:node(headerText) headerText = mw.html.create('th') :wikitext('Description'):done header:node(headerText) headerText = mw.html.create('th') :wikitext('Materials'):done header:node(headerText) headerText = mw.html.create('th') :wikitext('Cost'):done header:node(headerText) headerText = mw.html.create('th') :wikitext('Location'):done header:node(headerText) resultTable:node(header) for _, upgrade in ipairs(upgrades) do		local row = mw.html.create('tr'):done local data = mw.html.create('td') :addClass('centered') :wikitext(" " .. Term.printTerm({game = "SS", page = upgrade["item"], link = "link"}) .. ""):done row:node(data) data = mw.html.create('td') :wikitext(upgrade["description"]):done row:node(data) data = mw.html.create('td') :wikitext(upgrade["materials"]):done row:node(data) data = mw.html.create('td') :wikitext("" .. upgrade["cost"] .. " " .. Term.printTerm({page = "Rupee", game = "SS", link = "link"}, true)):done row:node(data) data = mw.html.create('td') :wikitext(Term.printTerm({game = "Series", page = upgrade["location"], link = "link"})):done row:node(data) resultTable:node(row) end resultDiv:node(resultTable) return resultDiv end

function p.CreateMobileTable(upgrades) local resultDiv = mw.html.create('div') :addClass('mobile-only'):done local resultTable = mw.html.create('table') :addClass('wikitable compressed'):done for _, upgrade in ipairs(upgrades) do		local tr = mw.html.create('tr'):done local th = mw.html.create('th') :addClass('centered') :attr("colspan", "2") :wikitext(" " .. Term.printTerm({game = "SS", page = upgrade.item, link = "link"}) .. ""):done tr:node(th) resultTable:node(tr) tr = mw.html.create('tr'):done td = mw.html.create('td') :wikitext("Description"):done tr:node(td) td = mw.html.create('td') :wikitext(upgrade["description"]) tr:node(td) resultTable:node(tr) tr = mw.html.create('tr'):done td = mw.html.create('td') :wikitext("Materials"):done tr:node(td) td = mw.html.create('td') :wikitext(upgrade["materials"]) tr:node(td) resultTable:node(tr) tr = mw.html.create('tr'):done td = mw.html.create('td') :wikitext("Cost"):done tr:node(td) td = mw.html.create('td') :wikitext("" .. upgrade.cost .. " " .. Term.printTerm({game = "SS", page = "Rupee", link = "link"}, true)) tr:node(td) resultTable:node(tr) tr = mw.html.create('tr'):done td = mw.html.create('td') :wikitext("Location"):done tr:node(td) td = mw.html.create('td') :wikitext(Term.printTerm({game = "Series", page = upgrade.location, link = "link"})) tr:node(td) resultTable:node(tr) end resultDiv:node(resultTable) return resultDiv end

return p