卡牌:修订间差异
来自卡厄思梦境WIKI
小无编辑摘要 |
小无编辑摘要 |
||
| 第55行: | 第55行: | ||
.. '<div style="position: absolute; top: 10px; left: 0px;">[[File:card_稀有度_' .. color .. '.png|22px|link=]]</div>' | .. '<div style="position: absolute; top: 10px; left: 0px;">[[File:card_稀有度_' .. color .. '.png|22px|link=]]</div>' | ||
.. '<div style="position: absolute; top: 2px; right: 4px;">[[File:card_稀有度_边框_' .. color .. '.png|11px|link=]]</div>' | .. '<div style="position: absolute; top: 2px; right: 4px;">[[File:card_稀有度_边框_' .. color .. '.png|11px|link=]]</div>' | ||
.. '<div style="position: absolute; bottom: 7px; left: 15px; width: 144px; height: 100px; font-size: 12px; color: white; line-height: 13px; text-align: center;">' .. description .. '</div>' | |||
-- 修改描述部分,使用Flexbox实现完全居中 | |||
.. '<div style="position: absolute; bottom: 7px; left: 15px; width: 144px; height: 100px; font-size: 12px; color: white; line-height: 13px; display: flex; justify-content: center; align-items: center; text-align: center;">' | |||
.. '<div>' .. description .. '</div>' | |||
.. '</div>' | |||
.. '</div>' | .. '</div>' | ||
2025年9月27日 (六) 15:56的版本
此模块的文档可以在模块:卡牌/doc创建
-- 模块:卡牌
local p = {}
local mw = require('mw')
-- 颜色映射表
local colorMap = {
["白"] = {
bgColor = "rgba(249, 249, 249, 0.5)",
textColor = "white"
},
["蓝"] = {
bgColor = "rgba(115, 236, 254, 0.5)",
textColor = "#7de5ff"
},
["橙"] = {
bgColor = "rgba(254, 199, 109, 0.5)",
textColor = "#ffee75"
},
["彩"] = {
bgColor = "rgba(201, 88, 241, 0.5)",
textColor = "#eba2fc"
}
}
-- 获取卡牌HTML
local function getCardHTML(frame, cardName, cardData)
if not cardData then
return "找不到卡牌数据: " .. (cardName or "未指定")
end
local data = cardData[1] -- 使用第一个数据条目
local color = data["颜色"] or "白"
local colorStyle = colorMap[color] or colorMap["白"]
local ap = data["AP"] or ""
local cardType = data["类型"] or ""
local description = data["描述"] or ""
-- 解析描述中的模板
if description ~= "" then
-- 使用frame:preprocess来解析描述中的模板
description = frame:preprocess(description)
end
-- 构建卡牌HTML
local html = '<div style="position: relative; width: 168px; height: 230px; overflow: hidden;">'
.. '<div style="position: absolute; top: 1px; left: 12px;">[[File:start_1041_01.png|151px|link=]]</div>'
.. '<div style="position: absolute; top: 1px; left: 12px;">[[File:card_黑色蒙版.png|151px|link=]]</div>'
.. '<div style="position: absolute; top: 20px; left: 10px; width: 148px; height: 10px; background-color: ' .. colorStyle.bgColor .. ';"></div>'
.. '<div style="position: absolute; left: 23px; top: 4px; color: white; font-weight: bold; text-shadow: 0 0 10px #4a90e2,0 0 20px #4a90e2, 0 0 30px #4a90e2, 0 0 40px #4a90e2; font-size: 32px;">' .. ap .. '</div>'
.. '<div style="position: absolute; left: 25px; top: 34px; color: white; font-weight: bold; text-shadow: 0 0 10px #4a90e2,0 0 20px #4a90e2, 0 0 30px #4a90e2, 0 0 40px #4a90e2;">—</div>'
.. '<div style="position: absolute; left: 50px; top: 13px; color: ' .. colorStyle.textColor .. '; font-size:16px">' .. cardName .. '</div>'
.. '<div style="position: absolute; left: 48px; top: 30px; ">[[File:icon_card_' .. cardType .. '.png|18px|link=]]</div>'
.. '<div style="position: absolute; left: 68px; top: 33px; color: white; font-size:14px">' .. cardType .. '</div>'
.. '<div style="position: absolute; top: 0px; left: 1px;">[[File:card_属性边框_虚无_normal.png|160px|link=]]</div>'
.. '<div style="position: absolute; top: 10px; left: 0px;">[[File:card_稀有度_' .. color .. '.png|22px|link=]]</div>'
.. '<div style="position: absolute; top: 2px; right: 4px;">[[File:card_稀有度_边框_' .. color .. '.png|11px|link=]]</div>'
-- 修改描述部分,使用Flexbox实现完全居中
.. '<div style="position: absolute; bottom: 7px; left: 15px; width: 144px; height: 100px; font-size: 12px; color: white; line-height: 13px; display: flex; justify-content: center; align-items: center; text-align: center;">'
.. '<div>' .. description .. '</div>'
.. '</div>'
.. '</div>'
return html
end
-- 主函数,用于处理模板调用
function p.main(frame)
local args = frame.args
local characterName = args[1] or ""
local cardName = args[2] or ""
-- 动态加载角色模块
local characterModule = nil
local success = pcall(function()
characterModule = require("模块:卡牌/" .. characterName)
end)
if not success or not characterModule then
return "找不到角色模块: 模块:卡牌/" .. characterName
end
-- 获取卡牌数据
local cards = characterModule.card or {}
local cardData = cards[cardName]
-- 返回卡牌HTML,传入frame以便解析模板
return getCardHTML(frame, cardName, cardData)
end
-- 为每个角色创建一个直接调用方法
setmetatable(p, {
__index = function(t, characterName)
return function(frame)
local args = frame.args
local cardName = args[1] or ""
-- 动态加载角色模块
local characterModule = nil
local success = pcall(function()
characterModule = require("模块:卡牌/" .. characterName)
end)
if not success or not characterModule then
return "找不到角色模块: 模块:卡牌/" .. characterName
end
-- 获取卡牌数据
local cards = characterModule.card or {}
local cardData = cards[cardName]
-- 返回卡牌HTML,传入frame以便解析模板
return getCardHTML(frame, cardName, cardData)
end
end
})
return p