2019-03-13 05:43:26 +01:00
|
|
|
from .helpers import osuButtons
|
|
|
|
|
|
|
|
class ReplayFrame:
|
|
|
|
delta = 0 # Int
|
|
|
|
x = 0.0 # Float
|
|
|
|
y = 0.0 # Float
|
|
|
|
buttons = 0 # Int
|
|
|
|
def __init__(self, delta, x, y, buttons):
|
|
|
|
self.set_delta(delta)
|
|
|
|
self.set_position(x, y)
|
|
|
|
self.set_buttons(buttons)
|
|
|
|
|
|
|
|
def set_delta(self, delta):
|
|
|
|
if type(delta) is not int:
|
|
|
|
raise Exception("Delta is not type of int")
|
2019-03-13 10:59:06 +01:00
|
|
|
self.delta = delta
|
2019-03-13 05:43:26 +01:00
|
|
|
|
|
|
|
def set_position(self, x, y):
|
|
|
|
self.x = x
|
|
|
|
self.y = y
|
|
|
|
|
|
|
|
def set_buttons(self, buttons):
|
|
|
|
if buttons < 0 or buttons > (1 << 5) - 1:
|
|
|
|
raise Exception("Buttons are out of range")
|
|
|
|
self.buttons = buttons
|
|
|
|
|
2019-03-17 02:57:48 +01:00
|
|
|
@staticmethod
|
|
|
|
def _float_convert(f):
|
|
|
|
if f % 1 == 0:
|
|
|
|
return repr(int(f))
|
|
|
|
return repr(round(f, 1))
|
|
|
|
|
2019-03-13 05:43:26 +01:00
|
|
|
def __str__(self):
|
2019-03-17 02:57:48 +01:00
|
|
|
return "%d|%s|%s|%d," % (self.delta,
|
|
|
|
self._float_convert(self.x),
|
|
|
|
self._float_convert(self.y),
|
|
|
|
self.buttons)
|
2019-03-13 05:43:26 +01:00
|
|
|
|
|
|
|
def __bytes__(self):
|
2019-03-13 09:07:46 +01:00
|
|
|
return str(self).encode()
|