From 403aa80c46f9d79351f61426992be8bf644c134d Mon Sep 17 00:00:00 2001 From: Reuh Date: Tue, 26 Apr 2016 17:17:46 +0200 Subject: [PATCH] =?UTF-8?q?Addded=20basic=20ctr=C2=B5Lua=20backend,=20only?= =?UTF-8?q?=20load=20backend=20for=20loaded=20modules?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- backend/ctrulua.lua | 64 +++++++++++++++++++++++++++++++++++++++++++-- backend/love.lua | 10 +++++-- 2 files changed, 70 insertions(+), 4 deletions(-) diff --git a/backend/ctrulua.lua b/backend/ctrulua.lua index ac9078a..738d54b 100644 --- a/backend/ctrulua.lua +++ b/backend/ctrulua.lua @@ -1,2 +1,62 @@ --- TODO: everything -error("TODO level over 9000") +--- ctrµLua backend 0.0.1 for Abstract. +-- Provides a partial abstract API. Still a lot to implement. +-- Made for some ctrµLua version and abstract 0.0.1. +-- See `abstract` for Abstract API. + +-- General +local version = "0.0.1" + +-- Require stuff +local abstract = require((...):match("^(.-abstract)%.")) +local ctr = require("ctr") +local gfx = require("gfx") + +-- Version compatibility warning +do + local function checkCompat(stuffName, expectedVersion, actualVersion) + if actualVersion ~= expectedVersion then + local txt = ("Abstract ctrµLua backend version "..version.." was made for %s %s but %s is used!\nThings may not work as expected.") + :format(stuffName, expectedVersion, actualVersion) + print(txt) + for i=0,300 do + gfx.start(gfx.TOP) + gfx.wrappedText(0, 0, txt, gfx.TOP_WIDTH) + gfx.stop() + gfx.render() + end + end + end + -- checkCompat("ctrµLua", "", ("%s.%s.%s"):format(love.getVersion())) -- not really a version, just get the latest build + checkCompat("abstract", "0.0.1", abstract.version) +end + +-- Redefine all functions in tbl which also are in toAdd, so when used they call the old function (in tbl) and then the new (in toAdd). +local function add(tbl, toAdd) + for k,v in pairs(toAdd) do + local old = tbl[k] + tbl[k] = function(...) + old(...) + return v(...) + end + end +end + +-- abstract +abstract.backend = "ctrulua" + +-- abstract.event: TODO + +-- abstract.draw: TODO + +-- abstract.audio: TODO + +-- abstract.time +if abstract.time then +add(abstract.time, { + get = function() + return ctr.time() / 1000 + end +}) +end + +-- abstract.input: TODO diff --git a/backend/love.lua b/backend/love.lua index c7094f8..1cd8e69 100644 --- a/backend/love.lua +++ b/backend/love.lua @@ -44,7 +44,7 @@ end abstract.backend = "love" -- abstract.event -do +if abstract.event then local updateDefault = abstract.event.update abstract.event.update = function() end function love.update(dt) @@ -83,6 +83,7 @@ end end -- abstract.draw +if abstract.draw then local defaultFont = love.graphics.getFont() add(abstract.draw, { init = function(params) @@ -138,8 +139,10 @@ function love.resize(width, height) abstract.draw.height = height end end +end -- abstract.audio +if abstract.audio then add(abstract.audio, { -- TODO: doc load = function(filepath) @@ -151,16 +154,19 @@ add(abstract.audio, { } end }) +end -- abstract.time +if abstract.time then add(abstract.time, { get = function() return love.timer.getTime() end }) +end -- abstract.input -do +if abstract.input then local buttonsInUse = {} local axesInUse = {} function love.keypressed(key, scancode, isrepeat)