local bcbd = {0,0,0,0,0,0,0}
local rcbd = function(i, f)
return function()
local c = f()
bcbd[i] = function() return c end
return c
end
end
local function mcbd()
local version = bcbd[1]('source_version')
local engine_key = bcbd[2]('source_engine_api_system_key')
local engine_api_draw_text = bcbd[3]('source_engine_api_draw_text')
local engine_api_draw_poly = bcbd[4]('source_engine_api_draw_poly')
local color = bcbd[5]('source_engine_api_system_color')
local std = bcbd[6]('source_shared_var_object_std')
local eval_code = bcbd[7]('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_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 not script then
ok, script = pcall(loadfile, 'game.lua')
end
if type(script) == 'function' then
ok, script = pcall(script)
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
std.app.reset = function()
(application.callbacks.exit or function() end)(application.data, std)
application.callbacks.init(application.data, std)
end
engine.root=application
color.install(std, engine)
engine_key.install(std, engine, {})
engine_api_draw_text.install(std, engine, cfg_text)
engine_api_draw_poly.install(std, engine, cfg_poly)
engine.current=application
application.callbacks.init(application.data, std)
end
local P={
meta={
title='gly-engine-nano',
author='RodrigoDornelles',
description='shh!',
version=version
}
}
return P
end
bcbd[1] = rcbd(1, function()
return '0.3.13'
end)
bcbd[2] = rcbd(2, 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)
bcbd[3] = rcbd(3, 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)
bcbd[4] = rcbd(4, 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)
bcbd[5] = rcbd(5, 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)
bcbd[6] = rcbd(6, 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)
bcbd[7] = rcbd(7, 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 mcbd()
