Module:Color

This module depends on the following other modules:
Module:Arguments
Documentation Module:Color/doc

This module is similar to {{Color}} but for modules.

Makes text bold and colored, using game text colors or a custom color.

Usage

The first parameter sets the color according to the list below; the second parameter sets the text; the parameter backing applies a background effect if defined

color('red','text you want red') gives text you want red

color('green','text you want green',{backing=1}) gives text you want green

Text can be left unbolded by setting the parameter bold to normal; so color('red','unbolded text',{bold='normal'}) gives unbolded text

Numerical font weights can also be used as a CSS font-weight value.

List of colors

Victoria 3 defines text colors using percentage RGB (as 0-1); the following colors are pre-defined in this template and can be found in Victoria 3\game\gui/textformatting.gui

Color key rgb (/ alpha)
black black 0% 0% 0% / 60%
blue blue 41% 67% 74%
gold gold 100% 67.4% 45.4%
green green 39% 67% 33%
green wiki_green 0% 128% 0%
light_green light_green 25% 57% 45%
grey grey 60% 57% 55%
red red 88% 34% 34%
red wiki_red 255% 0% 0%
white white 94% 95% 88%
darker_white darker_white 76% 74% 72%
yellow yellow 100% 97% 66%

Custom colors can be used by defining any valid CSS color value. For example, {{color|#cc11cc|hexcode}} gives hexcode. Setting the parameter html or css to anything allows the use of CSS named colors that overlap the keys above.


local getArgs = require('Module:Arguments').getArgs

local p = {};

function p.main(frame)
    local args = getArgs(frame)
    return p.color(args[1], args[2], args)
end

-- First argument for color, second for text, third as table for named arguments
function p.color(color, text, options)
    options = options or {}
    local fWeight = options.bold or 'bold'
    local backing = options.backing and { background = '#E0E0E0', padding = '1px 3px', ['border-radius'] = '2px' } or {}

    local gameColors = {
        black        = '#00000099', --rgb(0% 0% 0% / 60%)
        blue         = '#69abbd', --rgb(41% 67% 74%)
        gold         = '#ffac74', --rgb(100% 67.4% 45.4%)
        wiki_green   = 'green',
        green        = '#63ab54', --rgb(39% 67% 33%)
        light_green  = '#409173', --rgb(25% 57% 45%)
        grey         = '#99918c', --rgb(60% 57% 55%)
        wiki_red     = 'red',
        red          = '#e05757', --rgb(88% 34% 34%)
        white        = '#f0f2e0', --rgb(94% 95% 88%)
        darker_white = '#c2bdb8', --rgb(76% 74% 72%)
        yellow       = '#fff7a8', --rgb(100% 97% 66%)
        -- [color] = 'class="effect-custom" style="color: '..color..';',
    }
    if not (options.html or options.css) then
        for k, v in pairs(gameColors) do
            if color == k then
                color = v
                break
            end
        end
    end

    local span = mw.html.create('span')
        :css('color', color)
        :css('font-weight', fWeight)
        :css(backing)
        :wikitext(text)
    return tostring(span)
end

return p