1
0
Fork 0
mirror of https://github.com/Reuh/ubiquitousse.git synced 2025-10-27 17:19:31 +00:00

Probably works better this way

This commit is contained in:
Reuh 2017-04-05 21:01:42 +02:00
parent b2d22c75d1
commit e063f55514
4 changed files with 44 additions and 23 deletions

View file

@ -14,6 +14,7 @@ local version = "0.0.1"
-- Require stuff -- Require stuff
local uqt = require((...):match("^(.-ubiquitousse)%.")) local uqt = require((...):match("^(.-ubiquitousse)%."))
local m = uqt.module
-- Version compatibility warning -- Version compatibility warning
do do
@ -49,7 +50,7 @@ end
uqt.backend = "love" uqt.backend = "love"
-- uqt.event -- uqt.event
if uqt.event then if m.event then
local updateDefault = uqt.event.update local updateDefault = uqt.event.update
uqt.event.update = function() end uqt.event.update = function() end
function love.update(dt) function love.update(dt)
@ -63,15 +64,17 @@ end
local drawDefault = uqt.event.draw local drawDefault = uqt.event.draw
uqt.event.draw = function() end uqt.event.draw = function() end
function love.draw() function love.draw()
love.graphics.push() if m.draw then
love.graphics.push()
-- Resize type -- Resize type
local winW, winH = love.graphics.getWidth(), love.graphics.getHeight() local winW, winH = love.graphics.getWidth(), love.graphics.getHeight()
local gameW, gameH = uqt.draw.params.width, uqt.draw.params.height local gameW, gameH = uqt.draw.params.width, uqt.draw.params.height
if uqt.draw.params.resizeType == "auto" then if uqt.draw.params.resizeType == "auto" then
love.graphics.scale(winW/gameW, winH/gameH) love.graphics.scale(winW/gameW, winH/gameH)
elseif uqt.draw.params.resizeType == "center" then elseif uqt.draw.params.resizeType == "center" then
love.graphics.translate(math.floor(winW/2-gameW/2), math.floor(winH/2-gameH/2)) love.graphics.translate(math.floor(winW/2-gameW/2), math.floor(winH/2-gameH/2))
end
end end
-- Stuff defined in ubiquitousse.lua -- Stuff defined in ubiquitousse.lua
@ -80,12 +83,14 @@ function love.draw()
-- Callback -- Callback
uqt.event.draw() uqt.event.draw()
love.graphics.pop() if m.draw then
love.graphics.pop()
end
end end
end end
-- uqt.draw -- uqt.draw
if uqt.draw then if m.draw then
local defaultFont = love.graphics.getFont() local defaultFont = love.graphics.getFont()
add(uqt.draw, { add(uqt.draw, {
init = function(params) init = function(params)
@ -165,7 +170,7 @@ function love.resize(width, height)
uqt.draw.height = height uqt.draw.height = height
end end
end end
elseif uqt.input then -- fields required by uqt.input elseif m.input then -- fields required by uqt.input
uqt.draw = { uqt.draw = {
width = love.graphics.getWidth(), width = love.graphics.getWidth(),
height = love.graphics.getHeight() height = love.graphics.getHeight()
@ -173,7 +178,7 @@ elseif uqt.input then -- fields required by uqt.input
end end
-- uqt.audio -- uqt.audio
if uqt.audio then if m.audio then
add(uqt.audio, { add(uqt.audio, {
-- TODO: cf audio.lua -- TODO: cf audio.lua
load = function(filepath) load = function(filepath)
@ -188,7 +193,7 @@ add(uqt.audio, {
end end
-- uqt.time -- uqt.time
if uqt.time then if m.time then
add(uqt.time, { add(uqt.time, {
get = function() get = function()
return love.timer.getTime() return love.timer.getTime()
@ -197,7 +202,7 @@ add(uqt.time, {
end end
-- uqt.input -- uqt.input
if uqt.input then if m.input then
local buttonsInUse = {} local buttonsInUse = {}
local axesInUse = {} local axesInUse = {}
function love.keypressed(key, scancode, isrepeat) function love.keypressed(key, scancode, isrepeat)

View file

@ -1,5 +1,6 @@
-- ubiquitousse.event -- ubiquitousse.event
local uqt = require((...):match("^(.-ubiquitousse)%.")) local uqt = require((...):match("^(.-ubiquitousse)%."))
local m = uqt.module
local input = uqt.input local input = uqt.input
local time = uqt.time local time = uqt.time
local scene = uqt.scene local scene = uqt.scene
@ -17,15 +18,15 @@ return {
-- @tparam number dt time since last call, in miliseconds -- @tparam number dt time since last call, in miliseconds
-- @impl mixed -- @impl mixed
update = function(dt) update = function(dt)
if input then input.update(dt) end if m.input then input.update(dt) end
if time then time.update(dt) end if m.time then time.update(dt) end
if scene then scene.update(dt) end if m.scene then scene.update(dt) end
end, end,
--- Called each time the game expect a new frame to be drawn. --- Called each time the game expect a new frame to be drawn.
-- The screen is expected to be cleared since last frame. -- The screen is expected to be cleared since last frame.
-- @impl backend -- @impl backend
draw = function() draw = function()
if scene then scene.draw() end if m.scene then scene.draw() end
end end
} }

View file

@ -76,6 +76,17 @@ ubiquitousse = {
-- @impl ubiquitousse -- @impl ubiquitousse
version = "0.0.1", version = "0.0.1",
--- Table of enabled modules.
-- @impl ubiquitousse
module = {
time = false,
draw = false,
audio = false,
input = false,
scene = false,
event = false
},
--- Backend name. --- Backend name.
-- For consistency, only use lowercase letters [a-z] (no special char) -- For consistency, only use lowercase letters [a-z] (no special char)
-- @impl backend -- @impl backend
@ -86,9 +97,12 @@ ubiquitousse = {
package.loaded[p] = ubiquitousse package.loaded[p] = ubiquitousse
-- Require external submodules -- Require external submodules
for _, m in ipairs({"time", "draw", "audio", "input", "scene", "event"}) do for m in pairs(ubiquitousse.module) do
local s, t = pcall(require, p.."."..m) local s, t = pcall(require, p.."."..m)
if s then ubiquitousse[m] = t end if s then
ubiquitousse[m] = t
ubiquitousse.module[m] = true
end
end end
-- Backend engine autodetect and load -- Backend engine autodetect and load

View file

@ -1,5 +1,6 @@
-- ubiquitousse.scene -- ubiquitousse.scene
local uqt = require((...):match("^(.-ubiquitousse)%.")) local uqt = require((...):match("^(.-ubiquitousse)%."))
local m = uqt.module
local time = uqt.time local time = uqt.time
--- Returns the file path of the given module name. --- Returns the file path of the given module name.
@ -52,7 +53,7 @@ scene = {
return { return {
name = name or "unamed", -- The scene name. name = name or "unamed", -- The scene name.
time = time and time.new(), -- Scene-specific TimerRegistry, if uqt.time is enabled. time = m.time and time.new(), -- Scene-specific TimerRegistry, if uqt.time is enabled.
enter = function(self, ...) end, -- Called when entering a scene. 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). exit = function(self) end, -- Called when exiting a scene, and not expecting to come back (scene may be unloaded).
@ -116,7 +117,7 @@ scene = {
-- @impl ubiquitousse -- @impl ubiquitousse
update = function(dt, ...) update = function(dt, ...)
if scene.current then if scene.current then
if time then scene.current.time.update(dt) end if m.time then scene.current.time.update(dt) end
scene.current:update(dt, ...) scene.current:update(dt, ...)
end end
end, end,