@gamely/gly-engine-lite 0.0.14
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 +1332 -0
- package/package.json +17 -0
package/README.md
ADDED
package/dist/main.lua
ADDED
|
@@ -0,0 +1,1332 @@
|
|
|
1
|
+
local math = ((function() local x, y = pcall(require, 'math'); return x and y end)()) or _G.math
|
|
2
|
+
local core_src_version = nil
|
|
3
|
+
local core_src_lib_common_module = nil
|
|
4
|
+
local core_src_lib_engine_api_encoder = nil
|
|
5
|
+
local core_src_lib_engine_api_app = nil
|
|
6
|
+
local core_src_lib_engine_api_hash = nil
|
|
7
|
+
local core_src_lib_engine_api_http = nil
|
|
8
|
+
local core_src_lib_engine_api_i18n = nil
|
|
9
|
+
local core_src_lib_engine_api_key = nil
|
|
10
|
+
local core_src_lib_engine_api_math = nil
|
|
11
|
+
local core_src_lib_engine_draw_fps = nil
|
|
12
|
+
local core_src_lib_engine_draw_text = nil
|
|
13
|
+
local core_src_lib_engine_draw_poly = nil
|
|
14
|
+
local core_src_lib_engine_raw_memory = nil
|
|
15
|
+
local core_src_lib_object_root = nil
|
|
16
|
+
local core_src_lib_object_color = nil
|
|
17
|
+
local core_src_lib_object_std = nil
|
|
18
|
+
local core_src_lib_util_pipeline = nil
|
|
19
|
+
local core_src_lib_util_decorator = nil
|
|
20
|
+
local function main()
|
|
21
|
+
local version = core_src_version()
|
|
22
|
+
local zeebo_module = core_src_lib_common_module()
|
|
23
|
+
local engine_encoder = core_src_lib_engine_api_encoder()
|
|
24
|
+
local engine_game = core_src_lib_engine_api_app()
|
|
25
|
+
local engine_hash = core_src_lib_engine_api_hash()
|
|
26
|
+
local engine_http = core_src_lib_engine_api_http()
|
|
27
|
+
local engine_i18n = core_src_lib_engine_api_i18n()
|
|
28
|
+
local engine_key = core_src_lib_engine_api_key()
|
|
29
|
+
local engine_math = core_src_lib_engine_api_math()
|
|
30
|
+
local engine_draw_fps = core_src_lib_engine_draw_fps()
|
|
31
|
+
local engine_draw_text = core_src_lib_engine_draw_text()
|
|
32
|
+
local engine_draw_poly = core_src_lib_engine_draw_poly()
|
|
33
|
+
local engine_raw_memory = core_src_lib_engine_raw_memory()
|
|
34
|
+
local application_default = core_src_lib_object_root()
|
|
35
|
+
local color = core_src_lib_object_color()
|
|
36
|
+
local std = core_src_lib_object_std()
|
|
37
|
+
local application = application_default
|
|
38
|
+
local engine = {
|
|
39
|
+
keyboard = function(a, b, c, d) end,
|
|
40
|
+
current = application_default,
|
|
41
|
+
root = application_default
|
|
42
|
+
}
|
|
43
|
+
local cfg_text = {
|
|
44
|
+
font_previous = native_text_font_previous
|
|
45
|
+
}
|
|
46
|
+
function native_callback_loop(dt)
|
|
47
|
+
std.milis = std.milis + dt
|
|
48
|
+
std.delta = dt
|
|
49
|
+
application.callbacks.loop(std, application.data)
|
|
50
|
+
end
|
|
51
|
+
function native_callback_draw()
|
|
52
|
+
native_draw_start()
|
|
53
|
+
application.callbacks.draw(std, application.data)
|
|
54
|
+
native_draw_flush()
|
|
55
|
+
end
|
|
56
|
+
function native_callback_resize(width, height)
|
|
57
|
+
application.data.width = width
|
|
58
|
+
application.data.height = height
|
|
59
|
+
std.app.width = width
|
|
60
|
+
std.app.height = height
|
|
61
|
+
end
|
|
62
|
+
function native_callback_keyboard(key, value)
|
|
63
|
+
engine.keyboard(std, engine, key, value)
|
|
64
|
+
end
|
|
65
|
+
function native_callback_init(width, height, game_lua)
|
|
66
|
+
application = zeebo_module.loadgame(game_lua)
|
|
67
|
+
if application then
|
|
68
|
+
application.data.width = width
|
|
69
|
+
application.data.height = height
|
|
70
|
+
std.app.width = width
|
|
71
|
+
std.app.height = height
|
|
72
|
+
end
|
|
73
|
+
std.bus = {
|
|
74
|
+
emit=function() end,
|
|
75
|
+
emit_next=function() end,
|
|
76
|
+
listen=function() end,
|
|
77
|
+
listen_std_engine=function() end
|
|
78
|
+
}
|
|
79
|
+
std.draw.color=native_draw_color
|
|
80
|
+
std.draw.font=native_draw_font
|
|
81
|
+
std.draw.rect=native_draw_rect
|
|
82
|
+
std.draw.line=native_draw_line
|
|
83
|
+
std.draw.image=native_draw_image
|
|
84
|
+
std.text.print=native_text_print
|
|
85
|
+
std.text.mensure=native_text_mensure
|
|
86
|
+
std.text.font_size=native_text_font_size
|
|
87
|
+
std.text.font_name=native_text_font_name
|
|
88
|
+
std.text.font_default=native_text_font_default
|
|
89
|
+
std.draw.clear=function(tint)
|
|
90
|
+
native_draw_clear(tint, 0, 0, application.data.width, application.data.height)
|
|
91
|
+
end
|
|
92
|
+
zeebo_module.require(std, application, engine)
|
|
93
|
+
:package('@memory', engine_raw_memory)
|
|
94
|
+
:package('@game', engine_game, native_dict_game)
|
|
95
|
+
:package('@math', engine_math)
|
|
96
|
+
:package('@key', engine_key, {})
|
|
97
|
+
:package('@draw.fps', engine_draw_fps)
|
|
98
|
+
:package('@draw.fps', engine_draw_text, cfg_text)
|
|
99
|
+
:package('@draw.poly', engine_draw_poly, native_dict_poly)
|
|
100
|
+
:package('@color', color)
|
|
101
|
+
:package('math', engine_math.clib)
|
|
102
|
+
:package('math.random', engine_math.clib_random)
|
|
103
|
+
:package('http', engine_http, native_dict_http)
|
|
104
|
+
:package('json', engine_encoder, native_dict_json)
|
|
105
|
+
:package('xml', engine_encoder, native_dict_xml)
|
|
106
|
+
:package('i18n', engine_i18n, native_get_system_lang)
|
|
107
|
+
:package('hash', engine_hash, native_dict_secret)
|
|
108
|
+
:run()
|
|
109
|
+
application.data.width, std.app.width = width, width
|
|
110
|
+
application.data.height, std.app.height = height, height
|
|
111
|
+
std.app.title(application.meta.title..' - '..application.meta.version)
|
|
112
|
+
engine.root = application
|
|
113
|
+
engine.current = application
|
|
114
|
+
application.callbacks.init(std, application.data)
|
|
115
|
+
end
|
|
116
|
+
local P = {
|
|
117
|
+
meta={
|
|
118
|
+
title='gly-engine-lite',
|
|
119
|
+
author='RodrigoDornelles',
|
|
120
|
+
description='native lite',
|
|
121
|
+
version=version
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return P
|
|
125
|
+
end
|
|
126
|
+
core_src_version = function()
|
|
127
|
+
return '0.0.14'
|
|
128
|
+
end
|
|
129
|
+
--
|
|
130
|
+
core_src_lib_common_module = function()
|
|
131
|
+
local zeebo_pipeline = core_src_lib_util_pipeline()
|
|
132
|
+
local application_default = core_src_lib_object_root()
|
|
133
|
+
local function default(application, defaults)
|
|
134
|
+
if not application then return nil end
|
|
135
|
+
local index = 1
|
|
136
|
+
local items = {'data', 'meta', 'config', 'callbacks'}
|
|
137
|
+
local normalized_aplication = {}
|
|
138
|
+
defaults = defaults or application_default
|
|
139
|
+
while index <= #items do
|
|
140
|
+
local key1 = items[index]
|
|
141
|
+
local keys = defaults[key1]
|
|
142
|
+
normalized_aplication[key1] = {}
|
|
143
|
+
for key2, default_value in pairs(keys) do
|
|
144
|
+
local value = application[key1] and application[key1][key2]
|
|
145
|
+
normalized_aplication[key1][key2] = value or default_value
|
|
146
|
+
end
|
|
147
|
+
index = index + 1
|
|
148
|
+
end
|
|
149
|
+
normalized_aplication.config.id = tostring(application)
|
|
150
|
+
normalized_aplication.assets = application.assets or {}
|
|
151
|
+
if application.callbacks then
|
|
152
|
+
for event, handler in pairs(application.callbacks) do
|
|
153
|
+
normalized_aplication.callbacks[event] = handler
|
|
154
|
+
end
|
|
155
|
+
end
|
|
156
|
+
return normalized_aplication
|
|
157
|
+
end
|
|
158
|
+
local function normalize(application)
|
|
159
|
+
if not application then return nil end
|
|
160
|
+
if application.Game then
|
|
161
|
+
application = application.Game
|
|
162
|
+
end
|
|
163
|
+
if application.new and type(application.new) == 'function' then
|
|
164
|
+
application = application.new()
|
|
165
|
+
end
|
|
166
|
+
if application and (application.meta or application.callbacks) then
|
|
167
|
+
return application
|
|
168
|
+
end
|
|
169
|
+
local normalized_aplication = {
|
|
170
|
+
data = {},
|
|
171
|
+
meta = {},
|
|
172
|
+
assets = {},
|
|
173
|
+
config = {},
|
|
174
|
+
callbacks = {}
|
|
175
|
+
}
|
|
176
|
+
for key, value in pairs(application) do
|
|
177
|
+
if key == 'assets' then
|
|
178
|
+
normalized_aplication.assets = value
|
|
179
|
+
elseif application_default.meta[key] then
|
|
180
|
+
normalized_aplication.meta[key] = value
|
|
181
|
+
elseif application_default.config[key] then
|
|
182
|
+
normalized_aplication.config[key] = value
|
|
183
|
+
elseif type(value) == 'function' then
|
|
184
|
+
normalized_aplication.callbacks[key] = value
|
|
185
|
+
else
|
|
186
|
+
normalized_aplication.data[key] = value
|
|
187
|
+
end
|
|
188
|
+
end
|
|
189
|
+
return normalized_aplication
|
|
190
|
+
end
|
|
191
|
+
local function loadgame(game_file, defaults)
|
|
192
|
+
if type(game_file) == 'table' or type(game_file) == 'userdata' then
|
|
193
|
+
return default(normalize(game_file), defaults)
|
|
194
|
+
end
|
|
195
|
+
local cwd = '.'
|
|
196
|
+
local application = type(game_file) == 'function' and game_file
|
|
197
|
+
local game_title = not application and game_file and game_file:gsub('%.lua$', '') or 'game'
|
|
198
|
+
if not application and game_file and game_file:find('\n') then
|
|
199
|
+
local ok, app = pcall(load, game_file)
|
|
200
|
+
if not ok then
|
|
201
|
+
ok, app = pcall(loadstring, game_file)
|
|
202
|
+
end
|
|
203
|
+
application = ok and app
|
|
204
|
+
else
|
|
205
|
+
if love and love.filesystem and love.filesystem.getSource then
|
|
206
|
+
cwd = love.filesystem.getSource()
|
|
207
|
+
end
|
|
208
|
+
if not application then
|
|
209
|
+
application = loadfile(cwd..'/'..game_title..'.lua')
|
|
210
|
+
end
|
|
211
|
+
if not application then
|
|
212
|
+
local ok, app = pcall(require, game_title)
|
|
213
|
+
application = ok and app
|
|
214
|
+
end
|
|
215
|
+
end
|
|
216
|
+
if not application and io and io.open and game_file then
|
|
217
|
+
local app_file = io.open(game_file)
|
|
218
|
+
if app_file then
|
|
219
|
+
local app_src = app_file:read('*a')
|
|
220
|
+
local ok, app = pcall(load, app_src)
|
|
221
|
+
if not ok then
|
|
222
|
+
ok, app = pcall(loadstring, app_src)
|
|
223
|
+
end
|
|
224
|
+
application = ok and app
|
|
225
|
+
app_file:close()
|
|
226
|
+
end
|
|
227
|
+
end
|
|
228
|
+
while application and type(application) == 'function' do
|
|
229
|
+
application = application()
|
|
230
|
+
end
|
|
231
|
+
return default(normalize(application), defaults)
|
|
232
|
+
end
|
|
233
|
+
local function package(self, module_name, module, custom)
|
|
234
|
+
local system = module_name:sub(1, 1) == '@'
|
|
235
|
+
local name = system and module_name:sub(2) or module_name
|
|
236
|
+
if system then
|
|
237
|
+
self.list_append(name)
|
|
238
|
+
self.stdlib_required[name] = true
|
|
239
|
+
end
|
|
240
|
+
self.pipeline[#self.pipeline + 1] = function ()
|
|
241
|
+
if not self.list_exist(name) then return end
|
|
242
|
+
if not system and not self.lib_required[name] then return end
|
|
243
|
+
if not system and self.engine.lib_installed[name] then return end
|
|
244
|
+
if system and self.engine.stdlib_installed[name] then return end
|
|
245
|
+
local try_install = function()
|
|
246
|
+
module.install(self.std, self.engine, custom, module_name)
|
|
247
|
+
if module.event_bus then
|
|
248
|
+
module.event_bus(self.std, self.engine, custom, module_name)
|
|
249
|
+
end
|
|
250
|
+
end
|
|
251
|
+
local ok, msg = pcall(try_install)
|
|
252
|
+
if not ok then
|
|
253
|
+
self.lib_error[name] = msg
|
|
254
|
+
return
|
|
255
|
+
end
|
|
256
|
+
if system then
|
|
257
|
+
self.engine.stdlib_installed[name] = true
|
|
258
|
+
else
|
|
259
|
+
self.engine.lib_installed[name] = true
|
|
260
|
+
end
|
|
261
|
+
end
|
|
262
|
+
return self
|
|
263
|
+
end
|
|
264
|
+
local function require(std, application, engine)
|
|
265
|
+
if not application then
|
|
266
|
+
error('game not found!')
|
|
267
|
+
end
|
|
268
|
+
local application_require = application.config.require
|
|
269
|
+
local next_library = application_require:gmatch('%S+')
|
|
270
|
+
local self = {
|
|
271
|
+
std=std,
|
|
272
|
+
engine=engine,
|
|
273
|
+
package = package,
|
|
274
|
+
event = {},
|
|
275
|
+
list = {},
|
|
276
|
+
lib_error = {},
|
|
277
|
+
lib_optional = {},
|
|
278
|
+
lib_required = {},
|
|
279
|
+
stdlib_required = {},
|
|
280
|
+
pipeline = {},
|
|
281
|
+
pipe = zeebo_pipeline.pipe
|
|
282
|
+
}
|
|
283
|
+
if not engine.lib_installed then
|
|
284
|
+
engine.lib_installed = {}
|
|
285
|
+
engine.stdlib_installed = {}
|
|
286
|
+
end
|
|
287
|
+
self.list_exist = function (name)
|
|
288
|
+
return self.lib_optional[name] or self.lib_required[name] or self.stdlib_required[name]
|
|
289
|
+
end
|
|
290
|
+
self.list_append = function (name)
|
|
291
|
+
if not self.list_exist(name) then
|
|
292
|
+
self.list[#self.list + 1] = name
|
|
293
|
+
end
|
|
294
|
+
end
|
|
295
|
+
self.run = function()
|
|
296
|
+
local index = 1
|
|
297
|
+
zeebo_pipeline.run(self)
|
|
298
|
+
while index <= #self.list do
|
|
299
|
+
local name = self.list[index]
|
|
300
|
+
if self.stdlib_required[name] and not self.engine.stdlib_installed[name] then
|
|
301
|
+
error('system library not loaded: '..name..'\n'..(self.lib_error[name] or ''))
|
|
302
|
+
end
|
|
303
|
+
if self.lib_required[name] and not self.engine.lib_installed[name] then
|
|
304
|
+
error('library not loaded: '..name..'\n'..(self.lib_error[name] or ''))
|
|
305
|
+
end
|
|
306
|
+
index = index + 1
|
|
307
|
+
end
|
|
308
|
+
end
|
|
309
|
+
repeat
|
|
310
|
+
local lib = next_library()
|
|
311
|
+
if lib then
|
|
312
|
+
local name, optional = lib:match('([%w%.]+)([?]?)')
|
|
313
|
+
self.list_append(name)
|
|
314
|
+
if optional and #optional > 0 then
|
|
315
|
+
self.lib_optional[name] = true
|
|
316
|
+
else
|
|
317
|
+
self.lib_required[name] = true
|
|
318
|
+
end
|
|
319
|
+
end
|
|
320
|
+
until not lib
|
|
321
|
+
return self
|
|
322
|
+
end
|
|
323
|
+
local P = {
|
|
324
|
+
loadgame = loadgame,
|
|
325
|
+
require = require
|
|
326
|
+
}
|
|
327
|
+
return P
|
|
328
|
+
end
|
|
329
|
+
--
|
|
330
|
+
core_src_lib_engine_api_encoder = function()
|
|
331
|
+
local function install(std, engine, library, name)
|
|
332
|
+
std = std or {}
|
|
333
|
+
std[name] = {
|
|
334
|
+
encode=library.encode,
|
|
335
|
+
decode=library.decode
|
|
336
|
+
}
|
|
337
|
+
return {[name]=std[name]}
|
|
338
|
+
end
|
|
339
|
+
local P = {
|
|
340
|
+
install=install
|
|
341
|
+
}
|
|
342
|
+
return P
|
|
343
|
+
end
|
|
344
|
+
--
|
|
345
|
+
core_src_lib_engine_api_app = function()
|
|
346
|
+
local util_decorator = core_src_lib_util_decorator()
|
|
347
|
+
local function reset(std, engine)
|
|
348
|
+
if std.node then
|
|
349
|
+
std.bus.emit('exit')
|
|
350
|
+
std.bus.emit('init')
|
|
351
|
+
else
|
|
352
|
+
engine.root.callbacks.exit(std, engine.root.data)
|
|
353
|
+
engine.root.callbacks.init(std, engine.root.data)
|
|
354
|
+
end
|
|
355
|
+
end
|
|
356
|
+
local function exit(std)
|
|
357
|
+
std.bus.emit('exit')
|
|
358
|
+
std.bus.emit('quit')
|
|
359
|
+
end
|
|
360
|
+
local function title(func, window_name)
|
|
361
|
+
if func then
|
|
362
|
+
func(window_name)
|
|
363
|
+
end
|
|
364
|
+
end
|
|
365
|
+
local function install(std, engine, config)
|
|
366
|
+
std = std or {}
|
|
367
|
+
config = config or {}
|
|
368
|
+
std.app = std.app or {}
|
|
369
|
+
std.bus.listen('post_quit', function()
|
|
370
|
+
if config.quit then
|
|
371
|
+
config.quit()
|
|
372
|
+
end
|
|
373
|
+
end)
|
|
374
|
+
std.app.title = util_decorator.prefix1(config.set_title, title)
|
|
375
|
+
std.app.exit = util_decorator.prefix1(std, exit)
|
|
376
|
+
std.app.reset = util_decorator.prefix2(std, engine, reset)
|
|
377
|
+
std.app.get_fps = config.fps
|
|
378
|
+
return std.app
|
|
379
|
+
end
|
|
380
|
+
local P = {
|
|
381
|
+
install=install
|
|
382
|
+
}
|
|
383
|
+
return P
|
|
384
|
+
end
|
|
385
|
+
--
|
|
386
|
+
core_src_lib_engine_api_hash = function()
|
|
387
|
+
local function djb2(digest)
|
|
388
|
+
local index = 1
|
|
389
|
+
local hash = 5381
|
|
390
|
+
while index <= #digest do
|
|
391
|
+
local char = string.byte(digest, index)
|
|
392
|
+
hash = (hash * 33) + char
|
|
393
|
+
index = index + 1
|
|
394
|
+
end
|
|
395
|
+
hash = string.format('%08x', hash)
|
|
396
|
+
hash = tonumber(hash:sub(#hash - 7), 16)
|
|
397
|
+
return hash
|
|
398
|
+
end
|
|
399
|
+
local function fingerprint(all_your_secrets)
|
|
400
|
+
local index = 1
|
|
401
|
+
local digest = ''
|
|
402
|
+
while index <= #all_your_secrets do
|
|
403
|
+
local value = all_your_secrets[index]
|
|
404
|
+
if type(value) == 'function' then
|
|
405
|
+
digest = digest..tostring(value())
|
|
406
|
+
else
|
|
407
|
+
digest = digest..tostring(value)
|
|
408
|
+
end
|
|
409
|
+
index = index + 1
|
|
410
|
+
end
|
|
411
|
+
return djb2(digest)
|
|
412
|
+
end
|
|
413
|
+
local function install(std, engine, all_your_secrets)
|
|
414
|
+
local id = fingerprint(all_your_secrets or {'not secret!'})
|
|
415
|
+
std = std or {}
|
|
416
|
+
std.hash = std.hash or {}
|
|
417
|
+
std.hash.djb2 = djb2
|
|
418
|
+
std.hash.fingerprint = function() return id end
|
|
419
|
+
return {hash=std.hash}
|
|
420
|
+
end
|
|
421
|
+
local P = {
|
|
422
|
+
install = install
|
|
423
|
+
}
|
|
424
|
+
return P
|
|
425
|
+
end
|
|
426
|
+
--
|
|
427
|
+
core_src_lib_engine_api_http = function()
|
|
428
|
+
local zeebo_pipeline = core_src_lib_util_pipeline()
|
|
429
|
+
local function fast(self)
|
|
430
|
+
self.speed = '_fast'
|
|
431
|
+
return self
|
|
432
|
+
end
|
|
433
|
+
local function body(self, content)
|
|
434
|
+
self.body_content=content
|
|
435
|
+
return self
|
|
436
|
+
end
|
|
437
|
+
local function param(self, name, value)
|
|
438
|
+
local index = #self.param_list + 1
|
|
439
|
+
self.param_list[index] = name
|
|
440
|
+
self.param_dict[name] = value
|
|
441
|
+
return self
|
|
442
|
+
end
|
|
443
|
+
local function header(self, name, value)
|
|
444
|
+
local index = #self.header_list + 1
|
|
445
|
+
self.header_list[index] = name
|
|
446
|
+
self.header_dict[name] = value
|
|
447
|
+
return self
|
|
448
|
+
end
|
|
449
|
+
local function success(self, handler_func)
|
|
450
|
+
self.success_handler = handler_func
|
|
451
|
+
return self
|
|
452
|
+
end
|
|
453
|
+
local function failed(self, handler_func)
|
|
454
|
+
self.failed_handler = handler_func
|
|
455
|
+
return self
|
|
456
|
+
end
|
|
457
|
+
local function error(self, handler_func)
|
|
458
|
+
self.error_handler = handler_func
|
|
459
|
+
return self
|
|
460
|
+
end
|
|
461
|
+
local function request(method, std, engine, protocol_handler)
|
|
462
|
+
local callback_handler = function()
|
|
463
|
+
std.node.emit(engine.current, 'http')
|
|
464
|
+
end
|
|
465
|
+
return function (url)
|
|
466
|
+
local game = engine.current.data
|
|
467
|
+
local self = {
|
|
468
|
+
url = url,
|
|
469
|
+
speed = '',
|
|
470
|
+
method = method,
|
|
471
|
+
body_content = '',
|
|
472
|
+
header_list = {},
|
|
473
|
+
header_dict = {},
|
|
474
|
+
param_list = {},
|
|
475
|
+
param_dict = {},
|
|
476
|
+
callback_handler = callback_handler,
|
|
477
|
+
success_handler = function (std, game) end,
|
|
478
|
+
failed_handler = function (std, game) end,
|
|
479
|
+
error_handler = function (std, game) end,
|
|
480
|
+
std = std,
|
|
481
|
+
game = game,
|
|
482
|
+
fast = fast,
|
|
483
|
+
body = body,
|
|
484
|
+
param = param,
|
|
485
|
+
header = header,
|
|
486
|
+
success = success,
|
|
487
|
+
failed = failed,
|
|
488
|
+
error = error,
|
|
489
|
+
run = zeebo_pipeline.run,
|
|
490
|
+
protocol_handler = protocol_handler
|
|
491
|
+
}
|
|
492
|
+
self.promise = function()
|
|
493
|
+
zeebo_pipeline.stop(self)
|
|
494
|
+
end
|
|
495
|
+
self.resolve = function()
|
|
496
|
+
zeebo_pipeline.resume(self)
|
|
497
|
+
end
|
|
498
|
+
self.set = function (key, value)
|
|
499
|
+
self.std.http[key] = value
|
|
500
|
+
end
|
|
501
|
+
self.pipeline = {
|
|
502
|
+
function()
|
|
503
|
+
self:protocol_handler()
|
|
504
|
+
end,
|
|
505
|
+
function()
|
|
506
|
+
self.callback_handler(self.std, self.game)
|
|
507
|
+
if self.std.http.ok then
|
|
508
|
+
self.success_handler(self.std, self.game)
|
|
509
|
+
elseif self.std.http.error or not self.std.http.status then
|
|
510
|
+
self.error_handler(self.std, self.game)
|
|
511
|
+
else
|
|
512
|
+
self.failed_handler(self.std, self.game)
|
|
513
|
+
end
|
|
514
|
+
end,
|
|
515
|
+
function ()
|
|
516
|
+
self.std.http.ok = nil
|
|
517
|
+
self.std.http.body = nil
|
|
518
|
+
self.std.http.error = nil
|
|
519
|
+
self.std.http.status = nil
|
|
520
|
+
end,
|
|
521
|
+
function()
|
|
522
|
+
zeebo_pipeline.reset(self)
|
|
523
|
+
end
|
|
524
|
+
}
|
|
525
|
+
return self
|
|
526
|
+
end
|
|
527
|
+
end
|
|
528
|
+
local function install(std, engine, protocol)
|
|
529
|
+
local protocol_handler = protocol.handler
|
|
530
|
+
std.http = std.http or {}
|
|
531
|
+
std.http.get=request('GET', std, engine, protocol_handler)
|
|
532
|
+
std.http.head=request('HEAD', std, engine, protocol_handler)
|
|
533
|
+
std.http.post=request('POST', std, engine, protocol_handler)
|
|
534
|
+
std.http.put=request('PUT', std, engine, protocol_handler)
|
|
535
|
+
std.http.delete=request('DELETE', std, engine, protocol_handler)
|
|
536
|
+
std.http.patch=request('PATCH', std, engine, protocol_handler)
|
|
537
|
+
if protocol.install then
|
|
538
|
+
protocol.install(std, engine)
|
|
539
|
+
end
|
|
540
|
+
return {
|
|
541
|
+
std={http=std.http}
|
|
542
|
+
}
|
|
543
|
+
end
|
|
544
|
+
local P = {
|
|
545
|
+
install=install
|
|
546
|
+
}
|
|
547
|
+
return P
|
|
548
|
+
end
|
|
549
|
+
--
|
|
550
|
+
core_src_lib_engine_api_i18n = function()
|
|
551
|
+
local language = 'en-US'
|
|
552
|
+
local language_default = 'en-US'
|
|
553
|
+
local language_list = {}
|
|
554
|
+
local language_inverse_list = {}
|
|
555
|
+
local translate = {}
|
|
556
|
+
local function update_languages(texts)
|
|
557
|
+
local index = 1
|
|
558
|
+
translate = texts
|
|
559
|
+
language_list = {language_default}
|
|
560
|
+
language_inverse_list = {[language_default]=1}
|
|
561
|
+
repeat
|
|
562
|
+
local lang = next(texts)
|
|
563
|
+
if lang then
|
|
564
|
+
index = index + 1
|
|
565
|
+
language_inverse_list[lang] = index
|
|
566
|
+
language_list[#language_list + 1] = lang
|
|
567
|
+
end
|
|
568
|
+
until lang
|
|
569
|
+
end
|
|
570
|
+
local function get_text(old_text)
|
|
571
|
+
local new_text = translate[language] and translate[language][old_text]
|
|
572
|
+
return new_text or old_text
|
|
573
|
+
end
|
|
574
|
+
local function get_language()
|
|
575
|
+
return language
|
|
576
|
+
end
|
|
577
|
+
local function set_language(l)
|
|
578
|
+
if language_inverse_list[l] then
|
|
579
|
+
language = l
|
|
580
|
+
else
|
|
581
|
+
language = language_default
|
|
582
|
+
end
|
|
583
|
+
end
|
|
584
|
+
local function next_language(to)
|
|
585
|
+
local index = language_inverse_list[language]
|
|
586
|
+
local incr = to or 1
|
|
587
|
+
if index then
|
|
588
|
+
index = index + incr
|
|
589
|
+
if index > #language_list then
|
|
590
|
+
index = 1
|
|
591
|
+
end
|
|
592
|
+
if index <= 0 then
|
|
593
|
+
index = #language_list
|
|
594
|
+
end
|
|
595
|
+
index = index == 0 and 1 or index
|
|
596
|
+
set_language(language_list[index])
|
|
597
|
+
end
|
|
598
|
+
end
|
|
599
|
+
local function back_language()
|
|
600
|
+
next_language(-1)
|
|
601
|
+
end
|
|
602
|
+
local function decorator_draw_text(func)
|
|
603
|
+
return function (x, y, text, a, b, c)
|
|
604
|
+
return func(x, y, get_text(text), a, b, c)
|
|
605
|
+
end
|
|
606
|
+
end
|
|
607
|
+
local function event_bus(std, engine)
|
|
608
|
+
std.bus.listen('ret_i18n', function(result)
|
|
609
|
+
update_languages(result)
|
|
610
|
+
end)
|
|
611
|
+
std.bus.emit_next('i18n')
|
|
612
|
+
end
|
|
613
|
+
local function install(std, engine, system_language)
|
|
614
|
+
if not (std and std.text and std.text.print) then
|
|
615
|
+
error('missing draw text')
|
|
616
|
+
end
|
|
617
|
+
local old_put = std.text.put
|
|
618
|
+
local old_print = std.text.print
|
|
619
|
+
local old_print_ex = std.text.print_ex
|
|
620
|
+
if system_language then
|
|
621
|
+
set_language(system_language())
|
|
622
|
+
end
|
|
623
|
+
std.text.put = decorator_draw_text(old_put)
|
|
624
|
+
std.text.print = decorator_draw_text(old_print)
|
|
625
|
+
std.text.print_ex = decorator_draw_text(old_print_ex)
|
|
626
|
+
std.i18n = {}
|
|
627
|
+
std.i18n.get_text = get_text
|
|
628
|
+
std.i18n.get_language = get_language
|
|
629
|
+
std.i18n.set_language = set_language
|
|
630
|
+
std.i18n.back = back_language
|
|
631
|
+
std.i18n.next = next_language
|
|
632
|
+
return {
|
|
633
|
+
std={
|
|
634
|
+
i18n=std.i18n,
|
|
635
|
+
draw={
|
|
636
|
+
text=std.draw.text
|
|
637
|
+
}
|
|
638
|
+
}
|
|
639
|
+
}
|
|
640
|
+
end
|
|
641
|
+
local P = {
|
|
642
|
+
event_bus=event_bus,
|
|
643
|
+
install=install
|
|
644
|
+
}
|
|
645
|
+
return P
|
|
646
|
+
end
|
|
647
|
+
--
|
|
648
|
+
core_src_lib_engine_api_key = function()
|
|
649
|
+
local function real_key(std, engine, rkey, rvalue)
|
|
650
|
+
local value = rvalue == 1 or rvalue == true
|
|
651
|
+
local key = engine.key_bindings[rkey] or (std.key.axis[rkey] and rkey)
|
|
652
|
+
if key then
|
|
653
|
+
std.key.axis[key] = value and 1 or 0
|
|
654
|
+
std.key.press[key] = value
|
|
655
|
+
if key == 'right' or key == 'left' then
|
|
656
|
+
std.key.axis.x = std.key.axis.right - std.key.axis.left
|
|
657
|
+
end
|
|
658
|
+
if key == 'down' or key == 'up' then
|
|
659
|
+
std.key.axis.y = std.key.axis.down - std.key.axis.up
|
|
660
|
+
end
|
|
661
|
+
std.bus.emit('key')
|
|
662
|
+
end
|
|
663
|
+
end
|
|
664
|
+
local function real_keydown(std, engine, key)
|
|
665
|
+
real_key(std, engine, key, 1)
|
|
666
|
+
end
|
|
667
|
+
local function real_keyup(std, engine, key)
|
|
668
|
+
real_key(std, engine, key, 0)
|
|
669
|
+
end
|
|
670
|
+
local function event_bus(std, engine)
|
|
671
|
+
std.bus.listen_std_engine('rkey', real_key)
|
|
672
|
+
std.bus.listen_std_engine('rkey1', real_keydown)
|
|
673
|
+
std.bus.listen_std_engine('rkey0', real_keyup)
|
|
674
|
+
end
|
|
675
|
+
local function install(std, engine, key_bindings)
|
|
676
|
+
engine.key_bindings = key_bindings or {}
|
|
677
|
+
engine.keyboard = real_key
|
|
678
|
+
end
|
|
679
|
+
local P = {
|
|
680
|
+
event_bus = event_bus,
|
|
681
|
+
install = install
|
|
682
|
+
}
|
|
683
|
+
return P
|
|
684
|
+
end
|
|
685
|
+
--
|
|
686
|
+
core_src_lib_engine_api_math = function()
|
|
687
|
+
local function abs(value)
|
|
688
|
+
if value < 0 then
|
|
689
|
+
return -value
|
|
690
|
+
end
|
|
691
|
+
return value
|
|
692
|
+
end
|
|
693
|
+
local function clamp(value, value_min, value_max)
|
|
694
|
+
if value < value_min then
|
|
695
|
+
return value_min
|
|
696
|
+
elseif value > value_max then
|
|
697
|
+
return value_max
|
|
698
|
+
else
|
|
699
|
+
return value
|
|
700
|
+
end
|
|
701
|
+
end
|
|
702
|
+
local function clamp2(value, value_min, value_max)
|
|
703
|
+
return (value - value_min) % (value_max - value_min + 1) + value_min
|
|
704
|
+
end
|
|
705
|
+
local function cycle(passed, duration)
|
|
706
|
+
local endtime = (passed) % duration
|
|
707
|
+
return ((endtime == 0 and (passed % (duration * 2)) or endtime)) / duration
|
|
708
|
+
end
|
|
709
|
+
local function dir(value, alpha)
|
|
710
|
+
alpha = alpha or 0
|
|
711
|
+
if value < -alpha then
|
|
712
|
+
return -1
|
|
713
|
+
elseif value > alpha then
|
|
714
|
+
return 1
|
|
715
|
+
else
|
|
716
|
+
return 0
|
|
717
|
+
end
|
|
718
|
+
end
|
|
719
|
+
local function dis(x1,y1,x2,y2)
|
|
720
|
+
return ((x2 - x1) ^ 2 + (y2 - y1) ^ 2) ^ 0.5
|
|
721
|
+
end
|
|
722
|
+
local function dis2(x1,y1,x2,y2)
|
|
723
|
+
return (x2 - x1) ^ 2 + (y2 - y1) ^ 2
|
|
724
|
+
end
|
|
725
|
+
local function lerp(a, b, alpha)
|
|
726
|
+
return a + alpha * ( b - a )
|
|
727
|
+
end
|
|
728
|
+
local function map(value, in_min, in_max, out_min, out_max)
|
|
729
|
+
return (value - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
|
|
730
|
+
end
|
|
731
|
+
local function max(...)
|
|
732
|
+
local args = {...}
|
|
733
|
+
local index = 1
|
|
734
|
+
local value = nil
|
|
735
|
+
local max_value = nil
|
|
736
|
+
if #args == 1 then
|
|
737
|
+
args = args[1]
|
|
738
|
+
end
|
|
739
|
+
while index <= #args do
|
|
740
|
+
value = args[index]
|
|
741
|
+
if max_value == nil or value > max_value then
|
|
742
|
+
max_value = value
|
|
743
|
+
end
|
|
744
|
+
index = index + 1
|
|
745
|
+
end
|
|
746
|
+
return max_value
|
|
747
|
+
end
|
|
748
|
+
local function min(...)
|
|
749
|
+
local args = {...}
|
|
750
|
+
local index = 1
|
|
751
|
+
local value = nil
|
|
752
|
+
local min_value = nil
|
|
753
|
+
if #args == 1 then
|
|
754
|
+
args = args[1]
|
|
755
|
+
end
|
|
756
|
+
while index <= #args do
|
|
757
|
+
value = args[index]
|
|
758
|
+
if min_value == nil or value < min_value then
|
|
759
|
+
min_value = value
|
|
760
|
+
end
|
|
761
|
+
index = index + 1
|
|
762
|
+
end
|
|
763
|
+
return min_value
|
|
764
|
+
end
|
|
765
|
+
local function saw(value)
|
|
766
|
+
if value < 0.25 then
|
|
767
|
+
return value * 4
|
|
768
|
+
elseif value < 0.50 then
|
|
769
|
+
return 1 - ((value - 0.25) * 4)
|
|
770
|
+
elseif value < 0.75 then
|
|
771
|
+
return ((value - 0.50) * 4) * (-1)
|
|
772
|
+
end
|
|
773
|
+
return ((value - 0.75) * 4) - 1
|
|
774
|
+
end
|
|
775
|
+
local function install(std)
|
|
776
|
+
std = std or {}
|
|
777
|
+
std.math = std.math or {}
|
|
778
|
+
std.math.abs=abs
|
|
779
|
+
std.math.clamp=clamp
|
|
780
|
+
std.math.clamp2=clamp2
|
|
781
|
+
std.math.cycle=cycle
|
|
782
|
+
std.math.dir=dir
|
|
783
|
+
std.math.dis=dis
|
|
784
|
+
std.math.dis2=dis2
|
|
785
|
+
std.math.lerp=lerp
|
|
786
|
+
std.math.map=map
|
|
787
|
+
std.math.max=max
|
|
788
|
+
std.math.min=min
|
|
789
|
+
std.math.saw=saw
|
|
790
|
+
return std.math
|
|
791
|
+
end
|
|
792
|
+
local function install_clib(std)
|
|
793
|
+
std = std or {}
|
|
794
|
+
std.math = std.math or {}
|
|
795
|
+
std.math.acos=math.acos
|
|
796
|
+
std.math.asin=math.asin
|
|
797
|
+
std.math.atan=math.atan
|
|
798
|
+
std.math.atan2=math.atan2
|
|
799
|
+
std.math.ceil=math.ceil
|
|
800
|
+
std.math.cos=math.cos
|
|
801
|
+
std.math.cosh=math.cosh
|
|
802
|
+
std.math.deg=math.deg
|
|
803
|
+
std.math.exp=math.exp
|
|
804
|
+
std.math.floor=math.floor
|
|
805
|
+
std.math.fmod=math.fmod
|
|
806
|
+
std.math.frexp=math.frexp
|
|
807
|
+
std.math.huge=math.huge
|
|
808
|
+
std.math.ldexp=math.ldexp
|
|
809
|
+
std.math.log=math.log
|
|
810
|
+
std.math.log10=math.log10
|
|
811
|
+
std.math.modf=math.modf
|
|
812
|
+
std.math.pi=math.pi
|
|
813
|
+
std.math.pow=math.pow
|
|
814
|
+
std.math.rad=math.rad
|
|
815
|
+
std.math.sin=math.sin
|
|
816
|
+
std.math.sinh=math.sinh
|
|
817
|
+
std.math.sqrt=math.sqrt
|
|
818
|
+
std.math.tan=math.tan
|
|
819
|
+
std.math.tanh=math.tanh
|
|
820
|
+
return std.math
|
|
821
|
+
end
|
|
822
|
+
local function install_clib_random(std)
|
|
823
|
+
std = std or {}
|
|
824
|
+
std.math = std.math or {}
|
|
825
|
+
std.math.random = function(a, b)
|
|
826
|
+
a = a and math.floor(a)
|
|
827
|
+
b = b and math.floor(b)
|
|
828
|
+
return math.random(a, b)
|
|
829
|
+
end
|
|
830
|
+
return std.math
|
|
831
|
+
end
|
|
832
|
+
local P = {
|
|
833
|
+
install = install,
|
|
834
|
+
clib = {
|
|
835
|
+
install = install_clib
|
|
836
|
+
},
|
|
837
|
+
clib_random = {
|
|
838
|
+
install = install_clib_random
|
|
839
|
+
}
|
|
840
|
+
}
|
|
841
|
+
return P;
|
|
842
|
+
end
|
|
843
|
+
--
|
|
844
|
+
core_src_lib_engine_draw_fps = function()
|
|
845
|
+
local function draw_fps(std, engine, show, pos_x, pos_y)
|
|
846
|
+
if show < 1 then return end
|
|
847
|
+
local x = engine.current.config.offset_x + pos_x
|
|
848
|
+
local y = engine.current.config.offset_y + pos_y
|
|
849
|
+
local s = 4
|
|
850
|
+
std.draw.color(0xFFFF00FF)
|
|
851
|
+
if show >= 1 then
|
|
852
|
+
std.draw.rect(0, x, y, 40, 24)
|
|
853
|
+
end
|
|
854
|
+
if show >= 2 then
|
|
855
|
+
std.draw.rect(0, x + 48, y, 40, 24)
|
|
856
|
+
end
|
|
857
|
+
if show >= 3 then
|
|
858
|
+
std.draw.rect(0, x + 96, y, 40, 24)
|
|
859
|
+
end
|
|
860
|
+
std.draw.color(0x000000FF)
|
|
861
|
+
std.draw.font('Tiresias', 16)
|
|
862
|
+
if show >= 3 then
|
|
863
|
+
local floor = std.math.floor or math.floor or function() return 'XX' end
|
|
864
|
+
local fps = floor((1/std.delta) * 1000)
|
|
865
|
+
std.draw.text(x + s, y, fps)
|
|
866
|
+
s = s + 46
|
|
867
|
+
end
|
|
868
|
+
if show >= 1 then
|
|
869
|
+
std.draw.text(x + s, y, engine.fps)
|
|
870
|
+
s = s + 46
|
|
871
|
+
end
|
|
872
|
+
if show >= 2 then
|
|
873
|
+
std.draw.text(x + s, y, engine.root.config.fps_max)
|
|
874
|
+
s = s + 46
|
|
875
|
+
end
|
|
876
|
+
end
|
|
877
|
+
local function event_bus(std, engine)
|
|
878
|
+
std.bus.listen('post_draw', function()
|
|
879
|
+
engine.current = engine.root
|
|
880
|
+
draw_fps(std, engine, engine.root.config.fps_show, 8, 8)
|
|
881
|
+
end)
|
|
882
|
+
end
|
|
883
|
+
local function install(std, engine)
|
|
884
|
+
std.app = std.app or {}
|
|
885
|
+
std.app.fps_show = function(show)
|
|
886
|
+
engine.root.config.fps_show = show
|
|
887
|
+
end
|
|
888
|
+
end
|
|
889
|
+
local P = {
|
|
890
|
+
event_bus=event_bus,
|
|
891
|
+
install=install
|
|
892
|
+
}
|
|
893
|
+
return P
|
|
894
|
+
end
|
|
895
|
+
--
|
|
896
|
+
core_src_lib_engine_draw_text = function()
|
|
897
|
+
local util_decorator = core_src_lib_util_decorator()
|
|
898
|
+
local function text_put(std, engine, font_previous, pos_x, pos_y, text, size)
|
|
899
|
+
size = size or 2
|
|
900
|
+
local hem = engine.current.data.width / 80
|
|
901
|
+
local vem = engine.current.data.height / 24
|
|
902
|
+
local font_size = hem * size
|
|
903
|
+
std.text.font_default(0)
|
|
904
|
+
std.text.font_size(font_size)
|
|
905
|
+
std.text.print(pos_x * hem, pos_y * vem, text)
|
|
906
|
+
font_previous()
|
|
907
|
+
end
|
|
908
|
+
local function text_print_ex(std, engine, x, y, text, align)
|
|
909
|
+
local w, h = std.text.mensure(text)
|
|
910
|
+
local aligns = {w, w/2, 0}
|
|
911
|
+
std.text.print(x - aligns[(align or 1) + 2], y, text)
|
|
912
|
+
return w, h
|
|
913
|
+
end
|
|
914
|
+
local function install(std, engine, config)
|
|
915
|
+
std.text.print_ex = util_decorator.prefix2(std, engine, text_print_ex)
|
|
916
|
+
std.text.put = util_decorator.prefix3(std, engine, config.font_previous, text_put)
|
|
917
|
+
end
|
|
918
|
+
local P = {
|
|
919
|
+
install=install
|
|
920
|
+
}
|
|
921
|
+
return P
|
|
922
|
+
end
|
|
923
|
+
--
|
|
924
|
+
core_src_lib_engine_draw_poly = function()
|
|
925
|
+
local function decorator_poo(object, func)
|
|
926
|
+
if not object or not func then return func end
|
|
927
|
+
return function(a, b, c, d)
|
|
928
|
+
return func(object, a, b, c, d)
|
|
929
|
+
end
|
|
930
|
+
end
|
|
931
|
+
local function decorator_line(func_draw_line)
|
|
932
|
+
return function(mode, verts)
|
|
933
|
+
local index = 4
|
|
934
|
+
while index <= #verts do
|
|
935
|
+
func_draw_line(verts[index - 3], verts[index - 2], verts[index - 1], verts[index])
|
|
936
|
+
index = index + 2
|
|
937
|
+
end
|
|
938
|
+
end
|
|
939
|
+
end
|
|
940
|
+
local function decorator_triangle(func_draw_poly, std, func_draw_triangle)
|
|
941
|
+
if not func_draw_triangle then
|
|
942
|
+
return func_draw_poly
|
|
943
|
+
end
|
|
944
|
+
local point = function(x, y, px, py, scale, angle, ox, oy)
|
|
945
|
+
local xx = x + ((ox - px) * -scale * std.math.cos(angle)) - ((ox - py) * -scale * std.math.sin(angle))
|
|
946
|
+
local yy = y + ((oy - px) * -scale * std.math.sin(angle)) + ((oy - py) * -scale * std.math.cos(angle))
|
|
947
|
+
return xx, yy
|
|
948
|
+
end
|
|
949
|
+
return function(engine_mode, verts, x, y, scale, angle, ox, oy)
|
|
950
|
+
if #verts ~= 6 then
|
|
951
|
+
return func_draw_poly(engine_mode, verts, x, y, scale, angle, ox, oy)
|
|
952
|
+
end
|
|
953
|
+
ox = ox or 0
|
|
954
|
+
oy = oy or ox or 0
|
|
955
|
+
local x1, y1 = point(x, y, verts[1], verts[2], scale, angle, ox, oy)
|
|
956
|
+
local x2, y2 = point(x, y, verts[3], verts[4], scale, angle, ox, oy)
|
|
957
|
+
local x3, y3 = point(x, y, verts[5], verts[6], scale, angle, ox, oy)
|
|
958
|
+
return func_draw_triangle(engine_mode, x1, y1, x2, y2, x3, y3)
|
|
959
|
+
end
|
|
960
|
+
end
|
|
961
|
+
local function decorator_poly(func_draw_poly, std, modes, repeats)
|
|
962
|
+
local func_repeat = function(verts, mode)
|
|
963
|
+
if repeats and repeats[mode + 1] then
|
|
964
|
+
verts[#verts + 1] = verts[1]
|
|
965
|
+
verts[#verts + 1] = verts[2]
|
|
966
|
+
end
|
|
967
|
+
end
|
|
968
|
+
return function (engine_mode, verts, x, y, scale, angle, ox, oy)
|
|
969
|
+
if #verts < 6 or #verts % 2 ~= 0 then return end
|
|
970
|
+
local mode = modes and modes[engine_mode + 1] or engine_mode
|
|
971
|
+
local rotated = std.math.cos and angle and angle ~= 0
|
|
972
|
+
ox = ox or 0
|
|
973
|
+
oy = oy or ox or 0
|
|
974
|
+
if x and y and not rotated then
|
|
975
|
+
local index = 1
|
|
976
|
+
local verts2 = {}
|
|
977
|
+
scale = scale or 1
|
|
978
|
+
while index <= #verts do
|
|
979
|
+
if index % 2 ~= 0 then
|
|
980
|
+
verts2[index] = x + (verts[index] * scale)
|
|
981
|
+
else
|
|
982
|
+
verts2[index] = y + (verts[index] * scale)
|
|
983
|
+
end
|
|
984
|
+
index = index + 1
|
|
985
|
+
end
|
|
986
|
+
func_repeat(verts2, engine_mode)
|
|
987
|
+
func_draw_poly(mode, verts2)
|
|
988
|
+
elseif x and y then
|
|
989
|
+
local index = 1
|
|
990
|
+
local verts2 = {}
|
|
991
|
+
while index < #verts do
|
|
992
|
+
local px = verts[index]
|
|
993
|
+
local py = verts[index + 1]
|
|
994
|
+
local xx = x + ((ox - px) * -scale * std.math.cos(angle)) - ((ox - py) * -scale * std.math.sin(angle))
|
|
995
|
+
local yy = y + ((oy - px) * -scale * std.math.sin(angle)) + ((oy - py) * -scale * std.math.cos(angle))
|
|
996
|
+
verts2[index] = xx
|
|
997
|
+
verts2[index + 1] = yy
|
|
998
|
+
index = index + 2
|
|
999
|
+
end
|
|
1000
|
+
func_repeat(verts2, engine_mode)
|
|
1001
|
+
func_draw_poly(mode, verts2)
|
|
1002
|
+
else
|
|
1003
|
+
func_draw_poly(mode, verts)
|
|
1004
|
+
end
|
|
1005
|
+
end
|
|
1006
|
+
end
|
|
1007
|
+
local function decorator_position(engine, func)
|
|
1008
|
+
return function(mode, verts, pos_x, pos_y, scale, angle, ox, oy)
|
|
1009
|
+
local x = engine.current.config.offset_x + (pos_x or 0)
|
|
1010
|
+
local y = engine.current.config.offset_y + (pos_y or 0)
|
|
1011
|
+
ox = ox or 0
|
|
1012
|
+
oy = ox or oy or 0
|
|
1013
|
+
scale = scale or 1
|
|
1014
|
+
angle = angle or 0
|
|
1015
|
+
return func(mode, verts, x, y, scale, angle, ox, oy)
|
|
1016
|
+
end
|
|
1017
|
+
end
|
|
1018
|
+
local function install(std, engine, config)
|
|
1019
|
+
local draw_line = decorator_poo(config.object, config.line)
|
|
1020
|
+
local draw_poly = decorator_poo(config.object, config.poly) or decorator_line(draw_line)
|
|
1021
|
+
local draw_poly2 = config.poly2 or decorator_poly(draw_poly, std, config.modes, config.repeats)
|
|
1022
|
+
local draw_verts = decorator_triangle(draw_poly2, std, config.triangle)
|
|
1023
|
+
std.draw.poly = decorator_position(engine, draw_verts)
|
|
1024
|
+
end
|
|
1025
|
+
local P = {
|
|
1026
|
+
install=install
|
|
1027
|
+
}
|
|
1028
|
+
return P
|
|
1029
|
+
end
|
|
1030
|
+
--
|
|
1031
|
+
core_src_lib_engine_raw_memory = function()
|
|
1032
|
+
local memory_dict_unload = {}
|
|
1033
|
+
local memory_dict = {}
|
|
1034
|
+
local memory_list = {}
|
|
1035
|
+
local function cache(key, load_func, unload_func)
|
|
1036
|
+
if memory_dict[key] then
|
|
1037
|
+
return memory_dict[key]
|
|
1038
|
+
end
|
|
1039
|
+
if not load_func then
|
|
1040
|
+
return nil
|
|
1041
|
+
end
|
|
1042
|
+
local value = load_func()
|
|
1043
|
+
memory_list[#memory_list + 1] = key
|
|
1044
|
+
memory_dict_unload[key] = unload_func
|
|
1045
|
+
memory_dict[key] = value
|
|
1046
|
+
return value
|
|
1047
|
+
end
|
|
1048
|
+
local function unset(key)
|
|
1049
|
+
if memory_dict_unload[key] then
|
|
1050
|
+
memory_dict_unload[key](memory_dict[key])
|
|
1051
|
+
end
|
|
1052
|
+
memory_dict[key] = nil
|
|
1053
|
+
end
|
|
1054
|
+
local function gc_clear_all()
|
|
1055
|
+
local index = 1
|
|
1056
|
+
local items = #memory_list
|
|
1057
|
+
while index <= items do
|
|
1058
|
+
unset(memory_list[index])
|
|
1059
|
+
index = index + 1
|
|
1060
|
+
end
|
|
1061
|
+
memory_list = {}
|
|
1062
|
+
return items
|
|
1063
|
+
end
|
|
1064
|
+
local function install(std)
|
|
1065
|
+
std = std or {}
|
|
1066
|
+
std.mem = std.mem or {}
|
|
1067
|
+
std.mem.cache = cache
|
|
1068
|
+
std.mem.unset = unset
|
|
1069
|
+
std.mem.gc_clear_all = gc_clear_all
|
|
1070
|
+
return {
|
|
1071
|
+
mem=std.mem
|
|
1072
|
+
}
|
|
1073
|
+
end
|
|
1074
|
+
local P = {
|
|
1075
|
+
install=install
|
|
1076
|
+
}
|
|
1077
|
+
return P
|
|
1078
|
+
end
|
|
1079
|
+
--
|
|
1080
|
+
core_src_lib_object_root = function()
|
|
1081
|
+
local P = {
|
|
1082
|
+
data={
|
|
1083
|
+
width=1280,
|
|
1084
|
+
height=720
|
|
1085
|
+
},
|
|
1086
|
+
meta={
|
|
1087
|
+
id='',
|
|
1088
|
+
title='',
|
|
1089
|
+
author='',
|
|
1090
|
+
company='',
|
|
1091
|
+
description='',
|
|
1092
|
+
version=''
|
|
1093
|
+
},
|
|
1094
|
+
config = {
|
|
1095
|
+
offset_x = 0,
|
|
1096
|
+
offset_y = 0,
|
|
1097
|
+
require = '',
|
|
1098
|
+
fps_max = 100,
|
|
1099
|
+
fps_show = 0,
|
|
1100
|
+
fps_drop = 5,
|
|
1101
|
+
fps_time = 5
|
|
1102
|
+
},
|
|
1103
|
+
callbacks={
|
|
1104
|
+
}
|
|
1105
|
+
}
|
|
1106
|
+
return P;
|
|
1107
|
+
end
|
|
1108
|
+
--
|
|
1109
|
+
core_src_lib_object_color = function()
|
|
1110
|
+
local white = 0xFFFFFFFF
|
|
1111
|
+
local lightgray = 0xC8CCCCFF
|
|
1112
|
+
local gray = 0x828282FF
|
|
1113
|
+
local darkgray = 0x505050FF
|
|
1114
|
+
local yellow = 0xFDF900FF
|
|
1115
|
+
local gold = 0xFFCB00FF
|
|
1116
|
+
local orange = 0xFFA100FF
|
|
1117
|
+
local pink = 0xFF6DC2FF
|
|
1118
|
+
local red = 0xE62937FF
|
|
1119
|
+
local maroon = 0xBE2137FF
|
|
1120
|
+
local green = 0x00E430FF
|
|
1121
|
+
local lime = 0x009E2FFF
|
|
1122
|
+
local darkgreen = 0x00752CFF
|
|
1123
|
+
local skyblue = 0x66BFFFFF
|
|
1124
|
+
local blue = 0x0079F1FF
|
|
1125
|
+
local darkblue = 0x0052ACFF
|
|
1126
|
+
local purple = 0xC87AFFFF
|
|
1127
|
+
local violet = 0x873CBEFF
|
|
1128
|
+
local darkpurple = 0x701F7EFF
|
|
1129
|
+
local beige = 0xD3B083FF
|
|
1130
|
+
local brown = 0x7F6A4FFF
|
|
1131
|
+
local darkbrown = 0x4C3F2FFF
|
|
1132
|
+
local black = 0x000000FF
|
|
1133
|
+
local blank = 0x00000000
|
|
1134
|
+
local magenta = 0xFF00FFFF
|
|
1135
|
+
local function install(std)
|
|
1136
|
+
std = std or {}
|
|
1137
|
+
std.color = std.color or {}
|
|
1138
|
+
std.color.white = white
|
|
1139
|
+
std.color.lightgray = lightgray
|
|
1140
|
+
std.color.gray = gray
|
|
1141
|
+
std.color.darkgray = darkgray
|
|
1142
|
+
std.color.yellow = yellow
|
|
1143
|
+
std.color.gold = gold
|
|
1144
|
+
std.color.orange = orange
|
|
1145
|
+
std.color.pink = pink
|
|
1146
|
+
std.color.red = red
|
|
1147
|
+
std.color.maroon = maroon
|
|
1148
|
+
std.color.green = green
|
|
1149
|
+
std.color.lime = lime
|
|
1150
|
+
std.color.darkgreen = darkgreen
|
|
1151
|
+
std.color.skyblue = skyblue
|
|
1152
|
+
std.color.blue = blue
|
|
1153
|
+
std.color.darkblue = darkblue
|
|
1154
|
+
std.color.purple = purple
|
|
1155
|
+
std.color.violet = violet
|
|
1156
|
+
std.color.darkpurple = darkpurple
|
|
1157
|
+
std.color.beige = beige
|
|
1158
|
+
std.color.brown = brown
|
|
1159
|
+
std.color.darkbrown = darkbrown
|
|
1160
|
+
std.color.black = black
|
|
1161
|
+
std.color.blank = blank
|
|
1162
|
+
std.color.magenta = magenta
|
|
1163
|
+
return std.color
|
|
1164
|
+
end
|
|
1165
|
+
local P = {
|
|
1166
|
+
install = install
|
|
1167
|
+
}
|
|
1168
|
+
return P
|
|
1169
|
+
end
|
|
1170
|
+
--
|
|
1171
|
+
core_src_lib_object_std = function()
|
|
1172
|
+
local P = {
|
|
1173
|
+
milis = 0,
|
|
1174
|
+
delta = 0,
|
|
1175
|
+
math = {
|
|
1176
|
+
},
|
|
1177
|
+
draw = {
|
|
1178
|
+
image = function() end,
|
|
1179
|
+
clear = function () end,
|
|
1180
|
+
color = function () end,
|
|
1181
|
+
rect = function () end,
|
|
1182
|
+
line = function () end,
|
|
1183
|
+
poly = function () end,
|
|
1184
|
+
tui_text = function() end
|
|
1185
|
+
},
|
|
1186
|
+
text = {
|
|
1187
|
+
put = function() end,
|
|
1188
|
+
print = function() end,
|
|
1189
|
+
mensure = function() end,
|
|
1190
|
+
font_size = function() end,
|
|
1191
|
+
font_name = function() end,
|
|
1192
|
+
font_default = function() end
|
|
1193
|
+
},
|
|
1194
|
+
app = {
|
|
1195
|
+
width = 1280,
|
|
1196
|
+
height = 720,
|
|
1197
|
+
title = function() end,
|
|
1198
|
+
reset = function () end,
|
|
1199
|
+
load = function() end,
|
|
1200
|
+
exit = function () end
|
|
1201
|
+
},
|
|
1202
|
+
key = {
|
|
1203
|
+
axis = {
|
|
1204
|
+
x = 0,
|
|
1205
|
+
y = 0,
|
|
1206
|
+
menu=0,
|
|
1207
|
+
up=0,
|
|
1208
|
+
down=0,
|
|
1209
|
+
left=0,
|
|
1210
|
+
right=0,
|
|
1211
|
+
a = 0,
|
|
1212
|
+
b = 0,
|
|
1213
|
+
c = 0,
|
|
1214
|
+
d = 0
|
|
1215
|
+
},
|
|
1216
|
+
press = {
|
|
1217
|
+
menu=false,
|
|
1218
|
+
up=false,
|
|
1219
|
+
down=false,
|
|
1220
|
+
left=false,
|
|
1221
|
+
right=false,
|
|
1222
|
+
a=false,
|
|
1223
|
+
b=false,
|
|
1224
|
+
c=false,
|
|
1225
|
+
d=false
|
|
1226
|
+
}
|
|
1227
|
+
}
|
|
1228
|
+
}
|
|
1229
|
+
return P;
|
|
1230
|
+
end
|
|
1231
|
+
--
|
|
1232
|
+
core_src_lib_util_pipeline = function()
|
|
1233
|
+
local function pipe(self)
|
|
1234
|
+
return function()
|
|
1235
|
+
self:run()
|
|
1236
|
+
end
|
|
1237
|
+
end
|
|
1238
|
+
local function stop(self)
|
|
1239
|
+
if self.pipeline and not self.pipeline2 then
|
|
1240
|
+
self.pipeline2 = self.pipeline
|
|
1241
|
+
self.pipeline = nil
|
|
1242
|
+
end
|
|
1243
|
+
end
|
|
1244
|
+
local function resume(self)
|
|
1245
|
+
if not self.pipeline and self.pipeline2 then
|
|
1246
|
+
self.pipeline = self.pipeline2
|
|
1247
|
+
self.pipeline2 = nil
|
|
1248
|
+
self:run()
|
|
1249
|
+
end
|
|
1250
|
+
end
|
|
1251
|
+
local function run(self)
|
|
1252
|
+
self.pipeline_current = self.pipeline_current or 1
|
|
1253
|
+
while self.pipeline and self.pipeline_current and self.pipeline_current <= #self.pipeline do
|
|
1254
|
+
self.pipeline[self.pipeline_current]()
|
|
1255
|
+
if self.pipeline_current then
|
|
1256
|
+
self.pipeline_current = self.pipeline_current + 1
|
|
1257
|
+
end
|
|
1258
|
+
end
|
|
1259
|
+
return self
|
|
1260
|
+
end
|
|
1261
|
+
local function reset(self)
|
|
1262
|
+
self.pipeline = self.pipeline or self.pipeline2
|
|
1263
|
+
self.pipeline2 = nil
|
|
1264
|
+
self.pipeline_current = nil
|
|
1265
|
+
end
|
|
1266
|
+
local function clear(self)
|
|
1267
|
+
self.pipeline_current = nil
|
|
1268
|
+
self.pipeline2 = nil
|
|
1269
|
+
self.pipeline = nil
|
|
1270
|
+
end
|
|
1271
|
+
local P = {
|
|
1272
|
+
reset=reset,
|
|
1273
|
+
clear=clear,
|
|
1274
|
+
pipe=pipe,
|
|
1275
|
+
stop=stop,
|
|
1276
|
+
resume=resume,
|
|
1277
|
+
run=run
|
|
1278
|
+
}
|
|
1279
|
+
return P
|
|
1280
|
+
end
|
|
1281
|
+
--
|
|
1282
|
+
core_src_lib_util_decorator = function()
|
|
1283
|
+
local function decorator_prefix3(zig, zag, zom, func)
|
|
1284
|
+
return function (a, b, c, d, e, f)
|
|
1285
|
+
return func(zig, zag, zom, a, b, c, d, e, f)
|
|
1286
|
+
end
|
|
1287
|
+
end
|
|
1288
|
+
local function decorator_prefix2(zig, zag, func)
|
|
1289
|
+
return function (a, b, c, d, e, f)
|
|
1290
|
+
return func(zig, zag, a, b, c, d, e, f)
|
|
1291
|
+
end
|
|
1292
|
+
end
|
|
1293
|
+
local function decorator_prefix1(zig, func)
|
|
1294
|
+
return function (a, b, c, d, e, f)
|
|
1295
|
+
return func(zig, a, b, c, d, e, f)
|
|
1296
|
+
end
|
|
1297
|
+
end
|
|
1298
|
+
local function decorator_offset_xy2(object, func)
|
|
1299
|
+
return function(a, b, c, d, e, f)
|
|
1300
|
+
local x = object.offset_x + (b or 0)
|
|
1301
|
+
local y = object.offset_y + (c or 0)
|
|
1302
|
+
return func(a, x, y, d, e, f)
|
|
1303
|
+
end
|
|
1304
|
+
end
|
|
1305
|
+
local function decorator_offset_xyxy1(object, func)
|
|
1306
|
+
return function(a, b, c, d, e, f)
|
|
1307
|
+
local x1 = object.offset_x + a
|
|
1308
|
+
local y1 = object.offset_y + b
|
|
1309
|
+
local x2 = object.offset_x + c
|
|
1310
|
+
local y2 = object.offset_y + d
|
|
1311
|
+
return func(x1, y1, x2, y2, e, f)
|
|
1312
|
+
end
|
|
1313
|
+
end
|
|
1314
|
+
local function decorator_offset_xy1(object, func)
|
|
1315
|
+
return function(a, b, c, d, e, f)
|
|
1316
|
+
local x = object.offset_x + a
|
|
1317
|
+
local y = object.offset_y + b
|
|
1318
|
+
return func(x, y, c, d, e, f)
|
|
1319
|
+
end
|
|
1320
|
+
end
|
|
1321
|
+
local P = {
|
|
1322
|
+
offset_xy1 = decorator_offset_xy1,
|
|
1323
|
+
offset_xy2 = decorator_offset_xy2,
|
|
1324
|
+
offset_xyxy1 = decorator_offset_xyxy1,
|
|
1325
|
+
prefix3 = decorator_prefix3,
|
|
1326
|
+
prefix2 = decorator_prefix2,
|
|
1327
|
+
prefix1 = decorator_prefix1
|
|
1328
|
+
}
|
|
1329
|
+
return P
|
|
1330
|
+
end
|
|
1331
|
+
--
|
|
1332
|
+
return main()
|
package/package.json
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@gamely/gly-engine-lite",
|
|
3
|
+
"version": "0.0.14",
|
|
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/index.lua",
|
|
12
|
+
"keywords": [
|
|
13
|
+
"game engine",
|
|
14
|
+
"game",
|
|
15
|
+
"engine"
|
|
16
|
+
]
|
|
17
|
+
}
|