装备:修订间差异
来自卡厄思梦境WIKI
无编辑摘要 |
无编辑摘要 |
||
| 第1行: | 第1行: | ||
local p = {} | local p = {} | ||
local data = mw.loadData('模块:装备/data') | |||
local function | |||
local function getArgs(frame) | |||
local args = frame.args or {} | |||
local parent = frame:getParent() | |||
return | if parent then | ||
setmetatable(args, { __index = parent.args }) | |||
end | |||
return args | |||
end | end | ||
local function sanitizeId(s) | |||
local function | s = tostring(s or '') | ||
s = mw.ustring.gsub(s, "%s+", "_") | |||
s = mw.ustring.gsub(s, "[%[%]{}()%c%p]", "_") | |||
return s | |||
return | |||
end | end | ||
local function clampLevel(level) | |||
local function | level = tonumber(level) or 1 | ||
if level < 1 then level = 1 end | |||
if level > 5 then level = 5 end | |||
return level | |||
return | |||
end | end | ||
local function starIcon(level) | |||
function | level = clampLevel(level) | ||
return string.format("icon_star_rating_%d.png", level) | |||
end | end | ||
function p.render(frame) | |||
function p. | local args = getArgs(frame) | ||
local name = args.name or args[1] | |||
local args = | local level = clampLevel(args.level or args.lv or args[2] or 1) | ||
if not | |||
if not name or not data[name] then | |||
return string.format("<span style='color:red'>[装备] 数据未找到:%s</span>", tostring(name or "未指定")) | |||
end | end | ||
-- | local eq = data[name] | ||
local base = eq.base or {} | |||
local | local rarity = base.rarity or "蓝" | ||
local art = base.art or "" | |||
local typ = base.type or "武器" | |||
local valueType = base.value_type or "" | |||
local lvlKey = tostring(level) | |||
local lvl = eq[lvlKey] or {} | |||
local value = lvl.value or "" | |||
local desc = lvl.desc_global or "" | |||
local modalId = "equip_modal_" .. sanitizeId(name) .. "_" .. tostring(level) | |||
local root = mw.html.create('div') | |||
-- 小卡片 | |||
local card = root:tag('div') | |||
:addClass('equip-card') | |||
:attr('data-equip-id', modalId) | |||
:attr('style', 'position: relative; display: inline-block; width:150px; height: 230px; cursor: pointer;') | |||
card:tag('div') | |||
:attr('style', 'position: absolute; top: 0px; left: 0px;') | |||
:wikitext(string.format('[[File:bg_equipment_rarity_%s.png|150px|link=]]', rarity)) | |||
card:tag('div') | |||
:attr('style', 'position: absolute; top: 43px; left: 13px;') | |||
:wikitext(string.format('[[File:%s|124px|link=]]', art)) | |||
card:tag('div') | |||
:attr('style', 'position: absolute; bottom: 5px; left: 5px; width: 140px; height: 35px; background-color: rgba(0,0,0,0.5); border-radius: 0px 0px 8px 8px') | |||
card:tag('div') | |||
:attr('style', 'position: absolute; bottom: 10px; left: 20px; ') | |||
:wikitext(string.format('[[File:%s|link=]]', starIcon(level))) | |||
card:tag('div') | |||
:attr('style', 'position: absolute; top: 0px; left: 0px;') | |||
:wikitext('[[File:equipment_顶层蒙版.png|150px|link=]]') | |||
-- 弹窗容器(遮罩) | |||
local modalContainer = root:tag('div') | |||
:addClass('equip-modal-container') | |||
:attr('id', modalId) | |||
:attr('style', 'display: none;') | |||
-- 点击遮罩关闭提示 | |||
-- 弹窗内容(按给定布局) | |||
local modal = modalContainer:tag('div') | |||
:addClass('equip-modal') | |||
:attr('style', 'position: relative; display: inline-block; width:368px; height: 335px; background-color: #343434; border-radius: 9px') | |||
modal:tag('div') | |||
:attr('style', 'position: absolute; top: 0px; left: 0px;') | |||
:wikitext(string.format('[[File:bg_collection_rarity_%s.png|link=]]', rarity)) | |||
modal:tag('div') | |||
:attr('style', 'position: absolute; top: 40px; left: 128px;') | |||
:wikitext(string.format('[[File:%s|124px|link=]]', art)) | |||
modal:tag('div') | |||
:attr('style', 'position: absolute; top: 167px; left: 0px; width: 368px; height: 35px; background-color: rgba(0,0,0,0.5); border-radius: 0px 0px 8px 8px') | |||
modal:tag('div') | |||
:attr('style', 'position: absolute; top: 173px; left: 128px; ') | |||
:wikitext(string.format('[[File:%s|link=]]', starIcon(level))) | |||
modal:tag('div') | |||
:attr('style', 'position: absolute; top: 205px; left: 5px; color: white') | |||
:wikitext(string.format('[[File:icon_equip_%s_%s.png|25px|link=]]', typ, rarity)) | |||
modal:tag('div') | |||
:attr('style', 'position: absolute; top: 209px; left: 33px; color: white') | |||
:wikitext(name) | |||
modal:tag('div') | |||
:attr('style', 'position: absolute; top: 235px; left: 9px; width: 350px; height: 35px; background-color: rgba(255,255,255,0.3); border-radius: 2px') | |||
modal:tag('div') | |||
:attr('style', 'position: absolute; top: 242px; left: 14px; color: white') | |||
:wikitext(valueType) | |||
modal:tag('div') | |||
:attr('style', 'position: absolute; top: 242px; right: 14px; color: white') | |||
:wikitext(tostring(value)) | |||
modal:tag('div') | |||
:attr('style', 'position: absolute; top: 277px; left: 10px; color: white') | |||
:wikitext(desc) | |||
-- 关闭按钮 | |||
modal:tag('div') | |||
:addClass('equip-modal-close') | |||
:attr('title', '关闭') | |||
:attr('style', 'position: absolute; top: 6px; right: 10px; color: white; font-size: 20px; line-height: 20px; cursor: pointer;') | |||
:wikitext('×') | |||
return tostring(root) | |||
end | end | ||
return p | return p | ||
2025年10月17日 (五) 15:36的版本
此模块的文档可以在模块:装备/doc创建
local p = {}
local data = mw.loadData('模块:装备/data')
local function getArgs(frame)
local args = frame.args or {}
local parent = frame:getParent()
if parent then
setmetatable(args, { __index = parent.args })
end
return args
end
local function sanitizeId(s)
s = tostring(s or '')
s = mw.ustring.gsub(s, "%s+", "_")
s = mw.ustring.gsub(s, "[%[%]{}()%c%p]", "_")
return s
end
local function clampLevel(level)
level = tonumber(level) or 1
if level < 1 then level = 1 end
if level > 5 then level = 5 end
return level
end
local function starIcon(level)
level = clampLevel(level)
return string.format("icon_star_rating_%d.png", level)
end
function p.render(frame)
local args = getArgs(frame)
local name = args.name or args[1]
local level = clampLevel(args.level or args.lv or args[2] or 1)
if not name or not data[name] then
return string.format("<span style='color:red'>[装备] 数据未找到:%s</span>", tostring(name or "未指定"))
end
local eq = data[name]
local base = eq.base or {}
local rarity = base.rarity or "蓝"
local art = base.art or ""
local typ = base.type or "武器"
local valueType = base.value_type or ""
local lvlKey = tostring(level)
local lvl = eq[lvlKey] or {}
local value = lvl.value or ""
local desc = lvl.desc_global or ""
local modalId = "equip_modal_" .. sanitizeId(name) .. "_" .. tostring(level)
local root = mw.html.create('div')
-- 小卡片
local card = root:tag('div')
:addClass('equip-card')
:attr('data-equip-id', modalId)
:attr('style', 'position: relative; display: inline-block; width:150px; height: 230px; cursor: pointer;')
card:tag('div')
:attr('style', 'position: absolute; top: 0px; left: 0px;')
:wikitext(string.format('[[File:bg_equipment_rarity_%s.png|150px|link=]]', rarity))
card:tag('div')
:attr('style', 'position: absolute; top: 43px; left: 13px;')
:wikitext(string.format('[[File:%s|124px|link=]]', art))
card:tag('div')
:attr('style', 'position: absolute; bottom: 5px; left: 5px; width: 140px; height: 35px; background-color: rgba(0,0,0,0.5); border-radius: 0px 0px 8px 8px')
card:tag('div')
:attr('style', 'position: absolute; bottom: 10px; left: 20px; ')
:wikitext(string.format('[[File:%s|link=]]', starIcon(level)))
card:tag('div')
:attr('style', 'position: absolute; top: 0px; left: 0px;')
:wikitext('[[File:equipment_顶层蒙版.png|150px|link=]]')
-- 弹窗容器(遮罩)
local modalContainer = root:tag('div')
:addClass('equip-modal-container')
:attr('id', modalId)
:attr('style', 'display: none;')
-- 点击遮罩关闭提示
-- 弹窗内容(按给定布局)
local modal = modalContainer:tag('div')
:addClass('equip-modal')
:attr('style', 'position: relative; display: inline-block; width:368px; height: 335px; background-color: #343434; border-radius: 9px')
modal:tag('div')
:attr('style', 'position: absolute; top: 0px; left: 0px;')
:wikitext(string.format('[[File:bg_collection_rarity_%s.png|link=]]', rarity))
modal:tag('div')
:attr('style', 'position: absolute; top: 40px; left: 128px;')
:wikitext(string.format('[[File:%s|124px|link=]]', art))
modal:tag('div')
:attr('style', 'position: absolute; top: 167px; left: 0px; width: 368px; height: 35px; background-color: rgba(0,0,0,0.5); border-radius: 0px 0px 8px 8px')
modal:tag('div')
:attr('style', 'position: absolute; top: 173px; left: 128px; ')
:wikitext(string.format('[[File:%s|link=]]', starIcon(level)))
modal:tag('div')
:attr('style', 'position: absolute; top: 205px; left: 5px; color: white')
:wikitext(string.format('[[File:icon_equip_%s_%s.png|25px|link=]]', typ, rarity))
modal:tag('div')
:attr('style', 'position: absolute; top: 209px; left: 33px; color: white')
:wikitext(name)
modal:tag('div')
:attr('style', 'position: absolute; top: 235px; left: 9px; width: 350px; height: 35px; background-color: rgba(255,255,255,0.3); border-radius: 2px')
modal:tag('div')
:attr('style', 'position: absolute; top: 242px; left: 14px; color: white')
:wikitext(valueType)
modal:tag('div')
:attr('style', 'position: absolute; top: 242px; right: 14px; color: white')
:wikitext(tostring(value))
modal:tag('div')
:attr('style', 'position: absolute; top: 277px; left: 10px; color: white')
:wikitext(desc)
-- 关闭按钮
modal:tag('div')
:addClass('equip-modal-close')
:attr('title', '关闭')
:attr('style', 'position: absolute; top: 6px; right: 10px; color: white; font-size: 20px; line-height: 20px; cursor: pointer;')
:wikitext('×')
return tostring(root)
end
return p