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:
Griatch 2016-10-12 20:27:21 +02:00
parent 070e4924e9
commit 95aa505b45

View file

@ -9,12 +9,16 @@ from __future__ import division
from time import time
from django.conf import settings
from evennia.server.models import ServerConfig
# Speed-up factor of the in-game time compared
# to real time.
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.
# You should not change this.
@ -37,6 +41,7 @@ SERVER_START_TIME = 0.0
SERVER_RUNTIME_LAST_UPDATED = 0.0
SERVER_RUNTIME = 0.0
def _format(seconds, *divisors) :
"""
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 runtime
def uptime(format=False):
"""
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 uptime
def gametime(format=False):
"""
Get the total gametime of the server since first start (minus downtimes)
@ -112,12 +119,25 @@ def gametime(format=False):
into time units.
"""
gametime = runtime() * TIMEFACTOR
gametime = (runtime() - GAME_TIME_OFFSET) * TIMEFACTOR
if format:
return _format(gametime, YEAR, MONTH, WEEK, DAY, HOUR, MIN)
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,
weeks=0, months=0, yrs=0, format=False):
"""