@gamely/gly-engine-micro 0.0.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +3 -0
- package/dist/main.lua +936 -0
- package/package.json +18 -0
- package/types/main.d.ts +4 -0
package/README.md
ADDED
package/dist/main.lua
ADDED
|
@@ -0,0 +1,936 @@
|
|
|
1
|
+
local math = ((function() local x, y = pcall(require, 'math'); return x and y end)()) or _G.math
|
|
2
|
+
local src_version_5630bfb01410 = nil
|
|
3
|
+
local src_lib_engine_api_app_5630bfb08c80 = nil
|
|
4
|
+
local src_lib_engine_api_key_5630bfb14660 = nil
|
|
5
|
+
local src_lib_engine_api_math_5630bfb12d50 = nil
|
|
6
|
+
local src_lib_engine_api_array_5630bfb125c0 = nil
|
|
7
|
+
local src_lib_engine_draw_text_5630bfaedb60 = nil
|
|
8
|
+
local src_lib_engine_draw_poly_5630bfb09000 = nil
|
|
9
|
+
local src_lib_engine_raw_memory_5630bfb08090 = nil
|
|
10
|
+
local src_lib_object_color_5630bfaff810 = nil
|
|
11
|
+
local src_lib_object_std_5630bfafeb40 = nil
|
|
12
|
+
local src_lib_util_lua_5630bfafb150 = nil
|
|
13
|
+
local src_lib_util_decorator_5630bfb153d0 = nil
|
|
14
|
+
local function main_5630bfacf130()
|
|
15
|
+
local version = src_version_5630bfb01410()
|
|
16
|
+
local engine_game = src_lib_engine_api_app_5630bfb08c80()
|
|
17
|
+
local engine_key = src_lib_engine_api_key_5630bfb14660()
|
|
18
|
+
local engine_math = src_lib_engine_api_math_5630bfb12d50()
|
|
19
|
+
local engine_array = src_lib_engine_api_array_5630bfb125c0()
|
|
20
|
+
local engine_draw_text = src_lib_engine_draw_text_5630bfaedb60()
|
|
21
|
+
local engine_draw_poly = src_lib_engine_draw_poly_5630bfb09000()
|
|
22
|
+
local engine_raw_memory = src_lib_engine_raw_memory_5630bfb08090()
|
|
23
|
+
local color = src_lib_object_color_5630bfaff810()
|
|
24
|
+
local std = src_lib_object_std_5630bfafeb40()
|
|
25
|
+
local util_lua = src_lib_util_lua_5630bfafb150()
|
|
26
|
+
local f=function(a,b)end
|
|
27
|
+
local engine={keyboard=f}
|
|
28
|
+
local application={
|
|
29
|
+
meta={title='', version=''},
|
|
30
|
+
data={width=1280,height=720},
|
|
31
|
+
config={offset_x=0,offset_y=0},
|
|
32
|
+
callbacks={loop=f,draw=f,exit=f,init=f}
|
|
33
|
+
}
|
|
34
|
+
std.log={fatal=f,error=f,warn=f,info=f,debug=f}
|
|
35
|
+
std.bus={emit=f,emit_next=f,listen=f,listen_std_engine=f}
|
|
36
|
+
std.i18n={next=f,back=f,get_language=function()return'en-US'end}
|
|
37
|
+
local cfg_system={
|
|
38
|
+
exit=native_system_exit,
|
|
39
|
+
reset=native_system_reset,
|
|
40
|
+
title=native_system_title,
|
|
41
|
+
get_fps=native_system_get_fps,
|
|
42
|
+
get_secret=native_system_get_secret,
|
|
43
|
+
get_language=native_system_get_language
|
|
44
|
+
}
|
|
45
|
+
local cfg_poly={
|
|
46
|
+
repeats={
|
|
47
|
+
native_cfg_poly_repeat_0 or false,
|
|
48
|
+
native_cfg_poly_repeat_1 or false,
|
|
49
|
+
native_cfg_poly_repeat_2 or false
|
|
50
|
+
},
|
|
51
|
+
triangle=native_draw_triangle,
|
|
52
|
+
poly2=native_draw_poly2,
|
|
53
|
+
poly=native_draw_poly,
|
|
54
|
+
line=native_draw_line
|
|
55
|
+
}
|
|
56
|
+
local cfg_text={
|
|
57
|
+
font_previous=native_text_font_previous
|
|
58
|
+
}
|
|
59
|
+
function native_callback_loop(dt)
|
|
60
|
+
std.milis, std.delta=std.milis + dt, dt
|
|
61
|
+
application.callbacks.loop(std, application.data)
|
|
62
|
+
end
|
|
63
|
+
function native_callback_draw()
|
|
64
|
+
native_draw_start()
|
|
65
|
+
application.callbacks.draw(std, application.data)
|
|
66
|
+
native_draw_flush()
|
|
67
|
+
end
|
|
68
|
+
function native_callback_resize(width, height)
|
|
69
|
+
application.data.width=width
|
|
70
|
+
application.data.height=height
|
|
71
|
+
std.app.width=width
|
|
72
|
+
std.app.height=height
|
|
73
|
+
end
|
|
74
|
+
function native_callback_keyboard(key, value)
|
|
75
|
+
engine.keyboard(std, engine, key, value)
|
|
76
|
+
end
|
|
77
|
+
function native_callback_init(width, height, game_lua)
|
|
78
|
+
local ok, script=true, game_lua
|
|
79
|
+
if type(script) == 'string' then
|
|
80
|
+
ok, script=util_lua.eval(script)
|
|
81
|
+
end
|
|
82
|
+
if not script then
|
|
83
|
+
ok, script=pcall(loadfile, 'game.lua')
|
|
84
|
+
end
|
|
85
|
+
if not ok or not script then
|
|
86
|
+
error(script, 0)
|
|
87
|
+
end
|
|
88
|
+
std.app.width=width
|
|
89
|
+
std.app.height=height
|
|
90
|
+
script.data={width=width,height=height}
|
|
91
|
+
script.config=application.config
|
|
92
|
+
application=script
|
|
93
|
+
std.draw.color=native_draw_color
|
|
94
|
+
std.draw.font=native_draw_font
|
|
95
|
+
std.draw.rect=native_draw_rect
|
|
96
|
+
std.draw.line=native_draw_line
|
|
97
|
+
std.draw.image=native_image_draw
|
|
98
|
+
std.image.load=native_image_load
|
|
99
|
+
std.image.draw=native_image_draw
|
|
100
|
+
std.text.print=native_text_print
|
|
101
|
+
std.text.mensure=native_text_mensure
|
|
102
|
+
std.text.font_size=native_text_font_size
|
|
103
|
+
std.text.font_name=native_text_font_name
|
|
104
|
+
std.text.font_default=native_text_font_default
|
|
105
|
+
std.draw.clear=function(tint)
|
|
106
|
+
native_draw_clear(tint, 0, 0, application.data.width, application.data.height)
|
|
107
|
+
end
|
|
108
|
+
engine.root=application
|
|
109
|
+
engine_raw_memory.install(std, engine)
|
|
110
|
+
engine_game.install(std, engine, cfg_system)
|
|
111
|
+
engine_key.install(std, engine, {})
|
|
112
|
+
engine_math.install(std, engine)
|
|
113
|
+
engine_math.wave.install(std, engine)
|
|
114
|
+
engine_math.clib.install(std, engine)
|
|
115
|
+
engine_math.clib_random.install(std, engine)
|
|
116
|
+
engine_array.install(std, engine, nil, 'array')
|
|
117
|
+
engine_draw_text.install(std, engine, cfg_text)
|
|
118
|
+
engine_draw_poly.install(std, engine, cfg_poly)
|
|
119
|
+
color.install(std, engine)
|
|
120
|
+
std.app.title(application.meta.title..' - '..application.meta.version)
|
|
121
|
+
engine.current=application
|
|
122
|
+
application.callbacks.init(std, application.data)
|
|
123
|
+
end
|
|
124
|
+
local P={
|
|
125
|
+
meta={
|
|
126
|
+
title='gly-engine-micro',
|
|
127
|
+
author='RodrigoDornelles',
|
|
128
|
+
description='shh!',
|
|
129
|
+
version=version
|
|
130
|
+
}
|
|
131
|
+
}
|
|
132
|
+
return P
|
|
133
|
+
end
|
|
134
|
+
src_version_5630bfb01410 = function()
|
|
135
|
+
return '0.0.20'
|
|
136
|
+
end
|
|
137
|
+
--
|
|
138
|
+
src_lib_engine_api_app_5630bfb08c80 = function()
|
|
139
|
+
local util_decorator = src_lib_util_decorator_5630bfb153d0()
|
|
140
|
+
local function reset(std, engine)
|
|
141
|
+
if std.node then
|
|
142
|
+
std.bus.emit('exit')
|
|
143
|
+
std.bus.emit('init')
|
|
144
|
+
else
|
|
145
|
+
engine.root.callbacks.exit(std, engine.root.data)
|
|
146
|
+
engine.root.callbacks.init(std, engine.root.data)
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
local function exit(std)
|
|
150
|
+
std.bus.emit('exit')
|
|
151
|
+
std.bus.emit('quit')
|
|
152
|
+
end
|
|
153
|
+
local function title(func, window_name)
|
|
154
|
+
if func then
|
|
155
|
+
func(window_name)
|
|
156
|
+
end
|
|
157
|
+
end
|
|
158
|
+
local function install(std, engine, config)
|
|
159
|
+
std = std or {}
|
|
160
|
+
config = config or {}
|
|
161
|
+
std.app = std.app or {}
|
|
162
|
+
std.bus.listen('post_quit', function()
|
|
163
|
+
if config.quit then
|
|
164
|
+
config.quit()
|
|
165
|
+
end
|
|
166
|
+
end)
|
|
167
|
+
std.app.title = util_decorator.prefix1(config.set_title, title)
|
|
168
|
+
std.app.exit = util_decorator.prefix1(std, exit)
|
|
169
|
+
std.app.reset = util_decorator.prefix2(std, engine, reset)
|
|
170
|
+
std.app.get_fps = config.get_fps
|
|
171
|
+
return std.app
|
|
172
|
+
end
|
|
173
|
+
local P = {
|
|
174
|
+
install=install
|
|
175
|
+
}
|
|
176
|
+
return P
|
|
177
|
+
end
|
|
178
|
+
--
|
|
179
|
+
src_lib_engine_api_key_5630bfb14660 = function()
|
|
180
|
+
local function real_key(std, engine, rkey, rvalue)
|
|
181
|
+
local value = rvalue == 1 or rvalue == true
|
|
182
|
+
local key = engine.key_bindings[rkey] or (std.key.axis[rkey] and rkey)
|
|
183
|
+
if key then
|
|
184
|
+
std.key.axis[key] = value and 1 or 0
|
|
185
|
+
std.key.press[key] = value
|
|
186
|
+
if key == 'right' or key == 'left' then
|
|
187
|
+
std.key.axis.x = std.key.axis.right - std.key.axis.left
|
|
188
|
+
end
|
|
189
|
+
if key == 'down' or key == 'up' then
|
|
190
|
+
std.key.axis.y = std.key.axis.down - std.key.axis.up
|
|
191
|
+
end
|
|
192
|
+
std.bus.emit('key')
|
|
193
|
+
end
|
|
194
|
+
local a = std.key.axis
|
|
195
|
+
std.key.press.any = (a.left + a.right + a.down + a.up + a.a + a.b + a.c + a.d + a.menu) > 0
|
|
196
|
+
end
|
|
197
|
+
local function real_keydown(std, engine, key)
|
|
198
|
+
real_key(std, engine, key, 1)
|
|
199
|
+
end
|
|
200
|
+
local function real_keyup(std, engine, key)
|
|
201
|
+
real_key(std, engine, key, 0)
|
|
202
|
+
end
|
|
203
|
+
local function event_bus(std, engine)
|
|
204
|
+
std.bus.listen_std_engine('rkey', real_key)
|
|
205
|
+
std.bus.listen_std_engine('rkey1', real_keydown)
|
|
206
|
+
std.bus.listen_std_engine('rkey0', real_keyup)
|
|
207
|
+
end
|
|
208
|
+
local function install(std, engine, key_bindings)
|
|
209
|
+
engine.key_bindings = key_bindings or {}
|
|
210
|
+
engine.keyboard = real_key
|
|
211
|
+
end
|
|
212
|
+
local P = {
|
|
213
|
+
event_bus = event_bus,
|
|
214
|
+
install = install
|
|
215
|
+
}
|
|
216
|
+
return P
|
|
217
|
+
end
|
|
218
|
+
--
|
|
219
|
+
src_lib_engine_api_math_5630bfb12d50 = function()
|
|
220
|
+
local function abs(value)
|
|
221
|
+
if value < 0 then
|
|
222
|
+
return -value
|
|
223
|
+
end
|
|
224
|
+
return value
|
|
225
|
+
end
|
|
226
|
+
local function clamp(value, value_min, value_max)
|
|
227
|
+
if value < value_min then
|
|
228
|
+
return value_min
|
|
229
|
+
elseif value > value_max then
|
|
230
|
+
return value_max
|
|
231
|
+
else
|
|
232
|
+
return value
|
|
233
|
+
end
|
|
234
|
+
end
|
|
235
|
+
local function clamp2(value, value_min, value_max)
|
|
236
|
+
return (value - value_min) % (value_max - value_min + 1) + value_min
|
|
237
|
+
end
|
|
238
|
+
local function dir(value, alpha)
|
|
239
|
+
alpha = alpha or 0
|
|
240
|
+
if value < -alpha then
|
|
241
|
+
return -1
|
|
242
|
+
elseif value > alpha then
|
|
243
|
+
return 1
|
|
244
|
+
else
|
|
245
|
+
return 0
|
|
246
|
+
end
|
|
247
|
+
end
|
|
248
|
+
local function dis(x1,y1,x2,y2)
|
|
249
|
+
local sqr = 1/2
|
|
250
|
+
return ((x2 - x1) ^ 2 + (y2 - y1) ^ 2) ^ (sqr ~= 0 and sqr or 1)
|
|
251
|
+
end
|
|
252
|
+
local function dis2(x1,y1,x2,y2)
|
|
253
|
+
return (x2 - x1) ^ 2 + (y2 - y1) ^ 2
|
|
254
|
+
end
|
|
255
|
+
local function dis3(x1,y1,x2,y2)
|
|
256
|
+
return abs(x1 - x2) + abs(x2 - y2)
|
|
257
|
+
end
|
|
258
|
+
local function lerp(a, b, alpha)
|
|
259
|
+
return a + alpha * ( b - a )
|
|
260
|
+
end
|
|
261
|
+
local function map(value, in_min, in_max, out_min, out_max)
|
|
262
|
+
return (value - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
|
|
263
|
+
end
|
|
264
|
+
local function max(...)
|
|
265
|
+
local args = {...}
|
|
266
|
+
local index = 1
|
|
267
|
+
local value = nil
|
|
268
|
+
local max_value = nil
|
|
269
|
+
if #args == 1 then
|
|
270
|
+
args = args[1]
|
|
271
|
+
end
|
|
272
|
+
while index <= #args do
|
|
273
|
+
value = args[index]
|
|
274
|
+
if max_value == nil or value > max_value then
|
|
275
|
+
max_value = value
|
|
276
|
+
end
|
|
277
|
+
index = index + 1
|
|
278
|
+
end
|
|
279
|
+
return max_value
|
|
280
|
+
end
|
|
281
|
+
local function min(...)
|
|
282
|
+
local args = {...}
|
|
283
|
+
local index = 1
|
|
284
|
+
local value = nil
|
|
285
|
+
local min_value = nil
|
|
286
|
+
if #args == 1 then
|
|
287
|
+
args = args[1]
|
|
288
|
+
end
|
|
289
|
+
while index <= #args do
|
|
290
|
+
value = args[index]
|
|
291
|
+
if min_value == nil or value < min_value then
|
|
292
|
+
min_value = value
|
|
293
|
+
end
|
|
294
|
+
index = index + 1
|
|
295
|
+
end
|
|
296
|
+
return min_value
|
|
297
|
+
end
|
|
298
|
+
local function sine(t, freq)
|
|
299
|
+
return math.pi and math.sin(2 * math.pi * freq * t) or 1
|
|
300
|
+
end
|
|
301
|
+
local function ramp(t, freq, ratio)
|
|
302
|
+
t = (t / 2) % (1 / freq) * freq
|
|
303
|
+
if t < ratio then
|
|
304
|
+
return 2 * t / ratio - 1
|
|
305
|
+
else
|
|
306
|
+
return (2 * t - ratio - 1) / (ratio - 1)
|
|
307
|
+
end
|
|
308
|
+
end
|
|
309
|
+
local function saw(t, freq)
|
|
310
|
+
return ramp(t, freq, 1)
|
|
311
|
+
end
|
|
312
|
+
local function triangle(t, freq)
|
|
313
|
+
return ramp(t, freq, 1/2)
|
|
314
|
+
end
|
|
315
|
+
local function rect(t, freq, duty)
|
|
316
|
+
duty = 1 - duty * 2
|
|
317
|
+
return saw(t, freq) > duty and 1 or -1
|
|
318
|
+
end
|
|
319
|
+
local function square(t, freq)
|
|
320
|
+
return rect(t, freq, 1/2)
|
|
321
|
+
end
|
|
322
|
+
local function install(std)
|
|
323
|
+
std.math = std.math or {}
|
|
324
|
+
std.math.abs=abs
|
|
325
|
+
std.math.clamp=clamp
|
|
326
|
+
std.math.clamp2=clamp2
|
|
327
|
+
std.math.dir=dir
|
|
328
|
+
std.math.dis=dis
|
|
329
|
+
std.math.dis2=dis2
|
|
330
|
+
std.math.dis3=dis3
|
|
331
|
+
std.math.lerp=lerp
|
|
332
|
+
std.math.map=map
|
|
333
|
+
std.math.max=max
|
|
334
|
+
std.math.min=min
|
|
335
|
+
end
|
|
336
|
+
local function install_wave(std)
|
|
337
|
+
std.math = std.math or {}
|
|
338
|
+
std.math.sine=sine
|
|
339
|
+
std.math.saw=saw
|
|
340
|
+
std.math.square=square
|
|
341
|
+
std.math.triangle=triangle
|
|
342
|
+
end
|
|
343
|
+
local function install_clib(std)
|
|
344
|
+
std.math = std.math or {}
|
|
345
|
+
std.math.acos=math.acos
|
|
346
|
+
std.math.asin=math.asin
|
|
347
|
+
std.math.atan=math.atan
|
|
348
|
+
std.math.atan2=math.atan2
|
|
349
|
+
std.math.ceil=math.ceil
|
|
350
|
+
std.math.cos=math.cos
|
|
351
|
+
std.math.cosh=math.cosh
|
|
352
|
+
std.math.deg=math.deg
|
|
353
|
+
std.math.exp=math.exp
|
|
354
|
+
std.math.floor=math.floor
|
|
355
|
+
std.math.fmod=math.fmod
|
|
356
|
+
std.math.frexp=math.frexp
|
|
357
|
+
std.math.huge=math.huge
|
|
358
|
+
std.math.ldexp=math.ldexp
|
|
359
|
+
std.math.log=math.log
|
|
360
|
+
std.math.log10=math.log10
|
|
361
|
+
std.math.modf=math.modf
|
|
362
|
+
std.math.pi=math.pi
|
|
363
|
+
std.math.pow=math.pow
|
|
364
|
+
std.math.rad=math.rad
|
|
365
|
+
std.math.sin=math.sin
|
|
366
|
+
std.math.sinh=math.sinh
|
|
367
|
+
std.math.sqrt=math.sqrt
|
|
368
|
+
std.math.tan=math.tan
|
|
369
|
+
std.math.tanh=math.tanh
|
|
370
|
+
end
|
|
371
|
+
local function install_clib_random(std)
|
|
372
|
+
std.math = std.math or {}
|
|
373
|
+
std.math.random = function(a, b)
|
|
374
|
+
a = a and math.floor(a)
|
|
375
|
+
b = b and math.floor(b)
|
|
376
|
+
return math.random(a, b)
|
|
377
|
+
end
|
|
378
|
+
end
|
|
379
|
+
local P = {
|
|
380
|
+
install = install,
|
|
381
|
+
wave = {
|
|
382
|
+
install = install_wave
|
|
383
|
+
},
|
|
384
|
+
clib = {
|
|
385
|
+
install = install_clib
|
|
386
|
+
},
|
|
387
|
+
clib_random = {
|
|
388
|
+
install = install_clib_random
|
|
389
|
+
}
|
|
390
|
+
}
|
|
391
|
+
return P;
|
|
392
|
+
end
|
|
393
|
+
--
|
|
394
|
+
src_lib_engine_api_array_5630bfb125c0 = function()
|
|
395
|
+
local util_decorator = src_lib_util_decorator_5630bfb153d0()
|
|
396
|
+
local function array_map(array, func)
|
|
397
|
+
local res = {}
|
|
398
|
+
local index = 1
|
|
399
|
+
local length = #array
|
|
400
|
+
while index <= length do
|
|
401
|
+
res[#res + 1] = func(array[index], index)
|
|
402
|
+
index = index + 1
|
|
403
|
+
end
|
|
404
|
+
return res
|
|
405
|
+
end
|
|
406
|
+
local function array_filter(array, func)
|
|
407
|
+
func = func or (function(v) return v and v ~= 0 end)
|
|
408
|
+
local res = {}
|
|
409
|
+
local index = 1
|
|
410
|
+
local length = #array
|
|
411
|
+
while index <= length do
|
|
412
|
+
local value = array[index]
|
|
413
|
+
if func(value, index) then
|
|
414
|
+
res[#res + 1] = value
|
|
415
|
+
end
|
|
416
|
+
index = index + 1
|
|
417
|
+
end
|
|
418
|
+
return res
|
|
419
|
+
end
|
|
420
|
+
local function array_unique(array)
|
|
421
|
+
local res = {}
|
|
422
|
+
local index = 1
|
|
423
|
+
local length = #array
|
|
424
|
+
local setmap = {}
|
|
425
|
+
while index <= length do
|
|
426
|
+
local value = array[index]
|
|
427
|
+
if not setmap[value] then
|
|
428
|
+
res[#res + 1] = value
|
|
429
|
+
end
|
|
430
|
+
setmap[value] = true
|
|
431
|
+
index = index + 1
|
|
432
|
+
end
|
|
433
|
+
return res
|
|
434
|
+
end
|
|
435
|
+
local function array_foreach(array, func)
|
|
436
|
+
local index = 1
|
|
437
|
+
local length = #array
|
|
438
|
+
while index <= length do
|
|
439
|
+
func(array[index], index)
|
|
440
|
+
index = index + 1
|
|
441
|
+
end
|
|
442
|
+
end
|
|
443
|
+
local function array_reducer(array, func, value)
|
|
444
|
+
local index = value and 1 or 2
|
|
445
|
+
local length = #array
|
|
446
|
+
value = value or array[1]
|
|
447
|
+
while index <= length do
|
|
448
|
+
value = func(value, array[index], index)
|
|
449
|
+
index = index + 1
|
|
450
|
+
end
|
|
451
|
+
return value
|
|
452
|
+
end
|
|
453
|
+
local function array_index(array, func, reverse)
|
|
454
|
+
func = func or function() return true end
|
|
455
|
+
local index, inc, final = 1, 1, #array
|
|
456
|
+
if reverse then
|
|
457
|
+
index, inc, final = #array, -1, 1
|
|
458
|
+
end
|
|
459
|
+
repeat
|
|
460
|
+
if func(array[index], index) then
|
|
461
|
+
return index
|
|
462
|
+
end
|
|
463
|
+
index = index + inc
|
|
464
|
+
until (reverse and index < final) or (not reverse and index > final)
|
|
465
|
+
return nil
|
|
466
|
+
end
|
|
467
|
+
local function array_first(array, func)
|
|
468
|
+
local index = array_index(array, func)
|
|
469
|
+
if index then
|
|
470
|
+
return array[index]
|
|
471
|
+
end
|
|
472
|
+
return nil
|
|
473
|
+
end
|
|
474
|
+
local function array_last(array, func)
|
|
475
|
+
local index = array_index(array, func, true)
|
|
476
|
+
if index then
|
|
477
|
+
return array[index]
|
|
478
|
+
end
|
|
479
|
+
return nil
|
|
480
|
+
end
|
|
481
|
+
local function array_some(array, func, reverse)
|
|
482
|
+
local index, inc, final = 1, 1, #array
|
|
483
|
+
if reverse then
|
|
484
|
+
index, inc, final = #array, -1, 1
|
|
485
|
+
end
|
|
486
|
+
repeat
|
|
487
|
+
if func(array[index], index) then
|
|
488
|
+
return true
|
|
489
|
+
end
|
|
490
|
+
index = index + inc
|
|
491
|
+
until (reverse and index < final) or (not reverse and index > final)
|
|
492
|
+
return false
|
|
493
|
+
end
|
|
494
|
+
local function array_every(array, func)
|
|
495
|
+
local index = 1
|
|
496
|
+
local length = #array
|
|
497
|
+
while index <= length do
|
|
498
|
+
if not func(array[index], index) then
|
|
499
|
+
return false
|
|
500
|
+
end
|
|
501
|
+
index = index + 1
|
|
502
|
+
end
|
|
503
|
+
return true
|
|
504
|
+
end
|
|
505
|
+
local function array_pipeline(std, array)
|
|
506
|
+
local decorator_iterator = function(func)
|
|
507
|
+
return function(self, func2, extra)
|
|
508
|
+
self.array = func(self.array, func2, extra)
|
|
509
|
+
return self
|
|
510
|
+
end
|
|
511
|
+
end
|
|
512
|
+
local decorator_reduce = function(func, return_self)
|
|
513
|
+
return function(self, func2, extra)
|
|
514
|
+
local res = func(self.array, func2, extra)
|
|
515
|
+
return (return_self and self) or res
|
|
516
|
+
end
|
|
517
|
+
end
|
|
518
|
+
local self = {
|
|
519
|
+
array = array,
|
|
520
|
+
map = decorator_iterator(array_map),
|
|
521
|
+
filter = decorator_iterator(array_filter),
|
|
522
|
+
unique = decorator_iterator(array_unique),
|
|
523
|
+
each = decorator_reduce(array_foreach, true),
|
|
524
|
+
reducer = decorator_reduce(array_reducer),
|
|
525
|
+
index = decorator_reduce(array_index),
|
|
526
|
+
first = decorator_reduce(array_first),
|
|
527
|
+
last = decorator_reduce(array_last),
|
|
528
|
+
some = decorator_reduce(array_some),
|
|
529
|
+
every = decorator_reduce(array_every),
|
|
530
|
+
table = function(self) return self.array end,
|
|
531
|
+
json = function(self) return std.json.encode(self.array) end
|
|
532
|
+
}
|
|
533
|
+
return self
|
|
534
|
+
end
|
|
535
|
+
local function install(std, engine, library, name)
|
|
536
|
+
local lib = std[name] or {}
|
|
537
|
+
lib.map = array_map
|
|
538
|
+
lib.filter = array_filter
|
|
539
|
+
lib.unique = array_unique
|
|
540
|
+
lib.each = array_foreach
|
|
541
|
+
lib.reducer = array_reducer
|
|
542
|
+
lib.index = array_index
|
|
543
|
+
lib.first = array_first
|
|
544
|
+
lib.last = array_last
|
|
545
|
+
lib.some = array_some
|
|
546
|
+
lib.every = array_every
|
|
547
|
+
lib.from = util_decorator.prefix1(std, array_pipeline)
|
|
548
|
+
std[name] = lib
|
|
549
|
+
end
|
|
550
|
+
local P = {
|
|
551
|
+
install = install
|
|
552
|
+
}
|
|
553
|
+
return P
|
|
554
|
+
end
|
|
555
|
+
--
|
|
556
|
+
src_lib_engine_draw_text_5630bfaedb60 = function()
|
|
557
|
+
local util_decorator = src_lib_util_decorator_5630bfb153d0()
|
|
558
|
+
local function text_put(std, engine, font_previous, pos_x, pos_y, text, size)
|
|
559
|
+
size = size or 2
|
|
560
|
+
local hem = engine.current.data.width / 80
|
|
561
|
+
local vem = engine.current.data.height / 24
|
|
562
|
+
local font_size = hem * size
|
|
563
|
+
std.text.font_default(0)
|
|
564
|
+
std.text.font_size(font_size)
|
|
565
|
+
std.text.print(pos_x * hem, pos_y * vem, text)
|
|
566
|
+
font_previous()
|
|
567
|
+
end
|
|
568
|
+
local function text_print_ex(std, engine, x, y, text, align)
|
|
569
|
+
local w, h = std.text.mensure(text)
|
|
570
|
+
local aligns = {w, w/2, 0}
|
|
571
|
+
std.text.print(x - aligns[(align or 1) + 2], y, text)
|
|
572
|
+
return w, h
|
|
573
|
+
end
|
|
574
|
+
local function install(std, engine, config)
|
|
575
|
+
std.text.print_ex = util_decorator.prefix2(std, engine, text_print_ex)
|
|
576
|
+
std.text.put = util_decorator.prefix3(std, engine, config.font_previous, text_put)
|
|
577
|
+
end
|
|
578
|
+
local P = {
|
|
579
|
+
install=install
|
|
580
|
+
}
|
|
581
|
+
return P
|
|
582
|
+
end
|
|
583
|
+
--
|
|
584
|
+
src_lib_engine_draw_poly_5630bfb09000 = function()
|
|
585
|
+
local function decorator_poo(object, func)
|
|
586
|
+
if not object or not func then return func end
|
|
587
|
+
return function(a, b, c, d)
|
|
588
|
+
return func(object, a, b, c, d)
|
|
589
|
+
end
|
|
590
|
+
end
|
|
591
|
+
local function decorator_line(func_draw_line)
|
|
592
|
+
return function(mode, verts)
|
|
593
|
+
local index = 4
|
|
594
|
+
while index <= #verts do
|
|
595
|
+
func_draw_line(verts[index - 3], verts[index - 2], verts[index - 1], verts[index])
|
|
596
|
+
index = index + 2
|
|
597
|
+
end
|
|
598
|
+
end
|
|
599
|
+
end
|
|
600
|
+
local function decorator_triangle(func_draw_poly, std, func_draw_triangle)
|
|
601
|
+
if not func_draw_triangle then
|
|
602
|
+
return func_draw_poly
|
|
603
|
+
end
|
|
604
|
+
local point = function(x, y, px, py, scale, angle, ox, oy)
|
|
605
|
+
local xx = x + ((ox - px) * -scale * std.math.cos(angle)) - ((ox - py) * -scale * std.math.sin(angle))
|
|
606
|
+
local yy = y + ((oy - px) * -scale * std.math.sin(angle)) + ((oy - py) * -scale * std.math.cos(angle))
|
|
607
|
+
return xx, yy
|
|
608
|
+
end
|
|
609
|
+
return function(engine_mode, verts, x, y, scale, angle, ox, oy)
|
|
610
|
+
if #verts ~= 6 then
|
|
611
|
+
return func_draw_poly(engine_mode, verts, x, y, scale, angle, ox, oy)
|
|
612
|
+
end
|
|
613
|
+
ox = ox or 0
|
|
614
|
+
oy = oy or ox or 0
|
|
615
|
+
local x1, y1 = point(x, y, verts[1], verts[2], scale, angle, ox, oy)
|
|
616
|
+
local x2, y2 = point(x, y, verts[3], verts[4], scale, angle, ox, oy)
|
|
617
|
+
local x3, y3 = point(x, y, verts[5], verts[6], scale, angle, ox, oy)
|
|
618
|
+
return func_draw_triangle(engine_mode, x1, y1, x2, y2, x3, y3)
|
|
619
|
+
end
|
|
620
|
+
end
|
|
621
|
+
local function decorator_poly(func_draw_poly, std, modes, repeats)
|
|
622
|
+
local func_repeat = function(verts, mode)
|
|
623
|
+
if repeats and repeats[mode + 1] then
|
|
624
|
+
verts[#verts + 1] = verts[1]
|
|
625
|
+
verts[#verts + 1] = verts[2]
|
|
626
|
+
end
|
|
627
|
+
end
|
|
628
|
+
return function (engine_mode, verts, x, y, scale, angle, ox, oy)
|
|
629
|
+
if #verts < 6 or #verts % 2 ~= 0 then return end
|
|
630
|
+
local mode = modes and modes[engine_mode + 1] or engine_mode
|
|
631
|
+
local rotated = std.math.cos and angle and angle ~= 0
|
|
632
|
+
ox = ox or 0
|
|
633
|
+
oy = oy or ox or 0
|
|
634
|
+
if x and y and not rotated then
|
|
635
|
+
local index = 1
|
|
636
|
+
local verts2 = {}
|
|
637
|
+
scale = scale or 1
|
|
638
|
+
while index <= #verts do
|
|
639
|
+
if index % 2 ~= 0 then
|
|
640
|
+
verts2[index] = x + (verts[index] * scale)
|
|
641
|
+
else
|
|
642
|
+
verts2[index] = y + (verts[index] * scale)
|
|
643
|
+
end
|
|
644
|
+
index = index + 1
|
|
645
|
+
end
|
|
646
|
+
func_repeat(verts2, engine_mode)
|
|
647
|
+
func_draw_poly(mode, verts2)
|
|
648
|
+
elseif x and y then
|
|
649
|
+
local index = 1
|
|
650
|
+
local verts2 = {}
|
|
651
|
+
while index < #verts do
|
|
652
|
+
local px = verts[index]
|
|
653
|
+
local py = verts[index + 1]
|
|
654
|
+
local xx = x + ((ox - px) * -scale * std.math.cos(angle)) - ((ox - py) * -scale * std.math.sin(angle))
|
|
655
|
+
local yy = y + ((oy - px) * -scale * std.math.sin(angle)) + ((oy - py) * -scale * std.math.cos(angle))
|
|
656
|
+
verts2[index] = xx
|
|
657
|
+
verts2[index + 1] = yy
|
|
658
|
+
index = index + 2
|
|
659
|
+
end
|
|
660
|
+
func_repeat(verts2, engine_mode)
|
|
661
|
+
func_draw_poly(mode, verts2)
|
|
662
|
+
else
|
|
663
|
+
func_draw_poly(mode, verts)
|
|
664
|
+
end
|
|
665
|
+
end
|
|
666
|
+
end
|
|
667
|
+
local function decorator_position(engine, func)
|
|
668
|
+
return function(mode, verts, pos_x, pos_y, scale, angle, ox, oy)
|
|
669
|
+
local x = engine.current.config.offset_x + (pos_x or 0)
|
|
670
|
+
local y = engine.current.config.offset_y + (pos_y or 0)
|
|
671
|
+
ox = ox or 0
|
|
672
|
+
oy = ox or oy or 0
|
|
673
|
+
scale = scale or 1
|
|
674
|
+
angle = angle or 0
|
|
675
|
+
return func(mode, verts, x, y, scale, angle, ox, oy)
|
|
676
|
+
end
|
|
677
|
+
end
|
|
678
|
+
local function install(std, engine, config)
|
|
679
|
+
local draw_line = decorator_poo(config.object, config.line)
|
|
680
|
+
local draw_poly = decorator_poo(config.object, config.poly) or decorator_line(draw_line)
|
|
681
|
+
local draw_poly2 = config.poly2 or decorator_poly(draw_poly, std, config.modes, config.repeats)
|
|
682
|
+
local draw_verts = decorator_triangle(draw_poly2, std, config.triangle)
|
|
683
|
+
std.draw.poly = decorator_position(engine, draw_verts)
|
|
684
|
+
end
|
|
685
|
+
local P = {
|
|
686
|
+
install=install
|
|
687
|
+
}
|
|
688
|
+
return P
|
|
689
|
+
end
|
|
690
|
+
--
|
|
691
|
+
src_lib_engine_raw_memory_5630bfb08090 = function()
|
|
692
|
+
local memory_dict_unload = {}
|
|
693
|
+
local memory_dict = {}
|
|
694
|
+
local memory_list = {}
|
|
695
|
+
local function cache_get(key)
|
|
696
|
+
return memory_dict[key]
|
|
697
|
+
end
|
|
698
|
+
local function cache_set(key, load_func, unload_func)
|
|
699
|
+
local value = load_func()
|
|
700
|
+
memory_list[#memory_list + 1] = key
|
|
701
|
+
memory_dict_unload[key] = unload_func
|
|
702
|
+
memory_dict[key] = value
|
|
703
|
+
end
|
|
704
|
+
local function cache(key, load_func, unload_func)
|
|
705
|
+
local value = cache_get(key)
|
|
706
|
+
if value == nil then
|
|
707
|
+
cache_set(key, load_func, unload_func)
|
|
708
|
+
value = cache_get(key)
|
|
709
|
+
end
|
|
710
|
+
return value
|
|
711
|
+
end
|
|
712
|
+
local function unset(key)
|
|
713
|
+
if memory_dict_unload[key] then
|
|
714
|
+
memory_dict_unload[key](memory_dict[key])
|
|
715
|
+
end
|
|
716
|
+
memory_dict[key] = nil
|
|
717
|
+
end
|
|
718
|
+
local function gc_clear_all()
|
|
719
|
+
local index = 1
|
|
720
|
+
local items = #memory_list
|
|
721
|
+
while index <= items do
|
|
722
|
+
unset(memory_list[index])
|
|
723
|
+
index = index + 1
|
|
724
|
+
end
|
|
725
|
+
memory_list = {}
|
|
726
|
+
return items
|
|
727
|
+
end
|
|
728
|
+
local function install(std)
|
|
729
|
+
std = std or {}
|
|
730
|
+
std.mem = std.mem or {}
|
|
731
|
+
std.mem.cache = cache
|
|
732
|
+
std.mem.cache_get = cache_get
|
|
733
|
+
std.mem.cache_set = cache_set
|
|
734
|
+
std.mem.unset = unset
|
|
735
|
+
std.mem.gc_clear_all = gc_clear_all
|
|
736
|
+
return {
|
|
737
|
+
mem=std.mem
|
|
738
|
+
}
|
|
739
|
+
end
|
|
740
|
+
local P = {
|
|
741
|
+
install=install
|
|
742
|
+
}
|
|
743
|
+
return P
|
|
744
|
+
end
|
|
745
|
+
--
|
|
746
|
+
src_lib_object_color_5630bfaff810 = function()
|
|
747
|
+
local function install(std)
|
|
748
|
+
std.color = std.color or {}
|
|
749
|
+
std.color.white = 0xFFFFFFFF
|
|
750
|
+
std.color.lightgray = 0xC8CCCCFF
|
|
751
|
+
std.color.gray = 0x828282FF
|
|
752
|
+
std.color.darkgray = 0x505050FF
|
|
753
|
+
std.color.yellow = 0xFDF900FF
|
|
754
|
+
std.color.gold = 0xFFCB00FF
|
|
755
|
+
std.color.orange = 0xFFA100FF
|
|
756
|
+
std.color.pink = 0xFF6DC2FF
|
|
757
|
+
std.color.red = 0xE62937FF
|
|
758
|
+
std.color.maroon = 0xBE2137FF
|
|
759
|
+
std.color.green = 0x00E430FF
|
|
760
|
+
std.color.lime = 0x009E2FFF
|
|
761
|
+
std.color.darkgreen = 0x00752CFF
|
|
762
|
+
std.color.skyblue = 0x66BFFFFF
|
|
763
|
+
std.color.blue = 0x0079F1FF
|
|
764
|
+
std.color.darkblue = 0x0052ACFF
|
|
765
|
+
std.color.purple = 0xC87AFFFF
|
|
766
|
+
std.color.violet = 0x873CBEFF
|
|
767
|
+
std.color.darkpurple = 0x701F7EFF
|
|
768
|
+
std.color.beige = 0xD3B083FF
|
|
769
|
+
std.color.brown = 0x7F6A4FFF
|
|
770
|
+
std.color.darkbrown = 0x4C3F2FFF
|
|
771
|
+
std.color.black = 0x000000FF
|
|
772
|
+
std.color.blank = 0x00000000
|
|
773
|
+
std.color.magenta = 0xFF00FFFF
|
|
774
|
+
end
|
|
775
|
+
local P = {
|
|
776
|
+
install = install
|
|
777
|
+
}
|
|
778
|
+
return P
|
|
779
|
+
end
|
|
780
|
+
--
|
|
781
|
+
src_lib_object_std_5630bfafeb40 = function()
|
|
782
|
+
local P = {
|
|
783
|
+
milis = 0,
|
|
784
|
+
delta = 0,
|
|
785
|
+
math = {
|
|
786
|
+
},
|
|
787
|
+
draw = {
|
|
788
|
+
image = function() end,
|
|
789
|
+
clear = function () end,
|
|
790
|
+
color = function () end,
|
|
791
|
+
rect = function () end,
|
|
792
|
+
line = function () end,
|
|
793
|
+
poly = function () end,
|
|
794
|
+
tui_text = function() end
|
|
795
|
+
},
|
|
796
|
+
text = {
|
|
797
|
+
put = function() end,
|
|
798
|
+
print = function() end,
|
|
799
|
+
mensure = function() end,
|
|
800
|
+
font_size = function() end,
|
|
801
|
+
font_name = function() end,
|
|
802
|
+
font_default = function() end
|
|
803
|
+
},
|
|
804
|
+
image = {
|
|
805
|
+
load = function() end,
|
|
806
|
+
draw = function() end
|
|
807
|
+
},
|
|
808
|
+
app = {
|
|
809
|
+
width = 1280,
|
|
810
|
+
height = 720,
|
|
811
|
+
title = function() end,
|
|
812
|
+
reset = function () end,
|
|
813
|
+
load = function() end,
|
|
814
|
+
exit = function () end
|
|
815
|
+
},
|
|
816
|
+
key = {
|
|
817
|
+
axis = {
|
|
818
|
+
x = 0,
|
|
819
|
+
y = 0,
|
|
820
|
+
menu=0,
|
|
821
|
+
up=0,
|
|
822
|
+
down=0,
|
|
823
|
+
left=0,
|
|
824
|
+
right=0,
|
|
825
|
+
a = 0,
|
|
826
|
+
b = 0,
|
|
827
|
+
c = 0,
|
|
828
|
+
d = 0
|
|
829
|
+
},
|
|
830
|
+
press = {
|
|
831
|
+
menu=false,
|
|
832
|
+
up=false,
|
|
833
|
+
down=false,
|
|
834
|
+
left=false,
|
|
835
|
+
right=false,
|
|
836
|
+
a=false,
|
|
837
|
+
b=false,
|
|
838
|
+
c=false,
|
|
839
|
+
d=false,
|
|
840
|
+
any=false
|
|
841
|
+
}
|
|
842
|
+
}
|
|
843
|
+
}
|
|
844
|
+
return P;
|
|
845
|
+
end
|
|
846
|
+
--
|
|
847
|
+
src_lib_util_lua_5630bfafb150 = function()
|
|
848
|
+
local function has_support_utf8()
|
|
849
|
+
if jit then
|
|
850
|
+
return true
|
|
851
|
+
end
|
|
852
|
+
if tonumber(_VERSION:match('Lua 5.(%d+)')) >= 3 then
|
|
853
|
+
return true
|
|
854
|
+
end
|
|
855
|
+
return false
|
|
856
|
+
end
|
|
857
|
+
local function eval(script)
|
|
858
|
+
local loader = loadstring or load
|
|
859
|
+
if not loader then
|
|
860
|
+
error('eval not allowed')
|
|
861
|
+
end
|
|
862
|
+
local ok, chunk = pcall(loader, script)
|
|
863
|
+
if not ok then
|
|
864
|
+
return false, chunk
|
|
865
|
+
end
|
|
866
|
+
if type(chunk) ~= 'function' then
|
|
867
|
+
return false, 'failed to eval'
|
|
868
|
+
end
|
|
869
|
+
return pcall(chunk)
|
|
870
|
+
end
|
|
871
|
+
local P = {
|
|
872
|
+
eval = eval,
|
|
873
|
+
has_support_utf8=has_support_utf8
|
|
874
|
+
}
|
|
875
|
+
return P
|
|
876
|
+
end
|
|
877
|
+
--
|
|
878
|
+
src_lib_util_decorator_5630bfb153d0 = function()
|
|
879
|
+
local function decorator_prefix3(zig, zag, zom, func)
|
|
880
|
+
return function (a, b, c, d, e, f)
|
|
881
|
+
return func(zig, zag, zom, a, b, c, d, e, f)
|
|
882
|
+
end
|
|
883
|
+
end
|
|
884
|
+
local function decorator_prefix2(zig, zag, func)
|
|
885
|
+
return function (a, b, c, d, e, f)
|
|
886
|
+
return func(zig, zag, a, b, c, d, e, f)
|
|
887
|
+
end
|
|
888
|
+
end
|
|
889
|
+
local function decorator_prefix1(zig, func)
|
|
890
|
+
return function (a, b, c, d, e, f)
|
|
891
|
+
return func(zig, a, b, c, d, e, f)
|
|
892
|
+
end
|
|
893
|
+
end
|
|
894
|
+
local function decorator_offset_xy2(object, func)
|
|
895
|
+
return function(a, b, c, d, e, f)
|
|
896
|
+
local x = object.offset_x + (b or 0)
|
|
897
|
+
local y = object.offset_y + (c or 0)
|
|
898
|
+
return func(a, x, y, d, e, f)
|
|
899
|
+
end
|
|
900
|
+
end
|
|
901
|
+
local function decorator_offset_xyxy1(object, func)
|
|
902
|
+
return function(a, b, c, d, e, f)
|
|
903
|
+
local x1 = object.offset_x + a
|
|
904
|
+
local y1 = object.offset_y + b
|
|
905
|
+
local x2 = object.offset_x + c
|
|
906
|
+
local y2 = object.offset_y + d
|
|
907
|
+
return func(x1, y1, x2, y2, e, f)
|
|
908
|
+
end
|
|
909
|
+
end
|
|
910
|
+
local function decorator_offset_xy1(object, func)
|
|
911
|
+
return function(a, b, c, d, e, f)
|
|
912
|
+
local x = object.offset_x + a
|
|
913
|
+
local y = object.offset_y + b
|
|
914
|
+
return func(x, y, c, d, e, f)
|
|
915
|
+
end
|
|
916
|
+
end
|
|
917
|
+
local function table_prefix1(prefix, fn_table)
|
|
918
|
+
local new_table = {}
|
|
919
|
+
for name, fn in pairs(fn_table) do
|
|
920
|
+
new_table[name] = decorator_prefix1(prefix, fn)
|
|
921
|
+
end
|
|
922
|
+
return new_table
|
|
923
|
+
end
|
|
924
|
+
local P = {
|
|
925
|
+
offset_xy1 = decorator_offset_xy1,
|
|
926
|
+
offset_xy2 = decorator_offset_xy2,
|
|
927
|
+
offset_xyxy1 = decorator_offset_xyxy1,
|
|
928
|
+
prefix3 = decorator_prefix3,
|
|
929
|
+
prefix2 = decorator_prefix2,
|
|
930
|
+
prefix1 = decorator_prefix1,
|
|
931
|
+
prefix1_t = table_prefix1
|
|
932
|
+
}
|
|
933
|
+
return P
|
|
934
|
+
end
|
|
935
|
+
--
|
|
936
|
+
return main_5630bfacf130()
|
package/package.json
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gamely/gly-engine-micro",
|
|
3
|
+
"version": "0.0.20",
|
|
4
|
+
"author": "RodrigoDornelles",
|
|
5
|
+
"license": "Apache-2.0",
|
|
6
|
+
"homepage": "https://docs.gamely.com.br",
|
|
7
|
+
"repository": "https://github.com/gamelly/gly-engine",
|
|
8
|
+
"funding": "https://github.com/sponsors/RodrigoDornelles",
|
|
9
|
+
"bugs": "https://github.com/gamelly/gly-engine/issues",
|
|
10
|
+
"description": "Game Engine written in 100% lua that runs in a vacuum.",
|
|
11
|
+
"main": "dist/main.lua",
|
|
12
|
+
"types": "types/main.d.ts",
|
|
13
|
+
"keywords": [
|
|
14
|
+
"game engine",
|
|
15
|
+
"game",
|
|
16
|
+
"engine"
|
|
17
|
+
]
|
|
18
|
+
}
|
package/types/main.d.ts
ADDED