diff --git a/BaseClasses.py b/BaseClasses.py index 13e74d131cac..446b1055beba 100644 --- a/BaseClasses.py +++ b/BaseClasses.py @@ -1012,6 +1012,10 @@ def hint_text(self): def pedestal_hint_text(self): return getattr(self, "_pedestal_hint_text", self.name.replace("_", " ").replace("-", " ")) + @property + def flags(self) -> int: + return self.advancement + (self.never_exclude << 1) + (self.trap << 2) + def __eq__(self, other): return self.name == other.name and self.player == other.player diff --git a/FactorioClient.py b/FactorioClient.py index bff2b81a637a..d3378796290d 100644 --- a/FactorioClient.py +++ b/FactorioClient.py @@ -333,12 +333,8 @@ class FactorioJSONtoTextParser(JSONtoTextParser): def _handle_color(self, node: JSONMessagePart): colors = node["color"].split(";") for color in colors: - if color in {"red", "green", "blue", "orange", "yellow", "pink", "purple", "white", "black", "gray", - "brown", "cyan", "acid"}: - node["text"] = f"[color={color}]{node['text']}[/color]" - return self._handle_text(node) - elif color == "magenta": - node["text"] = f"[color=pink]{node['text']}[/color]" + if color in self.color_codes: + node["text"] = f"[color=#{self.color_codes[color]}]{node['text']}[/color]" return self._handle_text(node) return self._handle_text(node) diff --git a/Generate.py b/Generate.py index 45902dc2ef63..ea2862c2e109 100644 --- a/Generate.py +++ b/Generate.py @@ -61,8 +61,8 @@ def mystery_argparse(): return args, options -def get_seed_name(random): - return f"{random.randint(0, pow(10, seeddigits) - 1)}".zfill(seeddigits) +def get_seed_name(random_source) -> str: + return f"{random_source.randint(0, pow(10, seeddigits) - 1)}".zfill(seeddigits) def main(args=None, callback=ERmain): @@ -220,11 +220,11 @@ def read_weights_yaml(path): return parse_yaml(yaml) -def interpret_on_off(value): +def interpret_on_off(value) -> bool: return {"on": True, "off": False}.get(value, value) -def convert_to_on_off(value): +def convert_to_on_off(value) -> str: return {True: "on", False: "off"}.get(value, value) @@ -527,10 +527,10 @@ def add_plando_item(item: str, location: str): options = weights.get("plando_items", []) for placement in options: - if roll_percentage(get_choice_legacy("percentage", placement, 100)): - from_pool = get_choice_legacy("from_pool", placement, PlandoItem._field_defaults["from_pool"]) - location_world = get_choice_legacy("world", placement, PlandoItem._field_defaults["world"]) - force = str(get_choice_legacy("force", placement, PlandoItem._field_defaults["force"])).lower() + if roll_percentage(get_choice("percentage", placement, 100)): + from_pool = get_choice("from_pool", placement, PlandoItem._field_defaults["from_pool"]) + location_world = get_choice("world", placement, PlandoItem._field_defaults["world"]) + force = str(get_choice("force", placement, PlandoItem._field_defaults["force"])).lower() if "items" in placement and "locations" in placement: items = placement["items"] locations = placement["locations"] @@ -546,8 +546,8 @@ def add_plando_item(item: str, location: str): for item, location in zip(items, locations): add_plando_item(item, location) else: - item = get_choice_legacy("item", placement, get_choice_legacy("items", placement)) - location = get_choice_legacy("location", placement) + item = get_choice("item", placement, get_choice("items", placement)) + location = get_choice("location", placement) add_plando_item(item, location) return plando_items diff --git a/Main.py b/Main.py index 02f67e7cf903..53855b7e70db 100644 --- a/Main.py +++ b/Main.py @@ -266,12 +266,9 @@ def write_multidata(): if world.worlds[slot].sending_visible: sending_visible_players.add(slot) - def get_item_flags(item: Item) -> int: - return item.advancement + (item.never_exclude << 1) + (item.trap << 2) - def precollect_hint(location): hint = NetUtils.Hint(location.item.player, location.player, location.address, - location.item.code, False, "", get_item_flags(location.item)) + location.item.code, False, "", location.item.flags) precollected_hints[location.player].add(hint) precollected_hints[location.item.player].add(hint) @@ -281,7 +278,7 @@ def precollect_hint(location): # item code None should be event, location.address should then also be None assert location.item.code is not None locations_data[location.player][location.address] = \ - location.item.code, location.item.player, get_item_flags(location.item) + location.item.code, location.item.player, location.item.flags if location.player in sending_visible_players: precollect_hint(location) elif location.name in world.start_location_hints[location.player]: diff --git a/MultiServer.py b/MultiServer.py index 9f166d5b6690..04b2bcfcc764 100644 --- a/MultiServer.py +++ b/MultiServer.py @@ -665,6 +665,7 @@ def register_location_checks(ctx: Context, team: int, slot: int, locations: typi if len(ctx.locations[slot][location]) == 3: item_id, target_player, flags = ctx.locations[slot][location] else: + # TODO: remove around version 0.2.5 item_id, target_player = ctx.locations[slot][location] flags = 0 @@ -702,6 +703,7 @@ def collect_hints(ctx: Context, team: int, slot: int, item: str) -> typing.List[ if len(result) == 3: item_id, receiving_player, item_flags = result else: + # TODO: remove around version 0.2.5 item_id, receiving_player = result item_flags = 0 @@ -720,6 +722,7 @@ def collect_hints_location(ctx: Context, team: int, slot: int, location: str) -> if len(result) == 3: item_id, receiving_player, item_flags = result else: + # TODO: remove around version 0.2.5 item_id, receiving_player = result item_flags = 0 @@ -1204,9 +1207,7 @@ def _cmd_hint(self, item_or_location: str = "") -> bool: @mark_raw def _cmd_hint_location(self, location: str = "") -> bool: """Use !hint_location {location_name}, - for example !hint_location atomic-bomb to get a spoiler peek for that location. - (In the case of factorio, or any other game where item names and location names are identical, - this command must be used explicitly.)""" + for example !hint_location atomic-bomb to get a spoiler peek for that location.""" return self.get_hints(location, True) @@ -1361,6 +1362,7 @@ async def process_client_cmd(ctx: Context, client: Client, args: dict): if len(ctx.locations[client.slot][location]) == 3: target_item, target_player, flags = ctx.locations[client.slot][location] else: + # TODO: remove around version 0.2.5 target_item, target_player = ctx.locations[client.slot][location] flags = 0 diff --git a/NetUtils.py b/NetUtils.py index b01ef58d97db..820ee0ed856e 100644 --- a/NetUtils.py +++ b/NetUtils.py @@ -164,6 +164,22 @@ class JSONTypes(str, enum.Enum): class JSONtoTextParser(metaclass=HandlerMeta): + + color_codes = { + # not exact color names, close enough but decent looking + "black": "000000", + "red": "EE0000", + "green": "00FF7F", + "yellow": "FAFAD2", + "blue": "6495ED", + "magenta": "EE00EE", + "cyan": "00EEEE", + "slateblue": "6D8BE8", + "plum": "AF99EF", + "salmon": "FA8072", + "white": "FFFFFF" + } + def __init__(self, ctx): self.ctx = ctx diff --git a/kvui.py b/kvui.py index f403b8263656..b1f5a9a9b47d 100644 --- a/kvui.py +++ b/kvui.py @@ -411,20 +411,6 @@ def handle_exception(self, inst): class KivyJSONtoTextParser(JSONtoTextParser): - color_codes = { - # not exact color names, close enough but decent looking - "black": "000000", - "red": "EE0000", - "green": "00FF7F", - "yellow": "FAFAD2", - "blue": "6495ED", - "magenta": "EE00EE", - "cyan": "00EEEE", - "slateblue": "6D8BE8", - "plum": "AF99EF", - "salmon": "FA8072", - "white": "FFFFFF" - } def _handle_color(self, node: JSONMessagePart): colors = node["color"].split(";")