@gamely/gly-engine-lite 0.0.18 → 0.0.19

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.
Files changed (2) hide show
  1. package/dist/main.lua +443 -126
  2. package/package.json +2 -2
package/dist/main.lua CHANGED
@@ -1,43 +1,48 @@
1
1
  local math = ((function() local x, y = pcall(require, 'math'); return x and y end)()) or _G.math
2
- local src_version_561fa16ca630 = nil
3
- local src_lib_common_module_561fa16cab70 = nil
4
- local src_lib_engine_api_encoder_561fa16cb2c0 = nil
5
- local src_lib_engine_api_app_561fa16cff00 = nil
6
- local src_lib_engine_api_hash_561fa16d0530 = nil
7
- local src_lib_engine_api_http_561fa16d0b50 = nil
8
- local src_lib_engine_api_i18n_561fa16d10f0 = nil
9
- local src_lib_engine_api_key_561fa16d1700 = nil
10
- local src_lib_engine_api_math_561fa16c5900 = nil
11
- local src_lib_engine_api_array_561fa16c1450 = nil
12
- local src_lib_engine_api_media_561fa16cce10 = nil
13
- local src_lib_engine_draw_fps_561fa16c6900 = nil
14
- local src_lib_engine_draw_text_561fa16c8d50 = nil
15
- local src_lib_engine_draw_poly_561fa16ca270 = nil
16
- local src_lib_engine_raw_memory_561fa16caab0 = nil
17
- local src_lib_object_root_561fa16cb030 = nil
18
- local src_lib_object_color_561fa16d0260 = nil
19
- local src_lib_object_std_561fa16c9dc0 = nil
20
- local src_lib_util_pipeline_561fa16c26b0 = nil
21
- local src_lib_util_decorator_561fa16bfce0 = nil
22
- local function main_561fa16ca3f0()
23
- local version = src_version_561fa16ca630()
24
- local zeebo_module = src_lib_common_module_561fa16cab70()
25
- local engine_encoder = src_lib_engine_api_encoder_561fa16cb2c0()
26
- local engine_game = src_lib_engine_api_app_561fa16cff00()
27
- local engine_hash = src_lib_engine_api_hash_561fa16d0530()
28
- local engine_http = src_lib_engine_api_http_561fa16d0b50()
29
- local engine_i18n = src_lib_engine_api_i18n_561fa16d10f0()
30
- local engine_key = src_lib_engine_api_key_561fa16d1700()
31
- local engine_math = src_lib_engine_api_math_561fa16c5900()
32
- local engine_array = src_lib_engine_api_array_561fa16c1450()
33
- local engine_media = src_lib_engine_api_media_561fa16cce10()
34
- local engine_draw_fps = src_lib_engine_draw_fps_561fa16c6900()
35
- local engine_draw_text = src_lib_engine_draw_text_561fa16c8d50()
36
- local engine_draw_poly = src_lib_engine_draw_poly_561fa16ca270()
37
- local engine_raw_memory = src_lib_engine_raw_memory_561fa16caab0()
38
- local application_default = src_lib_object_root_561fa16cb030()
39
- local color = src_lib_object_color_561fa16d0260()
40
- local std = src_lib_object_std_561fa16c9dc0()
2
+ local src_version_55d740741220 = nil
3
+ local src_lib_common_module_55d74078d4c0 = nil
4
+ local src_lib_engine_api_encoder_55d740797c20 = nil
5
+ local src_lib_engine_api_app_55d7407cdb00 = nil
6
+ local src_lib_engine_api_hash_55d740798450 = nil
7
+ local src_lib_engine_api_http_55d74079e880 = nil
8
+ local src_lib_engine_api_i18n_55d74075aa10 = nil
9
+ local src_lib_engine_api_key_55d7407bfbd0 = nil
10
+ local src_lib_engine_api_log_55d7407a7ec0 = nil
11
+ local src_lib_engine_api_math_55d740799d40 = nil
12
+ local src_lib_engine_api_array_55d740779000 = nil
13
+ local src_lib_engine_api_media_55d7407489d0 = nil
14
+ local src_lib_engine_draw_fps_55d740798890 = nil
15
+ local src_lib_engine_draw_text_55d7407c8b90 = nil
16
+ local src_lib_engine_draw_poly_55d740799b40 = nil
17
+ local src_lib_engine_raw_memory_55d74079abd0 = nil
18
+ local src_lib_protocol_http_callback_55d74079bca0 = nil
19
+ local src_lib_object_root_55d7407b5bb0 = nil
20
+ local src_lib_object_color_55d7407a8380 = nil
21
+ local src_lib_object_std_55d74076e7c0 = nil
22
+ local src_lib_util_pipeline_55d7407bc4c0 = nil
23
+ local src_lib_util_decorator_55d7407a7e30 = nil
24
+ local src_lib_util_http_55d74078aa00 = nil
25
+ local function main_55d7407a19d0()
26
+ local version = src_version_55d740741220()
27
+ local zeebo_module = src_lib_common_module_55d74078d4c0()
28
+ local engine_encoder = src_lib_engine_api_encoder_55d740797c20()
29
+ local engine_game = src_lib_engine_api_app_55d7407cdb00()
30
+ local engine_hash = src_lib_engine_api_hash_55d740798450()
31
+ local engine_http = src_lib_engine_api_http_55d74079e880()
32
+ local engine_i18n = src_lib_engine_api_i18n_55d74075aa10()
33
+ local engine_key = src_lib_engine_api_key_55d7407bfbd0()
34
+ local engine_log = src_lib_engine_api_log_55d7407a7ec0()
35
+ local engine_math = src_lib_engine_api_math_55d740799d40()
36
+ local engine_array = src_lib_engine_api_array_55d740779000()
37
+ local engine_media = src_lib_engine_api_media_55d7407489d0()
38
+ local engine_draw_fps = src_lib_engine_draw_fps_55d740798890()
39
+ local engine_draw_text = src_lib_engine_draw_text_55d7407c8b90()
40
+ local engine_draw_poly = src_lib_engine_draw_poly_55d740799b40()
41
+ local engine_raw_memory = src_lib_engine_raw_memory_55d74079abd0()
42
+ local callback_http = src_lib_protocol_http_callback_55d74079bca0()
43
+ local application_default = src_lib_object_root_55d7407b5bb0()
44
+ local color = src_lib_object_color_55d7407a8380()
45
+ local std = src_lib_object_std_55d74076e7c0()
41
46
  local application = application_default
42
47
  local engine = {
43
48
  keyboard = function(a, b, c, d) end,
@@ -53,6 +58,7 @@ get_secret = native_system_get_secret,
53
58
  get_language = native_system_get_language
54
59
  }
55
60
  local cfg_media = {
61
+ bootstrap=native_media_bootstrap,
56
62
  position=native_media_position,
57
63
  resize=native_media_resize,
58
64
  pause=native_media_pause,
@@ -74,8 +80,18 @@ local cfg_text = {
74
80
  font_previous = native_text_font_previous
75
81
  }
76
82
  local cfg_http = {
77
- ssl = native_http_has_ssl,
78
- handler = native_http_handler
83
+ install = native_http_install,
84
+ handler = native_http_handler,
85
+ has_ssl = native_http_has_ssl,
86
+ has_callback = native_http_has_callback,
87
+ force = native_http_force_protocol
88
+ }
89
+ local cfg_log = {
90
+ fatal = native_log_fatal,
91
+ error = native_log_error,
92
+ warn = native_log_warn,
93
+ info = native_log_info,
94
+ debug = native_log_debug
79
95
  }
80
96
  local cfg_base64 = {
81
97
  decode = native_base64_decode,
@@ -108,6 +124,12 @@ end
108
124
  function native_callback_keyboard(key, value)
109
125
  engine.keyboard(std, engine, key, value)
110
126
  end
127
+ function native_callback_http(id, key, data)
128
+ if cfg_http.has_callback then
129
+ return callback_http.func(engine['http_requests'][id], key, data)
130
+ end
131
+ return nil
132
+ end
111
133
  function native_callback_init(width, height, game_lua)
112
134
  application = zeebo_module.loadgame(game_lua)
113
135
  if application then
@@ -146,6 +168,7 @@ zeebo_module.require(std, application, engine)
146
168
  :package('@draw.text', engine_draw_text, cfg_text)
147
169
  :package('@draw.poly', engine_draw_poly, cfg_poly)
148
170
  :package('@color', color)
171
+ :package('@log', engine_log, cfg_log)
149
172
  :package('math', engine_math.clib)
150
173
  :package('math.random', engine_math.clib_random)
151
174
  :package('http', engine_http, cfg_http)
@@ -154,7 +177,10 @@ zeebo_module.require(std, application, engine)
154
177
  :package('xml', engine_encoder, cfg_xml)
155
178
  :package('i18n', engine_i18n, cfg_system)
156
179
  :package('hash', engine_hash, cfg_system)
157
- :package('media', engine_media, cfg_media)
180
+ :package('media.video', engine_media, cfg_media)
181
+ :package('media.audio', engine_media, cfg_media)
182
+ :package('mock.video', engine_media)
183
+ :package('mock.audio', engine_media)
158
184
  :run()
159
185
  application.data.width, std.app.width = width, width
160
186
  application.data.height, std.app.height = height, height
@@ -172,13 +198,13 @@ version=version
172
198
  }
173
199
  return P
174
200
  end
175
- src_version_561fa16ca630 = function()
176
- return '0.0.18'
201
+ src_version_55d740741220 = function()
202
+ return '0.0.19'
177
203
  end
178
204
  --
179
- src_lib_common_module_561fa16cab70 = function()
180
- local zeebo_pipeline = src_lib_util_pipeline_561fa16c26b0()
181
- local application_default = src_lib_object_root_561fa16cb030()
205
+ src_lib_common_module_55d74078d4c0 = function()
206
+ local zeebo_pipeline = src_lib_util_pipeline_55d7407bc4c0()
207
+ local application_default = src_lib_object_root_55d7407b5bb0()
182
208
  local function default(application, defaults)
183
209
  if not application then return nil end
184
210
  local index = 1
@@ -376,7 +402,7 @@ require = require
376
402
  return P
377
403
  end
378
404
  --
379
- src_lib_engine_api_encoder_561fa16cb2c0 = function()
405
+ src_lib_engine_api_encoder_55d740797c20 = function()
380
406
  local function install(std, engine, library, name)
381
407
  std = std or {}
382
408
  std[name] = {
@@ -391,8 +417,8 @@ install=install
391
417
  return P
392
418
  end
393
419
  --
394
- src_lib_engine_api_app_561fa16cff00 = function()
395
- local util_decorator = src_lib_util_decorator_561fa16bfce0()
420
+ src_lib_engine_api_app_55d7407cdb00 = function()
421
+ local util_decorator = src_lib_util_decorator_55d7407a7e30()
396
422
  local function reset(std, engine)
397
423
  if std.node then
398
424
  std.bus.emit('exit')
@@ -432,7 +458,7 @@ install=install
432
458
  return P
433
459
  end
434
460
  --
435
- src_lib_engine_api_hash_561fa16d0530 = function()
461
+ src_lib_engine_api_hash_55d740798450 = function()
436
462
  local function djb2(digest)
437
463
  local index = 1
438
464
  local hash = 5381
@@ -458,8 +484,8 @@ install = install
458
484
  return P
459
485
  end
460
486
  --
461
- src_lib_engine_api_http_561fa16d0b50 = function()
462
- local zeebo_pipeline = src_lib_util_pipeline_561fa16c26b0()
487
+ src_lib_engine_api_http_55d74079e880 = function()
488
+ local zeebo_pipeline = src_lib_util_pipeline_55d7407bc4c0()
463
489
  local function fast(self)
464
490
  self.speed = '_fast'
465
491
  return self
@@ -492,13 +518,24 @@ local function http_error(self, handler_func)
492
518
  self.error_handler = handler_func
493
519
  return self
494
520
  end
495
- local function request(method, std, engine, protocol_handler)
521
+ local function request(method, std, engine, protocol)
496
522
  local callback_handler = function()
523
+ if std.node then
497
524
  std.node.emit(engine.current, 'http')
525
+ elseif engine.current.callbacks.http then
526
+ engine.current.callbacks.http(std, engine.current.data)
527
+ end
498
528
  end
499
529
  return function (url)
530
+ if protocol.has_callback then
531
+ engine.http_count = engine.http_count + 1
532
+ end
533
+ if protocol.force then
534
+ url = url:gsub("^[^:]+://", protocol.force.."://")
535
+ end
500
536
  local game = engine.current.data
501
537
  local self = {
538
+ id = engine.http_count,
502
539
  url = url,
503
540
  speed = '',
504
541
  method = method,
@@ -507,12 +544,9 @@ header_list = {},
507
544
  header_dict = {},
508
545
  param_list = {},
509
546
  param_dict = {},
510
- callback_handler = callback_handler,
511
547
  success_handler = function (std, game) end,
512
548
  failed_handler = function (std, game) end,
513
549
  error_handler = function (std, game) end,
514
- std = std,
515
- game = game,
516
550
  fast = fast,
517
551
  body = body,
518
552
  param = param,
@@ -521,7 +555,6 @@ success = success,
521
555
  failed = failed,
522
556
  error = http_error,
523
557
  run = zeebo_pipeline.run,
524
- protocol_handler = protocol_handler
525
558
  }
526
559
  self.promise = function()
527
560
  zeebo_pipeline.stop(self)
@@ -530,29 +563,31 @@ self.resolve = function()
530
563
  zeebo_pipeline.resume(self)
531
564
  end
532
565
  self.set = function (key, value)
533
- self.std.http[key] = value
566
+ std.http[key] = value
534
567
  end
535
568
  self.pipeline = {
536
569
  function()
537
- self:protocol_handler()
570
+ if protocol.has_callback then engine.http_requests[self.id] = self end
571
+ protocol.handler(self, self.id)
538
572
  end,
539
573
  function()
540
- self.callback_handler(self.std, self.game)
541
- if self.std.http.ok then
542
- self.success_handler(self.std, self.game)
543
- elseif self.std.http.error or not self.std.http.status then
544
- self.error_handler(self.std, self.game)
574
+ callback_handler(std, game)
575
+ if std.http.ok then
576
+ self.success_handler(std, game)
577
+ elseif std.http.error or not std.http.status then
578
+ self.error_handler(std, game)
545
579
  else
546
- self.failed_handler(self.std, self.game)
580
+ self.failed_handler(std, game)
547
581
  end
548
582
  end,
549
583
  function ()
550
- self.std.http.ok = nil
551
- self.std.http.body = nil
552
- self.std.http.error = nil
553
- self.std.http.status = nil
584
+ std.http.ok = nil
585
+ std.http.body = nil
586
+ std.http.error = nil
587
+ std.http.status = nil
554
588
  end,
555
589
  function()
590
+ if protocol.has_callback then engine.http_requests[self.id] = nil end
556
591
  zeebo_pipeline.reset(self)
557
592
  end
558
593
  }
@@ -560,23 +595,21 @@ return self
560
595
  end
561
596
  end
562
597
  local function install(std, engine, protocol)
563
- local protocol_handler = protocol and protocol.handler
564
- if not protocol_handler then
565
- error('missing protocol handler')
598
+ assert(protocol.handler, 'missing protocol handler')
599
+ if protocol.has_callback then
600
+ engine.http_count = 0
601
+ engine.http_requests = {}
566
602
  end
567
603
  std.http = std.http or {}
568
- std.http.get=request('GET', std, engine, protocol_handler)
569
- std.http.head=request('HEAD', std, engine, protocol_handler)
570
- std.http.post=request('POST', std, engine, protocol_handler)
571
- std.http.put=request('PUT', std, engine, protocol_handler)
572
- std.http.delete=request('DELETE', std, engine, protocol_handler)
573
- std.http.patch=request('PATCH', std, engine, protocol_handler)
604
+ std.http.get=request('GET', std, engine, protocol)
605
+ std.http.head=request('HEAD', std, engine, protocol)
606
+ std.http.post=request('POST', std, engine, protocol)
607
+ std.http.put=request('PUT', std, engine, protocol)
608
+ std.http.delete=request('DELETE', std, engine, protocol)
609
+ std.http.patch=request('PATCH', std, engine, protocol)
574
610
  if protocol.install then
575
611
  protocol.install(std, engine)
576
612
  end
577
- return {
578
- std={http=std.http}
579
- }
580
613
  end
581
614
  local P = {
582
615
  install=install
@@ -584,7 +617,7 @@ install=install
584
617
  return P
585
618
  end
586
619
  --
587
- src_lib_engine_api_i18n_561fa16d10f0 = function()
620
+ src_lib_engine_api_i18n_55d74075aa10 = function()
588
621
  local language = 'en-US'
589
622
  local language_default = 'en-US'
590
623
  local language_list = {}
@@ -676,7 +709,7 @@ install=install
676
709
  return P
677
710
  end
678
711
  --
679
- src_lib_engine_api_key_561fa16d1700 = function()
712
+ src_lib_engine_api_key_55d7407bfbd0 = function()
680
713
  local function real_key(std, engine, rkey, rvalue)
681
714
  local value = rvalue == 1 or rvalue == true
682
715
  local key = engine.key_bindings[rkey] or (std.key.axis[rkey] and rkey)
@@ -691,6 +724,8 @@ std.key.axis.y = std.key.axis.down - std.key.axis.up
691
724
  end
692
725
  std.bus.emit('key')
693
726
  end
727
+ local a = std.key.axis
728
+ std.key.press.any = (a.left + a.right + a.down + a.up + a.a + a.b + a.c + a.d + a.menu) > 0
694
729
  end
695
730
  local function real_keydown(std, engine, key)
696
731
  real_key(std, engine, key, 1)
@@ -714,7 +749,54 @@ install = install
714
749
  return P
715
750
  end
716
751
  --
717
- src_lib_engine_api_math_561fa16c5900 = function()
752
+ src_lib_engine_api_log_55d7407a7ec0 = function()
753
+ local util_decorator = src_lib_util_decorator_55d7407a7e30()
754
+ local logging_types = {
755
+ 'none', 'fatal', 'error', 'warn', 'debug', 'info'
756
+ }
757
+ local function level(engine, lpf, lpn, level)
758
+ local l = lpf[level] or lpn[level] or level
759
+ if type(l) ~= 'number' or l <= 0 or l > #logging_types then
760
+ error('logging level not exist: '..tostring(level))
761
+ end
762
+ engine.loglevel = l
763
+ end
764
+ local function init(std, engine, printers)
765
+ local index = 1
766
+ local level_per_func = {}
767
+ local level_per_name = {}
768
+ while index <= #logging_types do
769
+ local ltype = logging_types[index]
770
+ local lfunc = function() end
771
+ if index > 1 and printers[ltype] then
772
+ lfunc = (function (level)
773
+ return function(message)
774
+ if engine.loglevel >= level then
775
+ printers[ltype](message)
776
+ end
777
+ end
778
+ end)(index - 1)
779
+ end
780
+ level_per_func[lfunc] = index - 1
781
+ level_per_name[ltype] = index - 1
782
+ std.log[ltype] = lfunc
783
+ index = index + 1
784
+ end
785
+ std.log.level = util_decorator.prefix3(engine, level_per_func, level_per_name, level)
786
+ end
787
+ local function install(std, engine, printers)
788
+ std.log = std.log or {}
789
+ engine.loglevel = #logging_types
790
+ std.log.init = util_decorator.prefix2(std, engine, init)
791
+ std.log.init(printers)
792
+ end
793
+ local P = {
794
+ install = install
795
+ }
796
+ return P
797
+ end
798
+ --
799
+ src_lib_engine_api_math_55d740799d40 = function()
718
800
  local function abs(value)
719
801
  if value < 0 then
720
802
  return -value
@@ -861,8 +943,8 @@ install = install_clib_random
861
943
  return P;
862
944
  end
863
945
  --
864
- src_lib_engine_api_array_561fa16c1450 = function()
865
- local util_decorator = src_lib_util_decorator_561fa16bfce0()
946
+ src_lib_engine_api_array_55d740779000 = function()
947
+ local util_decorator = src_lib_util_decorator_55d7407a7e30()
866
948
  local function array_map(array, func)
867
949
  local res = {}
868
950
  local index = 1
@@ -1004,6 +1086,7 @@ return self
1004
1086
  end
1005
1087
  local function install(std, engine, library, name)
1006
1088
  local lib = std[name] or {}
1089
+ lib.map = array_map
1007
1090
  lib.filter = array_filter
1008
1091
  lib.unique = array_unique
1009
1092
  lib.each = array_foreach
@@ -1022,43 +1105,43 @@ install = install
1022
1105
  return P
1023
1106
  end
1024
1107
  --
1025
- src_lib_engine_api_media_561fa16cce10 = function()
1026
- local util_decorator = src_lib_util_decorator_561fa16bfce0()
1027
- local function media_add(func, self, src)
1028
- func(self.id - 1, src)
1108
+ src_lib_engine_api_media_55d7407489d0 = function()
1109
+ local util_decorator = src_lib_util_decorator_55d7407a7e30()
1110
+ local function media_add(media, func, self, src)
1111
+ func(media - 1, self.id - 1, src)
1029
1112
  return self
1030
1113
  end
1031
- local function media_play(func, self)
1032
- func(self.id - 1)
1114
+ local function media_play(media, func, self)
1115
+ func(media - 1, self.id - 1)
1033
1116
  return self
1034
1117
  end
1035
- local function media_pause(func, self)
1036
- func(self.id - 1)
1118
+ local function media_pause(media, func, self)
1119
+ func(media - 1, self.id - 1)
1037
1120
  return self
1038
1121
  end
1039
- local function media_resize(func, self, width, height)
1040
- func(self.id - 1, width, height)
1122
+ local function media_resize(media, func, self, width, height)
1123
+ func(media - 1, self.id - 1, width, height)
1041
1124
  return self
1042
1125
  end
1043
- local function media_position(func, self, pos_x, pos_y)
1044
- func(self.id - 1, pos_x, pos_y)
1126
+ local function media_position(media, func, self, pos_x, pos_y)
1127
+ func(media - 1, self.id - 1, pos_x, pos_y)
1045
1128
  return self
1046
1129
  end
1047
- local channels = {}
1048
- local function media_channel(std, handler)
1130
+ local function media_channel(std, handler, mediatype, mediaid, max_channels)
1049
1131
  return function(id)
1132
+ local channels = std.media.channels[mediaid]
1050
1133
  id = id or 1
1051
- if 0 >= id or id > 8 then
1134
+ if 0 >= id or id > max_channels then
1052
1135
  error('Please, do not do that!')
1053
1136
  end
1054
1137
  if not channels[id] then
1055
1138
  channels[id] = {
1056
1139
  id = id,
1057
- add = util_decorator.prefix1(handler.load, media_add),
1058
- play = util_decorator.prefix1(handler.play, media_play),
1059
- pause = util_decorator.prefix1(handler.pause, media_pause),
1060
- resize = util_decorator.prefix1(handler.resize, media_resize),
1061
- position = util_decorator.prefix1(handler.position, media_position)
1140
+ add = util_decorator.prefix2(mediaid, handler.load, media_add),
1141
+ play = util_decorator.prefix2(mediaid, handler.play, media_play),
1142
+ pause = util_decorator.prefix2(mediaid, handler.pause, media_pause),
1143
+ resize = util_decorator.prefix2(mediaid, handler.resize, media_resize),
1144
+ position = util_decorator.prefix2(mediaid, handler.position, media_position)
1062
1145
  }
1063
1146
  if std.node then
1064
1147
  channels[id].node = std.node.load({})
@@ -1081,9 +1164,19 @@ end
1081
1164
  return channels[id]
1082
1165
  end
1083
1166
  end
1084
- local function install(std, engine, handlers)
1167
+ local function install(std, engine, handlers, name)
1168
+ handlers = handlers or {}
1085
1169
  std.media = std.media or {}
1086
- std.media.video = media_channel(std, handlers)
1170
+ std.media.types = std.media.types or {}
1171
+ std.media.channels = std.media.channels or {}
1172
+ local mediatype = name:match('%w+%.(%w+)')
1173
+ local mediaid = #std.media.types + 1
1174
+ if not std.media[mediatype] then
1175
+ local max_channels = handlers.bootstrap and handlers.bootstrap(mediaid - 1, mediatype) or 8
1176
+ std.media.channels[mediaid] = {}
1177
+ std.media.types[mediaid] = mediatype
1178
+ std.media[mediatype] = media_channel(std, handlers, mediatype, mediaid, max_channels)
1179
+ end
1087
1180
  end
1088
1181
  local P = {
1089
1182
  install=install
@@ -1091,7 +1184,7 @@ install=install
1091
1184
  return P
1092
1185
  end
1093
1186
  --
1094
- src_lib_engine_draw_fps_561fa16c6900 = function()
1187
+ src_lib_engine_draw_fps_55d740798890 = function()
1095
1188
  local function draw_fps(std, engine, show, pos_x, pos_y)
1096
1189
  if show < 1 then return end
1097
1190
  local x = engine.current.config.offset_x + pos_x
@@ -1143,8 +1236,8 @@ install=install
1143
1236
  return P
1144
1237
  end
1145
1238
  --
1146
- src_lib_engine_draw_text_561fa16c8d50 = function()
1147
- local util_decorator = src_lib_util_decorator_561fa16bfce0()
1239
+ src_lib_engine_draw_text_55d7407c8b90 = function()
1240
+ local util_decorator = src_lib_util_decorator_55d7407a7e30()
1148
1241
  local function text_put(std, engine, font_previous, pos_x, pos_y, text, size)
1149
1242
  size = size or 2
1150
1243
  local hem = engine.current.data.width / 80
@@ -1171,7 +1264,7 @@ install=install
1171
1264
  return P
1172
1265
  end
1173
1266
  --
1174
- src_lib_engine_draw_poly_561fa16ca270 = function()
1267
+ src_lib_engine_draw_poly_55d740799b40 = function()
1175
1268
  local function decorator_poo(object, func)
1176
1269
  if not object or not func then return func end
1177
1270
  return function(a, b, c, d)
@@ -1278,21 +1371,25 @@ install=install
1278
1371
  return P
1279
1372
  end
1280
1373
  --
1281
- src_lib_engine_raw_memory_561fa16caab0 = function()
1374
+ src_lib_engine_raw_memory_55d74079abd0 = function()
1282
1375
  local memory_dict_unload = {}
1283
1376
  local memory_dict = {}
1284
1377
  local memory_list = {}
1285
- local function cache(key, load_func, unload_func)
1286
- if memory_dict[key] then
1378
+ local function cache_get(key)
1287
1379
  return memory_dict[key]
1288
1380
  end
1289
- if not load_func then
1290
- return nil
1291
- end
1381
+ local function cache_set(key, load_func, unload_func)
1292
1382
  local value = load_func()
1293
1383
  memory_list[#memory_list + 1] = key
1294
1384
  memory_dict_unload[key] = unload_func
1295
1385
  memory_dict[key] = value
1386
+ end
1387
+ local function cache(key, load_func, unload_func)
1388
+ local value = cache_get(key)
1389
+ if value == nil then
1390
+ cache_set(key, load_func, unload_func)
1391
+ value = cache_get(key)
1392
+ end
1296
1393
  return value
1297
1394
  end
1298
1395
  local function unset(key)
@@ -1315,6 +1412,8 @@ local function install(std)
1315
1412
  std = std or {}
1316
1413
  std.mem = std.mem or {}
1317
1414
  std.mem.cache = cache
1415
+ std.mem.cache_get = cache_get
1416
+ std.mem.cache_set = cache_set
1318
1417
  std.mem.unset = unset
1319
1418
  std.mem.gc_clear_all = gc_clear_all
1320
1419
  return {
@@ -1327,7 +1426,75 @@ install=install
1327
1426
  return P
1328
1427
  end
1329
1428
  --
1330
- src_lib_object_root_561fa16cb030 = function()
1429
+ src_lib_protocol_http_callback_55d74079bca0 = function()
1430
+ local http_util = src_lib_util_http_55d74078aa00()
1431
+ local callbacks = {
1432
+ ['async-promise'] = function(self)
1433
+ return self:promise()
1434
+ end,
1435
+ ['async-resolve'] = function(self)
1436
+ return self:resolve()
1437
+ end,
1438
+ ['get-url'] = function(self)
1439
+ return self.url
1440
+ end,
1441
+ ['get-fullurl'] = function(self)
1442
+ return self.url..http_util.url_search_param(self.param_list, self.param_dict)
1443
+ end,
1444
+ ['get-method'] = function(self)
1445
+ return self.method
1446
+ end,
1447
+ ['get-body'] = function(self)
1448
+ return self.body_content
1449
+ end,
1450
+ ['get-param-count'] = function(self)
1451
+ return #self.param_list
1452
+ end,
1453
+ ['get-param-name'] = function(self, data)
1454
+ return self.param_list[self.data]
1455
+ end,
1456
+ ['get-param-data'] = function(self, data)
1457
+ return self.param_dict[self.data] or self.param_dict[self.param_list[self.data]]
1458
+ end,
1459
+ ['get-header-count'] = function(self)
1460
+ return #self.header_list
1461
+ end,
1462
+ ['get-header-name'] = function(self, data)
1463
+ return self.header_list[self.data]
1464
+ end,
1465
+ ['get-header-data'] = function(self, data)
1466
+ return self.heeader_dict[self.data] or self.heeader_dict[self.header_list[self.data]]
1467
+ end,
1468
+ ['set-status'] = function(self, data)
1469
+ self.set('status', data)
1470
+ self.set('ok', http_util.is_ok(data))
1471
+ end,
1472
+ ['set-error'] = function(self, data)
1473
+ self.set('error', data)
1474
+ end,
1475
+ ['set-ok'] = function(self, data)
1476
+ self.set('ok', data)
1477
+ end,
1478
+ ['set-body'] = function(self, data)
1479
+ self.set('body', data)
1480
+ end,
1481
+ ['add-body-data'] = function(self, data, std)
1482
+ self.set('body', (std.http.body or '')..data)
1483
+ end
1484
+ }
1485
+ local function native_http_callback(self, evt, data, std)
1486
+ if not callbacks[evt] then
1487
+ error('http evt '..evt..' not exist!')
1488
+ end
1489
+ return callbacks[evt](self, data, std)
1490
+ end
1491
+ local P = {
1492
+ func = native_http_callback
1493
+ }
1494
+ return P
1495
+ end
1496
+ --
1497
+ src_lib_object_root_55d7407b5bb0 = function()
1331
1498
  local P = {
1332
1499
  data={
1333
1500
  width=1280,
@@ -1357,7 +1524,7 @@ callbacks={
1357
1524
  return P;
1358
1525
  end
1359
1526
  --
1360
- src_lib_object_color_561fa16d0260 = function()
1527
+ src_lib_object_color_55d7407a8380 = function()
1361
1528
  local white = 0xFFFFFFFF
1362
1529
  local lightgray = 0xC8CCCCFF
1363
1530
  local gray = 0x828282FF
@@ -1419,7 +1586,7 @@ install = install
1419
1586
  return P
1420
1587
  end
1421
1588
  --
1422
- src_lib_object_std_561fa16c9dc0 = function()
1589
+ src_lib_object_std_55d74076e7c0 = function()
1423
1590
  local P = {
1424
1591
  milis = 0,
1425
1592
  delta = 0,
@@ -1473,14 +1640,15 @@ right=false,
1473
1640
  a=false,
1474
1641
  b=false,
1475
1642
  c=false,
1476
- d=false
1643
+ d=false,
1644
+ any=false
1477
1645
  }
1478
1646
  }
1479
1647
  }
1480
1648
  return P;
1481
1649
  end
1482
1650
  --
1483
- src_lib_util_pipeline_561fa16c26b0 = function()
1651
+ src_lib_util_pipeline_55d7407bc4c0 = function()
1484
1652
  local function pipe(self)
1485
1653
  return function()
1486
1654
  self:run()
@@ -1530,7 +1698,7 @@ run=run
1530
1698
  return P
1531
1699
  end
1532
1700
  --
1533
- src_lib_util_decorator_561fa16bfce0 = function()
1701
+ src_lib_util_decorator_55d7407a7e30 = function()
1534
1702
  local function decorator_prefix3(zig, zag, zom, func)
1535
1703
  return function (a, b, c, d, e, f)
1536
1704
  return func(zig, zag, zom, a, b, c, d, e, f)
@@ -1580,4 +1748,153 @@ prefix1 = decorator_prefix1
1580
1748
  return P
1581
1749
  end
1582
1750
  --
1583
- return main_561fa16ca3f0()
1751
+ src_lib_util_http_55d74078aa00 = function()
1752
+ local function is_ok(status)
1753
+ return (status and 200 <= status and status < 300) or false
1754
+ end
1755
+ local function is_ok_header(header)
1756
+ local status = tonumber(header:match('HTTP/%d.%d (%d%d%d)'))
1757
+ local ok = status and is_ok(status) or false
1758
+ return ok, status
1759
+ end
1760
+ local function is_redirect(status)
1761
+ return (status and 300 <= status and status < 400) or false
1762
+ end
1763
+ local function url_search_param(param_list, param_dict)
1764
+ local index, params = 1, ''
1765
+ while param_list and param_dict and index <= #param_list do
1766
+ local param = param_list[index]
1767
+ local value = param_dict[param]
1768
+ if #params == 0 then
1769
+ params = params..'?'
1770
+ else
1771
+ params = params..'&'
1772
+ end
1773
+ params = params..param..'='..(value or '')
1774
+ index = index + 1
1775
+ end
1776
+ return params
1777
+ end
1778
+ local function create_request(method, uri)
1779
+ local self = {
1780
+ body_content = '',
1781
+ header_list = {},
1782
+ header_dict = {},
1783
+ header_imutable = {},
1784
+ print_http_status = true
1785
+ }
1786
+ self.add_body_content = function (body)
1787
+ self.body_content = self.body_content..(body or '')
1788
+ return self
1789
+ end
1790
+ self.add_imutable_header = function (header, value, cond)
1791
+ if cond == false then return self end
1792
+ if self.header_imutable[header] == nil then
1793
+ self.header_list[#self.header_list + 1] = header
1794
+ self.header_dict[header] = value
1795
+ elseif self.header_imutable[header] == false then
1796
+ self.header_dict[header] = value
1797
+ end
1798
+ self.header_imutable[header] = true
1799
+ return self
1800
+ end
1801
+ self.add_mutable_header = function (header, value, cond)
1802
+ if cond == false then return self end
1803
+ if self.header_imutable[header] == nil then
1804
+ self.header_list[#self.header_list + 1] = header
1805
+ self.header_imutable[header] = false
1806
+ self.header_dict[header] = value
1807
+ end
1808
+ return self
1809
+ end
1810
+ self.add_custom_headers = function(header_list, header_dict)
1811
+ local index = 1
1812
+ while header_list and #header_list >= index do
1813
+ local header = header_list[index]
1814
+ local value = header_dict[header]
1815
+ if self.header_imutable[header] == nil then
1816
+ self.header_list[#self.header_list + 1] = header
1817
+ self.header_imutable[header] = false
1818
+ self.header_dict[header] = value
1819
+ elseif self.header_imutable[header] == false then
1820
+ self.header_dict[header] = value
1821
+ end
1822
+ index = index + 1
1823
+ end
1824
+ return self
1825
+ end
1826
+ self.not_status = function()
1827
+ self.print_http_status = false
1828
+ return self
1829
+ end
1830
+ self.to_http_protocol = function ()
1831
+ local index = 1
1832
+ local request = method..' '..uri..' HTTP/1.1\r\n'
1833
+ while index <= #self.header_list do
1834
+ local header = self.header_list[index]
1835
+ local value = self.header_dict[header]
1836
+ request = request..header..': '..value..'\r\n'
1837
+ index = index + 1
1838
+ end
1839
+ request = request..'\r\n'
1840
+ if method ~= 'GET' and method ~= 'HEAD' and #self.body_content > 0 then
1841
+ request = request..self.body_content..'\r\n\r\n'
1842
+ end
1843
+ return request, function() end
1844
+ end
1845
+ self.to_curl_cmd = function ()
1846
+ local index = 1
1847
+ local request = 'curl -L -'..'-silent -'..'-insecure '
1848
+ if self.print_http_status then
1849
+ request = request..'-w "\n%{http_code}" '
1850
+ end
1851
+ if method == 'HEAD' then
1852
+ request = request..'-'..'-HEAD '
1853
+ else
1854
+ request = request..'-X '..method..' '
1855
+ end
1856
+ while index <= #self.header_list do
1857
+ local header = self.header_list[index]
1858
+ local value = self.header_dict[header]
1859
+ request = request..'-H "'..header..': '..value..'" '
1860
+ index = index + 1
1861
+ end
1862
+ if method ~= 'GET' and method ~= 'HEAD' and #self.body_content > 0 then
1863
+ request = request..'-d \''..self.body_content..'\' '
1864
+ end
1865
+ request = request..uri
1866
+ return request, function() end
1867
+ end
1868
+ self.to_wget_cmd = function ()
1869
+ local request = 'wget -'..'-quiet -'..'-output-document=-'
1870
+ if method == 'HEAD' then
1871
+ request = request..' -'..'-method=HEAD'
1872
+ elseif method ~= 'GET' then
1873
+ request = request..' -'..'-method='..method
1874
+ end
1875
+ for index, header in ipairs(self.header_list) do
1876
+ local value = self.header_dict[header]
1877
+ if value then
1878
+ local escaped_value = value:gsub('"', '\\"')
1879
+ request = request..' -'..'-header="'..header..': '..escaped_value..'"'
1880
+ end
1881
+ end
1882
+ if method ~= 'GET' and method ~= 'HEAD' and #self.body_content > 0 then
1883
+ local escaped_body = self.body_content:gsub('"', '\\"')
1884
+ request = request..' -'..'-body-data="'..escaped_body..'"'
1885
+ end
1886
+ request = request..' '..uri
1887
+ return request, function() end
1888
+ end
1889
+ return self
1890
+ end
1891
+ return {
1892
+ is_ok=is_ok,
1893
+ is_ok_header=is_ok_header,
1894
+ is_redirect=is_redirect,
1895
+ url_search_param=url_search_param,
1896
+ create_request=create_request
1897
+ }
1898
+ end
1899
+ --
1900
+ return main_55d7407a19d0()
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@gamely/gly-engine-lite",
3
- "version": "0.0.18",
3
+ "version": "0.0.19",
4
4
  "author": "RodrigoDornelles",
5
5
  "license": "Apache-2.0",
6
6
  "homepage": "https://docs.gamely.com.br",
@@ -8,7 +8,7 @@
8
8
  "funding": "https://github.com/sponsors/RodrigoDornelles",
9
9
  "bugs": "https://github.com/gamelly/gly-engine/issues",
10
10
  "description": "Game Engine written in 100% lua that runs in a vacuum.",
11
- "main": "dist/index.lua",
11
+ "main": "dist/main.lua",
12
12
  "keywords": [
13
13
  "game engine",
14
14
  "game",