Skip to content

Tick update #147

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

Closed
wants to merge 3 commits into from
Closed
Changes from 1 commit
Commits
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
Prev Previous commit
Next Next commit
Updated cancel_on_map_end to a keyword argument
  • Loading branch information
Mahi committed Sep 23, 2016
commit f267be678d8cb445479911df35b9ca9f8a48ff7a
20 changes: 10 additions & 10 deletions addons/source-python/packages/source-python/listeners/tick.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class GameThread(Thread):
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
on_tick_listener_manager.register_listener(self._tick)

def __del__(self):
on_tick_listener_manager.unregister_listener(self._tick)

Expand Down Expand Up @@ -109,7 +109,7 @@ def add(self, delay):
class Delay(WeakAutoUnload):
"""Execute a callback after a given delay."""

def __init__(self, delay, callback, cancel_on_map_end=False, args=(), kwargs={}):
def __init__(self, delay, callback, args=(), kwargs={}, *, cancel_on_map_end=False):
"""Initialize the delay.

:param float delay: The delay in seconds.
Expand All @@ -129,9 +129,9 @@ def __init__(self, delay, callback, cancel_on_map_end=False, args=(), kwargs={})
self._start_time = time.time()
self.exec_time = self._start_time + delay
self.callback = callback
self.cancel_on_map_end = cancel_on_map_end
self.args = tuple(args)
self.kwargs = dict(kwargs)
self.cancel_on_map_end = cancel_on_map_end
_delay_manager.add(self)

def __lt__(self, other):
Expand Down Expand Up @@ -203,22 +203,22 @@ class RepeatStatus(IntEnum):
class Repeat(AutoUnload):
"""Class used to create and call repeats."""

def __init__(self, callback, cancel_on_map_end=False, args=(), kwargs={}):
def __init__(self, callback, args=(), kwargs={}, *, cancel_on_map_end=False):
"""Store all instance attributes.

:param callback: A callable object that should be called at the
end of each loop.
:param bool cancel_on_map_end: Whether or not to cancel the repeat at
the end of the map.
:param tuple args: Arguments that should be passed to the callback.
:param dict kwargs: Keyword arguments that should be passed to the
callback.
:param bool cancel_on_map_end: Whether or not to cancel the repeat at
the end of the map.
"""
# Store the base attributes
self.callback = callback
self.cancel_on_map_end = cancel_on_map_end
self.args = tuple(args)
self.kwargs = dict(kwargs)
self.cancel_on_map_end = cancel_on_map_end

# Log the __init__ message
listeners_tick_logger.log_debug(
Expand Down Expand Up @@ -276,7 +276,7 @@ def start(self, interval, limit, execute_on_start=False):

# Start the delay
self._delay = Delay(
self._interval, self._execute, self.cancel_on_map_end
self._interval, self._execute, cancel_on_map_end=self.cancel_on_map_end
)

# Call the callback if set to execute on start
Expand Down Expand Up @@ -378,7 +378,7 @@ def resume(self):

# Start the delay
self._delay = Delay(
self._loop_time, self._execute, self.cancel_on_map_end
self._loop_time, self._execute, cancel_on_map_end=self.cancel_on_map_end
)

def extend(self, adjustment):
Expand Down Expand Up @@ -477,7 +477,7 @@ def _execute(self):

# Call the delay again
self._delay = Delay(
self._interval, self._execute, self.cancel_on_map_end
self._interval, self._execute, cancel_on_map_end=self.cancel_on_map_end
)

# Are no more loops to be made?
Expand Down