-
Notifications
You must be signed in to change notification settings - Fork 85
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Typehint warnings #86
Changes from all commits
a17dc41
eada795
e7bfe6a
f709375
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ | |
from src.game_entities.building import Building | ||
from src.game_entities.character import Character | ||
from src.game_entities.chest import Chest | ||
from src.game_entities.consumable import Consumable | ||
from src.game_entities.destroyable import DamageKind, Destroyable | ||
from src.game_entities.door import Door | ||
from src.game_entities.effect import Effect | ||
|
@@ -252,7 +253,7 @@ def __init__( | |
|
||
# Storage of current selected entity | ||
self.selected_player: Optional[Player] = None | ||
self.selected_item: Optional[Item] = None | ||
self.selected_item: Optional[Equipment | Consumable] = None | ||
self.active_shop: Optional[Shop] = None | ||
|
||
self.quit_request: bool = False | ||
|
@@ -274,7 +275,6 @@ def __init__( | |
self.talk_sfx: Optional[pygame.mixer.Sound] = None | ||
self.gold_sfx: Optional[pygame.mixer.Sound] = None | ||
|
||
|
||
@property | ||
def diary_entries_text_element_set(self): | ||
""" | ||
|
@@ -483,7 +483,7 @@ def update_state(self) -> bool: | |
Verify if victory or defeat conditions are met. | ||
Handle next AI action if it's not player's turn. | ||
|
||
Return the whether the game should be ended or not. | ||
Return whether the game should be ended or not. | ||
""" | ||
if self.quit_request: | ||
return True | ||
|
@@ -738,7 +738,7 @@ def get_next_cases(self, position: Position) -> list[Optional[Entity]]: | |
return tiles_content | ||
|
||
def get_possible_moves( | ||
self, position: Position, max_moves: int | ||
self, position: tuple, max_moves: int | ||
) -> dict[Position, int]: | ||
""" | ||
Return all the possible moves with their distance from the starting position | ||
|
@@ -769,7 +769,7 @@ def get_possible_moves( | |
|
||
def get_possible_attacks( | ||
self, | ||
possible_moves: Sequence[tuple[int, int]], | ||
possible_moves: Sequence[Position], | ||
reach: Sequence[int], | ||
from_ally_side: bool, | ||
) -> set[tuple[float, float]]: | ||
|
@@ -781,7 +781,7 @@ def get_possible_attacks( | |
reach -- the reach of the attacking entity | ||
from_ally_side -- a boolean indicating whether this is a friendly attack or not | ||
""" | ||
tiles: list[tuple[float, float]] = [] | ||
tiles: list = [] | ||
|
||
entities = list(self.entities.breakables) | ||
if from_ally_side: | ||
|
@@ -828,7 +828,7 @@ def is_tile_available(self, tile: Position) -> bool: | |
|
||
return entity_on_tile is None | ||
|
||
def get_entity_on_tile(self, tile: Position) -> Optional[Entity]: | ||
def get_entity_on_tile(self, tile: Position) -> Optional[Entity, Destroyable]: | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think there was a downstream complaint by a function expecting a Destroyable. Hopefully this will be clearer when I roll back to a less ambitious PR. |
||
""" | ||
Return the entity that is on the given tile if there is any | ||
|
||
|
@@ -843,7 +843,7 @@ def get_entity_on_tile(self, tile: Position) -> Optional[Entity]: | |
return None | ||
|
||
def determine_path_to( | ||
self, destination_tile: Position, distance_for_tile: dict[tuple[int, int], int] | ||
self, destination_tile: Position, distance_for_tile: dict[tuple, int] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe it should be There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That makes sense, I think I made this change before I realized there was a Position class. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Trying it again, and it may be because Position is a Union with pygame.Vector2, which isn't hashable for the set function. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Indeed I remember something about it, can be annoying... |
||
) -> list[Position]: | ||
""" | ||
Return an ordered list of position that represent the path from one tile to another | ||
|
@@ -853,11 +853,11 @@ def determine_path_to( | |
distance -- the distance between the starting tile and the destination | ||
""" | ||
path: list[Position] = [destination_tile] | ||
current_tile: tuple[int, int] = tuple(destination_tile) | ||
current_tile: tuple = tuple(destination_tile) | ||
while distance_for_tile[current_tile] > 1: | ||
# Check for neighbour cases | ||
available_tiles: dict[tuple[int, int], int] = self.get_possible_moves( | ||
tuple(current_tile), 1 | ||
available_tiles: dict[tuple, int] = self.get_possible_moves( | ||
current_tile, 1 | ||
) | ||
for tile in available_tiles: | ||
if tile in distance_for_tile: | ||
|
@@ -877,7 +877,7 @@ def distance_between_all( | |
entity -- the entity for which the distance from all other entities should be computed | ||
all_other_entities -- all other entities for which the distance should be computed | ||
""" | ||
free_tiles_distance: dict[tuple[int, int], int] = self.get_possible_moves( | ||
free_tiles_distance: dict[Position, int] = self.get_possible_moves( | ||
tuple(entity.position), | ||
(self.map["width"] * self.map["height"]) // (TILE_SIZE * TILE_SIZE), | ||
) | ||
|
@@ -899,8 +899,8 @@ def open_chest(self, actor: Character, chest: Chest) -> None: | |
Open a chest and send its content to the given character | ||
|
||
Keyword arguments: | ||
actor -- the character opening the chest | ||
chest -- the chest that is being open | ||
actor -- the character performing the action | ||
chest -- the object that is being opened | ||
""" | ||
# Get object inside the chest | ||
item = chest.open() | ||
|
@@ -1142,7 +1142,7 @@ def interact( | |
elif isinstance(target, Character): | ||
pygame.mixer.Sound.play(self.talk_sfx) | ||
|
||
element_grid = target.talk(actor) | ||
element_grid = target.talk() | ||
self.menu_manager.open_menu( | ||
InfoBox( | ||
str(target), | ||
|
@@ -1195,7 +1195,6 @@ def duel( | |
self, | ||
attacker: Movable, | ||
target: Destroyable, | ||
attacker_allies: Sequence[Destroyable], | ||
target_allies: Sequence[Destroyable], | ||
kind: DamageKind, | ||
) -> None: | ||
|
@@ -1205,7 +1204,6 @@ def duel( | |
Keyword arguments: | ||
attacker -- the entity that is making the attack | ||
target -- the target of the attack | ||
attacker_allies -- the allies of the attacker | ||
target_allies -- the allies of the target | ||
kind -- the nature of the damage that would be dealt | ||
""" | ||
|
@@ -1328,15 +1326,15 @@ def process_entity_action(self, entity: Movable, is_ally: bool) -> None: | |
entity -- the entity for which the action should be computed | ||
is_ally -- a boolean indicating if the entity is an ally or not | ||
""" | ||
possible_moves: dict[tuple[int, int], int] = self.get_possible_moves( | ||
possible_moves: dict[Position, int] = self.get_possible_moves( | ||
tuple(entity.position), entity.max_moves | ||
) | ||
targets: Sequence[Movable] = ( | ||
self.entities.foes if is_ally else self.players + self.entities.allies | ||
) | ||
allies: Sequence[Movable] = ( | ||
self.players + self.entities.allies if is_ally else self.entities.foes | ||
) | ||
# allies: Sequence[Movable] = ( | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I assume it's something you planned to fix later on because it's still only a draft PR (I know), but I'm putting this comment as a reminder There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. allies doesn't actually get used by the duel function on line 1194. Seems like something that might get implemented in the future, so I didn't want to get rid of it entirely. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Nah feel free to remove not used stuff. We are using Git for a reason: if some later time we need these changes (because of a feature related to allies) then we could just get back what was removed by the commit. Commented out code is a code smell, and is harmless to remove when having a good versioning system tool. |
||
# self.players + self.entities.allies if is_ally else self.entities.foes | ||
# ) | ||
tile: Optional[Position] = entity.act( | ||
possible_moves, self.distance_between_all(entity, targets) | ||
) | ||
|
@@ -1349,8 +1347,8 @@ def process_entity_action(self, entity: Movable, is_ally: bool) -> None: | |
entity.set_move(path) | ||
else: | ||
# Entity choose to attack the entity on the tile | ||
entity_attacked = self.get_entity_on_tile(tile) | ||
self.duel(entity, entity_attacked, allies, targets, entity.attack_kind) | ||
entity_attacked: Destroyable = self.get_entity_on_tile(tile) | ||
self.duel(entity, entity_attacked, targets, entity.attack_kind) | ||
entity.end_turn() | ||
|
||
def interact_item_shop(self, item: Item, item_button: Button) -> None: | ||
|
@@ -2088,7 +2086,6 @@ def left_click(self, position: Position) -> None: | |
self.duel( | ||
self.selected_player, | ||
entity, | ||
self.players + self.entities.allies, | ||
self.entities.foes, | ||
self.selected_player.attack_kind, | ||
) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
feel like we are loosing some level of precision about the structure of position arg here
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This change doesn't make sense, must've been an overzealous mistake on my part.