Changes

no edit summary
Line 62: Line 62:  
types[name1] = v1.item and 'item' or v1.equipment and 'equipment' or v1.ship and 'ship' or '??'
 
types[name1] = v1.item and 'item' or v1.equipment and 'equipment' or v1.ship and 'ship' or '??'
 
types[name2] = v2.item and 'item' or v2.equipment and 'equipment' or v2.ship and 'ship' or '??'
 
types[name2] = v2.item and 'item' or v2.equipment and 'equipment' or v2.ship and 'ship' or '??'
tbl['choice1' .. name1] = tbl['choice1' .. name1] or {}
  −
tbl['choice1' .. name1][diff] = { count = v1.count or 1, level = v1.level }
  −
tbl['choice2' .. name2] = tbl['choice2' .. name2] or {}
  −
tbl['choice2' .. name2][diff] = { count = v2.count or 1, level = v2.level }
   
if not U.ifind(choice1Index, name1) then table.insert(choice1Index, name1) end
 
if not U.ifind(choice1Index, name1) then table.insert(choice1Index, name1) end
 
if not U.ifind(choice2Index, name2) then table.insert(choice2Index, name2) end
 
if not U.ifind(choice2Index, name2) then table.insert(choice2Index, name2) end
if not U.ifindBy(choiceIndex, function(e) return e[1] == name1 and e[2] == name2 end) then table.insert(choiceIndex, {name1, name2}) end
+
        if version == 0 then
 +
        local names = table.concat({name1, name2}, '|')
 +
        tbl[names] = tbl[names] or {}
 +
        tbl[names][diff] = {{ count = v1.count or 1, level = v1.level }, { count = v2.count or 1, level = v2.level }}
 +
        if not U.ifind(choiceIndex, names) then table.insert(choiceIndex, names) end
 +
        else
 +
        tbl['choice1' .. name1] = tbl['choice1' .. name1] or {}
 +
        tbl['choice1' .. name1][diff] = { count = v1.count or 1, level = v1.level }
 +
        tbl['choice2' .. name2] = tbl['choice2' .. name2] or {}
 +
        tbl['choice2' .. name2][diff] = { count = v2.count or 1, level = v2.level }
 +
        if not U.ifindBy(choiceIndex, function(e) return e[1] == name1 and e[2] == name2 end) then table.insert(choiceIndex, {name1, name2}) end
 +
        end
 
else
 
else
 
local name = v.item or v.equipment or v.ship or '??'
 
local name = v.item or v.equipment or v.ship or '??'
Line 82: Line 89:  
end
 
end
 
end
 
end
local function getCount(name, diff)
+
local function getCount(name, diff, i)
return ((tbl[name] or {})[diff] or {}).count or 0
+
    local data = (tbl[name] or {})[diff] or {}
 +
    return data[i] and (data[i].count or 0) or data.count or 0
 
end
 
end
local function getLevel(name, diff)
+
local function getLevel(name, diff, i)
local level = ((tbl[name] or {})[diff] or {}).level
+
    local data = (tbl[name] or {})[diff] or {}
 +
    local level = data[i] and data[i].level or data.level
 
return level and string.format(" (★%d)", level) or ''
 
return level and string.format(" (★%d)", level) or ''
 
end
 
end
local function getCell(name, diff)
+
local function getCell(name, diff, i)
local count = getCount(name, diff)
+
local count = getCount(name, diff, i)
return (count == 0 and '' or count) .. getLevel(name, diff)
+
return (count == 0 and '' or count) .. getLevel(name, diff, i)
 
end
 
end
 
local function getAsset(name, size)
 
local function getAsset(name, size)
return string.format("[[File:%s %s.png|%s|link=%s]]", assetType[types[name]] or '??', name, assetSize[size or types[name]] or '??', name)
+
local fname = name:gsub('/', ' ')
 +
return string.format("[[File:%s %s.png|%s|link=%s]]", assetType[types[name]] or '??', fname, assetSize[size or types[name]] or '??', name)
 
end
 
end
 
setData('Hard')
 
setData('Hard')
Line 102: Line 112:  
local deep_plot1 = {}
 
local deep_plot1 = {}
 
local deep_plot2 = {}
 
local deep_plot2 = {}
for _, choice in ipairs(choiceIndex) do
+
if version >= 2 then
deep_plot1[choice[1]] = deep_plot1[choice[1]] or {}
+
for _, choice in ipairs(choiceIndex) do
table.insert(deep_plot1[choice[1]], 1, choice[2])
+
deep_plot1[choice[1]] = deep_plot1[choice[1]] or {}
deep_plot2[choice[2]] = deep_plot2[choice[2]] or {}
+
table.insert(deep_plot1[choice[1]], 1, choice[2])
table.insert(deep_plot2[choice[2]], 1, choice[1])
+
deep_plot2[choice[2]] = deep_plot2[choice[2]] or {}
 +
table.insert(deep_plot2[choice[2]], 1, choice[1])
 +
end
 
end
 
end
 
if version >= 3 then
 
if version >= 3 then
Line 175: Line 187:  
end
 
end
 
end
 
end
else
+
elseif version == 0 then
if #choice1Index == #choice2Index then
+
for i, names in ipairs(choiceIndex) do
for i, e in ipairs(choiceIndex) do
+
local names_ = U.split(names, '|')
local name = e[1]
+
for j, name in ipairs(names_) do
 
table.insert(result, string.format(template.item_row, 0, getAsset(name), name,
 
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')))
+
getCell(names, 'Casual', j), getCell(names, 'Easy', j), getCell(names, 'Medium', j), getCell(names, 'Hard', j)))
table.insert(result, template.choice)
+
if j < #names_ then
name = e[2]
+
table.insert(result, template.choice)
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
 
end
 
end
else
+
if i < #choiceIndex then
for i, name in ipairs(choice1Index) do
+
table.insert(result, template.choice_separator)
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
 
end
 +
end
 +
elseif #choice1Index == #choice2Index then
 +
for i, e in ipairs(choiceIndex) do
 +
local name = e[1]
 +
        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')))
 
table.insert(result, template.choice)
 
table.insert(result, template.choice)
for i, name in ipairs(choice2Index) do
+
name = e[2]
table.insert(result, string.format(template.item_row, 0, getAsset(name), name,
+
  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')))
+
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
 +
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
Line 213: Line 237:  
return x.i < y.i
 
return x.i < y.i
 
end)
 
end)
local sortValues = {}
+
-- local sortValues = {}
for i, e in ipairs(sortedIndex) do sortValues[e.name] = i end
+
-- for i, e in ipairs(sortedIndex) do sortValues[e.name] = i end
for i, name in ipairs(index) do
+
for i, e in ipairs(sortedIndex) do
table.insert(result, string.format(template.item_row, sortValues[name], getAsset(name), name,
+
table.insert(result, string.format(template.item_row, e.i, getAsset(e.name), e.name,
getCell(name, 'Casual'), getCell(name, 'Easy'), getCell(name, 'Medium'), getCell(name, 'Hard')))
+
getCell(e.name, 'Casual'), getCell(e.name, 'Easy'), getCell(e.name, 'Medium'), getCell(e.name, 'Hard')))
 
end
 
end
 
table.insert(result, template.footer)
 
table.insert(result, template.footer)
Line 224: Line 248:     
local function test()
 
local function test()
-- mw.log(render(nil, 'Summer 2022 Event', 'E-1'))
+
mw.log(render(nil, 'Summer 2023 Event', 'E-7'))
-- mw.log(render(nil, 'Early Spring 2023 Event', 'E-1'))
  −
mw.log(render(nil, 'Summer 2023 Event', 'E-3'))
   
end
 
end
  
cssedit, gkautomate
6,926

edits