Module:MOS modes: Difference between revisions

Ganaram inukshuk (talk | contribs)
Changed code to how I currently write template modules (underscore-prefixed primary function called by no-underscore-prefix wrapper function)
Ganaram inukshuk (talk | contribs)
Added rotational order to table; made table sortable by UDP, step pattern, and rotational order
Line 71: Line 71:
local mos_modes = p.modes_by_brightness(input_mos)
local mos_modes = p.modes_by_brightness(input_mos)
local periods = utils._gcd(input_mos.nL, input_mos.ns) -- Needed for UDP
local periods = utils._gcd(input_mos.nL, input_mos.ns) -- Needed for UDP
local mossteps_per_period = (input_mos.nL + input_mos.ns) / periods


-- This is for entering multiple columns of info, if a single column of mode names isn't enough
-- This is for entering multiple columns of info, if a single column of mode names isn't enough
Line 85: Line 86:
add_columns = add_columns and #mos_modes * #headers == #entries
add_columns = add_columns and #mos_modes * #headers == #entries
end
end
-- Get the number of mossteps in the bright gen
-- Used for calculating rotational order
local bright_gen = mos.bright_gen(input_mos)
local mossteps_per_bright_gen = bright_gen['L'] + bright_gen['s']
-- Make a table with a column for the mode (as a string of L's and s's) and UDP
-- Make a table with a column for the mode (as a string of L's and s's) and UDP
local result = '{| class="wikitable"\n'
local result = '{| class="wikitable sortable"\n'
result = result .. "|+ " .. "Modes of " .. mos.as_string(input_mos) .. "\n" -- To create the scale signature with〈〉instead of <>
result = result .. "|+ " .. "Modes of " .. mos.as_string(input_mos) .. "\n" -- To create the scale signature with〈〉instead of <>
result = result .. "|-\n"
result = result .. "|-\n"
result = result .. "! [[UDP]]\n"
result = result .. "! [[UDP]]\n"
result = result .. "! Rotational order\n"
result = result .. "! Step pattern\n"
result = result .. "! Step pattern\n"
-- If there are mode names (if the mode names array is not nil), then add a column for mode names
-- If there are mode names (if the mode names array is not nil), then add a column for mode names
if #mode_names == #mos_modes then
if #mode_names == #mos_modes then
result = result .. "! Mode names\n"
result = result .. '! class="unsortable" | Mode names\n'
end
end
Line 102: Line 109:
if add_columns then
if add_columns then
for i = 1, #headers do
for i = 1, #headers do
result = result .. "! " .. headers[i] .. "\n"
result = result .. '! class="unsortable" |' .. headers[i] .. "\n"
end
end
end
end
Line 124: Line 131:
udp_as_text = gens_up .. '&#124;' .. gens_down .. "(" .. periods .. ")"
udp_as_text = gens_up .. '&#124;' .. gens_down .. "(" .. periods .. ")"
end
end
result = result .. "|" .. udp_as_text .. "\n"
result = result .. "|" .. udp_as_text .. "\n"
-- Add the mode's rotational order
local bright_gens_up = mossteps_per_bright_gen * (i-1)
local rotational_order = bright_gens_up % mossteps_per_period + 1
result = result .. "|" .. rotational_order .. "\n"


-- Add the mode's step pattern
-- Add the mode's step pattern