@gamely/love2tic
Version:
Convert your love2d games to tic80 cartridges!
520 lines (502 loc) • 12.2 kB
JavaScript
var f=`local math = ((function() local x, y = pcall(require, 'math'); return x and y end)()) or _G.math
local src_audio_55b17c110440 = nil
local src_event_55b17c110830 = nil
local src_filesystem_55b17c110d10 = nil
local src_graphics_55b17c111550 = nil
local src_image_55b17c111e30 = nil
local src_joystick_55b17c111ef0 = nil
local src_keyboard_55b17c1126a0 = nil
local src_lovemath_55b17c113090 = nil
local src_mouse_55b17c113760 = nil
local src_sound_55b17c113800 = nil
local src_system_55b17c1140c0 = nil
local src_timer_55b17c1167a0 = nil
local src_window_55b17c118b00 = nil
local function main_55b17c10b940()
if not arg then
arg = {}
end
if not unpack then
unpack = function(t) return t and table.unpack(t) end
end
love = {
color_r = 1,
color_g = 1,
color_b = 1,
color_a = 1,
load = function() end,
update = function(dt) end,
draw = function() end,
resize = function(w, h) end,
keypressed = function (key, scancode, isrepeat) end,
keyreleased = function (key, scancode) end,
physics = {},
filesystem = {},
graphics = {},
joystick = {},
keyboard = {},
image = {},
timer = {},
system = {},
mouse = {},
math = {},
audio = {},
sound = {},
window = {},
event = {}
}
src_audio_55b17c110440()
src_event_55b17c110830()
src_filesystem_55b17c110d10()
src_graphics_55b17c111550()
src_image_55b17c111e30()
src_joystick_55b17c111ef0()
src_keyboard_55b17c1126a0()
src_lovemath_55b17c113090()
src_mouse_55b17c113760()
src_sound_55b17c113800()
src_system_55b17c1140c0()
src_timer_55b17c1167a0()
src_window_55b17c118b00()
engine = {
width=1280,
height=720,
keys={},
milis=0
}
keybindings = {
}
function love.getVersion()
return 11, 0, 0
end
function native_callback_loop(dt)
engine.milis = engine.milis + dt
love.update(dt/1000)
end
function native_callback_draw()
native_draw_start()
love.draw()
native_draw_flush()
end
function native_callback_resize(width, height)
engine.width = width
engine.height = height
love.resize(w, h)
end
function native_callback_keyboard(vkey, value)
local key = keybindings[vkey] or vkey
if value == true or value == 1 then
engine.keys[key] = true
love.keypressed(key, key, false)
else
engine.keys[key] = false
love.keyreleased(key, key)
end
end
function native_callback_init(width, height, game_lua)
engine.width = width
engine.height = height
native_draw_clear(0x000000FF, 0, 0, engine.width, engine.height)
native_draw_color(0xFFFFFFFF)
native_text_font_size(12)
local ok, app = pcall(loadstring, game_lua)
if not ok then
ok, app = pcall(load, game_lua)
end
while type(app) == 'function' do
app = app()
end
love.load(arg)
end
local function main()
local config_file = io and io.open and io.open('love.json')
if config_file then
local index = 1
local config_content = config_file:read('*a')
local config_table = native_json_decode(config_content) or {}
local key_list = {'a', 'b', 'c', 'd', 'menu', 'up', 'left', 'down', 'right'}
while index <= #key_list do
keybindings[key_list[index]] = config_table['key_'..key_list[index]]
index = index + 1
end
end
pcall(require, 'conf')
end
main()
local P = {
meta={
title='love-engine',
author='RodrigoDornelles',
description='reimplementation of the love2d framework to make homebrew games to gba, nds, wii, ps2 and many other platforms!',
version='0.0.19'
}
}
return P
end
src_audio_55b17c110440 = function()
function love.audio.play()
end
function love.audio.stop()
end
function love.audio.setPosition()
end
function love.audio.newSource()
return {
play = function() end,
stop = function() end,
setLooping = function() end,
setVolume = function() end,
setPosition = function() end,
setAttenuationDistances=function() end,
}
end
end
--
src_event_55b17c110830 = function()
function love.event.quit()
end
end
--
src_filesystem_55b17c110d10 = function()
function love.filesystem.getInfo()
end
function love.filesystem.read()
end
end
--
src_graphics_55b17c111550 = function()
local conversor_frame = {
fill = 0,
line = 1,
frame = 1
}
function love.graphics.print(text, x, y)
return native_text_print(x, y, text)
end
function love.graphics.rectangle(mode, x, y, w, h)
return native_draw_rect(conversor_frame[mode], x, y, w, h)
end
function love.graphics.getColor()
return love.color_r, love.color_g, love.color_b, love.color_a
end
function love.graphics.setColor(r, g, b, a)
love.color_r, love.color_g, love.color_b, love.color_a = r, g, b, a
local color = (r * 0xFF000000) + (g * 0xFF0000) + (b * 0xFF00) + ((a or 1) * 0xFF)
return native_draw_color(color)
end
function love.graphics.clear(r, g, b, a)
local color = (r * 0xFF000000) + (g * 0xFF0000) + (b * 0xFF00) + ((a or 1) * 0xFF)
native_draw_clear(0x000000FF, 0, 0, engine.width, engine.height)
end
function love.graphics.getHeight()
return engine.height
end
function love.graphics.getWidth()
return engine.width
end
function love.graphics.setDefaultFilter()
end
function love.graphics.setBackgroundColor()
end
function love.graphics.setBlendMode()
end
function love.graphics.setShader()
end
function love.graphics.newShader()
return {
send = function() end
}
end
function love.graphics.newCanvas()
return {
renderTo = function() end
}
end
function love.graphics.newFont()
return {}
end
function love.graphics.newImageFont()
return {}
end
function love.graphics.present()
end
function love.graphics.draw(src, x, y)
if src.src and src.t == 'img' then
if type(x) == 'table' then
y, x = x.y, x.x
end
return native_draw_image(src.src, x, y)
end
end
function love.graphics.newImage(src)
return {
t='img',
src=src,
release = function() end,
getWidth = function() return 100 end,
getHeight = function() return 100 end,
setWrap = function() end,
setFilter = function() end,
}
end
function love.graphics.newQuad(x, y, width, height, sw,sh)
return {
t='quad',
x=x,
y=y,
width=width,
height=height
}
end
function love.graphics.newSpriteBatch()
return {
setColor=function() end,
clear=function() end,
add=function() end
}
end
function love.graphics.scale()
end
function love.graphics.translate()
end
function love.graphics.origin()
end
end
--
src_image_55b17c111e30 = function()
function love.image.newImageData(width, height)
return {
paste = function() end,
setPixel = function() end,
getWidth = function() return 100 end,
getHeight = function() return 100 end
}
end
end
--
src_joystick_55b17c111ef0 = function()
function love.joystick.getJoysticks()
return {}
end
end
--
src_keyboard_55b17c1126a0 = function()
function love.keyboard.isDown(key)
return engine.keys[key] == true
end
function love.keyboard.setKeyRepeat()
end
end
--
src_lovemath_55b17c113090 = function()
function love.math.random(foo, bar)
local one = bar and foo or 0
local two = bar or foo
return math.random(one, two)
end
function love.math.newRandomGenerator()
return {
random = function(self)
return math.random(0, 1)
end
}
end
end
--
src_mouse_55b17c113760 = function()
function love.mouse.setVisible()
end
function love.mouse.getPosition()
return 0, 0
end
end
--
src_sound_55b17c113800 = function()
function love.sound.newSoundData()
return {}
end
end
--
src_system_55b17c1140c0 = function()
function love.system.getOS()
return 'Web'
end
end
--
src_timer_55b17c1167a0 = function()
function love.timer.getTime()
return engine.milis
end
end
--
src_window_55b17c118b00 = function()
function love.window.setMode()
end
function love.window.toPixels(w)
return w
end
function love.window.setTitle()
end
function love.window.setIcon()
end
function love.window.getDesktopDimensions()
return engine.width, engine.height
end
end
--
return main_55b17c10b940()
`;var g=`local started = false
local current_color = 12
local font_size, font_previous = 5, 5
local delta, last = 0, time()
local keypress = {}
local keymap = {
'up', 'down', 'left', 'right', 'a', 'b', 'c', 'd'
}
local colormap = {
[0x000000] = 0,
[0x1A1C2C] = 0,
[0xFF00FF] = 1,
[0xFF6DC2] = 1,
[0xC87AFF] = 1,
[0x701F7E] = 1,
[0x873CBE] = 1,
[0x5D275D] = 1,
[0xFF0000] = 2,
[0xE62937] = 2,
[0xBE2137] = 2,
[0xB13E53] = 2,
[0xFFA100] = 3,
[0xFFCB00] = 3,
[0xEF7D57] = 3,
[0xFDF900] = 4,
[0xFFCD75] = 4,
[0x00E430] = 5,
[0xA7F070] = 5,
[0x009E2F] = 6,
[0x38B764] = 6,
[0x00752C] = 7,
[0x38B764] = 7,
[0x0052AC] = 8,
[0x29366F] = 8,
[0x0000FF] = 9,
[0x3B5DC9] = 9,
[0x0079F1] = 10,
[0x41A6F6] = 10,
[0x66BFFF] = 11,
[0x73EFF7] = 11,
[0xFFFFFF] = 12,
[0xF4F4F4] = 12,
[0xC8CCCC] = 13,
[0x94B0C2] = 13,
[0xD3B083] = 13,
[0x828282] = 14,
[0x566C86] = 14,
[0x7F6A4F] = 14,
[0x505050] = 15,
[0x333C57] = 15,
[0x4C3F2F] = 15
}
local function colorid(c)
local colornew = colormap[c>>8]
if not colornew then
local r,g,b = (c>>24) & 255, (c>>16) & 255, (c>>8) & 255
local best,d = nil, math.huge
for k,v in pairs(colormap) do
local kr,kg,kb = (k>>16)&255, (k>>8)&255, k&255
local dist = ((r-kr)^2 + (g-kg)^2 + (b-kb)^2)
if dist < d then d,best = dist,v end
end
colornew = best
end
return colornew
end
function native_draw_start()
end
function native_draw_flush()
end
function native_draw_clear(c)
cls(colorid(c))
end
function native_draw_color(c)
current_color = colorid(c)
end
function native_draw_line(x1, y1, x2, y2)
line(x1, y1, x2, y2, current_color)
end
function native_draw_rect(mode, x, y, w, h)
if mode == 0 then
rect(x, y, w, h, current_color)
else
local x2, y2 = x + w, y + h
line(x, y, x2, y, current_color)
line(x2 , y, x2, y2, current_color)
line(x , y2, x2, y2, current_color)
line(x , y, x, y2, current_color)
end
end
function native_text_font_previous()
font_size, font_previous = font_previous, font_size
end
function native_text_font_default()
end
function native_text_font_name()
end
function native_text_font_size(n)
font_size = math.ceil(n/5)
if font_size < 1 then
font_size = 1
end
end
function native_text_mensure(text)
local s = font_size * 5
local t = tostring(text)
local a = #t > 1 and 1 or 0
return #t * (a + s), s
end
function native_text_print(x, y, t)
print(tostring(t), x, y, current_color, true, font_size)
end
native_cfg_poly_repeat_0 = true
native_cfg_poly_repeat_1 = true
tic80engine = tic80engine()
tic80game = tic80game()
function TIC()
if not started then
started = true
if tic80engine and type(tic80engine) == 'table' and tic80engine.meta and tic80engine.meta.title then
trace('engine: '..tic80engine.meta.title..' '..tostring(tic80engine.meta.version))
end
if tic80game and type(tic80game) == 'table' and tic80game.meta and tic80game.meta.title then
trace('game: '..tic80game.meta.title..' '..tostring(tic80game.meta.version))
end
native_callback_init(240, 136, tic80game)
else
do
local now = time()
delta = now - last
last = now
end
do
local index = 1
while index <= #keymap do
local keyname = keymap[index]
local pressed = btn(index - 1)
if not keypress[index] and pressed then
keypress[index] = true
native_callback_keyboard(keyname, pressed)
elseif keypress[index] and not pressed then
keypress[index] = false
native_callback_keyboard(keyname, pressed)
end
index = index + 1
end
end
native_callback_loop(delta)
native_callback_draw()
end
end
`;function d(a,h){function c(n,o,i){let u=i.length,t=new Uint8Array(4);t[0]=n<<5|o,t[1]=u%256,t[2]=Math.floor(u/256),t[3]=0;let _=new TextEncoder().encode(i),l=new Uint8Array(t.length+_.length);return l.set(t,0),l.set(_,t.length),l}function s(n,o){return`local ${n} = function()
${o}
end
`}function r(n,o){let i=new Uint8Array(n.length+o.length);return i.set(n),i.set(o,n.length),i}let v=String.fromCharCode(0),e=new Uint8Array(0);return e=r(e,c(2,5,s("tic80game",h))),e=r(e,c(1,5,s("tic80engine",a))),e=r(e,c(0,5,g)),e=r(e,c(0,17,v)),e}function y(a){return d(f,a)}export{y as default};