-
Notifications
You must be signed in to change notification settings - Fork 25
4.0 SMInterface.dll
Section 1 Accessing Ship Manifest
Section 2 Basic Operations
Section 3 Configuration File
SMInterface.dll
(Deprecated, No longer used. Replaced by SMWrapper.cs reflection class for inclusion in devloper code.)
Ship Manifest provides an interface to allow for detection of Crew transfers in progress. Realism Mode introduces a delay (7 second default) that freezes the interface until the completion of the transfer process. This can cause issues with other mods that manipulate kerbals. if the user initiates a change that affects the kerbal being moved, a race condition can occur, and cause "duplicate" or ghost kerbals to exist.
This interface exposes the details of the transfer and provides notification of when a transfer is in progress.
The code for the dll is shown as follows:
using System;
using System.Reflection;
using System.Linq;
namespace ShipManifest
{
public interface ICrewTransfer
{
bool CrewXferActive { get; set; }
bool IsStockXfer { get; }
bool OverrideStockCrewXfer { get; }
double CrewXferDelaySec { get; }
bool IsSeat2SeatXfer { get; }
double Seat2SeatXferDelaySec { get; }
bool IvaDelayActive { get; }
Guid XferVesselID { get; }
Part FromPart { get; }
Part ToPart { get; }
ProtoCrewMember FromCrewMember { get; }
ProtoCrewMember ToCrewMember { get; }
InternalSeat FromSeat { get; }
InternalSeat ToSeat { get; }
}
public static class SMInterface
{
private static bool _smChecked = false;
private static bool _smInstalled = false;
public static bool IsSMInstalled
{
get
{
if (!_smChecked)
{
string assemblyName = "ShipManifest";
var assemblies = AppDomain.CurrentDomain.GetAssemblies();
var assembly = (from a in assemblies
where a.FullName.Contains(assemblyName)
select a).SingleOrDefault();
if (assembly != null)
_smInstalled = true;
else
_smInstalled = false;
_smChecked = true;
}
return _smInstalled;
}
}
public static ICrewTransfer GetCrewTransfer()
{
ICrewTransfer _ISMobj = null;
Type SMAddonType = AssemblyLoader.loadedAssemblies.SelectMany(a => a.assembly.GetExportedTypes()).SingleOrDefault(t => t.FullName == "ShipManifest.TransferCrew");
if (SMAddonType != null)
{
object crewTransferObj = SMAddonType.GetProperty("Instance", BindingFlags.Public | BindingFlags.Static).GetValue(null, null);
_ISMobj = (ICrewTransfer)crewTransferObj;
}
return _ISMobj;
}
}
}
Accessing SMInterface
The SMInterface.dll is designed to reside in your plugins folder. Create a reference to the dll, and then make a call to interrogate the provided bool IsSMInstalled to determine if Ship Manifest is installed. Once you have established that ShipManifest is installed you can then call GetCrewTransfer() to obtain an instance of the ICrewTransfer Object for your use.
Sample Code:
ShipManifest.ICrewTransfer SMObject = null;
bool IsSMCrewXferActive = false
if (ShipManifest.SMInterface.IsSMInstalled)
{
//Perform your work here
SMObject = SMInterface.GetCrewTransfer();
IsSMCrewXferActive = SMObject.CrewXferActive;
}
ICrewTransfer interface
This interface exposes several properties for third party mod use. They are explained below.
- CrewXferActive { get; set; } This flag indicates when a transfer is in progress.
- IsStockXfer { get; } This flag indicates if the transfer was initiated by the Stock Crew Transfer interface. It stays enabled during the Crew Transfer Process (just like CrewXferActive)
- OverrideStockCrewXfer { get; } This flag indicates if SM is overriding the Stock Crew Transfer process.
- CrewXferDelaySec { get; } This is the number of seconds delay used for the transfer in progress
- IsSeat2SeatXfer { get; } This flag indicates if the transfer is Seat 2 seat, i.e. within the same part.
- Seat2SeatXferDelaySec { get; } This is the number of seconds used for Seat2seat transfer delays
- IvaPortraitDelay { get; } This stores the number of frames that have passed since transfer has completed. In order for the portraits to update properly, a wait period is needed to allow for unity/ksp async callbacks to complete after crew are moved. This is currently hard coded at 20 Frames (update cycles). I then fire an OnVesselChanged event to refresh the portraits.
- IvaDelayActive { get; } This flag indicates the IVA delay is active. This means that the transfer has occurred (kerbals have actually moved) and we are cleaning up portraits.
- XferVesselID { get; } This is the vessel id for the transfer in question
- FromPart { get; } This is the part from which the kerbal is being transferred.
- ToPart { get; } This is the part to which the kerbal is being transferred. It can be the same as the source (Seat2Seat transfers).
- FromCrewMember { get; } This is the crew member being transferred.
- ToCrewMember { get; } This is the crew member that would be swapped if the target seat is occupied. can be null.
- FromSeat { get; } This is the part seat where the kerbal is being moved from. In the case of parts with no internal view, it can be null.
- ToSeat { get; } This is the part seat where the kerbal is being moved to. In the case of parts with no internal view, it can be null.
You can cancel a transfer in progress by setting the CrewXferActive flag to false, as long as the IvadelayActive Flag is also false.