Skip to content

Commit 289e1a1

Browse files
satoon101Ayuto
authored andcommitted
Tick Repeat/Delay updates (#156)
* Fixes for issue #142. Changed TickRepeat/TickRepeatStatus to Repeat/RepeatStatus to match Delay class naming convention. Added time_remaining/time_elapsed properties to Delay class. Added execute_on_start argument to Repeat.start to know if the function needs to be executed before any delays occur. Changed Repeat properties remaining, count, limit, and elapsed to remaining_loops, loop_count, loop_limit, and time_elapsed to better describe what the property is for. Added Repeat properties delay_time_remaining/delay_time_elapsed to return the values for the current delay. * Updated doc-strings in listeners.tick. * Fix for issue #145. Both Delay and Repeat now allow for the argument cancel_on_map_end to denote whether the object should be cancelled when the current map ends. * Fix for issue #145. Changed args and kwargs passed to Delay to not use star-args format. Moved cancel_on_map_end to the end of the arguments. Updated all instances of Delay class to use the new format. * Fix for issue #145. Updated doc strings for Delay/Repeat changes. Updated Repeat argument structure to match Delay's new structure. Changed args to use tuple() as it is immutable and should work fine in place of None. * Fix for issue #145. Changed cancel_on_map_end to cancel_on_level_end to match naming convention of the listener used to cancel the Delay. * Fixed possible unexpected behaviour when canceling delays at the end of the map * Fix for issue #145. Moved properties above methods in Repeat class. Changed property names of Repeat to be more conform. * Fix for issue #145. Fixed Repeat methods for changes to property names. Changed Repeat values for loops_remaining, total_time, and total_time_remaining to return math.inf if there is no limit on the number of loops. * Fix for issue #145. Fixed Repeat status remaining RUNNING when its delay was cancelled on level end. * Fixed possible error when using <function> named _execute for a Delay callback. * Updated Entity.delay for upcoming changes. * Updated documentation * Infinity update * Fixed total_time_remaining raising an error when the repeat stopped * Added getters for interval, adjusted_loops and original_loops
1 parent f9e63ff commit 289e1a1

File tree

5 files changed

+375
-209
lines changed

5 files changed

+375
-209
lines changed

addons/source-python/packages/source-python/core/command/__init__.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@
2323
from engines.server import queue_command_string
2424
# Paths
2525
from paths import SP_DATA_PATH
26-
# Players
27-
from players.entity import Player
2826
# Plugins
2927
from plugins import _plugin_strings
3028
from plugins.command import SubCommandManager
@@ -144,19 +142,22 @@ def print_credits(self):
144142
@_core_command.server_sub_command(['delay'])
145143
def _sp_delay(command_info, delay:float, command, *args):
146144
"""Execute a command after a given delay."""
147-
Delay(delay, queue_command_string, command + ' ' + ' '.join(args))
145+
Delay(delay, queue_command_string, (command + ' ' + ' '.join(args), ))
146+
148147

149148
@_core_command.server_sub_command(['version'])
150149
def _sp_version(command_info):
151150
"""Display Source.Python version information."""
152151
core_command_logger.log_message(
153152
'Current Source.Python version: {0}'.format(VERSION))
154153

154+
155155
@_core_command.server_sub_command(['credits'])
156156
def _sp_credits(command_info):
157157
"""List all credits for Source.Python."""
158158
_core_command.print_credits()
159159

160+
160161
@_core_command.server_sub_command(['help'])
161162
def _sp_help(command_info, command=None, *server_sub_commands):
162163
"""Print all sp sub-commands or help for a specific command."""

addons/source-python/packages/source-python/entities/entity.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -518,15 +518,20 @@ def _set_property(self, name, prop_type, value):
518518
'Property "{0}" not found for entity type "{1}"'.format(
519519
name, self.classname))
520520

521-
def delay(self, delay, callback, *args, **kwargs):
521+
def delay(
522+
self, delay, callback, args=(), kwargs=None,
523+
cancel_on_level_end=False):
522524
"""Execute a callback after the given delay.
523525
524-
:param int delay: The delay in seconds.
526+
:param float delay: The delay in seconds.
525527
:param callback: A callable object that should be called after the
526528
delay expired.
527-
:param args: Arguments that should be passed to the callback.
528-
:param kwargs: Keyword arguments that should be passed to the
529+
:param tuple args: Arguments that should be passed to the callback.
530+
:param dict kwargs: Keyword arguments that should be passed to the
529531
callback.
532+
:param bool cancel_on_level_end: Whether or not to cancel the delay at
533+
the end of the map.
534+
:raises ValueError: If the given callback is not callable.
530535
531536
:return: The delay instance.
532537
:rtype: Delay
@@ -548,7 +553,7 @@ def _callback(*args, **kwargs):
548553
callback(*args, **kwargs)
549554

550555
# Get the delay instance...
551-
delay = Delay(delay, _callback, *args, **kwargs)
556+
delay = Delay(delay, _callback, args, kwargs, cancel_on_level_end)
552557

553558
# Add the delay to the dictionary...
554559
_entity_delays[self.index].add(delay)

0 commit comments

Comments
 (0)