Skip to content

Commit

Permalink
Merge branch 'feature/save-and-load' (Fix #247)
Browse files Browse the repository at this point in the history
  • Loading branch information
djungelorm committed Apr 10, 2016
2 parents a7d9d76 + 72cf99f commit 94516cc
Show file tree
Hide file tree
Showing 5 changed files with 67 additions and 0 deletions.
4 changes: 4 additions & 0 deletions doc/order.txt
Expand Up @@ -20,6 +20,10 @@ SpaceCenter.TargetDockingPort
SpaceCenter.ClearTarget
SpaceCenter.LaunchVesselFromVAB
SpaceCenter.LaunchVesselFromSPH
SpaceCenter.Save
SpaceCenter.Load
SpaceCenter.Quicksave
SpaceCenter.Quickload
SpaceCenter.UT
SpaceCenter.G
SpaceCenter.WarpMode
Expand Down
1 change: 1 addition & 0 deletions doc/src/dictionary.txt
Expand Up @@ -50,6 +50,7 @@ prograde
proto
protobuf
py
quicksave
serializable
streamPort
symlink
Expand Down
3 changes: 3 additions & 0 deletions service/SpaceCenter/CHANGES.txt
@@ -1,3 +1,6 @@
v0.2.4
* Add saving and loading games using SpaceCenter.Save, Load, Quicksave and Quickload (#247)

v0.2.3
* Add support for engine mode switching (#219)
* Engine.GimbalLimit and GimbalLocked now return an error if the engine is not gimballed
Expand Down
50 changes: 50 additions & 0 deletions service/SpaceCenter/src/Services/SpaceCenter.cs
Expand Up @@ -146,6 +146,56 @@ public static void LaunchVesselFromSPH (string name)
throw new YieldException (new ParameterizedContinuationVoid<int> (WaitForVesselSwitch, 0));
}

/// <summary>
/// Save the game with a given name.
/// This will create a save file called <c>name.sfs</c> in the folder of the current save game.
/// </summary>
[KRPCProcedure]
public static void Save (string name)
{
GamePersistence.SaveGame (name, HighLogic.SaveFolder, SaveMode.OVERWRITE);
}

/// <summary>
/// Load the game with the given name.
/// This will create a load a save file called <c>name.sfs</c> from the folder of the current save game.
/// </summary>
[KRPCProcedure]
public static void Load (string name)
{
var game = GamePersistence.LoadGame (name, HighLogic.SaveFolder, true, false);
if (game == null || game.flightState == null || !game.compatible)
throw new ArgumentException ("Failed to load " + name);
if (game.flightState.protoVessels.Count == 0)
throw new ArgumentException ("Failed to load vessel id 0 from " + name);
FlightDriver.StartAndFocusVessel (game, game.flightState.activeVesselIdx);
throw new YieldException (new ParameterizedContinuationVoid<int> (WaitForVesselSwitch, 0));
}

/// <summary>
/// Save a quicksave.
/// </summary>
/// <remarks>
/// This is the same as calling <see cref="Save"/> with the name "quicksave".
/// </remarks>
[KRPCProcedure]
public static void Quicksave ()
{
Save ("quicksave");
}

/// <summary>
/// Load a quicksave.
/// </summary>
/// <remarks>
/// This is the same as calling <see cref="Load"/> with the name "quicksave".
/// </remarks>
[KRPCProcedure]
public static void Quickload ()
{
Load ("quicksave");
}

/// <summary>
/// The current universal time in seconds.
/// </summary>
Expand Down
9 changes: 9 additions & 0 deletions service/SpaceCenter/test/test_spacecenter.py
Expand Up @@ -115,6 +115,15 @@ def test_clear_target(self):
self.assertEqual(None, self.sc.target_vessel)
self.assertEqual(None, self.sc.target_docking_port)

def test_save_and_load(self):
name = self.vessel.name
self.sc.save('test_save_and_load')
self.vessel.name = 'vessel_name_before_load'
time.sleep(0.1)
self.assertEqual(self.vessel.name, 'vessel_name_before_load')
self.sc.load('test_save_and_load')
self.assertEqual(self.vessel.name, name)

def test_ut(self):
ut = self.sc.ut
time.sleep(1)
Expand Down

0 comments on commit 94516cc

Please sign in to comment.