• 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"

From Kancolle Wiki
Jump to navigation Jump to search
m
Line 5: Line 5:
 
!colspan="5" style="background-color:#3baef5;color:white"|Rewards]],
 
!colspan="5" style="background-color:#3baef5;color:white"|Rewards]],
 
footer = [[|}]],
 
footer = [[|}]],
all = [=[|-
+
ship = [=[|-
 
!style="background-color:#3baef5;color:white"|Ship
 
!style="background-color:#3baef5;color:white"|Ship
 
|colspan="4" style="background-color:#eef2f7"|%s<br>[[%s]]]=],
 
|colspan="4" style="background-color:#eef2f7"|%s<br>[[%s]]]=],
Line 21: Line 21:
 
|style="background-color:#eef2f7;font-size:18px"|%s]=],
 
|style="background-color:#eef2f7;font-size:18px"|%s]=],
 
}
 
}
 +
 +
local assetTypes = { item = 'Item Icon', equipment = 'Equipment Card', ship = 'Ship Banner' }
 +
 +
local assetSizes = { item = '75px', equipment = '75px', ship = '240px' }
  
 
local function render(frame)
 
local function render(frame)
Line 32: Line 36:
 
local tbl = {}
 
local tbl = {}
 
local types = {}
 
local types = {}
-- TODO: assuming 0-1 single ship rewards on all difficulties
+
-- TODO: assuming 0-1 single ship reward on all difficulties
 
local ship = false
 
local ship = false
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 60: Line 62:
 
end
 
end
 
local function getAsset(name)
 
local function getAsset(name)
local typ = types[name]
+
return string.format("[[File:%s %s.png|%s|link=%s]]", assetTypes[types[name]] or '??', name, assetSizes[types[name]] or '??', name)
return string.format("[[File:%s %s.png|%s|link=%s]]", assetTypes[typ] or '??', name, assetSizes[typ] or '??', name)
 
 
end
 
end
 
setData('Hard')
 
setData('Hard')
Line 69: Line 70:
 
local result = { template.top_header }
 
local result = { template.top_header }
 
if ship then
 
if ship then
table.insert(result, string.format(template.all, getAsset(ship), ship))
+
table.insert(result, string.format(template.ship, getAsset(ship), ship))
 
end
 
end
 
table.insert(result, template.header)
 
table.insert(result, template.header)

Revision as of 00:18, 25 June 2022

Documentation for this module may be created at Module:MapRewards/doc

local U = require('Module:Core')

local template = {
	top_header = [[{|style="text-align:center"
!colspan="5" style="background-color:#3baef5;color:white"|Rewards]],
	footer = [[|}]],
	ship = [=[|-
!style="background-color:#3baef5;color:white"|Ship
|colspan="4" style="background-color:#eef2f7"|%s<br>[[%s]]]=],
	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]],
	row = [=[|-
|style="background-color:#eef2f7;font-size:12px"|%s<br>[[%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
|style="background-color:#eef2f7;font-size:18px"|%s]=],
}

local assetTypes = { item = 'Item Icon', equipment = 'Equipment Card', ship = 'Ship Banner' }

local assetSizes = { item = '75px', equipment = '75px', ship = '240px' }

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 index = {}
	local tbl = {}
	local types = {}
	-- TODO: assuming 0-1 single ship reward on all difficulties
	local ship = false
	local function setData(diff)
		for _, v in ipairs(data[diff] or {}) do
			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
	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
	local function getAsset(name)
		return string.format("[[File:%s %s.png|%s|link=%s]]", assetTypes[types[name]] or '??', name, assetSizes[types[name]] or '??', name)
	end
	setData('Hard')
	setData('Medium')
	setData('Easy')
	setData('Casual')
	local result = { template.top_header }
	if ship then
		table.insert(result, string.format(template.ship, getAsset(ship), ship))
	end
	table.insert(result, template.header)
	for _, name in ipairs(index) do
		table.insert(result, string.format(template.row, getAsset(name), 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 }