Last active
September 7, 2019 10:04
-
-
Save Davnit/5b31a451a0994e310b89ee4c9bd604f6 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import base64 | |
import json | |
import zlib | |
directions = { | |
0: "N", | |
1: "NE", | |
2: "E", | |
3: "SE", | |
4: "S", | |
5: "SW", | |
6: "W", | |
7: "NW" | |
} | |
bp_str = None | |
ori = "x" | |
bp_str = bp_str or input("Enter the blueprint string: ") | |
ori = ori or input("Enter flip direction (H/V): ") | |
version = bp_str[0] | |
bp_str = bp_str[1:] | |
if version != "0": | |
raise Exception("Unsupported version: %s" % version) | |
data = base64.b64decode(bp_str) | |
data = zlib.decompress(data) | |
data = json.loads(data) | |
print(json.dumps(data, indent=4)) | |
if "blueprint" not in data: | |
raise Exception("Invalid blueprint.") | |
if ori.lower() in ["x", "h"]: | |
ori = "x" | |
elif ori.lower() in ["y", "v"]: | |
ori = "y" | |
else: | |
raise Exception("Invalid flip direction.") | |
entities = data["blueprint"].get("entities", []) | |
for entity in entities: | |
if "position" in entity: | |
entity["position"][ori] = entity["position"][ori] * -1 | |
rotation = entity.get("direction", 0) | |
if entity.get("name") == "storage-tank" and ori == "x": | |
pass | |
if entity.get("name") == "curved-rail": | |
switches = { | |
"x": [(0, 1), (3, 6), (5, 4), (2, 7)], | |
"y": [(0, 5), (3, 2), (6, 7), (1, 4)] | |
} | |
for sw in switches.get(ori): | |
if rotation == sw[0]: | |
rotation = sw[1] | |
elif rotation == sw[1]: | |
rotation = sw[0] | |
else: | |
continue | |
break | |
else: | |
if rotation not in ([0, 4] if ori == "x" emlse [2, 6]): | |
rotation = (rotation + 4) % 8 | |
entity["direction"] = rotation | |
data = json.dumps(data).encode() | |
data = zlib.compress(data) | |
data = base64.b64encode(data) | |
print("Output: 0%s" % data.decode()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment