diff --git a/NetUtils.py b/NetUtils.py index a9618506..64a778c5 100644 --- a/NetUtils.py +++ b/NetUtils.py @@ -10,6 +10,14 @@ import websockets from Utils import ByValue, Version +class HintStatus(enum.IntEnum): + HINT_FOUND = 0 + HINT_UNSPECIFIED = 1 + HINT_NO_PRIORITY = 10 + HINT_AVOID = 20 + HINT_PRIORITY = 30 + + class JSONMessagePart(typing.TypedDict, total=False): text: str # optional @@ -19,6 +27,8 @@ class JSONMessagePart(typing.TypedDict, total=False): player: int # if type == item indicates item flags flags: int + # if type == hint_status + hint_status: HintStatus class ClientStatus(ByValue, enum.IntEnum): @@ -29,14 +39,6 @@ class ClientStatus(ByValue, enum.IntEnum): CLIENT_GOAL = 30 -class HintStatus(enum.IntEnum): - HINT_FOUND = 0 - HINT_UNSPECIFIED = 1 - HINT_NO_PRIORITY = 10 - HINT_AVOID = 20 - HINT_PRIORITY = 30 - - class SlotType(ByValue, enum.IntFlag): spectator = 0b00 player = 0b01 @@ -192,6 +194,7 @@ class JSONTypes(str, enum.Enum): location_name = "location_name" location_id = "location_id" entrance_name = "entrance_name" + hint_status = "hint_status" class JSONtoTextParser(metaclass=HandlerMeta): @@ -273,6 +276,10 @@ class JSONtoTextParser(metaclass=HandlerMeta): node["color"] = 'blue' return self._handle_color(node) + def _handle_hint_status(self, node: JSONMessagePart): + node["color"] = status_colors.get(node["hint_status"], "red") + return self._handle_color(node) + class RawJSONtoTextParser(JSONtoTextParser): def _handle_color(self, node: JSONMessagePart): @@ -319,6 +326,13 @@ status_colors: typing.Dict[HintStatus, str] = { HintStatus.HINT_AVOID: "salmon", HintStatus.HINT_PRIORITY: "plum", } + + +def add_json_hint_status(parts: list, hint_status: HintStatus, text: typing.Optional[str] = None, **kwargs): + parts.append({"text": text if text != None else status_names.get(hint_status, "(unknown)"), + "hint_status": hint_status, "type": JSONTypes.hint_status, **kwargs}) + + class Hint(typing.NamedTuple): receiving_player: int finding_player: int @@ -363,8 +377,7 @@ class Hint(typing.NamedTuple): else: add_json_text(parts, "'s World") add_json_text(parts, ". ") - add_json_text(parts, status_names.get(self.status, "(unknown)"), type="color", - color=status_colors.get(self.status, "red")) + add_json_hint_status(parts, self.status) return {"cmd": "PrintJSON", "data": parts, "type": "Hint", "receiving": self.receiving_player, diff --git a/docs/network protocol.md b/docs/network protocol.md index 4331cf97..2ad8d4c4 100644 --- a/docs/network protocol.md +++ b/docs/network protocol.md @@ -554,6 +554,7 @@ class JSONMessagePart(TypedDict): color: Optional[str] # only available if type is a color flags: Optional[int] # only available if type is an item_id or item_name player: Optional[int] # only available if type is either item or location + hint_status: Optional[HintStatus] # only available if type is hint_status ``` `type` is used to denote the intent of the message part. This can be used to indicate special information which may be rendered differently depending on client. How these types are displayed in Archipelago's ALttP client is not the end-all be-all. Other clients may choose to interpret and display these messages differently. @@ -569,6 +570,7 @@ Possible values for `type` include: | location_id | Location ID, should be resolved to Location Name | | location_name | Location Name, not currently used over network, but supported by reference Clients. | | entrance_name | Entrance Name. No ID mapping exists. | +| hint_status | The [HintStatus](#HintStatus) of the hint. Both `text` and `hint_status` are given. | | color | Regular text that should be colored. Only `type` that will contain `color` data. |