|
color = StructProp[colour.Color](id=TrackID.Data) |
Solution 1; Change StructBase to encode and decode colour.Color directly into StructEvent._props
|
def __init__(self, stream: BytesIOEx): |
|
self._props: dict[str, Any] = dict.fromkeys(type(self).PROPS) |
|
self._stream = stream |
|
self._stream_len = len(stream.getvalue()) |
|
|
|
for key, type_or_size in type(self).PROPS.items(): |
|
if isinstance(type_or_size, int): |
|
self._props[key] = self._stream.read(type_or_size) |
|
else: |
|
self._props[key] = getattr(self._stream, f"read_{type_or_size}")() |
|
def __setitem__(self, key: str, value: Any): |
|
if key not in type(self).PROPS: |
|
raise KeyError(key) |
|
|
|
self._stream.seek(type(self).OFFSETS[key]) |
|
type_or_size = type(self).PROPS[key] |
|
if isinstance(type_or_size, int): |
|
self._stream.write(value) |
|
else: |
|
getattr(self._stream, f"write_{type_or_size}")(value) |
|
|
|
if len(self._stream.getvalue()) > self._stream_len and self.TRUNCATE: |
|
raise PropertyCannotBeSet |
|
self._props[key] = value |
Solution 2: Add a ColorProp to pyflp._base, specifically for colours encoded in variable sized events
This is the better option imo, because it will not modify StructEvent._props, which will be used to store event values without any type of interpretation (mainly for debugging purposes). Using the first solution also breaks one of the highlights of PyFLP 2.0.0 - zero pre-parse validation.
PyFLP/pyflp/arrangement.py
Line 308 in 4a063da
Solution 1; Change
StructBaseto encode and decodecolour.Colordirectly intoStructEvent._propsPyFLP/pyflp/_base.py
Lines 521 to 530 in 4a063da
PyFLP/pyflp/_base.py
Lines 544 to 557 in 4a063da
Solution 2: Add a
ColorProptopyflp._base, specifically for colours encoded in variable sized eventsThis is the better option imo, because it will not modify
StructEvent._props, which will be used to store event values without any type of interpretation (mainly for debugging purposes). Using the first solution also breaks one of the highlights of PyFLP 2.0.0 - zero pre-parse validation.