模块:物品
来自卡厄思梦境WIKI
此模块的文档可以在模块:物品/doc创建
local p = {}
local data = mw.loadData("模块:物品/data")
function p.main(frame)
local args = frame:getParent().args
return p._main(args)
end
function p._main(args)
local itemName = args[1] or ""
local count = args[2] or ""
local size = args["size"] or "124px"
-- 获取物品数据
local itemData = data[itemName]
if not itemData then
return "[[Category:物品数据缺失]]<span style='color:red'>物品数据不存在: " .. itemName .. "</span>"
end
-- 解析尺寸
local sizeNum = tonumber(string.match(size, "%d+")) or 124
local frameSize = sizeNum
-- 精确计算各个元素的尺寸和位置(保持比例)
local borderWidth = math.floor(sizeNum * 8 / 124) -- 边框到外框的距离
local innerSize = math.floor(sizeNum * 108 / 124) -- 内边框尺寸
local artOffset = math.floor(sizeNum * 6 / 124) -- 图标到外框的距离
local artSize = math.floor(sizeNum * 112 / 124) -- 图标尺寸
local countBottom = math.floor(sizeNum * 6 / 124)
local countRight = math.floor(sizeNum * 1 / 124)
local rarity = itemData.rarity or "白"
local art = itemData.art or ""
local html = mw.html.create('div')
:css('position', 'relative')
:css('width', frameSize .. 'px')
:css('height', frameSize .. 'px')
-- 背景框
html:tag('div')
:css('position', 'absolute')
:css('top', '0px')
:css('left', '0px')
:wikitext('[[File:frame_item_rarity_' .. rarity .. '.png|' .. frameSize .. 'px|link=]]')
-- 边框(居中)
html:tag('div')
:css('position', 'absolute')
:css('top', borderWidth .. 'px')
:css('left', borderWidth .. 'px')
:css('width', innerSize .. 'px')
:css('height', innerSize .. 'px')
:css('border', '1px #f282ff solid')
-- 物品图标(居中)
html:tag('div')
:css('position', 'absolute')
:css('top', artOffset .. 'px')
:css('left', artOffset .. 'px')
:wikitext('[[File:' .. art .. '|' .. artSize .. 'px|link=]]')
-- 数量显示
if count ~= "" then
html:tag('div')
:css('position', 'absolute')
:css('bottom', countBottom .. 'px')
:css('right', countRight .. 'px')
:css('color', '#ffffff')
:css('font-weight', 'bold')
:css('background-color', 'rgba(0,0,0,0.5)')
:css('padding', '2px 5px')
:css('text-align', 'right')
:wikitext(count)
end
return tostring(html)
end
return p