PEP 8 whitespace comply, visual align
This commit is contained in:
parent
0f72f0f74c
commit
3d268eaa39
1 changed files with 14 additions and 11 deletions
|
|
@ -39,6 +39,7 @@ _GAME_EPOCH = None
|
||||||
# Helper Script dealing in gametime (created by `schedule` function
|
# Helper Script dealing in gametime (created by `schedule` function
|
||||||
# below).
|
# below).
|
||||||
|
|
||||||
|
|
||||||
class TimeScript(DefaultScript):
|
class TimeScript(DefaultScript):
|
||||||
"""Gametime-sensitive script."""
|
"""Gametime-sensitive script."""
|
||||||
|
|
||||||
|
|
@ -60,6 +61,7 @@ class TimeScript(DefaultScript):
|
||||||
|
|
||||||
# Access functions
|
# Access functions
|
||||||
|
|
||||||
|
|
||||||
def runtime():
|
def runtime():
|
||||||
"""
|
"""
|
||||||
Get the total runtime of the server since first start (minus
|
Get the total runtime of the server since first start (minus
|
||||||
|
|
@ -134,8 +136,9 @@ def gametime(absolute=False):
|
||||||
gtime = epoch + (runtime() - GAME_TIME_OFFSET) * TIMEFACTOR
|
gtime = epoch + (runtime() - GAME_TIME_OFFSET) * TIMEFACTOR
|
||||||
return gtime
|
return gtime
|
||||||
|
|
||||||
def real_seconds_until(sec=None, min=None, hour=None, day=None,
|
|
||||||
month=None, year=None):
|
def real_seconds_until(sec=None, min=None, hour=None,
|
||||||
|
day=None, month=None, year=None):
|
||||||
"""
|
"""
|
||||||
Return the real seconds until game time.
|
Return the real seconds until game time.
|
||||||
|
|
||||||
|
|
@ -187,8 +190,9 @@ def real_seconds_until(sec=None, min=None, hour=None, day=None,
|
||||||
seconds = (projected - current).total_seconds()
|
seconds = (projected - current).total_seconds()
|
||||||
return seconds / TIMEFACTOR
|
return seconds / TIMEFACTOR
|
||||||
|
|
||||||
def schedule(callback, repeat=False, sec=None, min=None, hour=None,
|
|
||||||
day=None, month=None, year=None):
|
def schedule(callback, repeat=False, sec=None, min=None,
|
||||||
|
hour=None, day=None, month=None, year=None):
|
||||||
"""
|
"""
|
||||||
Call a callback at a given in-game time.
|
Call a callback at a given in-game time.
|
||||||
|
|
||||||
|
|
@ -212,12 +216,12 @@ def schedule(callback, repeat=False, sec=None, min=None, hour=None,
|
||||||
schedule(func, min=5, sec=0) # Will call 5 minutes past the next (in-game) hour.
|
schedule(func, min=5, sec=0) # Will call 5 minutes past the next (in-game) hour.
|
||||||
schedule(func, hour=2, min=30, sec=0) # Will call the next (in-game) day at 02:30.
|
schedule(func, hour=2, min=30, sec=0) # Will call the next (in-game) day at 02:30.
|
||||||
"""
|
"""
|
||||||
seconds = real_seconds_until(sec=sec, min=min, hour=hour, day=day,
|
seconds = real_seconds_until(sec=sec, min=min, hour=hour,
|
||||||
month=month, year=year)
|
day=day, month=month, year=year)
|
||||||
script = create_script("evennia.utils.gametime.TimeScript",
|
script = create_script("evennia.utils.gametime.TimeScript",
|
||||||
key="TimeScript", desc="A gametime-sensitive script",
|
key="TimeScript", desc="A gametime-sensitive script",
|
||||||
interval=seconds, start_delay=True,
|
interval=seconds, start_delay=True,
|
||||||
repeats=-1 if repeat else 1)
|
repeats=-1 if repeat else 1)
|
||||||
script.db.callback = callback
|
script.db.callback = callback
|
||||||
script.db.gametime = {
|
script.db.gametime = {
|
||||||
"sec": sec,
|
"sec": sec,
|
||||||
|
|
@ -229,6 +233,7 @@ def schedule(callback, repeat=False, sec=None, min=None, hour=None,
|
||||||
}
|
}
|
||||||
return script
|
return script
|
||||||
|
|
||||||
|
|
||||||
def reset_gametime():
|
def reset_gametime():
|
||||||
"""
|
"""
|
||||||
Resets the game time to make it start from the current time. Note that
|
Resets the game time to make it start from the current time. Note that
|
||||||
|
|
@ -238,5 +243,3 @@ def reset_gametime():
|
||||||
global GAME_TIME_OFFSET
|
global GAME_TIME_OFFSET
|
||||||
GAME_TIME_OFFSET = runtime()
|
GAME_TIME_OFFSET = runtime()
|
||||||
ServerConfig.objects.conf("gametime_offset", GAME_TIME_OFFSET)
|
ServerConfig.objects.conf("gametime_offset", GAME_TIME_OFFSET)
|
||||||
|
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue