summaryrefslogtreecommitdiffstats
path: root/main.lua
blob: c9f63fbcda6492f832c92715a215d75fafaa3267 (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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
local debugGraph = require 'vendor.debugGraph'
local inspect = require 'vendor.inspect'
local push = require 'vendor.push'

environment = os.getenv('ENV')

screens = {
  require 'screens.weather',
  require 'screens.time',
  require 'screens.screen1',
}

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

local gameWidth, gameHeight = 1280, 720
local windowWidth, windowHeight = love.window.getDesktopDimensions()
windowWidth, windowHeight = windowWidth*.5, windowHeight*.5 --make the window a bit smaller than the screen itself

if environment == 'DEV' then
  push:setupScreen(gameWidth, gameHeight, windowWidth, windowHeight, {fullscreen = false, resizable = true})
else
  push:setupScreen(gameWidth, gameHeight, gameWidth, gameHeight, {fullscreen = true})
end

function love.resize(w, h)
  push:resize(w, h)
  secondaryCanvas = love.graphics.newCanvas(push:getWidth(), push:getHeight())
end

function love.load()
  love.mouse.setVisible( false )

  secondaryCanvas = love.graphics.newCanvas(push:getWidth(), push:getHeight())

  fpsGraph = debugGraph:new('fps', 0, 0)
  memGraph = debugGraph:new('mem', 0, 30)

  for key, node in ipairs(screens) do
    node.load()
  end
end

function getw() return push:getWidth() end
function geth() return push:getHeight() end

function love.draw()
  push:start()

  -- Patch love.graphics.getWidth/Height to account for push
  oldw, oldh = love.graphics.getWidth, love.graphics.getHeight
  love.graphics.getWidth, love.graphics.getHeight = getw, geth

  screens[state.currentScreen].render()

  if state.transitioning then
    -- Render next screen into canvas and fade accordingly
    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()

  love.graphics.getWidth, love.graphics.getHeight = oldw, oldh
  push:finish()
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