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

Add LDoc for scene, timer, signal, util

This commit is contained in:
Étienne Fildadut 2021-12-25 20:45:44 +01:00
parent 23f797286b
commit d9eba04966
21 changed files with 3209 additions and 109 deletions

View file

@ -3,7 +3,7 @@ title = "Ubiquitousse reference"
description = "Ubiquitousse game development tools" description = "Ubiquitousse game development tools"
full_description = [[Set of Lua libraries to make game development easier using the [LÖVE](https://love2d.org/) game framework. full_description = [[Set of Lua libraries to make game development easier using the [LÖVE](https://love2d.org/) game framework.
See [main module](modules/init.html) for more information, or the [GitHub page](https://github.com/Reuh/ubiquitousse) for the source. See [main module](modules/ubiquitousse.html) for more information, or the [GitHub page](https://github.com/Reuh/ubiquitousse) for the source.
]] ]]
--package = "ubiquitousse" --package = "ubiquitousse"
@ -31,4 +31,14 @@ custom_display_name_handler = function(item, default_handler)
end end
topics = { "README.md", "LICENSE" } topics = { "README.md", "LICENSE" }
file = { "init.lua", "ldtk/ldtk.can", "ecs/ecs.can", "asset/asset.lua" } file = {
"init.lua",
"asset/asset.lua",
"ecs/ecs.can",
-- TODO: input
"ldtk/ldtk.can",
"scene/scene.lua",
"signal/signal.can",
"timer/timer.lua",
"util/util.lua"
}

View file

@ -33,9 +33,13 @@
<h2>Modules</h2> <h2>Modules</h2>
<ul class="nowrap"> <ul class="nowrap">
<li><a href="modules/ubiquitousse.html">ubiquitousse</a></li> <li><a href="modules/ubiquitousse.html">ubiquitousse</a></li>
<li><a href="modules/ldtk.html">ldtk</a></li>
<li><a href="modules/ecs.html">ecs</a></li>
<li><a href="modules/asset.html">asset</a></li> <li><a href="modules/asset.html">asset</a></li>
<li><a href="modules/ecs.html">ecs</a></li>
<li><a href="modules/ldtk.html">ldtk</a></li>
<li><a href="modules/scene.html">scene</a></li>
<li><a href="modules/signal.html">signal</a></li>
<li><a href="modules/timer.html">timer</a></li>
<li><a href="modules/util.html">util</a></li>
</ul> </ul>
<h2>Topics</h2> <h2>Topics</h2>
<ul class=""> <ul class="">
@ -51,7 +55,7 @@
<h2>Ubiquitousse game development tools</h2> <h2>Ubiquitousse game development tools</h2>
<p>Set of Lua libraries to make game development easier using the <a href="https://love2d.org/">LÖVE</a> game framework.</p> <p>Set of Lua libraries to make game development easier using the <a href="https://love2d.org/">LÖVE</a> game framework.</p>
<p>See <a href="modules/init.html">main module</a> for more information, or the <a href="https://github.com/Reuh/ubiquitousse">GitHub page</a> for the source.</p> <p>See <a href="modules/ubiquitousse.html">main module</a> for more information, or the <a href="https://github.com/Reuh/ubiquitousse">GitHub page</a> for the source.</p>
<h2>Modules</h2> <h2>Modules</h2>
<table class="module_list"> <table class="module_list">
@ -60,8 +64,8 @@
<td class="summary">Ubiquitousse main module.</td> <td class="summary">Ubiquitousse main module.</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="modules/ldtk.html">ldtk</a></td> <td class="name" nowrap><a href="modules/asset.html">asset</a></td>
<td class="summary"><a href="https://ldtk.io/">LDtk</a> level importer for Lua and drawing using LÖVE.</td> <td class="summary">Asset manager.</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="modules/ecs.html">ecs</a></td> <td class="name" nowrap><a href="modules/ecs.html">ecs</a></td>
@ -70,8 +74,24 @@
<p> Entity Component System library, inspired by the excellent tiny-ecs.</td> <p> Entity Component System library, inspired by the excellent tiny-ecs.</td>
</tr> </tr>
<tr> <tr>
<td class="name" nowrap><a href="modules/asset.html">asset</a></td> <td class="name" nowrap><a href="modules/ldtk.html">ldtk</a></td>
<td class="summary">Asset manager.</td> <td class="summary"><a href="https://ldtk.io/">LDtk</a> level importer for Lua and drawing using LÖVE.</td>
</tr>
<tr>
<td class="name" nowrap><a href="modules/scene.html">scene</a></td>
<td class="summary">Scene management.</td>
</tr>
<tr>
<td class="name" nowrap><a href="modules/signal.html">signal</a></td>
<td class="summary">Signal management.</td>
</tr>
<tr>
<td class="name" nowrap><a href="modules/timer.html">timer</a></td>
<td class="summary">Time related functions.</td>
</tr>
<tr>
<td class="name" nowrap><a href="modules/util.html">util</a></td>
<td class="summary">Various functions useful for game developement.</td>
</tr> </tr>
</table> </table>
<h2>Topics</h2> <h2>Topics</h2>
@ -90,7 +110,7 @@
</div> <!-- id="main" --> </div> <!-- id="main" -->
<div id="about"> <div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i> <i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
<i style="float:right;">Last updated 2021-12-25 19:17:08 </i> <i style="float:right;">Last updated 2021-12-25 20:46:24 </i>
</div> <!-- id="about" --> </div> <!-- id="about" -->
</div> <!-- id="container" --> </div> <!-- id="container" -->
</body> </body>

View file

@ -41,9 +41,13 @@
<h2>Modules</h2> <h2>Modules</h2>
<ul class="nowrap"> <ul class="nowrap">
<li><a href="../modules/ubiquitousse.html">ubiquitousse</a></li> <li><a href="../modules/ubiquitousse.html">ubiquitousse</a></li>
<li><a href="../modules/ldtk.html">ldtk</a></li>
<li><a href="../modules/ecs.html">ecs</a></li>
<li><strong>asset</strong></li> <li><strong>asset</strong></li>
<li><a href="../modules/ecs.html">ecs</a></li>
<li><a href="../modules/ldtk.html">ldtk</a></li>
<li><a href="../modules/scene.html">scene</a></li>
<li><a href="../modules/signal.html">signal</a></li>
<li><a href="../modules/timer.html">timer</a></li>
<li><a href="../modules/util.html">util</a></li>
</ul> </ul>
<h2>Topics</h2> <h2>Topics</h2>
<ul class=""> <ul class="">
@ -325,7 +329,7 @@
</div> <!-- id="main" --> </div> <!-- id="main" -->
<div id="about"> <div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i> <i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
<i style="float:right;">Last updated 2021-12-25 19:17:08 </i> <i style="float:right;">Last updated 2021-12-25 20:46:24 </i>
</div> <!-- id="about" --> </div> <!-- id="about" -->
</div> <!-- id="container" --> </div> <!-- id="container" -->
</body> </body>

View file

@ -42,9 +42,13 @@
<h2>Modules</h2> <h2>Modules</h2>
<ul class="nowrap"> <ul class="nowrap">
<li><a href="../modules/ubiquitousse.html">ubiquitousse</a></li> <li><a href="../modules/ubiquitousse.html">ubiquitousse</a></li>
<li><a href="../modules/ldtk.html">ldtk</a></li>
<li><strong>ecs</strong></li>
<li><a href="../modules/asset.html">asset</a></li> <li><a href="../modules/asset.html">asset</a></li>
<li><strong>ecs</strong></li>
<li><a href="../modules/ldtk.html">ldtk</a></li>
<li><a href="../modules/scene.html">scene</a></li>
<li><a href="../modules/signal.html">signal</a></li>
<li><a href="../modules/timer.html">timer</a></li>
<li><a href="../modules/util.html">util</a></li>
</ul> </ul>
<h2>Topics</h2> <h2>Topics</h2>
<ul class=""> <ul class="">
@ -73,7 +77,7 @@
<p> No mandatory dependency. <p> No mandatory dependency.
Optional dependency: <a href="../modules/ubiquitousse.html#scene">ubiquitousse.scene</a>, to allow quick creation of ECS-based scenes.</p> Optional dependency: <a href="../modules/ubiquitousse.html#scene">ubiquitousse.scene</a>, to allow quick creation of ECS-based scenes.</p>
<p> The module returns a table that contains several functions, <a href="../modules/ecs.html#world">world</a> or <a href="../modules/ecs.html#scene">scene</a> are starting points <p> The module returns a table that contains several functions, <a href="../modules/ecs.html#world">world</a> or <a href="../modules/scene.html#">scene</a> are starting points
to create your world.</p> to create your world.</p>
<h3>Usage:</h3> <h3>Usage:</h3>
<ul> <ul>
@ -1361,7 +1365,7 @@
</div> <!-- id="main" --> </div> <!-- id="main" -->
<div id="about"> <div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i> <i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
<i style="float:right;">Last updated 2021-12-25 19:17:08 </i> <i style="float:right;">Last updated 2021-12-25 20:46:24 </i>
</div> <!-- id="about" --> </div> <!-- id="about" -->
</div> <!-- id="container" --> </div> <!-- id="container" -->
</body> </body>

View file

@ -47,9 +47,13 @@
<h2>Modules</h2> <h2>Modules</h2>
<ul class="nowrap"> <ul class="nowrap">
<li><a href="../modules/ubiquitousse.html">ubiquitousse</a></li> <li><a href="../modules/ubiquitousse.html">ubiquitousse</a></li>
<li><strong>ldtk</strong></li>
<li><a href="../modules/ecs.html">ecs</a></li>
<li><a href="../modules/asset.html">asset</a></li> <li><a href="../modules/asset.html">asset</a></li>
<li><a href="../modules/ecs.html">ecs</a></li>
<li><strong>ldtk</strong></li>
<li><a href="../modules/scene.html">scene</a></li>
<li><a href="../modules/signal.html">signal</a></li>
<li><a href="../modules/timer.html">timer</a></li>
<li><a href="../modules/util.html">util</a></li>
</ul> </ul>
<h2>Topics</h2> <h2>Topics</h2>
<ul class=""> <ul class="">
@ -71,7 +75,7 @@
<p> This modules returns a single function, <a href="../modules/ldtk.html#LDtk">LDtk</a>(path).</p> <p> This modules returns a single function, <a href="../modules/ldtk.html#LDtk">LDtk</a>(path).</p>
<p> No mandatory dependency. <p> No mandatory dependency.
Requires LÖVE <code>love.graphics</code> (drawing Image, SpriteBatch, Quad) for drawing only.</p> Optionally requires LÖVE <code>love.graphics</code> (drawing Image, SpriteBatch, Quad) for drawing only.</p>
<h3>Usage:</h3> <h3>Usage:</h3>
<ul> <ul>
<pre class="example">local ldtk = require(&quot;ubiquitousse.ldtk&quot;) <pre class="example">local ldtk = require(&quot;ubiquitousse.ldtk&quot;)
@ -1583,7 +1587,7 @@ end
Level background. </p> Level background. </p>
<p> If there is a background image, <code>background.image</code> contains a table <code>{image=image, x=number, y=number, sx=number, sy=number}</code> <p> If there is a background image, <code>background.image</code> contains a table <code>{image=image, x=number, y=number, sx=number, sy=number}</code>
where <a href="../modules/ldtk.html#Tileset.image">image</a> is the LÖVE image (or image filepath if LÖVE not available) <a href="../modules/ldtk.html#IntTile.x">x</a> and <a href="../modules/ldtk.html#Tile.y">y</a> are the top-left position, where <a href="../modules/ldtk.html#Tileset.image">image</a> is the LÖVE image (or image filepath if LÖVE not available) <a href="../modules/ldtk.html#Entity.x">x</a> and <a href="../modules/ldtk.html#Level.y">y</a> are the top-left position,
and <a href="../modules/ldtk.html#Entity.sx">sx</a> and <a href="../modules/ldtk.html#Entity.sy">sy</a> the horizontal and vertical scale factors. and <a href="../modules/ldtk.html#Entity.sx">sx</a> and <a href="../modules/ldtk.html#Entity.sy">sy</a> the horizontal and vertical scale factors.
</ul> </ul>
@ -1640,7 +1644,7 @@ end
</div> <!-- id="main" --> </div> <!-- id="main" -->
<div id="about"> <div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i> <i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
<i style="float:right;">Last updated 2021-12-25 19:17:08 </i> <i style="float:right;">Last updated 2021-12-25 20:46:24 </i>
</div> <!-- id="about" --> </div> <!-- id="about" -->
</div> <!-- id="container" --> </div> <!-- id="container" -->
</body> </body>

679
docs/modules/scene.html Normal file
View file

@ -0,0 +1,679 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
<title>Ubiquitousse reference</title>
<link rel="stylesheet" href="../ldoc_new.css" type="text/css" />
</head>
<body>
<div id="container">
<div id="product">
<div id="product_logo"></div>
<div id="product_name"><big><b></b></big></div>
<div id="product_description"></div>
</div> <!-- id="product" -->
<div id="main">
<!-- Menu -->
<div id="navigation">
<br/>
<h1>Ubiquitousse</h1>
<ul>
<li><a href="../index.html">Index</a></li>
</ul>
<h2>Contents</h2>
<ul>
<li><a href="#Scene_objects">Scene objects </a></li>
<li><a href="#Module">Module </a></li>
</ul>
<h2>Modules</h2>
<ul class="nowrap">
<li><a href="../modules/ubiquitousse.html">ubiquitousse</a></li>
<li><a href="../modules/asset.html">asset</a></li>
<li><a href="../modules/ecs.html">ecs</a></li>
<li><a href="../modules/ldtk.html">ldtk</a></li>
<li><strong>scene</strong></li>
<li><a href="../modules/signal.html">signal</a></li>
<li><a href="../modules/timer.html">timer</a></li>
<li><a href="../modules/util.html">util</a></li>
</ul>
<h2>Topics</h2>
<ul class="">
<li><a href="../topics/README.md.html">README</a></li>
<li><a href="../topics/LICENSE.html">LICENSE</a></li>
</ul>
</div>
<div id="content">
<h1>Module <code>scene</code></h1>
<p>Scene management.</p>
<p><p> 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 Ubiquitousse and is mostly a &ldquo;recommended way&rdquo; of organising an Ubiquitousse-based game.
However, you don&rsquo;t have to use this if you don&rsquo;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.</p>
<p> The expected code-organisation is:</p>
<ul>
<li>each scene is in a file, identified by its module name (scenes will be loaded using require(&ldquo;modulename&rdquo;))</li>
<li>each scene file create a new scene table using ubiquitousse.scene.new and returns it at the end of the file</li>
</ul>
<p> Order of callbacks:</p>
<ul>
<li>all scene change callbacks are called after setting scene.current to the new scene but before changing scene.stack</li>
<li>all scene exit/suspend callbacks are called before scene enter/resume callbacks</li>
</ul>
<p> No mendatory dependency.
Optional dependencies:</p>
<ul>
<li>ubiquitousse.timer (to provide each scene a timer registry).</li>
<li>ubiquitousse.signal (to bind to update and draw signal in signal.event).</li>
</ul>
</p>
<h2><a href="#Scene_objects">Scene objects </a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#Scene.name">Scene.name</a></td>
<td class="summary">The scene name.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Scene.timer">Scene.timer</a></td>
<td class="summary">Scene-specific TimerRegistry, if uqt.time is available.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Scene.signal">Scene.signal</a></td>
<td class="summary">Scene-specific SignalRegistry, if uqt.signal is available.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Scene:enter">Scene:enter (...) <sup><em>[callback]</em></sup></a></td>
<td class="summary">Called when entering a scene.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Scene:exit">Scene:exit () <sup><em>[callback]</em></sup></a></td>
<td class="summary">Called when exiting a scene, and not expecting to come back (scene may be unloaded).</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Scene:suspend">Scene:suspend () <sup><em>[callback]</em></sup></a></td>
<td class="summary">Called when suspending a scene, and expecting to come back (scene won&rsquo;t be unloaded).</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Scene:resume">Scene:resume () <sup><em>[callback]</em></sup></a></td>
<td class="summary">Called when resuming a suspended scene (after calling suspend).</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Scene:update">Scene:update (dt, ...) <sup><em>[callback]</em></sup></a></td>
<td class="summary">Called on each update on the current scene.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#Scene:draw">Scene:draw (...) <sup><em>[callback]</em></sup></a></td>
<td class="summary">Called on each draw on the current scene.</td>
</tr>
</table>
<h2><a href="#Module">Module </a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#current">current</a></td>
<td class="summary">The current scene object.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#timer">timer</a></td>
<td class="summary">Shortcut for scene.current.timer.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#signal">signal</a></td>
<td class="summary">Shortcut for scene.current.signal.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#stack">stack</a></td>
<td class="summary">The scene stack: list of scene, from the farest one to the nearest.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#prefix">prefix</a></td>
<td class="summary">A prefix for scene modules names.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#new">new ([name="unamed"])</a></td>
<td class="summary">Creates and returns a new Scene object.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#switch">switch (scenePath, ...)</a></td>
<td class="summary">Switch to a new scene.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#push">push (scenePath, ...)</a></td>
<td class="summary">Push a new scene to the scene stack.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#pop">pop ()</a></td>
<td class="summary">Pop the current scene from the scene stack.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#popAll">popAll ()</a></td>
<td class="summary">Pop all scenes.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#update">update (dt, ...)</a></td>
<td class="summary">Update the current scene.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#draw">draw (...)</a></td>
<td class="summary">Draw the current scene.</td>
</tr>
</table>
<br/>
<br/>
<h2 class="section-header has-description"><a name="Scene_objects"></a>Scene objects </h2>
<div class="section-description">
Scene object.
</div>
<dl class="function">
<dt>
<a name = "Scene.name"></a>
<strong>Scene.name</strong>
</dt>
<dd>
The scene name.
</ul>
</ul>
</ul>
</ul>
</dd>
<dt>
<a name = "Scene.timer"></a>
<strong>Scene.timer</strong>
</dt>
<dd>
Scene-specific TimerRegistry, if uqt.time is available.
</ul>
</ul>
</ul>
</ul>
</dd>
<dt>
<a name = "Scene.signal"></a>
<strong>Scene.signal</strong>
</dt>
<dd>
Scene-specific SignalRegistry, if uqt.signal is available.
</ul>
</ul>
</ul>
</ul>
</dd>
<dt>
<a name = "Scene:enter"></a>
<strong>Scene:enter (...) <sup><em>[callback]</em></sup></strong>
</dt>
<dd>
Called when entering a scene.
</ul>
</ul>
</ul>
</ul>
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">...</span>
</li>
</ul>
</dd>
<dt>
<a name = "Scene:exit"></a>
<strong>Scene:exit () <sup><em>[callback]</em></sup></strong>
</dt>
<dd>
Called when exiting a scene, and not expecting to come back (scene may be unloaded).
</ul>
</ul>
</ul>
</ul>
</dd>
<dt>
<a name = "Scene:suspend"></a>
<strong>Scene:suspend () <sup><em>[callback]</em></sup></strong>
</dt>
<dd>
Called when suspending a scene, and expecting to come back (scene won&rsquo;t be unloaded).
</ul>
</ul>
</ul>
</ul>
</dd>
<dt>
<a name = "Scene:resume"></a>
<strong>Scene:resume () <sup><em>[callback]</em></sup></strong>
</dt>
<dd>
Called when resuming a suspended scene (after calling suspend).
</ul>
</ul>
</ul>
</ul>
</dd>
<dt>
<a name = "Scene:update"></a>
<strong>Scene:update (dt, ...) <sup><em>[callback]</em></sup></strong>
</dt>
<dd>
Called on each update on the current scene.
</ul>
</ul>
</ul>
</ul>
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">dt</span>
</li>
<li><span class="parameter">...</span>
</li>
</ul>
</dd>
<dt>
<a name = "Scene:draw"></a>
<strong>Scene:draw (...) <sup><em>[callback]</em></sup></strong>
</dt>
<dd>
Called on each draw on the current scene.
</ul>
</ul>
</ul>
</ul>
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">...</span>
</li>
</ul>
</dd>
</dl>
<h2 class="section-header "><a name="Module"></a>Module </h2>
<dl class="function">
<dt>
<a name = "current"></a>
<strong>current</strong>
</dt>
<dd>
The current scene object.
</ul>
</ul>
</ul>
</ul>
</dd>
<dt>
<a name = "timer"></a>
<strong>timer</strong>
</dt>
<dd>
Shortcut for scene.current.timer.
</ul>
</ul>
</ul>
</ul>
</dd>
<dt>
<a name = "signal"></a>
<strong>signal</strong>
</dt>
<dd>
Shortcut for scene.current.signal.
</ul>
</ul>
</ul>
</ul>
</dd>
<dt>
<a name = "stack"></a>
<strong>stack</strong>
</dt>
<dd>
The scene stack: list of scene, from the farest one to the nearest.
</ul>
</ul>
</ul>
</ul>
</dd>
<dt>
<a name = "prefix"></a>
<strong>prefix</strong>
</dt>
<dd>
A prefix for scene modules names.
Will search in the &ldquo;scene&rdquo; directory by default (<code>prefix=&quot;scene.&quot;</code>). Redefine it to fit your own ridiculous filesystem.
</ul>
</ul>
</ul>
</ul>
</dd>
<dt>
<a name = "new"></a>
<strong>new ([name="unamed"])</strong>
</dt>
<dd>
Creates and returns a new Scene object.
</ul>
</ul>
</ul>
</ul>
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">name</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
the new scene name
(<em>default</em> "unamed")
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="../modules/scene.html#Scene_objects">Scene</a></span>
</ol>
</dd>
<dt>
<a name = "switch"></a>
<strong>switch (scenePath, ...)</strong>
</dt>
<dd>
Switch to a new scene.
The new scene will be required() and the current scene will be replaced by the new one,
then the previous scene exit function will be called, then the enter callback is called on the new scence.
Then the stack is changed to replace the old scene with the new one.
</ul>
</ul>
</ul>
</ul>
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">scenePath</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string/table</a></span>
the new scene module name, or the scene table directly
</li>
<li><span class="parameter">...</span>
arguments to pass to the scene&rsquo;s enter function
</li>
</ul>
</dd>
<dt>
<a name = "push"></a>
<strong>push (scenePath, ...)</strong>
</dt>
<dd>
Push a new scene to the scene stack.
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.
</ul>
</ul>
</ul>
</ul>
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">scenePath</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string/table</a></span>
the new scene module name, or the scene table directly
</li>
<li><span class="parameter">...</span>
arguments to pass to the scene&rsquo;s enter function
</li>
</ul>
</dd>
<dt>
<a name = "pop"></a>
<strong>pop ()</strong>
</dt>
<dd>
Pop the current scene from the scene stack.
The previous scene will be set as the current scene, then the current scene exit function will be called,
then the previous scene resume function will be called, and then the current scene will be removed from the stack.
</ul>
</ul>
</ul>
</ul>
</dd>
<dt>
<a name = "popAll"></a>
<strong>popAll ()</strong>
</dt>
<dd>
Pop all scenes.
</ul>
</ul>
</ul>
</ul>
</dd>
<dt>
<a name = "update"></a>
<strong>update (dt, ...)</strong>
</dt>
<dd>
Update the current scene.
Should be called at every game update. If ubiquitousse.signal is available, will be bound to the &ldquo;update&rdquo; signal in signal.event.
</ul>
</ul>
</ul>
</ul>
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">dt</span>
<span class="types"><span class="type">number</span></span>
the delta-time (milisecond)
</li>
<li><span class="parameter">...</span>
arguments to pass to the scene&rsquo;s update function after dt
</li>
</ul>
</dd>
<dt>
<a name = "draw"></a>
<strong>draw (...)</strong>
</dt>
<dd>
Draw the current scene.
Should be called every time the game is draw. If ubiquitousse.signal is available, will be bound to the &ldquo;draw&rdquo; signal in signal.event.
</ul>
</ul>
</ul>
</ul>
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">...</span>
arguments to pass to the scene&rsquo;s draw function
</li>
</ul>
</dd>
</dl>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
<i style="float:right;">Last updated 2021-12-25 20:46:24 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>

410
docs/modules/signal.html Normal file
View file

@ -0,0 +1,410 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
<title>Ubiquitousse reference</title>
<link rel="stylesheet" href="../ldoc_new.css" type="text/css" />
</head>
<body>
<div id="container">
<div id="product">
<div id="product_logo"></div>
<div id="product_name"><big><b></b></big></div>
<div id="product_description"></div>
</div> <!-- id="product" -->
<div id="main">
<!-- Menu -->
<div id="navigation">
<br/>
<h1>Ubiquitousse</h1>
<ul>
<li><a href="../index.html">Index</a></li>
</ul>
<h2>Contents</h2>
<ul>
<li><a href="#Module">Module </a></li>
<li><a href="#SignalRegistry_objects">SignalRegistry objects </a></li>
</ul>
<h2>Modules</h2>
<ul class="nowrap">
<li><a href="../modules/ubiquitousse.html">ubiquitousse</a></li>
<li><a href="../modules/asset.html">asset</a></li>
<li><a href="../modules/ecs.html">ecs</a></li>
<li><a href="../modules/ldtk.html">ldtk</a></li>
<li><a href="../modules/scene.html">scene</a></li>
<li><strong>signal</strong></li>
<li><a href="../modules/timer.html">timer</a></li>
<li><a href="../modules/util.html">util</a></li>
</ul>
<h2>Topics</h2>
<ul class="">
<li><a href="../topics/README.md.html">README</a></li>
<li><a href="../topics/LICENSE.html">LICENSE</a></li>
</ul>
</div>
<div id="content">
<h1>Module <code>signal</code></h1>
<p>Signal management.</p>
<p> No dependency.</p>
<h2><a href="#Module">Module </a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#new">new ()</a></td>
<td class="summary">Creates and return a new SignalRegistry.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#event">event</a></td>
<td class="summary">SignalRegistry which will be used to bind signals that need to be called on game engine event; other ubiquitousse modules may bind to this registry
if avaible.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#registerEvents">registerEvents ()</a></td>
<td class="summary">Call this function to hook <a href="../modules/signal.html#event">signal.event</a> signals to LÖVE events.</td>
</tr>
</table>
<h2><a href="#SignalRegistry_objects">SignalRegistry objects </a></h2>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#SignalRegistry.signals">SignalRegistry.signals</a></td>
<td class="summary">Map of signals to list of listeners.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#SignalRegistry:bind">SignalRegistry:bind (name, fn, ...)</a></td>
<td class="summary">Bind one or several functions to a signal name.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#SignalRegistry:unbind">SignalRegistry:unbind (name, fn, ...)</a></td>
<td class="summary">Unbind one or several functions to a signal name.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#SignalRegistry:unbindAll">SignalRegistry:unbindAll (name)</a></td>
<td class="summary">Remove every bound function to a signal name.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#SignalRegistry:replace">SignalRegistry:replace (name, sourceFn, destFn)</a></td>
<td class="summary">Replace a bound function with another function.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#SignalRegistry:clear">SignalRegistry:clear ()</a></td>
<td class="summary">Remove every bound function to every signal.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#SignalRegistry:emit">SignalRegistry:emit (name, ...)</a></td>
<td class="summary">Emit a signal, i.e.</td>
</tr>
</table>
<br/>
<br/>
<h2 class="section-header "><a name="Module"></a>Module </h2>
<dl class="function">
<dt>
<a name = "new"></a>
<strong>new ()</strong>
</dt>
<dd>
Creates and return a new SignalRegistry.
</ul>
</ul>
</ul>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="../modules/signal.html#SignalRegistry_objects">SignalRegistry</a></span>
</ol>
</dd>
<dt>
<a name = "event"></a>
<strong>event</strong>
</dt>
<dd>
<p>SignalRegistry which will be used to bind signals that need to be called on game engine event; other ubiquitousse modules may bind to this registry
if avaible. </p>
<p> For example, every ubiquitousse module with a &ldquo;update&rdquo; function will bind it to the &ldquo;update&rdquo; signal in the registry;
you can then call this signal on each game update to update every ubiquitousse module easily.</p>
<p> Provided signals:</p>
<ul>
<li><code>update(dt)</code>, should be called on every game update</li>
<li><code>draw()</code>, should be called on every game draw</li>
<li>for LÖVE, there are callbacks for every LÖVE callback function that need to be called on their corresponding LÖVE callback</li>
</ul>
</ul>
</ul>
</ul>
</ul>
</dd>
<dt>
<a name = "registerEvents"></a>
<strong>registerEvents ()</strong>
</dt>
<dd>
Call this function to hook <a href="../modules/signal.html#event">signal.event</a> signals to LÖVE events.
This means overriding every existing LÖVE callback. If a callback is already defined, the new one will call the old function along with the signal:emit.
<h3>Requires:</h3>
<ul>
love
</ul>
</ul>
</ul>
</ul>
</dd>
</dl>
<h2 class="section-header has-description"><a name="SignalRegistry_objects"></a>SignalRegistry objects </h2>
<div class="section-description">
Signal registry. </p>
<p> A SignalRegistry is a separate ubiquitousse.signal instance: its signals will be independant from other registries.
</div>
<dl class="function">
<dt>
<a name = "SignalRegistry.signals"></a>
<strong>SignalRegistry.signals</strong>
</dt>
<dd>
Map of signals to list of listeners.
</ul>
</ul>
</ul>
</ul>
</dd>
<dt>
<a name = "SignalRegistry:bind"></a>
<strong>SignalRegistry:bind (name, fn, ...)</strong>
</dt>
<dd>
Bind one or several functions to a signal name.
</ul>
</ul>
</ul>
</ul>
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">name</span>
</li>
<li><span class="parameter">fn</span>
</li>
<li><span class="parameter">...</span>
</li>
</ul>
</dd>
<dt>
<a name = "SignalRegistry:unbind"></a>
<strong>SignalRegistry:unbind (name, fn, ...)</strong>
</dt>
<dd>
Unbind one or several functions to a signal name.
</ul>
</ul>
</ul>
</ul>
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">name</span>
</li>
<li><span class="parameter">fn</span>
</li>
<li><span class="parameter">...</span>
</li>
</ul>
</dd>
<dt>
<a name = "SignalRegistry:unbindAll"></a>
<strong>SignalRegistry:unbindAll (name)</strong>
</dt>
<dd>
Remove every bound function to a signal name.
</ul>
</ul>
</ul>
</ul>
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">name</span>
</li>
</ul>
</dd>
<dt>
<a name = "SignalRegistry:replace"></a>
<strong>SignalRegistry:replace (name, sourceFn, destFn)</strong>
</dt>
<dd>
Replace a bound function with another function.
</ul>
</ul>
</ul>
</ul>
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">name</span>
</li>
<li><span class="parameter">sourceFn</span>
</li>
<li><span class="parameter">destFn</span>
</li>
</ul>
</dd>
<dt>
<a name = "SignalRegistry:clear"></a>
<strong>SignalRegistry:clear ()</strong>
</dt>
<dd>
Remove every bound function to every signal.
</ul>
</ul>
</ul>
</ul>
</dd>
<dt>
<a name = "SignalRegistry:emit"></a>
<strong>SignalRegistry:emit (name, ...)</strong>
</dt>
<dd>
Emit a signal, i.e. call every function bound to it, with the given arguments.
</ul>
</ul>
</ul>
</ul>
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">name</span>
</li>
<li><span class="parameter">...</span>
</li>
</ul>
</dd>
</dl>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
<i style="float:right;">Last updated 2021-12-25 20:46:24 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>

1054
docs/modules/timer.html Normal file

File diff suppressed because it is too large Load diff

View file

@ -40,9 +40,13 @@
<h2>Modules</h2> <h2>Modules</h2>
<ul class="nowrap"> <ul class="nowrap">
<li><strong>ubiquitousse</strong></li> <li><strong>ubiquitousse</strong></li>
<li><a href="../modules/ldtk.html">ldtk</a></li>
<li><a href="../modules/ecs.html">ecs</a></li>
<li><a href="../modules/asset.html">asset</a></li> <li><a href="../modules/asset.html">asset</a></li>
<li><a href="../modules/ecs.html">ecs</a></li>
<li><a href="../modules/ldtk.html">ldtk</a></li>
<li><a href="../modules/scene.html">scene</a></li>
<li><a href="../modules/signal.html">signal</a></li>
<li><a href="../modules/timer.html">timer</a></li>
<li><a href="../modules/util.html">util</a></li>
</ul> </ul>
<h2>Topics</h2> <h2>Topics</h2>
<ul class=""> <ul class="">
@ -282,7 +286,7 @@
<h3>See also:</h3> <h3>See also:</h3>
<ul> <ul>
<a href="../modules/ubiquitousse.html#scene">scene</a> <a href="../modules/scene.html#">scene</a>
</ul> </ul>
@ -304,7 +308,7 @@
<h3>See also:</h3> <h3>See also:</h3>
<ul> <ul>
<a href="../modules/ubiquitousse.html#signal">signal</a> <a href="../modules/signal.html#">signal</a>
</ul> </ul>
@ -326,7 +330,7 @@
<h3>See also:</h3> <h3>See also:</h3>
<ul> <ul>
<a href="../modules/ubiquitousse.html#timer">timer</a> <a href="../modules/timer.html#">timer</a>
</ul> </ul>
@ -348,7 +352,7 @@
<h3>See also:</h3> <h3>See also:</h3>
<ul> <ul>
<a href="../modules/ubiquitousse.html#util">util</a> <a href="../modules/util.html#">util</a>
</ul> </ul>
@ -360,7 +364,7 @@
</div> <!-- id="main" --> </div> <!-- id="main" -->
<div id="about"> <div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i> <i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
<i style="float:right;">Last updated 2021-12-25 19:17:08 </i> <i style="float:right;">Last updated 2021-12-25 20:46:24 </i>
</div> <!-- id="about" --> </div> <!-- id="about" -->
</div> <!-- id="container" --> </div> <!-- id="container" -->
</body> </body>

786
docs/modules/util.html Normal file
View file

@ -0,0 +1,786 @@
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<head>
<title>Ubiquitousse reference</title>
<link rel="stylesheet" href="../ldoc_new.css" type="text/css" />
</head>
<body>
<div id="container">
<div id="product">
<div id="product_logo"></div>
<div id="product_name"><big><b></b></big></div>
<div id="product_description"></div>
</div> <!-- id="product" -->
<div id="main">
<!-- Menu -->
<div id="navigation">
<br/>
<h1>Ubiquitousse</h1>
<ul>
<li><a href="../index.html">Index</a></li>
</ul>
<h2>Contents</h2>
<ul>
<li><a href="#Functions">Functions </a></li>
</ul>
<h2>Modules</h2>
<ul class="nowrap">
<li><a href="../modules/ubiquitousse.html">ubiquitousse</a></li>
<li><a href="../modules/asset.html">asset</a></li>
<li><a href="../modules/ecs.html">ecs</a></li>
<li><a href="../modules/ldtk.html">ldtk</a></li>
<li><a href="../modules/scene.html">scene</a></li>
<li><a href="../modules/signal.html">signal</a></li>
<li><a href="../modules/timer.html">timer</a></li>
<li><strong>util</strong></li>
</ul>
<h2>Topics</h2>
<ul class="">
<li><a href="../topics/README.md.html">README</a></li>
<li><a href="../topics/LICENSE.html">LICENSE</a></li>
</ul>
</div>
<div id="content">
<h1>Module <code>util</code></h1>
<p>Various functions useful for game developement.</p>
<p> No dependency.</p>
<h2><a href="#Functions">Functions </a></h2>
<table class="function_list">
</table>
<h3 class="doc-title"><a href="#math">Basic maths</a></h3>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#aabb">aabb (x1, y1, w1, h1, x2, y2, w2, h2)</a></td>
<td class="summary">AABB collision check.</td>
</tr>
</table>
<h3 class="doc-title"><a href="#list">List operations</a></h3>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#has">has (t, v)</a></td>
<td class="summary">Check if the list contains a value.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#remove">remove (t, x[, n=#t])</a></td>
<td class="summary">Remove the first occurence of an element in a list.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#extract">extract (t, k[, n=#t])</a></td>
<td class="summary">Extract the list of elements with a specific key from a list of tables</td>
</tr>
<tr>
<td class="name" nowrap><a href="#ipairs">ipairs (a, b[, ...])</a></td>
<td class="summary">Chainable ipairs.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#each">each (t, fn[, n=#t])</a></td>
<td class="summary">Applies a function to every item in list t.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#map">map (t, fn[, n=#t])</a></td>
<td class="summary">Applies a function to every item in list t and returns the associated new list.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#all">all (t, fn[, n=#t])</a></td>
<td class="summary">Test if all the values in the list are true.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#any">any (t, fn[, n=#t])</a></td>
<td class="summary">Test if at least one value in the list is true.</td>
</tr>
</table>
<h3 class="doc-title"><a href="#dict">Dictionary operations</a></h3>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#invert">invert (t)</a></td>
<td class="summary">Returns a new table where the keys and values have been inverted.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#copy">copy (t)</a></td>
<td class="summary">Perform a deep copy of a table.</td>
</tr>
<tr>
<td class="name" nowrap><a href="#requirer">requirer ([prefix=""])</a></td>
<td class="summary">Returns a table which, when indexed, will require() the module with the index as a name (and a optional prefix).</td>
</tr>
</table>
<h3 class="doc-title"><a href="#random">Random and UUID</a></h3>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#uuid4">uuid4 ()</a></td>
<td class="summary">Generate a UUID v4.</td>
</tr>
</table>
<h3 class="doc-title"><a href="#grouping">Object grouping</a></h3>
<table class="function_list">
<tr>
<td class="name" nowrap><a href="#group">group (list[, n=#t[, p=nil]])</a></td>
<td class="summary">Groups objects in a meta-object-proxy-thingy.</td>
</tr>
</table>
<br/>
<br/>
<h2 class="section-header "><a name="Functions"></a>Functions </h2>
<dl class="function">
</dl>
<h3 class="doc-title"><a name = "math"></a>Basic maths</h3>
<div class="doc-description">
</div>
<dl class="function">
</ul>
</ul>
</ul>
</ul>
</dd>
<dt>
<a name = "aabb"></a>
<strong>aabb (x1, y1, w1, h1, x2, y2, w2, h2)</strong>
</dt>
<dd>
AABB collision check.
</ul>
</ul>
</ul>
</ul>
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">x1</span>
<span class="types"><span class="type">number</span></span>
first rectangle top-left x coordinate
</li>
<li><span class="parameter">y1</span>
<span class="types"><span class="type">number</span></span>
first rectangle top-left y coordinate
</li>
<li><span class="parameter">w1</span>
<span class="types"><span class="type">number</span></span>
first rectangle width
</li>
<li><span class="parameter">h1</span>
<span class="types"><span class="type">number</span></span>
first rectangle height
</li>
<li><span class="parameter">x2</span>
<span class="types"><span class="type">number</span></span>
second rectangle top-left x coordinate
</li>
<li><span class="parameter">y2</span>
<span class="types"><span class="type">number</span></span>
second rectangle top-left y coordinate
</li>
<li><span class="parameter">w2</span>
<span class="types"><span class="type">number</span></span>
second rectangle width
</li>
<li><span class="parameter">h2</span>
<span class="types"><span class="type">number</span></span>
second rectangle height
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">true</span></span>
if the objects collide, false otherwise
</ol>
</dd>
</dl>
<h3 class="doc-title"><a name = "list"></a>List operations</h3>
<div class="doc-description">
</div>
<dl class="function">
</ul>
</ul>
</ul>
</ul>
</dd>
<dt>
<a name = "has"></a>
<strong>has (t, v)</strong>
</dt>
<dd>
Check if the list contains a value.
</ul>
</ul>
</ul>
</ul>
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">t</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a></span>
the list
</li>
<li><span class="parameter">v</span>
value to search
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">bool</span></span>
true if is in list, false otherwise
</ol>
</dd>
<dt>
<a name = "remove"></a>
<strong>remove (t, x[, n=#t])</strong>
</dt>
<dd>
Remove the first occurence of an element in a list.
</ul>
</ul>
</ul>
</ul>
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">t</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a></span>
the list
</li>
<li><span class="parameter">x</span>
the element to remove
</li>
<li><span class="parameter">n</span>
<span class="types"><span class="type">number</span></span>
the number of expected elements in the list, including nil values
(<em>default</em> #t)
</li>
</ul>
<h3>Returns:</h3>
<ol>
x the removed element
</ol>
</dd>
<dt>
<a name = "extract"></a>
<strong>extract (t, k[, n=#t])</strong>
</dt>
<dd>
Extract the list of elements with a specific key from a list of tables
</ul>
</ul>
</ul>
</ul>
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">t</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a></span>
the list of tables
</li>
<li><span class="parameter">k</span>
the chosen key
</li>
<li><span class="parameter">n</span>
<span class="types"><span class="type">number</span></span>
the number of expected elements in the list, including nil values
(<em>default</em> #t)
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a></span>
the extracted table
</ol>
</dd>
<dt>
<a name = "ipairs"></a>
<strong>ipairs (a, b[, ...])</strong>
</dt>
<dd>
Chainable ipairs.
Same as ipairs, but can take several tables, which will be chained, in order.
</ul>
</ul>
</ul>
</ul>
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">a</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a></span>
first list to iterate over
</li>
<li><span class="parameter">b</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a></span>
second list to iterate over after the first one
</li>
<li><span class="parameter">...</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table,...</a></span>
next tables to iterate over
(<em>optional</em>)
</li>
</ul>
</dd>
<dt>
<a name = "each"></a>
<strong>each (t, fn[, n=#t])</strong>
</dt>
<dd>
Applies a function to every item in list t.
The function receive two argument: the value and then the key.
</ul>
</ul>
</ul>
</ul>
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">t</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a></span>
initial list
</li>
<li><span class="parameter">fn</span>
<span class="types"><span class="type">function</span></span>
the function to apply
</li>
<li><span class="parameter">n</span>
<span class="types"><span class="type">number</span></span>
the number of expected elements in the list, including nil values
(<em>default</em> #t)
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a></span>
the initial list
</ol>
</dd>
<dt>
<a name = "map"></a>
<strong>map (t, fn[, n=#t])</strong>
</dt>
<dd>
Applies a function to every item in list t and returns the associated new list.
The function receive two argument: the value and then the key.
</ul>
</ul>
</ul>
</ul>
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">t</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a></span>
initial list
</li>
<li><span class="parameter">fn</span>
<span class="types"><span class="type">function</span></span>
the function to apply
</li>
<li><span class="parameter">n</span>
<span class="types"><span class="type">number</span></span>
the number of expected elements in the list, including nil values
(<em>default</em> #t)
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a></span>
the new list
</ol>
</dd>
<dt>
<a name = "all"></a>
<strong>all (t, fn[, n=#t])</strong>
</dt>
<dd>
Test if all the values in the list are true. Optionnaly applies a function to get the truthness.
The function receive two argument: the value and then the key.
</ul>
</ul>
</ul>
</ul>
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">t</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a></span>
initial list
</li>
<li><span class="parameter">fn</span>
<span class="types"><span class="type">function</span></span>
the function to apply
</li>
<li><span class="parameter">n</span>
<span class="types"><span class="type">number</span></span>
the number of expected elements in the list, including nil values
(<em>default</em> #t)
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">boolean</span></span>
result
</ol>
</dd>
<dt>
<a name = "any"></a>
<strong>any (t, fn[, n=#t])</strong>
</dt>
<dd>
Test if at least one value in the list is true. Optionnaly applies a function to get the truthness.
The function receive two argument: the value and then the key.
</ul>
</ul>
</ul>
</ul>
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">t</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a></span>
initial list
</li>
<li><span class="parameter">fn</span>
<span class="types"><span class="type">function</span></span>
the function to apply
</li>
<li><span class="parameter">n</span>
<span class="types"><span class="type">number</span></span>
the number of expected elements in the list, including nil values
(<em>default</em> #t)
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">boolean</span></span>
result
</ol>
</dd>
</dl>
<h3 class="doc-title"><a name = "dict"></a>Dictionary operations</h3>
<div class="doc-description">
</div>
<dl class="function">
</ul>
</ul>
</ul>
</ul>
</dd>
<dt>
<a name = "invert"></a>
<strong>invert (t)</strong>
</dt>
<dd>
Returns a new table where the keys and values have been inverted.
</ul>
</ul>
</ul>
</ul>
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">t</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a></span>
the table
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a></span>
the inverted table
</ol>
</dd>
<dt>
<a name = "copy"></a>
<strong>copy (t)</strong>
</dt>
<dd>
Perform a deep copy of a table.
The copied table will keep the share the same metatable as the original table.
If a key is a table, it will be reused and not copied.
Note this uses pairs() to perform the copy, which will honor the __pairs methamethod if present.
</ul>
</ul>
</ul>
</ul>
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">t</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a></span>
the table
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a></span>
the copied table
</ol>
</dd>
<dt>
<a name = "requirer"></a>
<strong>requirer ([prefix=""])</strong>
</dt>
<dd>
Returns a table which, when indexed, will require() the module with the index as a name (and a optional prefix).
</ul>
</ul>
</ul>
</ul>
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">prefix</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
that will prefix modules names when calling require()
(<em>default</em> "")
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a></span>
the requirer table
</ol>
</dd>
</dl>
<h3 class="doc-title"><a name = "random"></a>Random and UUID</h3>
<div class="doc-description">
</div>
<dl class="function">
</ul>
</ul>
</ul>
</ul>
</dd>
<dt>
<a name = "uuid4"></a>
<strong>uuid4 ()</strong>
</dt>
<dd>
Generate a UUID v4.
</ul>
</ul>
</ul>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.4">string</a></span>
the UUID in its canonical representation
</ol>
</dd>
</dl>
<h3 class="doc-title"><a name = "grouping"></a>Object grouping</h3>
<div class="doc-description">
</div>
<dl class="function">
</ul>
</ul>
</ul>
</ul>
</dd>
<dt>
<a name = "group"></a>
<strong>group (list[, n=#t[, p=nil]])</strong>
</dt>
<dd>
Groups objects in a meta-object-proxy-thingy.
Works great with Lua 5.2+. LuaJit requires to be built with Lua 5.2 compatibility enabled to support group comparaison.
</ul>
</ul>
</ul>
</ul>
<h3>Parameters:</h3>
<ul>
<li><span class="parameter">list</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a></span>
of objects
</li>
<li><span class="parameter">n</span>
<span class="types"><span class="type">number</span></span>
the number of expected elements in the list, including nil values
(<em>default</em> #t)
</li>
<li><span class="parameter">p</span>
<span class="types"><a class="type" href="https://www.lua.org/manual/5.1/manual.html#5.5">table</a></span>
list of parents. Used to find the first arguments of method calls.
(<em>default</em> nil)
</li>
</ul>
<h3>Returns:</h3>
<ol>
<span class="types"><span class="type">Group</span></span>
object
</ol>
</dd>
</dl>
</div> <!-- id="content" -->
</div> <!-- id="main" -->
<div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
<i style="float:right;">Last updated 2021-12-25 20:46:24 </i>
</div> <!-- id="about" -->
</div> <!-- id="container" -->
</body>
</html>

View file

@ -41,9 +41,13 @@
<h2>Modules</h2> <h2>Modules</h2>
<ul class="nowrap"> <ul class="nowrap">
<li><a href="../modules/ubiquitousse.html">ubiquitousse</a></li> <li><a href="../modules/ubiquitousse.html">ubiquitousse</a></li>
<li><a href="../modules/ldtk.html">ldtk</a></li>
<li><a href="../modules/ecs.html">ecs</a></li>
<li><a href="../modules/asset.html">asset</a></li> <li><a href="../modules/asset.html">asset</a></li>
<li><a href="../modules/ecs.html">ecs</a></li>
<li><a href="../modules/ldtk.html">ldtk</a></li>
<li><a href="../modules/scene.html">scene</a></li>
<li><a href="../modules/signal.html">signal</a></li>
<li><a href="../modules/timer.html">timer</a></li>
<li><a href="../modules/util.html">util</a></li>
</ul> </ul>
</div> </div>
@ -60,7 +64,7 @@
</div> <!-- id="main" --> </div> <!-- id="main" -->
<div id="about"> <div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i> <i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
<i style="float:right;">Last updated 2021-12-25 19:17:08 </i> <i style="float:right;">Last updated 2021-12-25 20:46:24 </i>
</div> <!-- id="about" --> </div> <!-- id="about" -->
</div> <!-- id="container" --> </div> <!-- id="container" -->
</body> </body>

View file

@ -41,9 +41,13 @@
<h2>Modules</h2> <h2>Modules</h2>
<ul class="nowrap"> <ul class="nowrap">
<li><a href="../modules/ubiquitousse.html">ubiquitousse</a></li> <li><a href="../modules/ubiquitousse.html">ubiquitousse</a></li>
<li><a href="../modules/ldtk.html">ldtk</a></li>
<li><a href="../modules/ecs.html">ecs</a></li>
<li><a href="../modules/asset.html">asset</a></li> <li><a href="../modules/asset.html">asset</a></li>
<li><a href="../modules/ecs.html">ecs</a></li>
<li><a href="../modules/ldtk.html">ldtk</a></li>
<li><a href="../modules/scene.html">scene</a></li>
<li><a href="../modules/signal.html">signal</a></li>
<li><a href="../modules/timer.html">timer</a></li>
<li><a href="../modules/util.html">util</a></li>
</ul> </ul>
</div> </div>
@ -65,7 +69,7 @@
</div> <!-- id="main" --> </div> <!-- id="main" -->
<div id="about"> <div id="about">
<i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i> <i>generated by <a href="http://github.com/stevedonovan/LDoc">LDoc 1.4.6</a></i>
<i style="float:right;">Last updated 2021-12-25 19:17:08 </i> <i style="float:right;">Last updated 2021-12-25 20:46:24 </i>
</div> <!-- id="about" --> </div> <!-- id="about" -->
</div> <!-- id="container" --> </div> <!-- id="container" -->
</body> </body>

View file

@ -7,7 +7,7 @@
-- This modules returns a single function, @{LDtk}(path). -- This modules returns a single function, @{LDtk}(path).
-- --
-- No mandatory dependency. -- No mandatory dependency.
-- Requires LÖVE `love.graphics` (drawing Image, SpriteBatch, Quad) for drawing only. -- Optionally requires LÖVE `love.graphics` (drawing Image, SpriteBatch, Quad) for drawing only.
-- --
-- @module ldtk -- @module ldtk
-- @require love -- @require love

7
scene/README.md Normal file
View file

@ -0,0 +1,7 @@
# ubiquitousse.scene
Scene management library.
You can read the documentation [here](https://reuh.github.io/ubiquitousse/modules/scene.html).
Licensed under ISC (equivalent to MIT/Expat/Simplified BSD).

View file

@ -1,27 +1,68 @@
--- ubiquitousse.scene
-- Optional dependencies: ubiquitousse.timer (to provide each scene a timer registry)
-- Optional dependencies: ubiquitousse.signal (to bind to update and draw signal in signal.event)
local loaded, signal = pcall(require, (...):match("^(.-)scene").."signal")
if not loaded then signal = nil end
local loaded, timer = pcall(require, (...):match("^(.-)scene").."timer")
if not loaded then timer = nil end
--- Scene management. --- Scene management.
--
-- You can use use scenes to seperate the different states of your game: for example, a menu scene and a game scene. -- 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 Ubiquitousse and is mostly a "recommended way" of organising an Ubiquitousse-based game. -- 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 -- 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 -- 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 -- states are generally a bad idea). Theses scene-specific states should be created and available in the table returned by
-- ubiquitousse.scene.new. -- ubiquitousse.scene.new.
--
-- The expected code-organisation is: -- The expected code-organisation is:
--
-- * each scene is in a file, identified by its module name (scenes will be loaded using require("modulename")) -- * each scene is in a file, identified by its module name (scenes will be loaded using require("modulename"))
-- * each scene file create a new scene table using ubiquitousse.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: -- Order of callbacks:
--
-- * all scene change callbacks are called after setting scene.current to the new scene but before changing scene.stack -- * all scene change callbacks are called after setting scene.current to the new scene but before changing scene.stack
-- * all scene exit/suspend callbacks are called before scene enter/resume callbacks -- * all scene exit/suspend callbacks are called before scene enter/resume callbacks
--
-- No mendatory dependency.
-- Optional dependencies:
--
-- * ubiquitousse.timer (to provide each scene a timer registry).
-- * ubiquitousse.signal (to bind to update and draw signal in signal.event).
-- @module scene
local loaded, signal = pcall(require, (...):match("^(.-)scene").."signal")
if not loaded then signal = nil end
local loaded, timer = pcall(require, (...):match("^(.-)scene").."timer")
if not loaded then timer = nil end
--- Scene object.
-- @type Scene
local _ = {
--- The scene name.
name = name or "unamed",
--- Scene-specific TimerRegistry, if uqt.time is available.
timer = timer and timer.new(),
--- Scene-specific SignalRegistry, if uqt.signal is available.
signal = signal and signal.new(),
--- Called when entering a scene.
-- @callback
enter = function(self, ...) end,
--- Called when exiting a scene, and not expecting to come back (scene may be unloaded).
-- @callback
exit = function(self) end,
--- Called when suspending a scene, and expecting to come back (scene won't be unloaded).
-- @callback
suspend = function(self) end,
--- Called when resuming a suspended scene (after calling suspend).
-- @callback
resume = function(self) end,
--- Called on each update on the current scene.
-- @callback
update = function(self, dt, ...) end,
--- Called on each draw on the current scene.
-- @callback
draw = function(self, ...) end
}
--- Module.
-- @section module
local scene local scene
scene = { scene = {
--- The current scene table. --- The current scene object.
current = nil, current = nil,
--- Shortcut for scene.current.timer. --- Shortcut for scene.current.timer.
@ -33,26 +74,23 @@ scene = {
stack = {}, stack = {},
--- A prefix for scene modules names. --- A prefix for scene modules names.
-- Will search in the "scene" directory by default. Redefine it to fit your own ridiculous filesystem. -- Will search in the "scene" directory by default (`prefix="scene."`). Redefine it to fit your own ridiculous filesystem.
prefix = "scene.", prefix = "scene.",
--- Creates and returns a new Scene object. --- Creates and returns a new Scene object.
-- @tparam[opt="unamed"] string name the new scene name -- @tparam[opt="unamed"] string name the new scene name
-- @treturn Scene
new = function(name) new = function(name)
return { return {
name = name or "unamed", -- The scene name. name = name or "unamed",
timer = timer and timer.new(),
timer = timer and timer.new(), -- Scene-specific TimerRegistry, if uqt.time is available. signal = signal and signal.new(),
signal = signal and signal.new(), -- Scene-specific SignalRegistry, if uqt.signal is available. enter = function(self, ...) end,
exit = function(self) end,
enter = function(self, ...) end, -- Called when entering a scene. suspend = function(self) end,
exit = function(self) end, -- Called when exiting a scene, and not expecting to come back (scene may be unloaded). resume = function(self) end,
update = function(self, dt, ...) end,
suspend = function(self) end, -- Called when suspending a scene, and expecting to come back (scene won't be unloaded). draw = function(self, ...) end
resume = function(self) end, -- Called when resuming a suspended scene (after calling suspend).
update = function(self, dt, ...) end, -- Called on each update on the current scene.
draw = function(self, ...) end -- Called on each draw on the current scene.
} }
end, end,

7
signal/README.md Normal file
View file

@ -0,0 +1,7 @@
# ubiquitousse.signal
Signal management library.
You can read the documentation [here](https://reuh.github.io/ubiquitousse/modules/signal.html).
Licensed under ISC (equivalent to MIT/Expat/Simplified BSD).

View file

@ -1,5 +1,12 @@
--- ubiquitousse.signal --- Signal management.
--
-- No dependency.
-- @module signal
--- Signal registry.
--
-- A SignalRegistry is a separate ubiquitousse.signal instance: its signals will be independant from other registries.
-- @type SignalRegistry
let registry_mt = { let registry_mt = {
--- Map of signals to list of listeners. --- Map of signals to list of listeners.
signals = {}, signals = {},
@ -64,14 +71,20 @@ let registry_mt = {
} }
registry_mt.__index = registry_mt registry_mt.__index = registry_mt
--- Module.
--
-- This module also acts as a global `SignalRegistry`, so you can call the `:bind`, `:emit`, etc. methods directly on the module
-- if you don't need to isolate your signals in separate registries.
-- @section module
let signal = { let signal = {
--- Creates and return a new SignalRegistry. --- Creates and return a new SignalRegistry.
-- A SignalRegistry is a separate ubiquitousse.signal instance: its signals will be independant from other registries. -- @treturn SignalRegistry
new = () new = ()
return setmetatable({ signals = {} }, registry_mt) return setmetatable({ signals = {} }, registry_mt)
end, end,
--- Global SignalRegistry. -- Global SignalRegistry.
signals = {}, signals = {},
bind = (...) bind = (...)
return registry_mt.bind(signal, ...) return registry_mt.bind(signal, ...)
@ -79,6 +92,12 @@ let signal = {
unbind = (...) unbind = (...)
return registry_mt.unbind(signal, ...) return registry_mt.unbind(signal, ...)
end, end,
unbindAll = (...)
return registry_mt.unbindAll(signal, ...)
end,
replace = (...)
return registry_mt.replace(signal, ...)
end,
clear = (...) clear = (...)
return registry_mt.clear(signal, ...) return registry_mt.clear(signal, ...)
end, end,
@ -86,17 +105,21 @@ let signal = {
return registry_mt.emit(signal, ...) return registry_mt.emit(signal, ...)
end, end,
--- SignalRegistry which will be used to bind signals that need to be called on game engine event. --- SignalRegistry which will be used to bind signals that need to be called on game engine event; other ubiquitousse modules may bind to this registry
-- if avaible.
--
-- For example, every ubiquitousse module with a "update" function will bind it to the "update" signal in the registry; -- For example, every ubiquitousse module with a "update" function will bind it to the "update" signal in the registry;
-- you can then call this signal on each game update to update every ubiquitousse module easily. -- you can then call this signal on each game update to update every ubiquitousse module easily.
--
-- Provided signals: -- Provided signals:
-- * update(dt), should be called on every game update --
-- * draw, should be called on every game draw -- * `update(dt)`, should be called on every game update
-- * `draw()`, should be called on every game draw
-- * for LÖVE, there are callbacks for every LÖVE callback function that need to be called on their corresponding LÖVE callback -- * for LÖVE, there are callbacks for every LÖVE callback function that need to be called on their corresponding LÖVE callback
event = nil, event = nil,
--- Call this function to hook signal.event signals to the current backend. --- Call this function to hook `signal.event` signals to LÖVE events.
-- For LÖVE, this means overriding every existing LÖVE callback. If a callback is already defined, the new one will call the old function along with the signal:emit. -- This means overriding every existing LÖVE callback. If a callback is already defined, the new one will call the old function along with the signal:emit.
-- @require love -- @require love
registerEvents = () registerEvents = ()
local callbacks = { -- everything except run, errorhandler, threaderror local callbacks = { -- everything except run, errorhandler, threaderror

7
timer/README.md Normal file
View file

@ -0,0 +1,7 @@
# ubiquitousse.timer
Timer and time related functions.
You can read the documentation [here](https://reuh.github.io/ubiquitousse/modules/timer.html).
Licensed under ISC (equivalent to MIT/Expat/Simplified BSD).

View file

@ -1,4 +1,7 @@
--- ubiquitousse.timer --- Time related functions.
--
-- No dependency.
-- @module timer
local ease = require((...):match("^.-timer")..".easing") local ease = require((...):match("^.-timer")..".easing")
local timer_module local timer_module
@ -21,9 +24,11 @@ local function all(list, default)
end end
end end
-- Timer methods. --- Timer methods.
-- @type Timer
local timer_mt = { local timer_mt = {
--- timer data table --- timer data table
-- @local
t = nil, t = nil,
--- Wait time milliseconds before running the function. --- Wait time milliseconds before running the function.
@ -51,7 +56,9 @@ local timer_mt = {
return self return self
end, end,
--- Function conditions --- --- Function conditions
-- @doc conditions
--- Starts the function execution when func() returns true. Checked before the "after" condition, --- Starts the function execution when func() returns true. Checked before the "after" condition,
-- meaning the "after" countdown starts when func() returns true. -- meaning the "after" countdown starts when func() returns true.
-- If multiple init functions are added, init will trigger only when all of them returns true. -- If multiple init functions are added, init will trigger only when all of them returns true.
@ -79,7 +86,9 @@ local timer_mt = {
return self return self
end, end,
--- Conditions override --- --- Conditions override
-- @doc conditionoverride
--- Force the function to start its execution. --- Force the function to start its execution.
start = function(self) start = function(self)
self.t.forceStart = true self.t.forceStart = true
@ -100,26 +109,31 @@ local timer_mt = {
self.t.skip = (self.t.skip or 0) + time self.t.skip = (self.t.skip or 0) + time
end, end,
--- Callbacks functions --- --- Callbacks functions
--- Will execute func(self, lag) when the function execution start. -- @doc callbacks
--- Add a function to the start callback: will execute func(self, lag) when the function execution start.
onStart = function(self, func) onStart = function(self, func)
table.insert(self.t.onStart, func) table.insert(self.t.onStart, func)
return self return self
end, end,
--- Will execute func(self, lag) each frame the main function is run. --- Add a function to the update callback: will execute func(self, lag) each frame the main function is run.
onUpdate = function(self, func) onUpdate = function(self, func)
table.insert(self.t.onUpdate, func) table.insert(self.t.onUpdate, func)
return self return self
end, end,
--- Will execute func(self, lag) when the function execution end. --- Add a function to the end callback: will execute func(self, lag) when the function execution end.
onEnd = function(self, func) onEnd = function(self, func)
table.insert(self.t.onEnd, func) table.insert(self.t.onEnd, func)
return self return self
end, end,
--- Chaining --- --- Chaining
-- @doc chaining
--- Creates another timer which will be replace the current one when it ends. --- Creates another timer which will be replace the current one when it ends.
-- Returns the new timer (and not the original one!). -- Returns the new timer (and not the original one!).
-- @treturn Timer
chain = function(self, func) chain = function(self, func)
local fn = timer_module.run(func) local fn = timer_module.run(func)
self:onEnd(function(self, lag) self:onEnd(function(self, lag)
@ -129,7 +143,9 @@ local timer_mt = {
return fn return fn
end, end,
--- Management --- --- Management
-- @doc management
--- Update the timer. --- Update the timer.
-- Should be called at every game update. -- Should be called at every game update.
-- @tparam number dt the delta-time (time spent since last time the function was called) (miliseconds) -- @tparam number dt the delta-time (time spent since last time the function was called) (miliseconds)
@ -205,6 +221,7 @@ local timer_mt = {
timer_mt.__index = timer_mt timer_mt.__index = timer_mt
--- Registry methods. --- Registry methods.
-- @type TimerRegistry
local registry_mt = { local registry_mt = {
--- Update all the timers in the registry. --- Update all the timers in the registry.
-- Should be called at every game update; called by ubiquitousse.update. -- Should be called at every game update; called by ubiquitousse.update.
@ -246,17 +263,20 @@ local registry_mt = {
} }
registry_mt.__index = registry_mt registry_mt.__index = registry_mt
--- Time related functions --- Module.
-- @section module
timer_module = { timer_module = {
--- Creates and return a new timer registry. --- Creates and return a new timer registry.
-- A timer registry provides an easy way to handle your timers; it will keep track of them, -- A timer registry provides an easy way to handle your timers; it will keep track of them,
-- updating and removing them as needed. If you use the scene system, a scene-specific -- updating and removing them as needed. If you use the scene system, a scene-specific
-- timer registry is available at ubiquitousse.scene.current.timer. -- timer registry is available at ubiquitousse.scene.current.timer.
-- @treturn TimerRegistry
new = function() new = function()
return setmetatable({ return setmetatable({
--- Used to store all the functions delayed with ubiquitousse.time.delay --- Used to store all the functions delayed with ubiquitousse.time.delay
-- The default implementation use the structure {<key: function> = <value: data table>, ...} -- 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. -- This table is for internal use and shouldn't be used from an external script.
-- @local
timers = {} timers = {}
}, registry_mt) }, registry_mt)
end, end,
@ -269,7 +289,7 @@ timer_module = {
-- You will need to call the :update(dt) method on the timer object every frame to make it do something, or create the timer from a timer registry if you -- You will need to call the :update(dt) method on the timer object every frame to make it do something, or create the timer from a timer registry if you
-- don't want to handle your timers manually. -- don't want to handle your timers manually.
-- @tparam[opt] function func the function to schedule -- @tparam[opt] function func the function to schedule
-- @treturn timer the object -- @treturn Timer the object
run = function(func) run = function(func)
local r = setmetatable({ local r = setmetatable({
t = { t = {
@ -303,11 +323,13 @@ timer_module = {
--- Create a timer that will tween some numeric values. --- Create a timer that will tween some numeric values.
-- You will need to call the :update(dt) method on the timer object every frame to make it do something, or create the timer from a timer registry if you -- You will need to call the :update(dt) method on the timer object every frame to make it do something, or create the timer from a timer registry if you
-- don't want to handle your timers manually. -- don't want to handle your timers manually.
--
--
-- @tparam number duration tween duration (miliseconds) -- @tparam number duration tween duration (miliseconds)
-- @tparam table tbl the table containing the values to tween -- @tparam table tbl the table containing the values to tween
-- @tparam table to the new values -- @tparam table to the new values
-- @tparam[opt="linear"] string/function method tweening method (string name or the actual function(time, start, change, duration)) -- @tparam[opt="linear"] string/function method tweening method (string name or the actual function(time, start, change, duration))
-- @treturn timer the object. A duration is already defined, and the :chain methods takes the same arguments as tween (and creates a tween). -- @treturn TweenTimer the object. A duration is already defined, and the :chain methods takes the same arguments as tween (and creates a tween).
tween = function(duration, tbl, to, method) tween = function(duration, tbl, to, method)
method = method or "linear" method = method or "linear"
method = type(method) == "string" and ease[method] or method method = type(method) == "string" and ease[method] or method
@ -347,9 +369,13 @@ timer_module = {
copy(to, tbl, from) copy(to, tbl, from)
end) end)
--- Tween timer: inherit all fields and methods from `Timer` and change a few to make them easier to use in a tweening context.
-- @type TweenTimer
--- Creates another tween which will be initialized when the current one ends. --- Creates another tween which will be initialized when the current one ends.
-- If tbl_ and/or method_ are not specified, the values from the current tween will be used. -- If tbl_ and/or method_ are not specified, the values from the current tween will be used.
-- Returns the new tween. -- Returns the new tween.
-- @treturn TweenTimer
r.chain = function(_, duration_, tbl_, to_, method_) r.chain = function(_, duration_, tbl_, to_, method_)
if not method_ and to_ then if not method_ and to_ then
if type(to_) == "string" then if type(to_) == "string" then

7
util/README.md Normal file
View file

@ -0,0 +1,7 @@
# ubiquitousse.util
Various functions useful for game developement.
You can read the documentation [here](https://reuh.github.io/ubiquitousse/modules/util.html).
Licensed under ISC (equivalent to MIT/Expat/Simplified BSD).

View file

@ -1,12 +1,15 @@
--- ubiquitousse.util
-- No dependency.
--- Various functions useful for game developement. --- Various functions useful for game developement.
--
-- No dependency.
-- @module util
--- Functions
-- @section Functions
local util, group_mt local util, group_mt
util = { util = {
------------------- --- Basic maths
--- Basic maths --- -- @doc math
-------------------
--- AABB collision check. --- AABB collision check.
-- @tparam number x1 first rectangle top-left x coordinate -- @tparam number x1 first rectangle top-left x coordinate
@ -27,9 +30,8 @@ util = {
y1 + h1 >= y2 and y1 <= y2 + h2 y1 + h1 >= y2 and y1 <= y2 + h2
end, end,
----------------------- --- List operations
--- List operations --- -- @doc list
-----------------------
--- Check if the list contains a value. --- Check if the list contains a value.
-- @tparam table t the list -- @tparam table t the list
@ -46,7 +48,7 @@ util = {
-- @tparam table t the list -- @tparam table t the list
-- @param x the element to remove -- @param x the element to remove
-- @tparam[opt=#t] number n the number of expected elements in the list, including nil values -- @tparam[opt=#t] number n the number of expected elements in the list, including nil values
-- @return x -- @return x the removed element
remove = function(t, x, n) remove = function(t, x, n)
n = n or #t n = n or #t
for i=1, n do for i=1, n do
@ -62,7 +64,7 @@ util = {
-- @tparam table t the list of tables -- @tparam table t the list of tables
-- @param k the chosen key -- @param k the chosen key
-- @tparam[opt=#t] number n the number of expected elements in the list, including nil values -- @tparam[opt=#t] number n the number of expected elements in the list, including nil values
-- @treturn the extracted table -- @treturn table the extracted table
extract = function(t, k, n) extract = function(t, k, n)
n = n or #t n = n or #t
local r = {} local r = {}
@ -74,6 +76,9 @@ util = {
--- Chainable ipairs. --- Chainable ipairs.
-- Same as ipairs, but can take several tables, which will be chained, in order. -- Same as ipairs, but can take several tables, which will be chained, in order.
-- @tparam table a first list to iterate over
-- @tparam table b second list to iterate over after the first one
-- @tparam[opt] table,... ... next tables to iterate over
ipairs = function(a, b, ...) ipairs = function(a, b, ...)
if b == nil then if b == nil then
return ipairs(a) return ipairs(a)
@ -160,9 +165,8 @@ util = {
return false return false
end, end,
----------------------------- --- Dictionary operations
--- Dictionary operations --- -- @doc dict
-----------------------------
--- Returns a new table where the keys and values have been inverted. --- Returns a new table where the keys and values have been inverted.
-- @tparam table t the table -- @tparam table t the table
@ -196,7 +200,7 @@ util = {
end, end,
--- Returns a table which, when indexed, will require() the module with the index as a name (and a optional prefix). --- Returns a table which, when indexed, will require() the module with the index as a name (and a optional prefix).
-- @tparam string[opt=""] string that will prefix modules names when calling require() -- @tparam[opt=""] string prefix that will prefix modules names when calling require()
-- @treturn table the requirer table -- @treturn table the requirer table
requirer = function(prefix) requirer = function(prefix)
prefix = prefix and tostring(prefix) or "" prefix = prefix and tostring(prefix) or ""
@ -208,9 +212,8 @@ util = {
}) })
end, end,
----------------------- --- Random and UUID
--- Random and UUID --- -- @doc random
-----------------------
--- Generate a UUID v4. --- Generate a UUID v4.
-- @treturn string the UUID in its canonical representation -- @treturn string the UUID in its canonical representation
@ -220,24 +223,23 @@ util = {
:gsub("x", function() return ("%x"):format(math.random(0x0, 0xf)) end) -- random hexadecimal digit :gsub("x", function() return ("%x"):format(math.random(0x0, 0xf)) end) -- random hexadecimal digit
end, end,
----------------------- --- Object grouping
--- Object grouping --- -- @doc grouping
-----------------------
--- Groups objects in a meta-object-proxy-thingy. --- Groups objects in a meta-object-proxy-thingy.
-- Works great with Lua 5.2+. LuaJit requires to be built with Lua 5.2 compatibility enabled to support group comparaison. -- Works great with Lua 5.2+. LuaJit requires to be built with Lua 5.2 compatibility enabled to support group comparaison.
-- @tparam table list of objects -- @tparam table list of objects
-- @tparam[opt=#t] number n the number of expected elements in the list, including nil values -- @tparam[opt=#t] number n the number of expected elements in the list, including nil values
-- @tparam[opt=nil] table p list of parents. Used to find the first arguments of method calls. -- @tparam[opt=nil] table p list of parents. Used to find the first arguments of method calls.
-- @treturn group object -- @treturn Group object
group = function(t, n, p) group = function(list, n, p)
n = n or #t n = n or #list
return setmetatable({ _n = n, _t = t, _p = p or false }, group_mt) return setmetatable({ _n = n, _t = list, _p = p or false }, group_mt)
end end
} }
group_mt = { group_mt = {
--- Everything but comparaison: returns a new group -- Everything but comparaison: returns a new group
__add = function(self, other) __add = function(self, other)
if getmetatable(other) == group_mt then if getmetatable(other) == group_mt then
if getmetatable(self) == group_mt then if getmetatable(self) == group_mt then
@ -325,7 +327,7 @@ group_mt = {
return util.group(util.extract(self._t, k, self._n), self._n, self._t) return util.group(util.extract(self._t, k, self._n), self._n, self._t)
end, end,
--- Comparaison: returns true if true for every object of the group -- Comparaison: returns true if true for every object of the group
__eq = function(self, other) __eq = function(self, other)
if getmetatable(other) == group_mt then if getmetatable(other) == group_mt then
if getmetatable(self) == group_mt then if getmetatable(self) == group_mt then
@ -360,7 +362,7 @@ group_mt = {
end end
end, end,
--- Special cases -- Special cases
__newindex = function(self, k, v) __newindex = function(self, k, v)
if getmetatable(v) == group_mt then -- unpack if getmetatable(v) == group_mt then -- unpack
util.each(self._t, function(t, i) t[k] = v._t[i] end, self._n) util.each(self._t, function(t, i) t[k] = v._t[i] end, self._n)
@ -378,7 +380,7 @@ group_mt = {
end end
end, end,
--- Full-blown debugger -- Full-blown debugger
__tostring = function(self) __tostring = function(self)
return ("group{%s}"):format(table.concat(util.map(self._t, tostring, self._n), ", ")) return ("group{%s}"):format(table.concat(util.map(self._t, tostring, self._n), ", "))
end end