This commit is contained in:
2019-03-13 10:59:06 +01:00
parent 204aed6b06
commit 8cfa8c7907
7 changed files with 144 additions and 17 deletions

View File

@@ -13,6 +13,7 @@ class ReplayFrame:
def set_delta(self, delta):
if type(delta) is not int:
raise Exception("Delta is not type of int")
self.delta = delta
def set_position(self, x, y):
self.x = x
@@ -24,7 +25,7 @@ class ReplayFrame:
self.buttons = buttons
def __str__(self):
return "%s|%s|%s|%s," % (self.delta, self.x, self.y, self.buttons)
return "%d|%s|%s|%d," % (self.delta, repr(self.x), repr(self.y), self.buttons)
def __bytes__(self):
return str(self).encode()

View File

@@ -12,7 +12,7 @@ NIGHTCORE = 1 << 9
FLASHLIGHT = 1 << 10
AUTOPLAY = 1 << 11
SPUNOUT = 1 << 12
RELAX2 = 1 << 13
AUTOPILOT = 1 << 13
PERFECT = 1 << 14
KEY4 = 1 << 15
KEY5 = 1 << 16

View File

@@ -2,6 +2,8 @@ import struct
import string
import lzma
from .frame import ReplayFrame
from .helpers import osuModes
from .helpers import osuMods
from .helpers import osuRanks
@@ -199,12 +201,19 @@ class Replay:
# Write replay data --------------------------------------------------------
def write(self, frame):
if type(frame) is list:
t_frame = type(frame)
if t_frame is list:
for _frame in frame: # (frames)
self.write(_frame)
return
self._replay_data.value += bytes(frame)
if t_frame is ReplayFrame:
self._replay_data.value += bytes(frame)
elif t_frame is bytes:
self._replay_data.value += frame
elif t_frame is str:
self._replay_data.value += frame.encode()
else:
raise Exception("Invalid frame data")
# --------------------------------------------------------------------------
# IO replay data -----------------------------------------------------------