-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.lua
More file actions
152 lines (127 loc) · 4.16 KB
/
main.lua
File metadata and controls
152 lines (127 loc) · 4.16 KB
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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
local font = love.graphics.newFont('fonts/moder-dos-437.ttf', 20)
love.graphics.setFont(font)
local screen = {
w = 800,
h = 600,
margin = 10,
}
-- Statistics: FPS, memory
local statUI = require('statUI')
local ui = require('likelihud')
local layoutUI = require('examples.layout')
local simpleUI = require('examples.simple')
local oeUI = require('examples.o')
local squaresUI = require('examples.squares')
local fillUI = require('examples.fill')
local startUI = require('examples.start')
local buttonsUI = require('examples.buttons')
local eventsUI = require('examples.events')
local focusUI = require('examples.focus')
local HUD = nil
local queue = {}
local function updateHUD(newHUD)
local w, h = love.window.getMode()
if HUD then
HUD:registerQ()
end
HUD = newHUD
HUD:place(screen.margin, screen.margin, w - 2 * screen.margin, h - 2 * screen.margin)
HUD:registerQ(queue)
end
local oeSound = love.audio.newSource( 'sounds/oe.mp3', 'stream' )
local n = 1
local keys = {
pressed = {
text = {
['n'] = function()
n = n + 1
HUD:push { id = 'number.changed', number = n }
end,
['1'] = function() updateHUD(layoutUI) end,
['2'] = function() updateHUD(simpleUI) end,
['3'] = function() updateHUD(oeUI) end,
['4'] = function() updateHUD(squaresUI) end,
['5'] = function() updateHUD(fillUI) end,
['6'] = function() updateHUD(buttonsUI) end,
['7'] = function() updateHUD(eventsUI) end,
['8'] = function() updateHUD(focusUI) end,
['q'] = function() love.event.quit() end,
},
['space'] = function()
if oeSound:isPlaying() then
oeSound:stop()
end
oeSound:play()
HUD:push({ id = 'button.pressed' })
end,
['escape'] = function () HUD:unsetFocus() end,
['backspace'] = function ()
HUD:push {
id = 'backspace',
filter = function (this) return this.focus end
}
end,
['left'] = function ()
HUD:push {
id = 'left',
filter = function (this) return this.focus end
}
end,
['right'] = function ()
HUD:push {
id = 'right',
filter = function (this) return this.focus end
}
end,
},
released = {
['space'] = function() HUD:push({ id = 'button.released' }) end,
}
}
function love.load()
love.window.setMode(screen.w, screen.h, { resizable = true })
updateHUD(startUI)
end
function love.update(_)
for _, event in ipairs(queue) do
if event.id == 'last.clicked' then
HUD:push { id = 'last.clicked', message = event.data }
end
end
ui.utils.clearArray(queue)
local fps = love.timer.getFPS()
local mem = math.floor(collectgarbage('count'))
statUI:push { id = 'stat', fps = fps, mem = mem }
end
function love.resize(w, h)
HUD:place(screen.margin, screen.margin, w - 2 * screen.margin, h - 2 * screen.margin)
statUI:place(screen.margin, screen.margin, w - 2 * screen.margin, h - 2 * screen.margin)
end
function love.keypressed(key)
if keys.pressed[key] then keys.pressed[key]() end
end
function love.keyreleased(key)
if keys.released[key] then keys.released[key]() end
end
function love.mousemoved(x, y, dx, dy, istouch)
HUD:mousemoved(x, y, dx, dy, istouch)
end
function love.mousepressed(x, y, button, istouch, presses)
HUD:mousepressed(x, y, button, istouch, presses)
end
function love.mousereleased(x, y, button, istouch, presses)
HUD:mousereleased(x, y, button, istouch, presses)
end
function love.textinput (text)
local event = { id = 'textinput',
text = text,
filter = function (this) return this.focus end }
HUD:push(event)
if not event.swallowed then
if keys.pressed.text[text] then keys.pressed.text[text]() end
end
end
function love.draw()
HUD:draw()
statUI:draw()
end