local me =
local bc = require('Module:BaseConvert')local Tuple = require('Module:Sandbox/isaacl/ColourSpace/Tuple')local Formats = require('Module:Sandbox/isaacl/ColourSpace/Formats')
local infoFor = -- data for formats
function me.buildColourTuple(args, parameters) local result = Tuple.clone(args) result.format = parameters.format result.colourSpace = parameters.colourSpace result.defaultConversion = parameters.defaultConversion result.fValid = true result.display = function(self, separator) return parameters.displayFunc(self, separator) end return resultend -- function buildColourTuple
local options =
local formatTypeFor =
local checkInputFormatFor =
me.create =
local createFromParsedInput =
me.mapTo =
local colourSpaceFor =
local commonFormatForColourSpace =
local function createInvalidColourValue(errorMsg) local invalidColourValue = return invalidColourValueend
me.configureFormatInfo = function(infoFor) for format, info in pairs(infoFor) do -- If basic information for the format has not been defined -- already, configure it if (me.create[format]
nil) then return createInvalidColourValue('badInputValues') end
return createFromParsedInput[format](parsedArgs) end -- function me.create[format]
formatTypeFor[format] = info.formatType colourSpaceFor[format] = info.colourSpace
if (info.isInputFormat ~= nil) then checkInputFormatFor[format] = info.isInputFormat end end -- if me.create[format]
-- Define mapping functions from other formats to the -- current format being configured. for startFormat, mapper in pairs(info.mapParametersFrom) do if (me.mapTo[format]
if (mappedParameters
me.configureFormatInfo(infoFor)
for idx=1, #Formats do local formatInfo = require('Module:Sandbox/isaacl/ColourSpace/Formats/' .. Formats[idx]) me.configureFormatInfo(formatInfo.infoFor)end
function me.loadFormatInfo(format) -- try to load the required module for the format local formatInfo = require('Module:Sandbox/isaacl/ColourSpace/Formats/' .. format) if (formatInfo ~= nil) then me.configureFormatInfo(formatInfo.infoFor) return format end return nilend
function me.determineInputFormat(frame) local args = frame.args local fromFormat = frame.args["from"] if (fromFormat ~= nil) then if (me.create[fromFormat] ~= nil) then return fromFormat else -- try to load the required module for the format return me.loadFormatInfo(fromFormat) end end
for format, isInputFormat in pairs(checkInputFormatFor) do if (isInputFormat(args)) then return format end end
-- unable to deduce format return nilend -- function determineInputFormat
local function determineOutputFormat(frame, startValue) local toFormat = frame.args["to"] if (toFormat ~= nil) then if (me.create[toFormat] ~= nil) then return toFormat else -- try to load the required module for the format return me.loadFormatInfo(toFormat) end end -- use default conversion return startValue.defaultConversionend -- function determineOutputFormat
local function convertBetweenFormats(colourValue, listOfFormats) local convertedValue = colourValue for idx, nextFormat in ipairs(listOfFormats) do if (convertedValue.format ~= nextFormat) then if (me.mapTo[nextFormat].from[convertedValue.format]
function me.convertColour(frame) if (frame.args[1]
if (frame.args.separator ~= nil) then options.separator = frame.args.separator end
local startFormat = me.determineInputFormat(frame) if (startFormat
local startValue = me.create[startFormat](frame.args)
if (not startValue.fValid) then return startValue:display end
local endFormat = determineOutputFormat(frame, startValue)
if (endFormat
if (startFormat
local result =
-- If a direct conversion exists, use it if (me.mapTo[endFormat].from[startFormat] ~= nil) then result = me.mapTo[endFormat].from[startFormat](startValue) return result:display(options.separator) end
local listOfFormats =
-- If the start and end formats are in the same colour space: -- first, convert to the common format for the starting colour space and format type -- second, convert to the common format for the ending colour space and format type -- third, convert to the ending format type
if (colourSpaceFor[startFormat]
return result:display(options.separator)end -- function convertColour
function me.convertColour_fromTemplate(frame) return me.convertColour(frame:getParent)end -- function templateConvertColour
return me