private void writePrimaryUpdate()
{
if (isInFlight)
{
//Write vessel status
KLFVesselUpdate update = getVesselUpdate(FlightGlobals.ActiveVessel);
//Update the player vessel info
VesselStatusInfo my_status = new VesselStatusInfo();
my_status.info = update;
my_status.orbit = FlightGlobals.ActiveVessel.orbit;
my_status.color = KLFVessel.generateActiveColor(playerName);
my_status.ownerName = playerName;
my_status.vesselName = FlightGlobals.ActiveVessel.vesselName;
my_status.lastUpdateTime = UnityEngine.Time.realtimeSinceStartup;
if (playerStatus.ContainsKey(playerName))
playerStatus[playerName] = my_status;
else
playerStatus.Add(playerName, my_status);
enqueuePluginInteropMessage(KLFCommon.PluginInteropMessageID.PRIMARY_PLUGIN_UPDATE, KSP.IO.IOUtils.SerializeToBinary(update));
}
else
{
//Check if the player is building a ship
bool building_ship = HighLogic.LoadedSceneIsEditor
&& EditorLogic.fetch != null
&& EditorLogic.fetch.ship != null && EditorLogic.fetch.ship.Count > 0
&& EditorLogic.fetch.shipNameField != null
&& EditorLogic.fetch.shipNameField.Text != null && EditorLogic.fetch.shipNameField.Text.Length > 0;
String[] status_array = null;
if (building_ship)
{
status_array = new String[3];
//Vessel name
String shipname = EditorLogic.fetch.shipNameField.Text;
if (shipname.Length > MAX_VESSEL_NAME_LENGTH)
shipname = shipname.Substring(0, MAX_VESSEL_NAME_LENGTH); //Limit vessel name length
status_array[1] = "Building " + shipname;
//Vessel details
status_array[2] = "Parts: " + EditorLogic.fetch.ship.Count;
}
else
{
status_array = new String[2];
switch (HighLogic.LoadedScene)
{
case GameScenes.SPACECENTER:
status_array[1] = "At Space Center";
break;
case GameScenes.EDITOR:
status_array[1] = "In Vehicle Assembly Building";
break;
case GameScenes.SPH:
status_array[1] = "In Space Plane Hangar";
break;
case GameScenes.TRACKSTATION:
status_array[1] = "At Tracking Station";
break;
default:
status_array[1] = String.Empty;
break;
}
}
//Check if player is idle
if (isIdle)
status_array[1] = "(Idle) " + status_array[1];
status_array[0] = playerName;
//Serialize the update
byte[] update_bytes = KSP.IO.IOUtils.SerializeToBinary(status_array);
enqueuePluginInteropMessage(KLFCommon.PluginInteropMessageID.PRIMARY_PLUGIN_UPDATE, update_bytes);
VesselStatusInfo my_status = statusArrayToInfo(status_array);
if (playerStatus.ContainsKey(playerName))
playerStatus[playerName] = my_status;
else
playerStatus.Add(playerName, my_status);
}
}