Module:ShipCardTable: Difference between revisions
From Corsair Cove Official Wiki
No edit summary |
No edit summary |
||
| Line 64: | Line 64: | ||
function Export.ship_to_wiki(ship_type, cards) | function Export.ship_to_wiki(ship_type, cards) | ||
local cells = { | local cells = { | ||
"'''" .. (ship_type or '') .. "'''" | |||
} | } | ||
| Line 91: | Line 91: | ||
return table.concat({ | return table.concat({ | ||
'{| class="wikitable sortable"', | '{| class="wikitable sortable"', | ||
'! | '! Objective(s) !! class="unsortable" | ' .. | ||
table.concat(headers, ' !! class="unsortable" | '), | table.concat(headers, ' !! class="unsortable" | '), | ||
'|-', | '|-', | ||
Latest revision as of 18:48, 18 August 2026
Documentation for this module may be created at Module:ShipCardTable/doc
local Export = {}
local card_data = require("Module:CardData")
local ship_card_data = require("Module:ShipCardData")
local objective_order = {
{
label = "Chase<br/>Navigate<br/>Outrun<br/>Traverse",
key = "Move"
},
{
label = "Board<br/>Demoralise",
key = "Kill"
},
{
label = "Destroy<br/>Shoot",
key = "Shoot"
},
{
label = "Defend<br/>Endure<br/>Survive",
key = "Defend"
},
{
label = "Sneak<br/>Ambush",
key = "Sneak"
},
{
label = "Threaten",
key = "Threaten"
},
{
label = "Plunder",
key = "Plunder"
}
}
local function escape_html(text)
return text
:gsub('&', '&')
:gsub('<', '<')
:gsub('>', '>')
end
local function cards_to_wiki(cards)
cards = cards or {}
local card_1 = card_data[cards.Card1] or {}
local card_2 = card_data[cards.Card2] or {}
local card_1_text =
"'''Cost:''' " .. tostring(card_1.Cost or 0) ..
"<br/>'''Effect:''' <br/>''" .. escape_html(card_1.Effect or '') .. "''"
local card_2_text =
"'''Cost:''' " .. tostring(card_2.Cost or 0) ..
"<br/>'''Effect:''' <br/>''" .. escape_html(card_2.Effect or '') .. "''"
return table.concat({
'<table class="wikitable" style="min-width: 20vw;">',
'<tr><th style="min-width: 10vw;">Card 1</th><th style="min-width: 10vw;">Card 2</th></tr>',
'<tr><td style="min-width: 10vw;">' .. card_1_text .. '</td><td style="min-width: 10vw;">' .. card_2_text .. '</td></tr>',
'</table>'
}, '')
end
function Export.ship_to_wiki(ship_type, cards)
local cells = {
"'''" .. (ship_type or '') .. "'''"
}
cards = cards or {}
for _, objective in ipairs(objective_order) do
table.insert(cells, cards_to_wiki(cards[objective.key]))
end
return '| ' .. table.concat(cells, '\n| ')
end
function Export.wiki_ship_card_table()
local rows = {}
for ship_type, objective_cards in pairs(ship_card_data) do
table.insert(rows, Export.ship_to_wiki(ship_type, objective_cards))
end
local headers = {}
for _, objective in ipairs(objective_order) do
table.insert(headers, objective.label)
end
return table.concat({
'{| class="wikitable sortable"',
'! Objective(s) !! class="unsortable" | ' ..
table.concat(headers, ' !! class="unsortable" | '),
'|-',
table.concat(rows, '\n|-\n'),
'|}',
''
}, '\n')
end
return Export


