Spaces:
Building
Building
File size: 1,222 Bytes
d49f7bc |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 |
# Copyright (c) Meta Platforms, Inc. and affiliates.
# This source code is licensed under the MIT license found in the
# LICENSE file in the root directory of this source tree.
from typing import Optional
from abc import abstractmethod
class TimeManager():
""" Mixin class designed to be used by objects that must keep track of their own time (e.g. time-varying animations) """
def __init__(self, **kwargs):
super().__init__(**kwargs)
self._time: float = 0.0 # object's internal time, in seconds
self._is_paused: bool = False
def tick(self, delta_t: float) -> None:
""" Progress objects interval time by delta_t seconds if not paused """
if not self._is_paused:
self._time += delta_t
self.update()
@abstractmethod
def update(self):
""" Contains logic needed to update subclass after tick() """
pass
def set_pause(self, pause: Optional[bool]) -> None:
if pause is None:
self._is_paused = not self._is_paused
else:
self._is_paused = pause
def set_time(self, time: float) -> None:
self._time = time
def get_time(self) -> float:
return self._time
|