模块

物品:修订间差异

来自卡厄思梦境WIKI

律Rhyme留言 | 贡献
创建页面,内容为“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'>物品数据不…”
 
律Rhyme留言 | 贡献
无编辑摘要
 
第21行: 第21行:
     local sizeNum = tonumber(string.match(size, "%d+")) or 124
     local sizeNum = tonumber(string.match(size, "%d+")) or 124
     local frameSize = sizeNum
     local frameSize = sizeNum
     local artSize = sizeNum - 12
      
     local innerSize = sizeNum - 16
     -- 精确计算各个元素的尺寸和位置(保持比例)
     local borderTop = math.floor(sizeNum * 8 / 124)
     local borderWidth = math.floor(sizeNum * 8 / 124) -- 边框到外框的距离
     local borderLeft = math.floor(sizeNum * 8 / 124)
     local innerSize = math.floor(sizeNum * 108 / 124) -- 内边框尺寸
     local artTop = math.floor(sizeNum * 6 / 124)
     local artOffset = math.floor(sizeNum * 6 / 124)   -- 图标到外框的距离
     local artLeft = math.floor(sizeNum * 6 / 124)
     local artSize = math.floor(sizeNum * 112 / 124)   -- 图标尺寸
     local countBottom = math.floor(sizeNum * 6 / 124)
     local countBottom = math.floor(sizeNum * 6 / 124)
     local countRight = math.floor(sizeNum * 1 / 124)
     local countRight = math.floor(sizeNum * 1 / 124)
第45行: 第45行:
         :wikitext('[[File:frame_item_rarity_' .. rarity .. '.png|' .. frameSize .. 'px|link=]]')
         :wikitext('[[File:frame_item_rarity_' .. rarity .. '.png|' .. frameSize .. 'px|link=]]')
      
      
     -- 边框
     -- 边框(居中)
     html:tag('div')
     html:tag('div')
         :css('position', 'absolute')
         :css('position', 'absolute')
         :css('top', borderTop .. 'px')
         :css('top', borderWidth .. 'px')
         :css('left', borderLeft .. 'px')
         :css('left', borderWidth .. 'px')
         :css('width', innerSize .. 'px')
         :css('width', innerSize .. 'px')
         :css('height', innerSize .. 'px')
         :css('height', innerSize .. 'px')
         :css('border', '1px #f282ff solid')
         :css('border', '1px #f282ff solid')
      
      
     -- 物品图标
     -- 物品图标(居中)
     html:tag('div')
     html:tag('div')
         :css('position', 'absolute')
         :css('position', 'absolute')
         :css('top', artTop .. 'px')
         :css('top', artOffset .. 'px')
         :css('left', artLeft .. 'px')
         :css('left', artOffset .. 'px')
         :wikitext('[[File:' .. art .. '|' .. artSize .. 'px|link=]]')
         :wikitext('[[File:' .. art .. '|' .. artSize .. 'px|link=]]')
      
      

2025年10月24日 (五) 16:57的最新版本

此模块的文档可以在模块:物品/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