Line 1: |
Line 1: |
− | | + | local format = require('Module:StringInterpolation').format |
− | local format = require("Module:StringInterpolation").format | |
| local getArgs = require('Module:GetArgs') | | local getArgs = require('Module:GetArgs') |
− |
| |
| local Ship = require('Module:Ship') | | local Ship = require('Module:Ship') |
| local Formatting = require('Module:Formatting') | | local Formatting = require('Module:Formatting') |
− |
| |
− | local DropList = {}
| |
| | | |
| -- http://kancolle.wikia.com/wiki/Thread:295964 | | -- http://kancolle.wikia.com/wiki/Thread:295964 |
| local rare_ships = { | | local rare_ships = { |
− | | + | 'Akitsushima', 'Akizuki', 'Amagi', 'Isokaze', 'Katsuragi', 'Littorio', 'Prinz Eugen', 'Roma', 'Tokitsukaze', |
− | "Akitsushima", "Akizuki", "Amagi", "Isokaze", "Katsuragi", "Littorio", "Prinz Eugen", "Roma", "Tokitsukaze",
| + | 'Akitsu Maru', 'Bismarck', 'Musashi', 'Noshiro', 'Yamato', 'Taihou', |
− | | + | 'Agano', 'Akashi', 'Amatsukaze', 'Asagumo', 'Asashimo', 'Harusame', 'Hatsukaze', 'Hayashimo', 'I-401', 'Katori', 'Kiyoshimo', 'Maruyu', |
− | "Akitsu Maru", "Bismarck", "Musashi", "Noshiro", "Yamato", "Taihou",
| + | 'Mikuma', 'Nowaki', 'Ooyodo', 'Sakawa', 'Taigei', 'Takanami', 'U-511', 'Unryuu', 'Uzuki', 'Yahagi', |
− | | + | 'Z1', 'Z3', 'Tanikaze', 'Maikaze', |
− | "Agano", "Akashi", "Amatsukaze", "Asagumo", "Asashimo", "Harusame", "Hatsukaze", "Hayashimo", "I-401", "Katori", "Kiyoshimo", "Maruyu",
| + | 'Libeccio', 'Mizuho', 'Kazagumo', 'Umikaze', 'Kawakaze', 'Hayasui', 'Teruzuki', |
− | "Mikuma", "Nowaki", "Ooyodo", "Sakawa", "Taigei", "Takanami", "U-511", "Unryuu", "Uzuki", "Yahagi", | |
− | | |
− | "Z1", "Z3", "Tanikaze", "Maikaze", | |
− | | |
− | "Libeccio", "Mizuho", "Kazagumo", "Umikaze", "Kawakaze", "Hayasui", "Teruzuki", | |
− |
| |
| } | | } |
| | | |
Line 58: |
Line 48: |
| | | |
| local tbl = { nodes = {}, rows = {}, debug = '' } | | local tbl = { nodes = {}, rows = {}, debug = '' } |
| + | |
| + | function log(message, arg) |
| + | tbl.debug = tbl.debug .. string.format('%s: %s\n', message, value) |
| + | end |
| | | |
| -- header args | | -- header args |
− | local boss = args.boss and string.upper(args.boss) or nil | + | local boss = args.boss and string.upper(args.boss) or '?' |
− | for node in string.gmatch(args.nodes, args_grammar.comma_list) do | + | for node_ in string.gmatch(args.nodes, args_grammar.comma_list) do |
− | local node = node:match(args_grammar.node) | + | local node = node_:match(args_grammar.node) |
| if node then | | if node then |
| local node = string.upper(node) | | local node = string.upper(node) |
− | if find(tbl.nodes, node, "name") then | + | if find(tbl.nodes, node, 'name') then |
− | tbl.debug = tbl.debug .. string.format("node duplicate: %s\n", node) | + | log('node duplicate', node) |
| else | | else |
| table.insert(tbl.nodes, { name = node, boss = node == boss }) | | table.insert(tbl.nodes, { name = node, boss = node == boss }) |
| end | | end |
| + | else |
| + | log('node syntax error', node_) |
| end | | end |
| + | end |
| + | if not find(tbl.nodes, boss, 'name') then |
| + | log('boss node ignored', boss) |
| end | | end |
| | | |
| -- ship args | | -- ship args |
− | for arg_name, arg in pairs(args) do | + | for arg_name, ship_and_nodes in pairs(args) do |
| if tonumber(arg_name) then | | if tonumber(arg_name) then |
− | local ship, nodes = arg:match(args_grammar.ship_and_nodes) | + | local ship, nodes = ship_and_nodes:match(args_grammar.ship_and_nodes) |
− | local ship_table = Ship:get_table(ship, "") | + | if ship and nodes then |
− | if ship_table and ship_table._type then
| + | local ship_table = Ship:get_table(ship, '') |
− | if find(tbl.rows, ship, "ship") then
| + | if ship_table and ship_table._type then |
− | tbl.debug = tbl.debug .. string.format("ship duplicate: %s\n", ship)
| + | if find(tbl.rows, ship, 'ship') then |
− | else
| + | log('ship duplicate', ship) |
− | table.insert(tbl.rows, {})
| + | else |
− | local row = tbl.rows[#tbl.rows]
| + | table.insert(tbl.rows, { |
− | row.ship = ship
| + | ship = ship, |
− | row.rare = false
| + | rare = find(rare_ships, ship), |
− | row.rare = find(rare_ships, ship)
| + | type = Formatting:format_ship_code(ship_table._type) or '?', |
− | row.type = Formatting:format_ship_code(ship_table._type) or '?'
| + | nodes = {} |
− | row.nodes = {}
| + | }) |
− | for _, node in pairs(tbl.nodes) do
| + | local row = tbl.rows[#tbl.rows] |
− | row.nodes[node.name] = nil
| + | for _, node in pairs(tbl.nodes) do |
− | end
| + | row.nodes[node.name] = nil |
− | for node_and_diff in string.gmatch(nodes, args_grammar.comma_list) do
| |
− | local node, diff = node_and_diff:match(args_grammar.node_and_diff)
| |
− | if not node or not diff then
| |
− | node = node_and_diff:match(args_grammar.just_node)
| |
− | diff = nil
| |
| end | | end |
− | if node then | + | for node_and_diff in string.gmatch(nodes, args_grammar.comma_list) do |
− | local node = string.upper(node) | + | local node, diff = node_and_diff:match(args_grammar.node_and_diff) |
− | if row.nodes[node] then
| + | if not node or not diff then |
− | tbl.debug = tbl.debug .. string.format("ship node duplicate: %s for %s\n", node, ship)
| + | node = node_and_diff:match(args_grammar.just_node) |
− | elseif not find(tbl.nodes, node, "name") then
| + | diff = nil |
− | tbl.debug = tbl.debug .. string.format("ignored node: %s for %s\n", node, ship)
| + | end |
| + | if node then |
| + | local node = string.upper(node) |
| + | if row.nodes[node] then |
| + | log('ship node duplicate', string.format('%s for %s', node, ship)) |
| + | elseif not find(tbl.nodes, node, 'name') then |
| + | log('ignored node', string.format('%s for %s', node, ship)) |
| + | else |
| + | row.nodes[node] = { |
| + | color = diff and diff_colors[diff] or diff_colors['?'], |
| + | diff = diff and diff_names[diff] or '?' |
| + | } |
| + | end |
| else | | else |
− | row.nodes[node] = { color = diff and diff_colors[diff] or diff_colors['?'], diff = diff and diff_names[diff] or '?' } | + | log('ship node syntax error', node_and_diff) |
| end | | end |
| end | | end |
| end | | end |
| + | else |
| + | log('ship ignored', ship) |
| end | | end |
| + | else |
| + | log('ship syntax error', ship_and_nodes) |
| end | | end |
| end | | end |
Line 158: |
Line 168: |
| for _, node in pairs(tbl.nodes) do | | for _, node in pairs(tbl.nodes) do |
| local node = row.nodes[node.name] | | local node = row.nodes[node.name] |
− | res = res .. (node and format{table_format.node_cell, color = node.color, diff = node.diff} or table_format.empty_cell) | + | res = res .. (node and format{ |
| + | table_format.node_cell, |
| + | color = node.color, |
| + | diff = node.diff |
| + | } or table_format.empty_cell) |
| end | | end |
| end | | end |
Line 164: |
Line 178: |
| res = res .. table_format.footer | | res = res .. table_format.footer |
| | | |
− | if tbl.debug ~= "" then | + | if tbl.debug ~= '' then |
| res = res .. format{table_format.debugger, debug = tbl.debug} | | res = res .. format{table_format.debugger, debug = tbl.debug} |
| end | | end |
Line 171: |
Line 185: |
| | | |
| end | | end |
| + | |
| + | local DropList = {} |
| | | |
| function DropList.show(frame) | | function DropList.show(frame) |