From b1c5456d189c30014611e9a07a387807cfe0fa90 Mon Sep 17 00:00:00 2001 From: Fabian Dill Date: Sat, 29 Apr 2023 15:57:22 +0200 Subject: [PATCH] Subnautica: move mod exports to own module --- worlds/subnautica/Exports.py | 65 ++++++++++++++++++++++++++++++++++ worlds/subnautica/Items.py | 13 ------- worlds/subnautica/Locations.py | 37 ------------------- 3 files changed, 65 insertions(+), 50 deletions(-) create mode 100644 worlds/subnautica/Exports.py diff --git a/worlds/subnautica/Exports.py b/worlds/subnautica/Exports.py new file mode 100644 index 000000000000..1a3675176b3f --- /dev/null +++ b/worlds/subnautica/Exports.py @@ -0,0 +1,65 @@ +"""Runnable module that exports data needed by the mod/client.""" + +if __name__ == "__main__": + import json + import math + import sys + import os + + # makes this module runnable from its world folder. + sys.path.remove(os.path.dirname(__file__)) + new_home = os.path.normpath(os.path.join(os.path.dirname(__file__), os.pardir, os.pardir)) + os.chdir(new_home) + sys.path.append(new_home) + + from worlds.subnautica.Locations import Vector, location_table + from worlds.subnautica.Items import item_table, group_items + from NetUtils import encode + + payload = {location_id: location_data["position"] for location_id, location_data in location_table.items()} + with open("locations.json", "w") as f: + json.dump(payload, f) + + # copy-paste from Rules + def is_radiated(x: float, y: float, z: float) -> bool: + aurora_dist = math.sqrt((x - 1038.0) ** 2 + y ** 2 + (z - -163.1) ** 2) + return aurora_dist < 950 + # end of copy-paste + + + def radiated(pos: Vector): + return is_radiated(pos["x"], pos["y"], pos["z"]) + + + def far_away(pos: Vector): + return (pos["x"] ** 2 + pos["z"] ** 2) > (800 ** 2) + + + payload = { + # "LaserCutter" in Subnautica ID + "761": [location_id for location_id, location_data + in location_table.items() if location_data["need_laser_cutter"]], + # PropulsionCannon in Subnautica ID + "757": [location_id for location_id, location_data + in location_table.items() if location_data.get("need_propulsion_cannon", False)], + # Radiation Suit in Subnautica ID + "519": [location_id for location_id, location_data + in location_table.items() if radiated(location_data["position"])], + # SeaGlide in Subnautica ID + "751": [location_id for location_id, location_data + in location_table.items() if far_away(location_data["position"])], + } + with open("logic.json", "w") as f: + json.dump(payload, f) + + itemcount = sum(item_data["count"] for item_data in item_table.values()) + assert itemcount == len(location_table), f"{itemcount} != {len(location_table)}" + payload = {item_id: item_data["tech_type"] for item_id, item_data in item_table.items()} + import json + + with open("items.json", "w") as f: + json.dump(payload, f) + with open("group_items.json", "w") as f: + f.write(encode(group_items)) + + print(f"Subnautica exports dumped to {new_home}") diff --git a/worlds/subnautica/Items.py b/worlds/subnautica/Items.py index 600e1d1996a3..9529e0bafc59 100644 --- a/worlds/subnautica/Items.py +++ b/worlds/subnautica/Items.py @@ -388,16 +388,3 @@ class ItemDict(TypedDict): 35069, 35070, 35073, 35074}, 35101: {35049, 35050, 35051, 35071, 35072, 35074} } - -if False: # turn to True to export for Subnautica mod - from .Locations import location_table - from NetUtils import encode - itemcount = sum(item_data["count"] for item_data in item_table.values()) - assert itemcount == len(location_table), f"{itemcount} != {len(location_table)}" - payload = {item_id: item_data["tech_type"] for item_id, item_data in item_table.items()} - import json - - with open("items.json", "w") as f: - json.dump(payload, f) - with open("group_items.json", "w") as f: - f.write(encode(group_items)) diff --git a/worlds/subnautica/Locations.py b/worlds/subnautica/Locations.py index e0a33966f088..6222cd0ed646 100644 --- a/worlds/subnautica/Locations.py +++ b/worlds/subnautica/Locations.py @@ -571,40 +571,3 @@ class LocationDict(TypedDict, total=False): 'need_laser_cutter': False, 'position': {'x': 83.2, 'y': -276.4, 'z': -345.5}}, } - -if False: # turn to True to export for Subnautica mod - import json - import math - - payload = {location_id: location_data["position"] for location_id, location_data in location_table.items()} - with open("locations.json", "w") as f: - json.dump(payload, f) - - # copy-paste from Rules - def is_radiated(x: float, y: float, z: float) -> bool: - aurora_dist = math.sqrt((x - 1038.0) ** 2 + y ** 2 + (z - -163.1) ** 2) - return aurora_dist < 950 - # end of copy-paste - - def radiated(pos: Vector): - return is_radiated(pos["x"], pos["y"], pos["z"]) - - def far_away(pos: Vector): - return (pos["x"] ** 2 + pos["z"] ** 2) > (800 ** 2) - - payload = { - # "LaserCutter" in Subnautica ID - "761": [location_id for location_id, location_data - in location_table.items() if location_data["need_laser_cutter"]], - # PropulsionCannon in Subnautica ID - "757": [location_id for location_id, location_data - in location_table.items() if location_data.get("need_propulsion_cannon", False)], - # Radiation Suit in Subnautica ID - "519": [location_id for location_id, location_data - in location_table.items() if radiated(location_data["position"])], - # SeaGlide in Subnautica ID - "751": [location_id for location_id, location_data - in location_table.items() if far_away(location_data["position"])], - } - with open("logic.json", "w") as f: - json.dump(payload, f)