love-loader/main.lua

149 lines
3.6 KiB
Lua

local ll = require 'lib.main'
error = love.errhand or love.errorhandler
ll.skin = require 'skins.psp' (ll)
function splash()
if not ll.mgme then return end
love.graphics.setColor(255, 255, 255, 100 / COLDIV)
if ll.mgme.screens and ll.mgme.screens[1] then
local img = love.graphics.newImage(ll.mgme.screens[1])
love.graphics.draw(img, 0, 0, 0, W / img:getWidth(), H / img:getHeight())
end
love.graphics.setColor(255, 255, 255, 255)
love.graphics.print('Loading '..ll.mgme.name, W / 2, H / 2)
end
require 'll-min'
llUsed = true
if love.getVersion() >= 12 then
function llHome()
ll.umount()
love.event.restart()
end
else
function llHome()
ll.umount()
love.event.push('quit', 'restart')
end
end
if love.getVersion() >= 11
then love.errorhandler = error
else love.errhand = error
end
local dt = love.timer and love.timer.step() or 0
local brk = false
while not brk and not ll.mdir do
-- event handling
love.event.pump()
for n, a,b,c in love.event.poll() do
if n == 'quit'
or (n == 'keypressed' and a == 'escape')
then ll.umount()
love.event.push('quit')
brk = true; break
elseif n == 'filedropped' then
love.graphics.clear()
local x, y, g = 32, 32, 16
local w, h = 84, 96
love.graphics.rectangle('line', x, y, w, h, w / 8)
love.graphics.line(x + w / 1.5, y, x + w, y + h / 3)
if ll.skin.addGame then
a:open 'r'
ll.skin.addGame(a:getFilename(), a:read(), x + w + g, y)
else love.graphics.print('This skin does not support file dropping', x + w + g, y)
end
love.graphics.present()
love.timer.sleep(2)
end
love.handlers[n](a,b,c)
end
-- update and drawing
if love.timer then
love.timer.step()
dt = love.timer.getDelta()
end
ll.skin.update(dt)
love.graphics.origin()
love.graphics.clear(0, 0, 0)
ll.skin.draw()
love.graphics.present()
love.timer.sleep(0.001)
end
if ll.mdir then
love.graphics.setNewFont()
resize = nil
love.graphics.clear(0, 0, 0)
splash()
love.graphics.present()
if ll.skin.lovecb then
for _, v in pairs(ll.skin.lovecb)
do love[v] = nil
end
end
love.filesystem.setIdentity(ll.mgme.dir)
local f, err = load(love.filesystem.read(ll.mgme.main), ll.mgme.name)
if not f then error(err)
else xpcall(f, function(e)
error(e)
llHome()
end)
end
local t = {
title = 'Untitled',
window = {
width = W, height = H,
fullscreen = love.window.getFullscreen(),
resizable = false,
},
audio = {
mixwithsystem = true,
mic = false,
},
modules = {},
console = false,
accelerometerjoystick = true,
gammacorrect = false,
}
if pcall(require, 'conf')
and love.conf
then pcall(love.conf, t)
end
if t.console and love._openConsole
then love._openConsole()
end
love._setGammaCorrect(t.gammacorrect)
if MOBILE then
love._setAccelerometerAsJoystick(t.accelerometerjoystick)
if love.isVersionCompatible '11.3' then
love._setAudioMixWithSystem(t.audio.mixwithsystem)
love._requestRecordingPermission(t.audio.mic)
end
love.filesystem._setAndroidSaveExternal(t.externalstorage)
end
if t.window then
love.window.setTitle(t.window.title or t.title)
local ww, wh, wi =
t.window.width, t.window.height,
t.window.icon
t.window.width, t.window.height, t.window.title, t.window.icon
= nil
assert(love.window.setMode(ww, wh, t.window), 'Error setting up window')
if wi
then love.window.setIcon(love.image.newImageData(wi))
end
end
love.resize(love.graphics.getDimensions())
end