Module:Setlist/Songs: Difference between revisions

Jump to navigation Jump to search
no edit summary
mNo edit summary
Tag: Reverted
No edit summary
Tag: Reverted
Line 1: Line 1:
local p = {}
-- Функция для определения актуального альбома по названию страницы
function p.getCurrentAlbum()
    local title = mw.title.getCurrentTitle().text or ""
    local year = mw.ustring.match(title, "%.(%d%d%d%d)$")
    year = tonumber(year)
    if year and year >= 2008 and year <= 2012 then
        return "Regional At Best"
    elseif year and year >= 2013 then
        return "Vessel"
    end
    return nil
end
local songs = {
local songs = {
     ["Implicit Demand For Proof"] = {"Twenty One Pilots"},
     ["Implicit Demand For Proof"] = {"Twenty One Pilots"},
Line 112: Line 127:
}
}


-- Функция для получения таблицы песен в зависимости от даты
-- Пример функции: возвращает песни, относящиеся к альбому для текущей страницы
local function getSongsForDate(date)
function p.getSongsForCurrentAlbum(frame)
    -- Дата выхода Vessel: 8 января 2013 года
     local album = p.getCurrentAlbum()
     local vesselReleaseDate = os.time{year=2013, month=1, day=8}
    if not album then
     local modifiedSongs = {}
        return "Альбом не определён"
 
    end
    -- Проходим по всем песням в исходной таблице
     local result = {}
     for song, albums in pairs(songs) do
     for song, albums in pairs(songs) do
         if #albums == 1 then
         for _, a in ipairs(albums) do
             -- Если песня в одном альбоме, оставляем как есть
             if a == album then
            modifiedSongs[song] = albums
                table.insert(result, song)
        elseif #albums == 2 and albums[1] == "Regional At Best" and albums[2] == "Vessel" then
                 break
            -- Если песня в обоих альбомах, выбираем альбом в зависимости от даты
            if date < vesselReleaseDate then
                modifiedSongs[song] = {"Regional At Best"}
            else
                 modifiedSongs[song] = {"Vessel"}
             end
             end
        else
            -- Для всех остальных случаев (хотя в текущих данных таких нет)
            modifiedSongs[song] = albums
         end
         end
     end
     end
 
     return table.concat(result, "<br>")
     return modifiedSongs
end
end


-- Возвращаем модуль с таблицами и функцией
return p
return {
    songs = songs,
    albumColors = albumColors,
    albumLinks = albumLinks,
    getSongsForDate = getSongsForDate
}

Navigation menu