mirror of
https://codeberg.org/Wuzzy/pride_flags.git
synced 2025-03-15 04:41:21 +00:00
Add API function for wind speed
This commit is contained in:
parent
2a002a736a
commit
c7a4d879e0
2 changed files with 50 additions and 13 deletions
36
API.md
36
API.md
|
@ -5,7 +5,8 @@ get a list of all flags, and set and get the flag of flag pole nodes.
|
||||||
|
|
||||||
## Functions
|
## Functions
|
||||||
|
|
||||||
### `pride_flags.add_flag = function(name)`
|
### `pride_flags.add_flag(name)`
|
||||||
|
|
||||||
Add a new flag to the game. `name` is the flag identifier.
|
Add a new flag to the game. `name` is the flag identifier.
|
||||||
There *must* exist a texture with the name `prideflag_<name>.png`.
|
There *must* exist a texture with the name `prideflag_<name>.png`.
|
||||||
The texture *should* have an aspect ratio of 1.3.
|
The texture *should* have an aspect ratio of 1.3.
|
||||||
|
@ -21,16 +22,43 @@ added.
|
||||||
|
|
||||||
Returns `true` on success and `false` on failure.
|
Returns `true` on success and `false` on failure.
|
||||||
|
|
||||||
### `pride_flags.get_flags = function()`
|
### `pride_flags.get_flags()`
|
||||||
|
|
||||||
Returns a list of all available flag identifiers. The flags
|
Returns a list of all available flag identifiers. The flags
|
||||||
are sorted by selection order.
|
are sorted by selection order.
|
||||||
|
|
||||||
### `pride_flags.set_flag_at = function(pos, flag_name)`
|
### `pride_flags.set_flag_at(pos, flag_name)`
|
||||||
|
|
||||||
Sets the flag at an upper mast node at position `pos` to the flag `flag_name`.
|
Sets the flag at an upper mast node at position `pos` to the flag `flag_name`.
|
||||||
The node at `pos` *must* be `pride_flags:upper_mast`.
|
The node at `pos` *must* be `pride_flags:upper_mast`.
|
||||||
Returns `true` on success and `false` otherwise.
|
Returns `true` on success and `false` otherwise.
|
||||||
|
|
||||||
### `pride_flags.get_flag_at = function(pos)`
|
### `pride_flags.get_flag_at(pos)`
|
||||||
|
|
||||||
Returns the currently used flag at the upper mast node at position `pos`.
|
Returns the currently used flag at the upper mast node at position `pos`.
|
||||||
The node at `pos` *must* be `pride_flags:upper_mast`.
|
The node at `pos` *must* be `pride_flags:upper_mast`.
|
||||||
Returns a string on success and `nil` otherwise.
|
Returns a string on success and `nil` otherwise.
|
||||||
|
|
||||||
|
### `pride_flags.get_wind(pos)`
|
||||||
|
|
||||||
|
Returns the current wind strength at pos. The wind strength determines how
|
||||||
|
fast a flag at pos would be waving at the time this function was called.
|
||||||
|
|
||||||
|
This function will be called from time to time by the mod to update
|
||||||
|
the flag waving speed of flags. It is called for every flag once about
|
||||||
|
every 115 seconds (plusminus 10 seconds).
|
||||||
|
|
||||||
|
This function is predefined in this mod by pseudorandomly changing the wind
|
||||||
|
strength over time using a Perlin noise. By default, the wind strength is
|
||||||
|
only controlled by the current time; the position is ignored.
|
||||||
|
|
||||||
|
This function can be overwritten by mods to define your own wind algorithm.
|
||||||
|
You can do whatever in this function, you only need to return a number in
|
||||||
|
the end. The number should be roughly in the range between 0 and 50.
|
||||||
|
|
||||||
|
This is how the wind strength affects the flag waving speed:
|
||||||
|
|
||||||
|
* wind < 10: slow
|
||||||
|
* 10 < wind < 20: medium
|
||||||
|
* 20 < wind < 40: fast
|
||||||
|
* wind > 40: very fast
|
||||||
|
|
27
init.lua
27
init.lua
|
@ -183,15 +183,9 @@ minetest.register_entity( "pride_flags:wavingflag", {
|
||||||
end,
|
end,
|
||||||
|
|
||||||
reset_animation = function ( self, initial )
|
reset_animation = function ( self, initial )
|
||||||
local coords = { x = os.time( ) % 65535, y = 0 }
|
local pos = self.object:get_pos( )
|
||||||
local cur_wind
|
local cur_wind = pride_flags.get_wind( pos )
|
||||||
if old_get2d then
|
minetest.log("verbose", "[pride_flags] Current wind at "..minetest.pos_to_string(pos, 1)..": " .. cur_wind)
|
||||||
cur_wind = wind_noise:get2d(coords)
|
|
||||||
else
|
|
||||||
cur_wind = wind_noise:get_2d(coords)
|
|
||||||
end
|
|
||||||
cur_wind = cur_wind * 30 + 30
|
|
||||||
minetest.log("verbose", "[pride_flags] Current wind: " .. cur_wind)
|
|
||||||
local anim_speed
|
local anim_speed
|
||||||
local wave_sound
|
local wave_sound
|
||||||
|
|
||||||
|
@ -678,4 +672,19 @@ pride_flags.get_flag_at = function( pos )
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
-- Returns the wind strength at pos.
|
||||||
|
-- Can be overwritten by mods.
|
||||||
|
pride_flags.get_wind = function( pos )
|
||||||
|
-- The default wind function ignores pos.
|
||||||
|
-- Returns a wind between ca. 0 and 55
|
||||||
|
local coords = { x = os.time( ) % 65535, y = 0 }
|
||||||
|
local cur_wind
|
||||||
|
if old_get2d then
|
||||||
|
cur_wind = wind_noise:get2d(coords)
|
||||||
|
else
|
||||||
|
cur_wind = wind_noise:get_2d(coords)
|
||||||
|
end
|
||||||
|
cur_wind = cur_wind * 30 + 30
|
||||||
|
return cur_wind
|
||||||
|
end
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue