Love Loader v2.0
This commit is contained in:
parent
9513a5c471
commit
f562b23197
16 changed files with 933 additions and 207 deletions
26
lib/chroot.lua
Normal file
26
lib/chroot.lua
Normal file
|
@ -0,0 +1,26 @@
|
|||
return function(ll)
|
||||
|
||||
ll.mdir = nil
|
||||
ll.mgme = nil
|
||||
|
||||
function ll.mount(gme)
|
||||
--[[
|
||||
ll.mdir = gme.base .. gme.dir
|
||||
ll.mgme = gme
|
||||
--[=[
|
||||
if gme.main then
|
||||
print('Load', ll.mdir ..'/'.. gme.main)
|
||||
end
|
||||
--]=]
|
||||
--]]
|
||||
error 'unimplemented'
|
||||
end
|
||||
|
||||
function ll.umount()
|
||||
if ll.mdir ~= nil then
|
||||
ll.mdir = nil
|
||||
error 'unimplemented'
|
||||
end
|
||||
end
|
||||
|
||||
end
|
100
lib/game.lua
Normal file
100
lib/game.lua
Normal file
|
@ -0,0 +1,100 @@
|
|||
return function(ll)
|
||||
|
||||
ll.games = {}
|
||||
|
||||
local function parse(conf)
|
||||
local r = {}
|
||||
local k, v
|
||||
|
||||
local buf = ''
|
||||
local t = 'str'
|
||||
local esc = false
|
||||
local prg = true
|
||||
|
||||
local i = 1
|
||||
repeat
|
||||
local ch = conf:sub(i, i)
|
||||
|
||||
if ch == '\\'
|
||||
then esc = true
|
||||
|
||||
elseif ch == '#' then
|
||||
repeat i = i + 1
|
||||
ch = conf:sub(i, i)
|
||||
until ch == '' or ch == '\n' or ch == '\r'
|
||||
|
||||
elseif ch == '[' then
|
||||
buf = buf:match '%s*(.*)%s*'
|
||||
assert(#buf == 0, 'Unexpected array usage')
|
||||
t = 'arr'
|
||||
prg = true
|
||||
v = {}
|
||||
|
||||
elseif ch == ''
|
||||
or (ch == '=' and not k)
|
||||
or (ch == ']' and t == 'arr')
|
||||
or (ch == ';' and t == 'arr')
|
||||
or ch == '\n' or ch == '\r' then
|
||||
buf = buf:match '^%s*(.-)%s*$'
|
||||
|
||||
if ch == '=' then
|
||||
assert(t == 'str', 'Cannot use other types than string for key')
|
||||
end
|
||||
|
||||
if t == 'str'
|
||||
or (t == 'arr' and ch == ']')
|
||||
then prg = false end
|
||||
|
||||
if not prg or ch == ';' then
|
||||
if #buf ~= 0 then
|
||||
if k then
|
||||
if t == 'str'
|
||||
then v = buf
|
||||
elseif t == 'arr'
|
||||
then table.insert(v, buf)
|
||||
else error 'wut?' end
|
||||
else k = buf
|
||||
end
|
||||
buf = ''
|
||||
elseif ch ~= ''
|
||||
and ch ~= '\r'
|
||||
and ch ~= '\n'
|
||||
then error 'empty buffer'
|
||||
end
|
||||
end
|
||||
if k and v and not prg then
|
||||
r[k] = v
|
||||
k = nil
|
||||
v = nil
|
||||
buf = ''
|
||||
t = 'str'
|
||||
end
|
||||
|
||||
elseif esc then
|
||||
buf = buf .. ch
|
||||
esc = false
|
||||
|
||||
else buf = buf .. ch
|
||||
end
|
||||
i = i + 1
|
||||
until i >= #conf + 1
|
||||
return r
|
||||
end
|
||||
|
||||
function ll.gameNew(conf, file, base, dir)
|
||||
local cfg = parse(conf or '')
|
||||
local gme = {
|
||||
name = cfg.name or dir or 'No name',
|
||||
desc = cfg.desc or 'No description provided.',
|
||||
base = base,
|
||||
dir = dir,
|
||||
main = cfg.main or 'main.lua',
|
||||
screens = cfg.screens or cfg.pics or nil,
|
||||
scrcur = 1,
|
||||
scrprv = 1,
|
||||
dat = nil,
|
||||
}
|
||||
return gme
|
||||
end
|
||||
|
||||
end
|
9
lib/load.lua
Normal file
9
lib/load.lua
Normal file
|
@ -0,0 +1,9 @@
|
|||
return function(ll)
|
||||
|
||||
function ll.gameAdd(conf, file, base, dir)
|
||||
local gme = ll.gameNew(conf, file, base, dir)
|
||||
table.insert(ll.games, gme)
|
||||
return gme
|
||||
end
|
||||
|
||||
end
|
33
lib/love/chroot.lua
Normal file
33
lib/love/chroot.lua
Normal file
|
@ -0,0 +1,33 @@
|
|||
return function(ll)
|
||||
|
||||
local ffi = require 'ffi'
|
||||
ffi.cdef [[
|
||||
int PHYSFS_mount(const char *, const char *, int);
|
||||
int PHYSFS_unmount(const char *);
|
||||
]]
|
||||
|
||||
function ll.mount(gme)
|
||||
local mdir = gme.base .. gme.dir
|
||||
|
||||
love.filesystem.setRequirePath(''
|
||||
.. mdir .. '/?.lua;'
|
||||
.. mdir .. '/?/init.lua;'
|
||||
.. '?.lua;?/init.lua;'
|
||||
)
|
||||
-- FIXME: Bug may appear in Linux. Recompile Love2D or use official PPA.
|
||||
if ffi.C.PHYSFS_mount(mdir, '/', 0) == 0
|
||||
then error 'Cannot mount'
|
||||
else
|
||||
ll.mdir = mdir
|
||||
ll.mgme = gme
|
||||
end
|
||||
end
|
||||
|
||||
function ll.umount()
|
||||
if ll.mdir ~= nil then
|
||||
ffi.C.PHYSFS_unmount(ll.mdir)
|
||||
ll.mdir = nil
|
||||
end
|
||||
end
|
||||
|
||||
end
|
28
lib/love/load.lua
Normal file
28
lib/love/load.lua
Normal file
|
@ -0,0 +1,28 @@
|
|||
return function(ll)
|
||||
|
||||
function ll.gameAdd(conf, file, base, dir)
|
||||
local gme = ll.gameNew(conf, file, base, dir)
|
||||
gme.dat = {}
|
||||
|
||||
if gme.screens and gme.screens[1] then
|
||||
gme.dat.scr = {}
|
||||
for i = 1, #gme.screens do
|
||||
table.insert(gme.dat.scr, love.graphics.newImage(ll.cfg.root .. gme.dir ..'/'.. gme.screens[i]))
|
||||
end
|
||||
end
|
||||
|
||||
table.insert(ll.games, gme)
|
||||
return gme
|
||||
end
|
||||
|
||||
for _, dir in pairs(love.filesystem.getDirectoryItems(ll.cfg.root)) do
|
||||
local file = ll.cfg.root .. dir..'/'.. 'info.ll'
|
||||
ll.gameAdd(
|
||||
love.filesystem.read(file),
|
||||
file,
|
||||
love.filesystem.getSource():match '(.*)[\\/]*' ..'/'.. ll.cfg.root, -- TODO: AppData folders support
|
||||
dir
|
||||
)
|
||||
end
|
||||
|
||||
end
|
27
lib/main.lua
Normal file
27
lib/main.lua
Normal file
|
@ -0,0 +1,27 @@
|
|||
local ll = {}
|
||||
|
||||
ll.cfg = {
|
||||
root = 'games/',
|
||||
}
|
||||
|
||||
require 'lib.game' (ll)
|
||||
require 'lib.chroot' (ll)
|
||||
require 'lib.load' (ll)
|
||||
|
||||
function ll.home()
|
||||
ll.umount()
|
||||
error 'go to home'
|
||||
end
|
||||
|
||||
if love then
|
||||
require 'lib.love.chroot' (ll)
|
||||
require 'lib.love.load' (ll)
|
||||
|
||||
function ll.home()
|
||||
ll.umount()
|
||||
love.event.push('quit', 'restart')
|
||||
end
|
||||
llHome = ll.home
|
||||
end
|
||||
|
||||
return ll
|
Loading…
Add table
Add a link
Reference in a new issue