Module:TarsicanSaros

From MicrasWiki
Revision as of 23:24, 31 May 2025 by NewZimiaGov (talk | contribs)
Jump to navigationJump to search

Documentation for this module may be created at Module:TarsicanSaros/doc

local p = {}
local calendar = require("Module:BassaridianCalendar")  -- Ensure this matches your calendar module name

-- Constants
local synodicPeriod = 24.8
local micrasYearLength = 183

-- Zodiac definitions
local zodiacSigns = {
    { name = "Atosien",    start = 1,   stop = 12 },
    { name = "Eosena",     start = 13,  stop = 24 },
    { name = "Micrasha",   start = 25,  stop = 36 },
    { name = "Pyreska",    start = 37,  stop = 48 },
    { name = "Indomin",    start = 49,  stop = 61 },
    { name = "Chrysen",    start = 62,  stop = 73 },
    { name = "Thalassian", start = 74,  stop = 85 },
    { name = "Nephelia",   start = 86,  stop = 97 },
    { name = "Glinaeus",   start = 98,  stop = 109 },
    { name = "Noctien",    start = 110, stop = 122 },
    { name = "Opsithia",   start = 123, stop = 133 },
    { name = "Stygian",    start = 134, stop = 145 },
    { name = "Faunian",    start = 146, stop = 157 },
    { name = "Silenian",   start = 158, stop = 169 },
    { name = "Catosien",   start = 170, stop = 183 }
}

-- Determine season/month
local function getMonth(day)
    if day <= 61 then return "Atosiel"
    elseif day <= 122 then return "Thalassiel"
    else return "Opsitheiel"
    end
end

-- Determine zodiac sign
local function getZodiac(day)
    for _, z in ipairs(zodiacSigns) do
        if day >= z.start and day <= z.stop then
            return z.name
        end
    end
    return "Unknown"
end

-- Generate random eclipse subtype
local function getEclipseSubtype(eclipseType)
    math.randomseed(os.time())
    if eclipseType == "Solar" then
        local options = { "Total Solar", "Annular Solar", "Partial Solar" }
        return options[math.random(#options)]
    else
        local options = { "Total Lunar", "Penumbral Lunar", "Partial Lunar" }
        return options[math.random(#options)]
    end
end

-- Format event entry
local function formatEvent(event)
    if event.link and event.name then
        return string.format("[%s %s]<br><small>''%s''</small>", event.link, event.name, event.city or "")
    elseif event.name then
        return string.format("'''%s'''", event.name)
    else
        return "—"
    end
end

-- MAIN TABLE FUNCTION
function p.sarosTable(frame)
    local output = {}

    -- Get year and events from calendar module
    local dateString = calendar.getCurrentDate()
    local psscYear = tonumber(string.match(dateString, "(%d+)%s+PSSC"))
    local events = calendar.events or {}

    table.insert(output, string.format("== Tarsican Eclipse Schedule – Year %d PSSC ==\n", psscYear))
    table.insert(output, '{| class="wikitable sortable" style="width:100%; text-align:center;"')
    table.insert(output, '|-\n! # !! Day !! Month !! Zodiac !! Eclipse Type !! Nearby Ritual or Holiday')

    local eclipseDay = 18
    local isSolar = true

    for i = 1, 10 do
        if eclipseDay > micrasYearLength then break end

        local eclipseType = isSolar and "Solar" or "Lunar"
        local subtype = getEclipseSubtype(eclipseType)
        local month = getMonth(eclipseDay)
        local zodiac = getZodiac(eclipseDay)

        -- Look ±1 day for a nearby holiday
        local holidayOutput = "—"
        for offset = -1, 1 do
            local checkDay = eclipseDay + offset
            if checkDay >= 1 and checkDay <= micrasYearLength then
                local checkMonth = getMonth(checkDay)
                local dayInMonth = checkDay
                if checkMonth == "Thalassiel" then
                    dayInMonth = checkDay - 61
                elseif checkMonth == "Opsitheiel" then
                    dayInMonth = checkDay - 122
                end
                local key = checkMonth .. "," .. dayInMonth
                if events[key] then
                    holidayOutput = formatEvent(events[key])
                    break
                end
            end
        end

        table.insert(output, string.format(
            '|-\n| %d || %d || %s || %s || %s || %s',
            i, eclipseDay, month, zodiac, subtype, holidayOutput
        ))

        eclipseDay = math.floor(eclipseDay + synodicPeriod + ((-1)^i) * 2.3)
        isSolar = not isSolar
    end

    table.insert(output, '|}')
    return table.concat(output, "\n")
end

return p