Skip to content

Commit

Permalink
Factorio: support new colors in-game
Browse files Browse the repository at this point in the history
Various: cleanup and comments
  • Loading branch information
Berserker66 committed Jan 18, 2022
1 parent c9fa49d commit 0282070
Show file tree
Hide file tree
Showing 7 changed files with 39 additions and 38 deletions.
4 changes: 4 additions & 0 deletions BaseClasses.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
8 changes: 2 additions & 6 deletions FactorioClient.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down
20 changes: 10 additions & 10 deletions Generate.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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"]
Expand All @@ -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

Expand Down
7 changes: 2 additions & 5 deletions Main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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]:
Expand Down
8 changes: 5 additions & 3 deletions MultiServer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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

Expand All @@ -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

Expand Down Expand Up @@ -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)


Expand Down Expand Up @@ -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

Expand Down
16 changes: 16 additions & 0 deletions NetUtils.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
14 changes: 0 additions & 14 deletions kvui.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(";")
Expand Down

0 comments on commit 0282070

Please sign in to comment.