summaryrefslogtreecommitdiffstats
path: root/main.lua
blob: d2987ee6200aab8c3c4beb098d37b1998487698d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
debugGraph = require 'vendor.debugGraph'
inspect = require 'vendor.inspect'

screens = {
  require 'screens.screen1',
  require 'screens.screen2',
}

state = {
  currentScreen = 1,
  state = 'running',
  cycleTime = 3,
  transitionTime = 1,
  transitioning = false,
  stateCounter = 0,
}

function love.load()
  love.window.setMode(1366, 768, {borderless=true})

  secondaryCanvas = love.graphics.newCanvas(love.graphics.getWidth(), love.graphics.getHeight())
  fpsGraph = debugGraph:new('fps', 0, 0)
  memGraph = debugGraph:new('mem', 0, 30)
end

function love.draw()
  -- love.graphics.reset()
  screens[state.currentScreen].render()
  if state.transitioning then
    secondaryCanvas:renderTo(screens[state.currentScreen % #screens + 1].render)
    love.graphics.setColor(255, 255, 255, 255 * (state.stateCounter / state.transitionTime)) -- red, green, blue, opacity (this would be white with 20% opacity)
    love.graphics.draw(secondaryCanvas, 0, 0)
  end

  -- Draw graphs
  love.graphics.setColor(255, 255, 255, 128)
  --love.graphics.setNewFont(10)
  --love.graphics.print(inspect(state), 0, 60, 0)

  fpsGraph:draw()
  memGraph:draw()
end

function love.update(dt)
  screens[state.currentScreen].update(dt)

  if state.transitioning then
    screens[state.currentScreen % #screens + 1].update(dt)
  end

  state.stateCounter = state.stateCounter + dt

  if state.transitioning then
    if state.stateCounter >= state.transitionTime then
      state.stateCounter = 0
      state.transitioning = false
      state.currentScreen = (state.currentScreen % #screens) + 1
    end
  else
    if state.stateCounter >= state.cycleTime then
      state.stateCounter = 0
      state.transitioning = true
    end
  end

  -- Update the graphs
  fpsGraph:update(dt)
  memGraph:update(dt)

  require("vendor.lurker").update()
end