diff --git a/CharacterService_ren.py b/CharacterService_ren.py index 84f4203..e967bf2 100644 --- a/CharacterService_ren.py +++ b/CharacterService_ren.py @@ -1,14 +1,13 @@ from __future__ import annotations -from typing import Optional, TYPE_CHECKING +from typing import Optional +from game.characters.ICharacter_ren import ICharacter import renpy.exports as renpy from game.characters.Relationship_ren import Relationship from game.characters.Moods_ren import Moods -if TYPE_CHECKING: - from game.characters.NonPlayableCharacter_ren import NonPlayableCharacter - from game.characters.PlayableCharacters_ren import PlayableCharacter, mc +from game.characters.PlayableCharacters_ren import mc """renpy init python: @@ -18,7 +17,7 @@ class CharacterService: @staticmethod def get_relationship( - character: NonPlayableCharacter, target: Optional[PlayableCharacter] = None + character: ICharacter, target: Optional[ICharacter] = None ) -> Relationship: if target is None: target = mc @@ -26,13 +25,13 @@ def get_relationship( if not hasattr(character, "relationships"): character.relationships = {} - return character.relationships.setdefault(target.name, Relationship.FRIEND) + return character.relationships.setdefault(target, Relationship.FRIEND) @staticmethod def has_relationship( - character: NonPlayableCharacter, + character: ICharacter, relationship: Relationship, - target: Optional[PlayableCharacter] = None, + target: Optional[ICharacter] = None, ) -> bool: if target is None: target = mc @@ -41,9 +40,9 @@ def has_relationship( @staticmethod def set_relationship( - character: NonPlayableCharacter, + character: ICharacter, relationship: Relationship, - target: Optional[PlayableCharacter] = None, + target: Optional[ICharacter] = None, ) -> None: if target is None: target = mc @@ -55,35 +54,35 @@ def set_relationship( target.relationships = {} if ( - character.relationships.setdefault(target.name, Relationship.FRIEND) + character.relationships.setdefault(target, Relationship.FRIEND) == relationship ): return - character.relationships[target.name] = relationship - target.relationships[character.name] = relationship + character.relationships[target] = relationship + target.relationships[character] = relationship @staticmethod - def get_mood(character: NonPlayableCharacter) -> Moods: + def get_mood(character: ICharacter) -> Moods: return character.mood @staticmethod - def has_mood(character: NonPlayableCharacter, mood: Moods) -> bool: + def has_mood(character: ICharacter, 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: ICharacter, mood: Moods) -> None: if mood == character.mood: return character.mood = mood @staticmethod - def reset_mood(character: NonPlayableCharacter) -> None: + def reset_mood(character: ICharacter) -> None: character.mood = Moods.NORMAL @staticmethod - def add_mood(character: NonPlayableCharacter, mood: Moods) -> None: + def add_mood(character: ICharacter, mood: Moods) -> None: if mood == character.mood: return @@ -94,7 +93,7 @@ def add_mood(character: NonPlayableCharacter, mood: Moods) -> None: character.mood = character.mood | mood @staticmethod - def remove_mood(character: NonPlayableCharacter, mood: Moods) -> None: + def remove_mood(character: ICharacter, mood: Moods) -> None: character.mood = character.mood & ~mood @staticmethod @@ -112,7 +111,7 @@ def get_profile_pictures(character_name: str) -> list[str]: @staticmethod def is_girlfriend( - character: NonPlayableCharacter, target: Optional[PlayableCharacter] = None + character: ICharacter, target: Optional[ICharacter] = None ) -> bool: if target is None: target = mc @@ -122,54 +121,44 @@ def is_girlfriend( ) @staticmethod - def is_fwb( - character: NonPlayableCharacter, target: Optional[PlayableCharacter] = None - ) -> bool: + def is_fwb(character: ICharacter, target: Optional[ICharacter] = None) -> bool: if target is None: target = mc return CharacterService.has_relationship(character, Relationship.FWB, target) @staticmethod - def is_dating( - character: NonPlayableCharacter, target: Optional[PlayableCharacter] = None - ) -> bool: + def is_dating(character: ICharacter, target: Optional[ICharacter] = None) -> bool: if target is None: target = mc return CharacterService.has_relationship(character, Relationship.DATING, target) @staticmethod - def is_kissed( - character: NonPlayableCharacter, target: Optional[PlayableCharacter] = None - ) -> bool: + def is_kissed(character: ICharacter, target: Optional[ICharacter] = None) -> bool: if target is None: target = mc return CharacterService.has_relationship(character, Relationship.KISSED, target) @staticmethod - def is_friend( - character: NonPlayableCharacter, target: Optional[PlayableCharacter] = None - ) -> bool: + def is_friend(character: ICharacter, target: Optional[ICharacter] = None) -> bool: if target is None: target = mc return CharacterService.has_relationship(character, Relationship.FRIEND, target) @staticmethod - def is_ex( - character: NonPlayableCharacter, target: Optional[PlayableCharacter] = None - ) -> bool: + def is_ex(character: ICharacter, target: Optional[ICharacter] = None) -> bool: if target is None: target = mc return CharacterService.has_relationship(character, Relationship.EX, target) @staticmethod - def is_mad(character: NonPlayableCharacter) -> bool: + def is_mad(character: ICharacter) -> bool: return CharacterService.has_mood(character, Moods.MAD) @staticmethod - def is_threatened(character: NonPlayableCharacter) -> bool: + def is_threatened(character: ICharacter) -> bool: return CharacterService.has_mood(character, Moods.THREATENED) diff --git a/ICharacter_ren.py b/ICharacter_ren.py new file mode 100644 index 0000000..991286f --- /dev/null +++ b/ICharacter_ren.py @@ -0,0 +1,14 @@ +from __future__ import annotations +from abc import ABC +from game.characters.Moods_ren import Moods + +from game.characters.Relationship_ren import Relationship + +"""renpy +init python: +""" + + +class ICharacter(ABC): + relationships: dict[ICharacter, Relationship] + mood: Moods diff --git a/NonPlayableCharacter_ren.py b/NonPlayableCharacter_ren.py index d6add15..b268679 100644 --- a/NonPlayableCharacter_ren.py +++ b/NonPlayableCharacter_ren.py @@ -2,6 +2,7 @@ from dataclasses import dataclass, field from game.characters.CharacterService_ren import CharacterService +from game.characters.ICharacter_ren import ICharacter from game.characters.Moods_ren import Moods from game.characters.Relationship_ren import Relationship from game.phone.Message_ren import Message @@ -12,11 +13,11 @@ @dataclass -class NonPlayableCharacter: +class NonPlayableCharacter(ICharacter): name: str username: str = "" - relationships: dict[str, Relationship] = field(default_factory=dict) + relationships: dict[ICharacter, Relationship] = field(default_factory=dict) mood: Moods = Moods.NORMAL profile_pictures: list[str] = field(default_factory=list) diff --git a/PlayableCharacters_ren.py b/PlayableCharacters_ren.py index c0043f2..34add7a 100644 --- a/PlayableCharacters_ren.py +++ b/PlayableCharacters_ren.py @@ -1,6 +1,7 @@ from __future__ import annotations from dataclasses import dataclass, field from typing import Optional, TYPE_CHECKING +from game.characters.ICharacter_ren import ICharacter import renpy.exports as renpy @@ -19,14 +20,14 @@ @dataclass -class PlayableCharacter: +class PlayableCharacter(ICharacter): name: str = "" username: str = "" profile_pictures: list[str] = field(default_factory=list) money: int = 0 inventory: list[str] = field(default_factory=list) detective: Optional[Detective] = None - relationships: dict[str, Relationship] = field(default_factory=dict) + relationships: dict[ICharacter, Relationship] = field(default_factory=dict) frat: Frat = Frat.WOLVES daddy_name: str = "Daddy" @@ -47,6 +48,14 @@ def __hash__(self) -> int: def profile_picture(self) -> str: return self.profile_pictures[0] + @property + def girlfriends(self) -> list[ICharacter]: + return [ + npc + for npc in self.relationships + if self.relationships[npc] == Relationship.GIRLFRIEND + ] + # @property # def fighter(self): # return self._fighter