Module:MapNodesTable

local getArgs = require('Module:GetArgs') local format = require('Module:StringInterpolation').format local EnemyShip = require("Module:EnemyShip") local ShipBattleCardKai = require("Module:ShipBattleCardKai")

local templates = {

table_header = Enemy patterns !Pattern !Form ! style="min-width:calc(160px * 3)" |Fleet !AP/AS/AS+ !Base Exp !HQ ,

table_footer = '\n|}\n',

node_title_row = Node ${node_label} : ${node_name},

node_pattern_row = [[|-
 * style="text-align:center;" |${node_label}${pattern_id}
 * style="text-align:center;" |${formations_string}
 * style="text-align:left;" |${fleet_string}
 * style="text-align:center;" |${air_string}
 * style="text-align:center;" |${exp}
 * style="text-align:center;" |${hq}]],

}

function formatTable(map_nodes) local rows = {} for node_label, node_data in pairs(map_nodes) do       table.insert(rows, format{            templates.node_title_row,            node_label = node_label,            node_name = node_data.name,        }) for i, pattern_data in ipairs(node_data.patterns) do           local formations_string = table.concat(pattern_data.formations, " ") local fleet_string = table.concat(pattern_data.fleet, " ") local enemy_images = {} local enemy_fleet_air_power = 0 local air_power_complete = true

for j, enemy_name in ipairs(pattern_data.fleet) do               local ship = EnemyShip(enemy_name) local ship_caption = (ship:name or "?") .. " (" .. (ship:api_id or "?") .. "): " .. (ship:armor or "?") .. " Armor, " .. (ship:hp or "?") .. " HP" table.insert(enemy_images, ShipBattleCardKai:get{ship = ship, caption = ship_caption, link = ship:link, flagship = j == 1}) local enemy_air_power = ship:air_power if enemy_air_power then enemy_fleet_air_power = enemy_fleet_air_power + enemy_air_power else air_power_complete = false end end local fleet_string = table.concat(enemy_images, "")

local air_parity = (air_power_complete or enemy_fleet_air_power > 0) and string.format("%.1d", math.ceil((2./3.) * enemy_fleet_air_power)) or "??" local air_superiority = (air_power_complete or enemy_fleet_air_power > 0) and string.format("%.1d", math.ceil(enemy_fleet_air_power * (3 / 2))) or "??" local air_supremacy = (air_power_complete or enemy_fleet_air_power > 0) and tostring(enemy_fleet_air_power * 3) or "??" local air_string = not air_power_complete and enemy_fleet_air_power > 0 and (air_parity .. "+/" .. air_superiority .. "+/" .. air_supremacy .. "+") or (air_parity .. "/" .. air_superiority .. "/" .. air_supremacy)

table.insert(rows, format{               templates.node_pattern_row,                node_label = node_label,                pattern_id = i,                formations_string = formations_string,                fleet_string = fleet_string,                air_string = air_string,                exp = pattern_data.exp or "",                hq = pattern_data.hq or "",            }) end end return templates.table_header .. table.concat(rows, "\n") .. templates.table_footer end

local MapNodesTable = {} function MapNodesTable.format(frame, args_) local args = args_ or getArgs{frame = frame:getParent} local map_id = args[1] local map_nodes = require(string.format('Module:Map %s/Nodes', map_id)) return formatTable(map_nodes) end

-- MapNodesTable.t = MapNodesTable.format(nil, { "6-5" })

return MapNodesTable