From 7fd8279d11d1d8f459bc77287a2c6731f874bcc8 Mon Sep 17 00:00:00 2001 From: BCDeshiG Date: Wed, 7 Sep 2022 20:16:00 +0100 Subject: [PATCH] Detect format --- testDEMO.way | 44 ++++++++++++++++++++++++++++++++++++++++++++ testPC.way | 32 ++++++++++++++++++++++++++++++++ waycon.py | 25 +++++++++++++++++++++---- 3 files changed, 97 insertions(+), 4 deletions(-) create mode 100644 testDEMO.way create mode 100644 testPC.way diff --git a/testDEMO.way b/testDEMO.way new file mode 100644 index 0000000..1f11db3 --- /dev/null +++ b/testDEMO.way @@ -0,0 +1,44 @@ +Waypoint +{ +origin = '705.8 99.7 120.0' +id = 1 +special = door2 +target = 2 +target2 = 3 +target3 = +target4 = +target5 = +target6 = +target7 = +target8 = +} + +Waypoint +{ +origin = '698.7 339.5 120.0' +id = 2 +special = +target = 1 +target2 = 3 +target3 = +target4 = +target5 = +target6 = +target7 = +target8 = +} + +Waypoint +{ +origin = '322.7 122.8 120.0' +id = 3 +special = +target = 1 +target2 = +target3 = +target4 = +target5 = +target6 = +target7 = +target8 = +} diff --git a/testPC.way b/testPC.way new file mode 100644 index 0000000..90e5123 --- /dev/null +++ b/testPC.way @@ -0,0 +1,32 @@ +waypoint +{ + id: 1 + origin: '280.0 460.0 40.0' + door: tilt + targets: + [ + 2 + 3 + ] +} + +waypoint +{ + id: 2 + origin: '160.0 450.0 40.0' + targets: + [ + 1 + 3 + ] +} + +waypoint +{ + id: 3 + origin: '152.0 720.0 40.0' + targets: + [ + 1 + ] +} \ No newline at end of file diff --git a/waycon.py b/waycon.py index 8c085f5..79d32de 100644 --- a/waycon.py +++ b/waycon.py @@ -16,9 +16,26 @@ def startConversion(inputFile, outputFile): if not(outputFile.lower().endswith(".way")): outputFile += ".way" # Read in old waypoints - tempF = open(inputFile, "r") - oldWayFile = tempF.read() - tempF.close() - print(oldWayFile) + with open(inputFile, "r") as tempF: + oldWayFile = tempF.readlines() + + # Check format + header = oldWayFile[0].strip("\n") + if header == "Waypoint": # PSP + print("PSP format detected") + elif header == "waypoint": # PC + print("PC format detected") + else: # Check if BETA or just random crap + where = header.strip("'").split() # Split xyz + # Should look something like [-40.5, 12.2, 8.0] + if len(where) != 3: + print("Invalid waypoint file") # Clearly not co-ords + else: + try: # Check if they're actual numbers + for i in range(len(where)): + float(where[i]) + print("BETA format detected") + except ValueError: + print("Invalid waypoint co-ords") parseArgs() \ No newline at end of file