mirror of
https://github.com/Reuh/ubiquitousse.git
synced 2025-10-27 17:19:31 +00:00
abstract is ded
This commit is contained in:
parent
07cc7216a1
commit
42738cc7c9
8 changed files with 219 additions and 135 deletions
|
|
@ -1,7 +1,7 @@
|
|||
--- 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.
|
||||
--- ctrµLua backend 0.0.1 for Ubiquitousse.
|
||||
-- Provides a partial Ubiquitousse API. Still a lot to implement.
|
||||
-- Made for some ctrµLua version and Ubiquitousse 0.0.1.
|
||||
-- See `ubiquitousse` for Ubiquitousse API.
|
||||
|
||||
-- General
|
||||
local version = "0.0.1"
|
||||
|
|
@ -15,7 +15,7 @@ local gfx = require("ctr.gfx")
|
|||
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.")
|
||||
local txt = ("Ubiquitousse 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 _=0,300 do
|
||||
|
|
@ -26,8 +26,8 @@ do
|
|||
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", uqt.version)
|
||||
checkCompat("ctrµLua", "v1.0", ctr.version) -- not really a version, just get the latest build
|
||||
checkCompat("Ubiquitousse", "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).
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
--- Löve backend 0.0.1 for Abstract.
|
||||
-- Provides all the Abstract API on a Löve environment.
|
||||
-- Made for Löve 0.10.1 and abstract 0.0.1.
|
||||
-- See `abstract` for Abstract API.
|
||||
--- Löve backend 0.0.1 for Ubiquitousse.
|
||||
-- Provides all the Ubiquitousse API on a Löve environment.
|
||||
-- Made for Löve 0.10.1 and Ubiquitousse 0.0.1.
|
||||
-- See `ubiquitousse` for Ubiquitousse API.
|
||||
|
||||
-- Config
|
||||
local useScancodes = true -- Use ScanCodes (layout independant input) instead of KeyConstants (layout dependant) for keyboard input
|
||||
|
|
@ -19,14 +19,14 @@ local uqt = require((...):match("^(.-ubiquitousse)%."))
|
|||
do
|
||||
local function checkCompat(stuffName, expectedVersion, actualVersion)
|
||||
if actualVersion ~= expectedVersion then
|
||||
local txt = ("Abstract Löve backend version "..version.." was made for %s %s but %s is used!\nThings may not work as expected.")
|
||||
local txt = ("Ubiquitousse Löve backend version "..version.." was made for %s %s but %s is used!\nThings may not work as expected.")
|
||||
:format(stuffName, expectedVersion, actualVersion)
|
||||
print(txt)
|
||||
love.window.showMessageBox("Warning", txt, "warning")
|
||||
end
|
||||
end
|
||||
checkCompat("Löve", "0.10.1", ("%s.%s.%s"):format(love.getVersion()))
|
||||
checkCompat("abstract", "0.0.1", uqt.version)
|
||||
checkCompat("Löve", "0.10.2", ("%s.%s.%s"):format(love.getVersion()))
|
||||
checkCompat("Ubiquitousse", "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).
|
||||
|
|
@ -51,7 +51,7 @@ function love.update(dt)
|
|||
-- Value update
|
||||
uqt.draw.fps = love.timer.getFPS()
|
||||
|
||||
-- Stuff defined in abstract.lua
|
||||
-- Stuff defined in ubiquitousse.lua
|
||||
updateDefault(dt*1000)
|
||||
|
||||
-- Callback
|
||||
|
|
@ -72,7 +72,7 @@ function love.draw()
|
|||
love.graphics.translate(math.floor(winW/2-gameW/2), math.floor(winH/2-gameH/2))
|
||||
end
|
||||
|
||||
-- Stuff defined in abstract.lua
|
||||
-- Stuff defined in ubiquitousse.lua
|
||||
drawDefault()
|
||||
|
||||
-- Callback
|
||||
|
|
@ -468,23 +468,9 @@ add(uqt.input, {
|
|||
-- Defaults
|
||||
uqt.input.default.pointer:bind(
|
||||
{ "absolute", "keyboard.left,keyboard.right", "keyboard.up,keyboard.down" },
|
||||
{ "absolute", "gamepad.axis.1.leftx", "gamepad.axis.1.lefty" }
|
||||
)
|
||||
uqt.input.default.up:bind(
|
||||
"keyboard.up", "keyboard.w",
|
||||
"gamepad.button.1.dpup", "gamepad.axis.1.lefty%-0.5"
|
||||
)
|
||||
uqt.input.default.down:bind(
|
||||
"keyboard.down", "keyboard.s",
|
||||
"gamepad.button.1.dpdown", "gamepad.axis.1.lefty%0.5"
|
||||
)
|
||||
uqt.input.default.right:bind(
|
||||
"keyboard.right", "keyboard.d",
|
||||
"gamepad.button.1.dpright", "gamepad.axis.1.leftx%0.5"
|
||||
)
|
||||
uqt.input.default.left:bind(
|
||||
"keyboard.left", "keyboard.a",
|
||||
"gamepad.button.1.dpleft", "gamepad.axis.1.leftx%-0.5"
|
||||
{ "absolute", "keyboard.a,keyboard.d", "keyboard.w,keyboard.s" },
|
||||
{ "absolute", "gamepad.axis.1.leftx", "gamepad.axis.1.lefty" },
|
||||
{ "absolute", "gamepad.button.1.dpleft,gamepad.button.1.dpright", "gamepad.button.1.dpup,gamepad.button.1.dpdown"}
|
||||
)
|
||||
uqt.input.default.confirm:bind(
|
||||
"keyboard.enter", "keyboard.space", "keyboard.lshift", "keyboard.e",
|
||||
|
|
|
|||
10
config.ld
10
config.ld
|
|
@ -1,9 +1,9 @@
|
|||
project = "Abstract"
|
||||
description = "Abstract Game Engine"
|
||||
full_description = "A simple Lua game engine, made to run everywhere. See the abstract module for more information."
|
||||
project = "Ubiquitousse"
|
||||
description = "Ubiquitousse Game Engine"
|
||||
full_description = "A simple Lua game engine, made to run everywhere. See the Ubiquitousse module for more information."
|
||||
|
||||
title = "Abstract Reference"
|
||||
package = "abstract"
|
||||
title = "Ubiquitousse Reference"
|
||||
package = "ubiquitousse"
|
||||
|
||||
file = "./"
|
||||
format = "markdown"
|
||||
|
|
|
|||
6
draw.lua
6
draw.lua
|
|
@ -14,9 +14,9 @@ local uqt = require((...):match("^(.-ubiquitousse)%."))
|
|||
local draw
|
||||
draw = {
|
||||
--- Initial game view paramters (some defaults).
|
||||
-- @impl abstract
|
||||
-- @impl ubiquitousse
|
||||
params = {
|
||||
title = "Abstract Engine",
|
||||
title = "Ubiquitousse Game",
|
||||
width = 800,
|
||||
height = 600,
|
||||
resizable = false,
|
||||
|
|
@ -29,7 +29,7 @@ draw = {
|
|||
-- @tparam table params the game parameters
|
||||
-- @usage -- Default values:
|
||||
-- ubiquitousse.init {
|
||||
-- title = "Abstract Engine", -- usually window title
|
||||
-- title = "Ubiquitousse Game", -- usually window title
|
||||
-- width = 800, -- in px
|
||||
-- height = 600, -- in px
|
||||
-- resizable = false, -- can the game be resized?
|
||||
|
|
|
|||
34
init.lua
34
init.lua
|
|
@ -1,33 +1,33 @@
|
|||
-- ubiquitousse
|
||||
|
||||
--- Abstract Engine.
|
||||
-- Main module, containing the abstract things.
|
||||
-- The API exposed here is the Abstract API.
|
||||
-- It is as the name imply abstract, and must be implemented in a backend, such as abstract.love.
|
||||
--- Ubiquitousse Game Engine.
|
||||
-- Main module, containing the main things.
|
||||
-- The API exposed here is the Ubiquitousse API.
|
||||
-- It is as the name does not imply anymore abstract, and must be implemented in a backend, such as ubiquitousse.love.
|
||||
-- When required, this file will try to autodetect the engine it is running on, and load a correct backend.
|
||||
--
|
||||
-- abstract may or may not be used as a full game engine. You can delete the modules files you don't need and abstract
|
||||
-- Ubiquitousse may or may not be used as a full game engine. You can delete the modules files you don't need and Ubiquitousse
|
||||
-- should adapt accordingly.
|
||||
--
|
||||
-- For backend writers:
|
||||
-- If a function defined here already contains some code, this means this code is mandatory and you must put/call
|
||||
-- it in your implementation.
|
||||
-- Also, a backend file shouldn't redefine the abstract table itself but only redefine the backend-dependant fields.
|
||||
-- Also, a backend file shouldn't redefine the ubiquitousse table itself but only redefine the backend-dependant fields.
|
||||
-- The API doesn't make the difference between numbers and integers, so convert to integers when needed.
|
||||
--
|
||||
-- Abstract's goal is to run everywhere with the least porting effort possible.
|
||||
-- Ubiquitousse's goal is to run everywhere with the least porting effort possible.
|
||||
-- To achieve this, the engine needs to stay simple, and only provide features that are almost sure to be
|
||||
-- available everywhere, so writing a backend should be straighforward.
|
||||
-- However, Abstract still make some small assumptions about the engine:
|
||||
-- However, Ubiquitousse still make some small assumptions about the engine:
|
||||
-- * The engine has some kind of main loop, or at least a function called very often (may or may not be the
|
||||
-- same as the redraw screen callback).
|
||||
-- * 32bit color depth.
|
||||
--
|
||||
-- Regarding data formats, Abstract reference implemtations expect and recommend:
|
||||
-- Regarding data formats, Ubiquitousse reference implemtations expect and recommend:
|
||||
-- * For images, PNG support is expected.
|
||||
-- * For audio files, OGG Vorbis support is expected.
|
||||
-- * For fonts, TTF support is expected.
|
||||
-- Theses formats are respected for the reference implementations, but Abstract may provide a script to
|
||||
-- Theses formats are respected for the reference implementations, but Ubiquitousse may provide a script to
|
||||
-- automatically convert data formats from a project at some point.
|
||||
--
|
||||
-- Units used in the API:
|
||||
|
|
@ -42,19 +42,19 @@
|
|||
-- * lowerCamelCase is expected for everything else.
|
||||
--
|
||||
-- Implementation levels:
|
||||
-- * backend: nothing defined in abstract, must be implemented in backend
|
||||
-- * mixed: partly implemented in abstract but must be complemeted in backend
|
||||
-- * abstract: fully-working version in abstract, may or may not be redefined in backend
|
||||
-- * backend: nothing defined in Ubiquitousse, must be implemented in backend
|
||||
-- * mixed: partly implemented in Ubiquitousse but must be complemeted in backend
|
||||
-- * ubiquitousse: fully-working version in Ubiquitousse, may or may not be redefined in backend
|
||||
-- The implementation level is indicated using the "@impl level" annotation.
|
||||
--
|
||||
-- @usage local abstract = require("abstract")
|
||||
-- @usage local ubiquitousse = require("ubiquitousse")
|
||||
|
||||
local p = ... -- require path
|
||||
local ubiquitousse
|
||||
|
||||
ubiquitousse = {
|
||||
--- Abstract version.
|
||||
-- @impl abstract
|
||||
--- Ubiquitousse version.
|
||||
-- @impl ubiquitousse
|
||||
version = "0.0.1",
|
||||
|
||||
--- Backend name.
|
||||
|
|
@ -63,7 +63,7 @@ ubiquitousse = {
|
|||
backend = "unknown"
|
||||
}
|
||||
|
||||
-- We're going to require modules requiring abstract, so to avoid stack overflows we already register the abstract package
|
||||
-- We're going to require modules requiring Ubiquitousse, so to avoid stack overflows we already register the ubiquitousse package
|
||||
package.loaded[p] = ubiquitousse
|
||||
|
||||
-- Require external submodules
|
||||
|
|
|
|||
214
input.lua
214
input.lua
|
|
@ -10,14 +10,17 @@ local updated = {}
|
|||
--- Input stuff
|
||||
-- Inspired by Tactile by Andrew Minnich (https://github.com/tesselode/tactile).
|
||||
-- I don't think I need to include the license since it's just inspiration, but for the sake of information, Tactile is under the MIT license.
|
||||
-- Abstract considers two input methods, called buttons (binary input) and axes (analog input).
|
||||
-- Ubiquitousse considers two input methods, called buttons (binary input) and axes (analog input).
|
||||
local input
|
||||
input = {
|
||||
---------------------------------
|
||||
--- Detectors (input sources) ---
|
||||
---------------------------------
|
||||
|
||||
-- Buttons detectors --
|
||||
-- A button detector is a function which returns true (pressed) or false (unpressed).
|
||||
-- Any fuction which returns a boolean can be used as a button detector, but you will probably want to get the data from an HID.
|
||||
-- Abstract being abstract, it doesn't suppose there is a keyboard and mouse available for example, and all HID buttons are identified using
|
||||
-- Ubiquitousse being platform-agnostic, it doesn't suppose there is a keyboard and mouse available for example, and all HID buttons are identified using
|
||||
-- an identifier string, which depends of the backend. Identifier strings should be of the format "source1.source2.[...].button", for example "keyboard.up"
|
||||
-- or "gamepad.button.1.a" for the A-button of the first gamepad.
|
||||
-- If the button is actually an axis (ie, the button is pressed if the axis value passes a certain threshold), the threshold should be in the end of the
|
||||
|
|
@ -27,7 +30,7 @@ input = {
|
|||
|
||||
--- Makes a new button detector(s) from the identifier(s) string.
|
||||
-- The function may error if the identifier is incorrect.
|
||||
-- @tparam string button identifier, depends on the platform abstract is running on (multiple parameters)
|
||||
-- @tparam string button identifier, depends on the platform Ubiquitousse is running on (multiple parameters)
|
||||
-- @treturn each button detector (multiple-returns)
|
||||
-- @impl backend
|
||||
buttonDetector = function(...) end,
|
||||
|
|
@ -37,20 +40,24 @@ input = {
|
|||
-- Threshold value can be used similarly with %.
|
||||
-- Axis detectors should support "binary axis", ie an axis defined by two buttons: if the 1rst button is pressed, value will be -1, if the 2nd is pressed it will be 1
|
||||
-- and if none or the both are pressed, the value will be 0. This kind of axis identifier should have an identifier like "button1,button2" (comma-separated).
|
||||
-- Axis detectors may also optionally return after the number between -1 and 1 the raw value and max value. The raw value is between -max and +max.
|
||||
|
||||
--- Makes a new axis detector(s) from the identifier(s) string.
|
||||
-- @tparam string axis identifier, depends on the platform abstract is running on (multiple parameters)
|
||||
-- @tparam string axis identifier, depends on the platform Ubiquitousse is running on (multiple parameters)
|
||||
-- @treturn each axis detector (multiple-returns)
|
||||
-- @impl backend
|
||||
axisDetector = function(...) end,
|
||||
|
||||
------------------------------------------
|
||||
--- Inputs (the thing you want to use) ---
|
||||
------------------------------------------
|
||||
|
||||
-- Buttons inputs --
|
||||
-- Button input is a container for buttons detector. A button will be pressed when one of its detectors returns true.
|
||||
-- Inputs also knows if the button was just pressed or released.
|
||||
-- @tparam ButtonDetectors ... all the buttons detectors or buttons identifiers
|
||||
-- @tretrun ButtonInput the object
|
||||
-- @impl abstract
|
||||
-- @impl ubiquitousse
|
||||
button = function(...)
|
||||
local r -- object
|
||||
local detectors = {} -- detectors list
|
||||
|
|
@ -82,6 +89,8 @@ input = {
|
|||
end
|
||||
-- Object
|
||||
r = {
|
||||
--- Returns a new ButtonInput with the same properties.
|
||||
-- @treturn ButtonInput the cloned object
|
||||
clone = function(self)
|
||||
local clone = input.button()
|
||||
for name, detector in pairs(detectors) do
|
||||
|
|
@ -94,6 +103,9 @@ input = {
|
|||
return clone
|
||||
end,
|
||||
|
||||
--- Bind new ButtonDetector(s) to this input.
|
||||
-- @tparam ButtonDetectors ... buttons detectors or buttons identifiers to add
|
||||
-- @treturn ButtonInput this ButtonInput object
|
||||
bind = function(self, ...)
|
||||
for _,d in ipairs({...}) do
|
||||
if type(d) == "string" then
|
||||
|
|
@ -106,6 +118,9 @@ input = {
|
|||
end
|
||||
return self
|
||||
end,
|
||||
--- Unbind ButtonDetector(s).
|
||||
-- @tparam ButtonDetectors ... buttons detectors or buttons identifiers to remove
|
||||
-- @treturn ButtonInput this ButtonInput object
|
||||
unbind = function(self, ...)
|
||||
for _,d in ipairs({...}) do
|
||||
detectors[d] = nil
|
||||
|
|
@ -113,15 +128,21 @@ input = {
|
|||
return self
|
||||
end,
|
||||
|
||||
pressed = function(_)
|
||||
--- Returns true if the input was just pressed.
|
||||
-- @treturn boolean true if the input was pressed, false otherwise
|
||||
pressed = function(self)
|
||||
update()
|
||||
return state == "pressed"
|
||||
end,
|
||||
down = function(_)
|
||||
--- Returns true if the input is down.
|
||||
-- @treturn boolean true if the input is currently down, false otherwise
|
||||
down = function(self)
|
||||
update()
|
||||
return state == "down" or state == "pressed"
|
||||
end,
|
||||
released = function(_)
|
||||
--- Returns true if the input was just released.
|
||||
-- @treturn boolean true if the input was released, false otherwise
|
||||
released = function(self)
|
||||
update()
|
||||
return state == "released"
|
||||
end,
|
||||
|
|
@ -130,7 +151,12 @@ input = {
|
|||
return r
|
||||
end,
|
||||
|
||||
-- TODO: doc
|
||||
-- Axis inputs --
|
||||
-- Axis input is a container for axes detector. An axis input will return the value of the axis detector the most far away from their center (0).
|
||||
-- Axis input provide a threshold setting ; every axis which has a distance to the center below th threshold will be ignored.
|
||||
-- @tparam AxisDetectors ... all the axis detectors or axis identifiers
|
||||
-- @tretrun AxisInput the object
|
||||
-- @impl ubiquitousse
|
||||
axis = function(...)
|
||||
local r -- object
|
||||
local detectors = {} -- detectors list
|
||||
|
|
@ -150,6 +176,8 @@ input = {
|
|||
end
|
||||
-- Object
|
||||
r = {
|
||||
--- Returns a new AxisInput with the same properties.
|
||||
-- @treturn AxisInput the cloned object
|
||||
clone = function(self)
|
||||
local clone = input.axis()
|
||||
for name, detector in pairs(detectors) do
|
||||
|
|
@ -163,6 +191,9 @@ input = {
|
|||
return clone
|
||||
end,
|
||||
|
||||
--- Bind new AxisDetector(s) to this input.
|
||||
-- @tparam AxisDetectors ... axis detectors or axis identifiers to add
|
||||
-- @treturn AxisInput this AxisInput object
|
||||
bind = function(self, ...)
|
||||
for _,d in ipairs({...}) do
|
||||
if type(d) == "string" then
|
||||
|
|
@ -175,6 +206,9 @@ input = {
|
|||
end
|
||||
return self
|
||||
end,
|
||||
--- Unbind AxisDetector(s).
|
||||
-- @tparam AxisDetectors ... axis detectors or axis identifiers to remove
|
||||
-- @treturn AxisInput this AxisInput object
|
||||
unbind = function(self, ...)
|
||||
for _,d in ipairs({...}) do
|
||||
detectors[d] = nil
|
||||
|
|
@ -182,58 +216,52 @@ input = {
|
|||
return self
|
||||
end,
|
||||
|
||||
--- Sets the default detection threshold (deadzone).
|
||||
-- @tparam number new the new detection threshold
|
||||
-- @treturn AxisInput this AxisInput object
|
||||
threshold = function(self, new)
|
||||
threshold = tonumber(new)
|
||||
return self
|
||||
end,
|
||||
|
||||
value = function(_, curThreshold)
|
||||
--- Returns the value of the input (between -1 and 1).
|
||||
-- @tparam[opt=default threshold] number threshold value to use
|
||||
-- @treturn number the input value
|
||||
value = function(self, curThreshold)
|
||||
update()
|
||||
return math.abs(value) > math.abs(curThreshold or threshold) and value or 0
|
||||
end,
|
||||
raw = function(_, rawThreshold)
|
||||
--- Returns the raw value of the input (between -max and +max).
|
||||
-- @tparam[opt=default threshold*max] number raw threshold value to use
|
||||
-- @treturn number the input raw value
|
||||
raw = function(self, rawThreshold)
|
||||
update()
|
||||
return math.abs(raw) > math.abs(rawThreshold or threshold*max) and raw or 0
|
||||
end,
|
||||
max = function(_)
|
||||
--- Return the raw max of the input.
|
||||
-- @treturn number the input raw max
|
||||
max = function(self)
|
||||
update()
|
||||
return max
|
||||
end
|
||||
end,
|
||||
|
||||
--- The associated button pressed when the axis reaches a positive value.
|
||||
positive = input.button(function() return r:value() > 0 end),
|
||||
--- The associated button pressed when the axis reaches a negative value.
|
||||
negative = input.button(function() return r:value() < 0 end)
|
||||
}
|
||||
r:bind(...)
|
||||
return r
|
||||
end,
|
||||
|
||||
--- Returns a list of the buttons currently in use, identified by their string button identifier.
|
||||
-- This may also returns "axis threshold" buttons if an axis passes the threshold.
|
||||
-- @treturn table<string> buttons identifiers list
|
||||
-- @treturn[opt=0.5] number threshold the threshold to detect axes as button
|
||||
-- @impl backend
|
||||
buttonsInUse = function(threshold) end,
|
||||
|
||||
--- Returns a list of the axes currently in use, identified by their string axis identifier
|
||||
-- @treturn table<string> axes identifiers list
|
||||
-- @treturn[opt=0.5] number threshold the threshold to detect axes
|
||||
-- @impl backend
|
||||
axesInUse = function(threshold) end,
|
||||
|
||||
--- Returns a nice name for the button identifier.
|
||||
-- Can be locale-depedant and stuff, it's only for display.
|
||||
-- May returns the raw identifier if you're lazy.
|
||||
-- @tparam string... button identifier string(s)
|
||||
-- @treturn string... the displayable names
|
||||
-- @impl backend
|
||||
buttonName = function(...) end,
|
||||
|
||||
--- Returns a nice name for the axis identifier.
|
||||
-- Can be locale-depedant and stuff, it's only for display.
|
||||
-- May returns the raw identifier if you're lazy.
|
||||
-- @tparam string... axis identifier string(s)
|
||||
-- @treturn string... the displayable names
|
||||
-- @impl backend
|
||||
axisName = function(...) end,
|
||||
|
||||
-- TODO: doc
|
||||
-- Pointer inputs --
|
||||
-- Pointer inputs are container for two axes input, in order to represent a two-dimensionnal pointing device, e.g. a mouse or a stick.
|
||||
-- Each pointer detector is a table with 3 fields: mode(string), XAxis(axis), YAxis(axis). mode can either be "relative" or "absolute".
|
||||
-- In relative mode, the pointer will return the movement since last update (for example to move a mouse pointer with a stick).
|
||||
-- In absolute mode, the pointer will return the pointer position directly deduced of the current axes position.
|
||||
-- @tparam table{mode,XAxis,YAxis} ... couples of axis detectors, axis identifiers or axis input to add and in which mode
|
||||
-- @tretrun PointerInput the object
|
||||
-- @impl ubiquitousse
|
||||
pointer = function(...)
|
||||
local pointers = {} -- pointers list
|
||||
local x, y = 0, 0 -- pointer position
|
||||
|
|
@ -277,6 +305,8 @@ input = {
|
|||
end
|
||||
end
|
||||
r = {
|
||||
--- Returns a new PointerInput with the same properties.
|
||||
-- @treturn PointerInput the cloned object
|
||||
clone = function(self)
|
||||
return input.pointer(unpack(pointers))
|
||||
:dimensions(width, height)
|
||||
|
|
@ -284,6 +314,9 @@ input = {
|
|||
:speed(xSpeed, ySpeed)
|
||||
end,
|
||||
|
||||
--- Bind new axis couples to this input.
|
||||
-- @tparam table{mode,XAxis,YAxis} ... couples of axis detectors, axis identifiers or axis input to add and in which mode
|
||||
-- @treturn PointerInput this PointerInput object
|
||||
bind = function(self, ...)
|
||||
for _,p in ipairs({...}) do
|
||||
if type(p) == "table" then
|
||||
|
|
@ -296,6 +329,9 @@ input = {
|
|||
end
|
||||
return self
|
||||
end,
|
||||
--- Unbind axis couples.
|
||||
-- @tparam table{mode,XAxis,YAxis} ... couples of axis detectors, axis identifiers or axis input to remove
|
||||
-- @treturn PointerInput this PointerInput object
|
||||
unbind = function(self, ...)
|
||||
for _,p in ipairs({...}) do
|
||||
for i,pointer in ipairs(pointers) do
|
||||
|
|
@ -312,7 +348,9 @@ input = {
|
|||
-- Call without argument to use half the window dimensions.
|
||||
-- It's the half dimensions because axes values goes from -1 to 1, so theses dimensions only
|
||||
-- covers values from x=0,y=0 to x=1,y=1. The full moving area will be 4*newWidth*newHeight.
|
||||
-- @impl abstract
|
||||
-- @tparam number newWidth new width
|
||||
-- @tparam number newHeight new height
|
||||
-- @treturn PointerInput this PointerInput object
|
||||
dimensions = function(self, newWidth, newHeight)
|
||||
width, height = newWidth, newHeight
|
||||
return self
|
||||
|
|
@ -320,7 +358,9 @@ input = {
|
|||
--- Set the moving area coordinates offset.
|
||||
-- The offset is a value automatically added to the x and y values when using the x() and y() methods.
|
||||
-- Call without argument to automatically offset so 0,0 <= x(),y() <= width,height, i.e. offset to width,height.
|
||||
-- @impl abstract
|
||||
-- @tparam number newOffX new X offset
|
||||
-- @tparam number newOffY new Y offset
|
||||
-- @treturn PointerInput this PointerInput object
|
||||
offset = function(self, newOffX, newOffY)
|
||||
offsetX, offsetY = newOffX, newOffY
|
||||
return self
|
||||
|
|
@ -328,46 +368,108 @@ input = {
|
|||
--- Set maximal speed (pixels-per-milisecond)
|
||||
-- Only used in relative mode.
|
||||
-- Calls without argument to use the raw data and don't apply a speed modifier.
|
||||
-- @impl abstract
|
||||
-- @tparam number newXSpeed new X speed
|
||||
-- @tparam number newYSpeed new Y speed
|
||||
-- @treturn PointerInput this PointerInput object
|
||||
speed = function(self, newXSpeed, newYSpeed)
|
||||
xSpeed, ySpeed = newXSpeed, newYSpeed or newXSpeed
|
||||
return self
|
||||
end,
|
||||
|
||||
--- Returns the current X value of the pointer.
|
||||
-- @treturn number X value
|
||||
x = function()
|
||||
update()
|
||||
return x + (offsetX or width or draw.width/2)
|
||||
end,
|
||||
--- Returns the current Y value of the pointer.
|
||||
-- @treturn number Y value
|
||||
y = function()
|
||||
update()
|
||||
return y + (offsetY or height or draw.height/2)
|
||||
end
|
||||
end,
|
||||
|
||||
--- The associated horizontal axis.
|
||||
horizontal = input.axis(function()
|
||||
local h = r:x()
|
||||
return h/width, h, width
|
||||
end),
|
||||
--- The associated vertical axis.
|
||||
vertical = input.axis(function()
|
||||
local v = r:y()
|
||||
return v/height, v, height
|
||||
end),
|
||||
|
||||
--- The associated button pressed when the pointer goes to the right.
|
||||
right = nil,
|
||||
--- The associated button pressed when the pointer goes to the left.
|
||||
left = nil,
|
||||
--- The associated button pressed when the pointer points up.
|
||||
up = nil,
|
||||
--- The associated button pressed when the pointer points down.
|
||||
down = nil
|
||||
}
|
||||
r.right, r.left = r.horizontal.positive, r.horizontal.negative
|
||||
r.up, r.down = r.vertical.negative, r.vertical.positive
|
||||
r:bind(...)
|
||||
return r
|
||||
end,
|
||||
|
||||
------------------------------
|
||||
--- Input detection helpers --
|
||||
------------------------------
|
||||
|
||||
--- Returns a list of the buttons currently in use, identified by their string button identifier.
|
||||
-- This may also returns "axis threshold" buttons if an axis passes the threshold.
|
||||
-- @treturn table<string> buttons identifiers list
|
||||
-- @treturn[opt=0.5] number threshold the threshold to detect axes as button
|
||||
-- @impl backend
|
||||
buttonsInUse = function(threshold) end,
|
||||
|
||||
--- Returns a list of the axes currently in use, identified by their string axis identifier
|
||||
-- @treturn table<string> axes identifiers list
|
||||
-- @treturn[opt=0.5] number threshold the threshold to detect axes
|
||||
-- @impl backend
|
||||
axesInUse = function(threshold) end,
|
||||
|
||||
--- Returns a nice name for the button identifier.
|
||||
-- Can be locale-depedant and stuff, it's only for display.
|
||||
-- May returns the raw identifier if you're lazy.
|
||||
-- @tparam string... button identifier string(s)
|
||||
-- @treturn string... the displayable names
|
||||
-- @impl backend
|
||||
buttonName = function(...) end,
|
||||
|
||||
--- Returns a nice name for the axis identifier.
|
||||
-- Can be locale-depedant and stuff, it's only for display.
|
||||
-- May returns the raw identifier if you're lazy.
|
||||
-- @tparam string... axis identifier string(s)
|
||||
-- @treturn string... the displayable names
|
||||
-- @impl backend
|
||||
axisName = function(...) end,
|
||||
|
||||
-------------------
|
||||
--- Other stuff ---
|
||||
-------------------
|
||||
|
||||
--- Some default inputs.
|
||||
-- The backend may bind detectors to thoses inputs.
|
||||
-- The backend should bind detectors to thoses inputs.
|
||||
-- These are used to provide some common input default detectors to allow to start a game quickly on
|
||||
-- any platform without having to configure the keys.
|
||||
-- If some key function in your game match one of theses defaults, using it instead of creating a new
|
||||
-- input would be a good idea.
|
||||
-- @impl mixed
|
||||
default = {
|
||||
pointer = nil, -- A default Pointer: used to move. Example binds: arrow keys, stick.
|
||||
up = nil, -- Button: similar to pointer, but only the up button.
|
||||
down = nil, -- Button: similar to pointer, but only the down button.
|
||||
right = nil, -- Button: similar to pointer, but only the right button.
|
||||
left = nil, -- Button: similar to pointer, but only the left button.
|
||||
pointer = nil, -- Pointer: used to move and select. Example binds: arrow keys, WASD, stick.
|
||||
confirm = nil, -- Button: used to confirm something. Example binds: Enter, A button.
|
||||
cancel = nil -- Button: used to cancel something. Example binds: Escape, B button.
|
||||
},
|
||||
|
||||
--- Update all the Inputs.
|
||||
-- Supposed to be called in ubiquitousse.event.update.
|
||||
-- The backend can hook into this function to to its input-related updates.
|
||||
-- @tparam numder dt the delta-time
|
||||
-- @impl abstract
|
||||
-- @impl ubiquitousse
|
||||
update = function(dt)
|
||||
updated = {}
|
||||
end
|
||||
|
|
@ -375,10 +477,6 @@ input = {
|
|||
|
||||
-- Create default inputs
|
||||
input.default.pointer = input.pointer()
|
||||
input.default.up = input.button()
|
||||
input.default.down = input.button()
|
||||
input.default.right = input.button()
|
||||
input.default.left = input.button()
|
||||
input.default.confirm = input.button()
|
||||
input.default.cancel = input.button()
|
||||
|
||||
|
|
|
|||
22
scene.lua
22
scene.lua
|
|
@ -17,8 +17,8 @@ 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. ubiquitousse.scene handles all the differents abstract-states and
|
||||
-- This module is fully implemented in Ubiquitousse and is mostly a "recommended way" of organising an Ubiquitousse-based game.
|
||||
-- However, you don't have to use this if you don't want to. ubiquitousse.scene handles all the differents Ubiquitousse-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
|
||||
-- ubiquitousse.scene.new.
|
||||
|
|
@ -38,19 +38,19 @@ end
|
|||
local scene
|
||||
scene = {
|
||||
--- The current scene table.
|
||||
-- @impl abstract
|
||||
-- @impl ubiquitousse
|
||||
current = nil,
|
||||
|
||||
--- The scene stack: list of scene, from the farest one to the nearest.
|
||||
-- @impl abstract
|
||||
-- @impl ubiquitousse
|
||||
stack = {},
|
||||
|
||||
--- A prefix for scene modules names
|
||||
-- @impl abstract
|
||||
-- @impl ubiquitousse
|
||||
prefix = "",
|
||||
|
||||
--- Creates and returns a new Scene object.
|
||||
-- @impl abstract
|
||||
-- @impl ubiquitousse
|
||||
new = function()
|
||||
return {
|
||||
time = time.new(), -- Scene-specific TimerRegistry.
|
||||
|
|
@ -71,7 +71,7 @@ scene = {
|
|||
-- the current scene will then be replaced by the new one, and then the enter callback is called.
|
||||
-- @tparam string scenePath the new scene module name
|
||||
-- @param ... arguments to pass to the scene's enter function
|
||||
-- @impl abstract
|
||||
-- @impl ubiquitousse
|
||||
switch = function(scenePath, ...)
|
||||
if scene.current then scene.current.exit() end
|
||||
scene.current = dofile(getPath(scene.prefix..scenePath))
|
||||
|
|
@ -86,7 +86,7 @@ scene = {
|
|||
-- will be reused.
|
||||
-- @tparam string scenePath the new scene module name
|
||||
-- @param ... arguments to pass to the scene's enter function
|
||||
-- @impl abstract
|
||||
-- @impl ubiquitousse
|
||||
push = function(scenePath, ...)
|
||||
if scene.current then scene.current.suspend() end
|
||||
scene.current = dofile(getPath(scene.prefix..scenePath))
|
||||
|
|
@ -97,7 +97,7 @@ scene = {
|
|||
--- Pop the current scene from the scene stack.
|
||||
-- The current scene exit function will be called, then the previous scene resume function will be called.
|
||||
-- Then the current scene will be removed from the stack, and the previous scene will be set as the current scene.
|
||||
-- @impl abstract
|
||||
-- @impl ubiquitousse
|
||||
pop = function()
|
||||
if scene.current then scene.current.exit() end
|
||||
local previous = scene.stack[#scene.stack-1]
|
||||
|
|
@ -110,7 +110,7 @@ scene = {
|
|||
-- 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
|
||||
-- @impl ubiquitousse
|
||||
update = function(dt, ...)
|
||||
if scene.current then
|
||||
scene.current.time.update(dt)
|
||||
|
|
@ -121,7 +121,7 @@ scene = {
|
|||
--- Draw the current scene.
|
||||
-- Should be called in ubiquitousse.event.draw.
|
||||
-- @param ... arguments to pass to the scene's draw function
|
||||
-- @impl abstract
|
||||
-- @impl ubiquitousse
|
||||
draw = function(...)
|
||||
if scene.current then scene.current.draw(...) end
|
||||
end
|
||||
|
|
|
|||
14
time.lua
14
time.lua
|
|
@ -17,7 +17,7 @@ local function newTimerRegistry()
|
|||
-- 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
|
||||
-- @impl ubiquitousse
|
||||
new = function()
|
||||
local new = newTimerRegistry()
|
||||
new.get = registry.get
|
||||
|
|
@ -32,8 +32,8 @@ local function newTimerRegistry()
|
|||
|
||||
--- Update all the TimedFunctions calls.
|
||||
-- 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
|
||||
-- @tparam[opt=calculate here] number dt the delta-time (time spent since last time the function was called) (miliseconds)
|
||||
-- @impl ubiquitousse
|
||||
update = function(dt)
|
||||
if dt then
|
||||
registry.dt = dt
|
||||
|
|
@ -95,7 +95,7 @@ local function newTimerRegistry()
|
|||
-- The function will receive as first parameter the wait(time) function, which will pause the function execution for time miliseconds.
|
||||
-- @tparam[opt] function func the function to schedule
|
||||
-- @treturn TimedFunction the object
|
||||
-- @impl abstract
|
||||
-- @impl ubiquitousse
|
||||
run = function(func)
|
||||
-- Creates empty function (the TimedFunction may be used for time measure or stuff like that which doesn't need a specific function)
|
||||
func = func or function() end
|
||||
|
|
@ -159,7 +159,7 @@ local function newTimerRegistry()
|
|||
-- @tparam table to the new values
|
||||
-- @tparam[opt="linear"] string/function method tweening method (string name or the actual function(time, start, change, duration))
|
||||
-- @treturn TimedFunction the object
|
||||
-- @impl abstract
|
||||
-- @impl ubiquitousse
|
||||
tween = function(duration, tbl, to, method)
|
||||
method = method or "linear"
|
||||
method = type(method) == "string" and ease[method] or method
|
||||
|
|
@ -177,13 +177,13 @@ local function newTimerRegistry()
|
|||
end,
|
||||
|
||||
--- Cancels all the running TimedFunctions.
|
||||
-- @impl abstract
|
||||
-- @impl ubiquitousse
|
||||
clear = function()
|
||||
delayed = {}
|
||||
end,
|
||||
|
||||
--- Time since last update (miliseconds).
|
||||
-- @impl abstract
|
||||
-- @impl ubiquitousse
|
||||
dt = 0
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue