diff --git a/tools/dmm2tgm/Source/dmm2tgm.py b/tools/dmm2tgm/Source/dmm2tgm.py deleted file mode 100644 index 637986f9a6..0000000000 --- a/tools/dmm2tgm/Source/dmm2tgm.py +++ /dev/null @@ -1,77 +0,0 @@ - -import sys - -# .dmm format converter, by RemieRichards -# Version 2.0 -# Converts the internal structure of a .dmm file to a syntax -# that git can better handle conflicts-wise, it's also fairly human readable! -# Processes Boxstation (tgstation.2.1.3) almost instantly - - -def convert_map(map_file): - #CHECK FOR PREVIOUS CONVERSION - with open(map_file, "r") as conversion_candidate: - header = conversion_candidate.readline() - if header.find("//MAP CONVERTED BY dmm2tgm.py THIS HEADER COMMENT PREVENTS RECONVERSION, DO NOT REMOVE") != -1: - sys.exit() - return - - - #ACTUAL CONVERSION - with open(map_file, "r+") as unconverted_map: - characters = unconverted_map.read() - converted_map = "" - in_object_block = False #() - in_variable_block = False #{} - in_quote_block = False #'' - in_double_quote_block = False #"" - for char in characters: - if not in_quote_block: #Checking for things like "Flashbangs (Warning!)" Because we only care about ({'";, that are used as byond syntax, not strings - if not in_double_quote_block: - if not in_variable_block: - if char == "(": - in_object_block = True - char = char + "\n" - if char == ")": - in_object_block = False - if char == ",": - char = char + "\n" - - if char == "{": - in_variable_block = True - if in_object_block: - char = char + "\n\t" - if char == "}": - in_variable_block = False - if in_object_block: - char = "\n\t" + char - - if char == ";": - char = char + "\n\t" - - if char == "\"": - if in_double_quote_block: - in_double_quote_block = False - else: - in_double_quote_block = True - - if char == "'": - if not in_double_quote_block: - if in_quote_block: - in_quote_block = False - else: - in_quote_block = True - - converted_map = converted_map + char - - #OVERWRITE MAP FILE WITH CONVERTED MAP STRING - with open(map_file, "r+") as final_converted_map: - final_converted_map.write("//MAP CONVERTED BY dmm2tgm.py THIS HEADER COMMENT PREVENTS RECONVERSION, DO NOT REMOVE \n") - final_converted_map.write(converted_map) - - sys.exit() - - -if sys.argv[1]: #Run like dmm2tgm.py "folder/folder/a_map.dmm" - convert_map(sys.argv[1]) - diff --git a/tools/dmm2tgm/dmm2tgm.exe b/tools/dmm2tgm/dmm2tgm.exe deleted file mode 100644 index fba25d71d0..0000000000 Binary files a/tools/dmm2tgm/dmm2tgm.exe and /dev/null differ diff --git a/tools/dmm2tgm/library.zip b/tools/dmm2tgm/library.zip deleted file mode 100644 index 068102032b..0000000000 Binary files a/tools/dmm2tgm/library.zip and /dev/null differ diff --git a/tools/dmm2tgm/python27.dll b/tools/dmm2tgm/python27.dll deleted file mode 100644 index e45374fb33..0000000000 Binary files a/tools/dmm2tgm/python27.dll and /dev/null differ diff --git a/tools/dmm2tgm/w9xpopen.exe b/tools/dmm2tgm/w9xpopen.exe deleted file mode 100644 index 9303628363..0000000000 Binary files a/tools/dmm2tgm/w9xpopen.exe and /dev/null differ diff --git a/tools/mapmerge/Convert Maps to TGM.bat b/tools/mapmerge/Convert Maps to TGM.bat new file mode 100644 index 0000000000..0b88dfaf1d --- /dev/null +++ b/tools/mapmerge/Convert Maps to TGM.bat @@ -0,0 +1,3 @@ +@echo off +set MAPROOT="../../_maps/" +python dmm2tgm.py %1 %MAPROOT% \ No newline at end of file diff --git a/tools/mapmerge/dmm2tgm.py b/tools/mapmerge/dmm2tgm.py new file mode 100644 index 0000000000..4ed4d8ffe6 --- /dev/null +++ b/tools/mapmerge/dmm2tgm.py @@ -0,0 +1,39 @@ +import map_helpers +import sys +import shutil + +#main("../../_maps/") +def main(map_folder): + tgm = "1" + maps = map_helpers.prompt_maps(map_folder, "convert", tgm) + + print("\nConverting these maps:") + for i in maps.indices: + print(str(maps.files[i])[len(map_folder):]) + + convert = input("\nPress Enter to convert...\n") + if convert == "abort": + print("\nAborted map convert.") + sys.exit() + else: + for i in maps.indices: + path_str = str(maps.files[i]) + path_str_pretty = path_str[len(map_folder):] + error = map_helpers.merge_map(path_str, path_str, tgm) + if error > 1: + print(map_helpers.error[error]) + continue + if error == 1: + print(map_helpers.error[1]) + print("CONVERTED: {}".format(path_str_pretty)) + print(" - ") + + print("\nFinished converting.") + +def string_to_num(s): + try: + return int(s) + except ValueError: + return -1 + +main(sys.argv[1]) diff --git a/tools/mapmerge/map_helpers.py b/tools/mapmerge/map_helpers.py index ea06641f50..e1eb7e875c 100644 --- a/tools/mapmerge/map_helpers.py +++ b/tools/mapmerge/map_helpers.py @@ -1,5 +1,8 @@ import sys import subprocess +import os +import pathlib +import collections from datetime import datetime tgm_header = "//MAP CONVERTED BY dmm2tgm.py THIS HEADER COMMENT PREVENTS RECONVERSION, DO NOT REMOVE" @@ -727,3 +730,45 @@ def combine_tiles(tile_A, tile_B, priority, marker): def run_shell_command(command): return subprocess.run(command, shell=True, stdout=subprocess.PIPE, universal_newlines=True).stdout + +def prompt_maps(map_folder, verb, tgm): + list_of_files = list() + for root, directories, filenames in os.walk(map_folder): + for filename in [f for f in filenames if f.endswith(".dmm")]: + list_of_files.append(pathlib.Path(root, filename)) + + last_dir = "" + for i in range(0, len(list_of_files)): + this_dir = list_of_files[i].parent + if last_dir != this_dir: + print("--------------------------------") + last_dir = this_dir + print("[{}]: {}".format(i, str(list_of_files[i])[len(map_folder):])) + + print("--------------------------------") + in_list = input("List the maps you want to " + verb + " (example: 1,3-5,12):\n") + in_list = in_list.replace(" ", "") + in_list = in_list.split(",") + + valid_indices = list() + for m in in_list: + index_range = m.split("-") + if len(index_range) == 1: + index = string_to_num(index_range[0]) + if index >= 0 and index < len(list_of_files): + valid_indices.append(index) + elif len(index_range) == 2: + index0 = string_to_num(index_range[0]) + index1 = string_to_num(index_range[1]) + if index0 >= 0 and index0 <= index1 and index1 < len(list_of_files): + valid_indices.extend(range(index0, index1 + 1)) + + if tgm == "1": + print("\nMaps will be converted to tgm.") + tgm = True + else: + print("\nMaps will not be converted to tgm.") + tgm = False + + maps_to_run = collections.namedtuple('maps_to_run', ['files', 'indices']) + return maps_to_run(list_of_files, valid_indices) \ No newline at end of file diff --git a/tools/mapmerge/mapmerger.py b/tools/mapmerge/mapmerger.py index b93684bbc9..2b679cb131 100644 --- a/tools/mapmerge/mapmerger.py +++ b/tools/mapmerge/mapmerger.py @@ -1,52 +1,15 @@ import map_helpers import sys -import os -import pathlib import shutil #main("../../_maps/") def main(map_folder, tgm=0): - list_of_files = list() - for root, directories, filenames in os.walk(map_folder): - for filename in [f for f in filenames if f.endswith(".dmm")]: - list_of_files.append(pathlib.Path(root, filename)) - - last_dir = "" - for i in range(0, len(list_of_files)): - this_dir = list_of_files[i].parent - if last_dir != this_dir: - print("--------------------------------") - last_dir = this_dir - print("[{}]: {}".format(i, str(list_of_files[i])[len(map_folder):])) - - print("--------------------------------") - in_list = input("List the maps you want to merge (example: 1,3-5,12):\n") - in_list = in_list.replace(" ", "") - in_list = in_list.split(",") - - valid_indices = list() - for m in in_list: - index_range = m.split("-") - if len(index_range) == 1: - index = string_to_num(index_range[0]) - if index >= 0 and index < len(list_of_files): - valid_indices.append(index) - elif len(index_range) == 2: - index0 = string_to_num(index_range[0]) - index1 = string_to_num(index_range[1]) - if index0 >= 0 and index0 <= index1 and index1 < len(list_of_files): - valid_indices.extend(range(index0, index1 + 1)) - - if tgm == "1": - print("\nMaps will be converted to tgm.") - tgm = True - else: - print("\nMaps will not be converted to tgm.") - tgm = False + valid_indices = map_helpers.prompt_maps(map_folder, "merge", tgm) print("\nMerging these maps:") - for i in valid_indices: - print(str(list_of_files[i])[len(map_folder):]) + for i in maps.indices: + print(str(maps.files[i])[len(map_folder):]) + merge = input("\nPress Enter to merge...\n") if merge == "abort": print("\nAborted map merge.")