事件:修订间差异
来自卡厄思梦境WIKI
无编辑摘要 |
无编辑摘要 |
||
| (未显示同一用户的1个中间版本) | |||
| 第22行: | 第22行: | ||
-- 图片 | -- 图片 | ||
local imageLink = eventName | |||
html:tag('div') | html:tag('div') | ||
:addClass('event-image') | :addClass('event-image') | ||
:wikitext(string.format('[[File:cc_%s.png|link=]]', eventInfo.id)) | :wikitext(string.format('[[File:cc_%s.png|link=%s]]', eventInfo.id, imageLink)) | ||
-- 标题背景 | -- 标题背景 | ||
| 第39行: | 第40行: | ||
-- 渲染选项 | -- 渲染选项 | ||
for i, optionText in ipairs(eventInfo.option) do | for i, optionText in ipairs(eventInfo.option) do | ||
-- 选项 | |||
optionsContainer:tag('div') | |||
:addClass('event-option') | :addClass('event-option') | ||
:attr('data-option-index', i) | :attr('data-option-index', i) | ||
:wikitext(optionText) | :wikitext(optionText) | ||
-- | -- 结果显示区域 | ||
local effectDiv = optionsContainer:tag('div') | local effectDiv = optionsContainer:tag('div') | ||
:addClass('event-effect') | :addClass('event-effect') | ||
:attr('data-effect-index', i) | :attr('data-effect-index', i) | ||
-- | -- 处理结果文本 | ||
local effectText = eventInfo.effect[i] | local effectText = eventInfo.effect[i] | ||
if effectText then | if effectText then | ||
if frame then | if frame then | ||
effectText = frame:preprocess(effectText) | effectText = frame:preprocess(effectText) | ||
2025年10月18日 (六) 13:38的最新版本
此模块的文档可以在模块:事件/doc创建
local p = {}
local eventData = mw.loadData('模块:事件/data')
function p.main(frame)
local output = {}
-- 遍历所有事件
for eventName, eventInfo in pairs(eventData) do
table.insert(output, p.renderEvent(frame, eventName, eventInfo))
end
return table.concat(output, '\n')
end
function p.renderEvent(frame, eventName, eventInfo)
local html = mw.html.create('div')
:addClass('event-container')
:attr('data-event-id', eventInfo.id)
-- 背景层
html:tag('div'):addClass('event-background')
-- 图片
local imageLink = eventName
html:tag('div')
:addClass('event-image')
:wikitext(string.format('[[File:cc_%s.png|link=%s]]', eventInfo.id, imageLink))
-- 标题背景
html:tag('div'):addClass('event-title-bg')
-- 标题
html:tag('div')
:addClass('event-title')
:wikitext(eventName)
-- 选项容器
local optionsContainer = html:tag('div'):addClass('event-options')
-- 渲染选项
for i, optionText in ipairs(eventInfo.option) do
-- 选项
optionsContainer:tag('div')
:addClass('event-option')
:attr('data-option-index', i)
:wikitext(optionText)
-- 结果显示区域
local effectDiv = optionsContainer:tag('div')
:addClass('event-effect')
:attr('data-effect-index', i)
-- 处理结果文本
local effectText = eventInfo.effect[i]
if effectText then
if frame then
effectText = frame:preprocess(effectText)
end
effectDiv:wikitext(effectText)
end
end
return tostring(html)
end
-- 单独显示某个事件
function p.show(frame)
local eventName = frame.args[1]
if not eventName or not eventData[eventName] then
return '错误:未找到指定的事件'
end
return p.renderEvent(frame, eventName, eventData[eventName])
end
return p