Add the evennia.utils.gamtime.reset_gametime() function, for restarting gametime from a later time than the server creation time.
This commit is contained in:
parent
070e4924e9
commit
95aa505b45
1 changed files with 21 additions and 1 deletions
|
|
@ -9,12 +9,16 @@ from __future__ import division
|
||||||
|
|
||||||
from time import time
|
from time import time
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
from evennia.server.models import ServerConfig
|
||||||
|
|
||||||
# Speed-up factor of the in-game time compared
|
# Speed-up factor of the in-game time compared
|
||||||
# to real time.
|
# to real time.
|
||||||
|
|
||||||
TIMEFACTOR = settings.TIME_FACTOR
|
TIMEFACTOR = settings.TIME_FACTOR
|
||||||
|
|
||||||
|
# Only set if gametime_reset was called at some point.
|
||||||
|
GAME_TIME_OFFSET = ServerConfig.objects.conf("gametime_offset", default=0)
|
||||||
|
|
||||||
# Common real-life time measure, in seconds.
|
# Common real-life time measure, in seconds.
|
||||||
# You should not change this.
|
# You should not change this.
|
||||||
|
|
||||||
|
|
@ -37,6 +41,7 @@ SERVER_START_TIME = 0.0
|
||||||
SERVER_RUNTIME_LAST_UPDATED = 0.0
|
SERVER_RUNTIME_LAST_UPDATED = 0.0
|
||||||
SERVER_RUNTIME = 0.0
|
SERVER_RUNTIME = 0.0
|
||||||
|
|
||||||
|
|
||||||
def _format(seconds, *divisors) :
|
def _format(seconds, *divisors) :
|
||||||
"""
|
"""
|
||||||
Helper function. Creates a tuple of even dividends given a range
|
Helper function. Creates a tuple of even dividends given a range
|
||||||
|
|
@ -83,6 +88,7 @@ def runtime(format=False):
|
||||||
return _format(runtime, 31536000, 2628000, 604800, 86400, 3600, 60)
|
return _format(runtime, 31536000, 2628000, 604800, 86400, 3600, 60)
|
||||||
return runtime
|
return runtime
|
||||||
|
|
||||||
|
|
||||||
def uptime(format=False):
|
def uptime(format=False):
|
||||||
"""
|
"""
|
||||||
Get the current uptime of the server since last reload
|
Get the current uptime of the server since last reload
|
||||||
|
|
@ -100,6 +106,7 @@ def uptime(format=False):
|
||||||
return _format(uptime, 31536000, 2628000, 604800, 86400, 3600, 60)
|
return _format(uptime, 31536000, 2628000, 604800, 86400, 3600, 60)
|
||||||
return uptime
|
return uptime
|
||||||
|
|
||||||
|
|
||||||
def gametime(format=False):
|
def gametime(format=False):
|
||||||
"""
|
"""
|
||||||
Get the total gametime of the server since first start (minus downtimes)
|
Get the total gametime of the server since first start (minus downtimes)
|
||||||
|
|
@ -112,12 +119,25 @@ def gametime(format=False):
|
||||||
into time units.
|
into time units.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
gametime = runtime() * TIMEFACTOR
|
gametime = (runtime() - GAME_TIME_OFFSET) * TIMEFACTOR
|
||||||
if format:
|
if format:
|
||||||
return _format(gametime, YEAR, MONTH, WEEK, DAY, HOUR, MIN)
|
return _format(gametime, YEAR, MONTH, WEEK, DAY, HOUR, MIN)
|
||||||
return gametime
|
return gametime
|
||||||
|
|
||||||
|
|
||||||
|
def reset_gametime():
|
||||||
|
"""
|
||||||
|
Resets the game time to make it start from the current time.
|
||||||
|
|
||||||
|
"""
|
||||||
|
global GAME_TIME_OFFSET
|
||||||
|
GAME_TIME_OFFSET = runtime()
|
||||||
|
ServerConfig.objects.conf("gametime_offset", GAME_TIME_OFFSET)
|
||||||
|
|
||||||
|
|
||||||
|
# Conversion functions
|
||||||
|
|
||||||
|
|
||||||
def gametime_to_realtime(secs=0, mins=0, hrs=0, days=0,
|
def gametime_to_realtime(secs=0, mins=0, hrs=0, days=0,
|
||||||
weeks=0, months=0, yrs=0, format=False):
|
weeks=0, months=0, yrs=0, format=False):
|
||||||
"""
|
"""
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue