Network: unify flags docs and implementation
This commit is contained in:
parent
4841926f83
commit
5c1d2b3393
|
@ -710,7 +710,8 @@ def collect_hints(ctx: Context, team: int, slot: int, item: str) -> typing.List[
|
||||||
if receiving_player == slot and item_id == seeked_item_id:
|
if receiving_player == slot and item_id == seeked_item_id:
|
||||||
found = location_id in ctx.location_checks[team, finding_player]
|
found = location_id in ctx.location_checks[team, finding_player]
|
||||||
entrance = ctx.er_hint_data.get(finding_player, {}).get(location_id, "")
|
entrance = ctx.er_hint_data.get(finding_player, {}).get(location_id, "")
|
||||||
hints.append(NetUtils.Hint(receiving_player, finding_player, location_id, item_id, found, entrance, item_flags))
|
hints.append(NetUtils.Hint(receiving_player, finding_player, location_id, item_id, found, entrance,
|
||||||
|
item_flags))
|
||||||
|
|
||||||
return hints
|
return hints
|
||||||
|
|
||||||
|
|
|
@ -17,6 +17,8 @@ class JSONMessagePart(typing.TypedDict, total=False):
|
||||||
color: str
|
color: str
|
||||||
# owning player for location/item
|
# owning player for location/item
|
||||||
player: int
|
player: int
|
||||||
|
# if type == item indicates item flags
|
||||||
|
flags: int
|
||||||
|
|
||||||
|
|
||||||
class ClientStatus(enum.IntEnum):
|
class ClientStatus(enum.IntEnum):
|
||||||
|
@ -211,7 +213,7 @@ class JSONtoTextParser(metaclass=HandlerMeta):
|
||||||
return self._handle_color(node)
|
return self._handle_color(node)
|
||||||
|
|
||||||
def _handle_item_name(self, node: JSONMessagePart):
|
def _handle_item_name(self, node: JSONMessagePart):
|
||||||
flags = node.get("item_flags", 0)
|
flags = node.get("flags", 0)
|
||||||
if flags == 0:
|
if flags == 0:
|
||||||
node["color"] = 'cyan'
|
node["color"] = 'cyan'
|
||||||
elif flags & 1 << 0: # advancement
|
elif flags & 1 << 0: # advancement
|
||||||
|
@ -266,7 +268,7 @@ def add_json_text(parts: list, text: typing.Any, **kwargs) -> None:
|
||||||
|
|
||||||
|
|
||||||
def add_json_item(parts: list, item_id: int, player: int = 0, item_flags: int = 0, **kwargs) -> None:
|
def add_json_item(parts: list, item_id: int, player: int = 0, item_flags: int = 0, **kwargs) -> None:
|
||||||
parts.append({"text": str(item_id), "player": player, "item_flags": item_flags, "type": JSONTypes.item_id, **kwargs})
|
parts.append({"text": str(item_id), "player": player, "flags": item_flags, "type": JSONTypes.item_id, **kwargs})
|
||||||
|
|
||||||
|
|
||||||
def add_json_location(parts: list, item_id: int, player: int = 0, **kwargs) -> None:
|
def add_json_location(parts: list, item_id: int, player: int = 0, **kwargs) -> None:
|
||||||
|
@ -287,7 +289,8 @@ class Hint(typing.NamedTuple):
|
||||||
return self
|
return self
|
||||||
found = self.location in ctx.location_checks[team, self.finding_player]
|
found = self.location in ctx.location_checks[team, self.finding_player]
|
||||||
if found:
|
if found:
|
||||||
return Hint(self.receiving_player, self.finding_player, self.location, self.item, found, self.entrance, self.item_flags)
|
return Hint(self.receiving_player, self.finding_player, self.location, self.item, found, self.entrance,
|
||||||
|
self.item_flags)
|
||||||
return self
|
return self
|
||||||
|
|
||||||
def __hash__(self):
|
def __hash__(self):
|
||||||
|
|
|
@ -342,10 +342,10 @@ In JSON this may look like:
|
||||||
Flags are bit flags:
|
Flags are bit flags:
|
||||||
| Flag | Meaning |
|
| Flag | Meaning |
|
||||||
| ----- | ----- |
|
| ----- | ----- |
|
||||||
| 0 | Indicates, indicates the item had no specail use in generation |
|
| 0 | Nothing special about this item |
|
||||||
| 1 << 0 | If set, indicates the item can unlock advancement |
|
| 0b100 | If set, indicates the item can unlock logical advancement |
|
||||||
| 1 << 1 | If set, indicates the item is important but not necessarily unlocks advancement |
|
| 0b100 | If set, indicates the item is important but not in a way that unlocks advancement |
|
||||||
| 1 << 2 | If set, indicates the item is an trap |
|
| 0b100 | If set, indicates the item is a trap |
|
||||||
|
|
||||||
### JSONMessagePart
|
### JSONMessagePart
|
||||||
Message nodes sent along with [PrintJSON](#PrintJSON) packet to be reconstructed into a legible message. The nodes are intended to be read in the order they are listed in the packet.
|
Message nodes sent along with [PrintJSON](#PrintJSON) packet to be reconstructed into a legible message. The nodes are intended to be read in the order they are listed in the packet.
|
||||||
|
@ -355,8 +355,8 @@ from typing import TypedDict, Optional
|
||||||
class JSONMessagePart(TypedDict):
|
class JSONMessagePart(TypedDict):
|
||||||
type: Optional[str]
|
type: Optional[str]
|
||||||
text: Optional[str]
|
text: Optional[str]
|
||||||
color: Optional[str] # only available if type is an color
|
color: Optional[str] # only available if type is a color
|
||||||
item_flags: Optional[int] # only available if type is an item
|
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
|
player: Optional[int] # only available if type is either item or location
|
||||||
```
|
```
|
||||||
|
|
||||||
|
@ -400,7 +400,7 @@ Color options:
|
||||||
|
|
||||||
`text` is the content of the message part to be displayed.
|
`text` is the content of the message part to be displayed.
|
||||||
`player` marks owning player id for location/item,
|
`player` marks owning player id for location/item,
|
||||||
`item_flags` contains the [NetworkItem](#NetworkItem) flags that belong to the item
|
`flags` contains the [NetworkItem](#NetworkItem) flags that belong to the item
|
||||||
|
|
||||||
### Client States
|
### Client States
|
||||||
An enumeration containing the possible client states that may be used to inform the server in [StatusUpdate](#StatusUpdate).
|
An enumeration containing the possible client states that may be used to inform the server in [StatusUpdate](#StatusUpdate).
|
||||||
|
|
Loading…
Reference in New Issue