| Line 1: |
Line 1: |
| − | local find = require('Module:Utils').includes | + | local find = require('Module:Core').includes |
| − | local format = require('Module:Utils').format | + | local format = require('Module:Core').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 SortId = require('Module:DropList/Sort') |
| | | | |
| | -- * Rarity definitions. | | -- * Rarity definitions. |
| − | -- sync with http://kancolle.wikia.com/wiki/Template:DropList/doc
| |
| | | | |
| | local rare_ships = { | | local rare_ships = { |
| | 'Agano', 'Akashi', 'Akitsu Maru', 'Akitsushima', 'Akizuki', 'Amagi', 'Amagiri', 'Amatsukaze', 'Arashi', | | 'Agano', 'Akashi', 'Akitsu Maru', 'Akitsushima', 'Akizuki', 'Amagi', 'Amagiri', 'Amatsukaze', 'Arashi', |
| − | 'Ark Royal', 'Asagumo', 'Asakaze', 'Asashimo', 'Aquila', 'Bismarck', 'Commandant Teste', 'Daitou', 'Etorofu', | + | 'Ark Royal', 'Asagumo', 'Asakaze', 'Asashimo', 'Aquila', 'Bismarck', 'Colorado', 'Commandant Teste', 'Daitou', |
| − | 'Fujinami', 'Fukae', 'Gambier Bay', 'Gangut','Giuseppe Garibaldi', 'Gotland', 'Graf Zeppelin', 'Hachijou',
| + | 'Etorofu', 'Fletcher', 'Fujinami', 'Fukae', 'Gambier Bay', 'Gangut','Giuseppe Garibaldi', 'Gotland', |
| − | 'Hagikaze', 'Hamanami', 'Harukaze', 'Harusame', 'Hatakaze', 'Hatsukaze', 'Hatsuzuki', 'Hayanami', 'Hayashimo',
| + | 'Graf Zeppelin', 'Hachijou', 'Hagikaze', 'Hamanami', 'Harukaze', 'Harusame', 'Hatakaze', 'Hatsukaze', |
| − | 'Hayasui', 'Hiburi', 'I-13', 'I-14', 'I-26', 'I-400', 'I-401', 'Intrepid', 'Ishigaki', 'Iowa', 'Isokaze',
| + | 'Hatsuzuki', 'Hayanami', 'Hayashimo', 'Hayasui', 'Hiburi', 'I-13', 'I-14', 'I-26', 'I-400', 'I-401', 'Intrepid', |
| − | 'Jervis', 'Johnston', 'Kamikaze', 'Kamoi', 'Kashima', 'Kasuga Maru', 'Katsuragi', 'Kawakaze', 'Kazagumo',
| + | 'Ishigaki', 'Iowa', 'Isokaze', 'Jervis', 'Johnston', 'Kamikaze', 'Kamoi', 'Kashima', 'Kasuga Maru', 'Katsuragi', |
| − | 'Kishinami', 'Kiyoshimo', 'Kunashiri', 'Libeccio', 'Littorio', 'Luigi Torelli', 'Maikaze', 'Maestrale',
| + | 'Kawakaze', 'Kazagumo', 'Kishinami', 'Kiyoshimo', 'Kunashiri', 'Libeccio', 'Littorio', 'Luigi Torelli', 'Maikaze', |
| − | 'Matsuwa', 'Maruyu', 'Matsukaze', 'Mikuma', 'Minazuki', 'Minegumo', 'Mizuho', 'Musashi', 'Nelson', 'Nisshin',
| + | 'Maestrale', 'Matsuwa', 'Maruyu', 'Matsukaze', 'Mikuma', 'Minazuki', 'Minegumo', 'Mizuho', 'Musashi', 'Nelson', |
| − | 'Noshiro', 'Nowaki', 'Okinami', 'Ooyodo', 'Oyashio', 'Pola', 'Prinz Eugen', 'Richelieu', 'Roma', 'Sado',
| + | 'Nisshin', 'Noshiro', 'Nowaki', 'Okinami', 'Ooyodo', 'Oyashio', 'Pola', 'Prinz Eugen', 'Richelieu', 'Roma', 'Sado', |
| | 'Sagiri', 'Sakawa', 'Samuel B. Roberts', 'Saratoga', 'Shimushu', 'Shinyou', 'Suzutsuki', 'Taigei', 'Taihou', | | 'Sagiri', 'Sakawa', 'Samuel B. Roberts', 'Saratoga', 'Shimushu', 'Shinyou', 'Suzutsuki', 'Taigei', 'Taihou', |
| | 'Takanami', 'Tanikaze', 'Tashkent', 'Teruzuki', 'Tokitsukaze', 'Tsushima', 'U-511', 'Umikaze', 'Unryuu', | | 'Takanami', 'Tanikaze', 'Tashkent', 'Teruzuki', 'Tokitsukaze', 'Tsushima', 'U-511', 'Umikaze', 'Unryuu', |
| | 'Uranami', 'Uzuki', 'Warspite', 'Yahagi', 'Yamakaze', 'Yamato', 'Z1', 'Z3', 'Zara', | | 'Uranami', 'Uzuki', 'Warspite', 'Yahagi', 'Yamakaze', 'Yamato', 'Z1', 'Z3', 'Zara', |
| − | 'Fletcher', 'Colorado', | + | |
| | + | 'Mikura', 'Grecale', 'Duca degli Abruzzi', 'Janus', |
| | + | |
| | + | 'Houston', 'De Ruyter', 'Perth', 'Shinshuu Maru', |
| | + | |
| | + | 'Akishimo', 'Hirato', 'Atlanta', |
| | + | |
| | + | 'Usugumo', 'I-47', 'Matsu', 'Jingei', 'Kaiboukan No.4', |
| | + | |
| | + | 'Ariake', 'Helena', 'Yashiro', 'South Dakota', 'Hornet', |
| | + | |
| | + | 'Scirocco', 'Sheffield', 'Washington', 'Take', |
| | + | |
| | + | 'Momo', 'I-203', 'Northampton', 'Makinami', |
| | + | |
| | + | 'Honolulu', 'Suzunami', 'Souya', |
| | + | |
| | + | 'Chougei', 'Conte di Cavour', 'Victorious', 'Kaiboukan No.30', |
| | + | |
| | + | 'Shounan', 'Scamp', |
| | + | |
| | + | 'Yawata Maru', |
| | + | |
| | + | 'Ume', 'Yamashio Maru', 'Fuyutsuki', 'Tamanami', |
| | + | |
| | + | 'Hayashio', 'I-201', 'Maryland', 'Kurahashi', |
| | + | |
| | + | 'Ukuru', 'Natsugumo', 'Langley', 'Brooklyn', 'Massachusetts', 'Ranger', 'Jean Bart', |
| | + | |
| | + | 'Yuugure', 'Heywood L. Edwards', 'Kumano Maru', 'Noumi', 'Tuscaloosa', 'No.101 Transport Ship', |
| | + | |
| | + | 'Kaiboukan No.22', 'Inagi', 'Shirakumo', 'Salmon', 'Asahi', 'C.Cappellini', 'Javelin', 'Nevada', 'Rodney', |
| | + | |
| | + | 'Drum', 'I-41', 'I-36', 'Heian Maru', |
| | + | |
| | + | 'Mogador', 'Valiant', 'Gloire', 'Phoenix', 'Lexington', |
| | + | |
| | + | 'Ootomari', 'Wahoo', 'Kaya', 'Kirov', 'Sugi', 'Shimane Maru', 'Minneapolis', |
| | + | |
| | + | 'Norge', 'Eidsvold', 'Glorious', 'Nankai', 'Nosaki', 'Kashi', 'Dace', 'Leonardo da Vinci', 'Wasp', |
| | } | | } |
| | | | |
| Line 51: |
Line 90: |
| | ['Hard'] = 'Hard+', | | ['Hard'] = 'Hard+', |
| | ['?'] = '?', | | ['?'] = '?', |
| − | ['Regular'] = '✓', | + | ['Regular'] = '✔️', |
| | } | | } |
| | | | |
| Line 66: |
Line 105: |
| | | | |
| | local table_format = { | | local table_format = { |
| − | header = '{| class="article-table sortable ${classes}" align="center" width="100%" style="text-align:center; line-height:15px;"\n!Type\n!<span style="border-bottom:1px dotted;">Ship<sup>[[Template:DropList/doc|?]]</sup></span>\n', | + | -- header = '{| class="article-table sortable center ${classes}" width="100%" style="text-align:center; line-height:15px;"\n!Type\n!<span style="border-bottom:1px dotted;">Ship<sup>[[Template:DropList/doc|?]]</sup></span>\n', |
| | + | header = '{|class="wikitable mw-collapsible mw-collapsed" width="50%" style="text-align:center"\n!colspan="100"|Ship drops\n|-\n!Type\n!Ship<sup>[[Module:DropList|?]]</sup>\n', |
| | header_node = '!${node}\n', | | header_node = '!${node}\n', |
| − | header_boss_node = '!style="background-color:#FFCDD2;color:red;"|\'\'\'${node}\'\'\'\n', | + | header_boss_node = '!style="background-color:#FFCDD2;color:red"|\'\'\'${node}\'\'\'\n', |
| − | row = '|- class="toggle-target-droplist-non-rare-ship" style="display:none;"\n', | + | row = '|-\n', -- class="toggle-target-droplist-non-rare-ship" style="display:none;" |
| | rare_row = '|-\n', | | rare_row = '|-\n', |
| | type_cell = '|${type}\n', | | type_cell = '|${type}\n', |
| | -- TODO: japanese tooltips | | -- TODO: japanese tooltips |
| − | ship_cell = '|[[${ship}|<span style="color:${color};">${ship}</span>]]\n', | + | ship_cell = '|[[${ship}|<span style="color:${color}">${ship}</span>]]\n', |
| − | node_cell = '|style="background-color:#${background_color};color:${color}"|${diff}\n', | + | none_cell = '|None\n', |
| | + | node_cell = '|style="background-color:#${background_color}${color}"|${diff}\n', |
| | empty_cell = '|\n', | | empty_cell = '|\n', |
| | footer = '|}\n', | | footer = '|}\n', |
| − | debugger = [[{| style="width:100%;" align="center" cellspacing="0" class="article-table mw-collapsible mw-collapsed" | + | debugger = [[{|style="width:100%" align="center" cellspacing="0" class="article-table mw-collapsible mw-collapsed" |
| | !Notes | | !Notes |
| | |- | | |- |
| Line 94: |
Line 135: |
| | node_diff_tooltip = '^%s*(%w-)%s*/%s*(%S-)%s*{(.-)}%s*$', | | node_diff_tooltip = '^%s*(%w-)%s*/%s*(%S-)%s*{(.-)}%s*$', |
| | node_diff_tooltip_s = '^%s*(%w-)%s*/%s*(%S-)%s*{(.-)}%s*S%s*$', | | node_diff_tooltip_s = '^%s*(%w-)%s*/%s*(%S-)%s*{(.-)}%s*S%s*$', |
| | + | just_node_diff = '^%s*(%w-)%s*/%s*(%S-)%s*$', |
| | + | just_node_diff_s = '^%s*(%w-)%s*/%s*(%S-)%s*S%s*$', |
| | -- TODO: | | -- TODO: |
| | -- * just_node_tooltip | | -- * just_node_tooltip |
| Line 110: |
Line 153: |
| | | | |
| | function log(message, value) | | function log(message, value) |
| − | tbl.debug = tbl.debug .. string.format('%s: %s\n', message, value) | + | -- tbl.debug = tbl.debug .. string.format('%s: %s\n', message, value) |
| | end | | end |
| | | | |
| Line 163: |
Line 206: |
| | local ship, nodes = ship_and_nodes:match(args_grammar.ship_and_nodes) | | local ship, nodes = ship_and_nodes:match(args_grammar.ship_and_nodes) |
| | if ship and nodes then | | if ship and nodes then |
| − | local ship_table = Ship:get_table(ship, '') | + | local ship_table = ship == 'None' and { _type = '' } or Ship:get_table(ship, '') |
| | if ship_table and ship_table._type then | | if ship_table and ship_table._type then |
| | local ignored, rare = find(ignored_ships, ship), find(rare_ships, ship) | | local ignored, rare = find(ignored_ships, ship), find(rare_ships, ship) |
| Line 174: |
Line 217: |
| | ship = ship, | | ship = ship, |
| | rare = rare, | | rare = rare, |
| | + | ignored = ignored, |
| | regular = regular, | | regular = regular, |
| | ship_color = rarity_colors[ignored][rare], | | ship_color = rarity_colors[ignored][rare], |
| | type = Formatting:format_ship_code(ship_table._type) or '?', | | type = Formatting:format_ship_code(ship_table._type) or '?', |
| | + | type_id = ship_table._type or 0, |
| | + | sort_id = SortId[ship_table._api_id] or 0, |
| | nodes = {}, | | nodes = {}, |
| | }) | | }) |
| Line 191: |
Line 237: |
| | s_only = true | | s_only = true |
| | end | | end |
| | + | if not node then |
| | + | node, diff = node_arg:match(args_grammar.just_node_diff_s) |
| | + | if not node then |
| | + | node, diff = node_arg:match(args_grammar.just_node_diff) |
| | + | else |
| | + | s_only = true |
| | + | end |
| | + | end |
| | if not node then | | if not node then |
| | node, diff = node_arg:match(args_grammar.node_and_diff) | | node, diff = node_arg:match(args_grammar.node_and_diff) |
| Line 234: |
Line 288: |
| | function showTable(tbl) | | function showTable(tbl) |
| | | | |
| − | local res = format{table_format.header, classes = tbl.classes or ''} | + | local res = { format{table_format.header, classes = tbl.classes or ''} } |
| | | | |
| | function add(str) | | function add(str) |
| − | res = res .. str | + | table.insert(res, str) |
| | end | | end |
| | | | |
| Line 243: |
Line 297: |
| | add(row.rare and table_format.rare_row or table_format.row) | | add(row.rare and table_format.rare_row or table_format.row) |
| | add(format{table_format.type_cell, type = row.type}) | | add(format{table_format.type_cell, type = row.type}) |
| − | add(format{table_format.ship_cell, color = row.ship_color, ship = row.ship}) | + | add(row.ship == 'None' and table_format.none_cell or format{table_format.ship_cell, color = row.ship_color, ship = row.ship}) |
| | 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] |
| Line 249: |
Line 303: |
| | table_format.node_cell, | | table_format.node_cell, |
| | background_color = node.color, | | background_color = node.color, |
| − | color = node.s_only and 'red' or '', | + | color = node.s_only and ';color:red' or '', |
| − | diff = node.tooltip and Formatting:tooltip(node.diff, node.tooltip) or node.diff | + | diff = node.tooltip and Formatting:tooltip2(node.diff, node.tooltip:gsub("@", " / @@"), " / ", "@") or node.diff |
| | } or table_format.empty_cell) | | } or table_format.empty_cell) |
| | end | | end |
| Line 262: |
Line 316: |
| | }) | | }) |
| | end | | end |
| | + | |
| | + | -- true when the first is less than the second (so that not comp(a[i+1],a[i]) will be true after the sort). If comp is not given, then the standard Lua operator < is used instead. |
| | + | |
| | + | table.sort(tbl.rows, function(a, b) |
| | + | if a.type_id < b.type_id then |
| | + | return true |
| | + | elseif a.type_id == b.type_id then |
| | + | return a.sort_id < b.sort_id |
| | + | else |
| | + | return false |
| | + | end |
| | + | end) |
| | | | |
| − | -- rows
| |
| | for _, row in pairs(tbl.rows) do | | for _, row in pairs(tbl.rows) do |
| − | -- TODO: Sort by type/name
| |
| | if row.rare then | | if row.rare then |
| | add_row(row) | | add_row(row) |
| Line 271: |
Line 335: |
| | end | | end |
| | for key, row in pairs(tbl.rows) do | | for key, row in pairs(tbl.rows) do |
| − | -- TODO: Sort by type/name | + | if not row.rare and not row.ignored then |
| − | if not row.rare then | + | add_row(row) |
| | + | end |
| | + | end |
| | + | for key, row in pairs(tbl.rows) do |
| | + | if row.ignored then |
| | add_row(row) | | add_row(row) |
| | end | | end |
| Line 279: |
Line 347: |
| | add(table_format.footer) | | add(table_format.footer) |
| | | | |
| − | if tbl.debug ~= '' then | + | if tbl.debug ~= '' and tbl.log then |
| | add(format{table_format.debugger, debug = tbl.debug}) | | add(format{table_format.debugger, debug = tbl.debug}) |
| | end | | end |
| | | | |
| − | return res | + | return table.concat(res, '') |
| | | | |
| | end | | end |