Module:Scale

local p = {} local h = {} local data = mw.loadData('Module:Scale/Data')

local getArgs = require('Module:Arguments').getArgs local utilsError = require("Module:UtilsError") local utilsFile = require("Module:UtilsFile") local utilsTable = require('Module:UtilsTable') local validate = require("Module:ArgsUtil/Validate") local wikitable = require('Module:Wikitable')

local NOTE_SIZE = "12px";

function p.Main(frame) local args = getArgs(frame) return p.main({   	system = args[1],    	notes = mw.text.split(args[2], '')    }) end

function p.main(args) local err = validate(args, {		system = {			required = true,			values = utilsTable.keys(data.notes),		},		notes = {			required = true,			values = function(args) return utilsTable.keys(data.notes[args.system] or {}) end		}	}) if err then utilsError.logWarnings(err) return utilsError.printErrorCategories(utilsError.INVALID_TEMPLATE_ARGUMENTS) end local notes = utilsTable.mapSafe(args.notes, h.symbolToNote(args.system)) return h.makeScale(notes) end

function h.symbolToNote(system) local notes = data.notes[system] local positions = data.relativePositions[#utilsTable.keys(notes)] return function(symbol) local note = notes[symbol] local thumbnail = utilsFile.link({	       file= note.file,	        link= '',	        size= NOTE_SIZE,	    }) local notePosition = positions[note.position] local positionedNote = mw.html.create('span') :css({               position= 'relative',                top= notePosition .. 'px',            }) :wikitext(thumbnail, ' ') return positionedNote end end

function h.makeScale(notes) local div = mw.html.create('div') :css({           display= 'inline-block',            ['line-height']= '28px',        }) for _, note in ipairs(notes) do       div:node(note) end return tostring(div) end

function p.Documentation local tableData = { headerRows = , tabs = {} }	for system, notes in pairs(data.notes) do		local rows = {} for noteSymbol, noteData in pairs(notes) do			local result = p.main({				system = system,				notes = {noteSymbol},			}) local imageLink = ("File:%s"):format(noteData.file) table.insert(rows, {cells = {noteSymbol, result, imageLink}}) end table.insert(tableData.tabs, {			tabName = system,			rows = rows		}) end return wikitable.createTabbedTable(tableData) end return p