| 
									
										
										
										
											2022-03-15 08:55:57 -04:00
										 |  |  |  |      | 
					
						
							|  |  |  |  | from typing import Any, List | 
					
						
							|  |  |  |  | import copy | 
					
						
							| 
									
										
										
										
											2023-04-08 16:52:34 -04:00
										 |  |  |  | from ..Text.Dialog import Dialog | 
					
						
							|  |  |  |  | from ..Text.Texts import openFile | 
					
						
							| 
									
										
										
										
											2022-08-15 10:48:13 -04:00
										 |  |  |  | from Utils import unsafe_parse_yaml | 
					
						
							| 
									
										
										
										
											2022-03-15 08:55:57 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  | class StringTable: | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     @staticmethod | 
					
						
							|  |  |  |  |     def ParseEntries(resource: str): | 
					
						
							| 
									
										
										
										
											2023-04-08 16:52:34 -04:00
										 |  |  |  |         with openFile(resource, 'rb') as f: | 
					
						
							| 
									
										
										
										
											2022-03-15 08:55:57 -04:00
										 |  |  |  |             yaml = str(f.read(), "utf-8") | 
					
						
							| 
									
										
										
										
											2022-08-15 10:48:13 -04:00
										 |  |  |  |         content = unsafe_parse_yaml(yaml) | 
					
						
							| 
									
										
										
										
											2022-03-15 08:55:57 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |         result = [] | 
					
						
							|  |  |  |  |         for entryValue in content: | 
					
						
							|  |  |  |  |             (key, value) = next(iter(entryValue.items())) | 
					
						
							|  |  |  |  |             if isinstance(value, List): | 
					
						
							|  |  |  |  |                 result.append((key, value)) | 
					
						
							|  |  |  |  |             elif isinstance(value, str): | 
					
						
							|  |  |  |  |                 result.append((key, Dialog.Compiled(value))) | 
					
						
							|  |  |  |  |             else: raise Exception(f"Did not expect an object of type {type(value)}") | 
					
						
							|  |  |  |  |         return result | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2023-04-08 16:52:34 -04:00
										 |  |  |  |     template = ParseEntries.__func__("smz3/TotalSMZ3/Text/Scripts/StringTable.yaml") | 
					
						
							| 
									
										
										
										
											2022-03-15 08:55:57 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     def __init__(self): | 
					
						
							|  |  |  |  |         self.entries = copy.deepcopy(StringTable.template) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     def SetSahasrahlaRevealText(self, text: str): | 
					
						
							|  |  |  |  |         self.SetText("sahasrahla_quest_information", text) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     def SetBombShopRevealText(self, text: str): | 
					
						
							|  |  |  |  |         self.SetText("bomb_shop", text) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     def SetBlindText(self, text: str): | 
					
						
							|  |  |  |  |         self.SetText("blind_by_the_light", text) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     def SetTavernManText(self, text: str): | 
					
						
							|  |  |  |  |         self.SetText("kakariko_tavern_fisherman", text) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     def SetGanonFirstPhaseText(self, text: str): | 
					
						
							|  |  |  |  |         self.SetText("ganon_fall_in", text) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     def SetGanonThirdPhaseText(self, text: str): | 
					
						
							|  |  |  |  |         self.SetText("ganon_phase_3", text) | 
					
						
							| 
									
										
										
										
											2022-08-15 10:48:13 -04:00
										 |  |  |  |         self.SetText("ganon_phase_3_no_silvers", text) | 
					
						
							|  |  |  |  |         self.SetText("ganon_phase_3_no_silvers_alt", text) | 
					
						
							| 
									
										
										
										
											2022-03-15 08:55:57 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     def SetTriforceRoomText(self, text: str): | 
					
						
							| 
									
										
										
										
											2022-08-15 10:48:13 -04:00
										 |  |  |  |         self.SetText("end_triforce", f"{{NOBORDER}}\n{text}") | 
					
						
							| 
									
										
										
										
											2022-03-15 08:55:57 -04:00
										 |  |  |  | 
 | 
					
						
							|  |  |  |  |     def SetPedestalText(self, text: str): | 
					
						
							|  |  |  |  |         self.SetText("mastersword_pedestal_translated", text) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     def SetEtherText(self, text: str): | 
					
						
							|  |  |  |  |         self.SetText("tablet_ether_book", text) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     def SetBombosText(self, text: str): | 
					
						
							|  |  |  |  |         self.SetText("tablet_bombos_book", text) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-08-15 10:48:13 -04:00
										 |  |  |  |     def SetTowerRequirementText(self, text: str): | 
					
						
							|  |  |  |  |         self.SetText("sign_ganons_tower", text) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     def SetGanonRequirementText(self, text: str): | 
					
						
							|  |  |  |  |         self.SetText("sign_ganon", text) | 
					
						
							|  |  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2022-03-15 08:55:57 -04:00
										 |  |  |  |     def SetText(self, name: str, text: str): | 
					
						
							|  |  |  |  |         count = 0 | 
					
						
							|  |  |  |  |         for key, value in self.entries: | 
					
						
							|  |  |  |  |             if (key == name): | 
					
						
							|  |  |  |  |                 index = count | 
					
						
							|  |  |  |  |                 break | 
					
						
							|  |  |  |  |             else: | 
					
						
							|  |  |  |  |                 count += 1 | 
					
						
							|  |  |  |  |         self.entries[index] = (name, Dialog.Compiled(text)) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     def GetPaddedBytes(self): | 
					
						
							|  |  |  |  |         return self.GetBytes(True) | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |     def GetBytes(self, pad = False): | 
					
						
							|  |  |  |  |         maxBytes = 0x7355 | 
					
						
							|  |  |  |  |         data = [] | 
					
						
							|  |  |  |  |         for entry in self.entries: | 
					
						
							|  |  |  |  |             data += entry[1] | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         if (len(data) > maxBytes): | 
					
						
							|  |  |  |  |             raise Exception(f"String Table exceeds 0x{maxBytes:X} bytes") | 
					
						
							|  |  |  |  | 
 | 
					
						
							|  |  |  |  |         if (pad and len(data) < maxBytes): | 
					
						
							|  |  |  |  |             data += [0xFF] * (maxBytes - len(data)) | 
					
						
							|  |  |  |  |         return data |