オブジェクトショーコミュニティ Wiki
Advertisement
オブジェクトショーコミュニティ Wiki

このモジュールについての説明文ページを モジュール:DiaM/doc に作成できます

local p = {}
local chrome = require("Dev:Colors")

local colData = mw.loadData( 'Module:Code/col' )
local ucData = mw.loadData( 'Module:Code/uc' )
local jpData = mw.loadData( 'Module:Code/jp' )
local enData = require( 'Module:Code/en' )
local emData = mw.loadData('Module:Code/emote') -- ユニークカラー時の名前制御用

local args = {} -- Arguments passed to template
local dia -- Actual dia

local twow = {}

------------------------------------------------
-- ARGUMENTS PREPROCESSOR
-- * データロードしながら値を定めます
------------------------------------------------

--- Preprocessor for the arguments.
-- Will fill up the args table with the parameters from the frame grouped by their type.
--
-- @param frame The frame passed to the Module.
local function preProcessArgs(frame)
    local tmp = {}

    if frame == mw.getCurrentFrame() then
        tmp = frame:getParent().args
    else
        tmp = frame
    end

    -- Loop over all the args
    for k,v in pairs(tmp) do
        -- Skip empty args, which are useless
        if v ~= '' then
            local cat,num = tostring(k):match('^(%a+)([1-9]%d*)$')

            args[k] = v -- Simple copy
        end
    end

    local id = args['id']
    twow['icnm'] = id
    twow['text'] = args['text']
    twow['name'] = emData[id] or id

    twow['col'] = ucData[id] or colData[twow.name] or {255, 255, 255}
end

------------------------------------------------
-- processColor/色を定めます
------------------------------------------------
local function prgb(fa)
    return chrome.fromRgb(fa[1] or 255, fa[2] or 255, fa[3] or 255, 0.58)
end
local function processColor()
    local diastyle =  'background-color:'..prgb(twow.col):hex()..';'

    if args.bodyclass then dia:addClass(args.bodyclass) end
    dia:cssText(diastyle)
    if args.bodystyle then dia:cssText( args.bodystyle ) end
end
local function processColor2()
    local newcol = prgb(twow.col):rotate(180);

    return 'color:'..newcol:lighten(-75):alpha(100):hex()..'; background-color:'..prgb(twow.col):hex()..';'
end
------------------------------------------------
-- processName/名前欄です
------------------------------------------------
--- processIcon/アイコンを置きます
local function processIcon(row)
    local iconcell = mw.html.create('td'):attr('rowspan',2):addClass('dia-image')
    local ext = '.png'

    local image
    if args['image'] ~= nil then
        image = args['image']
    else
        image = 'File:Dia'..(twow.icnm or 'ZZUnknown')..ext
    end

    local iclink = ''
    if twow.icnm ~= 'ZZUnknown' then iclink = twow.name end
        local width = args.iconwidth or '80px'
    if iclink ~= nil then
        iconcell:wikitext('['..'['.. image  ..'|'.. width ..'|link='.. iclink ..']'..']')
    else
        iconcell:wikitext('['..'['.. image  ..'|'.. width ..'|link=]'..']')
    end

    if args.iconclass then iconcell:addClass( args.iconclass ) end
    if args.iconstyle then iconcell:cssText( args.iconstyle ) end

    row:node(iconcell)
end
--- 名前欄はアイコンと同じ段です
local function processName()
    local namerow = mw.html.create('tr')
    local namecell = mw.html.create('td'):addClass('dia-name'):attr('valign','top')
    
    local jname = jpData[twow.name] or ''
    twow.name = enData.load(twow.name,2) or twow.name
        processIcon(namerow)
    if args['name'] ~= nil then
        namecell:wikitext(args.name)
    elseif jname ~= nil then
        namecell:wikitext(jname..' ('..(twow.name or '???')..')')
    else
        namecell:wikitext(twow.name or '???')
    end

    if args.nameclass then namecell:addClass( args.nameclass ) end
    namecell:cssText(namestyle2)
    if args.namestyle then namecell:cssText( args.namestyle ) end
    namerow:node(namecell)
    dia:node(namerow)
end
------------------------------------------------
-- processText/テキストを入力します
------------------------------------------------
local function processText()
    local textrow = mw.html.create('tr'):addClass('dia-text')
	local textcell = mw.html.create('td'):attr('valign','top')

    if twow.name == nil then
        textcell:wikitext('※nameの値が不正です')
    end
    if twow.icnm == nil then
        textcell:wikitext('※idの値が不正です')
    end
    if twow.col == nil then
        textcell:wikitext('※colの値が不正です')
    end
    textcell:wikitext(twow.text)

    if args.textclass then textrow:addClass( args.textclass ) end
    if args.textstyle then textcell:cssText( args.textstyle ) end
    textrow:node(textcell)
    dia:node(textrow)
end
------------------------------------------------
-- MAIN FUNCTIONS
------------------------------------------------

--- Processes the arguments to create the dialog.
--
-- @return A string with HTML that is the dialog.
local function _dia()
    -- Create the root HTML element
    local trim = function(s)
        return s and mw.ustring.gsub(s, "^%s*(.-)%s*$", "%1") or ''
    end
    local border = args.border or trim(args[1])  or ''

        dia = mw.html.create('table'):addClass('dia')

    -- Process...
        processColor()
        processName()
        processText()

    return tostring(dia)
end

--- Main module entry point.
-- To be called with {{#invoke:diaM|main}} or directly from another module.
--
-- @param frame The frame passed to the module via the #invoke. If called from another
--              module directly, this should be a table with the parameter definition.
function p.main(frame)
    -- データロードも忘れずに
    preProcessArgs(frame)

    return _dia()
end

return p
-- [[Category:OCRAULのモジュール]]
Advertisement