rolling-5

This commit is contained in:
Lars Mueller 2020-04-25 12:50:35 +02:00
parent 0134d50136
commit 4d31b19c73
4 changed files with 46 additions and 40 deletions

@ -1,4 +1,4 @@
# HUD Timers(`hud_timers`)
# HUD Timers (`hud_timers`)
A library for easily maintaining HUD timers.
@ -28,3 +28,42 @@ All in all, the media is licensed under the MIT license, with credits going to W
## API
Code should be self-explanatory. If not, feel free to contact me (opening an issue is also fine). Will probably document it here at some point...
## Configuration
### Locations
* JSON Configuration: `<worldpath>/config/hud_timers.json`
* Text Logs: `<worldpath>/logs/hud_timers/<date>.txt`
* Readme: `<modpath/gamepath>/hud_timers/Readme.md`
### Default Configuration
Located under `<modpath/gamepath>/hud_timers/default_config.json`
```json
{
"hud_pos": {"x": 0,"y": 0},
"globalstep": 0.1,
"hud_timers_max": 10,
"format": "%s: %s s"
}
```
### Usage
#### `hud_pos`
Screen coordinates where the timer stack should start.
#### `globalstep`
How often timers should be updated(interval, seconds).
#### `hud_timers_max`
How many timers(maximum) may exist at a time.
#### `format` : "%s : %s s"
The format for the timer label - first string is timer name, second one is seconds left.

@ -1,36 +0,0 @@
# HUD Timers - Configuration
## Locations
JSON Configuration : `<worldpath>/config/hud_timers.json`
Text Logs : `<worldpath>/logs/hud_timers/<date>.json`
Explaining document(this, Markdown) : `<modpath/gamepath>/hud_timers/config_help.md`
Readme : `<modpath/gamepath>/hud_timers/Readme.md`
## Default Configuration
Located under `<modpath/gamepath>/hud_timers/default_config.json`
```json
{
"hud_pos" : {"x": 0,"y": 0},
"globalstep" : 0.1,
"hud_timers_max" : 10,
"format" : "%s : %s s"
}
```
## Usage
### `hud_pos`
Screen coordinates where the timer stack should start.
### `globalstep`
How often timers should be updated(interval, seconds).
### `hud_timers_max`
How many timers(maximum) may exist at a time.
### `format` : "%s : %s s"
The format for the timer label - first string is timer name, second one is seconds left.

@ -2,5 +2,5 @@
"hud_pos" : {"x": 0.1,"y": 0.9},
"globalstep" : 0.1,
"hud_timers_max" : 10,
"format" : "%s : %s s"
"format" : "%s: %s s"
}

@ -132,7 +132,8 @@ function add_timer(playername, timer_definition)
name = timer_definition.name or "Unnamed Timer",
time_left = timer_definition.duration,
duration = timer_definition.duration,
on_complete = timer_definition.on_complete,
on_complete = timer_definition.on_complete or function() end,
on_remove = timer_definition.on_remove or function() end,
on_event = timer_definition.on_event,
rounding_steps = timer_definition.rounding_steps or 10,
ids = {bg = bg_id, bar = bar_id, label = text_id}
@ -175,8 +176,10 @@ function maintain_timers(timers, dtime, player)
timer.duration .. " removed from the HUD of player " .. player:get_player_name()
)
table.remove(timers, i)
if timer.on_complete then
if timer.time_left > 0 then
timer.on_complete(player:get_player_name(), timer)
else
timer.on_remove(player:get_player_name(), timer)
end
else
timers[i].time_left = time_left