def find_attribute(ent_data, target_attribute, end_location="\n"): attribute = TextModificationLib.find_between_two_values( ent_data, f'"{target_attribute}"', f"{end_location}") if attribute is not None: attribute = TextModificationLib.remove(attribute, '"') else: attribute = '' return attribute
def parse_brush_entity(entity_data): ent_brush_data = TextModificationLib.split(entity_data, '{') ent_brush_data[0] = '{' + ent_brush_data[0] + '}\n' ent_brush_data[1] = '{' + ent_brush_data[1] + '\n' for cut in ent_brush_data: if cut != ent_brush_data[0]: ent_brush_data[1] = ent_brush_data[1] + cut ent_brush_data[1] = TextModificationLib.replace(ent_brush_data[1], '}\n}', '}') return ent_brush_data
def detect_attributes(ent_data): attributes_dict = {} i = 0 attributes_list = TextModificationLib.split(ent_data, '"\n') for each in attributes_list: attributes_list[i] = each + '"' attribute_name = TextModificationLib.find_between_two_values( each, '"', '"') attribute = find_attribute( each, TextModificationLib.find_between_two_values(each, '"', '"')) attributes_dict[attribute_name] = attribute.strip() i += 1 return attributes_dict
def read_side(lines, mute=True): if not mute: print("Extracting Data") plane_dict = {} internal_side_id = 0 counter = 0 for line in lines: if "(" in line and ")" in line: internal_side_id += 1 value = TextModificationLib.remove(line, "[") value = TextModificationLib.remove(value, "]") value = TextModificationLib.remove(value, "( ") value = TextModificationLib.replace(value, " ", ' ') value = TextModificationLib.split(value, " ) ") other_values = TextModificationLib.split(value[3], ' ') for item in other_values: if item == ' ': other_values.remove(' ') if not len(other_values) < 7: plane_dict[counter] = { "points": [ TextModificationLib.add_to_both_sides( value[0], "(", ") "), TextModificationLib.add_to_both_sides( value[1], "(", ") "), TextModificationLib.add_to_both_sides( value[2], "(", ") ") ], "Material": other_values[0], 'x_off': other_values[1], 'y_off': other_values[2], 'rot_angle': other_values[3], 'x_scale': other_values[4], 'y_scale': other_values[5], 'ID': internal_side_id } counter += 1 else: pass else: internal_side_id = 0 return plane_dict
def prep_brushes(world_spawn_item): brushes = List_Dict_Array_Library.split_first_instance( world_spawn_item, '(') brushes = TextModificationLib.split(brushes[1], '\n') sides = [] for item in brushes: side = parse_brush(item) sides.append(side) return sides
def make_side_of_brush(properties): global texture_dir side: str = str(properties['points']) side = TextModificationLib.remove(side, ttr_multiple=["[", "]", ",", "'"]) side = side.strip() side = TextModificationLib.replace(side, ") ", ")") side = TextModificationLib.remove(side, "[") side = TextModificationLib.remove(side, "]") side = TextModificationLib.remove(side, ",") if properties['Material'] not in Texture_replacement_dictionary: texture = texture_dir + TextModificationLib.remove( properties['Material'], ttr_multiple=['#', '*']) texture = texture.casefold() else: texture = Texture_replacement_dictionary[properties['Material']] y_scale = properties['y_scale'] x_scale = properties['x_scale'] offset_x = properties['x_off'] offset_y = properties['y_off'] plane = f""" side {{ "id" "{properties['ID']}" "plane" "{side}" "material" "{texture}" "uaxis" "[0 0 0 {offset_x}] {x_scale}" "vaxis" "[0 0 0 {offset_y}] {y_scale}" "rotation" "{properties['rot_angle']}" "lightmapscale" "16" "smoothing_groups" "0" }}""" return plane
def get_contents_of_map_file(): entities = [] append_string = '' buffer = [] filename_internal = filename + ".map" max_lines = 0 map_file = '' i = 0 try: max_lines = TextModificationLib.count_lines_fast(filename_internal) map_file = open(filename_internal) except FileNotFoundError: print( 'ERROR: File has not been located!, please ensure the filename is in this location and that the path is' ' included if outside this directory') exit(-2) for _ in range(0, max_lines): line = map_file.readline() line_ascii = list(bytes(line, "ascii")) # Rotate list or if not big enough to qualify for a rotation just add another letter for letter in line_ascii: if len(buffer) == 2: buffer = List_Dict_Array_Library.rotate_list(buffer, -1) buffer[1] = letter else: buffer.append(letter) if buffer == [123, 10]: i += 1 if i == 1: append_string = '' elif buffer == [125, 10]: i -= 1 if i == 0: entities.append('{' + append_string) append_string = append_string + chr(letter) return entities
def parse_brush(brush): # Removes comments brush_data = TextModificationLib.remove_cpp_style_comments(brush) brush_data = TextModificationLib.recombine(brush_data) brush_data = TextModificationLib.unwrap(brush_data, '{', '}', True) return brush_data
i = 1 for entity in entities: create_entity(entities[entity], i) i += 1 def end_brushes(end_file=False, first_write=False): if end_file: return '}}' if not first_write: return """\n\t\t}\n\tsolid\n\t{""" else: return "\n\tsolid\n\t{" def browse_map_file(): filename_internal = filedialog.askopenfilename( initialdir=os.getcwd(), title="Select a File", filetypes=(("Quake 1 non-compiled map file (.map) ", "*.map"), ("all files", "*.*"))) return filename_internal filename = browse_map_file() filename = TextModificationLib.remove( TextModificationLib.make_lowercase(filename), ".map") print(filename) world = parse_file() write_vmf_file(world)