local bb0408a = {0,0,0,0,0,0,0,0,0,0,0,0,0}
local rb0408a = function(i, f)
return function()
local c = f()
bb0408a[i] = function() return c end
return c
end
end
local math = ((function() local x, y = pcall(require, 'math'); return x and y end)()) or _G.math
local function mb0408a()
local version = bb0408a[1]('source_version')
local engine_game = bb0408a[2]('source_engine_api_system_app')
local engine_key = bb0408a[3]('source_engine_api_system_key')
local engine_math = bb0408a[4]('source_engine_api_math_basic')
local engine_math_clib = bb0408a[5]('source_engine_api_math_clib')
local engine_math_random = bb0408a[6]('source_engine_api_math_random')
local engine_api_draw_text = bb0408a[7]('source_engine_api_draw_text')
local engine_api_draw_poly = bb0408a[8]('source_engine_api_draw_poly')
local engine_raw_memory = bb0408a[9]('source_engine_api_raw_memory')
local color = bb0408a[10]('source_engine_api_system_color')
local std = bb0408a[11]('source_shared_var_object_std')
local eval_code = bb0408a[12]('source_shared_string_eval_code')
local f=function(a,b)end
local engine={keyboard=f}
local application={
meta={title='', version=''},
data={width=1280,height=720},
config={offset_x=0,offset_y=0},
callbacks={loop=f,draw=f,exit=f,init=f}
}
std.log={fatal=f,error=f,warn=f,info=f,debug=f}
std.bus={emit=f,emit_next=f,listen=f,listen_std_engine=f}
local cfg_system={
exit=native_system_exit,
reset=native_system_reset,
title=native_system_title,
get_fps=native_system_get_fps,
get_secret=native_system_get_secret
}
local cfg_poly={
repeats={
native_cfg_poly_repeat_0 or false,
native_cfg_poly_repeat_1 or false,
native_cfg_poly_repeat_2 or false
},
triangle=native_draw_triangle,
poly2=native_draw_poly2,
poly=native_draw_poly,
line=native_draw_line
}
local cfg_text={
is_tui = native_text_is_tui,
font_previous=native_text_font_previous
}
function native_callback_loop(dt)
std.milis, std.delta=std.milis + dt, dt
application.callbacks.loop(application.data, std)
end
function native_callback_draw()
native_draw_start()
application.callbacks.draw(application.data, std)
native_draw_flush()
end
function native_callback_resize(width, height)
application.data.width=width
application.data.height=height
std.app.width=width
std.app.height=height
end
function native_callback_keyboard(key, value)
engine.keyboard(std, engine, key, value)
end
function native_callback_init(width, height, game_lua)
local ok, script=true, game_lua
if type(script) == 'string' then
ok, script = eval_code.script(script)
end
if type(script) == 'function' then
ok, script = pcall(script)
end
if not script then
ok, script=pcall(loadfile, 'game.lua')
end
if not ok or not script then
error(script, 0)
end
std.app.width=width
std.app.height=height
script.data={width=width,height=height}
script.config=application.config
application=script
std.draw.color=native_draw_color
std.draw.font=native_draw_font
std.draw.rect2=native_draw_rect2 or native_draw_rect
std.draw.rect=native_draw_rect
std.draw.line=native_draw_line
std.image.load=native_image_load
std.image.draw=native_image_draw
std.image.mensure=native_image_mensure
std.text.print=native_text_print
std.text.mensure=native_text_mensure
std.text.font_size=native_text_font_size
std.text.font_name=native_text_font_name
std.text.font_default=native_text_font_default
std.draw.clear=function(tint)
native_draw_clear(tint, 0, 0, application.data.width, application.data.height)
end
engine.root=application
color.install(std, engine)
engine_raw_memory.install(std, engine)
engine_game.install(std, engine, cfg_system)
engine_key.install(std, engine, {})
engine_api_draw_text.install(std, engine, cfg_text)
engine_api_draw_poly.install(std, engine, cfg_poly)
engine_math.install(std, engine)
if math or flr then engine_math_clib.install(std, engine) end
if math then engine_math_random.install(std, engine) end
if application.meta and application.meta.title then
std.app.title(application.meta.title..' - '..(application.meta.version or ''))
end
engine.current=application
application.callbacks.init(application.data, std)
end
local P={
meta={
title='gly-engine-micro',
author='RodrigoDornelles',
description='shh!',
version=version
}
}
return P
end
bb0408a[1] = rb0408a(1, function()
return '0.4.0'
end)
bb0408a[2] = rb0408a(2, function()
local function reset(std, engine)
if std.node then
return function()
std.bus.emit('exit')
std.bus.emit('init')
end
end
return function()
engine.root.callbacks.exit(engine.root.data, std)
engine.root.callbacks.init(engine.root.data, std)
end
end
local function exit(std)
return function()
std.bus.emit('exit')
std.bus.emit('quit')
end
end
local function title(func)
return function(window_name)
if func then
func(window_name)
end
end
end
local function get_info(my, info)
return function()
return my.root.meta[info]
end
end
local function install(std, engine, config)
std = std or {}
config = config or {}
std.app = std.app or {}
std.bus.listen('post_quit', config.quit or config.exit or function() end)
std.app.title = title(config.set_title)
std.app.exit = exit(std)
std.app.reset = reset(std, engine)
std.app.get_name = get_info(engine, 'title')
std.app.get_version = get_info(engine, 'version')
std.app.get_fps = config.get_fps
return std.app
end
local P = {
install=install
}
return P
end)
bb0408a[3] = rb0408a(3, function()
local function real_key(std, engine, rkey, rvalue)
local value = (rvalue == 1 or rvalue == true) or false
local key = engine.key_bindings[rkey] or rkey
if std.key.press[key] ~= nil or not engine.keyboard_lock then
std.key.press[key] = value
if key == 'right' or key == 'left' then
std.key.axis.x = (std.key.press['right'] and 1 or 0) - (std.key.press['left'] and 1 or 0) 
end
if key == 'down' or key == 'up' then
std.key.axis.y = (std.key.press['down'] and 1 or 0) - (std.key.press['up'] and 1 or 0)
end
std.key.any = false
for _, pressed in pairs(std.key.press) do
if pressed then std.key.any = true end
end
if std.bus and std.bus.emit and engine.keyboard_lock then
std.bus.emit('key', key, value)
end
end
end
local function real_keydown(std, engine, key)
real_key(std, engine, key, 1)
end
local function real_keyup(std, engine, key)
real_key(std, engine, key, 0)
end
local function install(std, engine, config)
config = config or {}
engine.key_bindings = config.bindings or {}
engine.keyboard = real_key
for _, key in pairs(engine.key_bindings) do
real_key(std, engine, key, false)
end
if std.bus.listen_std_engine then
std.bus.listen('load', function() engine.keyboard_lock = true end)
std.bus.listen_std_engine('rkey', real_key)
std.bus.listen_std_engine('rkey1', real_keydown)
std.bus.listen_std_engine('rkey0', real_keyup)
end
end
return {
install = install
}
end)
bb0408a[4] = rb0408a(4, function()
local function abs(value)
if value < 0 then
return -value
end
return value
end
local function clamp(value, value_min, value_max)
if value < value_min then
return value_min
elseif value > value_max then
return value_max
else
return value
end
end
local function clamp2(value, value_min, value_max)
return (value - value_min) % (value_max - value_min + 1) + value_min
end
local function dir(value, alpha)
alpha = alpha or 0
if value < -alpha then
return -1
elseif value > alpha then
return 1
else
return 0
end
end
local function dis(x1,y1,x2,y2)
local sqr = 1/2
return ((x2 - x1) ^ 2 + (y2 - y1) ^ 2) ^ (sqr ~= 0 and sqr or 1)
end
local function dis2(x1,y1,x2,y2)
return (x2 - x1) ^ 2 + (y2 - y1) ^ 2
end
local function dis3(x1,y1,x2,y2)
return abs(x1 - x2) + abs(x2 - y2)
end
local function lerp(a, b, alpha)
return a + alpha * ( b - a )
end 
local function map(value, in_min, in_max, out_min, out_max)
return (value - in_min) * (out_max - out_min) / (in_max - in_min) + out_min
end
local function max(...)
local args = {...}
local index = 1
local value = nil
local max_value = nil
if #args == 1 then
args = args[1]
end
while index <= #args do
value = args[index]
if max_value == nil or value > max_value then
max_value = value
end
index = index + 1
end
return max_value
end
local function min(...)
local args = {...}
local index = 1
local value = nil
local min_value = nil
if #args == 1 then
args = args[1]
end
while index <= #args do
value = args[index]
if min_value == nil or value < min_value then
min_value = value
end
index = index + 1
end
return min_value
end
local function install(std)
std.math = std.math or {}
std.math.abs=abs
std.math.clamp=clamp
std.math.clamp2=clamp2
std.math.dir=dir
std.math.dis=dis
std.math.dis2=dis2
std.math.dis3=dis3
std.math.lerp=lerp
std.math.map=map
std.math.max=max
std.math.min=min
end
local P = {
install = install
}
return P
end)
bb0408a[5] = rb0408a(5, function()
local function install(std)
assert(math and (1/2 ~= 0))
std.math = std.math or {}
std.math.acos=math.acos
std.math.asin=math.asin
std.math.atan=math.atan
std.math.atan2=math.atan2
std.math.ceil=math.ceil
std.math.cos=math.cos
std.math.cosh=math.cosh
std.math.deg=math.deg
std.math.exp=math.exp
std.math.floor=math.floor
std.math.fmod=math.fmod
std.math.frexp=math.frexp
std.math.huge=math.huge
std.math.ldexp=math.ldexp
std.math.log=math.log
std.math.log10=math.log10
std.math.modf=math.modf
std.math.pi=math.pi
std.math.pow=math.pow
std.math.rad=math.rad
std.math.sin=math.sin
std.math.sinh=math.sinh
std.math.sqrt=math.sqrt
std.math.tan=math.tan
std.math.tanh=math.tanh
end
local P = {
install = install
}
return P
end)
bb0408a[6] = rb0408a(6, function()
local function install(std)
assert(math and (1/2 ~= 0))
std.math = std.math or {}
std.math.random = function(a, b)
a = a and math.floor(a)
b = b and math.floor(b)
if a > b then a, b = b, a end
return math.random(a, b)
end
end
local P = {
install = install
}
return P
end)
bb0408a[7] = rb0408a(7, function()
local function text_put(std, engine, font_previous)
return function(pos_x, pos_y, text, size)
size = size or 2
local hem = engine.current.data.width / 80
local vem = engine.current.data.height / 24
local font_size = hem * size
std.text.font_default(0)
std.text.font_size(font_size)
std.text.print(pos_x * hem, pos_y * vem, text)
font_previous()
end
end
local function text_print_ex(std, engine)
return function(x, y, text, align_x, align_y)
local w, h = std.text.mensure(text)
local aligns_x, aligns_y = {w, w/2, 0}, {h, h/2, 0}
std.text.print(x - aligns_x[(align_x or 1) + 2], y - aligns_y[(align_y or 1) + 2], text)
return w, h
end
end
local function install(std, engine, config)
std.text.font_previous = config.font_previous
std.text.is_tui = config.is_tui or function() return false end
std.text.print_ex = text_print_ex(std, engine)
std.text.put = text_put(std, engine, config.font_previous)
end
local P = {
install=install
}
return P
end)
bb0408a[8] = rb0408a(8, function()
local function decorator_poo(object, func)
if not object or not func then return func end
return function(a, b, c, d)
return func(object, a, b, c, d)
end
end
local function decorator_line(func_draw_line)
return function(mode, verts)
local index = 4
while index <= #verts do
func_draw_line(verts[index - 3], verts[index - 2], verts[index - 1], verts[index])
index = index + 2
end
end
end
local function decorator_triangle(func_draw_poly, std, func_draw_triangle)
if not func_draw_triangle then
return func_draw_poly
end
local point = function(x, y, px, py, scale, angle, ox, oy)
local xx = x + ((ox - px) * -scale * std.math.cos(angle)) - ((ox - py) * -scale * std.math.sin(angle))
local yy = y + ((oy - px) * -scale * std.math.sin(angle)) + ((oy - py) * -scale * std.math.cos(angle))
return xx, yy
end
return function(engine_mode, verts, x, y, scale, angle, ox, oy)
if #verts ~= 6 then
return func_draw_poly(engine_mode, verts, x, y, scale, angle, ox, oy)
end
ox = ox or 0
oy = oy or ox or 0
local x1, y1 = point(x, y, verts[1], verts[2], scale, angle, ox, oy)
local x2, y2 = point(x, y, verts[3], verts[4], scale, angle, ox, oy)
local x3, y3 = point(x, y, verts[5], verts[6], scale, angle, ox, oy)
return func_draw_triangle(engine_mode, x1, y1, x2, y2, x3, y3)
end
end
local function decorator_poly(func_draw_poly, std, modes, repeats)
local func_repeat = function(verts, mode)
if repeats and repeats[mode + 1] then
verts[#verts + 1] = verts[1]
verts[#verts + 1] = verts[2]
end
end
return function (engine_mode, verts, x, y, scale, angle, ox, oy)
if #verts < 6 or #verts % 2 ~= 0 then return end
local mode = modes and modes[engine_mode + 1] or engine_mode
local rotated = std.math.cos and angle and angle ~= 0
ox = ox or 0
oy = oy or ox or 0
if x and y and not rotated then
local index = 1
local verts2 = {}
scale = scale or 1
while index <= #verts do
if index % 2 ~= 0 then
verts2[index] = x + (verts[index] * scale)
else
verts2[index] = y + (verts[index] * scale)
end
index = index + 1
end
func_repeat(verts2, engine_mode)
func_draw_poly(mode, verts2)
elseif x and y then
local index = 1
local verts2 = {}
while index < #verts do
local px = verts[index]
local py = verts[index + 1]
local xx = x + ((ox - px) * -scale * std.math.cos(angle)) - ((ox - py) * -scale * std.math.sin(angle))
local yy = y + ((oy - px) * -scale * std.math.sin(angle)) + ((oy - py) * -scale * std.math.cos(angle))
verts2[index] = xx
verts2[index + 1] = yy
index = index + 2
end
func_repeat(verts2, engine_mode)
func_draw_poly(mode, verts2)
else
func_draw_poly(mode, verts)
end
end
end
local function decorator_position(engine, func)
return function(mode, verts, pos_x, pos_y, scale, angle, ox, oy)
local x = engine.current.config.offset_x + (pos_x or 0)
local y = engine.current.config.offset_y + (pos_y or 0)
ox = ox or 0
oy = ox or oy or 0
scale = scale or 1
angle = angle or 0
return func(mode, verts, x, y, scale, angle, ox, oy)
end
end
local function install(std, engine, config)
local draw_line = decorator_poo(config.object, config.line)
local draw_poly = decorator_poo(config.object, config.poly) or decorator_line(draw_line)
local draw_poly2 = config.poly2 or decorator_poly(draw_poly, std, config.modes, config.repeats)
local draw_verts = decorator_triangle(draw_poly2, std, config.triangle)
std.draw.poly = decorator_position(engine, draw_verts)
end
local P = {
install=install
}
return P
end)
bb0408a[9] = rb0408a(9, function()
local memory_dict_unload = {}
local memory_dict = {}
local memory_list = {}
local function cache_get(key)
return memory_dict[key]
end
local function cache_set(key, load_func, unload_func)
local value = load_func()
memory_list[#memory_list + 1] = key
memory_dict_unload[key] = unload_func
memory_dict[key] = value
end
local function cache(key, load_func, unload_func)
local value = cache_get(key)
if value == nil then
cache_set(key, load_func, unload_func)
value = cache_get(key)
end    
return value
end
local function unset(key)
if memory_dict_unload[key] then
memory_dict_unload[key](memory_dict[key])
end
memory_dict[key] = nil
end
local function gc_clear_all()
local index = 1
local items = #memory_list
while index <= items do
unset(memory_list[index])
index = index + 1
end
memory_list = {}
return items
end
local function install(std)
std = std or {}
std.mem = std.mem or {}
std.mem.cache = cache
std.mem.cache_get = cache_get
std.mem.cache_set = cache_set
std.mem.unset = unset
std.mem.gc_clear_all = gc_clear_all
return {
mem=std.mem
}
end
local P = {
install=install
}
return P
end)
bb0408a[10] = rb0408a(10, function()
local function install(std)
std.color = std.color or {}
std.color.white = 0xFFFFFFFF
std.color.lightgray = 0xC8CCCCFF
std.color.gray = 0x828282FF
std.color.darkgray = 0x505050FF
std.color.yellow = 0xFDF900FF
std.color.gold = 0xFFCB00FF
std.color.orange = 0xFFA100FF
std.color.pink = 0xFF6DC2FF
std.color.red = 0xE62937FF
std.color.maroon = 0xBE2137FF
std.color.green = 0x00E430FF
std.color.lime = 0x009E2FFF
std.color.darkgreen = 0x00752CFF
std.color.skyblue = 0x66BFFFFF
std.color.blue = 0x0079F1FF
std.color.darkblue = 0x0052ACFF
std.color.purple = 0xC87AFFFF
std.color.violet = 0x873CBEFF
std.color.darkpurple = 0x701F7EFF
std.color.beige = 0xD3B083FF
std.color.brown = 0x7F6A4FFF
std.color.darkbrown = 0x4C3F2FFF
std.color.black = 0x000000FF
std.color.blank = 0x00000000
std.color.magenta = 0xFF00FFFF
end
local P = {
install = install
}
return P
end)
bb0408a[11] = rb0408a(11, function()
local P = {
milis = 0,
delta = 0,
math = {
},
media = {
},
draw = {
image = function() end,
clear = function () end,
color = function () end,
rect = function () end,
line = function () end,
poly = function () end,
tui_text = function() end
},
text = {
put = function() end,
print = function() end,
mensure = function() end,
font_size = function() end,
font_name = function() end,
font_default = function() end
},
image = {
load = function() end,
draw = function() end
},
app = {
width = 1280,
height = 720,
title = function() end,
reset = function () end,
load = function() end,
exit = function () end
},
key = {
any = false,
axis = {
x = 0,
y = 0,
},
press = {
menu=false,
up=false,
down=false,
left=false,
right=false,
a=false,
b=false,
c=false,
d=false
}
}
}
return P;
end)
bb0408a[12] = rb0408a(12, function()
local function script(src)
local loader = loadstring or load
if not loader then
error('eval not allowed')
end
local ok, chunk = pcall(loader, src)
if not ok then
return false, chunk
end
if type(chunk) ~= 'function' then
return false, 'failed to eval code'
end
return pcall(chunk)
end
local P = {
script = script,
}
return P
end)
return mb0408a()
