Skip to content

Commit

Permalink
Timer interval (#145)
Browse files Browse the repository at this point in the history
* Add format timer

* send format if a client enters in an area

* Add format string to timer class

* Add format string to timer class

* Add format string to timer class

* add format timer to doc

* Use send_timer_set_time function instead of for loop

* Update roleplay.py

* Update roleplay.py

* add format_timer to command aliases

* Fix restart timer when change format

* add format_timer to commands

* add timer interval command

* add interval to timer

* add interval to timer

* add interval to timer

* add timer interval command to documentation

* add more info to the /format_timer doc

* Update timer interval docs

* modify timer interval

* update format timer command

* Update roleplay.py

* Update roleplay.py

* add send_timer_set_interval function

* Update roleplay.py

* Update area_manager.py

---------

Co-authored-by: Alex Noir <[email protected]>
  • Loading branch information
EstatoDeviato and Crystalwarrior authored Dec 27, 2024
1 parent 07fcb69 commit 2eaaf10
Show file tree
Hide file tree
Showing 6 changed files with 115 additions and 1 deletion.
3 changes: 2 additions & 1 deletion config_sample/command_aliases.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ evimod: evidence_mod
eviswap: evidence_swap
force_follow: follow_me
force_pos: forcepos
timer_format: format_timer
fp: firstperson
fps: firstperson
ga: getarea
Expand Down Expand Up @@ -111,4 +112,4 @@ get_link: getlink
get_links: getlinks
remove_musiclist: musiclist_remove
add_musiclist: musiclist_add
save_musiclist: musiclist_save
save_musiclist: musiclist_save
9 changes: 9 additions & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -522,6 +522,15 @@
- `start` starts the previously set timer, so `/timer 0 start`.
- `pause` OR `stop` pauses the timer that's currently running, so `/timer 0 pause`.
- `unset` OR `hide` hides the timer for it to no longer show up, so `/timer 0 hide`.
* **format_timer** `<id> <format>`
- Format the timer in the current area or hub.
- Example of format: `Time Left: hh:mm`
- Default format: `hh:mm:ss.zzz`
- For more information on how to implement your format, [go here!](https://doc.qt.io/qt-6/qtime.html#toString)
* **timer_interval** `<id> <interval>`
- Set timer interval in the current area or hub.
- Example: `/timer_interval 1 15m`
- Default interval: `/timer_interval 1 16ms`
## Musiclists
* **musiclist\_add** `<local/area/hub>` `<Category>` `<MusicName>` `[Length]` `[Path]`
- Allow you to add a song in a loaded musiclist!
Expand Down
2 changes: 2 additions & 0 deletions server/area.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ def __init__(
self.caller = caller
self.schedule = None
self.commands = []
self.format = "hh:mm:ss.zzz"
self.interval = 16

def timer_expired(self):
if self.schedule:
Expand Down
2 changes: 2 additions & 0 deletions server/area_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ def __init__(
self.caller = caller
self.schedule = None
self.commands = []
self.format = "hh:mm:ss.zzz"
self.interval = 16

def timer_expired(self):
if self.schedule:
Expand Down
18 changes: 18 additions & 0 deletions server/client_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import time
import math
import os
import arrow
from heapq import heappop, heappush


Expand Down Expand Up @@ -361,6 +362,23 @@ def send_timer_set_time(self, timer_id=None, new_time=None, start=False):
else:
self.send_command("TI", timer_id, 2, new_time) # Show timer
self.send_command("TI", timer_id, int(not start), new_time) # Set timer with value and start
if timer_id == 0:
timer = self.area.area_manager.timer
else:
timer = self.area.timers[timer_id-1]
self.send_command("TF", timer_id, timer.format, new_time)
self.send_command("TIN", timer_id, timer.interval)

def send_timer_set_interval(self, timer_id, timer):
if timer.started:
current_time = timer.target - arrow.get()
current_time = int(current_time.total_seconds()) * 1000
else:
current_time = int(timer.static.total_seconds()) * 1000
if timer_id == 0:
self.area.area_manager.send_timer_set_time(timer_id, current_time, timer.started)
else:
self.area.send_timer_set_time(timer_id, current_time, timer.started)

def send_timer_set_step_length(self, timer_id=None, new_step_length=None):
if self.software == "DRO":
Expand Down
82 changes: 82 additions & 0 deletions server/commands/roleplay.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@
"ooc_cmd_timer",
"ooc_cmd_demo",
"ooc_cmd_trigger",
"ooc_cmd_format_timer",
"ooc_cmd_timer_interval",
]


Expand Down Expand Up @@ -950,3 +952,83 @@ def ooc_cmd_trigger(client, arg):
val = args[1]
client.area.triggers[trig] = val
client.send_ooc(f'Changed to Call "{val}" on trigger "{trig}"')


def ooc_cmd_format_timer(client, arg):
"""
Format the timer
Usage: /format_timer <Timer_iD> <Format>
"""
args = shlex.split(arg)
try:
args[0] = int(args[0])
except:
raise ArgumentError("Timer ID should be an integer")
if args[0] == 0:
if client.is_mod or client in client.area.area_manager.owners:
timer = client.area.area_manager.timer
else:
client.send_ooc("You cannot change timer 0 format if you are not GM")
return
else:
if (
client.is_mod
or client in client.area.area_manager.owners
or client in client.area.owners
):
timer = client.area.timers[args[0] - 1]
else:
client.send_ooc("You cannot change timer format if you are at least CM")
return
timer.format = args[1:]
if timer.set:
if timer.started:
current_time = timer.target - arrow.get()
current_time = int(current_time.total_seconds()) * 1000
else:
current_time = int(timer.static.total_seconds()) * 1000
if args[0] == 0:
client.area.area_manager.send_timer_set_time(args[0], current_time, timer.started)
else:
client.area.send_timer_set_time(args[0], current_time, timer.started)
client.send_ooc(f"Timer {args[0]} format: '{args[1]}'")


def ooc_cmd_timer_interval(client, arg):
"""
Set timer interval
If timer interval is not written than will show default timer interval (16ms)
Example: /timer_interval 1 15m
Usage: /timer_interval <Timer_ID> <Interval>
"""
args = shlex.split(arg)
try:
args[0] = int(args[0])
except:
raise ArgumentError("Timer ID should be an integer")
if args[0] == 0:
if client.is_mod or client in client.area.area_manager.owners:
timer = client.area.area_manager.timer
else:
client.send_ooc("You cannot change timer 0 interval if you are not GM")
return
else:
if (
client.is_mod
or client in client.area.area_manager.owners
or client in client.area.owners
):
timer = client.area.timers[args[0] - 1]
else:
client.send_ooc("You cannot change timer interval if you are at least CM")
return
try:
if len(args) == 1:
timer.interval = 16
else:
timer.interval = pytimeparse.parse(args[1]) * 1000
except:
raise ArgumentError("Interval value not valid!")
if timer.set:
client.send_timer_set_interval(args[0], timer)
client.send_ooc(f"Timer {args[0]} interval is set to '{args[1]}'")

0 comments on commit 2eaaf10

Please sign in to comment.