|
3 | 3 | import typing |
4 | 4 | import math |
5 | 5 | import threading |
| 6 | +import time |
| 7 | +import json |
| 8 | +import zipfile |
| 9 | +import codecs |
| 10 | +from io import BytesIO |
6 | 11 | # Print the original running script |
7 | 12 | original_file = os.path.basename(sys.argv[0]) |
8 | 13 | if not "DK64Client" in original_file: |
|
16 | 21 | from .Regions import all_locations, create_regions, connect_regions |
17 | 22 | from .Rules import set_rules |
18 | 23 | from worlds.AutoWorld import WebWorld, World |
19 | | - import Patch |
| 24 | + # import Patch |
20 | 25 | from .Logic import LogicVarHolder |
21 | 26 | from worlds.dk64.DK64R.randomizer.Spoiler import Spoiler |
22 | 27 | from worlds.dk64.DK64R.randomizer.Settings import Settings |
| 28 | + from worlds.dk64.DK64R.randomizer.Patching.ApplyRandomizer import patching_response |
| 29 | + from worlds.dk64.DK64R import version |
23 | 30 |
|
24 | 31 | class DK64Web(WebWorld): |
25 | 32 | theme = "jungle" |
@@ -122,15 +129,43 @@ def generate_output(self, output_directory: str): |
122 | 129 | self.logic_holder.spoiler.LocationList[dk64_location_id].PlaceItem(self.logic_holder.spoiler, DK64RItems.NoItem) |
123 | 130 | else: |
124 | 131 | print(f"Location {ap_location.name} not found in DK64 location table.") |
125 | | - |
126 | | - rompath = os.path.join(output_directory, f"{self.multiworld.get_out_file_name_base(self.player)}.sfc") |
| 132 | + patch_data, _ = patching_response(self.logic_holder.spoiler) |
| 133 | + self.logic_holder.spoiler.FlushAllExcessSpoilerData() |
| 134 | + patch_file = self.update_seed_results(patch_data, self.logic_holder.spoiler, self.player) |
| 135 | + rompath = os.path.join(output_directory, f"{self.multiworld.get_out_file_name_base(self.player)}.lanky") |
| 136 | + with open(rompath, "wb") as f: |
| 137 | + f.write(patch_file) |
127 | 138 | except: |
128 | 139 | raise |
129 | 140 | finally: |
130 | 141 | if os.path.exists(rompath): |
131 | 142 | os.unlink(rompath) |
132 | 143 | self.rom_name_available_event.set() # make sure threading continues and errors are collected |
133 | 144 |
|
| 145 | + def update_seed_results(self, patch, spoiler, player_id): |
| 146 | + """Update the seed results.""" |
| 147 | + |
| 148 | + timestamp = time.time() |
| 149 | + hash = spoiler.settings.seed_hash |
| 150 | + spoiler_log = json.loads(spoiler.json) |
| 151 | + spoiler_log["Generated Time"] = timestamp |
| 152 | + # Zip all the data into a single file. |
| 153 | + zip_data = BytesIO() |
| 154 | + with zipfile.ZipFile(zip_data, "w") as zip_file: |
| 155 | + # Write each variable to the zip file |
| 156 | + zip_file.writestr("patch", patch) |
| 157 | + zip_file.writestr("hash", str(hash)) |
| 158 | + zip_file.writestr("spoiler_log", str(json.dumps(spoiler_log))) |
| 159 | + zip_file.writestr("seed_id", str(spoiler.settings.seed_id)) |
| 160 | + zip_file.writestr("generated_time", str(timestamp)) |
| 161 | + zip_file.writestr("version", version) |
| 162 | + zip_file.writestr("seed_number", "archipelago-seed-" + str(player_id)) |
| 163 | + zip_data.seek(0) |
| 164 | + # Convert the zip to a string of base64 data |
| 165 | + zip_conv = codecs.encode(zip_data.getvalue(), "base64").decode() |
| 166 | + |
| 167 | + return zip_conv |
| 168 | + |
134 | 169 | def modify_multidata(self, multidata: dict): |
135 | 170 | pass |
136 | 171 |
|
|
0 commit comments