装备:修订间差异
来自卡厄思梦境WIKI
无编辑摘要 |
无编辑摘要 |
||
| 第1行: | 第1行: | ||
local p = {} | local p = {} | ||
local | local data = mw.loadData('模块:装备/data') | ||
-- | -- 获取装备稀有度对应的中文 | ||
local | local rarityMap = { | ||
["蓝"] = "蓝", | |||
["紫"] = "紫", | |||
["金"] = "金" | |||
} | |||
-- | -- 生成装备卡片 | ||
function p.card(frame) | function p.card(frame) | ||
local args = frame.args | local args = frame.args | ||
| 第16行: | 第15行: | ||
local level = args[2] or args.level or "1" | local level = args[2] or args.level or "1" | ||
if not name or not | if not name or not data[name] then | ||
return "装备不存在" | return "装备不存在: " .. (name or "未指定") | ||
end | end | ||
local equip = | local equip = data[name] | ||
local base = equip.base | local base = equip.base | ||
local levelData = equip[level] | local levelData = equip[level] | ||
if not levelData then | if not levelData then | ||
return " | return "装备等级不存在: " .. level | ||
end | end | ||
-- | -- 生成HTML | ||
local html = ' | local html = mw.html.create('div') | ||
:addClass('equipment-card') | |||
:attr('data-equipment', name) | |||
:attr('data-level', level) | |||
:cssText('position: relative; display: inline-block; width:150px; height: 230px; cursor: pointer;') | |||
-- | -- 背景 | ||
html:tag('div') | |||
:cssText('position: absolute; top: 0px; left: 0px;') | |||
:wikitext(string.format('[[File:bg_equipment_rarity_%s.png|150px|link=]]', base.rarity)) | |||
return | -- 装备图片 | ||
html:tag('div') | |||
:cssText('position: absolute; top: 43px; left: 13px;') | |||
:wikitext(string.format('[[File:%s|124px|link=]]', base.art)) | |||
-- 底部背景 | |||
html:tag('div') | |||
:cssText('position: absolute; bottom: 5px; left: 5px; width: 140px; height: 35px; background-color: rgba(0,0,0,0.5); border-radius: 0px 0px 8px 8px') | |||
-- 星级 | |||
html:tag('div') | |||
:cssText('position: absolute; bottom: 10px; left: 20px;') | |||
:wikitext(string.format('[[File:icon_star_rating_%s.png|link=]]', level)) | |||
-- 顶层蒙版 | |||
html:tag('div') | |||
:cssText('position: absolute; top: 0px; left: 0px;') | |||
:wikitext('[[File:equipment_顶层蒙版.png|150px|link=]]') | |||
return tostring(html) | |||
end | end | ||
-- | -- 生成装备详情弹窗 | ||
function p. | function p.popup(frame) | ||
local | local args = frame.args | ||
local name = args[1] or args.name | |||
local level = args[2] or args.level or "1" | |||
if not name or not data[name] then | |||
return "装备不存在: " .. (name or "未指定") | |||
end | end | ||
return | |||
local equip = data[name] | |||
local base = equip.base | |||
local levelData = equip[level] | |||
if not levelData then | |||
return "装备等级不存在: " .. level | |||
end | |||
-- 处理描述文本 | |||
local desc = levelData.desc_global | |||
desc = string.gsub(desc, "{{文本|橙|([^}]+)}}", '<span style="color:#ff9500;">%1</span>') | |||
-- 生成HTML | |||
local html = mw.html.create('div') | |||
:addClass('equipment-popup') | |||
:attr('id', 'equipment-popup-' .. mw.uri.encode(name)) | |||
:cssText('position: relative; display: none; width:368px; height: 335px; background-color: #343434; border-radius: 9px') | |||
-- 背景 | |||
html:tag('div') | |||
:cssText('position: absolute; top: 0px; left: 0px;') | |||
:wikitext(string.format('[[File:bg_collection_rarity_%s.png|link=]]', base.rarity)) | |||
-- 装备图片 | |||
html:tag('div') | |||
:cssText('position: absolute; top: 40px; left: 128px;') | |||
:wikitext(string.format('[[File:%s|124px|link=]]', base.art)) | |||
-- 星级背景 | |||
html:tag('div') | |||
:cssText('position: absolute; top: 167px; left: 0px; width: 368px; height: 35px; background-color: rgba(0,0,0,0.5);') | |||
-- 星级 | |||
html:tag('div') | |||
:cssText('position: absolute; top: 173px; left: 128px;') | |||
:wikitext(string.format('[[File:icon_star_rating_%s.png|link=]]', level)) | |||
-- 类型图标 | |||
html:tag('div') | |||
:cssText('position: absolute; top: 205px; left: 5px; color: white') | |||
:wikitext(string.format('[[File:icon_equip_%s_%s.png|25px|link=]]', base.type, base.rarity)) | |||
-- 装备名称 | |||
html:tag('div') | |||
:cssText('position: absolute; top: 209px; left: 33px; color: white') | |||
:wikitext(name) | |||
-- 属性背景 | |||
html:tag('div') | |||
:cssText('position: absolute; top: 235px; left: 9px; width: 350px; height: 35px; background-color: rgba(255,255,255,0.3); border-radius: 2px') | |||
-- 属性类型 | |||
html:tag('div') | |||
:cssText('position: absolute; top: 242px; left: 14px; color: white') | |||
:wikitext(base.value_type) | |||
-- 属性值 | |||
html:tag('div') | |||
:cssText('position: absolute; top: 242px; right: 14px; color: white') | |||
:wikitext(levelData.value) | |||
-- 描述 | |||
html:tag('div') | |||
:cssText('position: absolute; top: 277px; left: 10px; right: 10px; color: white; font-size: 14px;') | |||
:wikitext(desc) | |||
-- 关闭按钮 | |||
html:tag('div') | |||
:addClass('equipment-popup-close') | |||
:cssText('position: absolute; top: 10px; right: 10px; width: 24px; height: 24px; cursor: pointer; color: white; font-size: 20px;') | |||
:wikitext('×') | |||
return tostring(html) | |||
end | |||
-- 生成装备完整展示(卡片+弹窗) | |||
function p.show(frame) | |||
local cardHtml = p.card(frame) | |||
local popupHtml = p.popup(frame) | |||
local wrapper = mw.html.create('div') | |||
:addClass('equipment-wrapper') | |||
:cssText('display: inline-block; position: relative;') | |||
:wikitext(cardHtml) | |||
:wikitext(popupHtml) | |||
return tostring(wrapper) | |||
end | end | ||
return p | return p | ||
2025年10月17日 (五) 16:13的版本
此模块的文档可以在模块:装备/doc创建
local p = {}
local data = mw.loadData('模块:装备/data')
-- 获取装备稀有度对应的中文
local rarityMap = {
["蓝"] = "蓝",
["紫"] = "紫",
["金"] = "金"
}
-- 生成装备卡片
function p.card(frame)
local args = frame.args
local name = args[1] or args.name
local level = args[2] or args.level or "1"
if not name or not data[name] then
return "装备不存在: " .. (name or "未指定")
end
local equip = data[name]
local base = equip.base
local levelData = equip[level]
if not levelData then
return "装备等级不存在: " .. level
end
-- 生成HTML
local html = mw.html.create('div')
:addClass('equipment-card')
:attr('data-equipment', name)
:attr('data-level', level)
:cssText('position: relative; display: inline-block; width:150px; height: 230px; cursor: pointer;')
-- 背景
html:tag('div')
:cssText('position: absolute; top: 0px; left: 0px;')
:wikitext(string.format('[[File:bg_equipment_rarity_%s.png|150px|link=]]', base.rarity))
-- 装备图片
html:tag('div')
:cssText('position: absolute; top: 43px; left: 13px;')
:wikitext(string.format('[[File:%s|124px|link=]]', base.art))
-- 底部背景
html:tag('div')
:cssText('position: absolute; bottom: 5px; left: 5px; width: 140px; height: 35px; background-color: rgba(0,0,0,0.5); border-radius: 0px 0px 8px 8px')
-- 星级
html:tag('div')
:cssText('position: absolute; bottom: 10px; left: 20px;')
:wikitext(string.format('[[File:icon_star_rating_%s.png|link=]]', level))
-- 顶层蒙版
html:tag('div')
:cssText('position: absolute; top: 0px; left: 0px;')
:wikitext('[[File:equipment_顶层蒙版.png|150px|link=]]')
return tostring(html)
end
-- 生成装备详情弹窗
function p.popup(frame)
local args = frame.args
local name = args[1] or args.name
local level = args[2] or args.level or "1"
if not name or not data[name] then
return "装备不存在: " .. (name or "未指定")
end
local equip = data[name]
local base = equip.base
local levelData = equip[level]
if not levelData then
return "装备等级不存在: " .. level
end
-- 处理描述文本
local desc = levelData.desc_global
desc = string.gsub(desc, "{{文本|橙|([^}]+)}}", '<span style="color:#ff9500;">%1</span>')
-- 生成HTML
local html = mw.html.create('div')
:addClass('equipment-popup')
:attr('id', 'equipment-popup-' .. mw.uri.encode(name))
:cssText('position: relative; display: none; width:368px; height: 335px; background-color: #343434; border-radius: 9px')
-- 背景
html:tag('div')
:cssText('position: absolute; top: 0px; left: 0px;')
:wikitext(string.format('[[File:bg_collection_rarity_%s.png|link=]]', base.rarity))
-- 装备图片
html:tag('div')
:cssText('position: absolute; top: 40px; left: 128px;')
:wikitext(string.format('[[File:%s|124px|link=]]', base.art))
-- 星级背景
html:tag('div')
:cssText('position: absolute; top: 167px; left: 0px; width: 368px; height: 35px; background-color: rgba(0,0,0,0.5);')
-- 星级
html:tag('div')
:cssText('position: absolute; top: 173px; left: 128px;')
:wikitext(string.format('[[File:icon_star_rating_%s.png|link=]]', level))
-- 类型图标
html:tag('div')
:cssText('position: absolute; top: 205px; left: 5px; color: white')
:wikitext(string.format('[[File:icon_equip_%s_%s.png|25px|link=]]', base.type, base.rarity))
-- 装备名称
html:tag('div')
:cssText('position: absolute; top: 209px; left: 33px; color: white')
:wikitext(name)
-- 属性背景
html:tag('div')
:cssText('position: absolute; top: 235px; left: 9px; width: 350px; height: 35px; background-color: rgba(255,255,255,0.3); border-radius: 2px')
-- 属性类型
html:tag('div')
:cssText('position: absolute; top: 242px; left: 14px; color: white')
:wikitext(base.value_type)
-- 属性值
html:tag('div')
:cssText('position: absolute; top: 242px; right: 14px; color: white')
:wikitext(levelData.value)
-- 描述
html:tag('div')
:cssText('position: absolute; top: 277px; left: 10px; right: 10px; color: white; font-size: 14px;')
:wikitext(desc)
-- 关闭按钮
html:tag('div')
:addClass('equipment-popup-close')
:cssText('position: absolute; top: 10px; right: 10px; width: 24px; height: 24px; cursor: pointer; color: white; font-size: 20px;')
:wikitext('×')
return tostring(html)
end
-- 生成装备完整展示(卡片+弹窗)
function p.show(frame)
local cardHtml = p.card(frame)
local popupHtml = p.popup(frame)
local wrapper = mw.html.create('div')
:addClass('equipment-wrapper')
:cssText('display: inline-block; position: relative;')
:wikitext(cardHtml)
:wikitext(popupHtml)
return tostring(wrapper)
end
return p