From 4d31b19c7358024abd8bcc8b45a04463a69e73e4 Mon Sep 17 00:00:00 2001 From: Lars Mueller Date: Sat, 25 Apr 2020 12:50:35 +0200 Subject: [PATCH] rolling-5 --- Readme.md | 41 ++++++++++++++++++++++++++++++++++++++++- config_help.md | 36 ------------------------------------ default_config.json | 2 +- main.lua | 7 +++++-- 4 files changed, 46 insertions(+), 40 deletions(-) delete mode 100644 config_help.md diff --git a/Readme.md b/Readme.md index c7eb94f..fa4e6ec 100644 --- a/Readme.md +++ b/Readme.md @@ -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: `/config/hud_timers.json` +* Text Logs: `/logs/hud_timers/.txt` +* Readme: `/hud_timers/Readme.md` + +### Default Configuration + +Located under `/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. \ No newline at end of file diff --git a/config_help.md b/config_help.md deleted file mode 100644 index 1b44571..0000000 --- a/config_help.md +++ /dev/null @@ -1,36 +0,0 @@ -# HUD Timers - Configuration - -## Locations - -JSON Configuration : `/config/hud_timers.json` - -Text Logs : `/logs/hud_timers/.json` - -Explaining document(this, Markdown) : `/hud_timers/config_help.md` - -Readme : `/hud_timers/Readme.md` - -## Default Configuration -Located under `/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. diff --git a/default_config.json b/default_config.json index 51f0da2..3bf1437 100644 --- a/default_config.json +++ b/default_config.json @@ -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" } \ No newline at end of file diff --git a/main.lua b/main.lua index 7f22745..482ae84 100644 --- a/main.lua +++ b/main.lua @@ -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