mirror of
https://github.com/Reuh/ubiquitousse.git
synced 2025-10-27 09:09:30 +00:00
Probably works better this way
This commit is contained in:
parent
b2d22c75d1
commit
e063f55514
4 changed files with 44 additions and 23 deletions
|
|
@ -14,6 +14,7 @@ local version = "0.0.1"
|
|||
|
||||
-- Require stuff
|
||||
local uqt = require((...):match("^(.-ubiquitousse)%."))
|
||||
local m = uqt.module
|
||||
|
||||
-- Version compatibility warning
|
||||
do
|
||||
|
|
@ -49,7 +50,7 @@ end
|
|||
uqt.backend = "love"
|
||||
|
||||
-- uqt.event
|
||||
if uqt.event then
|
||||
if m.event then
|
||||
local updateDefault = uqt.event.update
|
||||
uqt.event.update = function() end
|
||||
function love.update(dt)
|
||||
|
|
@ -63,15 +64,17 @@ end
|
|||
local drawDefault = uqt.event.draw
|
||||
uqt.event.draw = function() end
|
||||
function love.draw()
|
||||
love.graphics.push()
|
||||
if m.draw then
|
||||
love.graphics.push()
|
||||
|
||||
-- Resize type
|
||||
local winW, winH = love.graphics.getWidth(), love.graphics.getHeight()
|
||||
local gameW, gameH = uqt.draw.params.width, uqt.draw.params.height
|
||||
if uqt.draw.params.resizeType == "auto" then
|
||||
love.graphics.scale(winW/gameW, winH/gameH)
|
||||
elseif uqt.draw.params.resizeType == "center" then
|
||||
love.graphics.translate(math.floor(winW/2-gameW/2), math.floor(winH/2-gameH/2))
|
||||
-- Resize type
|
||||
local winW, winH = love.graphics.getWidth(), love.graphics.getHeight()
|
||||
local gameW, gameH = uqt.draw.params.width, uqt.draw.params.height
|
||||
if uqt.draw.params.resizeType == "auto" then
|
||||
love.graphics.scale(winW/gameW, winH/gameH)
|
||||
elseif uqt.draw.params.resizeType == "center" then
|
||||
love.graphics.translate(math.floor(winW/2-gameW/2), math.floor(winH/2-gameH/2))
|
||||
end
|
||||
end
|
||||
|
||||
-- Stuff defined in ubiquitousse.lua
|
||||
|
|
@ -80,12 +83,14 @@ function love.draw()
|
|||
-- Callback
|
||||
uqt.event.draw()
|
||||
|
||||
love.graphics.pop()
|
||||
if m.draw then
|
||||
love.graphics.pop()
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- uqt.draw
|
||||
if uqt.draw then
|
||||
if m.draw then
|
||||
local defaultFont = love.graphics.getFont()
|
||||
add(uqt.draw, {
|
||||
init = function(params)
|
||||
|
|
@ -165,7 +170,7 @@ function love.resize(width, height)
|
|||
uqt.draw.height = height
|
||||
end
|
||||
end
|
||||
elseif uqt.input then -- fields required by uqt.input
|
||||
elseif m.input then -- fields required by uqt.input
|
||||
uqt.draw = {
|
||||
width = love.graphics.getWidth(),
|
||||
height = love.graphics.getHeight()
|
||||
|
|
@ -173,7 +178,7 @@ elseif uqt.input then -- fields required by uqt.input
|
|||
end
|
||||
|
||||
-- uqt.audio
|
||||
if uqt.audio then
|
||||
if m.audio then
|
||||
add(uqt.audio, {
|
||||
-- TODO: cf audio.lua
|
||||
load = function(filepath)
|
||||
|
|
@ -188,7 +193,7 @@ add(uqt.audio, {
|
|||
end
|
||||
|
||||
-- uqt.time
|
||||
if uqt.time then
|
||||
if m.time then
|
||||
add(uqt.time, {
|
||||
get = function()
|
||||
return love.timer.getTime()
|
||||
|
|
@ -197,7 +202,7 @@ add(uqt.time, {
|
|||
end
|
||||
|
||||
-- uqt.input
|
||||
if uqt.input then
|
||||
if m.input then
|
||||
local buttonsInUse = {}
|
||||
local axesInUse = {}
|
||||
function love.keypressed(key, scancode, isrepeat)
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
-- ubiquitousse.event
|
||||
local uqt = require((...):match("^(.-ubiquitousse)%."))
|
||||
local m = uqt.module
|
||||
local input = uqt.input
|
||||
local time = uqt.time
|
||||
local scene = uqt.scene
|
||||
|
|
@ -17,15 +18,15 @@ return {
|
|||
-- @tparam number dt time since last call, in miliseconds
|
||||
-- @impl mixed
|
||||
update = function(dt)
|
||||
if input then input.update(dt) end
|
||||
if time then time.update(dt) end
|
||||
if scene then scene.update(dt) end
|
||||
if m.input then input.update(dt) end
|
||||
if m.time then time.update(dt) end
|
||||
if m.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()
|
||||
if scene then scene.draw() end
|
||||
if m.scene then scene.draw() end
|
||||
end
|
||||
}
|
||||
|
|
|
|||
18
init.lua
18
init.lua
|
|
@ -76,6 +76,17 @@ ubiquitousse = {
|
|||
-- @impl ubiquitousse
|
||||
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.
|
||||
-- For consistency, only use lowercase letters [a-z] (no special char)
|
||||
-- @impl backend
|
||||
|
|
@ -86,9 +97,12 @@ ubiquitousse = {
|
|||
package.loaded[p] = ubiquitousse
|
||||
|
||||
-- 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)
|
||||
if s then ubiquitousse[m] = t end
|
||||
if s then
|
||||
ubiquitousse[m] = t
|
||||
ubiquitousse.module[m] = true
|
||||
end
|
||||
end
|
||||
|
||||
-- Backend engine autodetect and load
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
-- ubiquitousse.scene
|
||||
local uqt = require((...):match("^(.-ubiquitousse)%."))
|
||||
local m = uqt.module
|
||||
local time = uqt.time
|
||||
|
||||
--- Returns the file path of the given module name.
|
||||
|
|
@ -52,7 +53,7 @@ scene = {
|
|||
return {
|
||||
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.
|
||||
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
|
||||
update = function(dt, ...)
|
||||
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, ...)
|
||||
end
|
||||
end,
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue