-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #101 from randovania/feature/maya-spline
Properly decode Spline properties
- Loading branch information
Showing
5 changed files
with
183 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
from __future__ import annotations | ||
|
||
import dataclasses | ||
|
||
from retro_data_structures.properties.base_property import BaseProperty | ||
|
||
|
||
@dataclasses.dataclass() | ||
class BaseColor(BaseProperty): | ||
r: float = 0.0 | ||
g: float = 0.0 | ||
b: float = 0.0 | ||
a: float = 0.0 | ||
|
||
@classmethod | ||
def from_json(cls, data: dict): | ||
return cls(data["r"], data["g"], data["b"], data["a"]) | ||
|
||
def to_json(self) -> dict: | ||
return { | ||
"r": self.r, | ||
"g": self.g, | ||
"b": self.b, | ||
"a": self.a, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
from __future__ import annotations | ||
|
||
import dataclasses | ||
import typing | ||
|
||
from retro_data_structures.properties.base_property import BaseProperty | ||
|
||
|
||
@dataclasses.dataclass() | ||
class Knot: | ||
time: float # X position | ||
amplitude: float # Y position | ||
unk_a: int | ||
unk_b: int | ||
cached_tangents_a: tuple[float, float] | None | ||
cached_tangents_b: tuple[float, float] | None | ||
|
||
@classmethod | ||
def from_json(cls, data: dict) -> typing.Self: | ||
return cls( | ||
time=data["time"], | ||
amplitude=data["amplitude"], | ||
unk_a=data["unk_a"], | ||
unk_b=data["unk_b"], | ||
cached_tangents_a=data["cached_tangents_a"], | ||
cached_tangents_b=data["cached_tangents_b"], | ||
) | ||
|
||
def to_json(self) -> dict: | ||
return { | ||
"time": self.time, | ||
"amplitude": self.amplitude, | ||
"unk_a": self.unk_a, | ||
"unk_b": self.unk_b, | ||
"cached_tangents_a": self.cached_tangents_a, | ||
"cached_tangents_b": self.cached_tangents_b, | ||
} | ||
|
||
|
||
@dataclasses.dataclass() | ||
class BaseSpline(BaseProperty): | ||
knots: list[Knot] = dataclasses.field(default_factory=list) | ||
minimum_amplitude: float = 0.0 | ||
maximum_amplitude: float = 0.0 | ||
pre_infinity: int = 0 | ||
post_infinity: int = 0 | ||
clamp_mode: int = 0 | ||
|
||
@classmethod | ||
def from_json(cls, data: dict) -> typing.Self: | ||
return cls( | ||
knots=[Knot.from_json(knot) for knot in data["knots"]], | ||
minimum_amplitude=data["minimum_amplitude"], | ||
maximum_amplitude=data["maximum_amplitude"], | ||
pre_infinity=data["pre_infinity"], | ||
post_infinity=data["post_infinity"], | ||
clamp_mode=data["clamp_mode"], | ||
) | ||
|
||
def to_json(self) -> dict: | ||
return { | ||
"knots": [knot.to_json() for knot in self.knots], | ||
"minimum_amplitude": self.minimum_amplitude, | ||
"maximum_amplitude": self.maximum_amplitude, | ||
"pre_infinity": self.pre_infinity, | ||
"post_infinity": self.post_infinity, | ||
"clamp_mode": self.clamp_mode, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
from __future__ import annotations | ||
|
||
import dataclasses | ||
|
||
from retro_data_structures.properties.base_property import BaseProperty | ||
|
||
|
||
@dataclasses.dataclass() | ||
class BaseVector(BaseProperty): | ||
x: float = 0.0 | ||
y: float = 0.0 | ||
z: float = 0.0 | ||
|
||
@classmethod | ||
def from_json(cls, data: dict): | ||
return cls(data["x"], data["y"], data["z"]) | ||
|
||
def to_json(self) -> dict: | ||
return { | ||
"x": self.x, | ||
"y": self.y, | ||
"z": self.z, | ||
} | ||
|
||
def dependencies_for(self, asset_manager): | ||
yield from [] |