| 
									
										
										
										
											2023-04-29 15:57:22 +02:00
										 |  |  | """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) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-10-15 04:51:52 +02:00
										 |  |  |     from worlds.subnautica.locations import Vector, location_table | 
					
						
							|  |  |  |     from worlds.subnautica.items import item_table, group_items, items_by_type | 
					
						
							| 
									
										
										
										
											2023-04-29 15:57:22 +02:00
										 |  |  |     from NetUtils import encode | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-25 22:57:15 +02:00
										 |  |  |     export_folder = os.path.join(new_home, "Subnautica Export") | 
					
						
							|  |  |  |     os.makedirs(export_folder, exist_ok=True) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     def in_export_folder(path: str) -> str: | 
					
						
							|  |  |  |         return os.path.join(export_folder, path) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-29 15:57:22 +02:00
										 |  |  |     payload = {location_id: location_data["position"] for location_id, location_data in location_table.items()} | 
					
						
							| 
									
										
										
										
											2023-05-25 22:57:15 +02:00
										 |  |  |     with open(in_export_folder("locations.json"), "w") as f: | 
					
						
							| 
									
										
										
										
											2023-04-29 15:57:22 +02:00
										 |  |  |         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"])], | 
					
						
							|  |  |  |     } | 
					
						
							| 
									
										
										
										
											2023-05-25 22:57:15 +02:00
										 |  |  |     with open(in_export_folder("logic.json"), "w") as f: | 
					
						
							| 
									
										
										
										
											2023-04-29 15:57:22 +02:00
										 |  |  |         json.dump(payload, f) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-25 22:57:15 +02:00
										 |  |  |     itemcount = sum(item_data.count for item_data in item_table.values()) | 
					
						
							| 
									
										
										
										
											2023-04-29 15:57:22 +02:00
										 |  |  |     assert itemcount == len(location_table), f"{itemcount} != {len(location_table)}" | 
					
						
							| 
									
										
										
										
											2023-05-25 22:57:15 +02:00
										 |  |  |     payload = {item_id: item_data.tech_type for item_id, item_data in item_table.items()} | 
					
						
							| 
									
										
										
										
											2023-04-29 15:57:22 +02:00
										 |  |  |     import json | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-25 22:57:15 +02:00
										 |  |  |     with open(in_export_folder("items.json"), "w") as f: | 
					
						
							| 
									
										
										
										
											2023-04-29 15:57:22 +02:00
										 |  |  |         json.dump(payload, f) | 
					
						
							| 
									
										
										
										
											2023-05-25 22:57:15 +02:00
										 |  |  | 
 | 
					
						
							|  |  |  |     with open(in_export_folder("group_items.json"), "w") as f: | 
					
						
							|  |  |  |         # encode to convert set to list | 
					
						
							| 
									
										
										
										
											2023-04-29 15:57:22 +02:00
										 |  |  |         f.write(encode(group_items)) | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-05-25 22:57:15 +02:00
										 |  |  |     with open(in_export_folder("item_types.json"), "w") as f: | 
					
						
							|  |  |  |         json.dump(items_by_type, f) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  |     print(f"Subnautica exports dumped to {in_export_folder('')}") |