Module:Scale

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

local utilsArg = require("Module:UtilsArg") local utilsError = require("Module:UtilsError") local utilsFile = require("Module:UtilsFile") local utilsMarkup = require('Module:UtilsMarkup/Wikitable') local utilsTable = require('Module:UtilsTable')

local NOTE_SIZE = "12px";

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

function p.main(args) local err = utilsArg.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.map(h.symbolToNote(args.system), args.notes) 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 utilsMarkup.tabbedWikitable(tableData) end return p