private void handleVesselUpdate(KLFVesselUpdate vessel_update)
{
if (!isInFlight)
{
//While not in-flight don't create KLF vessel, just store the active vessel status info
if (vessel_update.state == State.ACTIVE) {
VesselStatusInfo status = new VesselStatusInfo();
status.info = vessel_update;
status.ownerName = vessel_update.player;
status.vesselName = vessel_update.name;
status.orbit = null;
status.lastUpdateTime = UnityEngine.Time.realtimeSinceStartup;
status.color = KLFVessel.generateActiveColor(status.ownerName);
if (playerStatus.ContainsKey(status.ownerName))
playerStatus[status.ownerName] = status;
else
playerStatus.Add(status.ownerName, status);
}
return; //Don't handle updates while not flying a ship
}
//Build the key for the vessel
System.Text.StringBuilder sb = new System.Text.StringBuilder();
sb.Append(vessel_update.player);
sb.Append(vessel_update.id.ToString());
String vessel_key = sb.ToString();
KLFVessel vessel = null;
//Try to find the key in the vessel dictionary
VesselEntry entry;
if (vessels.TryGetValue(vessel_key, out entry))
{
vessel = entry.vessel;
if (vessel == null || vessel.gameObj == null || vessel.vesselName != vessel_update.name)
{
//Delete the vessel if it's null or needs to be renamed
vessels.Remove(vessel_key);
if (vessel != null && vessel.gameObj != null)
GameObject.Destroy(vessel.gameObj);
vessel = null;
}
else
{
//Update the entry's timestamp
VesselEntry new_entry = new VesselEntry();
new_entry.vessel = entry.vessel;
new_entry.lastUpdateTime = UnityEngine.Time.realtimeSinceStartup;
vessels[vessel_key] = new_entry;
}
}
if (vessel == null) {
//Add the vessel to the dictionary
vessel = new KLFVessel(vessel_update.name, vessel_update.player, vessel_update.id);
entry = new VesselEntry();
entry.vessel = vessel;
entry.lastUpdateTime = UnityEngine.Time.realtimeSinceStartup;
if (vessels.ContainsKey(vessel_key))
vessels[vessel_key] = entry;
else
vessels.Add(vessel_key, entry);
/*Queue this update for the next update call because updating a vessel on the same step as
* creating it usually causes problems for some reason */
vesselUpdateQueue.Enqueue(vessel_update);
}
else
applyVesselUpdate(vessel_update, vessel); //Apply the vessel update to the existing vessel
}