模块

模块:物品

来自卡厄思梦境WIKI

律Rhyme留言 | 贡献2025年10月24日 (五) 16:54的版本 (创建页面,内容为“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'>物品数据不…”)
(差异) ←上一版本 | 最后版本 (差异) | 下一版本→ (差异)

此模块的文档可以在模块:物品/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 artSize = sizeNum - 12
    local innerSize = sizeNum - 16
    local borderTop = math.floor(sizeNum * 8 / 124)
    local borderLeft = math.floor(sizeNum * 8 / 124)
    local artTop = math.floor(sizeNum * 6 / 124)
    local artLeft = math.floor(sizeNum * 6 / 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', borderTop .. 'px')
        :css('left', borderLeft .. 'px')
        :css('width', innerSize .. 'px')
        :css('height', innerSize .. 'px')
        :css('border', '1px #f282ff solid')
    
    -- 物品图标
    html:tag('div')
        :css('position', 'absolute')
        :css('top', artTop .. 'px')
        :css('left', artLeft .. '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