Skip to content

Commit

Permalink
Add new character files and update existing classes
Browse files Browse the repository at this point in the history
  • Loading branch information
KiloOscarSix committed Jan 26, 2024
1 parent 2427690 commit 2b8299f
Show file tree
Hide file tree
Showing 20 changed files with 520 additions and 378 deletions.
36 changes: 34 additions & 2 deletions CharacterProtocol_ren.py
Original file line number Diff line number Diff line change
@@ -1,22 +1,54 @@
from abc import abstractmethod
from typing import Protocol
from typing import Protocol, runtime_checkable
from game.characters.Relationship_ren import Relationship

from renpy import config

chloe: "CharacterProtocol"

"""renpy
init python:
"""


@runtime_checkable
class CharacterProtocol(Protocol):
relationships: dict["CharacterProtocol", Relationship]

def __hash__(self) -> int:
return hash(self.name)

def __repr__(self) -> str:
return f"{self.__class__.__name__}({self.name})"

def __str__(self) -> str:
return self.name

def __eq__(self, __value: object) -> bool:
if not isinstance(__value, CharacterProtocol):
return NotImplemented

return self.name == __value.name

@property
@abstractmethod
def name(self) -> str:
...

@property
@abstractmethod
def username(self) -> str:
def profile_pictures(self) -> tuple[str, ...]:
...

@property
def profile_picture(self) -> str:
try:
return self.profile_pictures[0]
except (AttributeError, IndexError):
if config.developer:
raise AttributeError(f"{self.name} has no profile pictures.")
return chloe.profile_picture

# _profile_pictures: list[str] = field(default_factory=list)
# _profile_picture: str = ""
# money: int = 0
Expand Down
98 changes: 57 additions & 41 deletions CharacterService_ren.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from typing import Iterable, Optional, Union
from game.characters.ICharacter_ren import ICharacter
from game.compat.py_compat_ren import CustomCharacter, MainCharacter
from typing import Iterable, Optional
from game.characters.CharacterProtocol_ren import CharacterProtocol
from game.characters.NonPlayableCharacter_ren import NonPlayableCharacter

from renpy import store
import renpy.exports as renpy
Expand All @@ -17,22 +17,18 @@

class CharacterService:
@staticmethod
def get_user(
character: Union["ICharacter", "CustomCharacter", "MainCharacter"]
) -> ICharacter:
def get_user(character: CharacterProtocol) -> CharacterProtocol:
try:
if isinstance(character, PlayableCharacter):
user = mc
return mc
else:
user = getattr(store, character.name.lower().replace(" ", "_"))
return getattr(store, character.name.lower().replace(" ", "_"))
except AttributeError:
raise AttributeError(f"{character} is not a valid character.")

return user

@staticmethod
def get_relationship(
character: ICharacter, target: Optional[ICharacter] = None
character: CharacterProtocol, target: Optional[CharacterProtocol] = None
) -> Relationship:
if target is None:
target = mc
Expand All @@ -44,9 +40,9 @@ def get_relationship(

@staticmethod
def has_relationship(
character: ICharacter,
character: CharacterProtocol,
relationship: Relationship,
target: Optional[ICharacter] = None,
target: Optional[CharacterProtocol] = None,
) -> bool:
if target is None:
target = mc
Expand All @@ -55,9 +51,9 @@ def has_relationship(

@staticmethod
def set_relationship(
character: ICharacter,
character: CharacterProtocol,
relationship: Relationship,
target: Optional[ICharacter] = None,
target: Optional[CharacterProtocol] = None,
) -> None:
if target is None:
target = mc
Expand All @@ -81,26 +77,26 @@ def set_relationship(
target.relationships[character] = relationship

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

@staticmethod
def has_mood(character: ICharacter, 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: ICharacter, mood: Moods) -> None:
def set_mood(character: NonPlayableCharacter, mood: Moods) -> None:
if mood == character.mood:
return

character.mood = mood

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

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

Expand All @@ -111,25 +107,27 @@ def add_mood(character: ICharacter, mood: Moods) -> None:
character.mood = character.mood | mood

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

@staticmethod
def get_profile_pictures(character_name: str) -> list[str]:
def get_profile_pictures(character_name: str) -> tuple[str, ...]:
directory: str = f"characters/images/{character_name.lower()}"

try:
return [file for file in renpy.list_files() if file.startswith(directory)] # type: ignore
return tuple(
file for file in renpy.list_files() if file.startswith(directory)
)
except OSError:
return [
return tuple(
file
for file in renpy.list_files() # type: ignore
if file.startswith("characters/images/chloe") # type: ignore
]
for file in renpy.list_files()
if file.startswith("characters/images/chloe")
)

@staticmethod
def is_exclusive_girlfriend(
character: ICharacter, target: Optional[ICharacter] = None
character: CharacterProtocol, target: Optional[CharacterProtocol] = None
) -> bool:
if target is None:
target = mc
Expand All @@ -142,7 +140,7 @@ def is_exclusive_girlfriend(

@staticmethod
def is_girlfriend(
character: ICharacter, target: Optional[ICharacter] = None
character: CharacterProtocol, target: Optional[CharacterProtocol] = None
) -> bool:
if target is None:
target = mc
Expand All @@ -153,7 +151,8 @@ def is_girlfriend(

@staticmethod
def is_girlfriends(
characters: Iterable[ICharacter], target: Optional[ICharacter] = None
characters: Iterable[CharacterProtocol],
target: Optional[CharacterProtocol] = None,
) -> bool:
if target is None:
target = mc
Expand All @@ -165,7 +164,7 @@ def is_girlfriends(

@staticmethod
def is_exclusive(
character: ICharacter, target: Optional[ICharacter] = None
character: CharacterProtocol, target: Optional[CharacterProtocol] = None
) -> bool:
if target is None:
target = mc
Expand All @@ -177,14 +176,19 @@ def is_exclusive(
)

@staticmethod
def is_fwb(character: ICharacter, target: Optional[ICharacter] = None) -> bool:
def is_fwb(
character: CharacterProtocol, target: Optional[CharacterProtocol] = None
) -> bool:
if target is None:
target = mc

return CharacterService.has_relationship(character, Relationship.FWB, target)

@staticmethod
def is_fwbs(characters: Iterable[ICharacter], target: Optional[ICharacter] = None):
def is_fwbs(
characters: Iterable[CharacterProtocol],
target: Optional[CharacterProtocol] = None,
) -> bool:
if target is None:
target = mc

Expand All @@ -193,29 +197,36 @@ def is_fwbs(characters: Iterable[ICharacter], target: Optional[ICharacter] = Non
)

@staticmethod
def is_dating(character: ICharacter, target: Optional[ICharacter] = None) -> bool:
def is_dating(
character: CharacterProtocol, target: Optional[CharacterProtocol] = None
) -> bool:
if target is None:
target = mc

return CharacterService.has_relationship(character, Relationship.DATING, target)

@staticmethod
def is_kissed(character: ICharacter, target: Optional[ICharacter] = None) -> bool:
def is_kissed(
character: CharacterProtocol, target: Optional[CharacterProtocol] = None
) -> bool:
if target is None:
target = mc

return CharacterService.has_relationship(character, Relationship.KISSED, target)

@staticmethod
def is_friend(character: ICharacter, target: Optional[ICharacter] = None) -> bool:
def is_friend(
character: CharacterProtocol, target: Optional[CharacterProtocol] = None
) -> bool:
if target is None:
target = mc

return CharacterService.has_relationship(character, Relationship.FRIEND, target)

@staticmethod
def is_friends(
characters: Iterable[ICharacter], target: Optional[ICharacter] = None
characters: Iterable[CharacterProtocol],
target: Optional[CharacterProtocol] = None,
) -> bool:
if target is None:
target = mc
Expand All @@ -225,14 +236,19 @@ def is_friends(
)

@staticmethod
def is_ex(character: ICharacter, target: Optional[ICharacter] = None) -> bool:
def is_ex(
character: CharacterProtocol, target: Optional[CharacterProtocol] = None
) -> bool:
if target is None:
target = mc

return CharacterService.has_relationship(character, Relationship.EX, target)

@staticmethod
def is_exes(characters: Iterable[ICharacter], target: Optional[ICharacter] = None):
def is_exes(
characters: Iterable[CharacterProtocol],
target: Optional[CharacterProtocol] = None,
):
if target is None:
target = mc

Expand All @@ -241,9 +257,9 @@ def is_exes(characters: Iterable[ICharacter], target: Optional[ICharacter] = Non
)

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

@staticmethod
def is_threatened(character: ICharacter) -> bool:
def is_threatened(character: NonPlayableCharacter) -> bool:
return CharacterService.has_mood(character, Moods.THREATENED)
2 changes: 1 addition & 1 deletion Frat_ren.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,5 +11,5 @@ class Frat(Enum):
WOLVES = enum.auto()

@classmethod
def _missing_(cls, value):
def _missing_(cls, value: object) -> "Frat":
return cls.WOLVES
Loading

0 comments on commit 2b8299f

Please sign in to comment.