Remove QuitAction and ActionWithActor!

Move quit event handling to the interface and flatten the Action class
hierarchy. There are no longer any actions that don't take an Actor. This has
the happy side effect of resolving some pylint errors too. :)
This commit is contained in:
Eryn Wells 2023-03-11 01:09:53 -08:00
parent 02ed3d1e4a
commit 327cc90b2e
6 changed files with 24 additions and 43 deletions

View file

@ -12,6 +12,10 @@ if TYPE_CHECKING:
class Action:
'''An action with no specific actor'''
def __init__(self, actor: Actor):
super().__init__()
self.actor = actor
# pylint: disable=unused-argument
def perform(self, engine: 'Engine') -> ActionResult:
'''Perform this action.
@ -42,17 +46,3 @@ class Action:
def __repr__(self):
return f'{self.__class__.__name__}()'
class ActionWithActor(Action):
'''An action that assigned to an actor'''
def __init__(self, actor: Actor):
super().__init__()
self.actor = actor
def __str__(self) -> str:
return f'{self.__class__.__name__} for {self.actor!s}'
def __repr__(self):
return f'{self.__class__.__name__}({self.actor!r})'

View file

@ -11,7 +11,6 @@ Action : Base class of all actions
BumpAction
WalkAction
MeleeAction
ExitAction
WaitAction
'''
@ -22,21 +21,14 @@ from .. import items
from .. import log
from ..geometry import Vector
from ..object import Actor, Item
from .action import Action, ActionWithActor
from .action import Action
from .result import ActionResult
if TYPE_CHECKING:
from ..engine import Engine
class ExitAction(Action):
'''Exit the game.'''
def perform(self, engine: 'Engine') -> ActionResult:
raise SystemExit()
class MoveAction(ActionWithActor):
class MoveAction(Action):
'''An abstract Action that requires a direction to complete.'''
def __init__(self, actor: Actor, direction: Vector):
@ -157,7 +149,7 @@ class MeleeAction(MoveAction):
return self.success()
class WaitAction(ActionWithActor):
class WaitAction(Action):
'''Wait a turn'''
def perform(self, engine: 'Engine') -> ActionResult:
@ -174,7 +166,7 @@ class WaitAction(ActionWithActor):
return self.success()
class DieAction(ActionWithActor):
class DieAction(Action):
'''Kill an Actor'''
def perform(self, engine: 'Engine') -> ActionResult:
@ -193,7 +185,7 @@ class DieAction(ActionWithActor):
return self.success()
class DropItemAction(ActionWithActor):
class DropItemAction(Action):
'''Drop an item'''
def __init__(self, actor: 'Actor', item: 'Item'):
@ -205,7 +197,7 @@ class DropItemAction(ActionWithActor):
return self.success()
class HealAction(ActionWithActor):
class HealAction(Action):
'''Heal a target actor some number of hit points'''
def __init__(self, actor: 'Actor', hit_points_to_recover: int):