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
153
154
155
156
157
158
159
160
|
-- copy references to existing globals so that
-- debug.reload() will have a correct initial starting point.
if DEBUG then
-- remember initial state
local _initialGlobals = {}
local _initialPackages = {}
for key, value in pairs(_G) do
_initialGlobals[key] = value
end
for key, value in pairs(package.loaded) do
-- it looks as though the type of a module
-- that is currently being loaded, but hasn't
-- completed is userdata
if type(value) ~= 'userdata' then
_initialPackages[key] = value
end
end
debugger =
{
_initialGlobals = _initialGlobals,
_initialPackages = _initialPackages,
_originalErrhand = love.errhand,
_crashed = false
}
-- replace crash handler
-- we have to do this at this stage; there seems to be
-- some magic that happens to connect to this function
-- such that changing it later, even when creating the
-- initial view, doesn't work
love.errhand = function (message)
if debugger._crashed then
debugger._originalErrhand(message)
return
end
if the.console and the.keys then
debugger._crashed = true
print(string.rep('=', 40))
print('\nCrash, ' .. message .. '\n')
print(debug.traceback())
print('\n' .. string.rep('=', 40) .. '\n')
the.console:show()
love.audio.stop()
-- enter a mini event loop, just updating the
-- console and keys
local elapsed = 0
while true do
if love.event then
love.event.pump()
for e, a, b, c, d in love.event.poll() do
if e == 'quit' then
if not love.quit or not love.quit() then return end
end
love.handlers[e](a, b, c, d)
end
end
if love.timer then
love.timer.step()
elapsed = love.timer.getDelta()
end
the.keys:startFrame(elapsed)
the.console:startFrame(elapsed)
the.keys:update(elapsed)
the.console:update(elapsed)
the.keys:endFrame(elapsed)
the.console:endFrame(elapsed)
if the.keys:pressed('escape') then
if not love.quit or not love.quit() then return end
end
if love.graphics then
love.graphics.clear()
if love.draw then
the.console:draw()
end
end
if love.timer then love.timer.sleep(0.02) end
if love.graphics then love.graphics.present() end
end
else
debugger._originalErrhand(message)
end
end
end
-- Warn about accessing undefined globals in strict mode
if STRICT then
setmetatable(_G, {
__index = function (table, key)
local info = debug.getinfo(2, 'Sl')
print('Warning: accessing undefined global ' .. key .. ', ' ..
info.short_src .. ' line ' .. info.currentline)
end
})
end
require 'zoetrope.core.class'
require 'zoetrope.core.app'
require 'zoetrope.core.cached'
require 'zoetrope.core.collision'
require 'zoetrope.core.globals'
require 'zoetrope.core.sprite'
require 'zoetrope.core.group'
require 'zoetrope.core.promise'
require 'zoetrope.core.timer'
require 'zoetrope.core.tween'
require 'zoetrope.core.view'
require 'zoetrope.input.gamepad'
require 'zoetrope.input.keys'
require 'zoetrope.input.mouse'
require 'zoetrope.sprites.animation'
require 'zoetrope.sprites.emitter'
require 'zoetrope.sprites.fill'
require 'zoetrope.sprites.map'
require 'zoetrope.sprites.text'
require 'zoetrope.sprites.tile'
require 'zoetrope.ui.button'
require 'zoetrope.ui.cursor'
require 'zoetrope.ui.textinput'
require 'zoetrope.utils.debug'
require 'zoetrope.utils.factory'
require 'zoetrope.utils.recorder'
require 'zoetrope.utils.storage'
require 'zoetrope.utils.subview'
-- simple load function to bootstrap the app if love.load() hasn't already been defined;
-- defining it again after this works fine as well
if not love.load then
love.load = function()
if the.app then
-- if we only extended an app, instantiate it
if not (the.app.view and the.app.meta) then the.app = the.app:new() end
the.app:run()
end
end
end
|