mirror of
https://github.com/usysrc/LICK.git
synced 2024-11-16 09:34:22 +00:00
now more likely to work with Löve 0.8.0, also made module much better
This commit is contained in:
parent
2c8ebd86a3
commit
d43652a52c
@ -4,35 +4,31 @@
|
|||||||
|
|
||||||
|
|
||||||
|
|
||||||
lick = {}
|
local lick = {}
|
||||||
lick.file = "main.lua"
|
lick.file = "main.lua"
|
||||||
lick.debug = false
|
lick.debug = false
|
||||||
lick.reset = false
|
lick.reset = false
|
||||||
lick.clearFlag = false
|
lick.clearFlag = false
|
||||||
lick.sleepTime = love.graphics.newCanvas and 0.001 or 1
|
lick.sleepTime = 0.001
|
||||||
|
|
||||||
function handle(err)
|
local last_modified = 0
|
||||||
|
|
||||||
|
local function handle(err)
|
||||||
return "ERROR: " .. err
|
return "ERROR: " .. err
|
||||||
end
|
end
|
||||||
|
|
||||||
function lick.setFile(str)
|
|
||||||
live.file = str or "lick.lua"
|
|
||||||
end
|
|
||||||
|
|
||||||
-- Initialization
|
-- Initialization
|
||||||
function lick.load()
|
local function load()
|
||||||
last_modified = 0
|
last_modified = 0
|
||||||
end
|
end
|
||||||
|
|
||||||
-- load the lickcoding file and execute the contained update function
|
local function update(dt)
|
||||||
function lick.update(dt)
|
|
||||||
if love.filesystem.exists(lick.file) and last_modified < love.filesystem.getLastModified(lick.file) then
|
if love.filesystem.exists(lick.file) and last_modified < love.filesystem.getLastModified(lick.file) then
|
||||||
last_modified = love.filesystem.getLastModified(lick.file)
|
last_modified = love.filesystem.getLastModified(lick.file)
|
||||||
success, chunk = pcall(love.filesystem.load, lick.file)
|
success, chunk = pcall(love.filesystem.load, lick.file)
|
||||||
if not success then
|
if not success then
|
||||||
print(tostring(chunk))
|
print(tostring(chunk))
|
||||||
lick.debugoutput = chunk .. "\n"
|
lick.debugoutput = chunk .. "\n"
|
||||||
|
|
||||||
end
|
end
|
||||||
ok,err = xpcall(chunk, handle)
|
ok,err = xpcall(chunk, handle)
|
||||||
if not ok then
|
if not ok then
|
||||||
@ -70,7 +66,7 @@ function lick.update(dt)
|
|||||||
updateok_old = not updateok
|
updateok_old = not updateok
|
||||||
end
|
end
|
||||||
|
|
||||||
function lick.draw()
|
local function draw()
|
||||||
drawok, err = xpcall(love.draw, handle)
|
drawok, err = xpcall(love.draw, handle)
|
||||||
if not drawok and not drawok_old then
|
if not drawok and not drawok_old then
|
||||||
print(tostring(err))
|
print(tostring(err))
|
||||||
@ -80,23 +76,28 @@ function lick.draw()
|
|||||||
end
|
end
|
||||||
if lick.debug and lick.debugoutput then
|
if lick.debug and lick.debugoutput then
|
||||||
love.graphics.setColor(255,255,255,120)
|
love.graphics.setColor(255,255,255,120)
|
||||||
love.graphics.printf(lick.debugoutput, (1024/2)+50, 0, 400, "right")
|
love.graphics.printf(lick.debugoutput, (love.graphics.getWidth()/2)+50, 0, 400, "right")
|
||||||
end
|
end
|
||||||
drawok_old = not drawok
|
drawok_old = not drawok
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
function love.run()
|
function love.run()
|
||||||
|
|
||||||
if love.load then love.load(arg) end
|
math.randomseed(os.time())
|
||||||
lick.load()
|
math.random() math.random()
|
||||||
|
load()
|
||||||
|
|
||||||
|
|
||||||
local dt = 0
|
local dt = 0
|
||||||
|
|
||||||
-- Main loop time.
|
-- Main loop time.
|
||||||
while true do
|
while true do
|
||||||
-- Process events.
|
-- Process events.
|
||||||
if love.event then
|
if love.event then
|
||||||
|
love.event.pump()
|
||||||
for e,a,b,c,d in love.event.poll() do
|
for e,a,b,c,d in love.event.poll() do
|
||||||
if e == "q" or e == "quit" then
|
if e == "quit" then
|
||||||
if not love.quit or not love.quit() then
|
if not love.quit or not love.quit() then
|
||||||
if love.audio then
|
if love.audio then
|
||||||
love.audio.stop()
|
love.audio.stop()
|
||||||
@ -108,20 +109,24 @@ function love.run()
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Update dt, as we'll be passing it to update
|
||||||
if love.timer then
|
if love.timer then
|
||||||
love.timer.step()
|
love.timer.step()
|
||||||
dt = love.timer.getDelta()
|
dt = love.timer.getDelta()
|
||||||
end
|
end
|
||||||
lick.update(dt)
|
|
||||||
|
-- Call update and draw
|
||||||
|
if update then update(dt) end -- will pass 0 if love.timer is disabled
|
||||||
if love.graphics then
|
if love.graphics then
|
||||||
if not lick.clearFlag then love.graphics.clear() end
|
love.graphics.clear()
|
||||||
lick.draw()
|
if draw then draw() end
|
||||||
end
|
end
|
||||||
|
|
||||||
if love.timer then love.timer.sleep(lick.sleepTime) end
|
if love.timer then love.timer.sleep(0.001) end
|
||||||
if love.graphics then love.graphics.present() end
|
if love.graphics then love.graphics.present() end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
return lick
|
||||||
|
Loading…
Reference in New Issue
Block a user