Line 18: |
Line 18: |
| |colspan="4" style="background-color:#eef2f7"|]=], | | |colspan="4" style="background-color:#eef2f7"|]=], |
| choice_separator = [=[|- | | choice_separator = [=[|- |
− | !style="background-color:#eef2f7;border-style: solid none none none; border-width: 3px; border-color: black"|THEN | + | !style="background-color:#eee;color:blue"|THEN |
− | |colspan="4" style="background-color:#eef2f7;border-style: solid none none none; border-width: 3px; border-color: black"|]=], | + | |colspan="4" style="background-color:#eee"|]=], |
| item_header = [[{|style="text-align:center;width:100%" class="sortable" | | item_header = [[{|style="text-align:center;width:100%" class="sortable" |
| !style="background-color:#3baef5;color:white;width:40%"|Reward | | !style="background-color:#3baef5;color:white;width:40%"|Reward |
Line 45: |
Line 45: |
| data = data[map] | | data = data[map] |
| if not data then return "No data for map: " .. map end | | if not data then return "No data for map: " .. map end |
| + | local version = data.version or 1 |
| local index = {} | | local index = {} |
| local tbl = {} | | local tbl = {} |
Line 99: |
Line 100: |
| setData('Easy') | | setData('Easy') |
| setData('Casual') | | setData('Casual') |
| + | local deep_plot1 = {} |
| + | local deep_plot2 = {} |
| + | for _, choice in ipairs(choiceIndex) do |
| + | deep_plot1[choice[1]] = deep_plot1[choice[1]] or {} |
| + | table.insert(deep_plot1[choice[1]], 1, choice[2]) |
| + | deep_plot2[choice[2]] = deep_plot2[choice[2]] or {} |
| + | table.insert(deep_plot2[choice[2]], 1, choice[1]) |
| + | end |
| local result = { string.format(template.header, mw.uri.encode(event, 'WIKI')) } | | local result = { string.format(template.header, mw.uri.encode(event, 'WIKI')) } |
| if ship then | | if ship then |
Line 105: |
Line 114: |
| if #choiceIndex > 0 then | | if #choiceIndex > 0 then |
| table.insert(result, template.choice_header) | | table.insert(result, template.choice_header) |
− | if #choice1Index == #choice2Index then | + | if version == 2 then |
− | for i, e in ipairs(choiceIndex) do | + | local done = {} |
− | local name = e[1] | + | local first = true |
− | table.insert(result, string.format(template.item_row, 0, getAsset(name), name,
| + | for i, names in ipairs(choiceIndex) do |
− | getCell('choice1' .. name, 'Casual'), getCell('choice1' .. name, 'Easy'), getCell('choice1' .. name, 'Medium'), getCell('choice1' .. name, 'Hard')))
| + | if not done[names[1] .. '|' .. names[2]] then |
− | table.insert(result, template.choice)
| + | if first then |
− | name = e[2]
| + | first = false |
− | table.insert(result, string.format(template.item_row, 0, getAsset(name), name,
| + | else |
− | getCell('choice2' .. name, 'Casual'), getCell('choice2' .. name, 'Easy'), getCell('choice2' .. name, 'Medium'), getCell('choice2' .. name, 'Hard')))
| + | table.insert(result, template.choice_separator) |
− | if i < #choiceIndex then
| + | end |
− | table.insert(result, template.choice_separator) | + | local size1 = #deep_plot1[names[1]] |
| + | local size2 = #deep_plot2[names[2]] |
| + | if size1 > size2 then |
| + | table.insert(result, string.format(template.item_row, 0, getAsset(names[1]), names[1], |
| + | getCell('choice1' .. names[1], 'Casual'), getCell('choice1' .. names[1], 'Easy'), getCell('choice1' .. names[1], 'Medium'), getCell('choice1' .. names[1], 'Hard'))) |
| + | table.insert(result, template.choice) |
| + | for _, name in ipairs(deep_plot1[names[1]]) do |
| + | table.insert(result, string.format(template.item_row, 0, getAsset(name), name, |
| + | getCell('choice2' .. name, 'Casual'), getCell('choice2' .. name, 'Easy'), getCell('choice2' .. name, 'Medium'), getCell('choice2' .. name, 'Hard'))) |
| + | done[names[1] .. '|' .. name] = true |
| + | end |
| + | elseif size2 > size1 then |
| + | for _, name in ipairs(deep_plot2[names[2]]) do |
| + | table.insert(result, string.format(template.item_row, 0, getAsset(name), name, |
| + | getCell('choice1' .. name, 'Casual'), getCell('choice1' .. name, 'Easy'), getCell('choice1' .. name, 'Medium'), getCell('choice1' .. name, 'Hard'))) |
| + | done[name .. '|' .. names[2]] = true |
| + | end |
| + | table.insert(result, template.choice) |
| + | table.insert(result, string.format(template.item_row, 0, getAsset(names[2]), names[2], |
| + | getCell('choice2' .. names[2], 'Casual'), getCell('choice2' .. names[2], 'Easy'), getCell('choice2' .. names[2], 'Medium'), getCell('choice2' .. names[2], 'Hard'))) |
| + | else |
| + | table.insert(result, string.format(template.item_row, 0, getAsset(names[1]), names[1], |
| + | getCell('choice1' .. names[1], 'Casual'), getCell('choice1' .. names[1], 'Easy'), getCell('choice1' .. names[1], 'Medium'), getCell('choice1' .. names[1], 'Hard'))) |
| + | table.insert(result, template.choice) |
| + | table.insert(result, string.format(template.item_row, 0, getAsset(names[2]), names[2], |
| + | getCell('choice2' .. names[2], 'Casual'), getCell('choice2' .. names[2], 'Easy'), getCell('choice2' .. names[2], 'Medium'), getCell('choice2' .. names[2], 'Hard'))) |
| + | done[names[1] .. '|' .. names[2]] = true |
| + | end |
| end | | end |
| end | | end |
| else | | else |
− | for i, name in ipairs(choice1Index) do | + | if #choice1Index == #choice2Index then |
− | table.insert(result, string.format(template.item_row, 0, getAsset(name), name,
| + | for i, e in ipairs(choiceIndex) do |
− | getCell('choice1' .. name, 'Casual'), getCell('choice1' .. name, 'Easy'), getCell('choice1' .. name, 'Medium'), getCell('choice1' .. name, 'Hard')))
| + | local name = e[1] |
− | end
| + | table.insert(result, string.format(template.item_row, 0, getAsset(name), name, |
− | table.insert(result, template.choice)
| + | getCell('choice1' .. name, 'Casual'), getCell('choice1' .. name, 'Easy'), getCell('choice1' .. name, 'Medium'), getCell('choice1' .. name, 'Hard'))) |
− | for i, name in ipairs(choice2Index) do
| + | table.insert(result, template.choice) |
− | table.insert(result, string.format(template.item_row, 0, getAsset(name), name,
| + | name = e[2] |
− | getCell('choice2' .. name, 'Casual'), getCell('choice2' .. name, 'Easy'), getCell('choice2' .. name, 'Medium'), getCell('choice2' .. name, 'Hard')))
| + | table.insert(result, string.format(template.item_row, 0, getAsset(name), name, |
| + | getCell('choice2' .. name, 'Casual'), getCell('choice2' .. name, 'Easy'), getCell('choice2' .. name, 'Medium'), getCell('choice2' .. name, 'Hard'))) |
| + | if i < #choiceIndex then |
| + | table.insert(result, template.choice_separator) |
| + | end |
| + | end |
| + | else |
| + | for i, name in ipairs(choice1Index) do |
| + | table.insert(result, string.format(template.item_row, 0, getAsset(name), name, |
| + | getCell('choice1' .. name, 'Casual'), getCell('choice1' .. name, 'Easy'), getCell('choice1' .. name, 'Medium'), getCell('choice1' .. name, 'Hard'))) |
| + | end |
| + | table.insert(result, template.choice) |
| + | for i, name in ipairs(choice2Index) do |
| + | table.insert(result, string.format(template.item_row, 0, getAsset(name), name, |
| + | getCell('choice2' .. name, 'Casual'), getCell('choice2' .. name, 'Easy'), getCell('choice2' .. name, 'Medium'), getCell('choice2' .. name, 'Hard'))) |
| + | end |
| end | | end |
| end | | end |
Line 152: |
Line 203: |
| | | |
| local function test() | | local function test() |
− | mw.log(render(nil, 'Summer 2022 Event', 'E-1')) | + | -- mw.log(render(nil, 'Summer 2022 Event', 'E-1')) |
− | mw.log(render(nil, 'Early Spring 2023 Event', 'E-1')) | + | -- mw.log(render(nil, 'Early Spring 2023 Event', 'E-1')) |
| + | mw.log(render(nil, 'Summer 2023 Event', 'E-1')) |
| end | | end |
| | | |