模块

事件:修订间差异

来自卡厄思梦境WIKI

律Rhyme留言 | 贡献
无编辑摘要
律Rhyme留言 | 贡献
无编辑摘要
 
(未显示同一用户的4个中间版本)
第3行: 第3行:


function p.main(frame)
function p.main(frame)
     local output = mw.html.create('div')
     local output = {}
    output:addClass('event-list-container')
   
    -- 添加RL模块
    frame:extensionTag{
        name = 'templatestyles',
        args = { src = 'MediaWiki:EventList.css' }
    }
      
      
     -- 遍历所有事件
     -- 遍历所有事件
     for eventName, eventInfo in pairs(eventData) do
     for eventName, eventInfo in pairs(eventData) do
         local eventDiv = p.createEventCard(eventName, eventInfo)
         table.insert(output, p.renderEvent(frame, eventName, eventInfo))
        output:node(eventDiv)
     end
     end
      
      
     return tostring(output)
     return table.concat(output, '\n')
end
end


function p.createEventCard(eventName, eventInfo)
function p.renderEvent(frame, eventName, eventInfo)
     local container = mw.html.create('div')
     local html = mw.html.create('div')
         :css('position', 'relative')
         :addClass('event-container')
        :css('width', '375px')
        :css('height', '270px')
        :css('display', 'inline-block')
        :css('margin', '10px')
        :css('vertical-align', 'top')
         :attr('data-event-id', eventInfo.id)
         :attr('data-event-id', eventInfo.id)
        :addClass('event-card')
      
      
     -- 底部背景
     -- 背景层
     local bottomBg = mw.html.create('div')
     html:tag('div'):addClass('event-background')
        :css('position', 'absolute')
        :css('top', '160px')
        :css('left', '5px')
        :css('width', '365px')
        :css('height', '110px')
        :css('background-color', '#343434')
        :css('border-radius', '0px 0px 8px 8px')
    container:node(bottomBg)
      
      
     -- 图片
     -- 图片
     local imageDiv = mw.html.create('div')
     local imageLink = eventName
         :css('position', 'absolute')
    html:tag('div')
         :css('top', '0px')
         :addClass('event-image')
        :css('left', '0px')
         :wikitext(string.format('[[File:cc_%s.png|link=%s]]', eventInfo.id, imageLink))
        :wikitext('[[File:cc_' .. eventInfo.id .. '.png|link=]]')
    container:node(imageDiv)
      
      
     -- 标题背景
     -- 标题背景
     local titleBg = mw.html.create('div')
     html:tag('div'):addClass('event-title-bg')
        :css('position', 'absolute')
        :css('top', '135px')
        :css('left', '5px')
        :css('width', '365px')
        :css('height', '30px')
        :css('background-color', 'rgba(0,0,0,0.3)')
        :css('border-radius', '0px 0px 8px 8px')
    container:node(titleBg)
      
      
     -- 标题文字
     -- 标题
     local titleText = mw.html.create('div')
     html:tag('div')
         :css('position', 'absolute')
         :addClass('event-title')
        :css('top', '140px')
        :css('left', '5px')
        :css('width', '365px')
        :css('height', '30px')
        :css('color', 'white')
        :css('text-align', 'center')
        :css('line-height', '30px')
         :wikitext(eventName)
         :wikitext(eventName)
    container:node(titleText)
      
      
     -- 选项列表
     -- 选项容器
     local optionCount = 0
     local optionsContainer = html:tag('div'):addClass('event-options')
    for i, optionText in pairs(eventInfo.option) do
        optionCount = optionCount + 1
    end
      
      
     for i = 1, optionCount do
    -- 渲染选项
        if eventInfo.option[i] then
     for i, optionText in ipairs(eventInfo.option) do
            local optionDiv = mw.html.create('div')
        -- 选项
                :addClass('event-option')
        optionsContainer:tag('div')
                :css('position', 'absolute')
            :addClass('event-option')
                :css('top', (160 + (i-1)*35) .. 'px')
            :attr('data-option-index', i)
                :css('left', '10px')
            :wikitext(optionText)
                :css('width', '355px')
       
                :css('min-height', '30px')
        -- 结果显示区域
                :css('color', 'white')
        local effectDiv = optionsContainer:tag('div')
                :css('text-align', 'left')
            :addClass('event-effect')
                :css('padding', '5px 0px 5px 10px')
            :attr('data-effect-index', i)
                :css('background-color', 'rgba(255,255,255,0.3)')
       
                :css('border-radius', '4px')
        -- 处理结果文本
                :css('cursor', 'pointer')
        local effectText = eventInfo.effect[i]
                :attr('data-option-index', i)
        if effectText then
                :wikitext(eventInfo.option[i])
            if frame then
            container:node(optionDiv)
                 effectText = frame:preprocess(effectText)
           
            -- 效果显示区域(默认隐藏)
            if eventInfo.effect[i] then
                local effectDiv = mw.html.create('div')
                    :addClass('event-effect')
                    :css('position', 'absolute')
                    :css('top', (195 + (i-1)*35) .. 'px')
                    :css('left', '10px')
                    :css('width', '355px')
                    :css('color', '#ffcc00')
                    :css('text-align', 'left')
                    :css('padding', '5px 10px')
                    :css('background-color', 'rgba(0,0,0,0.7)')
                    :css('border-radius', '4px')
                    :css('font-size', '12px')
                    :css('display', 'none')
                    :attr('data-effect-index', i)
                    :wikitext('→ ' .. eventInfo.effect[i])
                 container:node(effectDiv)
             end
             end
            effectDiv:wikitext(effectText)
         end
         end
     end
     end
      
      
     return container
     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
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