Love Loader v2.1
Bugfixes. Removed cross-engine support, only Love2D. Added filesystem and keyboard modules in LibLL. Remade input handling in skins. Files and broken folders are not shows in game list. Add MOBILE variable and auto-fullscreen on mobile phones.
This commit is contained in:
parent
f562b23197
commit
e46bc230a6
13 changed files with 242 additions and 153 deletions
|
@ -3,23 +3,34 @@ return function(ll)
|
|||
ll.mdir = nil
|
||||
ll.mgme = nil
|
||||
|
||||
local ffi = require 'ffi'
|
||||
ffi.cdef [[
|
||||
int PHYSFS_mount(const char *, const char *, int);
|
||||
int PHYSFS_unmount(const char *);
|
||||
]]
|
||||
|
||||
local baseReq = '?.lua;?/init.lua;'
|
||||
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'
|
||||
local mdir = gme.base .. gme.dir
|
||||
ll.mgme = gme
|
||||
|
||||
love.filesystem.setRequirePath(''
|
||||
.. mdir .. '/?.lua;'
|
||||
.. mdir .. '/?/init.lua;'
|
||||
.. baseReq
|
||||
)
|
||||
-- FIXME: Bug may appear in Linux. Recompile Love2D or use official PPA.
|
||||
if ffi.C.PHYSFS_mount(mdir, '/', 0) == 0
|
||||
then error('Cannot mount '..mdir)
|
||||
love.filesystem.setRequirePath(baseReq)
|
||||
else ll.mdir = mdir
|
||||
end
|
||||
end
|
||||
|
||||
function ll.umount()
|
||||
if ll.mdir ~= nil then
|
||||
ffi.C.PHYSFS_unmount(ll.mdir)
|
||||
ll.mdir = nil
|
||||
error 'unimplemented'
|
||||
end
|
||||
end
|
||||
|
||||
|
|
20
lib/fs.lua
Normal file
20
lib/fs.lua
Normal file
|
@ -0,0 +1,20 @@
|
|||
return function(ll)
|
||||
|
||||
function ll.fsIsAbs(f)
|
||||
f = f:sub(1, 1)
|
||||
return f == '/' or f == '\\'
|
||||
end
|
||||
|
||||
function ll.fsIsRel(f)
|
||||
return not ll.fsIsAbs(f)
|
||||
end
|
||||
|
||||
function ll.fsFile(f)
|
||||
return f:match '([^/\\]*)[/\\]*$'
|
||||
end
|
||||
|
||||
function ll.fsDir(f)
|
||||
return f:match '^(.*)[/\\]+[^/\\]*[/\\]*$'
|
||||
end
|
||||
|
||||
end
|
81
lib/keyb.lua
Normal file
81
lib/keyb.lua
Normal file
|
@ -0,0 +1,81 @@
|
|||
return function(ll)
|
||||
|
||||
local mx, my, mb, mpb
|
||||
local dir, sc1, sc2, sclm
|
||||
|
||||
-- d - direction (h, v, x, y, *)
|
||||
-- c1 - coordinate before card (mouse) (be left or top)
|
||||
-- c2 - coordinate after card (mouse) (be right or bottom)
|
||||
-- clm - other coordinate limit (mouse) (set -1 to disable)
|
||||
function ll.kbInit(d, c1, c2, clim)
|
||||
if d == 'h' or d == 'v' or d == '*'
|
||||
then dir = d
|
||||
elseif d == 'y'
|
||||
then dir = 'v'
|
||||
elseif d == 'x'
|
||||
then dir = 'h'
|
||||
else error 'Direction must be *, h (x) or v (y)'
|
||||
end
|
||||
|
||||
c1, c2 =
|
||||
tonumber(c1) or 0,
|
||||
tonumber(c2) or 0
|
||||
sc1, sc2, sclm =
|
||||
math.min(c1, c2),
|
||||
math.max(c1, c2),
|
||||
tonumber(clim) or -1
|
||||
end
|
||||
|
||||
-- returns: <, >, o, m, nil
|
||||
-- ^ and v if dir is *
|
||||
function ll.kbGet()
|
||||
assert(dir, 'Call ll.kbInit(dir, coord1, coord2, coordlimit) before')
|
||||
mx, my = love.mouse.getPosition()
|
||||
mpb = mb
|
||||
if love.mouse.isDown(1) then mb = 1
|
||||
else mb = 0
|
||||
end
|
||||
|
||||
if love.keyboard.isScancodeDown('up', 'w')
|
||||
then return dir == '*' and '^' or '<'
|
||||
|
||||
elseif love.keyboard.isScancodeDown('left', 'a')
|
||||
then return '<'
|
||||
|
||||
elseif love.keyboard.isScancodeDown('down', 's')
|
||||
then return dir == '*' and 'v' or '>'
|
||||
|
||||
elseif love.keyboard.isScancodeDown('right', 'd')
|
||||
then return '>'
|
||||
|
||||
elseif love.keyboard.isScancodeDown('return', 'space')
|
||||
then return 'o'
|
||||
|
||||
elseif love.keyboard.isDown 'menu'
|
||||
then return 'm'
|
||||
|
||||
elseif mb == 0 and mpb == 1 then -- unpressed
|
||||
if dir == 'h' then
|
||||
if sclm < 0 or my <= sclm then
|
||||
if mx <= sc1
|
||||
then return '<'
|
||||
elseif mx >= sc2
|
||||
then return '>'
|
||||
else return 'o'
|
||||
end
|
||||
end
|
||||
else
|
||||
if sclm < 0 or mx <= sclm then
|
||||
if my <= sc1
|
||||
then return '<'
|
||||
elseif my >= sc2
|
||||
then return '>'
|
||||
else return 'o'
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
|
||||
end
|
42
lib/load.lua
42
lib/load.lua
|
@ -1,9 +1,51 @@
|
|||
return function(ll)
|
||||
|
||||
function ll.addGame(file, cont)
|
||||
local dir = ll.fsDir(file)
|
||||
file = ll.fsFile(file)
|
||||
local ext = file:match '%.(%w+)$'
|
||||
print(file, ext, dir)
|
||||
return 'NO!', nil
|
||||
end
|
||||
|
||||
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
|
||||
|
||||
local lfs = love.filesystem
|
||||
local info = lfs.getInfo
|
||||
|
||||
for _, dir in pairs(love.filesystem.getDirectoryItems(ll.cfg.root)) do
|
||||
local isDir
|
||||
if info
|
||||
then isDir = info(ll.cfg.root .. dir).type == 'directory'
|
||||
else isDir = lfs.isDirectory(ll.cfg.root .. dir)
|
||||
end
|
||||
|
||||
if isDir then
|
||||
local file = ll.cfg.root .. dir..'/'.. 'info.ll'
|
||||
local realDir = love.filesystem.getRealDirectory(file)
|
||||
or love.filesystem.getRealDirectory(ll.cfg.root .. dir..'/main.lua')
|
||||
if realDir
|
||||
then ll.gameAdd(
|
||||
love.filesystem.read(file),
|
||||
file,
|
||||
realDir ..'/'.. ll.cfg.root,
|
||||
dir
|
||||
)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
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
|
|
@ -1,28 +0,0 @@
|
|||
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
|
18
lib/main.lua
18
lib/main.lua
|
@ -4,24 +4,24 @@ ll.cfg = {
|
|||
root = 'games/',
|
||||
}
|
||||
|
||||
require 'lib.fs' (ll)
|
||||
require 'lib.game' (ll)
|
||||
require 'lib.chroot' (ll)
|
||||
require 'lib.load' (ll)
|
||||
require 'lib.keyb' (ll)
|
||||
|
||||
function ll.home()
|
||||
ll.umount()
|
||||
error 'go to home'
|
||||
love.event.push('quit', 'restart')
|
||||
end
|
||||
|
||||
if love then
|
||||
require 'lib.love.chroot' (ll)
|
||||
require 'lib.love.load' (ll)
|
||||
|
||||
function ll.home()
|
||||
ll.umount()
|
||||
love.event.push('quit', 'restart')
|
||||
ll.dt = false
|
||||
function ll.devtools()
|
||||
if not ll.dt then
|
||||
ll.dt = true
|
||||
__LL = ll
|
||||
pcall(function() require 'dev.tools' end)
|
||||
end
|
||||
llHome = ll.home
|
||||
end
|
||||
|
||||
return ll
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue