Module:ShipCardTable: Difference between revisions

From Corsair Cove Official Wiki
Dorce (talk | contribs)
No edit summary
Dorce (talk | contribs)
No edit summary
Line 53: Line 53:
     end
     end


return "<nowiki>" .. table.concat({
return table.concat({
    '{| class="wikitable sortable"',
    '{| class="wikitable sortable"',
    '! class="unsortable" | Ship Type !! ' .. table.concat(objective_order, ' !! '),
    '! class="unsortable" | Ship Type !! ' .. table.concat(objective_order, ' !! '),
Line 60: Line 60:
    '|}',
    '|}',
    ''
    ''
}, '\n') .. "</nowiki>"
}, '\n')
end
end


return Export
return Export

Revision as of 18:02, 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 = {
    "Chase",
    "Navigate",
    "Outrun",
    "Traverse",
    "Board",
    "Demoralise",
    "Destroy",
    "Shoot",
    "Defend",
    "Survive",
    "Sneak",
    "Threaten",
    "Plunder",
}

local function cards_to_wiki(cards)
    cards = cards or {}

    return table.concat({
        '{| class="wikitable"',
        '! Card 1 !! Card 2',
        '|-',
        '| ' .. (cards.Card1 or '') .. ' || ' .. (cards.Card2 or ''),
        '|}'
    }, '\n')
end

function Export.ship_to_wiki(ship_type, cards)
    local objectives = {}

    cards = cards or {}

    for _, objective in ipairs(objective_order) do
        table.insert(objectives, cards_to_wiki(cards[objective]))
    end

    return table.concat({
        '| ' .. (ship_type or ''),
        table.concat(objectives, '\n| '),
    }, '\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

	return table.concat({
	    '{| class="wikitable sortable"',
	    '! class="unsortable" | Ship Type !! ' .. table.concat(objective_order, ' !! '),
	    '|-',
	    table.concat(rows, '\n|-\n'),
	    '|}',
	    ''
	}, '\n')
end

return Export