3.0 begin

This commit is contained in:
Er2 2022-07-08 21:09:39 +03:00
parent 45f3db4f47
commit ab8638bfe5
5 changed files with 213 additions and 19 deletions

View File

@ -3,33 +3,47 @@ return function(ll)
ll.mdir = nil
ll.mgme = nil
local ffi = require 'ffi'
ffi.cdef [[
if love.getVersion() >= 12 then
function ll._mntdir(dir)
return love.filesystem.mountFullPath(dir, '/')
end
function ll._umntdir(dir)
love.filesystem.unmountFullPath(dir)
end
else
local ffi = require 'ffi'
ffi.cdef [[
int PHYSFS_mount(const char *, const char *, int);
int PHYSFS_unmount(const char *);
]]
int PHYSFS_unmount(const char *);]]
-- FIXME: Bug may appear in Linux. Recompile Love2D or use official PPA.
function ll._mntdir(dir)
return ffi.C.PHYSFS_mount(dir, '/', 0) ~= 0
end
function ll._umntdir(dir)
ffi.C.PHYSFS_unmount(dir)
end
end
local baseReq = '?.lua;?/init.lua;'
function ll.mount(gme)
local mdir = gme.base .. gme.dir
ll.mgme = gme
love.filesystem.setRequirePath(''
.. mdir .. '/?.lua;'
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)
if ll._mntdir(mdir)
then ll.mdir, ll.mgme = mdir, gme
else 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._umntdir(ll.mdir)
ll.mdir = nil
end
end

View File

@ -1,5 +1,5 @@
-- Minimal Love Loader API
-- Version 2.1
-- Version 3.0
-- (c) Er2 2022 <er2@dismail.de>
-- Zlib License
@ -9,6 +9,22 @@ COLDIV = love.getVersion() == 0 and 1 or 255
MOBILE = love.system.getOS() == 'Android'
or love.system.getOS() == 'iOS'
function llHome()
love.event.push('quit', 'restart')
end
if love.getVersion() >= 12 then
local stfn
function love.graphics.stencil(fn) stfn = fn end
function love.graphics.setStencilTest(cmp, val)
if not cmp
then love.graphics.setStencilMode()
else love.graphics.setStencilMode('replace', cmp, val, 1, 1)
stfn()
end
end
end
if MOBILE
then love.window.setFullscreen(true)
end
@ -22,9 +38,6 @@ function love.resize(x, y)
end
love.resize(love.graphics.getDimensions())
function llHome()
love.event.push('quit')
end
function love.event.quit()
llHome()
end

View File

@ -16,9 +16,20 @@ ll.skin = require 'skins.psp' (ll)
require 'll-min'
llUsed = true
if love.errorhandler
then love.errorhandler = error
else love.errhand = error
if love.getVersion() >= 12 then
function llHome()
ll.umount()
love.event.restart()
end
else
function llHome()
ll.umount()
love.event.push('quit', 'restart')
end
if love.getVersion() >= 11 then
love.errorhandler = error
else love.errhand = error
end
end
local brk = false
@ -31,6 +42,19 @@ while not brk and not ll.mdir do
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

View File

@ -68,6 +68,10 @@ local function update()
if sel > #ll.games then sel = 1 end
end
if logger:sub(-3) == 'mm'
then ll.skin = require 'skins.select' (ll)
end
pikchv = pikchv + 1
if pikchv >= ll.cfg.pcht then
pikchv = 0
@ -151,9 +155,18 @@ local function draw()
end
end
local function addGame(file, cont, x, y)
local msg, id = ll.addGame(file, cont)
love.graphics.print(msg, x, y)
if id then
sel = id
end
end
return {
update = update,
draw = draw,
addGame = addGame,
}
end

130
skins/select.lua Normal file
View File

@ -0,0 +1,130 @@
return function(ll)
local skins = {
require 'skins.psp',
require 'skins.gui',
require 'skins.base',
require 'skins.select',
}
local sel = 1
local sk, ssel
local cx, cw, ch
local scx, scy = 1, 1
local tscx, tscy
local canv
local resz, l
function load(nunl)
l = true
resize = nil
assert(skins[sel], 'Skin does not exists')
sk = skins[sel](ll)
love.resize(love.graphics.getDimensions())
sk.update()
if not nunl then
if sk.lovecb then
for _, v in pairs(sk.lovecb)
do love[v] = nil
end
end
resize = resz
love.resize(love.graphics.getDimensions())
love.graphics.setCanvas(canv)
love.graphics.setColor(0, 0, 0)
love.graphics.rectangle('fill', 0, 0, W, H)
love.graphics.setColor(255, 255, 255)
sk.draw()
love.graphics.setCanvas()
else ll.skin = sk
end
l = false
end
function resize()
cx = math.min(W, H) / 8
cw, ch =
W - cx * 2.5,
H - cx * 1.5
tscx, tscy =
cw / W,
ch / H
canv = love.graphics.newCanvas(W, H)
if not l then load() end
ll.kbInit('h', cx, W - cx)
end
resz = resize
local d
local function update()
if not sk then load() end
scx = scx + (tscx - scx) * 0.1
scy = scy + (tscy - scy) * 0.1
if ssel
and scx > 0.99
and scy > 0.99
then load(true) end
local nd = ll.kbGet()
if nd ~= d then
d = nd
local ns = sel
if d == '<'
then ns = sel - 1
elseif d == '>'
then ns = sel + 1
elseif d == 'o'
then ssel = true
tscx, tscy = 1, 1
end
if ns < 1 then ns = #skins end
if ns > #skins then ns = 1 end
if sel ~= ns then
sel = ns
load()
end
end
end
local function draw()
local w, h = W * scx, H * scy
local x, y, r =
(W - w) / 2,
(H - h) / 2,
math.min(W - w, H - h) / 8
love.graphics.setColor(100 / COLDIV, 100 / COLDIV, 100 / COLDIV)
love.graphics.rectangle('fill', 0, 0, W, H)
love.graphics.setColor(255, 255, 255)
love.graphics.stencil(function()
love.graphics.rectangle('fill', x, y, w, h, r)
end)
love.graphics.setStencilTest('greater', 0)
love.graphics.draw(canv, x, y, 0, scx, scy)
love.graphics.setStencilTest()
love.graphics.rectangle('line', x, y, w, h, r)
end
-- execute if loaded from other skin
if ll.skin then
load()
resize()
update()
end
return {
draw = draw,
update = update,
}
end