Skip to content

Commit

Permalink
Removes debugging code and an unused method. Rebuilt + compressed.
Browse files Browse the repository at this point in the history
  • Loading branch information
davwheat committed Oct 28, 2018
1 parent 11dda9c commit e549284
Show file tree
Hide file tree
Showing 3 changed files with 97 additions and 69 deletions.
Binary file modified _Resource/VoiceGPS.zip
Binary file not shown.
Binary file modified _Resource/VoiceGPS/VoiceGPS_FiveM.Client.net.dll
Binary file not shown.
166 changes: 97 additions & 69 deletions src/VoiceGPS-FiveM.Client/ClientScript.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,9 +76,6 @@ private async Task OnTick()
_justPlayedArrived = true;
await Delay(2000);
}
#if DEBUG
//Chat("a");
#endif

_playedStartDriveAudio = false;

Expand All @@ -89,9 +86,6 @@ private async Task OnTick()
_justPlayedArrived = false;
if (!_playedStartDriveAudio)
{
#if DEBUG
//Chat("b");
#endif
PlayAudio("start");
await Delay(2600);
_playedStartDriveAudio = true;
Expand All @@ -111,10 +105,6 @@ private async Task OnTick()
return;
}

#if DEBUG
//ShowNotification(DirectionToString(dir));
#endif

//0 : You arrived at your destination
//1 : Going The Wrong wAY...recalculating
//2: Follow this lane and wait for more instructions
Expand All @@ -125,7 +115,7 @@ private async Task OnTick()
//7: Take the next return to the right. (distance on p6)
//8: Exit motorway

if (_lastDirection != dir || (_lastDirection == dir && _lastDistance < dist))
if (_lastDirection != dir || (_lastDirection == dir && _lastDistance - dist < -50))
{
_justPlayed200M = false;
_justPlayedImmediate = false;
Expand Down Expand Up @@ -192,100 +182,87 @@ private async Task OnTick()

}

private string DirectionToString(int direction)
{
switch (direction)
{
default:
return $"Unknown ({direction})";
case 0:
return $"You have arrived (0)";
case 1:
return $"Recalculating (1)";
case 2:
return $"Follow the road (2)";
case 3:
return $"Left at next junction (3)";
case 4:
return $"Right at next junction (4)";
case 5:
return $"Straight at next junction (5)";
case 6:
return $"Keep left (6)";
case 7:
return $"Keep right (7)";
case 8:
return $"Exit motorway (8)";
}
}
//private string DirectionToString(int direction)
//{
// switch (direction)
// {
// default:
// return $"Unknown ({direction})";
// case 0:
// return $"You have arrived (0)";
// case 1:
// return $"Recalculating (1)";
// case 2:
// return $"Follow the road (2)";
// case 3:
// return $"Left at next junction (3)";
// case 4:
// return $"Right at next junction (4)";
// case 5:
// return $"Straight at next junction (5)";
// case 6:
// return $"Keep left (6)";
// case 7:
// return $"Keep right (7)";
// case 8:
// return $"Exit motorway (8)";
// }
//}

private async Task PlayDirectionAudio(int dir, int dist)
{
//Chat("Attempting to play sound.");

var streets = GetStreetNameForDirection(dist);

var roadName = streets.Item1;
var crossingRoadName = streets.Item2;

var playerPosition = _playerPed.Position;
var hash = 0u;
var crossingRoadHash = 0u;
var dontPlayStreetName = false;
var roadName = "";

API.GetStreetNameAtCoord(
playerPosition.X,
playerPosition.Y,
playerPosition.Z,
ref hash, ref crossingRoadHash);

var currentRoad = API.GetStreetNameFromHashKey(hash);

var dontPlayStreetName = (currentRoad == roadName);


roadName = ConvertStreetNameToAudioFileName(roadName);
crossingRoadName = crossingRoadName != null ? ConvertStreetNameToAudioFileName(crossingRoadName) : "N/A";
#if DEBUG
ShowNotification("Upcoming street: " + roadName + " |X| " + crossingRoadName);
#endif
if (dir == 3 || dir == 4)
{
roadName = GetCorrectTurningRoadName(dir, dist, out dontPlayStreetName);
}

switch (dir)
{
default:
// Anything NOT known
Chat(dir.ToString());
// Chat(dir.ToString());
break;

case 6:
// Not 100%
PlayAudio("keepleft");
await Delay(900);
break;

case 7:
// Not 100%
PlayAudio("keepright");
await Delay(900);
break;

case 3:
// Turn left at next intersection
// Chat(dir.ToString());

PlayAudio("turnleft");
await Delay(900);

if (dist < 175 && dist > 30 && !dontPlayStreetName)
{
await Delay(900);
PlayAudio("onto");
await Delay(500);
PlayAudio("streetnames/" + roadName);
await Delay(1250); // Generic time wait to prevent audio overlapping
}

break;

case 4:
// Turn right at next intersection
// Chat(dir.ToString());

PlayAudio("turnright");
await Delay(900);

if (dist < 175 && dist > 30 && !dontPlayStreetName)
{
await Delay(900);
PlayAudio("onto");
await Delay(500);
PlayAudio("streetnames/" + roadName);
Expand All @@ -302,10 +279,11 @@ private async Task PlayDirectionAudio(int dir, int dist)
case 1:
// Driver went wrong way -- remaking route
PlayAudio("recalculating");
await Delay(1200);
break;

case 8:
PlayAudio("exitMotorwayToRight");
//PlayAudio("exitMotorwayToRight");
break;
}
}
Expand All @@ -318,7 +296,8 @@ void ToggleVgps()
{
_lastDirection = 0;
_justPlayed200M = _justPlayedArrived = _justPlayedFollowRoad =
_justPlayedImmediate = _justPlayedRecalc = _justPlayed1000M = false;
_justPlayedImmediate = _justPlayedRecalc = _justPlayed1000M =
_playedStartDriveAudio = false;
}

ShowNotification(_voiceGpsEnabled ? "Voice GPS ~g~ENABLED" : "Voice GPS ~r~DISABLED");
Expand Down Expand Up @@ -382,6 +361,7 @@ private Tuple<string, string> GetStreetNameForDirection(int distance, Vector3? x
xyOffset = new Vector3(0, 0, 0);

Vector3 coords = Game.PlayerPed.Position + (Game.PlayerPed.ForwardVector * distance) + (Vector3) xyOffset;

// ReSharper disable once InconsistentNaming
var roadPositionXY = new Vector2(coords.X, coords.Y);

Expand Down Expand Up @@ -431,5 +411,53 @@ private string ConvertStreetNameToAudioFileName(string streetName)

return streetName;
}

private string GetCorrectTurningRoadName(int direction, int distance, out bool incorrectStreetName)
{
var streets = GetStreetNameForDirection(distance);
var roadName = streets.Item1;

var playerPosition = _playerPed.Position;

var hash = 0u;
var crossingRoadHash = 0u;

API.GetStreetNameAtCoord(
playerPosition.X,
playerPosition.Y,
playerPosition.Z,
ref hash, ref crossingRoadHash);

var currentRoad = API.GetStreetNameFromHashKey(hash);

incorrectStreetName = (currentRoad == roadName);

if (incorrectStreetName)
{
var rightVector = _playerPed.RightVector;
var leftVector = rightVector * -1;

switch (direction)
{
case 3:
streets = GetStreetNameForDirection(distance, leftVector * 5);
roadName = streets.Item1;
incorrectStreetName = (currentRoad == roadName);
break;
case 4:
streets = GetStreetNameForDirection(distance, rightVector * 5);
roadName = streets.Item1;
incorrectStreetName = (currentRoad == roadName);
break;
}
}

if (incorrectStreetName)
return null;

roadName = ConvertStreetNameToAudioFileName(roadName);

return roadName;
}
}
}

0 comments on commit e549284

Please sign in to comment.