Skip to content

Commit

Permalink
Merge pull request #304 from Kopernicus/periodFix
Browse files Browse the repository at this point in the history
Periodfix
StollD authored Aug 8, 2018
2 parents b00d1ac + 495e9bc commit 2c78400
Showing 2 changed files with 27 additions and 22 deletions.
41 changes: 21 additions & 20 deletions src/Kopernicus/Configuration/OrbitLoader.cs
Original file line number Diff line number Diff line change
@@ -72,12 +72,12 @@ public String referenceBody

// How inclined is the orbit
[ParserTarget("inclination")]
public NumericParser<Double> inclination
public NumericParser<Double> inclination
{
get { return Value.orbit.inclination; }
set { Value.orbit.inclination = value; }
}

// How excentric is the orbit
[ParserTarget("eccentricity")]
public NumericParser<Double> eccentricity
@@ -135,7 +135,7 @@ public NumericParser<Double> epoch
get { return Value.orbit.epoch; }
set { Value.orbit.epoch = value; }
}

// Orbit renderer color
[ParserTarget("color")]
[KittopiaDescription("The color of the orbit line in the Tracking Station")]
@@ -148,7 +148,7 @@ public ColorParser color
return generatedBody.orbitRenderer.nodeColor;
}
KopernicusOrbitRendererData data =
(KopernicusOrbitRendererData) PSystemManager.OrbitRendererDataCache[Value];
(KopernicusOrbitRendererData)PSystemManager.OrbitRendererDataCache[Value];
return data.nodeColor;
}
set
@@ -160,7 +160,7 @@ public ColorParser color
else
{
KopernicusOrbitRendererData data =
(KopernicusOrbitRendererData) PSystemManager.OrbitRendererDataCache[Value];
(KopernicusOrbitRendererData)PSystemManager.OrbitRendererDataCache[Value];
data.nodeColor = value;
data.orbitColor = (value.Value * 0.5f).A(data.nodeColor.a);
PSystemManager.OrbitRendererDataCache[Value] = data;
@@ -181,7 +181,7 @@ public ColorParser iconColor
return generatedBody.orbitRenderer.nodeColor;
}
KopernicusOrbitRendererData data =
(KopernicusOrbitRendererData) PSystemManager.OrbitRendererDataCache[Value];
(KopernicusOrbitRendererData)PSystemManager.OrbitRendererDataCache[Value];
return data.nodeColor;
}
set
@@ -193,7 +193,7 @@ public ColorParser iconColor
else
{
KopernicusOrbitRendererData data =
(KopernicusOrbitRendererData) PSystemManager.OrbitRendererDataCache[Value];
(KopernicusOrbitRendererData)PSystemManager.OrbitRendererDataCache[Value];
data.nodeColor = value;
PSystemManager.OrbitRendererDataCache[Value] = data;
}
@@ -263,6 +263,14 @@ public NumericCollectionParser<Single> cameraSmaRatioBounds
}
}

// OrbitalPeriod
[ParserTarget("period")]
public NumericParser<Double> period
{
get { return Value.orbit.period; }
set { generatedBody.celestialBody.Set("customOrbitalPeriod", value.Value); }
}

[ParserTarget("iconTexture")]
public Texture2DParser iconTexture
{
@@ -280,14 +288,6 @@ public void FinalizeOrbit()
FinalizeOrbit(Value);
}

// OrbitalPeriod
[ParserTarget("period")]
public NumericParser<Double> period
{
get { return Value.orbit.period; }
set { OrbitalPeriod(Value, value); }
}

// Parser apply event
void IParserEventSubscriber.Apply(ConfigNode node)
{
@@ -300,7 +300,7 @@ void IParserEventSubscriber.PostApply(ConfigNode node)
{
if (epoch != null)
Value.orbit.epoch += Templates.epoch;

Events.OnOrbitLoaderPostApply.Fire(this, node);
}

@@ -349,7 +349,7 @@ public OrbitLoader(CelestialBody body)

// Add the rendering updater to the celestial body
body.gameObject.AddOrGetComponent<OrbitRendererUpdater>();

// Update the OrbitRenderer data
KopernicusOrbitRendererData data = body.orbitDriver.Renderer == null
? new KopernicusOrbitRendererData(body, PSystemManager.OrbitRendererDataCache[body])
@@ -422,9 +422,11 @@ public static void FinalizeOrbit(CelestialBody body)
}

// Set Orbital Period
public static void OrbitalPeriod(CelestialBody body, Double period)
public static void OrbitalPeriod(CelestialBody body)
{
if (body.orbitDriver != null && body.referenceBody != null)
double period = body.Get<double>("customOrbitalPeriod");

if (period > 0 && body.orbitDriver != null && body.referenceBody != null)
{
body.orbit.period = period;
body.orbit.meanMotion =
@@ -451,4 +453,3 @@ public static void OrbitalPeriod(CelestialBody body, Double period)
}
}
}

8 changes: 6 additions & 2 deletions src/Kopernicus/Injector.cs
Original file line number Diff line number Diff line change
@@ -47,7 +47,7 @@ public static List<Type> ModTypes

// Backup of the old system prefab, in case someone deletes planet templates we need at Runtime (Kittopia)
public static PSystem StockSystemPrefab { get; set; }

// Whether the injector is currently patching the prefab
public static Boolean IsInPrefab { get; private set; }

@@ -167,6 +167,10 @@ public void PostSpawnFixups()
if (body.Get("finalizeBody", false))
OrbitLoader.FinalizeOrbit(body);

// Set Custom OrbitalPeriod
if (body.Has("customOrbitalPeriod"))
OrbitLoader.OrbitalPeriod(body);

// Patch the SOI
if (body.Has("sphereOfInfluence"))
body.sphereOfInfluence = body.Get<Double>("sphereOfInfluence");
@@ -250,4 +254,4 @@ public void OnDestroy()
Logger.Default.Flush();
}
}
}
}

0 comments on commit 2c78400

Please sign in to comment.