装备:修订间差异
来自卡厄思梦境WIKI
无编辑摘要 |
无编辑摘要 |
||
| 第1行: | 第1行: | ||
local p = {} | local p = {} | ||
| 第85行: | 第84行: | ||
local modalId = "equip_modal_" .. sanitizeId(name) .. "_" .. tostring(level) | local modalId = "equip_modal_" .. sanitizeId(name) .. "_" .. tostring(level) | ||
local root = mw.html.create(' | local root = mw.html.create('span') | ||
-- 使用锚点触发 :target 显示弹窗(无 JS 也可用) | |||
local link = root:tag('a') | |||
:attr('href', '#' .. modalId) | |||
:attr('style', 'text-decoration:none;') | |||
-- 卡片 | -- 卡片 | ||
local card = | local card = link:tag('div') | ||
:addClass('equip-card') | :addClass('equip-card') | ||
:attr('data-equip-id', modalId) | :attr('data-equip-id', modalId) | ||
| 第112行: | 第116行: | ||
:wikitext('[[File:equipment_顶层蒙版.png|150px|link=]]') | :wikitext('[[File:equipment_顶层蒙版.png|150px|link=]]') | ||
-- | -- 弹窗容器(遮罩) | ||
local modalContainer = root:tag('div') | local modalContainer = root:tag('div') | ||
:addClass('equip-modal-container') | :addClass('equip-modal-container') | ||
:attr('id', modalId) | :attr('id', modalId) | ||
-- 弹窗内容 | |||
local modal = modalContainer:tag('div') | local modal = modalContainer:tag('div') | ||
:addClass('equip-modal') | :addClass('equip-modal') | ||
| 第160行: | 第164行: | ||
:wikitext(desc) | :wikitext(desc) | ||
modal:tag(' | -- 关闭按钮(锚点,回到无 hash) | ||
modal:tag('a') | |||
:addClass('equip-modal-close') | :addClass('equip-modal-close') | ||
:attr('href', '#') | |||
:attr('title', '关闭') | :attr('title', '关闭') | ||
:attr('style', 'position: absolute; top: 6px; right: 10px; color: white; font-size: 20px; line-height: 20px; cursor: pointer;') | :attr('style', 'position: absolute; top: 6px; right: 10px; color: white; font-size: 20px; line-height: 20px; cursor: pointer; text-decoration:none;') | ||
:wikitext('×') | :wikitext('×') | ||
2025年10月17日 (五) 15:42的版本
此模块的文档可以在模块:装备/doc创建
local p = {}
-- 兼容不同命名空间的 data 路径
local function loadData()
local paths = { '模块:装备/data', 'Module:装备/data' }
for _, path in ipairs(paths) do
local ok, d = pcall(mw.loadData, path)
if ok and type(d) == 'table' then
return d
end
end
return {}
end
local data = loadData()
-- 更稳健的参数获取(优先使用 Arguments 模块,兼容中英文命名)
local function getArgsCompat(frame)
local tryModules = { 'Module:Arguments', '模块:Arguments' }
for _, m in ipairs(tryModules) do
local ok, Arguments = pcall(require, m)
if ok and type(Arguments) == 'table' and type(Arguments.getArgs) == 'function' then
return Arguments.getArgs(frame, { parentOnly = false })
end
end
-- 回退:合并 frame.args 与 parent.args 到普通表
local args = {}
local fa = frame.args or {}
for k, v in pairs(fa) do args[k] = v end
local parent = frame:getParent()
if parent and parent.args then
for k, v in pairs(parent.args) do
if args[k] == nil then args[k] = v end
end
end
return args
end
local function clampLevel(level)
level = tonumber(level)
if not level then return 1 end
if level < 1 then return 1 end
if level > 5 then return 5 end
return level
end
local function starIcon(level)
level = clampLevel(level)
return string.format("icon_star_rating_%d.png", level)
end
local function sanitizeId(s)
s = tostring(s or '')
s = mw.text.trim(s)
s = mw.ustring.gsub(s, "%s+", "_")
s = mw.ustring.gsub(s, "[%[%]{}()%c%p]", "_")
return s
end
function p.render(frame)
local args = getArgsCompat(frame)
-- 支持多种参数名(中文键使用方括号访问,避免语法错误)
local name = args.name or args['名称'] or args[1]
local level = clampLevel(args.level or args.lv or args['等级'] or args[2] or 1)
if not name or name == '' then
return "<span style='color:red'>[装备] 数据未找到:未指定</span>"
end
if not data[name] then
return string.format("<span style='color:red'>[装备] 数据未找到:%s</span>", mw.text.encode(name))
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('span')
-- 使用锚点触发 :target 显示弹窗(无 JS 也可用)
local link = root:tag('a')
:attr('href', '#' .. modalId)
:attr('style', 'text-decoration:none;')
-- 卡片
local card = link: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)
-- 弹窗内容
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)
-- 关闭按钮(锚点,回到无 hash)
modal:tag('a')
:addClass('equip-modal-close')
:attr('href', '#')
:attr('title', '关闭')
:attr('style', 'position: absolute; top: 6px; right: 10px; color: white; font-size: 20px; line-height: 20px; cursor: pointer; text-decoration:none;')
:wikitext('×')
return tostring(root)
end
return p