• Welcome to the Kancolle Wiki!
  • If you have any questions regarding site content, account registration, etc., please visit the KanColle Wiki Discord

Changes

Jump to navigation Jump to search
no edit summary
Line 9: Line 9:  
|colspan="4" style="background-color:#eef2f7"|%s<br>[[%s]]]=],
 
|colspan="4" style="background-color:#eef2f7"|%s<br>[[%s]]]=],
 
choice = [=[|-
 
choice = [=[|-
!colspan="5" style="background-color:#3baef5;color:red"|OR]=],
+
!style="background-color:#eef2f7;color:red"|OR
 +
|colspan="4" style="background-color:#eef2f7"|]=],
 
-- TODO: class="sortable"
 
-- TODO: class="sortable"
 
item_header = [[{|style="text-align:center;width:100%"
 
item_header = [[{|style="text-align:center;width:100%"
Line 23: Line 24:  
|style="background-color:#eef2f7;font-size:18px"|%s
 
|style="background-color:#eef2f7;font-size:18px"|%s
 
|style="background-color:#eef2f7;font-size:18px"|%s]=],
 
|style="background-color:#eef2f7;font-size:18px"|%s]=],
 +
item_row_choice1 = [=[|-
 +
|data-sort-value="%s" style="background-color:#eef2f7;font-size:12px;line-height:14px;border-top:4px solid grey"|%s<br>[[%s]]
 +
|style="background-color:#eef2f7;font-size:18px;border-top:4px solid grey"|%s
 +
|style="background-color:#eef2f7;font-size:18px;border-top:4px solid grey"|%s
 +
|style="background-color:#eef2f7;font-size:18px;border-top:4px solid grey"|%s
 +
|style="background-color:#eef2f7;font-size:18px;border-top:4px solid grey"|%s]=],
 +
item_row_choice2 = [=[|-
 +
|data-sort-value="%s" style="background-color:#eef2f7;font-size:12px;line-height:14px;border-bottom:4px solid grey"|%s<br>[[%s]]
 +
|style="background-color:#eef2f7;font-size:18px;border-bottom:4px solid grey"|%s
 +
|style="background-color:#eef2f7;font-size:18px;border-bottom:4px solid grey"|%s
 +
|style="background-color:#eef2f7;font-size:18px;border-bottom:4px solid grey"|%s
 +
|style="background-color:#eef2f7;font-size:18px;border-bottom:4px solid grey"|%s]=],
 
}
 
}
   Line 29: Line 42:  
local assetSizes = { item = '75px', equipment = '75px', ship = '240px' }
 
local assetSizes = { item = '75px', equipment = '75px', ship = '240px' }
   −
local function render(frame)
+
local function render(frame, event, map)
local event = frame.args[1] or "??"
+
local event = event or frame.args[1] or "??"
local map = frame.args[2] or "??"
+
local map = map or frame.args[2] or "??"
 
local success, data = U.loadData("Data/Map/" .. event)
 
local success, data = U.loadData("Data/Map/" .. event)
 
if not success then return "Unknown event: " .. event end
 
if not success then return "Unknown event: " .. event end
Line 39: Line 52:  
local tbl = {}
 
local tbl = {}
 
local types = {}
 
local types = {}
local choices = {}
   
-- TODO: assuming 0-1 single ship reward on all difficulties
 
-- TODO: assuming 0-1 single ship reward on all difficulties
 
local ship = false
 
local ship = false
local function setDataItem(diff, v, choice, last)
  −
local name = v.item or v.equipment or v.ship or '??'
  −
types[name] = v.item and 'item' or v.equipment and 'equipment' or v.ship and 'ship' or '??'
  −
if choice then
  −
if not U.ifind(index, name) then table.insert(index, name) end
  −
tbl[name] = tbl[name] or {}
  −
tbl[name][diff] = { count = v.count or 1, level = v.level }
  −
if not last then
  −
choices[name] = true
  −
end
  −
else
  −
if v.ship then
  −
ship = v.ship
  −
else
  −
if not U.ifind(index, name) then table.insert(index, name) end
  −
tbl[name] = tbl[name] or {}
  −
tbl[name][diff] = { count = v.count or 1, level = v.level }
  −
end
  −
end
  −
end
   
local function setData(diff)
 
local function setData(diff)
 
for _, v in ipairs(data[diff] or {}) do
 
for _, v in ipairs(data[diff] or {}) do
 
if v.choice then
 
if v.choice then
for i, v in ipairs(v.choice) do
+
local v1 = v.choice[1]
setDataItem(diff, v, true, i == #v.choice)
+
local v2 = v.choice[2]
 +
local name1 = v1.item or v1.equipment or v1.ship or '??'
 +
local name2 = v2.item or v2.equipment or v2.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 '??'
 +
local names = {name1 .. '1', name2 .. '2'}
 +
local name = names[1] .. '||' .. names[2]
 +
types[name] = 'choice'
 +
if not U.ifind(index, name) then table.insert(index, name) end
 +
tbl[name] = tbl[name] or {}
 +
tbl[name][diff] = {
 +
{ name = name1, count = v1.count or 1, level = v1.level },
 +
{ name = name2, count = v2.count or 1, level = v2.level },
 +
}
 +
else
 +
local name = v.item or v.equipment or v.ship or '??'
 +
types[name] = v.item and 'item' or v.equipment and 'equipment' or v.ship and 'ship' or '??'
 +
if v.ship then
 +
ship = v.ship
 +
else
 +
if not U.ifind(index, name) then table.insert(index, name) end
 +
tbl[name] = tbl[name] or {}
 +
tbl[name][diff] = { count = v.count or 1, level = v.level }
 
end
 
end
else
  −
setDataItem(diff, v)
   
end
 
end
 
end
 
end
 
end
 
end
local function getCount(name, diff)
+
local function getCount(name, diff, i)
return ((tbl[name] or {})[diff] or {}).count or 0
+
if i then
 +
return (((tbl[name] or {})[diff] or {})[i] or {}).count or 0
 +
else
 +
return ((tbl[name] or {})[diff] or {}).count or 0
 +
end
 
end
 
end
local function getLevel(name, diff)
+
local function getLevel(name, diff, i)
local level = ((tbl[name] or {})[diff] or {}).level
+
local level
 +
if i then
 +
level = (((tbl[name] or {})[diff] or {})[i] or {}).level
 +
else
 +
level = ((tbl[name] or {})[diff] or {}).level
 +
end
 
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)
 
local function getAsset(name)
Line 97: Line 118:  
table.insert(result, template.footer)
 
table.insert(result, template.footer)
 
table.insert(result, template.item_header)
 
table.insert(result, template.item_header)
 +
--[[
 
local sortedIndex = U.imap(index, function(name, i) return { name = name, i = i, typ = types[name] } end)
 
local sortedIndex = U.imap(index, function(name, i) return { name = name, i = i, typ = types[name] } end)
 
table.sort(sortedIndex, function (x, y)
 
table.sort(sortedIndex, function (x, y)
Line 108: Line 130:  
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
 +
]]--
 +
-- sortValues[name]
 
for i, name in ipairs(index) do
 
for i, name in ipairs(index) do
table.insert(result, string.format(template.item_row, sortValues[name], getAsset(name), name,
+
if types[name] == 'choice' then
getCell(name, 'Casual'), getCell(name, 'Easy'), getCell(name, 'Medium'), getCell(name, 'Hard')))
+
local names = U.split(name, '||')
if choices[name] then
+
local name1 = names[1]:sub(1, -2)
 +
local name2 = names[2]:sub(1, -2)
 +
table.insert(result, string.format(template.item_row_choice1, 0, getAsset(name1), name1,
 +
getCell(name, 'Casual', 1), getCell(name, 'Easy', 1), getCell(name, 'Medium', 1), getCell(name, 'Hard', 1)))
 
table.insert(result, template.choice)
 
table.insert(result, template.choice)
 +
table.insert(result, string.format(template.item_row_choice2, 0, getAsset(name2), name2,
 +
getCell(name, 'Casual', 2), getCell(name, 'Easy', 2), getCell(name, 'Medium', 2), getCell(name, 'Hard', 2)))
 +
else
 +
table.insert(result, string.format(template.item_row, 0, getAsset(name), name,
 +
getCell(name, 'Casual'), getCell(name, 'Easy'), getCell(name, 'Medium'), getCell(name, 'Hard')))
 
end
 
end
 
end
 
end
Line 119: Line 151:  
end
 
end
   −
return { render = render }
+
local function test()
 +
mw.log(render(nil, 'Summer 2022 Event', 'E-1'))
 +
end
 +
 
 +
return { render = render, test = test }
cssedit, gkautomate
6,928

edits

Navigation menu