事件:修订间差异
来自卡厄思梦境WIKI
无编辑摘要 |
无编辑摘要 |
||
| 第24行: | 第24行: | ||
local html = mw.html.create('div') | local html = mw.html.create('div') | ||
:addClass('event-container') | :addClass('event-container') | ||
: | :attr('data-event-id', event.id) | ||
-- | -- 图片容器 | ||
html:tag('div') | local imageContainer = html:tag('div') | ||
:addClass('event- | :addClass('event-image-container') | ||
-- 图片 | -- 图片 | ||
local imageFile = 'cc_' .. event.id .. '.png' | local imageFile = 'cc_' .. event.id .. '.png' | ||
imageContainer:wikitext('[[File:' .. imageFile .. '|375px|link=]]') | |||
-- | -- 标题条 | ||
imageContainer:tag('div') | |||
: | :addClass('event-title-bar') | ||
: | :tag('div') | ||
:addClass('event-title') | |||
:wikitext(eventName) | |||
-- | -- 选项容器 | ||
html:tag('div') | local optionsContainer = html:tag('div') | ||
:addClass('event- | :addClass('event-options-container') | ||
-- 选项 | -- 选项 | ||
for i = 1, 3 do | for i = 1, 3 do | ||
if event.option[i] then | if event.option[i] then | ||
local optionDiv = | local optionWrapper = optionsContainer:tag('div') | ||
:addClass('event-option-wrapper') | |||
local optionDiv = optionWrapper:tag('div') | |||
:addClass('event-option') | :addClass('event-option') | ||
:attr('data-option-id', tostring(i)) | :attr('data-option-id', tostring(i)) | ||
:attr('data-event-name', eventName) | :attr('data-event-name', eventName) | ||
-- 选项文本 | -- 选项文本 | ||
| 第95行: | 第61行: | ||
:wikitext(event.option[i]) | :wikitext(event.option[i]) | ||
-- | -- 结果文本容器(默认隐藏) | ||
local effectDiv = optionWrapper:tag('div') | |||
:addClass('option-effect') | :addClass('option-effect-container') | ||
:css('display', 'none') | :css('display', 'none') | ||
: | :tag('div') | ||
:addClass('option-effect') | |||
:wikitext(frame:preprocess(event.effect[i])) | |||
end | end | ||
end | end | ||
2025年10月18日 (六) 11:25的版本
此模块的文档可以在模块:事件/doc创建
local p = {}
local eventData = mw.loadData('模块:事件/data')
function p.main(frame)
-- 直接从frame.args获取参数(用于#invoke调用)
local eventName = frame.args[1] or frame.args.name
-- 如果没有找到,尝试从父frame获取(用于模板调用)
if not eventName and frame:getParent() then
local parentArgs = frame:getParent().args
eventName = parentArgs[1] or parentArgs.name
end
if not eventName or eventName == '' then
return "错误:未指定事件名称"
end
local event = eventData[eventName]
if not event then
return "错误:找不到事件 '" .. eventName .. "'"
end
-- 构建HTML
local html = mw.html.create('div')
:addClass('event-container')
:attr('data-event-id', event.id)
-- 图片容器
local imageContainer = html:tag('div')
:addClass('event-image-container')
-- 图片
local imageFile = 'cc_' .. event.id .. '.png'
imageContainer:wikitext('[[File:' .. imageFile .. '|375px|link=]]')
-- 标题条
imageContainer:tag('div')
:addClass('event-title-bar')
:tag('div')
:addClass('event-title')
:wikitext(eventName)
-- 选项容器
local optionsContainer = html:tag('div')
:addClass('event-options-container')
-- 选项
for i = 1, 3 do
if event.option[i] then
local optionWrapper = optionsContainer:tag('div')
:addClass('event-option-wrapper')
local optionDiv = optionWrapper:tag('div')
:addClass('event-option')
:attr('data-option-id', tostring(i))
:attr('data-event-name', eventName)
-- 选项文本
optionDiv:tag('div')
:addClass('option-text')
:wikitext(event.option[i])
-- 结果文本容器(默认隐藏)
local effectDiv = optionWrapper:tag('div')
:addClass('option-effect-container')
:css('display', 'none')
:tag('div')
:addClass('option-effect')
:wikitext(frame:preprocess(event.effect[i]))
end
end
return tostring(html)
end
return p