@gamely/gly-engine-nano 0.1.5

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/dist/main.lua ADDED
@@ -0,0 +1,473 @@
1
+ local source_version_c2b = nil
2
+ local source_engine_api_system_key_c3d = nil
3
+ local source_engine_api_draw_text_c48 = nil
4
+ local source_engine_api_draw_poly_c53 = nil
5
+ local source_engine_api_system_color_c65 = nil
6
+ local source_shared_var_object_std_c70 = nil
7
+ local source_shared_string_eval_code_c82 = nil
8
+ local source_shared_functional_decorator_10a6 = nil
9
+ local function main_c22()
10
+ local version = source_version_c2b()
11
+ local engine_key = source_engine_api_system_key_c3d()
12
+ local engine_api_draw_text = source_engine_api_draw_text_c48()
13
+ local engine_api_draw_poly = source_engine_api_draw_poly_c53()
14
+ local color = source_engine_api_system_color_c65()
15
+ local std = source_shared_var_object_std_c70()
16
+ local eval_code = source_shared_string_eval_code_c82()
17
+ local f=function(a,b)end
18
+ local engine={keyboard=f}
19
+ local application={
20
+ meta={title='', version=''},
21
+ data={width=1280,height=720},
22
+ config={offset_x=0,offset_y=0},
23
+ callbacks={loop=f,draw=f,exit=f,init=f}
24
+ }
25
+ std.log={fatal=f,error=f,warn=f,info=f,debug=f}
26
+ std.bus={emit=f,emit_next=f,listen=f,listen_std_engine=f}
27
+ std.i18n={next=f,back=f,get_language=function()return'en-US'end}
28
+ local cfg_poly={
29
+ repeats={
30
+ native_cfg_poly_repeat_0 or false,
31
+ native_cfg_poly_repeat_1 or false,
32
+ native_cfg_poly_repeat_2 or false
33
+ },
34
+ triangle=native_draw_triangle,
35
+ poly2=native_draw_poly2,
36
+ poly=native_draw_poly,
37
+ line=native_draw_line
38
+ }
39
+ local cfg_text={
40
+ is_tui = native_text_is_tui,
41
+ font_previous=native_text_font_previous
42
+ }
43
+ function native_callback_loop(dt)
44
+ std.milis, std.delta=std.milis + dt, dt
45
+ application.callbacks.loop(std, application.data)
46
+ end
47
+ function native_callback_draw()
48
+ native_draw_start()
49
+ application.callbacks.draw(std, application.data)
50
+ native_draw_flush()
51
+ end
52
+ function native_callback_resize(width, height)
53
+ application.data.width=width
54
+ application.data.height=height
55
+ std.app.width=width
56
+ std.app.height=height
57
+ end
58
+ function native_callback_keyboard(key, value)
59
+ engine.keyboard(std, engine, key, value)
60
+ end
61
+ function native_callback_init(width, height, game_lua)
62
+ local ok, script=true, game_lua
63
+ if type(script) == 'string' then
64
+ ok, script=eval_code.script(script)
65
+ end
66
+ if not script then
67
+ ok, script=pcall(loadfile, 'game.lua')
68
+ end
69
+ if not ok or not script then
70
+ error(script, 0)
71
+ end
72
+ std.app.width=width
73
+ std.app.height=height
74
+ script.data={width=width,height=height}
75
+ script.config=application.config
76
+ application=script
77
+ std.draw.color=native_draw_color
78
+ std.draw.font=native_draw_font
79
+ std.draw.rect=native_draw_rect
80
+ std.draw.line=native_draw_line
81
+ std.image.load=native_image_load
82
+ std.image.draw=native_image_draw
83
+ std.text.print=native_text_print
84
+ std.text.mensure=native_text_mensure
85
+ std.text.font_size=native_text_font_size
86
+ std.text.font_name=native_text_font_name
87
+ std.text.font_default=native_text_font_default
88
+ std.draw.clear=function(tint)
89
+ native_draw_clear(tint, 0, 0, application.data.width, application.data.height)
90
+ end
91
+ std.app.reset = function()
92
+ (application.callbacks.exit or function() end)(std, application.data)
93
+ application.callbacks.init(std, application.data)
94
+ end
95
+ engine.root=application
96
+ color.install(std, engine)
97
+ engine_key.install(std, engine, {})
98
+ engine_api_draw_text.install(std, engine, cfg_text)
99
+ engine_api_draw_poly.install(std, engine, cfg_poly)
100
+ engine.current=application
101
+ application.callbacks.init(std, application.data)
102
+ end
103
+ local P={
104
+ meta={
105
+ title='gly-engine-nano',
106
+ author='RodrigoDornelles',
107
+ description='shh!',
108
+ version=version
109
+ }
110
+ }
111
+ return P
112
+ end
113
+ source_version_c2b = function()
114
+ return '0.1.5'
115
+ end
116
+ --
117
+ source_engine_api_system_key_c3d = function()
118
+ local function real_key(std, engine, rkey, rvalue)
119
+ local value = rvalue == 1 or rvalue == true
120
+ local key = engine.key_bindings[rkey] or (std.key.axis[rkey] and rkey)
121
+ if key then
122
+ std.key.axis[key] = value and 1 or 0
123
+ std.key.press[key] = value
124
+ if key == 'right' or key == 'left' then
125
+ std.key.axis.x = std.key.axis.right - std.key.axis.left
126
+ end
127
+ if key == 'down' or key == 'up' then
128
+ std.key.axis.y = std.key.axis.down - std.key.axis.up
129
+ end
130
+ std.bus.emit('key')
131
+ end
132
+ local a = std.key.axis
133
+ std.key.press.any = (a.left + a.right + a.down + a.up + a.a + a.b + a.c + a.d + a.menu) > 0
134
+ end
135
+ local function real_keydown(std, engine, key)
136
+ real_key(std, engine, key, 1)
137
+ end
138
+ local function real_keyup(std, engine, key)
139
+ real_key(std, engine, key, 0)
140
+ end
141
+ local function install(std, engine, key_bindings)
142
+ engine.key_bindings = key_bindings or {}
143
+ engine.keyboard = real_key
144
+ std.bus.listen_std_engine('rkey', real_key)
145
+ std.bus.listen_std_engine('rkey1', real_keydown)
146
+ std.bus.listen_std_engine('rkey0', real_keyup)
147
+ end
148
+ local P = {
149
+ install = install
150
+ }
151
+ return P
152
+ end
153
+ --
154
+ source_engine_api_draw_text_c48 = function()
155
+ local util_decorator = source_shared_functional_decorator_10a6()
156
+ local function text_put(std, engine, font_previous, pos_x, pos_y, text, size)
157
+ size = size or 2
158
+ local hem = engine.current.data.width / 80
159
+ local vem = engine.current.data.height / 24
160
+ local font_size = hem * size
161
+ std.text.font_default(0)
162
+ std.text.font_size(font_size)
163
+ std.text.print(pos_x * hem, pos_y * vem, text)
164
+ font_previous()
165
+ end
166
+ local function text_print_ex(std, engine, x, y, text, align_x, align_y)
167
+ local w, h = std.text.mensure(text)
168
+ local aligns_x, aligns_y = {w, w/2, 0}, {h, h/2, 0}
169
+ std.text.print(x - aligns_x[(align_x or 1) + 2], y - aligns_y[(align_y or 1) + 2], text)
170
+ return w, h
171
+ end
172
+ local function install(std, engine, config)
173
+ std.text.font_previous = config.font_previous
174
+ std.text.is_tui = config.is_tui or function() return false end
175
+ std.text.print_ex = util_decorator.prefix2(std, engine, text_print_ex)
176
+ std.text.put = util_decorator.prefix3(std, engine, config.font_previous, text_put)
177
+ end
178
+ local P = {
179
+ install=install
180
+ }
181
+ return P
182
+ end
183
+ --
184
+ source_engine_api_draw_poly_c53 = function()
185
+ local function decorator_poo(object, func)
186
+ if not object or not func then return func end
187
+ return function(a, b, c, d)
188
+ return func(object, a, b, c, d)
189
+ end
190
+ end
191
+ local function decorator_line(func_draw_line)
192
+ return function(mode, verts)
193
+ local index = 4
194
+ while index <= #verts do
195
+ func_draw_line(verts[index - 3], verts[index - 2], verts[index - 1], verts[index])
196
+ index = index + 2
197
+ end
198
+ end
199
+ end
200
+ local function decorator_triangle(func_draw_poly, std, func_draw_triangle)
201
+ if not func_draw_triangle then
202
+ return func_draw_poly
203
+ end
204
+ local point = function(x, y, px, py, scale, angle, ox, oy)
205
+ local xx = x + ((ox - px) * -scale * std.math.cos(angle)) - ((ox - py) * -scale * std.math.sin(angle))
206
+ local yy = y + ((oy - px) * -scale * std.math.sin(angle)) + ((oy - py) * -scale * std.math.cos(angle))
207
+ return xx, yy
208
+ end
209
+ return function(engine_mode, verts, x, y, scale, angle, ox, oy)
210
+ if #verts ~= 6 then
211
+ return func_draw_poly(engine_mode, verts, x, y, scale, angle, ox, oy)
212
+ end
213
+ ox = ox or 0
214
+ oy = oy or ox or 0
215
+ local x1, y1 = point(x, y, verts[1], verts[2], scale, angle, ox, oy)
216
+ local x2, y2 = point(x, y, verts[3], verts[4], scale, angle, ox, oy)
217
+ local x3, y3 = point(x, y, verts[5], verts[6], scale, angle, ox, oy)
218
+ return func_draw_triangle(engine_mode, x1, y1, x2, y2, x3, y3)
219
+ end
220
+ end
221
+ local function decorator_poly(func_draw_poly, std, modes, repeats)
222
+ local func_repeat = function(verts, mode)
223
+ if repeats and repeats[mode + 1] then
224
+ verts[#verts + 1] = verts[1]
225
+ verts[#verts + 1] = verts[2]
226
+ end
227
+ end
228
+ return function (engine_mode, verts, x, y, scale, angle, ox, oy)
229
+ if #verts < 6 or #verts % 2 ~= 0 then return end
230
+ local mode = modes and modes[engine_mode + 1] or engine_mode
231
+ local rotated = std.math.cos and angle and angle ~= 0
232
+ ox = ox or 0
233
+ oy = oy or ox or 0
234
+ if x and y and not rotated then
235
+ local index = 1
236
+ local verts2 = {}
237
+ scale = scale or 1
238
+ while index <= #verts do
239
+ if index % 2 ~= 0 then
240
+ verts2[index] = x + (verts[index] * scale)
241
+ else
242
+ verts2[index] = y + (verts[index] * scale)
243
+ end
244
+ index = index + 1
245
+ end
246
+ func_repeat(verts2, engine_mode)
247
+ func_draw_poly(mode, verts2)
248
+ elseif x and y then
249
+ local index = 1
250
+ local verts2 = {}
251
+ while index < #verts do
252
+ local px = verts[index]
253
+ local py = verts[index + 1]
254
+ local xx = x + ((ox - px) * -scale * std.math.cos(angle)) - ((ox - py) * -scale * std.math.sin(angle))
255
+ local yy = y + ((oy - px) * -scale * std.math.sin(angle)) + ((oy - py) * -scale * std.math.cos(angle))
256
+ verts2[index] = xx
257
+ verts2[index + 1] = yy
258
+ index = index + 2
259
+ end
260
+ func_repeat(verts2, engine_mode)
261
+ func_draw_poly(mode, verts2)
262
+ else
263
+ func_draw_poly(mode, verts)
264
+ end
265
+ end
266
+ end
267
+ local function decorator_position(engine, func)
268
+ return function(mode, verts, pos_x, pos_y, scale, angle, ox, oy)
269
+ local x = engine.current.config.offset_x + (pos_x or 0)
270
+ local y = engine.current.config.offset_y + (pos_y or 0)
271
+ ox = ox or 0
272
+ oy = ox or oy or 0
273
+ scale = scale or 1
274
+ angle = angle or 0
275
+ return func(mode, verts, x, y, scale, angle, ox, oy)
276
+ end
277
+ end
278
+ local function install(std, engine, config)
279
+ local draw_line = decorator_poo(config.object, config.line)
280
+ local draw_poly = decorator_poo(config.object, config.poly) or decorator_line(draw_line)
281
+ local draw_poly2 = config.poly2 or decorator_poly(draw_poly, std, config.modes, config.repeats)
282
+ local draw_verts = decorator_triangle(draw_poly2, std, config.triangle)
283
+ std.draw.poly = decorator_position(engine, draw_verts)
284
+ end
285
+ local P = {
286
+ install=install
287
+ }
288
+ return P
289
+ end
290
+ --
291
+ source_engine_api_system_color_c65 = function()
292
+ local function install(std)
293
+ std.color = std.color or {}
294
+ std.color.white = 0xFFFFFFFF
295
+ std.color.lightgray = 0xC8CCCCFF
296
+ std.color.gray = 0x828282FF
297
+ std.color.darkgray = 0x505050FF
298
+ std.color.yellow = 0xFDF900FF
299
+ std.color.gold = 0xFFCB00FF
300
+ std.color.orange = 0xFFA100FF
301
+ std.color.pink = 0xFF6DC2FF
302
+ std.color.red = 0xE62937FF
303
+ std.color.maroon = 0xBE2137FF
304
+ std.color.green = 0x00E430FF
305
+ std.color.lime = 0x009E2FFF
306
+ std.color.darkgreen = 0x00752CFF
307
+ std.color.skyblue = 0x66BFFFFF
308
+ std.color.blue = 0x0079F1FF
309
+ std.color.darkblue = 0x0052ACFF
310
+ std.color.purple = 0xC87AFFFF
311
+ std.color.violet = 0x873CBEFF
312
+ std.color.darkpurple = 0x701F7EFF
313
+ std.color.beige = 0xD3B083FF
314
+ std.color.brown = 0x7F6A4FFF
315
+ std.color.darkbrown = 0x4C3F2FFF
316
+ std.color.black = 0x000000FF
317
+ std.color.blank = 0x00000000
318
+ std.color.magenta = 0xFF00FFFF
319
+ end
320
+ local P = {
321
+ install = install
322
+ }
323
+ return P
324
+ end
325
+ --
326
+ source_shared_var_object_std_c70 = function()
327
+ local P = {
328
+ milis = 0,
329
+ delta = 0,
330
+ math = {
331
+ },
332
+ media = {
333
+ },
334
+ draw = {
335
+ image = function() end,
336
+ clear = function () end,
337
+ color = function () end,
338
+ rect = function () end,
339
+ line = function () end,
340
+ poly = function () end,
341
+ tui_text = function() end
342
+ },
343
+ text = {
344
+ put = function() end,
345
+ print = function() end,
346
+ mensure = function() end,
347
+ font_size = function() end,
348
+ font_name = function() end,
349
+ font_default = function() end
350
+ },
351
+ image = {
352
+ load = function() end,
353
+ draw = function() end
354
+ },
355
+ app = {
356
+ width = 1280,
357
+ height = 720,
358
+ title = function() end,
359
+ reset = function () end,
360
+ load = function() end,
361
+ exit = function () end
362
+ },
363
+ key = {
364
+ axis = {
365
+ x = 0,
366
+ y = 0,
367
+ menu=0,
368
+ up=0,
369
+ down=0,
370
+ left=0,
371
+ right=0,
372
+ a = 0,
373
+ b = 0,
374
+ c = 0,
375
+ d = 0
376
+ },
377
+ press = {
378
+ menu=false,
379
+ up=false,
380
+ down=false,
381
+ left=false,
382
+ right=false,
383
+ a=false,
384
+ b=false,
385
+ c=false,
386
+ d=false,
387
+ any=false
388
+ }
389
+ }
390
+ }
391
+ return P;
392
+ end
393
+ --
394
+ source_shared_string_eval_code_c82 = function()
395
+ local function script(src)
396
+ local loader = loadstring or load
397
+ if not loader then
398
+ error('eval not allowed')
399
+ end
400
+ local ok, chunk = pcall(loader, src)
401
+ if not ok then
402
+ return false, chunk
403
+ end
404
+ if type(chunk) ~= 'function' then
405
+ return false, 'failed to eval code'
406
+ end
407
+ return pcall(chunk)
408
+ end
409
+ local P = {
410
+ script = script,
411
+ }
412
+ return P
413
+ end
414
+ --
415
+ source_shared_functional_decorator_10a6 = function()
416
+ local function decorator_prefix3(zig, zag, zom, func)
417
+ return function (a, b, c, d, e, f)
418
+ return func(zig, zag, zom, a, b, c, d, e, f)
419
+ end
420
+ end
421
+ local function decorator_prefix2(zig, zag, func)
422
+ return function (a, b, c, d, e, f)
423
+ return func(zig, zag, a, b, c, d, e, f)
424
+ end
425
+ end
426
+ local function decorator_prefix1(zig, func)
427
+ return function (a, b, c, d, e, f)
428
+ return func(zig, a, b, c, d, e, f)
429
+ end
430
+ end
431
+ local function decorator_offset_xy2(object, func)
432
+ return function(a, b, c, d, e, f)
433
+ local x = object.offset_x + (b or 0)
434
+ local y = object.offset_y + (c or 0)
435
+ return func(a, x, y, d, e, f)
436
+ end
437
+ end
438
+ local function decorator_offset_xyxy1(object, func)
439
+ return function(a, b, c, d, e, f)
440
+ local x1 = object.offset_x + a
441
+ local y1 = object.offset_y + b
442
+ local x2 = object.offset_x + c
443
+ local y2 = object.offset_y + d
444
+ return func(x1, y1, x2, y2, e, f)
445
+ end
446
+ end
447
+ local function decorator_offset_xy1(object, func)
448
+ return function(a, b, c, d, e, f)
449
+ local x = object.offset_x + a
450
+ local y = object.offset_y + b
451
+ return func(x, y, c, d, e, f)
452
+ end
453
+ end
454
+ local function table_prefix1(prefix, fn_table)
455
+ local new_table = {}
456
+ for name, fn in pairs(fn_table) do
457
+ new_table[name] = decorator_prefix1(prefix, fn)
458
+ end
459
+ return new_table
460
+ end
461
+ local P = {
462
+ offset_xy1 = decorator_offset_xy1,
463
+ offset_xy2 = decorator_offset_xy2,
464
+ offset_xyxy1 = decorator_offset_xyxy1,
465
+ prefix3 = decorator_prefix3,
466
+ prefix2 = decorator_prefix2,
467
+ prefix1 = decorator_prefix1,
468
+ prefix1_t = table_prefix1
469
+ }
470
+ return P
471
+ end
472
+ --
473
+ return main_c22()
package/package.json ADDED
@@ -0,0 +1,26 @@
1
+ {
2
+ "name": "@gamely/gly-engine-nano",
3
+ "version": "0.1.5",
4
+ "author": "RodrigoDornelles",
5
+ "license": "Apache-2.0",
6
+ "homepage": "https://docs.gamely.com.br",
7
+ "repository": "https://github.com/gly-engine/gly-engine",
8
+ "funding": "https://github.com/sponsors/RodrigoDornelles",
9
+ "bugs": "https://github.com/gly-engine/gly-engine/issues",
10
+ "description": "Game Engine written in 100% lua that runs in a vacuum.",
11
+ "main": "dist/main.lua",
12
+ "browser": "dist/main.lua",
13
+ "types": "types/main.d.ts",
14
+ "keywords": [
15
+ "game engine",
16
+ "game",
17
+ "engine"
18
+ ],
19
+ "scripts": {
20
+ "step1": "cd ../.. && rm -Rf dist && mkdir -p ./dist/types",
21
+ "step2": "cd ../.. && node cli.js build --core nano --bundler --outdir dist/dist",
22
+ "step3": "cd ../.. && node cli.js meta source/cli/main.lua --infile npm/gly-engine-nano/package.json --outfile dist/package.json",
23
+ "step4": "cd ../.. && echo \"declare module '@gamely/gly-engine-nano' {\n const content: string;\n export default content;\n}\" > dist/types/main.d.ts",
24
+ "build": "npm run step1 && npm run step2 && npm run step3 && npm run step4"
25
+ }
26
+ }
@@ -0,0 +1,4 @@
1
+ declare module '@gamely/gly-engine-nano' {
2
+ const content: string;
3
+ export default content;
4
+ }