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

The Ubiquitousse Update

This commit is contained in:
Reuh 2016-12-23 17:22:38 +01:00
parent 8ccf3534bc
commit 07cc7216a1
9 changed files with 96 additions and 96 deletions

View file

@ -1,4 +1,4 @@
-- abstract.audio
-- ubiquitousse.audio
--- Audio functions.
return {

View file

@ -7,7 +7,7 @@
local version = "0.0.1"
-- Require stuff
local abstract = require((...):match("^(.-abstract)%."))
local uqt = require((...):match("^(.-ubiquitousse)%."))
local ctr = require("ctr")
local gfx = require("ctr.gfx")
@ -18,7 +18,7 @@ do
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
for _=0,300 do
gfx.start(gfx.TOP)
gfx.wrappedText(0, 0, txt, gfx.TOP_WIDTH)
gfx.stop()
@ -27,7 +27,7 @@ do
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)
checkCompat("abstract", "0.0.1", uqt.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).
@ -41,20 +41,20 @@ local function add(tbl, toAdd)
end
end
-- abstract
abstract.backend = "ctrulua"
-- uqt
uqt.backend = "ctrulua"
-- abstract.event: TODO
-- uqt.event: TODO
-- abstract.draw: TODO
-- uqt.draw: TODO
-- abstract.audio: TODO
-- uqt.audio: TODO
-- abstract.time
if abstract.time then
add(abstract.time, {
-- uqt.time
if uqt.time then
add(uqt.time, {
get = ctr.time
})
end
-- abstract.input: TODO
-- uqt.input: TODO

View file

@ -13,7 +13,7 @@ local displayKeyConstant = true -- If using ScanCodes, sets this to true so the
local version = "0.0.1"
-- Require stuff
local abstract = require((...):match("^(.-abstract)%."))
local uqt = require((...):match("^(.-ubiquitousse)%."))
-- Version compatibility warning
do
@ -26,7 +26,7 @@ do
end
end
checkCompat("Löve", "0.10.1", ("%s.%s.%s"):format(love.getVersion()))
checkCompat("abstract", "0.0.1", abstract.version)
checkCompat("abstract", "0.0.1", uqt.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).
@ -40,35 +40,35 @@ local function add(tbl, toAdd)
end
end
-- abstract
abstract.backend = "love"
-- uqt
uqt.backend = "love"
-- abstract.event
if abstract.event then
local updateDefault = abstract.event.update
abstract.event.update = function() end
-- uqt.event
if uqt.event then
local updateDefault = uqt.event.update
uqt.event.update = function() end
function love.update(dt)
-- Value update
abstract.draw.fps = love.timer.getFPS()
uqt.draw.fps = love.timer.getFPS()
-- Stuff defined in abstract.lua
updateDefault(dt*1000)
-- Callback
abstract.event.update(dt)
uqt.event.update(dt)
end
local drawDefault = abstract.event.draw
abstract.event.draw = function() end
local drawDefault = uqt.event.draw
uqt.event.draw = function() end
function love.draw()
love.graphics.push()
-- Resize type
local winW, winH = love.graphics.getWidth(), love.graphics.getHeight()
local gameW, gameH = abstract.draw.params.width, abstract.draw.params.height
if abstract.draw.params.resizeType == "auto" then
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 abstract.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))
end
@ -76,18 +76,18 @@ function love.draw()
drawDefault()
-- Callback
abstract.event.draw()
uqt.event.draw()
love.graphics.pop()
end
end
-- abstract.draw
if abstract.draw then
-- uqt.draw
if uqt.draw then
local defaultFont = love.graphics.getFont()
add(abstract.draw, {
add(uqt.draw, {
init = function(params)
local p = abstract.draw.params
local p = uqt.draw.params
love.window.setTitle(p.title)
love.window.setMode(p.width, p.height, {
resizable = p.resizable
@ -134,16 +134,16 @@ add(abstract.draw, {
end,
})
function love.resize(width, height)
if abstract.draw.params.resizeType == "none" then
abstract.draw.width = width
abstract.draw.height = height
if uqt.draw.params.resizeType == "none" then
uqt.draw.width = width
uqt.draw.height = height
end
end
end
-- abstract.audio
if abstract.audio then
add(abstract.audio, {
-- uqt.audio
if uqt.audio then
add(uqt.audio, {
-- TODO: doc
load = function(filepath)
local audio = love.audio.newSource(filepath)
@ -156,17 +156,17 @@ add(abstract.audio, {
})
end
-- abstract.time
if abstract.time then
add(abstract.time, {
-- uqt.time
if uqt.time then
add(uqt.time, {
get = function()
return love.timer.getTime()
end
})
end
-- abstract.input
if abstract.input then
-- uqt.input
if uqt.input then
local buttonsInUse = {}
local axesInUse = {}
function love.keypressed(key, scancode, isrepeat)
@ -227,7 +227,7 @@ end
love.mouse.setVisible(false)
add(abstract.input, {
add(uqt.input, {
buttonDetector = function(...)
local ret = {}
for _,id in ipairs({...}) do
@ -290,7 +290,7 @@ add(abstract.input, {
for _,id in ipairs({...}) do
-- Binary axis
if id:match(".+%,.+") then
local d1, d2 = abstract.input.buttonDetector(id:match("^(.+)%,(.+)$"))
local d1, d2 = uqt.input.buttonDetector(id:match("^(.+)%,(.+)$"))
table.insert(ret, function()
local b1, b2 = d1(), d2()
if b1 and b2 then return 0
@ -427,7 +427,7 @@ add(abstract.input, {
for _,id in ipairs({...}) do
-- Binary axis
if id:match(".+%,.+") then
local b1, b2 = abstract.input.buttonName(id:match("^(.+)%,(.+)$"))
local b1, b2 = uqt.input.buttonName(id:match("^(.+)%,(.+)$"))
table.insert(ret, b1.." / "..b2)
-- Mouse move
elseif id:match("^mouse%.move%.") then
@ -466,31 +466,31 @@ add(abstract.input, {
})
-- Defaults
abstract.input.default.pointer:bind(
uqt.input.default.pointer:bind(
{ "absolute", "keyboard.left,keyboard.right", "keyboard.up,keyboard.down" },
{ "absolute", "gamepad.axis.1.leftx", "gamepad.axis.1.lefty" }
)
abstract.input.default.up:bind(
uqt.input.default.up:bind(
"keyboard.up", "keyboard.w",
"gamepad.button.1.dpup", "gamepad.axis.1.lefty%-0.5"
)
abstract.input.default.down:bind(
uqt.input.default.down:bind(
"keyboard.down", "keyboard.s",
"gamepad.button.1.dpdown", "gamepad.axis.1.lefty%0.5"
)
abstract.input.default.right:bind(
uqt.input.default.right:bind(
"keyboard.right", "keyboard.d",
"gamepad.button.1.dpright", "gamepad.axis.1.leftx%0.5"
)
abstract.input.default.left:bind(
uqt.input.default.left:bind(
"keyboard.left", "keyboard.a",
"gamepad.button.1.dpleft", "gamepad.axis.1.leftx%-0.5"
)
abstract.input.default.confirm:bind(
uqt.input.default.confirm:bind(
"keyboard.enter", "keyboard.space", "keyboard.lshift", "keyboard.e",
"gamepad.button.1.a"
)
abstract.input.default.cancel:bind(
uqt.input.default.cancel:bind(
"keyboard.escape", "keyboard.backspace",
"gamepad.button.1.b"
)

View file

@ -1,5 +1,5 @@
-- abstract.draw
local abstract = require((...):match("^(.-abstract)%."))
-- ubiquitousse.draw
local uqt = require((...):match("^(.-ubiquitousse)%."))
--- The drawing functions: everything that affect the display/window.
-- The coordinate system used is:
@ -28,7 +28,7 @@ draw = {
-- This function is expected to be only called once, before doing any drawing operation.
-- @tparam table params the game parameters
-- @usage -- Default values:
-- abstract.setup {
-- ubiquitousse.init {
-- title = "Abstract Engine", -- usually window title
-- width = 800, -- in px
-- height = 600, -- in px

View file

@ -1,14 +1,14 @@
-- abstract.event
local input = require((...):match("^(.-abstract)%.")..".input")
local time = require((...):match("^(.-abstract)%.")..".time")
local scene = require((...):match("^(.-abstract)%.")..".scene")
-- ubiquitousse.event
local input = require((...):match("^(.-ubiquitousse)%.")..".input")
local time = require((...):match("^(.-ubiquitousse)%.")..".time")
local scene = require((...):match("^(.-ubiquitousse)%.")..".scene")
--- The events: callback functions that will be called when something interesting occurs.
-- Theses are expected to be redefined in the game.
-- For backend writers: if they already contain code, then this code has to be called on each call.
-- @usage -- in the game's code
-- abstract.event.draw = function()
-- abstract.draw.text(5, 5, "Hello world")
-- ubiquitousse.event.draw = function()
-- ubiquitousse.draw.text(5, 5, "Hello world")
-- end
return {
--- Called each time the game loop is ran. Don't draw here.
@ -19,7 +19,7 @@ return {
time.update(dt)
scene.update(dt)
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

View file

@ -1,4 +1,4 @@
-- abstract
-- ubiquitousse
--- Abstract Engine.
-- Main module, containing the abstract things.
@ -50,9 +50,9 @@
-- @usage local abstract = require("abstract")
local p = ... -- require path
local abstract
local ubiquitousse
abstract = {
ubiquitousse = {
--- Abstract version.
-- @impl abstract
version = "0.0.1",
@ -64,12 +64,12 @@ abstract = {
}
-- We're going to require modules requiring abstract, so to avoid stack overflows we already register the abstract package
package.loaded[p] = abstract
package.loaded[p] = ubiquitousse
-- Require external submodules
for _, m in ipairs({"time", "draw", "audio", "input", "scene", "event"}) do
local s, t = pcall(require, p.."."..m)
if s then abstract[m] = t end
if s then ubiquitousse[m] = t end
end
-- Backend engine autodetect and load
@ -79,4 +79,4 @@ elseif package.loaded["ctr"] then
require(p..".backend.ctrulua")
end
return abstract
return ubiquitousse

View file

@ -1,6 +1,6 @@
-- abstract.input
local abstract = require((...):match("^(.-abstract)%."))
local draw = require((...):match("^(.-abstract)%.")..".draw")
-- ubiquitousse.input
local uqt = require((...):match("^(.-ubiquitousse)%."))
local draw = require((...):match("^(.-ubiquitousse)%.")..".draw")
--- Used to store inputs which were updated this frame
-- { Input: true, ... }
@ -251,11 +251,11 @@ input = {
if mode == "relative" then
local movX, movY = math.abs(xAxis:value()), math.abs(yAxis:value())
if movX > maxMovX then
newX = x + (xSpeed and (xAxis:value() * xSpeed * abstract.time.dt) or xAxis:raw())
newX = x + (xSpeed and (xAxis:value() * xSpeed * uqt.time.dt) or xAxis:raw())
maxMovX = movX
end
if movY > maxMovY then
newY = y + (ySpeed and (yAxis:value() * ySpeed * abstract.time.dt) or yAxis:raw())
newY = y + (ySpeed and (yAxis:value() * ySpeed * uqt.time.dt) or yAxis:raw())
maxMovY = movY
end
elseif mode == "absolute" then
@ -365,7 +365,7 @@ input = {
},
--- Update all the Inputs.
-- Supposed to be called in abstract.event.update.
-- Supposed to be called in ubiquitousse.event.update.
-- @tparam numder dt the delta-time
-- @impl abstract
update = function(dt)

View file

@ -1,5 +1,5 @@
-- abstract.scene
local time = require((...):match("^(.-abstract)%.")..".time")
-- ubiquitousse.scene
local time = require((...):match("^(.-ubiquitousse)%.")..".time")
--- Returns the file path of the given module name.
local function getPath(modname)
@ -18,10 +18,10 @@ end
--- Scene management.
-- You can use use scenes to seperate the different states of your game: for example, a menu scene and a game scene.
-- This module is fully implemented in abstract and is mostly a "recommended way" of organising an abstract-based game.
-- However, you don't have to use this if you don't want to. abstract.scene handles all the differents abstract-states and
-- However, you don't have to use this if you don't want to. ubiquitousse.scene handles all the differents abstract-states and
-- make them scene-independent, for example by creating a scene-specific TimerRegistry (TimedFunctions that are keept accross
-- states are generally a bad idea). Theses scene-specific states should be created and available in the table returned by
-- abstract.scene.new.
-- ubiquitousse.scene.new.
-- Currently, the implementation always execute a scene's file before setting it as current, but this may change in the future or
-- for some implementations (e.g., on a computer where memory isn't a problem, the scene may be put in a cache). The result of this
-- is that you can load assets, libraries, etc. outside of the enter callback, so they can be cached and not reloaded each time
@ -29,11 +29,11 @@ end
-- each enter otherwise.
-- The expected code-organisation is:
-- * each scene is in a file, identified by its module name (same identifier used by Lua's require)
-- * each scene file create a new scene table using abstract.scene.new and returns it at the end of the file
-- * each scene file create a new scene table using ubiquitousse.scene.new and returns it at the end of the file
-- Order of callbacks:
-- * all scene exit callbacks are called before changing the stack or the current scene (ie, abstract.scene.current and the
-- * all scene exit callbacks are called before changing the stack or the current scene (ie, ubiquitousse.scene.current and the
-- last stack element is the scene in which the exit or suspend function was called)
-- * all scene enter callbacks are called before changing the stack or the current scene (ie, abstract.scene.current and the
-- * all scene enter callbacks are called before changing the stack or the current scene (ie, ubiquitousse.scene.current and the
-- last stack element is the previous scene which was just exited, and not the new scene)
local scene
scene = {
@ -61,8 +61,8 @@ scene = {
suspend = function() end, -- Called when suspending a scene, and expecting to come back (scene won't be unloaded).
resume = function() end, -- Called when resuming a suspended scene (after calling suspend).
update = function(dt, ...) end, -- Called on each abstract.event.update on the current scene.
draw = function(...) end -- Called on each abstract.event.draw on the current scene.
update = function(dt, ...) end, -- Called on each ubiquitousse.event.update on the current scene.
draw = function(...) end -- Called on each ubiquitousse.event.draw on the current scene.
}
end,
@ -81,8 +81,8 @@ scene = {
end,
--- Push a new scene to the scene stack.
-- Similar to abstract.scene.switch, except suspend is called on the current scene instead of exit,
-- and the current scene is not replaced: when the new scene call abstract.scene.pop, the old scene
-- Similar to ubiquitousse.scene.switch, except suspend is called on the current scene instead of exit,
-- and the current scene is not replaced: when the new scene call ubiquitousse.scene.pop, the old scene
-- will be reused.
-- @tparam string scenePath the new scene module name
-- @param ... arguments to pass to the scene's enter function
@ -107,7 +107,7 @@ scene = {
end,
--- Update the current scene.
-- Should be called in abstract.event.update.
-- Should be called in ubiquitousse.event.update.
-- @tparam number dt the delta-time (milisecond)
-- @param ... arguments to pass to the scene's update function after dt
-- @impl abstract
@ -119,7 +119,7 @@ scene = {
end,
--- Draw the current scene.
-- Should be called in abstract.event.draw.
-- Should be called in ubiquitousse.event.draw.
-- @param ... arguments to pass to the scene's draw function
-- @impl abstract
draw = function(...)

View file

@ -1,9 +1,9 @@
-- abstract.time
local ease = require((...):match("^(.-abstract)%.")..".lib.easing")
-- ubiquitousse.time
local ease = require((...):match("^(.-ubiquitousse)%.")..".lib.easing")
--- Time related functions
local function newTimerRegistry()
--- Used to store all the functions delayed with abstract.time.delay
--- Used to store all the functions delayed with ubiquitousse.time.delay
-- The default implementation use the structure {<key: function> = <value: data table>, ...}
-- This table is for internal use and shouldn't be used from an external script.
local delayed = {}
@ -14,9 +14,9 @@ local function newTimerRegistry()
local registry
registry = {
--- Creates and return a new TimerRegistry.
-- A TimerRegistry is a separate abstract.time instance: its TimedFunctions will be independant
-- from the one registered using abstract.time.run (the global TimerRegistry). If you use the scene
-- system, a scene-specific TimerRegistry is available at abstract.scene.current.time.
-- A TimerRegistry is a separate ubiquitousse.time instance: its TimedFunctions will be independant
-- from the one registered using ubiquitousse.time.run (the global TimerRegistry). If you use the scene
-- system, a scene-specific TimerRegistry is available at ubiquitousse.scene.current.time.
-- @impl abstract
new = function()
local new = newTimerRegistry()
@ -31,7 +31,7 @@ local function newTimerRegistry()
get = function() end,
--- Update all the TimedFunctions calls.
-- Supposed to be called in abstract.event.update.
-- Supposed to be called in ubiquitousse.event.update.
-- @tparam[opt=calculate here] numder dt the delta-time (time spent since last time the function was called) (miliseconds)
-- @impl abstract
update = function(dt)