-- Bigint library
bigint = require "libs.bigint.bigint"
number_names = require "libs.bigint.named-powers-of-ten"

-- Fonts
FONT_tromi = love.graphics.newFont('res/fonts/monofonto rg.otf', 28)
FONT_big = love.graphics.newFont('res/fonts/monofonto rg.otf', 56)

-- Graphics
ShowLoadingText('backgrounds')
local gc_newImage, gc_newVideo = love.graphics.newImage, love.graphics.newVideo
BACKGROUNDS = {
    [0] = gc_newVideo("res/backgrounds/green_waterfall.ogv", {audio=false}),
    gc_newVideo("res/backgrounds/water.ogv", {audio=false}),
    gc_newVideo("res/backgrounds/green_streams.ogv", {audio=false}),
    gc_newVideo("res/backgrounds/streams.ogv", {audio=false}),
    gc_newVideo("res/backgrounds/red_forest_waterfall.ogv", {audio=false}),
    gc_newVideo("res/backgrounds/flowers_rain.ogv", {audio=false}),
    gc_newVideo("res/backgrounds/moonlight_tree.ogv", {audio=false}),
    gc_newVideo("res/backgrounds/lisa_frank.ogv", {audio=false}),
    gc_newVideo("res/backgrounds/snowy_trees.ogv", {audio=false}),
    gc_newVideo("res/backgrounds/snowy_cabin.ogv", {audio=false}),
}

ShowLoadingText('blocks')
BLOCKS = {
    ["2tie"] = {
        R   = gc_newImage("res/img/r.png"),
        O   = gc_newImage("res/img/o.png"),
        Y   = gc_newImage("res/img/y.png"),
        G   = gc_newImage("res/img/g.png"),
        C   = gc_newImage("res/img/b.png"),
        B   = gc_newImage("res/img/i.png"),
        M   = gc_newImage("res/img/v.png"),
        F   = gc_newImage("res/img/bl.png"),
        A   = gc_newImage("res/img/bl.png"),
        X   = gc_newImage("res/img/t.png"),
        W   = gc_newImage("res/img/w.png"),
        R_d = gc_newImage("res/img/r_d.png"),
        O_d = gc_newImage("res/img/o_d.png"),
        Y_d = gc_newImage("res/img/y_d.png"),
        G_d = gc_newImage("res/img/g_d.png"),
        C_d = gc_newImage("res/img/b_d.png"),
        B_d = gc_newImage("res/img/i_d.png"),
        M_d = gc_newImage("res/img/v_d.png"),
    }
}

COLOUR_SCHEMES = {
    Arika = {
        I = "R",
        L = "O",
        J = "B",
        S = "M",
        Z = "G",
        O = "Y",
        T = "C",
    }
}

-- BGMs and SFXs
ShowLoadingText('BGMs & SFXs')
local audio_newSource = love.audio.newSource
SOUNDS = {
    bottom         = audio_newSource("res/se/bottom.wav", "static"),
    lock           = audio_newSource("res/se/lock.wav", "static"),
    erase          = audio_newSource("res/se/erase.wav", "static"),
    fall           = audio_newSource("res/se/fall.wav", "static"),
    ready          = audio_newSource("res/se/ready.wav", "static"),
    promote        = audio_newSource("res/se/promote.wav", "static"),
    demote         = audio_newSource("res/se/demote.wav", "static"),
    autopromote    = audio_newSource("res/se/autopromote.wav", "static"),
    bgm_firsthalf  = audio_newSource("res/bgm/firsthalf.flac", "static"),
    bgm_secondhalf = audio_newSource("res/bgm/secondhalf.flac", "static"),
    bgm_title      = audio_newSource("res/bgm/title.flac", "static")
}

function PlaySE(sound, subsound)
    if sound ~= nil then
        if subsound ~= nil then
            SOUNDS[sound][subsound]:setVolume(0.4)
            if SOUNDS[sound][subsound]:isPlaying() then
                SOUNDS[sound][subsound]:stop()
            end
            SOUNDS[sound][subsound]:play()
        else
            SOUNDS[sound]:setVolume(0.4)
            if SOUNDS[sound]:isPlaying() then
                SOUNDS[sound]:stop()
            end
            SOUNDS[sound]:play()
        end
    end
end

function PlaySEOnce(sound, subsound)
    if sound ~= nil then
        if subsound ~= nil then
            SOUNDS[sound][subsound]:setVolume(0.4)
            if SOUNDS[sound][subsound]:isPlaying() then
                return
            end
            SOUNDS[sound][subsound]:play()
        else
            SOUNDS[sound]:setVolume(0.4)
            if SOUNDS[sound]:isPlaying() then
                return
            end
            SOUNDS[sound]:play()
        end
    end
end
