From 1d2e7a5756b1a627045ae49c9325debf784be9ad Mon Sep 17 00:00:00 2001 From: BCDeshiG Date: Thu, 8 Sep 2022 20:58:58 +0100 Subject: [PATCH] Process NZP Beta waypoints --- testBETA | 40 ++++++++++++++++++++++++++++++++++++++++ waycon.py | 39 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 79 insertions(+) create mode 100644 testBETA diff --git a/testBETA b/testBETA new file mode 100644 index 0000000..217e43b --- /dev/null +++ b/testBETA @@ -0,0 +1,40 @@ +'-112.3 -494.4 8.0' +1 +2 +3 +4 +0 +2 +3 +4 +0 +'-119.8 -115.7 8.0' +2 +1 +3 +4 +0 +1 +3 +4 +0 +' 41.6 87.6 8.0' +3 +1 +0 +0 +0 +1 +0 +0 +0 +'-115.0 152.3 120.0' +4 +1 +2 +0 +0 +1 +2 +0 +0 diff --git a/waycon.py b/waycon.py index cd742c9..e1a663e 100644 --- a/waycon.py +++ b/waycon.py @@ -41,8 +41,14 @@ def startConversion(inputFile, outputFile, wayFormat): header = oldWayFile[0].strip("\n") if header == "Waypoint": # PSP print("PSP format detected") + if wayFormat.upper() == "PSP": + raise ValueError("Already in PSP format!") + wayArray = parsePSP(oldWayFile) elif header == "waypoint": # PC print("PC format detected") + if wayFormat.upper() == "PC": + raise ValueError("Already in PC format!") + wayArray = parsePC(oldWayFile) else: # Check if BETA or just random crap where = header.strip("'").split() # Split xyz # Should look something like [-40.5, 12.2, 8.0] @@ -53,7 +59,40 @@ def startConversion(inputFile, outputFile, wayFormat): for i in range(len(where)): float(where[i]) print("BETA format detected") + if wayFormat.upper() == "BETA": + raise ValueError("Already in BETA format!") + wayArray = parseBETA(oldWayFile) except ValueError: print("Invalid waypoint co-ords") + + # Print out waypoint for now I guess + for waypoint in wayArray: + print(waypoint) + +def parsePSP(oldWayFile): + return ["This", "is", "a", "test"] + +def parsePC(oldWayFile): + return ["Notsee", "Zombies", "Portable", "2"] + +def parseBETA(oldWayFile): + tempArray = [] # Temporarily stores waypoint fields + wayArray = [] # Array of waypoints + for i, line in enumerate(oldWayFile): + relativeLineNum = (i+1)%10 + # Ignore 'owner' fields as they don't apply to modern format + if relativeLineNum < 7 and relativeLineNum != 0: + tempArray.append(line.strip()) # Add field to temporary array + if (i+1)%10 == 0: # Reached end of that waypoint + # Store waypoint fields in dictionary + waydict = { + "origin": tempArray[0], + "id": tempArray[1], + # Remove empty targets + "targets": [value for value in tempArray[2:] if value != "0"] + } + tempArray.clear() # Clear temporary array for next waypoint + wayArray.append(waydict) # Add waypoint to array + return wayArray parseArgs() \ No newline at end of file