/zoeplat

To get this branch, use:
bzr branch http://66.246.75.32/bzr/zoeplat
1 by Josh C
zoetrope 1.3.1
1
-- copy references to existing globals so that
2
-- debug.reload() will have a correct initial starting point.
3
4
if DEBUG then
5
	-- remember initial state
6
7
	local _initialGlobals = {}
8
	local _initialPackages = {}
9
10
	for key, value in pairs(_G) do
11
		_initialGlobals[key] = value
12
	end
13
14
	for key, value in pairs(package.loaded) do
15
		-- it looks as though the type of a module
16
		-- that is currently being loaded, but hasn't
17
		-- completed is userdata
18
19
		if type(value) ~= 'userdata' then
20
			_initialPackages[key] = value
21
		end
22
	end
23
24
	debugger =
25
	{
26
		_initialGlobals = _initialGlobals,
27
		_initialPackages = _initialPackages,
28
		_originalErrhand = love.errhand,
29
		_crashed = false
30
	}
31
32
	-- replace crash handler
33
	-- we have to do this at this stage; there seems to be
34
	-- some magic that happens to connect to this function
35
	-- such that changing it later, even when creating the
36
	-- initial view, doesn't work
37
38
	love.errhand = function (message)
39
		if debugger._crashed then
40
			debugger._originalErrhand(message)
41
			return
42
		end
43
44
		if the.console and the.keys then
45
			debugger._crashed = true
46
			print(string.rep('=', 40))
47
			print('\nCrash, ' .. message .. '\n')
48
			print(debug.traceback())
49
			print('\n' .. string.rep('=', 40) .. '\n')
50
			the.console:show()
51
			love.audio.stop()
52
53
			-- enter a mini event loop, just updating the
54
			-- console and keys
55
56
			local elapsed = 0
57
58
			while true do
59
				if love.event then
60
					love.event.pump()
61
					
62
					for e, a, b, c, d in love.event.poll() do
63
						if e == 'quit' then
64
							if not love.quit or not love.quit() then return end
65
						end
66
67
						love.handlers[e](a, b, c, d)
68
					end
69
				end
70
71
				if love.timer then
72
					love.timer.step()
73
					elapsed = love.timer.getDelta()
74
				end
75
76
				the.keys:startFrame(elapsed)
77
				the.console:startFrame(elapsed)
78
				the.keys:update(elapsed)
79
				the.console:update(elapsed)
80
				the.keys:endFrame(elapsed)
81
				the.console:endFrame(elapsed)
82
83
				if the.keys:pressed('escape') then
84
					if not love.quit or not love.quit() then return end
85
				end
86
87
				if love.graphics then
88
					love.graphics.clear()
89
					if love.draw then
90
						the.console:draw()
91
					end
92
				end
93
94
				if love.timer then love.timer.sleep(0.02) end
95
				if love.graphics then love.graphics.present() end
96
			end
97
		else
98
			debugger._originalErrhand(message)
99
		end
100
	end
101
end
102
103
-- Warn about accessing undefined globals in strict mode
104
105
if STRICT then
106
	setmetatable(_G, {
107
		__index = function (table, key)
108
			local info = debug.getinfo(2, 'Sl')
109
			print('Warning: accessing undefined global ' .. key .. ', ' ..
110
				  info.short_src .. ' line ' .. info.currentline)
111
		end
112
	})
113
end
114
115
require 'zoetrope.core.class'
116
117
require 'zoetrope.core.app'
118
require 'zoetrope.core.cached'
7 by Josh C
use zoetrope 288:a82a08660477 2013-02-23
119
require 'zoetrope.core.collision'
1 by Josh C
zoetrope 1.3.1
120
require 'zoetrope.core.globals'
121
require 'zoetrope.core.sprite'
122
require 'zoetrope.core.group'
123
require 'zoetrope.core.promise'
124
require 'zoetrope.core.timer'
125
require 'zoetrope.core.tween'
126
require 'zoetrope.core.view'
127
7 by Josh C
use zoetrope 288:a82a08660477 2013-02-23
128
require 'zoetrope.input.gamepad'
129
require 'zoetrope.input.keys'
130
require 'zoetrope.input.mouse'
131
1 by Josh C
zoetrope 1.3.1
132
require 'zoetrope.sprites.animation'
133
require 'zoetrope.sprites.emitter'
134
require 'zoetrope.sprites.fill'
135
require 'zoetrope.sprites.map'
136
require 'zoetrope.sprites.text'
137
require 'zoetrope.sprites.tile'
138
139
require 'zoetrope.ui.button'
140
require 'zoetrope.ui.cursor'
141
require 'zoetrope.ui.textinput'
142
143
require 'zoetrope.utils.debug'
144
require 'zoetrope.utils.factory'
145
require 'zoetrope.utils.recorder'
146
require 'zoetrope.utils.storage'
147
require 'zoetrope.utils.subview'
148
149
-- simple load function to bootstrap the app if love.load() hasn't already been defined;
150
-- defining it again after this works fine as well
151
152
if not love.load then
153
	love.load = function()
154
		if the.app then
155
			-- if we only extended an app, instantiate it
156
			if not (the.app.view and the.app.meta) then the.app = the.app:new() end
157
			the.app:run()
158
		end
159
	end
160
end