mirror of
https://github.com/thegeneralist01/Scene-Manager-DevRepo
synced 2026-01-11 15:40:29 +01:00
Added guard clause function for null checks
This commit is contained in:
parent
a87ac5ffdc
commit
b7b9cf3f8f
1 changed files with 48 additions and 16 deletions
|
|
@ -50,21 +50,7 @@ namespace SceneManager
|
||||||
|
|
||||||
for (int nextWaypoint = currentWaypoint.Number; nextWaypoint < waypoints.Count; nextWaypoint++)
|
for (int nextWaypoint = currentWaypoint.Number; nextWaypoint < waypoints.Count; nextWaypoint++)
|
||||||
{
|
{
|
||||||
if (waypoints.ElementAtOrDefault(nextWaypoint) == null)
|
VehicleAndDriverNullChecks(waypoints, nextWaypoint, collectedVehicle);
|
||||||
{
|
|
||||||
Game.LogTrivial($"Waypoint is null");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!vehicle)
|
|
||||||
{
|
|
||||||
Game.LogTrivial($"Vehicle is null");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
if (!driver)
|
|
||||||
{
|
|
||||||
Game.LogTrivial($"Driver is null");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
Game.LogTrivial($"{vehicle.Model.Name} is driving to waypoint {waypoints[nextWaypoint].Number}");
|
Game.LogTrivial($"{vehicle.Model.Name} is driving to waypoint {waypoints[nextWaypoint].Number}");
|
||||||
if (waypoints.ElementAtOrDefault(nextWaypoint) != null && !collectedVehicle.StoppedAtWaypoint)
|
if (waypoints.ElementAtOrDefault(nextWaypoint) != null && !collectedVehicle.StoppedAtWaypoint)
|
||||||
|
|
@ -90,10 +76,56 @@ namespace SceneManager
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void VehicleAndDriverNullChecks(CollectedVehicle collectedVehicle)
|
||||||
|
{
|
||||||
|
if (collectedVehicle == null)
|
||||||
|
{
|
||||||
|
Game.LogTrivial($"CollectedVehicle is null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!collectedVehicle.Vehicle)
|
||||||
|
{
|
||||||
|
Game.LogTrivial($"Vehicle is null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!collectedVehicle.Driver)
|
||||||
|
{
|
||||||
|
Game.LogTrivial($"Driver is null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void VehicleAndDriverNullChecks(List<Waypoint> waypoints, int nextWaypoint, CollectedVehicle collectedVehicle)
|
||||||
|
{
|
||||||
|
if (waypoints.ElementAtOrDefault(nextWaypoint) == null)
|
||||||
|
{
|
||||||
|
Game.LogTrivial($"Waypoint is null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if(collectedVehicle == null)
|
||||||
|
{
|
||||||
|
Game.LogTrivial($"CollectedVehicle is null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!collectedVehicle.Vehicle)
|
||||||
|
{
|
||||||
|
Game.LogTrivial($"Vehicle is null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (!collectedVehicle.Driver)
|
||||||
|
{
|
||||||
|
Game.LogTrivial($"Driver is null");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private static void StopVehicleAtWaypoint(CollectedVehicle collectedVehicle)
|
private static void StopVehicleAtWaypoint(CollectedVehicle collectedVehicle)
|
||||||
{
|
{
|
||||||
|
VehicleAndDriverNullChecks(collectedVehicle);
|
||||||
|
|
||||||
Game.LogTrivial($"{collectedVehicle.Vehicle.Model.Name} stopping at waypoint.");
|
Game.LogTrivial($"{collectedVehicle.Vehicle.Model.Name} stopping at waypoint.");
|
||||||
collectedVehicle.Driver.Tasks.DriveToPosition(collectedVehicle.Vehicle.FrontPosition, 10f, VehicleDrivingFlags.StopAtDestination);
|
//collectedVehicle.Driver.Tasks.PerformDrivingManeuver(VehicleManeuver.GoForwardStraightBraking);
|
||||||
|
collectedVehicle.Driver.Tasks.DriveToPosition(collectedVehicle.Vehicle.FrontPosition, 10f, (VehicleDrivingFlags)2147483648); // This causes FPS loss
|
||||||
collectedVehicle.SetStoppedAtWaypoint(true);
|
collectedVehicle.SetStoppedAtWaypoint(true);
|
||||||
|
|
||||||
while (collectedVehicle.Vehicle && collectedVehicle.StoppedAtWaypoint)
|
while (collectedVehicle.Vehicle && collectedVehicle.StoppedAtWaypoint)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue