Skip to content

Tick Repeat/Delay updates #156

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

Merged
merged 22 commits into from
Dec 4, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,6 @@
from engines.server import queue_command_string
# Paths
from paths import SP_DATA_PATH
# Players
from players.entity import Player
# Plugins
from plugins import _plugin_strings
from plugins.command import SubCommandManager
Expand Down Expand Up @@ -144,19 +142,22 @@ def print_credits(self):
@_core_command.server_sub_command(['delay'])
def _sp_delay(command_info, delay:float, command, *args):
"""Execute a command after a given delay."""
Delay(delay, queue_command_string, command + ' ' + ' '.join(args))
Delay(delay, queue_command_string, (command + ' ' + ' '.join(args), ))


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


@_core_command.server_sub_command(['credits'])
def _sp_credits(command_info):
"""List all credits for Source.Python."""
_core_command.print_credits()


@_core_command.server_sub_command(['help'])
def _sp_help(command_info, command=None, *server_sub_commands):
"""Print all sp sub-commands or help for a specific command."""
Expand Down
15 changes: 10 additions & 5 deletions addons/source-python/packages/source-python/entities/entity.py
Original file line number Diff line number Diff line change
Expand Up @@ -518,15 +518,20 @@ def _set_property(self, name, prop_type, value):
'Property "{0}" not found for entity type "{1}"'.format(
name, self.classname))

def delay(self, delay, callback, *args, **kwargs):
def delay(
self, delay, callback, args=(), kwargs=None,
cancel_on_level_end=False):
"""Execute a callback after the given delay.

:param int delay: The delay in seconds.
:param float delay: The delay in seconds.
:param callback: A callable object that should be called after the
delay expired.
:param args: Arguments that should be passed to the callback.
:param kwargs: Keyword arguments that should be passed to the
: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_level_end: Whether or not to cancel the delay at
the end of the map.
:raises ValueError: If the given callback is not callable.

:return: The delay instance.
:rtype: Delay
Expand All @@ -548,7 +553,7 @@ def _callback(*args, **kwargs):
callback(*args, **kwargs)

# Get the delay instance...
delay = Delay(delay, _callback, *args, **kwargs)
delay = Delay(delay, _callback, args, kwargs, cancel_on_level_end)

# Add the delay to the dictionary...
_entity_delays[self.index].add(delay)
Expand Down
Loading