-
Notifications
You must be signed in to change notification settings - Fork 38
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add waypoint serialization/deserialization
- Loading branch information
1 parent
1bc7bf4
commit 0c99215
Showing
3 changed files
with
69 additions
and
31 deletions.
There are no files selected for viewing
49 changes: 49 additions & 0 deletions
49
src/SpaceWarp.Game/API/Game/Waypoints/SerializedWaypoint.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
using JetBrains.Annotations; | ||
using Newtonsoft.Json; | ||
|
||
namespace SpaceWarp.API.Game.Waypoints; | ||
|
||
/// <summary> | ||
/// This contains the serialized information for a waypoint, used for saving/loading waypoints | ||
/// </summary> | ||
[Serializable] | ||
[method: JsonConstructor] | ||
[PublicAPI] | ||
public class SerializedWaypoint(string name, string bodyName, double latitude, double longitude, double altitude, WaypointState state) | ||
{ | ||
/// <summary> | ||
/// The name of the waypoint | ||
/// </summary> | ||
public string Name => name; | ||
|
||
/// <summary> | ||
/// The body the waypoint is on | ||
/// </summary> | ||
public string BodyName => bodyName; | ||
|
||
/// <summary> | ||
/// The latitude of the waypoint | ||
/// </summary> | ||
public double Latitude => latitude; | ||
|
||
/// <summary> | ||
/// The longitude of the waypoint | ||
/// </summary> | ||
public double Longitude => longitude; | ||
|
||
/// <summary> | ||
/// The altitude of the waypoint | ||
/// </summary> | ||
public double Altitude => altitude; | ||
|
||
/// <summary> | ||
/// The current state of the waypoint | ||
/// </summary> | ||
public WaypointState State => state; | ||
|
||
/// <summary> | ||
/// Deserializes the waypoint, creating an actual waypoint from it | ||
/// </summary> | ||
/// <returns>A newly created waypoint from the serialized waypoint's parameters</returns> | ||
public virtual Waypoint Deserialize() => new(latitude, longitude, altitude, bodyName, name, state); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
namespace SpaceWarp.API.Game.Waypoints; | ||
|
||
/// <summary> | ||
/// This contains the state for a waypoint | ||
/// </summary> | ||
public enum WaypointState | ||
{ | ||
/// <summary> | ||
/// The waypoint is shown in the flight/map view | ||
/// </summary> | ||
Visible, | ||
|
||
/// <summary> | ||
/// The waypoint is hidden in the flight/map view | ||
/// </summary> | ||
Hidden | ||
} |