Remove some redundancy
This commit is contained in:
parent
a796e947d1
commit
50ddf8cc01
@ -1,6 +1,6 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
from typing import Optional, Tuple, TYPE_CHECKING
|
from typing import Optional, Tuple, TYPE_CHECKING, overload
|
||||||
|
|
||||||
if TYPE_CHECKING:
|
if TYPE_CHECKING:
|
||||||
from engine import Engine
|
from engine import Engine
|
||||||
@ -17,6 +17,7 @@ class Action:
|
|||||||
"""Return the engine this action belongs to."""
|
"""Return the engine this action belongs to."""
|
||||||
return self.entity.gamemap.engine
|
return self.entity.gamemap.engine
|
||||||
|
|
||||||
|
@overload
|
||||||
def perform(self) -> None:
|
def perform(self) -> None:
|
||||||
"""Perform this action with the objects needed to determine its scope.
|
"""Perform this action with the objects needed to determine its scope.
|
||||||
|
|
||||||
@ -26,7 +27,6 @@ class Action:
|
|||||||
|
|
||||||
This method must be overwritten by Action subclasses.
|
This method must be overwritten by Action subclasses.
|
||||||
"""
|
"""
|
||||||
raise NotImplementedError()
|
|
||||||
|
|
||||||
|
|
||||||
class EscapeAction(Action):
|
class EscapeAction(Action):
|
||||||
@ -51,9 +51,6 @@ class ActionWithDirection(Action):
|
|||||||
"""Return the blocking entity at this action's destination."""
|
"""Return the blocking entity at this action's destination."""
|
||||||
return self.engine.game_map.get_blocking_entity_at_location(*self.dest_xy)
|
return self.engine.game_map.get_blocking_entity_at_location(*self.dest_xy)
|
||||||
|
|
||||||
def perform(self) -> None:
|
|
||||||
raise NotImplementedError()
|
|
||||||
|
|
||||||
|
|
||||||
class MeleeAction(ActionWithDirection):
|
class MeleeAction(ActionWithDirection):
|
||||||
def perform(self) -> None:
|
def perform(self) -> None:
|
||||||
|
@ -10,9 +10,6 @@ from components.base_component import BaseComponent
|
|||||||
|
|
||||||
|
|
||||||
class BaseAI(Action, BaseComponent):
|
class BaseAI(Action, BaseComponent):
|
||||||
def perform(self) -> None:
|
|
||||||
raise NotImplementedError()
|
|
||||||
|
|
||||||
def get_path_to(self, dest_x: int, dest_y: int) -> List[Tuple[int, int]]:
|
def get_path_to(self, dest_x: int, dest_y: int) -> List[Tuple[int, int]]:
|
||||||
"""Compute and return a path to the target position.
|
"""Compute and return a path to the target position.
|
||||||
|
|
||||||
@ -40,4 +37,4 @@ class BaseAI(Action, BaseComponent):
|
|||||||
path: List[List[int]] = pathfinder.path_to((dest_x, dest_y))[1:].tolist()
|
path: List[List[int]] = pathfinder.path_to((dest_x, dest_y))[1:].tolist()
|
||||||
|
|
||||||
# Convert from List[List[int]] to List[Tuple[int, int]].
|
# Convert from List[List[int]] to List[Tuple[int, int]].
|
||||||
return [(index[0], index[1]) for index in path]
|
return [(index[0], index[1]) for index in path]
|
||||||
|
@ -26,9 +26,6 @@ class EventHandler(tcod.event.EventDispatch[Action]):
|
|||||||
self.engine.handle_enemy_turns()
|
self.engine.handle_enemy_turns()
|
||||||
self.engine.update_fov()
|
self.engine.update_fov()
|
||||||
|
|
||||||
def ev_quit(self, event: tcod.event.Quit) -> Optional[Action]:
|
|
||||||
raise SystemExit()
|
|
||||||
|
|
||||||
def ev_keydown(self, event: tcod.event.KeyDown) -> Optional[Action]:
|
def ev_keydown(self, event: tcod.event.KeyDown) -> Optional[Action]:
|
||||||
action: Optional[Action] = None
|
action: Optional[Action] = None
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user