Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Timer interval #145

Merged
merged 26 commits into from
Dec 27, 2024
Merged
Show file tree
Hide file tree
Changes from 18 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
1e45ff2
Add format timer
EstatoDeviato May 21, 2024
3de8f2d
send format if a client enters in an area
EstatoDeviato May 21, 2024
fbdb908
Add format string to timer class
EstatoDeviato May 21, 2024
d72b536
Add format string to timer class
EstatoDeviato May 21, 2024
914bc71
Add format string to timer class
EstatoDeviato May 21, 2024
be1b300
add format timer to doc
EstatoDeviato Jun 11, 2024
9c84a39
Use send_timer_set_time function instead of for loop
EstatoDeviato Jun 11, 2024
c20fd9b
Update roleplay.py
EstatoDeviato Jun 11, 2024
b7f6a62
Update roleplay.py
EstatoDeviato Jun 11, 2024
80d7dd3
add format_timer to command aliases
EstatoDeviato Jun 11, 2024
431184b
Fix restart timer when change format
EstatoDeviato Jun 12, 2024
bc7bc86
add format_timer to commands
EstatoDeviato Jun 12, 2024
f710c54
add timer interval command
EstatoDeviato Jun 12, 2024
66d1025
add interval to timer
EstatoDeviato Jun 12, 2024
7690f43
add interval to timer
EstatoDeviato Jun 12, 2024
9e6aa38
add interval to timer
EstatoDeviato Jun 12, 2024
1418797
add timer interval command to documentation
EstatoDeviato Jun 12, 2024
a3a8928
add more info to the /format_timer doc
Crystalwarrior Jul 29, 2024
871c871
Update timer interval docs
Crystalwarrior Jul 29, 2024
b94526f
modify timer interval
EstatoDeviato Dec 18, 2024
291931d
update format timer command
EstatoDeviato Dec 18, 2024
e835550
Update roleplay.py
EstatoDeviato Dec 19, 2024
7682728
Update roleplay.py
EstatoDeviato Dec 19, 2024
6e33a6a
add send_timer_set_interval function
EstatoDeviato Dec 19, 2024
735008a
Update roleplay.py
EstatoDeviato Dec 19, 2024
0a9890a
Update area_manager.py
EstatoDeviato Dec 19, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
8 changes: 8 additions & 0 deletions docs/commands.md
Original file line number Diff line number Diff line change
Expand Up @@ -518,6 +518,14 @@
- `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
## 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 @@ -42,6 +42,8 @@ def __init__(
self.caller = caller
self.schedule = None
self.commands = []
self.format = "hh:mm:ss.zzz"
self.interval = 1000 / 60
EstatoDeviato marked this conversation as resolved.
Show resolved Hide resolved

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 = 1000 / 60

def timer_expired(self):
if self.schedule:
Expand Down
6 changes: 6 additions & 0 deletions server/client_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,12 @@ 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_step_length(self, timer_id=None, new_step_length=None):
if self.software == "DRO":
Expand Down
86 changes: 86 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 @@ -944,3 +946,87 @@ 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]
EstatoDeviato marked this conversation as resolved.
Show resolved Hide resolved
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
Example: /timer_interval 1 15m
Usage: /timer_interval <Timer_ID> <Interval>
"""
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there doesn't seem a way here to reset the timer interval to default. Also /timer_interval 1 should display the currently set timer 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:
timer.interval = pytimeparse.parse(args[1])*1000*60
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wait why do you multiply the result by 1000 and then 60?

except:
raise ArgumentError("Interval value not valid!")
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)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe this should be moved to a new function like send_timer_set_interval or smth?

client.send_ooc(f"Timer {args[0]} interval is set to '{args[1]}'")
Loading