| Line 1: |
Line 1: |
| | | | |
| | local DropList = {} | | local DropList = {} |
| − |
| |
| − | function trim(str)
| |
| − | return str:match('^%s*(.-)%s*$')
| |
| − | end
| |
| | | | |
| | local args_grammar = { | | local args_grammar = { |
| − | comma_list = '[^,]+', | + | to_trim = '^%s*(.-)%s*$', |
| − | ship = '^%s*(.-)%s*:%s*(.-)%s*$', | + | comma_list = '[^,]+', |
| − | node_name = '%s*(%a+)%s*/?', | + | ship_and_nodes = '^%s*(.-)%s*:%s*(.-)%s*$', |
| − | node_diff = '/%s*(%a+)%s*$' | + | just_node = '^%s*(%a)%s*$', |
| | + | node_and_diff = '^%s*(%a)%s*/%s*(%S-)%s*$' |
| | } | | } |
| | | | |
| Line 16: |
Line 13: |
| | ['Easy'] = '5a5', | | ['Easy'] = '5a5', |
| | ['Medium'] = 'da6', | | ['Medium'] = 'da6', |
| − | ['Hard'] = 'd33' | + | ['Hard'] = 'd33', |
| | + | ['?'] = '0ff' |
| | + | } |
| | + | |
| | + | local diffs = { |
| | + | ['Easy'] = 'Easy+', |
| | + | ['Medium'] = 'Medium+', |
| | + | ['Hard'] = 'Hard+', |
| | + | ['?'] = '?' |
| | } | | } |
| | | | |
| Line 25: |
Line 30: |
| | -- header args | | -- header args |
| | 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 = trim(node) | + | local node = node:match(args_grammar.to_trim) |
| | table.nodes[#table.nodes + 1] = { name = node } | | table.nodes[#table.nodes + 1] = { name = node } |
| | if node == args.boss then | | if node == args.boss then |
| Line 35: |
Line 40: |
| | for arg_name, arg in pairs(args) do | | for arg_name, arg in pairs(args) do |
| | if tonumber(arg_name) then | | if tonumber(arg_name) then |
| − | local ship, nodes = arg:match(args_grammar.ship) | + | local ship, nodes = arg:match(args_grammar.ship_and_nodes) |
| | -- TODO: check ship existence? | | -- TODO: check ship existence? |
| | table.rows[ship] = {} | | table.rows[ship] = {} |
| Line 42: |
Line 47: |
| | row.nodes = {} | | row.nodes = {} |
| | for _, node in pairs(table.nodes) do | | for _, node in pairs(table.nodes) do |
| − | row.nodes[node.name] = node | + | row.nodes[node.name] = nil |
| | end | | end |
| − | for node_diff in string.gmatch(nodes, args_grammar.comma_list) do | + | for node_and_diff in string.gmatch(nodes, args_grammar.comma_list) do |
| − | local node = node_diff:match(args_grammar.node_name) | + | local node, diff = node_and_diff:match(args_grammar.node_and_diff) |
| − | local diff = node_diff:match(args_grammar.node_diff) | + | if not node or not diff then |
| − | -- TODO: check node/difficulty existence? | + | node = node_and_diff:match(args_grammar.just_node) |
| − | if diff and colors[diff] then | + | diff = nil |
| − | row.nodes[node] = { color = colors[diff], diff = diff .. '+' } | + | end |
| − | else
| + | -- TODO: check node existence? |
| − | row.nodes[node] = { color = "0ff", diff = '?' }
| + | if node then |
| | + | print(node, diff) |
| | + | row.nodes[node] = { color = diff and colors[diff] or colors['?'], diff = diff and diffs[diff] or '?' } |
| | end | | end |
| | end | | end |
| Line 77: |
Line 84: |
| | -- header | | -- header |
| | for _, node in pairs(table.nodes) do | | for _, node in pairs(table.nodes) do |
| − | if node.boss then | + | res = res .. string.format(node.boss and table_format.header_boss_node or table_format.header_node, node.name) |
| − | res = res .. string.format(table_format.header_boss_node, node.name)
| |
| − | else
| |
| − | res = res .. string.format(table_format.header_node, node.name)
| |
| − | end
| |
| | end | | end |
| | | | |
| Line 89: |
Line 92: |
| | for _, node in pairs(table.nodes) do | | for _, node in pairs(table.nodes) do |
| | local node = row.nodes[node.name] | | local node = row.nodes[node.name] |
| − | if node.color then | + | res = res .. (node and string.format(table_format.node_cell, node.color, node.diff) or table_format.empty_cell) |
| − | if node.diff then
| |
| − | res = res .. string.format(table_format.node_cell, node.color, node.diff)
| |
| − | else
| |
| − | res = res .. string.format(table_format.node_cell, node.color, "?")
| |
| − | end
| |
| − | else
| |
| − | res = res .. table_format.empty_cell
| |
| − | end
| |
| | end | | end |
| | end | | end |