Module:Construction: Difference between revisions
From Against the Storm Official Wiki
Created to make building material tables easier |
m I forgot how variables work loooool |
||
| Line 38: | Line 38: | ||
row:tag("td"):wikitext(BOLD .. amount .. BOLD):done() | row:tag("td"):wikitext(BOLD .. amount .. BOLD):done() | ||
row:tag("td"):wikitext(resourceLink):done() | row:tag("td"):wikitext(resourceLink):done() | ||
row:done() | row:done():newline() | ||
return row | return row | ||
| Line 55: | Line 55: | ||
function Construction.renderTable(frame) | function Construction.renderTable(frame) | ||
local planks = frame.args. | local planks = frame.args.planks | ||
local bricks = frame.args. | local bricks = frame.args.bricks | ||
local fabric = frame.args. | local fabric = frame.args.fabric | ||
local parts = frame.args. | local parts = frame.args.parts | ||
local htmlTable = mw.html.create("table") | local htmlTable = mw.html.create("table") | ||
Revision as of 16:42, 28 November 2023
Documentation for this module may be created at Module:Construction/doc
---
--- Generates a small, inline-style table to show building materials. I tried
--- to do this with parser functions, but couldn't control the layout enough.
---
---@module Construction
local Construction = {}
--region Private constants
local RL_PLANKS = mw.getCurrentFrame():expandTemplate{ title="rl", args = {
resource = "Planks", iconsize = "med" } }
local RL_BRICKS = mw.getCurrentFrame():expandTemplate{ title="rl", args = {
resource = "Bricks", iconsize = "med" } }
local RL_FABRIC = mw.getCurrentFrame():expandTemplate{ title="rl", args = {
resource = "Fabric", iconsize = "med" } }
local RL_PARTS = mw.getCurrentFrame():expandTemplate{ title="rl", args = {
resource = "Parts", iconsize = "med" } }
local BOLD = "'''"
--endregion
--region Private methods
---
--- Adds a simple table row with data cells to the provided HTML table entity.
---
---@param htmlTable table an HTML table entity
---@param amount number of building material
---@param resourceLink string one of the constants representing a resource link template invocation
local function makeRow(htmlTable, amount, resourceLink)
local row = htmlTable:tag("tr")
row:tag("td"):wikitext(BOLD .. amount .. BOLD):done()
row:tag("td"):wikitext(resourceLink):done()
row:done():newline()
return row
end
--endregion
--region Public methods
---
--- Writes a simple HTML table with the specified template parameters
---
---@param frame table MediaWiki context
function Construction.renderTable(frame)
local planks = frame.args.planks
local bricks = frame.args.bricks
local fabric = frame.args.fabric
local parts = frame.args.parts
local htmlTable = mw.html.create("table")
if planks and planks > 0 then
makeRow(htmlTable, planks, RL_PLANKS)
end
if bricks and bricks > 0 then
makeRow(htmlTable, bricks, RL_BRICKS)
end
if fabric and fabric > 0 then
makeRow(htmlTable, fabric, RL_FABRIC)
end
if parts and parts > 0 then
makeRow(htmlTable, parts, RL_PARTS)
end
return htmlTable
end
--endregion
return Construction


