Skip to content

Commit

Permalink
Capitalize methods and more formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
dgfl-gh authored and siimav committed Dec 21, 2020
1 parent 0387d78 commit ca1354b
Show file tree
Hide file tree
Showing 4 changed files with 104 additions and 122 deletions.
54 changes: 24 additions & 30 deletions Source/CameraFixer.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Linq;
using UnityEngine;

/******************************************************************************
Expand Down Expand Up @@ -33,61 +34,54 @@ namespace regexKSP
public class CameraFixer : MonoBehaviour
{
public static bool ready = false;
public static bool hasKopernicus = false;
public static bool foundKopernicus = false;
private static bool? _hasKopernicus = false;

public static bool FoundKopernicus()
public static bool FoundKopernicus
{
foreach (AssemblyLoader.LoadedAssembly a in AssemblyLoader.loadedAssemblies)
get
{
if (a.assembly.GetName().Name.ToLowerInvariant().Contains("kopernicus"))
if (!_hasKopernicus.HasValue)
{
return true;
_hasKopernicus = false;
foreach (AssemblyLoader.LoadedAssembly a in AssemblyLoader.loadedAssemblies)
{
if (a.assembly.GetName().Name.ToLowerInvariant().Contains("kopernicus"))
{
_hasKopernicus = true;
}
}
}
}

return false;
return _hasKopernicus.Value;
}
}

public void Start()
{
if (!foundKopernicus)
{
hasKopernicus = FoundKopernicus();
foundKopernicus = true;
}

if (hasKopernicus) { return; }
if (HighLogic.LoadedScene.Equals(GameScenes.MAINMENU)) { ready = true; }
if (!ready) { return; }
if (FoundKopernicus) return;
if (HighLogic.LoadedScene.Equals(GameScenes.MAINMENU)) ready = true;
if (!ready) return;

if (HighLogic.LoadedScene == GameScenes.SPACECENTER)
{
PQSCity ksc = null;
foreach (PQSCity city in Resources.FindObjectsOfTypeAll(typeof(PQSCity)))
{
if (city.name == "KSC")
{
ksc = city;
break;
}
}
var ksc = Resources.FindObjectsOfTypeAll<PQSCity>().FirstOrDefault(city => city.name == "KSC");

if (ksc == null)
{
Debug.Log("KSCSwitcher could not find KSC to fix the camera.");
return;
}
foreach (SpaceCenterCamera2 cam in Resources.FindObjectsOfTypeAll(typeof(SpaceCenterCamera2)))
foreach (var cam in Resources.FindObjectsOfTypeAll<SpaceCenterCamera2>())
{
if (ksc.repositionToSphere || ksc.repositionToSphereSurface)
{
CelestialBody Kerbin = FlightGlobals.Bodies.Find(body => body.name == ksc.sphere.name);
if (Kerbin == null)
CelestialBody kerbin = FlightGlobals.Bodies.Find(body => body.name == ksc.sphere.name);
if (kerbin == null)
{
Debug.Log("KSCSwitcher could not find find the CelestialBody specified as KSC's sphere.");
return;
}
double nomHeight = Kerbin.pqsController.GetSurfaceHeight((Vector3d)ksc.repositionRadial.normalized) - Kerbin.Radius;
double nomHeight = kerbin.pqsController.GetSurfaceHeight(ksc.repositionRadial.normalized) - kerbin.Radius;
if (ksc.repositionToSphereSurface)
{
nomHeight += ksc.repositionRadiusOffset;
Expand Down
2 changes: 1 addition & 1 deletion Source/KSCLoader.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
Expand Down
Loading

0 comments on commit ca1354b

Please sign in to comment.