-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmodule.lua
More file actions
65 lines (51 loc) · 1.29 KB
/
module.lua
File metadata and controls
65 lines (51 loc) · 1.29 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
local M = {}
M.required = {}
function M.req(module)
M.required[module] = true
return require(module)
end
function M.load(gameModuleName)
M.hotload = function()
local firstRun = M.Game == nil
local prevState = nil
if M.Game and M.Game.hotunload then
prevState = M.Game.hotunload()
end
-- clear the loaded modules
for module, _ in pairs(M.required) do
package.loaded[module] = nil
M.required[module] = nil
end
-- require the game module
M.Game = M.req(gameModuleName)
-- register the love callbacks
if firstRun and M.Game.load then
M.Game.load()
end
-- call the game module's hotload function
M.Game.hotload(prevState)
for _, callback in pairs(M.loveCallbacks) do
love[callback] = M.Game[callback]
end
print(string.format('hotloaded %s module', gameModuleName), M.Game)
end
M.hotload()
end
M.loveCallbacks = {
-- core
'update', 'draw',
-- keyboard
'keypressed', 'keyreleased',
'textedited', 'text-input',
-- mouse
'mousepressed', 'mousereleased', 'mousemoved', 'wheelmoved',
-- mobile
'lowmemory',
'touchpressed', 'touchreleased', 'touchmoved',
-- window
'visible', 'focus', 'resize',
'directorydropped', 'filedropped',
-- process control
'quit', 'threaderror',
}
return M