MCPcopy Create free account
hub / github.com/GRAnimated/MinecraftLCE / LOCFile

Class LOCFile

tools/parse_languages_loc.py:110–216  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

108used_names = {}
109
110class LOCFile:
111 version: ctypes.c_uint
112 language_count = ctypes.c_uint
113 key_table: LOCKeyTable
114 language_list: LOCLanguageList
115 language_table: LOCLanguageTable
116
117 def read(self, reader: Reader):
118 self.version = reader.read_uint()
119 self.language_count = reader.read_uint()
120 self.key_table = LOCKeyTable()
121 self.key_table.read(reader)
122
123 self.language_list = LOCLanguageList()
124 self.language_list.read(reader, self.language_count)
125
126 self.language_table = LOCLanguageTable()
127 self.language_table.read(reader, self.language_count)
128
129 # Takes a string and makes a valid variable name for it
130 def createNameFromString(self, string: str):
131 final_str = ""
132
133 words = re.findall(r"[A-Za-z0-9]+", string)
134
135 # this name is very long, lets try to shorten it a bit
136 if len(string) > 50:
137 words = words[0:8]
138
139 for i in range(len(words)):
140 words[i] = words[i].capitalize()
141
142 base_name = "".join(words) or "Unnamed" # if the string is empty
143
144 # place an underscore behind numbers at the start of a string
145 if len(base_name) > 0 and base_name[0].isnumeric():
146 base_name = "_" + base_name
147
148 if base_name not in used_names:
149 used_names[base_name] = [string]
150 return base_name
151
152 existing_list = used_names[base_name]
153
154 first_words = re.findall(r"[A-Za-z0-9]+", existing_list[0])
155 new_words = re.findall(r"[A-Za-z0-9]+", string)
156
157 diff = [w.capitalize() for w in new_words if w not in first_words]
158
159 # find the first 5 words that are different
160 if diff:
161 name = f"{base_name}{''.join(diff[:5])}"
162 else:
163 name = f"{base_name}_{len(existing_list)}"
164
165 used_names[base_name].append(string) # to count duplicates
166
167 suffix_count = 1

Callers 1

mainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected