Skip to content

Commit

Permalink
Update type hints in CharacterService and related classes
Browse files Browse the repository at this point in the history
  • Loading branch information
KiloOscarSix committed Jan 31, 2024
1 parent 9c74cb2 commit 28fd1e5
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 22 deletions.
22 changes: 11 additions & 11 deletions CharacterService_ren.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ def get_user(character: Character) -> Character:
@staticmethod
def get_relationship(
character: Character, target: Optional[Character] = None
) -> Relationship:
) -> "Relationship":
if target is None:
target = mc

Expand All @@ -41,7 +41,7 @@ def get_relationship(
@staticmethod
def has_relationship(
character: Character,
relationship: Relationship,
relationship: "Relationship",
target: Optional[Character] = None,
) -> bool:
if target is None:
Expand All @@ -52,7 +52,7 @@ def has_relationship(
@staticmethod
def set_relationship(
character: Character,
relationship: Relationship,
relationship: "Relationship",
target: Optional[Character] = None,
) -> None:
if target is None:
Expand All @@ -77,26 +77,26 @@ def set_relationship(
target.relationships[character] = relationship

@staticmethod
def get_mood(character: NonPlayableCharacter) -> Moods:
def get_mood(character: "NonPlayableCharacter") -> "Moods":
return character.mood

@staticmethod
def has_mood(character: NonPlayableCharacter, mood: Moods) -> bool:
def has_mood(character: "NonPlayableCharacter", mood: "Moods") -> bool:
return mood == character.mood or character.mood & mood == mood

@staticmethod
def set_mood(character: NonPlayableCharacter, mood: Moods) -> None:
def set_mood(character: "NonPlayableCharacter", mood: "Moods") -> None:
if mood == character.mood:
return

character.mood = mood

@staticmethod
def reset_mood(character: NonPlayableCharacter) -> None:
def reset_mood(character: "NonPlayableCharacter") -> None:
character.mood = Moods.NORMAL

@staticmethod
def add_mood(character: NonPlayableCharacter, mood: Moods) -> None:
def add_mood(character: "NonPlayableCharacter", mood: "Moods") -> None:
if mood == character.mood:
return

Expand All @@ -107,7 +107,7 @@ def add_mood(character: NonPlayableCharacter, mood: Moods) -> None:
character.mood |= mood

@staticmethod
def remove_mood(character: NonPlayableCharacter, mood: Moods) -> None:
def remove_mood(character: "NonPlayableCharacter", mood: "Moods") -> None:
character.mood &= ~mood

@staticmethod
Expand Down Expand Up @@ -243,9 +243,9 @@ def is_exes(
)

@staticmethod
def is_mad(character: NonPlayableCharacter) -> bool:
def is_mad(character: "NonPlayableCharacter") -> bool:
return CharacterService.has_mood(character, Moods.MAD)

@staticmethod
def is_threatened(character: NonPlayableCharacter) -> bool:
def is_threatened(character: "NonPlayableCharacter") -> bool:
return CharacterService.has_mood(character, Moods.THREATENED)
10 changes: 6 additions & 4 deletions Character_ren.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,13 @@
chloe: "Character"

"""renpy
init python:
init -10 python:
"""


@runtime_checkable
class Character(Protocol):
relationships: dict["Character", Relationship]
relationships: dict["Character", "Relationship"]
_mood: Moods = Moods.NORMAL

def __hash__(self) -> int:
Expand Down Expand Up @@ -90,10 +90,12 @@ def is_threatened(self) -> bool:

# endregion Moods
# region Relationships
def get_relationship(self, target: "Character") -> Relationship:
def get_relationship(self, target: "Character") -> "Relationship":
return self.relationships.setdefault(target, Relationship.FRIEND)

def has_relationship(self, relationship: Relationship, target: "Character") -> bool:
def has_relationship(
self, relationship: "Relationship", target: "Character"
) -> bool:
return self.get_relationship(target) == relationship

def is_exclusive_girlfriend(self, target: "Character") -> bool:
Expand Down
2 changes: 1 addition & 1 deletion Moods_ren.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from enum import Flag

"""renpy
init python:
init -20 python:
"""


Expand Down
10 changes: 5 additions & 5 deletions NonPlayableCharacter_ren.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@

@runtime_checkable
class NonPlayableCharacter(Character, Protocol):
pending_text_messages: list[Message]
text_messages: list[Message]
pending_text_messages: list["Message"]
text_messages: list["Message"]

pending_simplr_messages: list[Message]
simplr_messages: list[Message]
pending_simplr_messages: list["Message"]
simplr_messages: list["Message"]

points: int = 0

Expand All @@ -34,7 +34,7 @@ def profile_pictures(self) -> tuple[str, ...]:
return CharacterService.get_profile_pictures(self.name.lower())

@property
def traits(self) -> CharacterTrait:
def traits(self) -> "CharacterTrait":
return CharacterTrait(0)

@property
Expand Down
2 changes: 1 addition & 1 deletion Relationship_ren.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from enum import Enum

"""renpy
init python:
init -20 python:
"""


Expand Down

0 comments on commit 28fd1e5

Please sign in to comment.