-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmoai.lua
393 lines (295 loc) · 9.46 KB
/
moai.lua
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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
--==============================================================
-- Copyright (c) 2010-2011 Zipline Games, Inc.
-- All Rights Reserved.
-- http://getmoai.com
--==============================================================
EnableLuaProfiler = false
if EnableLuaProfiler then
--KLEIProfiler.StartRecording()
local resume = coroutine.resume
local yield = coroutine.yield
local create = coroutine.create
coroutine.resume =
function(co, ...)
local cco = coroutine.running()
KLEIProfiler.co_pause( cco )
KLEIProfiler.co_resume( co )
local rval = { resume(co, ...) }
KLEIProfiler.co_pause( co )
if coroutine.status(co) == 'dead' then
KLEIProfiler.co_destroy( co )
end
KLEIProfiler.co_resume( cco )
return unpack(rval)
end
coroutine.create =
function(...)
local co = create(...)
KLEIProfiler.co_create( co )
return co
end
end
local function initTransform2DInterface ( interface, superInterface )
function interface.addLoc ( self, xDelta, yDelta )
superInterface.addLoc ( self, xDelta, yDelta, 0 )
end
function interface.addPiv ( self, xDelta, yDelta )
superInterface.addPiv ( self, xDelta, yDelta, 0 )
end
function interface.addRot ( self, rDelta )
superInterface.addRot ( self, 0, 0, rDelta )
end
function interface.addScl ( self, xSclDelta, ySclDelta )
superInterface.addScl ( self, xSclDelta, ySclDelta, 0 )
end
function interface.getLoc ( self )
local x, y = superInterface.getLoc ( self )
return x, y
end
function interface.getPiv ( self )
local x, y = superInterface.getPiv ( self )
return x, y
end
function interface.getRot ( self )
local x, y, z = superInterface.getRot ( self )
return z
end
function interface.getScl ( self )
local x, y = superInterface.getScl ( self )
return x, y
end
function interface.modelToWorld ( self, x, y )
local x, y = superInterface.modelToWorld ( self, x, y, 0 )
return x, y
end
function interface.move ( self, xDelta, yDelta, rDelta, xSclDelta, ySclDelta, length, mode )
return superInterface.move ( self, xDelta, yDelta, 0, 0, 0, rDelta, xSclDelta, ySclDelta, 0, length, mode )
end
function interface.moveLoc ( self, xDelta, yDelta, length, mode )
return superInterface.moveLoc ( self, xDelta, yDelta, 0, length, mode )
end
function interface.movePiv ( self, xDelta, yDelta, length, mode )
return superInterface.movePiv ( self, xDelta, yDelta, 0, length, mode )
end
function interface.moveRot ( self, rDelta, length, mode )
return superInterface.moveRot ( self, 0, 0, rDelta, length, mode )
end
function interface.moveScl ( self, xSclDelta, ySclDelta, length, mode )
return superInterface.moveScl ( self, xSclDelta, ySclDelta, 0, length, mode )
end
function interface.seek ( self, xGoal, yGoal, rGoal, xSclGoal, ySclGoal, length, mode )
return superInterface.seek ( self, xGoal, yGoal, 0, 0, 0, rGoal, xSclGoal, ySclGoal, 1, length, mode )
end
function interface.seekLoc ( self, xGoal, yGoal, length, mode )
return superInterface.seekLoc ( self, xGoal, yGoal, 0, length, mode )
end
function interface.seekPiv ( self, xGoal, yGoal, length, mode )
return superInterface.seekPiv ( self, xGoal, yGoal, 0, length, mode )
end
function interface.seekRot ( self, rGoal, length, mode )
return superInterface.seekRot ( self, 0, 0, rGoal, length, mode )
end
function interface.seekScl ( self, xSclGoal, ySclGoal, length, mode )
return superInterface.seekScl ( self, xSclGoal, ySclGoal, 1, length, mode )
end
function interface.setLoc ( self, x, y )
superInterface.setLoc ( self, x, y, 0 )
end
function interface.setPiv ( self, x, y )
superInterface.setPiv ( self, x, y, 0 )
end
function interface.setRot ( self, rot )
superInterface.setRot ( self, 0, 0, rot )
end
function interface.setScl ( self, x, y )
superInterface.setScl ( self, x, y, 1 )
end
function interface.worldToModel ( self, x, y )
local x, y = superInterface.worldToModel ( self, x, y, 0 )
return x, y
end
end
----------------------------------------------------------------
-- moai2D.lua - version 1.0 Beta
----------------------------------------------------------------
MOAIThread = MOAICoroutine
MOAILayerBridge2D = MOAILayerBridge
MOAICamera.extend (
'MOAICamera2D',
function ( interface, class, superInterface, superClass )
-- extend the interface
initTransform2DInterface ( interface, superInterface )
interface.getFieldOfView = nil
interface.getFocalLength = nil
interface.setFieldOfView = nil
interface.setOrtho = nil
function interface.setFarPlane ( self, far )
superInterface.setFarPlane ( self, far or -1 )
end
function interface.setNearPlane ( self, near )
superInterface.setNearPlane ( self, near or 1 )
end
-- extend the class
local new = class.new
function class.new ()
local self = new ()
superInterface.setOrtho ( self, true )
superInterface.setNearPlane ( self, 1 )
superInterface.setFarPlane ( self, -1 )
return self
end
end
)
if MOAIFreeTypeFontReader then
MOAIFont.extend (
'MOAIFont',
function ( interface, class, superInterface, superClass )
-- extend the interface
function interface.loadFromTTF ( self, filename, charcodes, points, dpi )
self:load ( filename )
self:preloadGlyphs ( charcodes, points, dpi )
end
-- extend the class
local new = class.new
function class.new ()
local self = new ()
superInterface.setCache ( self, MOAIGlyphCache.new ())
superInterface.setReader ( self, MOAIFreeTypeFontReader.new ())
return self
end
end
)
end
MOAIHttpTask = MOAIHttpTaskCurl or MOAIHttpNaCl or false
KLEIMetric = KLEIMetric or false
MOAILayer.extend (
'MOAILayer2D',
function ( interface, class, superInterface, superClass )
-- extend the interface
initTransform2DInterface ( interface, superInterface )
interface.setPartitionCull2D = nil
function interface.setSortScale ( self, x, y, priority )
superInterface.setSortScale ( self, x, y, 0, priority )
end
function interface.wndToWorld ( self, x, y )
local x, y = superInterface.wndToWorld ( self, x, y, 0 )
return x, y
end
function interface.worldToWnd ( self, x, y )
local x, y = superInterface.worldToWnd ( self, x, y, 0 )
return x, y
end
-- extend the class
class.SORT_Z_ASCENDING = nil
class.SORT_Z_DESCENDING = nil
end
)
MOAIProp.extend (
'MOAIProp2D',
function ( interface, class, superInterface, superClass )
-- extend the interface
initTransform2DInterface ( interface, superInterface )
function interface.setFrame ( self, xMin, yMin, xMax, yMax )
superInterface.setBounds ( self, xMin, yMin, 0, xMax, yMax, 0 )
end
function interface.getRect ( self )
print ( self )
local xMin, yMin, zMin, xMax, yMax, zMax = superInterface.getBounds ( self )
return xMin, yMin, xMax, yMax
end
end
)
MOAIRenderMgr.extend (
'MOAIRenderMgr',
function ( class, superClass )
-- extend the class
function class.affirmRenderTable ()
local renderTable = class.getRenderTable ()
if not renderTable then
renderTable = {}
class.setRenderTable ( renderTable )
end
return renderTable
end
function class.clearRenderStack ()
class.setRenderTable ( nil )
end
function class.popRenderPass ()
local renderTable = class.affirmRenderTable ()
table.remove ( renderTable )
end
function class.pushRenderPass ( pass )
local renderTable = class.affirmRenderTable ()
table.insert ( renderTable, pass )
end
function class.removeRenderPass ( pass )
local renderTable = class.affirmRenderTable ()
for i, cursor in ipairs ( renderTable ) do
if cursor == pass then
table.remove ( renderTable, i )
break
end
end
end
end
)
MOAISim.extend (
'MOAISim',
function ( class, superClass )
-- extend the class
function class.clearRenderStack ()
MOAIRenderMgr.clearRenderStack ()
end
function class.popRenderPass ()
MOAIRenderMgr.popRenderPass ()
end
function class.pushRenderPass ( pass )
MOAIRenderMgr.pushRenderPass ( pass )
end
function class.removeRenderPass ( pass )
MOAIRenderMgr.removeRenderPass ( pass )
end
end
)
MOAITextBox.extend (
'MOAITextBox',
function ( interface, class, superInterface, superClass )
-- extend the interface
function interface.affirmStyle ( self )
local style = self:getStyle ()
if not style then
style = MOAITextStyle.new ()
self:setStyle ( style )
end
return style
end
function interface.setFont ( self, font )
local style = self:affirmStyle ()
style:setFont ( font )
end
function interface.setTextSize ( self, points, dpi )
local style = self:affirmStyle ()
style:setSize ( points, dpi )
end
end
)
MOAITransform.extend (
'MOAITransform2D',
function ( interface, class, superInterface, superClass )
-- extend the interface
initTransform2DInterface ( interface, superInterface )
end
)
MOAIApp = MOAIAppAndroid or MOAIAppIOS
MOAIDialog = MOAIDialogAndroid or MOAIDialogIOS
MOAIMoviePlayer = MOAIMoviePlayerAndroid or MOAIMoviePlayerIOS
-- Optional 3rd party extensions
MOAIAdColony = MOAIAdColonyAndroid or MOAIAdColonyIOS
MOAIBilling = MOAIBillingAndroid or MOAIBillingIOS
MOAIChartBoost = MOAIChartBoostAndroid or MOAIChartBoostIOS
MOAICrittercism = MOAICrittercismAndroid or MOAICrittercismIOS
MOAIFacebook = MOAIFacebookAndroid or MOAIFacebookIOS
MOAINotifications = MOAINotificationsAndroid or MOAINotificationsIOS
MOAITapjoy = MOAITapjoyAndroid or MOAITapjoyIOS
KLEISteamWorkshop = KLEISteamWorkshop or false
KLEIAchievements = KLEIAchievements or false