1
Fork 0
mirror of https://github.com/thegeneralist01/Scene-Manager-DevRepo synced 2026-01-11 15:40:29 +01:00

Refactored with more encapsulation, better protection for class fields

This commit is contained in:
Rich Dunne 2020-08-20 15:31:10 -06:00
parent 7c6a3fdfcf
commit 0dc3b19bc2

View file

@ -1,52 +1,122 @@
using Rage;
using System.Runtime.InteropServices;
namespace SceneManager
{
public class Waypoint
{
public int Path;
public int WaypointNum;
public Vector3 WaypointPos;
public float Speed;
public VehicleDrivingFlags DrivingFlag;
public Blip WaypointBlip;
public uint YieldZone;
public bool Collector;
public float CollectorRadius;
public Blip CollectorRadiusBlip;
public int Path { get; private set; }
public int Number { get; private set; }
public Vector3 Position { get; private set; }
public float Speed { get; private set; }
public VehicleDrivingFlags DrivingFlag { get; private set; }
public Blip Blip { get; private set; }
public uint YieldZone { get; private set; }
public bool Collector { get; private set; }
public float CollectorRadius { get; private set; }
public Blip CollectorRadiusBlip { get; private set; }
// Can this constructor be deleted?
//public Waypoint(int path, Vector3 waypointPos, float speed, VehicleDrivingFlags drivingFlag, Blip waypointBlip, uint yieldZone)
//{
// Path = path;
// WaypointPos = waypointPos;
// Speed = speed;
// DrivingFlag = drivingFlag;
// WaypointBlip = waypointBlip;
// YieldZone = yieldZone;
//}
public Waypoint(int path, int waypointNum, Vector3 waypointPos, float speed, VehicleDrivingFlags drivingFlag, Blip waypointBlip)
{
Path = path;
Number = waypointNum;
Position = waypointPos;
Speed = speed;
DrivingFlag = drivingFlag;
Blip = waypointBlip;
}
public Waypoint(int path, int waypointNum, Vector3 waypointPos, float speed, VehicleDrivingFlags drivingFlag, Blip waypointBlip, bool collector, float collectorRadius, uint yieldZone)
{
Path = path;
WaypointNum = waypointNum;
WaypointPos = waypointPos;
Number = waypointNum;
Position = waypointPos;
Speed = speed;
DrivingFlag = drivingFlag;
WaypointBlip = waypointBlip;
Blip = waypointBlip;
Collector = collector;
CollectorRadius = collectorRadius;
if (collector)
{
YieldZone = yieldZone;
CollectorRadiusBlip = new Blip(waypointBlip.Position, collectorRadius)
{
Color = waypointBlip.Color,
Alpha = 0.5f
};
}
public void UpdateWaypoint(Waypoint currentWaypoint, VehicleDrivingFlags drivingFlag, float drivingSpeed, bool collectorWaypointChecked, float collectorRadius, bool updateWaypointPositionChecked)
{
UpdateDrivingFlag(drivingFlag);
UpdateWaypointSpeed(drivingSpeed);
UpdateCollectorOptions(currentWaypoint, drivingSpeed, collectorWaypointChecked, collectorRadius);
if (updateWaypointPositionChecked)
{
UpdateWaypointPosition(Game.LocalPlayer.Character.Position);
}
}
private void UpdateCollectorOptions(Waypoint currentWaypoint, float drivingSpeed, bool collectorWaypointChecked, float collectorRadius)
{
if (collectorWaypointChecked)
{
Collector = true;
YieldZone = World.AddSpeedZone(Game.LocalPlayer.Character.Position, 50f, drivingSpeed);
if (CollectorRadiusBlip)
{
currentWaypoint.CollectorRadiusBlip.Alpha = 0.5f;
currentWaypoint.CollectorRadiusBlip.Scale = collectorRadius;
}
else
{
CollectorRadiusBlip = new Blip(Blip.Position, collectorRadius)
{
Color = Blip.Color,
Alpha = 0.5f
};
}
CollectorRadius = collectorRadius;
}
else
{
Collector = false;
World.RemoveSpeedZone(YieldZone);
if (CollectorRadiusBlip)
{
CollectorRadiusBlip.Delete();
}
}
}
private void UpdateWaypointPosition(Vector3 newWaypointPosition)
{
Position = newWaypointPosition;
UpdateWaypointBlipPosition();
}
private void UpdateWaypointSpeed(float newWaypointSpeed)
{
Speed = newWaypointSpeed;
}
private void UpdateDrivingFlag(VehicleDrivingFlags newDrivingFlag)
{
DrivingFlag = newDrivingFlag;
}
private void UpdateWaypointBlipPosition()
{
Blip.Position = Game.LocalPlayer.Character.Position;
}
public void UpdatePathNumber(int newPathNumber)
{
Path = newPathNumber;
}
public void UpdateWaypointNumber(int newWaypointNumber)
{
Number = newWaypointNumber;
}
}
}