This commit is contained in:
CorruptComputer
2015-07-26 10:54:16 -05:00
parent 7c903ca027
commit 4516db6323
8 changed files with 239 additions and 177 deletions
-79
View File
@@ -1,79 +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
#TWEAKABLE VARIABLES
map_file = "tgstation.2.1.3.dmm" #Map file, .dmm or .txt
output_file = "" #Output file, .dmm or .txt, leave blank to overwrite 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("This map has already been converted, cancelling...")
#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 char == "(" :
if not in_object_block:
if not in_quote_block:
if not in_double_quote_block:
if not in_variable_block:
in_object_block = True
char = char + "\n"
if char == ")":
if in_object_block:
if not in_quote_block:
if not in_double_quote_block:
if not in_variable_block:
in_object_block = False
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 == ",":
if not in_variable_block:
char = char + "\n"
if char == "'":
if in_quote_block:
in_quote_block = False
else:
in_quote_block = True
if char == "\"":
if in_double_quote_block:
in_double_quote_block = False
else:
in_double_quote_block = True
if char == ";":
if not in_quote_block:
if not in_double_quote_block:
char = char + "\n\t"
converted_map = converted_map + char
if output_file == "":
output_file = map_file
with open(output_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)
Binary file not shown.
+1 -2
View File
@@ -1,5 +1,4 @@
@echo off
java -jar MapMerge.jar ../../_maps/
call java -jar MapMerge.jar "../../_maps/" /wait
pause
@@ -0,0 +1,60 @@
cleanup.add_default_serial_version_id=false
cleanup.add_generated_serial_version_id=true
cleanup.add_missing_annotations=true
cleanup.add_missing_deprecated_annotations=true
cleanup.add_missing_methods=false
cleanup.add_missing_nls_tags=false
cleanup.add_missing_override_annotations=true
cleanup.add_missing_override_annotations_interface_methods=true
cleanup.add_serial_version_id=false
cleanup.always_use_blocks=true
cleanup.always_use_parentheses_in_expressions=true
cleanup.always_use_this_for_non_static_field_access=false
cleanup.always_use_this_for_non_static_method_access=false
cleanup.convert_functional_interfaces=false
cleanup.convert_to_enhanced_for_loop=false
cleanup.correct_indentation=true
cleanup.format_source_code=true
cleanup.format_source_code_changes_only=false
cleanup.insert_inferred_type_arguments=false
cleanup.make_local_variable_final=true
cleanup.make_parameters_final=false
cleanup.make_private_fields_final=true
cleanup.make_type_abstract_if_missing_method=false
cleanup.make_variable_declarations_final=false
cleanup.never_use_blocks=false
cleanup.never_use_parentheses_in_expressions=false
cleanup.organize_imports=true
cleanup.qualify_static_field_accesses_with_declaring_class=false
cleanup.qualify_static_member_accesses_through_instances_with_declaring_class=true
cleanup.qualify_static_member_accesses_through_subtypes_with_declaring_class=true
cleanup.qualify_static_member_accesses_with_declaring_class=true
cleanup.qualify_static_method_accesses_with_declaring_class=true
cleanup.remove_private_constructors=true
cleanup.remove_redundant_type_arguments=true
cleanup.remove_trailing_whitespaces=false
cleanup.remove_trailing_whitespaces_all=true
cleanup.remove_trailing_whitespaces_ignore_empty=false
cleanup.remove_unnecessary_casts=true
cleanup.remove_unnecessary_nls_tags=true
cleanup.remove_unused_imports=true
cleanup.remove_unused_local_variables=true
cleanup.remove_unused_private_fields=true
cleanup.remove_unused_private_members=true
cleanup.remove_unused_private_methods=true
cleanup.remove_unused_private_types=true
cleanup.sort_members=false
cleanup.sort_members_all=false
cleanup.use_anonymous_class_creation=false
cleanup.use_blocks=true
cleanup.use_blocks_only_for_return_and_throw=false
cleanup.use_lambda=true
cleanup.use_parentheses_in_expressions=true
cleanup.use_this_for_non_static_field_access=true
cleanup.use_this_for_non_static_field_access_only_if_necessary=true
cleanup.use_this_for_non_static_method_access=true
cleanup.use_this_for_non_static_method_access_only_if_necessary=true
cleanup.use_type_arguments=false
cleanup_profile=_Default
cleanup_settings_version=2
eclipse.preferences.version=1
Binary file not shown.
+101
View File
@@ -0,0 +1,101 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Scanner;
public class MapMerge {
private static Scanner input = new Scanner(System.in);
private static Path pathToMaps;
public static void main(String[] mapPath) throws IOException {
pathToMaps = Paths.get(mapPath[0]);
FileFinder dmmFinder = new FileFinder("*.dmm");
Files.walkFileTree(pathToMaps, dmmFinder);
ArrayList<Path> foundFiles = dmmFinder.foundPaths;
if (foundFiles.size() > 0) {
try {
MapMerge.merge(foundFiles);
} catch (Exception e) {
System.out.println("Something went wrong.");
e.printStackTrace();
}
} else {
System.out.println("No files were found in provided directory!");
System.out.print("Path to maps folder: ");
pathToMaps = Paths.get(input.nextLine());
dmmFinder = new FileFinder("*.dmm");
Files.walkFileTree(pathToMaps, dmmFinder);
foundFiles = dmmFinder.foundPaths;
try {
MapMerge.merge(foundFiles);
} catch (Exception e) {
System.out.println("Something went wrong.");
e.printStackTrace();
}
}
}
public static void merge(ArrayList<Path> foundFiles) throws IOException {
System.out.println("How many files do you want to merge?");
int selection1;
inputCheck: while (true) {
while (!input.hasNextInt()) {
String temp = input.next();
System.out.println(temp + " is not a valid int.");
}
selection1 = input.nextInt();
if (selection1 < 0) {
System.out.println("Use a number greater than 0!");
continue inputCheck;
} else {
break inputCheck;
}
}
for (int numOfFiles = selection1; numOfFiles != 0; numOfFiles--) {
for (int num = 0; num < foundFiles.size(); num++) {
System.out.println(num + ": " + foundFiles.get(num));
}
System.out.print("File to use: ");
int selection2;
inputCheck: while (true) {
while (!input.hasNextInt()) {
String temp = input.next();
System.out.println(temp + " is not a valid int.");
}
selection2 = input.nextInt();
if ((selection2 < 0) || (selection2 >= foundFiles.size())) {
if (selection2 < 0) {
System.out.println("Use a number greater than 0!");
} else {
System.out.println("Use a number less than " + foundFiles.size() + "!");
}
continue inputCheck;
} else {
break inputCheck;
}
}
String selected_map = foundFiles.get(selection2) + "";
String backup_map = selected_map + ".backup";
String edited_map = selected_map;
String to_save = selected_map;
String[] passInto = { "-clean", backup_map, edited_map, to_save };
MapPatcher.main(passInto);
try{
Process process = new ProcessBuilder("C:\\Python27\\python.exe", "dmm2tgm.py", selected_map).start();
}catch(Exception e){
e.printStackTrace();
System.out.println("This was most likely caused by you not having python 2.7.x installed.");
System.out.println("Downloads can be found here: https://www.python.org/downloads/");
}
}
}
}
@@ -1,96 +0,0 @@
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.Scanner;
public class MapMergerMain {
private static Scanner input = new Scanner(System.in);
public static void main(String[] mapPath) throws IOException{
Path pathToMaps = Paths.get(mapPath[0]);
FileFinder dmmFinder = new FileFinder("*.dmm");
Files.walkFileTree(pathToMaps, dmmFinder);
ArrayList<Path> foundFiles = dmmFinder.foundPaths;
if (foundFiles.size() > 0) {
try{
merge(foundFiles);
}catch(Exception e){
System.out.println("Something went wrong.");
e.printStackTrace();
}
}else{
System.out.println("No files were found in provided directory!");
System.out.print("Path to maps folder: ");
pathToMaps = Paths.get(input.nextLine());
dmmFinder = new FileFinder("*.dmm");
Files.walkFileTree(pathToMaps, dmmFinder);
foundFiles = dmmFinder.foundPaths;
try{
merge(foundFiles);
}catch(Exception e){
System.out.println("Something went wrong.");
e.printStackTrace();
}
}
}
public static void merge(ArrayList<Path> foundFiles){
System.out.println("How many files do you want to merge?");
int selection1;
inputCheck:while(true){
while(!input.hasNextInt()){
String temp = input.next();
System.out.println(temp + " is not a valid int.");
}
selection1 = input.nextInt();
if(selection1 < 0){
System.out.println("Use a number greater than 0!");
continue inputCheck;
}else{
break inputCheck;
}
}
for(int numOfFiles = selection1; numOfFiles != 0; numOfFiles--){
for(int num = 0;num < foundFiles.size();num++){
System.out.println(num + ": " + foundFiles.get(num));
}
System.out.print("File to use: ");
int selection2;
inputCheck:while(true){
while(!input.hasNextInt()){
String temp = input.next();
System.out.println(temp + " is not a valid int.");
}
selection2 = input.nextInt();
if(selection2 < 0 || selection2 >= foundFiles.size()){
if(selection2 < 0){
System.out.println("Use a number greater than 0!");
}else{
System.out.println("Use a number less than " + foundFiles.size() +"!");
}
continue inputCheck;
}else{
break inputCheck;
}
}
String newMap = foundFiles.get(selection2) + "";
String oldMap = foundFiles.get(selection2) + ".backup";
String[] passInto = new String[4];
passInto[0] = "-clean";
passInto[1] = oldMap;
passInto[2] = newMap;
passInto[3] = newMap;
MapPatcher.main(passInto);
}
}
}
+77
View File
@@ -0,0 +1,77 @@
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])