Module:Soundtrack

-- Functions for Template:Infobox music

local p = {}; -- Soundtrack Package

-- --[==[ Modules ]==]-- local getArgs = require("Dev:Arguments").getArgs; local ostList = require("Module:Sountrack/OST List");

--[==[ Global Functions ]==]-- -- Creates a MediaWiki link function formatLink(name, link) return link == name or (not link) and "" .. name .. "" or "' .. name .. ""; end

--[==[ Module Functions ]==]-- -- Gets track name from raw article name -- e.g. "Alphys (track)" -> "Alphys" function p.getFrmTrack(articleName) return articleName:gsub("%s*%(.+%)$", ""); end

-- Gets track's index in track list from frame function p.getListing(frame) local rTrack = unpack(getArgs(frame)); -- Raw track name local track = p.getFrmTrack(rTrack);  -- Frm track name local trackNum; -- to hold the track number -- Perform a linear search for i,name in next, ostList do       if name == track then -- Track found trackNum = i;           break; end end return trackNum; end

-- wrapper function p.incr_track_wrapper = function(incr) return function(frame) local index = p.getListing(frame) + incr; local rTrack = ostList[index] or ""; -- raw track name local track = p.getFrmTrack(rTrack); -- frm track name return track ~= "" and formatLink(track, rTrack) or track; end end

p.next_track = incr_track_wrapper( 1); p.prev_track = incr_track_wrapper(-1);

return p;