| Line 45: |
Line 45: |
| | ['?'] = '?' | | ['?'] = '?' |
| | } | | } |
| | + | |
| | + | function find(tbl, v_, k_) |
| | + | for k, v in pairs(tbl) do |
| | + | if k_ and k == k_ and v == v_ or v == v_ then |
| | + | return true |
| | + | end |
| | + | end |
| | + | return false |
| | + | end |
| | | | |
| | function parseArgs(args) | | function parseArgs(args) |
| | | | |
| − | local tbl = { nodes = {}, rows = {} } | + | local tbl = { nodes = {}, rows = {}, debug = '' } |
| | | | |
| | -- header args | | -- header args |
| Line 56: |
Line 65: |
| | if node then | | if node then |
| | local node = string.upper(node) | | local node = string.upper(node) |
| − | table.insert(tbl.nodes, { name = node, boss = node == boss }) | + | if find(tbl.nodes, node, "name") then |
| | + | tbl.debug = tbl.debug .. string.format("node duplicate: %s\n", node) |
| | + | else |
| | + | table.insert(tbl.nodes, { name = node, boss = node == boss }) |
| | + | end |
| | end | | end |
| | end | | end |
| Line 66: |
Line 79: |
| | local ship_table = Ship:get_table(ship, "") | | local ship_table = Ship:get_table(ship, "") |
| | if ship_table and ship_table._type then | | if ship_table and ship_table._type then |
| − | table.insert(tbl.rows, {}) | + | if find(tbl.rows, ship, "ship") then |
| − | local row = tbl.rows[#tbl.rows]
| + | tbl.debug = tbl.debug .. string.format("ship duplicate: %s\n", ship) |
| − | row.ship = ship
| + | else |
| − | row.rare = false
| + | table.insert(tbl.rows, {}) |
| − | for _, rare_ship in pairs(rare_ships) do
| + | local row = tbl.rows[#tbl.rows] |
| − | if ship == rare_ship then
| + | row.ship = ship |
| − | row.rare = true | + | row.rare = false |
| − | break
| + | row.rare = find(rare_ships, ship) |
| | + | row.type = Formatting:format_ship_code(ship_table._type) or '?' |
| | + | row.nodes = {} |
| | + | for _, node in pairs(tbl.nodes) do |
| | + | row.nodes[node.name] = nil |
| | end | | end |
| − | end
| + | for node_and_diff in string.gmatch(nodes, args_grammar.comma_list) do |
| − | row.type = Formatting:format_ship_code(ship_table._type) or '?'
| + | local node, diff = node_and_diff:match(args_grammar.node_and_diff) |
| − | row.nodes = {}
| + | if not node or not diff then |
| − | for _, node in pairs(tbl.nodes) do
| + | node = node_and_diff:match(args_grammar.just_node) |
| − | row.nodes[node.name] = nil | + | diff = nil |
| − | end
| + | end |
| − | for node_and_diff in string.gmatch(nodes, args_grammar.comma_list) do
| + | if node then |
| − | local node, diff = node_and_diff:match(args_grammar.node_and_diff)
| + | local node = string.upper(node) |
| − | if not node or not diff then
| + | if row.nodes[node] then |
| − | node = node_and_diff:match(args_grammar.just_node)
| + | tbl.debug = tbl.debug .. string.format("ship node duplicate: %s\n", node) |
| − | diff = nil
| + | else |
| − | end
| + | row.nodes[node] = { color = diff and diff_colors[diff] or diff_colors['?'], diff = diff and diff_names[diff] or '?' } |
| − | if node then
| + | end |
| − | local node = string.upper(node)
| + | end |
| − | row.nodes[node] = { color = diff and diff_colors[diff] or diff_colors['?'], diff = diff and diff_names[diff] or '?' }
| |
| | end | | end |
| | end | | end |
| Line 110: |
Line 126: |
| | node_cell = '|style="background-color:#${color};"|${diff}\n', | | node_cell = '|style="background-color:#${color};"|${diff}\n', |
| | empty_cell = '|\n', | | empty_cell = '|\n', |
| − | footer = '|}\n' | + | footer = '|}\n', |
| | + | debugger = [[{| style="width:100%;" align="center" cellspacing="0" class="mw-collapsible mw-collapsed" |
| | + | |- |
| | + | |<pre>${debug}</pre> |
| | + | |}]] |
| | } | | } |
| | | | |
| Line 140: |
Line 160: |
| | | | |
| | res = res .. table_format.footer | | res = res .. table_format.footer |
| | + | |
| | + | if tbl.debug ~= "" then |
| | + | res = res .. format{table_format.debugger, debug = tbl.debug} |
| | + | end |
| | | | |
| | return res | | return res |