模块

事件:修订间差异

来自卡厄思梦境WIKI

律Rhyme留言 | 贡献
无编辑摘要
律Rhyme留言 | 贡献
无编辑摘要
 
(未显示同一用户的5个中间版本)
第1行: 第1行:
local p = {}
local p = {}
local eventData = require("Module:事件/data")
local eventData = mw.loadData('模块:事件/data')


function p.main(frame)
function p.main(frame)
     local html = mw.html.create()
     local output = {}
      
      
    -- 遍历所有事件
     for eventName, eventInfo in pairs(eventData) do
     for eventName, eventInfo in pairs(eventData) do
         html:node(p.createEventCard(eventName, eventInfo))
         table.insert(output, p.renderEvent(frame, eventName, eventInfo))
     end
     end
      
      
     return tostring(html)
     return table.concat(output, '\n')
end
end


function p.createEventCard(eventName, eventInfo)
function p.renderEvent(frame, eventName, eventInfo)
     local card = mw.html.create('div')
     local html = mw.html.create('div')
    card:addClass('event-card')
        :addClass('event-container')
        :attr('data-event-id', eventInfo.id)
      
      
     -- 容器
     -- 背景层
     local container = mw.html.create('div')
     html:tag('div'):addClass('event-background')
    container:addClass('event-container')
      
      
     -- 图片
     -- 图片
     local imageDiv = mw.html.create('div')
     local imageLink = eventName
    imageDiv:addClass('event-image')
    html:tag('div')
    imageDiv:node(string.format('[[File:cc_%s.png|link=]]', eventInfo.id))
        :addClass('event-image')
    container:node(imageDiv)
        :wikitext(string.format('[[File:cc_%s.png|link=%s]]', eventInfo.id, imageLink))
      
      
     -- 标题背景
     -- 标题背景
     local titleBg = mw.html.create('div')
     html:tag('div'):addClass('event-title-bg')
    titleBg:addClass('event-title-bg')
    container:node(titleBg)
      
      
     -- 标题
     -- 标题
     local titleDiv = mw.html.create('div')
     html:tag('div')
    titleDiv:addClass('event-title')
        :addClass('event-title')
    titleDiv:wikitext(eventName)
        :wikitext(eventName)
    container:node(titleDiv)
      
      
     -- 选项容器
     -- 选项容器
     local optionsDiv = mw.html.create('div')
     local optionsContainer = html:tag('div'):addClass('event-options')
    optionsDiv:addClass('event-options')
      
      
     for i, option in ipairs(eventInfo.option) do
    -- 渲染选项
         local optionDiv = mw.html.create('div')
     for i, optionText in ipairs(eventInfo.option) do
        optionDiv:addClass('event-option')
         -- 选项
        optionDiv:attr('data-option-index', i)
        optionsContainer:tag('div')
         optionDiv:attr('data-event-id', eventInfo.id)
            :addClass('event-option')
         optionDiv:wikitext(option)
            :attr('data-option-index', i)
        optionsDiv:node(optionDiv)
            :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
     end
      
      
     container:node(optionsDiv)
     return tostring(html)
   
end
    -- 效果显示区域
 
    local effectDiv = mw.html.create('div')
-- 单独显示某个事件
    effectDiv:addClass('event-effect')
function p.show(frame)
    effectDiv:attr('id', 'effect-' .. eventInfo.id)
     local eventName = frame.args[1]
    container:node(effectDiv)
    if not eventName or not eventData[eventName] then
   
         return '错误:未找到指定的事件'
    -- 隐藏的效果数据
    local dataDiv = mw.html.create('div')
     dataDiv:addClass('event-data')
    dataDiv:attr('style', 'display:none;')
   
    for i, effect in ipairs(eventInfo.effect) do
        local effectData = mw.html.create('div')
        effectData:addClass('effect-data')
         effectData:attr('data-index', i)
        effectData:wikitext(effect)
        dataDiv:node(effectData)
     end
     end
      
      
     container:node(dataDiv)
     return p.renderEvent(frame, eventName, eventData[eventName])
   
    card:node(container)
    return card
end
end


return p
return p

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