TaggedEngine/main.lua

185 lines
5.1 KiB
Lua

local state = require("modules.states.playstate")
local myMath = require("modules.math")
local myTypes = require("modules.types")
local files = require("modules.files")
local json = require("modules.json")
local logging = require("modules.logging")
local discord = require("modules.discord")
local applicationid = require("discord_app")
local songs = require("charts.songs")
local curSong = songs[1]
local curIndex = 1
local curDiffList = songs[1].difficulties
local curDiff = songs[1].difficulties[1]
local curDiffInd = 1
local curState = nil
local stateLoaded = false
local pressed = {false,false,false}
local bg
local logo
local gf
local freaky = love.audio.newSource("sounds/freakyMenu.ogg", "stream")
local function setup()
bg = myTypes.Image("images/menuBG.png", 0)
bg.ui = false
gf = myTypes.Sprite("sprites/gfDanceTitle.png", "sprites/gfDanceTitle.json")
gf:PlayAnimation("gfDance", 24, true)
gf.position = myTypes.Vector2(340, 60)
for index, rect in next, gf.quads.gfDance do
rect.resize = myTypes.Vector2(0.7,.7)
end
logo = myTypes.Sprite("sprites/logoBumpin.png", "sprites/logoBumpin.json")
logo:PlayAnimation("logo bumpin", 24, true)
logo.position = myTypes.Vector2(-80, 0)
freaky:play()
local timeStamp = os.time()
discord.updatePresence({
details = "In menu",
largeImageKey = "bigimage",
startTimestamp = timeStamp,
state = "TaggedEngine: FNF in LUA, better than ever."
})
end
local font = love.graphics.newFont("fonts/Phantomuff.ttf", 40)
local gettingKey
local settings = json.parse(files.read_file("settings.json"))
local keybinds = settings.Keybinds
function love.update(dt)
if curState and curState.loaded then
if stateLoaded then
curState.update(dt)
else
stateLoaded = true -- skipping this update frame
curState.finish()
end
elseif not curState then
myTypes.render.cameraTarget = myTypes.Vector2(0,0)
myTypes.updateSprites(dt)
end
end
function love.draw()
if curState and stateLoaded then
curState.draw()
else
myTypes.drawSprites()
love.graphics.print({{0,0,0}, string.format("Song: %s, Difficulty: %s, List: %s", curSong.name, curDiff, logging.dump(curDiffList))}, font, love.graphics.getWidth()/4, love.graphics:getHeight()/2 + 250, 0, 1, 1, 200)
love.graphics.print(
{{0,0,0}, string.format("Left: %s, Down: %s, Up: %s, Right: %s \nDownscroll: %s",
keybinds[1],
keybinds[2],
keybinds[3],
keybinds[4],
settings.Downscroll
)})
love.graphics.print({{0,0,0}, "Press 1 to change LEFT \nPress 2 to change DOWN \nPress 3 to change UP \nPress 4 to change RIGHT \nPress 0 to toggle DOWNSCROLL"}, 500, 0)
end
end
function run()
myTypes.destroyAllSprites()
freaky:stop()
curState = state(curSong.name, curDiff)
curState.quit = function()
curState = nil
stateLoaded = false
myTypes.destroyAllSprites()
setup()
end
curState.restart = function()
curState = nil
stateLoaded = false
myTypes.destroyAllSprites()
run()
end
curState.load()
end
function love.keypressed(key, un, is)
if curState and stateLoaded then
curState.keypressed(key, un, is)
elseif not curState then
if not gettingKey then
if key == "return" then
run()
elseif key == "down" then
curIndex, curSong = next(songs, curIndex)
if not curSong then
curIndex, curSong = next(songs)
curDiffList = curSong.difficulties
else
curDiffList = curSong.difficulties
end
curDiffInd = 1
curDiff = curDiffList[1]
elseif key == "up" then --the solution was so stupid easy
if songs[curIndex - 1] then
curSong = songs[curIndex - 1]
curIndex = curIndex - 1
else
curSong = songs[1]
curIndex = 1
end
curDiffInd = 1
curDiff = curDiffList[1]
elseif key == "right" then
if curDiffList[curDiffInd + 1] then
curDiff = curDiffList[curDiffInd + 1]
curDiffInd = curDiffInd + 1
else
curDiff = curDiffList[1]
curDiffInd = 1
end
elseif key == "left" then
if curDiffList[curDiffInd - 1] then
curDiff = curDiffList[curDiffInd - 1]
curDiffInd = curDiffInd - 1
elseif curDiffList[5] then
curDiff = curDiffList[5]
curDiffInd = 5
else
curDiff = curDiffList[3]
curDiffInd = 3
end
elseif tonumber(key) and tonumber(key) < 5 then
if key == "0" then
settings.Downscroll = not settings.Downscroll
files.write_file("settings.json", json.stringify(settings))
else
gettingKey = tonumber(key)
end
end
else
keybinds[gettingKey] = key
gettingKey = nil
files.write_file("settings.json", json.stringify(settings))
end
end
end
love.window.setMode(1280, 720, { fullscreen = false , resizable = true})
discord.initialize(applicationid, true)
setup()