Changes

no edit summary
Line 1: Line 1: −
---
  −
-- Data modules in Module:Data/Map/<event> should preferably follow game order (preferably generated from a DB).
  −
--
  −
-- TODO: assuming 0-1 ship
  −
-- TODO: assuming 0-1 choice with 2 options
  −
-- TODO: sorting for choices?
  −
   
local U = require('Module:Core')
 
local U = require('Module:Core')
   Line 23: Line 16:  
choice = [=[|-
 
choice = [=[|-
 
!style="background-color:#eef2f7;color:red"|OR
 
!style="background-color:#eef2f7;color:red"|OR
 +
|colspan="4" style="background-color:#eef2f7"|]=],
 +
choice_separator = [=[|-
 +
!style="background-color:#eef2f7"|THEN
 
|colspan="4" style="background-color:#eef2f7"|]=],
 
|colspan="4" style="background-color:#eef2f7"|]=],
 
item_header = [[{|style="text-align:center;width:100%" class="sortable"
 
item_header = [[{|style="text-align:center;width:100%" class="sortable"
Line 38: Line 34:  
}
 
}
   −
local assetTypes = { item = 'Item Icon', equipment = 'Equipment Card', ship = 'Ship Banner' }
+
local assetType = { item = 'Item Icon', equipment = 'Equipment Card', ship = 'Ship Banner' }
   −
local assetSizes = { item = '75px', equipment = '75px', ship = '160px', large_ship = '240px' }
+
local assetSize = { item = '75px', equipment = '75px', ship = '160px', large_ship = '240px' }
    
local function render(frame, event, map)
 
local function render(frame, event, map)
Line 53: Line 49:  
local types = {}
 
local types = {}
 
local ship = false
 
local ship = false
local choice = false
+
local choiceIndex = {}
local choiceFirstIndex = {}
+
local choice1Index = {}
local choiceSecondIndex = {}
+
local choice2Index = {}
 
local function setData(diff)
 
local function setData(diff)
 
for _, v in ipairs(data[diff] or {}) do
 
for _, v in ipairs(data[diff] or {}) do
Line 65: Line 61:  
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 '??'
choice = true
   
tbl['choice1' .. name1] = tbl['choice1' .. name1] or {}
 
tbl['choice1' .. name1] = tbl['choice1' .. name1] or {}
 
tbl['choice1' .. name1][diff] = { count = v1.count or 1, level = v1.level }
 
tbl['choice1' .. name1][diff] = { count = v1.count or 1, level = v1.level }
 
tbl['choice2' .. name2] = tbl['choice2' .. name2] or {}
 
tbl['choice2' .. name2] = tbl['choice2' .. name2] or {}
 
tbl['choice2' .. name2][diff] = { count = v2.count or 1, level = v2.level }
 
tbl['choice2' .. name2][diff] = { count = v2.count or 1, level = v2.level }
if not U.ifind(choiceFirstIndex, name1) then table.insert(choiceFirstIndex, name1) end
+
if not U.ifind(choice1Index, name1) then table.insert(choice1Index, name1) end
if not U.ifind(choiceSecondIndex, name2) then table.insert(choiceSecondIndex, 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
 
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 97: Line 93:  
end
 
end
 
local function getAsset(name, size)
 
local function getAsset(name, size)
return string.format("[[File:%s %s.png|%s|link=%s]]", assetTypes[types[name]] or '??', name, assetSizes[size or types[name]] or '??', name)
+
return string.format("[[File:%s %s.png|%s|link=%s]]", assetType[types[name]] or '??', name, assetSize[size or types[name]] or '??', name)
 
end
 
end
 
setData('Hard')
 
setData('Hard')
Line 107: Line 103:  
table.insert(result, string.format(template.ship_row, getAsset(ship, 'large_ship'), ship))
 
table.insert(result, string.format(template.ship_row, getAsset(ship, 'large_ship'), ship))
 
end
 
end
if choice then
+
if #choiceIndex > 0 then
 
table.insert(result, template.choice_header)
 
table.insert(result, template.choice_header)
for i, name in ipairs(choiceFirstIndex) 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(choiceSecondIndex) 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 142: Line 153:  
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'))
 
end
 
end
  
cssedit, gkautomate
7,064

edits