From 0f6dd0891ff7d9f69b486472ddc6166dbb901479 Mon Sep 17 00:00:00 2001 From: ineed bots Date: Wed, 6 Dec 2023 12:27:46 -0600 Subject: [PATCH] Refactor getWaypointLinesFromFile function in _bot_utility.gsc This commit refactors the implementation of the getWaypointLinesFromFile function in the _bot_utility.gsc file. The changes include improved handling of newline characters and more efficient processing of lines from the input waypoint string. Additionally, the code now correctly accounts for both '\n' and '\r\n' line endings. These modifications aim to enhance the overall readability and maintainability of the code. --- maps/mp/bots/_bot_utility.gsc | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/maps/mp/bots/_bot_utility.gsc b/maps/mp/bots/_bot_utility.gsc index 6ea1035..0b521bf 100644 --- a/maps/mp/bots/_bot_utility.gsc +++ b/maps/mp/bots/_bot_utility.gsc @@ -995,24 +995,27 @@ getWaypointLinesFromFile( filename ) if ( !isDefined( waypointStr ) ) return result; - line = ""; + linecount = 0; + linestart = 0; for ( i = 0; i < waypointStr.size; i++ ) { - c = waypointStr[i]; - - if ( c == "\n" ) + if ( waypointStr[i] == "\n" || waypointStr[i] == "\r" ) { - result.lines[result.lines.size] = line; + result.lines[result.lines.size] = getSubStr( waypointStr, linestart, linestart + linecount ); - line = ""; + if ( waypointStr[i] == "\r" && i < waypointStr.size - 1 && waypointStr[i + 1] == "\n" ) + i++; + + linecount = 0; + linestart = i + 1; continue; } - line += c; + linecount++; } - result.lines[result.lines.size] = line; + result.lines[result.lines.size] = getSubStr( waypointStr, linestart, linestart + linecount ); return result; }