- Welcome to the Kancolle Wiki!
- If you have any questions regarding site content, account registration, etc., please visit the KanColle Wiki Discord
Difference between revisions of "Module:MapRewards"
Jump to navigation
Jump to search
Line 37: | Line 37: | ||
local types = {} | local types = {} | ||
local assetTypes = { item = 'Item Icon', equipment = 'Equipment Card', ship = 'Ship Banner' } | local assetTypes = { item = 'Item Icon', equipment = 'Equipment Card', ship = 'Ship Banner' } | ||
+ | local assetSizes = { item = '75px', equipment = '75px', ship = '240px' } | ||
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 62: | Line 63: | ||
for _, name in ipairs(index) do | for _, name in ipairs(index) do | ||
local typ = types[name] | local typ = types[name] | ||
− | local asset = string.format("[[File:%s %s.png|%s|link=%s]]", assetTypes[typ] or '??', name, typ | + | local asset = string.format("[[File:%s %s.png|%s|link=%s]]", assetTypes[typ] or '??', name, assetSizes[typ] or '??', name) |
table.insert(result, string.format(template.row, asset, name, getCell(name, 'Casual'), getCell(name, 'Easy'), getCell(name, 'Medium'), getCell(name, 'Hard'))) | table.insert(result, string.format(template.row, asset, name, getCell(name, 'Casual'), getCell(name, 'Easy'), getCell(name, 'Medium'), getCell(name, 'Hard'))) | ||
end | end |
Revision as of 23:33, 24 June 2022
Documentation for this module may be created at Module:MapRewards/doc
local U = require('Module:Core')
local template = {
top_header = [[<div style="position:relative;height:auto;align-items:center;justify-content:center;display:inline-flex;width:100%">
{|style="width:100%;"
!colspan="5" style="background-color:#3baef5;color:white"|Rewards]],
footer = [[|}
</div>]],
header = [[|-
!style="background-color:#3baef5;color:white"|Equipment/Item
!style="background-color:#3baef5;color:white;width:15%"|丁<br>Casual
!style="background-color:#3baef5;color:white;width:15%"|丙<br>Easy
!style="background-color:#3baef5;color:white;width:15%"|乙<br>Medium
!style="background-color:#3baef5;color:white;width:15%"|甲<br>Hard]],
all = [[|-
!colspan="5" style="background-color:white"|All
|-
|colspan="5" style="text-align:center"|%s]],
row = [=[|-
|style="text-align:center;background-color:#eef2f7;font-size:12px;line-height:12px"|%s<br>[[%s]]
|style="text-align:center;background-color:#eef2f7;font-size:20px"|%s
|style="text-align:center;background-color:#eef2f7;font-size:20px"|%s
|style="text-align:center;background-color:#eef2f7;font-size:20px"|%s
|style="text-align:center;background-color:#eef2f7;font-size:20px"|%s]=],
}
local function render(frame)
local event = frame.args[1] or "??"
local map = frame.args[2] or "??"
local success, data = U.loadData("Data/Map/" .. event)
if not success then return "Unknown event: " .. event end
data = data[map]
if not data then return "Unknown map: " .. map end
local result = { template.top_header, template.header }
local index = {}
local tbl = {}
local types = {}
local assetTypes = { item = 'Item Icon', equipment = 'Equipment Card', ship = 'Ship Banner' }
local assetSizes = { item = '75px', equipment = '75px', ship = '240px' }
local function setData(diff)
for _, v in ipairs(data[diff] or {}) do
local name = v.item or v.equipment or v.ship or '??'
if not U.ifind(index, name) then table.insert(index, name) end
types[name] = v.item and 'item' or v.equipment and 'equipment' or v.ship and 'ship' or '??'
tbl[name] = tbl[name] or {}
tbl[name][diff] = { count = v.count or 1, level = v.level }
end
end
local function getCount(name, diff)
return ((tbl[name] or {})[diff] or {}).count or ''
end
local function getLevel(name, diff)
local level = ((tbl[name] or {})[diff] or {}).level
return level and string.format(" (★%d)", level) or ''
end
local function getCell(name, diff)
return getCount(name, diff) .. getLevel(name, diff)
end
setData('Hard')
setData('Medium')
setData('Easy')
setData('Casual')
for _, name in ipairs(index) do
local typ = types[name]
local asset = string.format("[[File:%s %s.png|%s|link=%s]]", assetTypes[typ] or '??', name, assetSizes[typ] or '??', name)
table.insert(result, string.format(template.row, asset, name, getCell(name, 'Casual'), getCell(name, 'Easy'), getCell(name, 'Medium'), getCell(name, 'Hard')))
end
table.insert(result, template.footer)
return table.concat(result, "\n")
end
return { render = render }