Skip to content

Commit

Permalink
Some refactoring and cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
siimav committed Jul 22, 2024
1 parent b8ee85a commit ca59161
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 33 deletions.
6 changes: 3 additions & 3 deletions Source/CameraFixer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void Start()

if (ksc == null)
{
Debug.Log("KSCSwitcher could not find KSC to fix the camera.");
Debug.Log("[KSCSwitcher] could not find KSC to fix the camera.");
return;
}
foreach (var cam in Resources.FindObjectsOfTypeAll<SpaceCenterCamera2>())
Expand All @@ -78,7 +78,7 @@ public void Start()
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.");
Debug.Log("[KSCSwitcher] could not find find the CelestialBody specified as KSC's sphere.");
return;
}
double nomHeight = kerbin.pqsController.GetSurfaceHeight(ksc.repositionRadial.normalized) - kerbin.Radius;
Expand All @@ -93,7 +93,7 @@ public void Start()
cam.altitudeInitial = 0f - (float)ksc.repositionRadiusOffset;
}
cam.ResetCamera();
Debug.Log("KSCSwitcher fixed the Space Center camera.");
Debug.Log("[KSCSwitcher] fixed the Space Center camera.");
}
}
}
Expand Down
34 changes: 16 additions & 18 deletions Source/GrassSeasoner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,10 @@

namespace regexKSP
{
public class GrassSeasoner
public static class GrassSeasoner
{
public static Material[] KSCGrassMaterials { get; private set; } = null;
public static GrassSeasoner Instance;

public static Color GroundColor
{
get
Expand All @@ -32,24 +32,22 @@ public static void SetGrassColor(Color newColor)
public static bool TryGetKSCGrassColor(CelestialBody home, ConfigNode pqsCity, out Color col)
{
col = new Color();
if (pqsCity.HasValue("changeGrassColor"))
if (pqsCity?.HasValue("changeGrassColor") ?? false &&
bool.TryParse(pqsCity.GetValue("changeGrassColor"), out bool btmp) && btmp)
{
if (bool.TryParse(pqsCity.GetValue("changeGrassColor"), out bool btmp) && btmp)
if (pqsCity.HasValue("grassColor"))
{
if (pqsCity.HasValue("grassColor"))
{
if (pqsCity.TryGetValue("grassColor", ref col))
{
Debug.Log($"KSCSwitcher found KSC grass color {col} from config");
return true;
}
}
else if (double.TryParse(pqsCity.GetValue("latitude"), out double lat) && double.TryParse(pqsCity.GetValue("longitude"), out double lon))
if (pqsCity.TryGetValue("grassColor", ref col))
{
if(TryParseGroundColor(home, lat, lon, out col, 2f))
return true;
Debug.Log($"[KSCSwitcher] found KSC grass color {col} from config");
return true;
}
}
else if (double.TryParse(pqsCity.GetValue("latitude"), out double lat) && double.TryParse(pqsCity.GetValue("longitude"), out double lon))
{
if (TryParseGroundColor(home, lat, lon, out col, 2f))
return true;
}
}
return false;
}
Expand Down Expand Up @@ -83,7 +81,7 @@ public static bool TryParseGroundColor(CelestialBody body, double lat, double lo
y = Mathf.Clamp(y, 0, texture.Height);

col = texture.GetPixelColor(x, y);
Debug.Log($"KSCSwitcher parsed {col} from color map at {x}, {y}");
Debug.Log($"[KSCSwitcher] parsed {col} from color map at {x}, {y}");
col *= colorMult;
col.a = 1;
return true;
Expand Down Expand Up @@ -117,7 +115,7 @@ public class EditorGrassFixer : MonoBehaviour
{
public void Start()
{
Debug.Log($"KSCSwitcher editor grass fixer start");
Debug.Log($"[KSCSwitcher] editor grass fixer start");
GameObject scenery = GameObject.Find("VABscenery") ?? GameObject.Find("SPHscenery");
Material material = scenery?.GetChild("ksc_terrain")?.GetComponent<Renderer>()?.sharedMaterial;

Expand All @@ -129,7 +127,7 @@ public void Start()
return;

material.color = c * 1.5f;
Debug.Log($"KSCSwitcher editor grass fixer end");
Debug.Log($"[KSCSwitcher] editor grass fixer end");
}
}
}
6 changes: 3 additions & 3 deletions Source/KSCLoader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ private void OnGameStateCreated(Game game)
else
{
KSCSwitcher.SetSiteAndResetCamera(site);
Debug.Log("KSCSwitcher set the launch site to the last site, " + l.lastSite);
Debug.Log("[KSCSwitcher] set the launch site to the last site, " + l.lastSite);
return;
}
}
Expand All @@ -61,13 +61,13 @@ private void OnGameStateCreated(Game game)
ConfigNode site = Sites.GetSiteByName(Sites.defaultSite);
if (site == null)
{
Debug.LogError("KSCSwitcher found a default site name but could not retrieve the site config: " + Sites.defaultSite);
Debug.LogError("[KSCSwitcher] found a default site name but could not retrieve the site config: " + Sites.defaultSite);
return;
}
else
{
KSCSwitcher.SetSiteAndResetCamera(site);
Debug.Log("KSCSwitcher set the initial launch site to the default" + Sites.defaultSite);
Debug.Log("[KSCSwitcher] set the initial launch site to the default" + Sites.defaultSite);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions Source/KSCSiteManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@ public KSCSiteManager()
}
else
{
Debug.Log("KSCSwitcher No LaunchSites node found!");
Debug.Log("[KSCSwitcher] No LaunchSites node found!");
}

Debug.Log("KSCSwitcher loaded " + Sites.Count + " launch sites.");
Debug.Log("[KSCSwitcher] loaded " + Sites.Count + " launch sites.");
}

public ConfigNode GetSiteByName(string name)
Expand Down
14 changes: 7 additions & 7 deletions Source/KSCSwitcher.cs
Original file line number Diff line number Diff line change
Expand Up @@ -277,7 +277,7 @@ public static bool SetSiteAndResetCamera(ConfigNode KSC, bool force = false)
{
FloatingOrigin.SetOffset(PSystemSetup.Instance.SCTransform.position);
LastFloatingOriginKSC = KSC.GetValue("name");
Debug.Log("KSCSwitcher set floating point origin offset");
Debug.Log("[KSCSwitcher] set floating point origin offset");
}

return b;
Expand All @@ -303,7 +303,7 @@ public static bool SetSite(ConfigNode KSC)
{
if (!ksc.name.Equals(pqsCity.GetValue("KEYname")))
{
Debug.Log("KSCSwitcher: Could not retrieve KSC to move, reporting failure and moving on.");
Debug.Log("[KSCSwitcher] Could not retrieve KSC to move, reporting failure and moving on.");
return false;
}
}
Expand Down Expand Up @@ -375,7 +375,7 @@ public static bool SetSite(ConfigNode KSC)
}
}

if(GrassSeasoner.TryGetKSCGrassColor(home, pqsCity, out Color col))
if (GrassSeasoner.TryGetKSCGrassColor(home, pqsCity, out Color col))
{
GrassSeasoner.SetGrassColor(col);
}
Expand All @@ -395,7 +395,7 @@ public static bool SetSite(ConfigNode KSC)
}
else
{
Debug.LogError("KSCSwitcher: Could not retrieve KSC to move, reporting failure and moving on.");
Debug.LogError("[KSCSwitcher] Could not retrieve KSC to move, reporting failure and moving on.");
return false;
}

Expand Down Expand Up @@ -476,7 +476,7 @@ private void SetSite(LaunchSite newSite)

private void FocusOnSite(Vector2d loc)
{
Debug.Log("Focusing on site");
Debug.Log("[KSCSwitcher] Focusing on site");
PlanetariumCamera camera = PlanetariumCamera.fetch;
CelestialBody Kerbin = KSCBody;
Vector3d point = ScaledSpace.LocalToScaledSpace(Kerbin.GetWorldSurfacePosition(loc.x, loc.y, 0));
Expand Down Expand Up @@ -517,9 +517,9 @@ private void LoadTextures()
eyeButtonHighlight = GameDatabase.Instance.GetTexture("KSCSwitcher/Plugins/Icons/eye-highlight", false);
magButtonNormal = GameDatabase.Instance.GetTexture("KSCSwitcher/Plugins/Icons/magnifier-normal", false);
}
catch (Exception e)
catch (Exception ex)
{
Debug.Log("Could not load button textures for KSCSwitcher, reverting to old button style: " + e.StackTrace);
Debug.LogError("[KSCSwitcher] Could not load button textures for KSCSwitcher, reverting to old button style: " + ex);
oldButton = true;
}

Expand Down

0 comments on commit ca59161

Please sign in to comment.