| 
									
										
										
										
											2020-12-04 23:56:21 +01:00
										 |  |  | from Gui import * | 
					
						
							|  |  |  | import threading | 
					
						
							| 
									
										
										
										
											2020-08-31 23:17:33 -04:00
										 |  |  | 
 | 
					
						
							|  |  |  | # Target directories | 
					
						
							| 
									
										
										
										
											2020-12-04 23:56:21 +01:00
										 |  |  | input_dir = local_path("data", "sprites", "alttpr") | 
					
						
							|  |  |  | output_dir = local_path("WebHostLib", "static", "static") | 
					
						
							| 
									
										
										
										
											2020-08-31 23:17:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-04 23:56:21 +01:00
										 |  |  | #update sprites through gui.py's functions | 
					
						
							|  |  |  | done = threading.Event() | 
					
						
							|  |  |  | top = Tk() | 
					
						
							|  |  |  | top.withdraw() | 
					
						
							|  |  |  | BackgroundTaskProgress(top, update_sprites, "Updating Sprites", lambda succesful, resultmessage: done.set()) | 
					
						
							|  |  |  | while not done.isSet(): | 
					
						
							|  |  |  |     top.update() | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | print("Done updating sprites") | 
					
						
							| 
									
										
										
										
											2020-08-31 23:17:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-05 23:25:26 +01:00
										 |  |  | spriteData = [] | 
					
						
							| 
									
										
										
										
											2020-08-31 23:17:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-04 23:56:21 +01:00
										 |  |  | for file in os.listdir(input_dir): | 
					
						
							|  |  |  |     sprite = Sprite(os.path.join(input_dir, file)) | 
					
						
							| 
									
										
										
										
											2020-08-31 23:17:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-04 23:56:21 +01:00
										 |  |  |     if not sprite.name: | 
					
						
							|  |  |  |         print("Warning:",file,"has no name.") | 
					
						
							|  |  |  |         sprite.name = file.split(".", 1)[0] | 
					
						
							| 
									
										
										
										
											2020-08-31 23:17:33 -04:00
										 |  |  | 
 | 
					
						
							| 
									
										
										
										
											2020-12-04 23:56:21 +01:00
										 |  |  |     if sprite.valid: | 
					
						
							|  |  |  |         with open(os.path.join(output_dir, "sprites", f"{sprite.name}.gif"), 'wb') as image: | 
					
						
							|  |  |  |             image.write(get_image_for_sprite(sprite, True)) | 
					
						
							| 
									
										
										
										
											2020-12-05 23:25:26 +01:00
										 |  |  |         spriteData.append({"file": file, "author": sprite.author_name, "name": sprite.name}) | 
					
						
							| 
									
										
										
										
											2020-12-04 23:56:21 +01:00
										 |  |  |     else: | 
					
						
							|  |  |  |         print(file, "dropped, as it has no valid sprite data.") | 
					
						
							| 
									
										
										
										
											2020-12-05 23:25:26 +01:00
										 |  |  | spriteData.sort(key=lambda entry: entry["name"]) | 
					
						
							| 
									
										
										
										
											2020-12-04 23:56:21 +01:00
										 |  |  | with open(f'{output_dir}/spriteData.json', 'w') as file: | 
					
						
							| 
									
										
										
										
											2020-12-06 17:12:41 +01:00
										 |  |  |     json.dump({"sprites": spriteData}, file, indent=1) |