Skip to content

Commit

Permalink
Merge pull request #16 from Li0n-0/DEV
Browse files Browse the repository at this point in the history
v0.17
  • Loading branch information
Li0n-0 committed Jan 31, 2018
2 parents e113dae + 079f06d commit cb81349
Show file tree
Hide file tree
Showing 7 changed files with 81 additions and 33 deletions.
Binary file modified GameData/AntennaHelper/AntennaHelper.dll
Binary file not shown.
2 changes: 1 addition & 1 deletion GameData/AntennaHelper/AntennaHelper.version
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
"VERSION":
{
"MAJOR":0,
"MINOR":16,
"MINOR":17,
"PATCH":0,
"BUILD":0
},
Expand Down
66 changes: 48 additions & 18 deletions Source/AntennaHelper/AHShipList.cs
Original file line number Diff line number Diff line change
Expand Up @@ -454,12 +454,15 @@ private void CommNetInit ()
[KSPAddon (KSPAddon.Startup.TrackingStation, false)]
public class AHShipListListenerTR : MonoBehaviour
{
private bool isReady = false;

public void Start ()
{
AHShipList.shipListReady = false;

GameEvents.CommNet.OnCommStatusChange.Add (CommNetChange);

StartCoroutine ("ParseVesselsConnection");
}

public void OnDestroy ()
Expand All @@ -469,41 +472,68 @@ public void OnDestroy ()

private void CommNetChange (Vessel v, bool b)
{
StartCoroutine ("CommNetChangeCoroutine", v);
// Debug.Log ("[AH] CommNet Update for vessel : " + v.GetName ());

if (isReady) {
StartCoroutine ("ParseOneVesselConnection", v);
}
}

private IEnumerator CommNetChangeCoroutine (Vessel v)
private IEnumerator ParseOneVesselConnection (Vessel v)
{
// add the real signal now
yield return new WaitForSeconds (.1f);
isReady = false;
AHShipList.shipListReady = false;

yield return new WaitForSeconds (.2f);

MapObject originalTarget = PlanetariumCamera.fetch.target;
float originalDistance = PlanetariumCamera.fetch.Distance;

PlanetariumCamera.fetch.SetTarget (v.mapObject);

PlanetariumCamera.fetch.SetTarget (originalTarget);
PlanetariumCamera.fetch.SetDistance (originalDistance);

yield return new WaitForSeconds (.2f);

AHShipList.ComputeRealSignal (v);

if (AllVesselAreUpToDate ()) {
yield return new WaitForSeconds (.1f);
AHShipList.ComputeAllSignal ();
AHShipList.shipListReady = true;
}
AHShipList.shipListReady = true;
isReady = true;
}

private bool AllVesselAreUpToDate ()
private IEnumerator ParseVesselsConnection ()
{
foreach (KeyValuePair<string, Dictionary<string, string>> kvp in AHShipList.GetShipList (false, true)) {
if (kvp.Value ["realSignal"] == "") {
return false;
}
Dictionary<string, Dictionary<string, string>> ahShipList = AHShipList.GetShipList (false, true);
List<Vessel> vesselList = FlightGlobals.Vessels.FindAll (v => ahShipList.ContainsKey (v.id.ToString ()));
// WaitForSeconds timer = new WaitForSeconds (.2f);

yield return new WaitForSeconds (.6f);
MapObject originalTarget = PlanetariumCamera.fetch.target;
float originalDistance = PlanetariumCamera.fetch.Distance;

foreach (Vessel v in vesselList) {
PlanetariumCamera.fetch.SetTarget (v.mapObject);
}
foreach (KeyValuePair<string, Dictionary<string, string>> kvp in AHShipList.GetShipList (false, true)) {
AHShipList.ComputeRealSignal (FlightGlobals.Vessels.Find (v => v.id.ToString () == kvp.Key));
PlanetariumCamera.fetch.SetTarget (originalTarget);
PlanetariumCamera.fetch.SetDistance (originalDistance);

yield return new WaitForSeconds (.2f);

foreach (Vessel v in vesselList) {
// Debug.Log ("[AH] Computing real signal for : " + v.GetName ());
AHShipList.ComputeRealSignal (v);
}
return true;

isReady = true;
AHShipList.shipListReady = true;
// Debug.Log ("[AH] shipList is now ready");
// foreach (KeyValuePair<string, Dictionary<string, string>> kvp in AHShipList.GetShipList (false, true)) {
// Debug.Log ("[AH]");
// foreach (KeyValuePair<string, string> kvp2 in kvp.Value) {
// Debug.Log ("[AH] " + kvp2.Key + " : " + kvp2.Value);
// }
// Debug.Log ("[AH]");
// }
}
}
}
Expand Down
34 changes: 26 additions & 8 deletions Source/AntennaHelper/AHTrackingStation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public class AHTrackingStation : MonoBehaviour
private float trackingStationLvl;
private double dsnPower;

private WaitForSeconds waitFor;

// GUI
private ToolbarControl toolbarControl;
private Rect rectMainWindow, rectEditorShipWindow;
Expand All @@ -37,6 +39,8 @@ public void Start ()
trackingStationLvl = ScenarioUpgradeableFacilities.GetFacilityLevel (SpaceCenterFacility.TrackingStation);
dsnPower = GameVariables.Instance.GetDSNRange (trackingStationLvl);

waitFor = new WaitForSeconds (.1f);

GameEvents.onPlanetariumTargetChanged.Add (NewTarget);
GameEvents.OnMapFocusChange.Add (NewTarget);
GameEvents.CommNet.OnCommStatusChange.Add (CommNetUpdate);
Expand Down Expand Up @@ -102,19 +106,33 @@ private void NewTarget (MapObject targetMapObject = null)

private void CommNetUpdate (Vessel v, bool b)
{
StartCoroutine ("CommNetUpdateCoroutine");
// Debug.Log ("[AH] CommNet Update fired");
if (!inCoroutine) {
StartCoroutine ("CommNetUpdateCoroutine");
}
}

private bool inCoroutine = false;
private IEnumerator CommNetUpdateCoroutine ()
{
yield return new WaitForSeconds (.5f);
if (AHShipList.shipListReady) {
if (listMarkers != null) {
DestroyMarkers ();
}
GetListsShip ();
CreateMarkers ();
inCoroutine = true;

yield return waitFor;

while (!AHShipList.shipListReady) {
yield return waitFor;
}

// Debug.Log ("[AH] ship list is ready");

if (listMarkers != null) {
DestroyMarkers ();
}

GetListsShip ();
CreateMarkers ();

inCoroutine = false;
}

private void GetListShipTransmitter ()
Expand Down
12 changes: 6 additions & 6 deletions Source/AntennaHelper/AntennaHelper.userprefs
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
<Properties StartupItem="AntennaHelper.csproj">
<MonoDevelop.Ide.Workspace ActiveConfiguration="Debug" PreferredExecutionTarget="Unity.Instance.Unity Editor" />
<MonoDevelop.Ide.Workbench ActiveDocument="AHFlight.cs">
<MonoDevelop.Ide.Workbench ActiveDocument="AHShipList.cs">
<Files>
<File FileName="AHEditorWindows.cs" Line="1" Column="1" />
<File FileName="AHShipList.cs" Line="56" Column="6" />
<File FileName="AHEditor.cs" Line="1" Column="1" />
<File FileName="AHEditorWindows.cs" Line="280" Column="6" />
<File FileName="AHShipList.cs" Line="491" Column="16" />
<File FileName="AHMapMarker.cs" Line="1" Column="1" NotebookId="1" />
<File FileName="AHUtil.cs" Line="1" Column="1" NotebookId="1" />
<File FileName="AHMapViewWindow.cs" Line="1" Column="1" NotebookId="1" />
<File FileName="AHSettings.cs" Line="1" Column="1" NotebookId="1" />
<File FileName="AHTrackingStation.cs" Line="1" Column="1" NotebookId="1" />
<File FileName="AHFlight.cs" Line="433" Column="53" NotebookId="1" />
<File FileName="AHTrackingStation.cs" Line="105" Column="41" NotebookId="1" />
<File FileName="AHFlight.cs" Line="1" Column="1" NotebookId="1" />
<File FileName="AHEditor.cs" Line="1" Column="1" NotebookId="1" />
</Files>
</MonoDevelop.Ide.Workbench>
<MonoDevelop.Ide.DebuggingService.Breakpoints>
Expand Down
Binary file not shown.
Binary file modified Source/AntennaHelper/obj/Debug/AntennaHelper.dll
Binary file not shown.

0 comments on commit cb81349

Please sign in to comment.