Skip to content

Commit

Permalink
Add Speaker class and update NonPlayableCharacter and PlayableCharact…
Browse files Browse the repository at this point in the history
…er classes
  • Loading branch information
KiloOscarSix committed Jan 26, 2024
1 parent 93f103f commit dd4eca3
Show file tree
Hide file tree
Showing 6 changed files with 147 additions and 163 deletions.
92 changes: 0 additions & 92 deletions CharacterProtocol_ren.py

This file was deleted.

60 changes: 23 additions & 37 deletions CharacterService_ren.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from typing import Iterable, Optional
from game.characters.CharacterProtocol_ren import CharacterProtocol
from game.characters.character_ren import Character
from game.characters.NonPlayableCharacter_ren import NonPlayableCharacter

from renpy import store
Expand All @@ -17,7 +17,7 @@

class CharacterService:
@staticmethod
def get_user(character: CharacterProtocol) -> CharacterProtocol:
def get_user(character: Character) -> Character:
try:
if isinstance(character, PlayableCharacter):
return mc
Expand All @@ -28,7 +28,7 @@ def get_user(character: CharacterProtocol) -> CharacterProtocol:

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

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

@staticmethod
def set_relationship(
character: CharacterProtocol,
character: Character,
relationship: Relationship,
target: Optional[CharacterProtocol] = None,
target: Optional[Character] = None,
) -> None:
if target is None:
target = mc
Expand Down Expand Up @@ -127,7 +127,7 @@ def get_profile_pictures(character_name: str) -> tuple[str, ...]:

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

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

Expand All @@ -151,8 +149,8 @@ def is_girlfriend(

@staticmethod
def is_girlfriends(
characters: Iterable[CharacterProtocol],
target: Optional[CharacterProtocol] = None,
characters: Iterable[Character],
target: Optional[Character] = None,
) -> bool:
if target is None:
target = mc
Expand All @@ -163,9 +161,7 @@ def is_girlfriends(
)

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

Expand All @@ -176,18 +172,16 @@ def is_exclusive(
)

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

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

@staticmethod
def is_fwbs(
characters: Iterable[CharacterProtocol],
target: Optional[CharacterProtocol] = None,
characters: Iterable[Character],
target: Optional[Character] = None,
) -> bool:
if target is None:
target = mc
Expand All @@ -197,36 +191,30 @@ def is_fwbs(
)

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

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

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

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

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

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

@staticmethod
def is_friends(
characters: Iterable[CharacterProtocol],
target: Optional[CharacterProtocol] = None,
characters: Iterable[Character],
target: Optional[Character] = None,
) -> bool:
if target is None:
target = mc
Expand All @@ -236,18 +224,16 @@ def is_friends(
)

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

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

@staticmethod
def is_exes(
characters: Iterable[CharacterProtocol],
target: Optional[CharacterProtocol] = None,
characters: Iterable[Character],
target: Optional[Character] = None,
):
if target is None:
target = mc
Expand Down
103 changes: 81 additions & 22 deletions Character_ren.py
Original file line number Diff line number Diff line change
@@ -1,33 +1,92 @@
from typing import Optional
from renpy.character import ADVCharacter
from abc import abstractmethod
from typing import Protocol, runtime_checkable
from game.characters.Relationship_ren import Relationship

from game.characters.Gender_ren import Gender
from game.characters.CharacterColors_ren import CharacterColor
from renpy import config

chloe: "Character"

"""renpy
init python:
"""


class Character(ADVCharacter):
def __init__(
self, name: Optional[str], kind: None = None, **properties: object
) -> None:
properties.setdefault("who_outlines", [(2, "#000")])
properties.setdefault("what_outlines", [(2, "#000")])
@runtime_checkable
class Character(Protocol):
relationships: dict["Character", 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, Character):
return NotImplemented

return self.name == __value.name

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

@property
@abstractmethod
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
# _inventory: list["Item"] = field(default_factory=list)
# detective: Optional["Detective"] = None
# relationships: dict["ICharacter", "Relationship"] = field(default_factory=dict)
# frat: Frat = Frat.WOLVES
# daddy_name: str = "Daddy"

# @property
# def name(self) -> str: # type: ignore
# return store.name

# @property
# def username(self) -> str:
# try:
# if self._username is None:
# return self.name
# return self._username
# except AttributeError:
# return self.name

# name: str = ""
# _username: str = ""

# relationships: dict[ICharacter, Relationship] = field(default_factory=dict)
# mood: Moods = Moods.NORMAL

if "gender" in properties and "who_color" not in properties:
gender: object = properties.pop("gender")
# _profile_pictures: list[str] = field(default_factory=list)
# points: int = 0
# has_had_sex_with_mc: bool = False

if gender == Gender.MALE:
who_color: str = CharacterColor.get_masculine_color()
elif gender == Gender.FEMALE:
who_color = CharacterColor.get_feminine_color()
elif gender == Gender.ANY:
who_color = CharacterColor.get_any_color()
else:
raise ValueError('Incorrect value for "gender" property')
# is_competitive: bool = False
# vindictive_characters: tuple["ICharacter", ...] = ()
# is_talkative: bool = False

properties["who_color"] = who_color
# _pending_text_messages: list[Message] = field(default_factory=list)
# _text_messages: list[Message] = field(default_factory=list)

super().__init__(name, kind, **properties)
# _pending_simplr_messages: list[Message] = field(default_factory=list)
# _simplr_messages: list[Message] = field(default_factory=list)
Loading

0 comments on commit dd4eca3

Please sign in to comment.