Some .Net compatibility
This commit is contained in:
parent
bbe51c4cc7
commit
218fb0298f
|
@ -34,7 +34,8 @@ from NetUtils import Node, Endpoint, CLientStatus, NetworkItem, decode
|
|||
|
||||
colorama.init()
|
||||
lttp_console_names = frozenset(set(Items.item_table) | set(Items.item_name_groups) | set(Regions.lookup_name_to_id))
|
||||
|
||||
all_console_names = frozenset(set(network_data_package["lookup_any_location_id_to_name"].values()) |
|
||||
set(network_data_package["lookup_any_item_id_to_name"].values()))
|
||||
|
||||
class Client(Endpoint):
|
||||
version = Version(0, 0, 0)
|
||||
|
@ -533,7 +534,7 @@ def json_format_send_event(net_item: NetworkItem, receiving_player: int):
|
|||
return {"cmd": "PrintJSON", "data": parts, "type": "ItemSend",
|
||||
"receiving": receiving_player, "sending": net_item.player}
|
||||
|
||||
def get_intended_text(input_text: str, possible_answers: typing.Iterable[str]= lttp_console_names) -> typing.Tuple[str, bool, str]:
|
||||
def get_intended_text(input_text: str, possible_answers: typing.Iterable[str]= all_console_names) -> typing.Tuple[str, bool, str]:
|
||||
picks = fuzzy_process.extract(input_text, possible_answers, limit=2)
|
||||
if len(picks) > 1:
|
||||
dif = picks[0][1] - picks[1][1]
|
||||
|
|
13
NetUtils.py
13
NetUtils.py
|
@ -61,12 +61,23 @@ _encode = JSONEncoder(
|
|||
def encode(obj):
|
||||
return _encode(_scan_for_TypedTuples(obj))
|
||||
|
||||
def get_any_version(data: dict) -> Version:
|
||||
data = {key.lower(): value for key, value in data.items()} # .NET version classes have capitalized keys
|
||||
return Version(int(data["major"]), int(data["minor"]), int(data["build"]))
|
||||
|
||||
whitelist = {"NetworkPlayer": NetworkPlayer,
|
||||
"NetworkItem": NetworkItem,
|
||||
"Version": Version}
|
||||
}
|
||||
|
||||
custom_hooks = {
|
||||
"Version": get_any_version
|
||||
}
|
||||
|
||||
def _object_hook(o: typing.Any) -> typing.Any:
|
||||
if isinstance(o, dict):
|
||||
hook = custom_hooks.get(o.get("class", None), None)
|
||||
if hook:
|
||||
return hook(o)
|
||||
cls = whitelist.get(o.get("class", None), None)
|
||||
if cls:
|
||||
for key in tuple(o):
|
||||
|
|
Loading…
Reference in New Issue