Skip to content

Commit

Permalink
Add the type itself to FieldReflection
Browse files Browse the repository at this point in the history
  • Loading branch information
henriquegemignani committed Oct 20, 2023
1 parent d333735 commit cd3c017
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 0 deletions.
1 change: 1 addition & 0 deletions parse_pwe_templates.py
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ def add_prop(self, prop: PropDetails, prop_name: str, raw_name: str):

# from retro_data_structures.json_util import JsonValue
reflection_fields = [
prop.prop_type,
f"id=0x{prop.id:08x}",
f"original_name={repr(raw_name)}",
]
Expand Down
1 change: 1 addition & 0 deletions src/retro_data_structures/properties/base_property.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
from retro_data_structures.game_check import Game


@dataclasses.dataclass()
class BaseProperty:
@classmethod
def game(cls) -> Game:
Expand Down
14 changes: 14 additions & 0 deletions src/retro_data_structures/properties/field_reflection.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,26 @@
if TYPE_CHECKING:
from collections.abc import Callable

Check warning on line 9 in src/retro_data_structures/properties/field_reflection.py

View check run for this annotation

Codecov / codecov/patch

src/retro_data_structures/properties/field_reflection.py#L9

Added line #L9 was not covered by tests

from retro_data_structures.properties.base_property import BaseProperty

Check warning on line 11 in src/retro_data_structures/properties/field_reflection.py

View check run for this annotation

Codecov / codecov/patch

src/retro_data_structures/properties/field_reflection.py#L11

Added line #L11 was not covered by tests

T = TypeVar("T")


@dataclasses.dataclass(frozen=True)
class FieldReflection(Generic[T]):
type: type[T]
id: int
original_name: str | None
from_json: Callable[[json_util.JsonValue], T] = json_util.identity
to_json: Callable[[T], json_util.JsonValue] = json_util.identity


def get_reflection(cls: type[BaseProperty]) -> dict[str, FieldReflection]:
"""
Get all FieldReflection objects for a given property.
:param cls:
:return: A dict of field name, to a FieldDetails
"""
return {

Check warning on line 31 in src/retro_data_structures/properties/field_reflection.py

View check run for this annotation

Codecov / codecov/patch

src/retro_data_structures/properties/field_reflection.py#L31

Added line #L31 was not covered by tests
field.name: field.metadata["reflection"] for field in dataclasses.fields(cls) if "reflection" in field.metadata
}

0 comments on commit cd3c017

Please sign in to comment.