模块

词典:修订间差异

来自卡厄思梦境WIKI

律Rhyme留言 | 贡献
创建页面,内容为“local p = {} local data = require('模块:词典/data') function p.main(frame) local args = frame:getParent().args local category = args[1] or "" local term = args[2] or "" local color = args["颜色"] or "black" local description = "" if category == "卡牌机制" then description = data.cardMechanics[term] or "未找到说明" end -- 构建HTML local html = string.format([[ <span class="dictionary-te…”
 
律Rhyme留言 | 贡献
无编辑摘要
 
(未显示同一用户的15个中间版本)
第1行: 第1行:
local p = {}
local p = {}
local data = require('模块:词典/data')


function p.main(frame)
function p.main(frame)
     local args = frame:getParent().args
     local args = frame:getParent().args
     local category = args[1] or ""
     local term = args[1] or ""
     local term = args[2] or ""
     local category = args[2] or "" -- 可选参数
    local color = args["颜色"] or "black"
      
      
     local description = ""
    -- 加载词典数据
     local data = require('Module:词典/data')
    local dictionary = data.dictionary
      
      
     if category == "卡牌机制" then
    -- 颜色映射(仅用于边框)
         description = data.cardMechanics[term] or "未找到说明"
    local colorMap = {
        ["白"] = "#ffffff",
        ["蓝"] = "#0099ff",
        ["红"] = "#ff3333",
        ["橙"] = "#f2ba02"
    }
   
    -- 查找词条
    local entries = dictionary[term]
    if not entries then
        return '<span style="color: red;">未找到词条: ' .. term .. '</span>'
    end
   
    -- 查找匹配的条目
    local entry = nil
     if category == "" then
         -- 如果没有指定类型,使用第一个条目
        entry = entries[1]
    else
        -- 如果指定了类型,查找匹配的类型
        for _, e in ipairs(entries) do
            if e["类型"] == category then
                entry = e
                break
            end
        end
    end
   
    if not entry then
        return '<span style="color: red;">未找到类型: ' .. category .. ' - ' .. term .. '</span>'
    end
   
    -- 获取边框颜色
    local lineColor = colorMap[entry["颜色"]] or colorMap["白"]
   
    -- 构建工具提示内容
    local tooltipContent = ""
   
    -- 添加图标(如果有)
    if entry["icon"] and entry["icon"] ~= "" then
        tooltipContent = tooltipContent .. '[[File:' .. entry["icon"] .. '|25px|link=]] '
     end
     end
      
      
     -- 构建HTML
    tooltipContent = tooltipContent .. term .. '<br>' .. entry["描述"]
     local html = string.format([[
   
<span class="dictionary-term" style="position: relative; display: inline-block;">
     -- 生成唯一ID
    <span style="color: %s; text-decoration: underline; cursor: help;">%s</span>
     local tooltipId = 'tooltip-' .. mw.uri.encode(term .. (category or "")):gsub('[%%%.%-%s]', '')
     <span class="dictionary-tooltip">
   
         <span class="dictionary-tooltip-bar"></span>
    -- 将tooltip内容存储在data属性中
         <span class="dictionary-tooltip-content">
    local tooltipHtml = '<div style="width: 250px; height: 2px; background-color: ' .. lineColor .. ';"></div>' ..
             <span class="dictionary-tooltip-title">%s</span><br/>
                        '<div style="width: 250px; background-color: #343434; color: white; padding: 5px; box-shadow: 0 2px 8px rgba(0,0,0,0.3);">' ..
             %s
                        tooltipContent .. '</div>'
         </span>
   
    </span>
    -- 生成HTML
</span>]], color, term, term, description)
     local html = mw.html.create('span')
        :addClass('dictionary-term')
         :attr('data-tooltip-content', tooltipHtml)
         :attr('data-tooltip-id', tooltipId)
        :css({
            ['text-decoration'] = 'underline',
             ['cursor'] = 'help',
             ['display'] = 'inline-block'
         })
        :wikitext(term)
      
      
     return html
     return tostring(html)
end
end


return p
return p

2025年10月5日 (日) 01:06的最新版本

此模块的文档可以在模块:词典/doc创建

local p = {}

function p.main(frame)
    local args = frame:getParent().args
    local term = args[1] or ""
    local category = args[2] or ""  -- 可选参数
    
    -- 加载词典数据
    local data = require('Module:词典/data')
    local dictionary = data.dictionary
    
    -- 颜色映射(仅用于边框)
    local colorMap = {
        ["白"] = "#ffffff",
        ["蓝"] = "#0099ff",
        ["红"] = "#ff3333",
        ["橙"] = "#f2ba02"
    }
    
    -- 查找词条
    local entries = dictionary[term]
    if not entries then
        return '<span style="color: red;">未找到词条: ' .. term .. '</span>'
    end
    
    -- 查找匹配的条目
    local entry = nil
    if category == "" then
        -- 如果没有指定类型,使用第一个条目
        entry = entries[1]
    else
        -- 如果指定了类型,查找匹配的类型
        for _, e in ipairs(entries) do
            if e["类型"] == category then
                entry = e
                break
            end
        end
    end
    
    if not entry then
        return '<span style="color: red;">未找到类型: ' .. category .. ' - ' .. term .. '</span>'
    end
    
    -- 获取边框颜色
    local lineColor = colorMap[entry["颜色"]] or colorMap["白"]
    
    -- 构建工具提示内容
    local tooltipContent = ""
    
    -- 添加图标(如果有)
    if entry["icon"] and entry["icon"] ~= "" then
        tooltipContent = tooltipContent .. '[[File:' .. entry["icon"] .. '|25px|link=]] '
    end
    
    tooltipContent = tooltipContent .. term .. '<br>' .. entry["描述"]
    
    -- 生成唯一ID
    local tooltipId = 'tooltip-' .. mw.uri.encode(term .. (category or "")):gsub('[%%%.%-%s]', '')
    
    -- 将tooltip内容存储在data属性中
    local tooltipHtml = '<div style="width: 250px; height: 2px; background-color: ' .. lineColor .. ';"></div>' ..
                        '<div style="width: 250px; background-color: #343434; color: white; padding: 5px; box-shadow: 0 2px 8px rgba(0,0,0,0.3);">' ..
                        tooltipContent .. '</div>'
    
    -- 生成HTML
    local html = mw.html.create('span')
        :addClass('dictionary-term')
        :attr('data-tooltip-content', tooltipHtml)
        :attr('data-tooltip-id', tooltipId)
        :css({
            ['text-decoration'] = 'underline',
            ['cursor'] = 'help',
            ['display'] = 'inline-block'
        })
        :wikitext(term)
    
    return tostring(html)
end

return p