Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: Kopernicus/Kopernicus
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: ad7b65670d8d
Choose a base ref
...
head repository: Kopernicus/Kopernicus
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: 41ed0418cc1c
Choose a head ref
  • 2 commits
  • 2 files changed
  • 1 contributor

Commits on Oct 29, 2018

  1. Copy the full SHA
    79e5d51 View commit details
  2. Copy the full SHA
    41ed041 View commit details
Showing with 40 additions and 36 deletions.
  1. +37 −26 src/Kopernicus.Components/KSC.cs
  2. +3 −10 src/Kopernicus/Configuration/SpaceCenterLoader.cs
63 changes: 37 additions & 26 deletions src/Kopernicus.Components/KSC.cs
Original file line number Diff line number Diff line change
@@ -26,6 +26,7 @@
using System;
using System.Linq;
using UnityEngine;
using UnityEngine.Networking;

namespace Kopernicus
{
@@ -34,32 +35,52 @@ namespace Components
/// <summary>
/// Stores information about the KSC
/// </summary>
public class KSC : MonoBehaviour
public class KSC : SerializableMonoBehaviour
{
// PQSCity
[SerializeField]
public Double? latitude;
[SerializeField]
public Double? longitude;
[SerializeField]
public Vector3? reorientInitialUp;
[SerializeField]
public Vector3? repositionRadial;
[SerializeField]
public Boolean? repositionToSphere;
[SerializeField]
public Boolean? repositionToSphereSurface;
[SerializeField]
public Boolean? repositionToSphereSurfaceAddHeight;
[SerializeField]
public Boolean? reorientToSphere;
[SerializeField]
public Double? repositionRadiusOffset;
[SerializeField]
public Double? lodvisibleRangeMult;
[SerializeField]
public Single? reorientFinalAngle;

// PQSMod_MapDecalTangent
[SerializeField]
public Vector3? position;
[SerializeField]
public Double? radius;
[SerializeField]
public Double? heightMapDeformity;
[SerializeField]
public Double? absoluteOffset;
[SerializeField]
public Boolean? absolute;
[SerializeField]
public Double? decalLatitude;
[SerializeField]
public Double? decalLongitude;

// Material
[SerializeField]
public Texture2D mainTexture;
[SerializeField]
public Color? color;

// Mods
@@ -70,41 +91,31 @@ public class KSC : MonoBehaviour
// Apply the patches
public void Start()
{
// Get the KSC-object from Kerbins PQS
if (FlightGlobals.Bodies != null)
body = GetComponent<CelestialBody>();
Debug.Log(body);
if (!body.isHomeWorld)
{
body = FlightGlobals.Bodies.First(b => b.isHomeWorld);
ksc = body.pqsController.GetComponentsInChildren<PQSCity>(true).First(m => m.name == "KSC");
mapDecal = body.pqsController.GetComponentsInChildren<PQSMod_MapDecalTangent>(true).First(m => m.name == "KSC");
Destroy(this);
return;
}
else
{
CelestialBody[] bodies = Resources.FindObjectsOfTypeAll<CelestialBody>();
foreach (CelestialBody b in bodies)
{
if (!b.isHomeWorld)
continue;

if (b.pqsController == null)
continue;
Debug.Log(this + " " + body);
Debug.Log(radius);

ksc = body.pqsController.GetComponentsInChildren<PQSCity>(true).First(m => m.name == "KSC");
mapDecal = body.pqsController.GetComponentsInChildren<PQSMod_MapDecalTangent>(true)
.First(m => m.name == "KSC");

ksc = b.pqsController.GetComponentsInChildren<PQSCity>(true).First(m => m.name == "KSC");
if (ksc != null)
{
body = b;
mapDecal = body.pqsController.GetComponentsInChildren<PQSMod_MapDecalTangent>(true).First(m => m.name == "KSC");
break;
}
}
}
if (ksc == null)
{
Debug.LogError("[Kopernicus] KSC: Unable to find homeworld body with PQSCity named KSC");
return;
}

if (mapDecal == null)
{
Debug.LogError("[Kopernicus] KSC: Unable to find homeworld body with PQSMod_MapDecalTangent named KSC");
Debug.LogError(
"[Kopernicus] KSC: Unable to find homeworld body with PQSMod_MapDecalTangent named KSC");
return;
}

@@ -179,7 +190,7 @@ public void Start()
if (lodvisibleRangeMult.HasValue)
{
foreach (PQSCity.LODRange lodRange in ksc.lod)
lodRange.visibleRange *= (Single)lodvisibleRangeMult.Value;
lodRange.visibleRange *= (Single) lodvisibleRangeMult.Value;
}
else
{
13 changes: 3 additions & 10 deletions src/Kopernicus/Configuration/SpaceCenterLoader.cs
Original file line number Diff line number Diff line change
@@ -356,12 +356,6 @@ void IParserEventSubscriber.Apply(ConfigNode node)
void IParserEventSubscriber.PostApply(ConfigNode node)
{
Events.OnSpaceCenterLoaderPostApply.Fire(this, node);

// Only keep the space center settings if the body is the homeworld
if (!generatedBody.celestialBody.isHomeWorld)
{
UnityEngine.Object.Destroy(Value.gameObject);
}
}

/// <summary>
@@ -376,7 +370,7 @@ public SpaceCenterLoader()
}

// Store values
Value = new GameObject("SpaceCenter " + generatedBody.name).AddComponent<KSC>();
Value = generatedBody.celestialBody.gameObject.AddComponent<KSC>();
UnityEngine.Object.DontDestroyOnLoad(Value);
}

@@ -393,11 +387,10 @@ public SpaceCenterLoader(CelestialBody body)
}

// Store values
Value = UnityEngine.Object.FindObjectsOfType<KSC>()
.FirstOrDefault(k => k.name == "SpaceCenter " + body.transform.name);
Value = body.GetComponent<KSC>();
if (Value == null)
{
Value = new GameObject("SpaceCenter " + body.transform.name).AddComponent<KSC>();
Value = generatedBody.celestialBody.gameObject.AddComponent<KSC>();
Value.Start();
UnityEngine.Object.DontDestroyOnLoad(Value);
}