- Welcome to the Kancolle Wiki!
- If you have any questions regarding site content, account registration, etc., please visit the KanColle Wiki Discord
Difference between revisions of "Module:Sandbox/MapNodesTable"
Jump to navigation
Jump to search
m |
(add node types) |
||
Line 13: | Line 13: | ||
! style="min-width:calc(160px * 3);width:calc(160px * 3);" |Fleet | ! style="min-width:calc(160px * 3);width:calc(160px * 3);" |Fleet | ||
!AP<br />AS<br />AS+ | !AP<br />AS<br />AS+ | ||
− | !Base Exp | + | !Base<br />Exp |
!HQ | !HQ | ||
]], | ]], | ||
Line 20: | Line 20: | ||
node_title_row = [[|- | node_title_row = [[|- | ||
− | ! colspan="7" |Node ${node_label} : ${node_name}]], | + | ! colspan="7" |Node ${node_label} : ${node_name} ${type}]], |
− | node_pattern_row = [[|- | + | node_pattern_row = [[|- style="background:#${background_color};" |
| style="text-align:center;" |${node_label}<sub>${pattern_id}</sub> | | style="text-align:center;" |${node_label}<sub>${pattern_id}</sub> | ||
| style="text-align:center;" |${formations_string} | | style="text-align:center;" |${formations_string} | ||
Line 30: | Line 30: | ||
| style="text-align:center;" |${hq}]], | | style="text-align:center;" |${hq}]], | ||
+ | } | ||
+ | |||
+ | local type_styles = { | ||
+ | night = { type = "(Night Battle)", background_color = "BBDEFB" }, | ||
+ | aerial = { type = "(Aerial Battle)", background_color = "C8E6C9" }, | ||
+ | raid = { type = "(Air Raid Battle)", background_color = "81C784" }, | ||
} | } | ||
Line 35: | Line 41: | ||
local rows = {} | local rows = {} | ||
for _, node_data in ipairs(map_nodes) do | for _, node_data in ipairs(map_nodes) do | ||
+ | local type_style = type_styles[node_data.type] | ||
table.insert(rows, format{ | table.insert(rows, format{ | ||
templates.node_title_row, | templates.node_title_row, | ||
node_label = node_data.label, | node_label = node_data.label, | ||
node_name = node_data.name, | node_name = node_data.name, | ||
+ | type = type_style and type_style.type or "", | ||
}) | }) | ||
for i, pattern_data in ipairs(node_data.patterns) do | for i, pattern_data in ipairs(node_data.patterns) do | ||
Line 80: | Line 88: | ||
exp = pattern_data.exp or "?", | exp = pattern_data.exp or "?", | ||
hq = pattern_data.hq or "?", | hq = pattern_data.hq or "?", | ||
+ | background_color = type_style and type_style.background_color or "", | ||
}) | }) | ||
end | end | ||
Line 95: | Line 104: | ||
end | end | ||
− | + | MapNodesTable.t = MapNodesTable.format(nil, { "6-5" }) | |
return MapNodesTable | return MapNodesTable |
Revision as of 22:54, 6 October 2016
Documentation for this module may be created at Module:Sandbox/MapNodesTable/doc
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 = [[{| class="wikitable mw-collapsible mw-collapsed typography-xl-optout" style="width:100%"
! colspan="7" |Enemy patterns
|-
!#
!Form
! style="min-width:calc(160px * 3);width:calc(160px * 3);" |Fleet
!AP<br />AS<br />AS+
!Base<br />Exp
!HQ
]],
table_footer = '\n|}\n',
node_title_row = [[|-
! colspan="7" |Node ${node_label} : ${node_name} ${type}]],
node_pattern_row = [[|- style="background:#${background_color};"
| style="text-align:center;" |${node_label}<sub>${pattern_id}</sub>
| 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}]],
}
local type_styles = {
night = { type = "(Night Battle)", background_color = "BBDEFB" },
aerial = { type = "(Aerial Battle)", background_color = "C8E6C9" },
raid = { type = "(Air Raid Battle)", background_color = "81C784" },
}
function formatTable(map_nodes)
local rows = {}
for _, node_data in ipairs(map_nodes) do
local type_style = type_styles[node_data.type]
table.insert(rows, format{
templates.node_title_row,
node_label = node_data.label,
node_name = node_data.name,
type = type_style and type_style.type or "",
})
for i, pattern_data in ipairs(node_data.patterns) do
local formations_string = table.concat(pattern_data.formations, "<br />")
local fleet_string = table.concat(pattern_data.fleet, "<br />")
local enemy_images = {}
local enemy_fleet_air_power = 0
local air_power_complete = true
-- TODO: refactor, try caching enemy data
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 .. "+<br />" .. air_superiority .. "+<br />" .. air_supremacy .. "+")
or (air_parity .. "<br />" .. air_superiority .. "<br />" .. air_supremacy)
table.insert(rows, format{
templates.node_pattern_row,
node_label = node_data.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 "?",
background_color = type_style and type_style.background_color 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