Module:Scale
Jump to navigation
Jump to search
This module uses the data at Module:Scale/Data to map symbols to music note icons, positioned relative to each other as they would be in-game.
local p = {}
local h = {}
local utilsArg = require("Module:UtilsArg")
local utilsMarkup = require("Module:UtilsMarkup")
local utilsLayout = require("Module:UtilsLayout")
local utilsString = require("Module:UtilsString")
local utilsTable = require("Module:UtilsTable")
local data = mw.loadData("Module:Scale/Data")
local NOTE_SIZE = "16px";
function p.Main(frame)
local args, err = utilsArg.parse(frame:getParent().args, p.Templates.Scale)
if err then
return utilsMarkup.categories(err.categories)
end
return p.printNotes(args.system, args.notes)
end
function p.printNotes(system, notes)
local notes = utilsTable.map(notes, h.symbolToNote(system))
local scale = h.makeScale(notes)
return scale
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 = utilsMarkup.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.Data()
local tableData = {
headerRows = {{
cells = {'Note', 'Result', 'Image'}
}},
tabs = {}
}
for system, notes in pairs(data.notes) do
local rows = {}
for noteSymbol, noteData in pairs(notes) do
local result = p.printNotes(system, {noteSymbol})
local imageLink = ("[[:File:%s]]"):format(noteData.file)
table.insert(rows, {cells = {noteSymbol, result, imageLink}})
end
table.insert(tableData.tabs, {
label = system,
rows = rows
})
end
return utilsLayout.tabbedTable(tableData)
end
p.Templates = {
Scale = {
purpose = "This template is used to display the [[Ocarina]] or [[Spirit Flute]] notes. They are properly positioned in relation to each other.",
format = "inline",
params = {
[1] = {
name = "system",
type = "string",
required = true,
enum = utilsTable.keys(data.notes),
desc = "See allowed values.",
},
[2] = {
name = "notes",
type = "string",
required = true,
enumDependsOn = "system",
enum = function(system)
return utilsTable.keys(data.notes[system] or {})
end,
desc = "A string of symbols representing notes.",
split = "",
}
},
examples = {
{"N64", "<^><^>"},
{"DS", "OYOB"},
{"3DS", "YYLLRR"},
{"foo"},
{"3DS", "foo"},
}
}
}
return p