local b15e1 = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0}
local r15e1 = function(i, f)
return function()
local c = f()
b15e1[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 m15e1()
local version = b15e1[1]('source_version')
local engine_game = b15e1[2]('source_engine_api_system_app')
local engine_key = b15e1[3]('source_engine_api_system_key')
local engine_math = b15e1[4]('source_engine_api_math_basic')
local engine_math_clib = b15e1[5]('source_engine_api_math_clib')
local engine_math_random = b15e1[6]('source_engine_api_math_random')
local engine_array = b15e1[7]('source_engine_api_data_array')
local engine_api_draw_text = b15e1[8]('source_engine_api_draw_text')
local engine_api_draw_poly = b15e1[9]('source_engine_api_draw_poly')
local engine_raw_memory = b15e1[10]('source_engine_api_raw_memory')
local color = b15e1[11]('source_engine_api_system_color')
local std = b15e1[12]('source_shared_var_object_std')
local eval_code = b15e1[13]('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}
std.i18n={next=f,back=f,get_language=function()return'en-US'end}
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,
get_language=native_system_get_language
}
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_array.install(std, engine, nil, 'array')
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
b15e1[1] = r15e1(1, function()
return '0.3.13'
end)
b15e1[2] = r15e1(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)
b15e1[3] = r15e1(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 (std.key.axis[rkey] and rkey)
local key_media = std.key.media and std.key.media[rkey] ~= nil and rkey
if key_media then
std.key.media[key_media] = value
std.bus.emit('key_media')
end
if key then
std.key.axis[key] = value and 1 or 0
std.key.press[key] = value
if key == 'right' or key == 'left' then
std.key.axis.x = std.key.axis.right - std.key.axis.left
end
if key == 'down' or key == 'up' then
std.key.axis.y = std.key.axis.down - std.key.axis.up
end
std.bus.emit('key')
end
local a = std.key.axis
std.key.press.any = (a.left + a.right + a.down + a.up + a.a + a.b + a.c + a.d + a.menu) > 0
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
if config.has_media then
std.key.media = {
ch_up = false,
ch_down = false,
vol_up = false,
vol_down = false
}
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
return {
install = install
}
end)
b15e1[4] = r15e1(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)
b15e1[5] = r15e1(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)
b15e1[6] = r15e1(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)
b15e1[7] = r15e1(7, function()
local util_decorator = b15e1[15]('source_shared_functional_decorator')
local function array_map(array, func)
local res = {}
local index = 1
local length = #array
while index <= length do
res[#res + 1] = func(array[index], index)
index = index + 1
end
return res
end
local function array_filter(array, func)
func = func or (function(v) return v and v ~= 0 end)
local res = {}
local index = 1
local length = #array
while index <= length do
local value = array[index]
if func(value, index) then
res[#res + 1] = value
end
index = index + 1
end
return res
end
local function array_unique(array)
local res = {}
local index = 1
local length = #array
local setmap = {}
while index <= length do
local value = array[index]
if not setmap[value] then
res[#res + 1] = value
end
setmap[value] = true
index = index + 1
end
return res
end
local function array_foreach(array, func)
local index = 1
local length = #array
while index <= length do
func(array[index], index)
index = index + 1
end
end
local function array_reducer(array, func, value)
local index = value and 1 or 2
local length = #array
value = value or array[1]
while index <= length do
value = func(value, array[index], index)
index = index + 1
end
return value
end
local function array_index(array, func, reverse)
func = func or function() return true end
local index, inc, final = 1, 1, #array
if reverse then
index, inc, final = #array, -1, 1
end
repeat
if func(array[index], index) then
return index
end
index = index + inc
until (reverse and index < final) or (not reverse and index > final)
return nil
end
local function array_first(array, func)
local index = array_index(array, func)
if index then
return array[index]
end
return nil
end
local function array_last(array, func)
local index = array_index(array, func, true)
if index then
return array[index]
end
return nil
end
local function array_some(array, func, reverse)
local index, inc, final = 1, 1, #array
if reverse then
index, inc, final = #array, -1, 1
end
repeat
if func(array[index], index) then
return true
end
index = index + inc
until (reverse and index < final) or (not reverse and index > final)
return false
end
local function array_every(array, func)
local index = 1
local length = #array
while index <= length do
if not func(array[index], index) then
return false
end
index = index + 1
end
return true
end
local function array_pipeline(std, array)
local decorator_iterator = function(func) 
return function(self, func2, extra)
self.array = func(self.array, func2, extra)
return self
end
end
local decorator_reduce = function(func, return_self)
return function(self, func2, extra)
local res = func(self.array, func2, extra)
return (return_self and self) or res
end
end
local self = {
array = array,
map = decorator_iterator(array_map),
filter = decorator_iterator(array_filter),
unique = decorator_iterator(array_unique),
each = decorator_reduce(array_foreach, true),
reducer = decorator_reduce(array_reducer),
index = decorator_reduce(array_index),
first = decorator_reduce(array_first),
last = decorator_reduce(array_last),
some = decorator_reduce(array_some),
every = decorator_reduce(array_every),
table = function(self) return self.array end,
json = function(self) return std.json.encode(self.array) end
}
return self
end
local function install(std, engine, library, name)
local lib = std[name] or {}
lib.map = array_map
lib.filter = array_filter
lib.unique = array_unique
lib.each = array_foreach
lib.reducer = array_reducer
lib.index = array_index
lib.first = array_first
lib.last = array_last
lib.some = array_some
lib.every = array_every
lib.from = util_decorator.prefix1(std, array_pipeline)
std[name] = lib
end
local P = {
install = install
}
return P
end)
b15e1[8] = r15e1(8, 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)
b15e1[9] = r15e1(9, 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)
b15e1[10] = r15e1(10, 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)
b15e1[11] = r15e1(11, 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)
b15e1[12] = r15e1(12, 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 = {
axis = {
x = 0,
y = 0,
menu=0,
up=0,
down=0,
left=0,
right=0,
a = 0,
b = 0, 
c = 0,
d = 0
},
press = {
menu=false,
up=false,
down=false,
left=false,
right=false,
a=false,
b=false,
c=false,
d=false,
any=false
}
}
}
return P;
end)
b15e1[13] = r15e1(13, 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)
b15e1[15] = r15e1(15, function()
local function decorator_prefix3(zig, zag, zom, func)
return function (a, b, c, d, e, f)
return func(zig, zag, zom, a, b, c, d, e, f)
end
end
local function decorator_prefix2(zig, zag, func)
return function (a, b, c, d, e, f)
return func(zig, zag, a, b, c, d, e, f)
end
end
local function decorator_prefix1(zig, func)
return function (a, b, c, d, e, f)
return func(zig, a, b, c, d, e, f)
end
end
local function decorator_offset_xy2(object, func)
return function(a, b, c, d, e, f)
local x = object.offset_x + (b or 0)
local y = object.offset_y + (c or 0)
return func(a, x, y, d, e, f)
end
end
local function decorator_offset_xyxy1(object, func)
return function(a, b, c, d, e, f)
local x1 = object.offset_x + a
local y1 = object.offset_y + b
local x2 = object.offset_x + c
local y2 = object.offset_y + d
return func(x1, y1, x2, y2, e, f)
end
end
local function decorator_offset_xy1(object, func)
return function(a, b, c, d, e, f)
local x = object.offset_x + a
local y = object.offset_y + b
return func(x, y, c, d, e, f)
end
end
local function table_prefix1(prefix, fn_table)
local new_table = {}
for name, fn in pairs(fn_table) do
new_table[name] = decorator_prefix1(prefix, fn)
end
return new_table
end
local P = {
offset_xy1 = decorator_offset_xy1,
offset_xy2 = decorator_offset_xy2,
offset_xyxy1 = decorator_offset_xyxy1,
prefix3 = decorator_prefix3,
prefix2 = decorator_prefix2,
prefix1 = decorator_prefix1,
prefix1_t = table_prefix1
}
return P
end)
return m15e1()
