diff --git a/backend/love.lua b/backend/love.lua index 9b095b8..b5f61b4 100644 --- a/backend/love.lua +++ b/backend/love.lua @@ -165,6 +165,11 @@ function love.resize(width, height) uqt.draw.height = height end end +elseif uqt.input then -- fields required by uqt.input + uqt.draw = { + width = love.graphics.getWidth(), + height = love.graphics.getHeight() + } end -- uqt.audio diff --git a/draw.lua b/draw.lua index 36d3cf1..261ea5a 100644 --- a/draw.lua +++ b/draw.lua @@ -1,5 +1,4 @@ -- ubiquitousse.draw -local uqt = require((...):match("^(.-ubiquitousse)%.")) --- The drawing functions: everything that affect the display/window. -- The coordinate system used is: @@ -144,10 +143,12 @@ draw = { scissor = function(x, y, width, height) end, --- The drawing area width, in pixels. + -- @requiredby input -- @impl backend width = 800, --- The drawing area height, in pixels. + -- @requiredby input -- @impl backend height = 600, diff --git a/event.lua b/event.lua index da8a5a1..c5c8f3f 100644 --- a/event.lua +++ b/event.lua @@ -1,7 +1,8 @@ -- ubiquitousse.event -local input = require((...):match("^(.-ubiquitousse)%.")..".input") -local time = require((...):match("^(.-ubiquitousse)%.")..".time") -local scene = require((...):match("^(.-ubiquitousse)%.")..".scene") +local uqt = require((...):match("^(.-ubiquitousse)%.")) +local input = uqt.input +local time = uqt.time +local scene = uqt.scene --- The events: callback functions that will be called when something interesting occurs. -- Theses are expected to be redefined in the game. @@ -16,15 +17,15 @@ return { -- @tparam number dt time since last call, in miliseconds -- @impl mixed update = function(dt) - input.update(dt) - time.update(dt) - scene.update(dt) + if input then input.update(dt) end + if time then time.update(dt) end + if scene then scene.update(dt) end end, --- Called each time the game expect a new frame to be drawn. -- The screen is expected to be cleared since last frame. -- @impl backend draw = function() - scene.draw() + if scene then scene.draw() end end } diff --git a/init.lua b/init.lua index 90ff923..ac98c2c 100644 --- a/init.lua +++ b/init.lua @@ -58,6 +58,10 @@ -- * ubiquitousse: fully-working version in Ubiquitousse, may or may not be redefined in backend -- The implementation level is indicated using the "@impl level" annotation. -- +-- Some Ubiquitousse modules require parts of other modules to work. Because every module should work when all the others are +-- disabled, the backend may need to provide defaults values for a few fields in disabled modules required by an enabled one. +-- Thoses fields are indicated with "@requiredby module" annotations. +-- -- Regarding the documentation: Ubiquitousse used LDoc/LuaDoc styled-comments, but since LDoc hates me and my code, the -- generated result is complete garbage, so please read the documentation directly in the comments here. -- Stuff you're interested in starts with triple - (e.g., "--- This functions saves the world"). diff --git a/input.lua b/input.lua index 6832589..080ce34 100644 --- a/input.lua +++ b/input.lua @@ -1,6 +1,6 @@ -- ubiquitousse.input local uqt = require((...):match("^(.-ubiquitousse)%.")) -local draw = require((...):match("^(.-ubiquitousse)%.")..".draw") +local draw = uqt.draw --- Used to store inputs which were updated this frame -- { Input: true, ... } diff --git a/scene.lua b/scene.lua index 6892117..596c810 100644 --- a/scene.lua +++ b/scene.lua @@ -1,5 +1,6 @@ -- ubiquitousse.scene -local time = require((...):match("^(.-ubiquitousse)%.")..".time") +local uqt = require((...):match("^(.-ubiquitousse)%.")) +local time = uqt.time --- Returns the file path of the given module name. local function getPath(modname) @@ -51,7 +52,7 @@ scene = { return { name = name or "unamed", -- The scene name. - time = time.new(), -- Scene-specific TimerRegistry. + time = time and time.new(), -- Scene-specific TimerRegistry, if uqt.time is enabled. enter = function(self, ...) end, -- Called when entering a scene. exit = function(self) end, -- Called when exiting a scene, and not expecting to come back (scene may be unloaded). @@ -115,7 +116,7 @@ scene = { -- @impl ubiquitousse update = function(dt, ...) if scene.current then - scene.current.time.update(dt) + if time then scene.current.time.update(dt) end scene.current:update(dt, ...) end end,