-
Notifications
You must be signed in to change notification settings - Fork 2
/
game.fnl
39 lines (31 loc) · 867 Bytes
/
game.fnl
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
(local fennel (require "lib.fennel"))
(local repl (require "lib.stdio"))
(var mode (require "mode.menu"))
(fn set-mode [mn ...]
(set mode (require mn))
(when mode.init
(mode.init ...)))
(fn love.load []
(repl.start))
(fn love.draw []
(mode.draw))
(fn love.update [dt]
(mode.update dt set-mode))
(fn love.keypressed [key]
;; LIVE RELOADING
(when (= "f5" key)
(let [name (.. "mode." (. mode :name))]
(let [old (require name)
_ (tset package.loaded name nil)
new (require name)]
(when (= (type new) :table)
(each [k v (pairs new)]
(tset old k v))
(each [k v (pairs old)]
(when (not (. new k))
(tset old k nil)))
(tset package.loaded name old))))
)
(when (= "escape" key)
(love.event.quit))
(mode.keypressed key set-mode))