master
GianptDev 2022-08-27 19:31:43 +02:00
parent f169ec0b7e
commit 73415dd83d
6 changed files with 176 additions and 60 deletions

View File

@ -55,16 +55,18 @@
- - version_name
- renamed tween property:
- - method ➡️ interpolation
- changes release style:
- - releases about using the mod will not include the resources/ folder.
- - releases about the source code will include it instead.
## 1.2 (again)
## 1.2 (fix)
- forgot to update docs (facepalm).
- forgot to update docs (facepalm), docs now are updated.
- more luadocs.
- now all callbacks must have as first argoument the tween.
- movement property now can accept string names and indexes for his values.
- fixes
- - fixed a bug that allowed to crash the server if a player leave the game with the interpolation hud enabled.
- all the stuff inside the resources/ folder is media and is not usefull for the project to run.
- - it will be move to an external drive (still public and accessible).
- - that folder now will only contain media used by the readme or external links.

View File

@ -3,11 +3,25 @@
This is a table that contain debug visual stuff.
______
| Property | Description |
| -------- | ----------- |
| hud_interpolation | List of all players that use the function list hud. |
| hud_running_tweens | List of all players that use the tween list hud. |
______
## Functions and methods
______
debug:show_functions(player_name: string)
Display all defined interpolations functions on screen with some animated images and the interpolation name.

View File

@ -3,31 +3,37 @@
This api implements a simple table called *BeTweenApi*, this table contains everything implemented in this library.
| Property | Description |
| ------------- | ----------- |
| *active_tweens* | This is a list of all running tweens, when a tween has started is inserted in this list until is stopped. |
| [interpolation](interpolation.md) | This is a table that contain a set of interpolation functions that can be used by tweens or directly. |
| [debug](debug.md) | This is a table that contain debug related stuff.
______
## Functions
## Features
These are all tables inside the *BeTweenApi* object wich contain everything they describe.
| Name | Description |
| ---- | ----------- |
| version_name() : string | This method return the current version of the api. |
- [interpolation](interpolation.md)
- - here are stored all build-in functions.
- [debug](debug.md)
- - all debug tools are stored here.
- [tween](tween.md)
- - This is an object able to get a configuration and run it to animate any movement automatically.
- - If you want to make animations see this feature.
## Objects
| Name | Description |
| ---- | ----------- |
| [Tween](tween.md) | This is the tween itself, contain all the stuff you need for time interpolation. |
______
## Commands
| Name | Description |
| ---- | ----------- |
| /between | Show a debug hud to display a topic of the api, require debug privileges to be executed. |
/between <functions | tweens>
Show a debug hud to display a topic of the api, require debug privileges to be executed.
______
## Functions and methods
version_name() : string
This method return the current version of the api, that's it.

View File

@ -3,39 +3,76 @@
The tween object is a table that contain informations and callbacks about an interpolation animation that can be started or stopped with the tween itself.
BeTweenApi.tween(
interpolation: function,
movement: {
number, -- start value
number, -- final value
boolean = false -- mirror mode
},
time: float,
loop: bool | int,
callbacks: table
) : Tween
BeTweenApi.tween(interpolation: function, movement: Movement, time: float, loop: bool, callbacks: TweenEvents) : Tween
This method will create a new Tween object.
- *interpolation* is the interpolation function to use, see [BeTweenApi.interpolation](interpolation.md) for functions to use.
You can define a custom function here too, make sure it ask for 3 argouments.
- *movement* a list that contain the start position and the destination of the interpolation, the third argoument is a boolean and specify if the interpolation should mirror.
- - When mirror is enabled the interpolation will become twince faster and reach the destination in half of the time, the other half is used to repeat the interpolation but reversed (from end to start).
- *movement* movement data from the initial position to the end, see [Movement](#Movement)
- *time* is the time in seconds of how much this tween must run.
- *loop* set if the tween should loop his interpolation when he finish it, if is true the tween will loop forever, if is a number the tween will loop for the specified amount.
- *callbacks* is a list of methods called on Tween events, each callback give the tween itself.
- *callbacks* contain all functions to execute on specific events of the tween, see [TweenEvents](#TweenEvents)
# Movement
This data contain initial and final position of the interpolation, every property with a default value does not require to be set.
| Property | Default | Description |
| -------- | ----------- | ------- |
| start: number | | is the initial position of the interpolation. |
| finish: number | | is the final position of the interpolation. |
| mirror: boolean | false | if enabled will make the interpolation move twince faster and use half of the time to repeat the animation in reverse. |
```lua
{ start = 0, finish = 64 } --- from 0 to 64 in time.
{ start = 0, finish = 64, mirror = true } --- same as before but also repeat in reverse.
{ 0, 64 } --- you can write it like this too.
{ 0, 64, true } --- same as second line.
```
# TweenEvents
These are all functions called on specific events, you give this table to a tween to make it execute your own code.
Each function receive the tween itself as first argoument, you can call any tween method from there.
| Callback | Description |
| - | - |
| on_start(tween: Tween) | Called when the Tween:start() is executed and the Tween will soon start to run his steps. |
| on_end(tween: Tween) | Called when the Tween:stop() is executed or when the tween has finished to run. |
| on_loop(tween: Tween) | Called every time the tween is looping, only called if loop is used.. |
| on_step(value: number, tween: Tween) | Called each step of the interpolation in the defined time, value is the result value. |
| on_step(tween: Tween, value: number) | Called each step of the interpolation in the defined time, value is the result value. |
```lua
{
on_start = function (tween)
minetest.log("Hello Tween!")
end,
on_end = function (tween)
minetest.log("Goodbye Tween!")
end,
on_loop = function (tween)
minetest.log("Boom, 360 loop!")
end,
on_step = function (tween, value)
--- do something with value.
end,
}
```
______
# Functions and methods
Tween:start()
@ -65,20 +102,65 @@ Get the index position of the Tween inside the list, if the Tween isn't running
______
Usage example:
# Examples
```lua
--- store the tween in a variable.
local tween = InterpolationApi.tween(
InterpolationApi.interpolation.linear, -- linear movement
{ 0, 64, false }, -- from 0 to 64, don't mirror
4.0, -- in 4 seconds
true, -- repeat after the time
InterpolationApi.interpolation.quadratic_in,
{ 0, 64, false },
8.0, false,
{
-- execute this method each step in time.
on_step = function (step, tween)
local item = player:hud_get(icon)
player:hud_change(icon, "offset", { x = step, y = 32 })
on_start = function (tween)
minetest.log("Interpolation start!")
end,
on_step = function (tween, value)
minetest.log(tostring(value))
end
}
)
tween:start() -- make sure to start the tween.
--- start the tween.
tween:start()
```
```lua
InterpolationApi.tween(
InterpolationApi.interpolation.linear, --- linear movement
{ start = 0, finish = 64 }, --- from 0 to 64, don't mirror
4.0, --- in 4 seconds
true, --- repeat after the time
{
--- execute this method each step in time.
on_step = function (tween, value)
local item = player:hud_get(icon)
player:hud_change(icon, "offset", { x = value, y = 32 })
end
}
):start() --- you can also start the tween without creating a variable.
```
______
# Extra
Extra informations about the Tween.
>## Tween loop
>
>The tween execute his loop using the server global steps, so his execution is synced to each player, but that's mean it will slow down when the server is lagging.
>## Tween list
>
>When a tween is running, by executing his :start() method) will insert itself in the *active_tweens* list inside the api.
>
>When the tween is stopped, paused, or has finished his interpolation job he will remove itself from the list.
>
>Tween in the list are only tween that **are** running.

View File

@ -17,11 +17,11 @@
BeTweenApi.debug = {
--- list of all players that are using the debug functions view.
--- @type table<string, any>
--- @type { [string]: any }
hud_interpolation = {},
--- list of all players that are using the debug tween view.
--- @type table<string, any>
--- @type { [string]: any }
hud_running_tweens = {},
}
@ -29,7 +29,7 @@ BeTweenApi.debug = {
--- -----------------------------------------------------------
local function A (_)
local function global_step (time)
for plr_name, visual in pairs(BeTweenApi.debug.hud_running_tweens) do
local player = minetest.get_player_by_name(plr_name)
@ -101,7 +101,24 @@ local function A (_)
end
minetest.register_globalstep(A)
--- this functions is to make sure all debug stuff is cleared when a player exit.
local function player_leave (player, time_out)
local plr_name = player:get_player_name()
local hud_interpolation = BeTweenApi.debug.hud_interpolation[plr_name]
BeTweenApi.debug.hud_interpolation[plr_name] = nil
BeTweenApi.debug.hud_running_tweens[plr_name] = nil
if (hud_interpolation ~= nil) then
for _, tween in pairs(hud_interpolation.tweens) do
tween:stop()
end
end
end
minetest.register_globalstep(global_step)
minetest.register_on_leaveplayer(player_leave)
--- -----------------------------------------------------------
@ -168,11 +185,11 @@ function BeTweenApi.debug.show_functions (_, player_name)
style = 1,
})
--- make the loop animation for each function.
visual.tweens[_] = BeTweenApi.tween(
interpolation,
{ start, finish },
4.0,
true,
4.0, true,
{
on_step = function (tween, step)
local item = player:hud_get(icon)

View File

@ -112,11 +112,6 @@ end
--- create a tween object that will interpolate an intial value to a destination in time, each value calculated in time are created from the function the tween is using, after the tween has been created it has run by calling :start()
---
--- --- movement values, they use index NOT names.
--- {
--- begin: number, destination: number, mirror: boolean
--- }
---
--- --- callbacks, each of then give the tween.
--- on_start(tween) --- executed on tween start.
--- on_stop(tween) --- executed on tween stop.