Add "help" trigger and help() static method to trigger objects
Signed-off-by: Alek Ratzloff <alekratz@gmail.com>
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import abc
|
||||
import re
|
||||
from typing import Match, Pattern, TYPE_CHECKING
|
||||
from agame.util import search_item_name
|
||||
from agame.util import search_item_name, trigger_help_builder
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from agame.game import Game
|
||||
@@ -22,6 +22,7 @@ if TYPE_CHECKING:
|
||||
# (put down)/drop [a[n]/the] x
|
||||
__all__ = (
|
||||
"Trigger",
|
||||
"HelpTrigger",
|
||||
"GetTrigger",
|
||||
"UseTrigger",
|
||||
"PutTrigger",
|
||||
@@ -30,6 +31,7 @@ __all__ = (
|
||||
"OpenTrigger",
|
||||
"CloseTrigger",
|
||||
"GoTrigger",
|
||||
"HELP",
|
||||
"GET",
|
||||
"USE",
|
||||
"PUT",
|
||||
@@ -39,6 +41,7 @@ __all__ = (
|
||||
"CLOSE",
|
||||
"GO",
|
||||
)
|
||||
HELP = "help"
|
||||
GET = "get"
|
||||
USE = "use"
|
||||
PUT = "put"
|
||||
@@ -55,11 +58,34 @@ class Trigger(metaclass=abc.ABCMeta):
|
||||
def pattern() -> Pattern:
|
||||
pass
|
||||
|
||||
@staticmethod
|
||||
@abc.abstractmethod
|
||||
def help() -> str:
|
||||
pass
|
||||
|
||||
@abc.abstractmethod
|
||||
def trigger(self, game: "Game", match: Match):
|
||||
pass
|
||||
|
||||
|
||||
class HelpTrigger(Trigger):
|
||||
@staticmethod
|
||||
def pattern() -> Pattern:
|
||||
return re.compile("help", re.IGNORECASE)
|
||||
|
||||
@staticmethod
|
||||
def help() -> str:
|
||||
return trigger_help_builder("help")
|
||||
|
||||
def trigger(self, game: "Game", _match: Match):
|
||||
game.say("In this game, short commands are usually the best.")
|
||||
game.say()
|
||||
game.say("These are the available actions that are recognized:")
|
||||
game.say()
|
||||
for trigger in game.database.triggers:
|
||||
game.say(trigger.help())
|
||||
|
||||
|
||||
class GetTrigger(Trigger):
|
||||
@staticmethod
|
||||
def pattern() -> Pattern:
|
||||
@@ -71,6 +97,12 @@ class GetTrigger(Trigger):
|
||||
re.IGNORECASE | re.VERBOSE,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def help() -> str:
|
||||
return trigger_help_builder(
|
||||
("get", "take", "grab", "pick up", "pickup"), "item"
|
||||
)
|
||||
|
||||
def trigger(self, game: "Game", match: Match):
|
||||
item_name = match["item"]
|
||||
if not item_name:
|
||||
@@ -101,6 +133,10 @@ class UseTrigger(Trigger):
|
||||
re.IGNORECASE | re.VERBOSE,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def help() -> str:
|
||||
return trigger_help_builder("use", ("item", "[with/on target]"))
|
||||
|
||||
def trigger(self, game: "Game", match: Match):
|
||||
item_name = match["item"]
|
||||
if not item_name:
|
||||
@@ -152,6 +188,10 @@ class PutTrigger(Trigger):
|
||||
re.IGNORECASE | re.VERBOSE,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def help() -> str:
|
||||
return trigger_help_builder("put", ("item", "[on/in target]"))
|
||||
|
||||
def trigger(self, game: "Game", match: Match):
|
||||
item_name = match["item"]
|
||||
|
||||
@@ -167,6 +207,10 @@ class LookTrigger(Trigger):
|
||||
re.IGNORECASE | re.VERBOSE,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def help() -> str:
|
||||
return trigger_help_builder("look", args=["[at]", "item"])
|
||||
|
||||
def trigger(self, game: "Game", match: Match):
|
||||
item_name = match["item"]
|
||||
if not item_name:
|
||||
@@ -193,6 +237,10 @@ class ReadTrigger(Trigger):
|
||||
re.IGNORECASE | re.VERBOSE,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def help() -> str:
|
||||
return trigger_help_builder("read", "item")
|
||||
|
||||
def trigger(self, game: "Game", match: Match):
|
||||
item_name = match["item"]
|
||||
if not item_name:
|
||||
@@ -219,6 +267,10 @@ class OpenTrigger(Trigger):
|
||||
re.IGNORECASE | re.VERBOSE,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def help() -> str:
|
||||
return trigger_help_builder("open", "item")
|
||||
|
||||
def trigger(self, game: "Game", match: Match):
|
||||
item_name = match["item"]
|
||||
if not item_name:
|
||||
@@ -243,6 +295,10 @@ class CloseTrigger(Trigger):
|
||||
re.IGNORECASE | re.VERBOSE,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def help() -> str:
|
||||
return trigger_help_builder("close", "item")
|
||||
|
||||
def trigger(self, game: "Game", match: Match):
|
||||
item_name = match["item"]
|
||||
if not item_name:
|
||||
@@ -267,6 +323,10 @@ class GoTrigger(Trigger):
|
||||
re.IGNORECASE | re.VERBOSE,
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def help() -> str:
|
||||
return trigger_help_builder(["go", "go to", "goto", "leave", "exit"], "target")
|
||||
|
||||
def trigger(self, game: "Game", match: Match):
|
||||
item_name = match["item"]
|
||||
if not item_name:
|
||||
|
||||
Reference in New Issue
Block a user