Skip to content

Commit

Permalink
Load PQS presets
Browse files Browse the repository at this point in the history
StollD committed Apr 5, 2018
1 parent 55ce4cd commit 7ebb846
Showing 3 changed files with 56 additions and 2 deletions.
36 changes: 35 additions & 1 deletion src/Kopernicus/Configuration/Loader.cs
Original file line number Diff line number Diff line change
@@ -44,6 +44,9 @@ public class Loader : IParserEventSubscriber
// Name of the config type which holds the asteroid definition
public const String asteroidNodeName = "Asteroid";

// Name of the config type which holds the pqs subdivision definitions
public const String presetNodeName = "Preset";

// Currently edited body
public static Body currentBody { get; set; }

@@ -244,6 +247,37 @@ void IParserEventSubscriber.PostApply(ConfigNode node)
Logger.Default.SetAsActive();
}

// Load all of the PQS Presets
foreach (ConfigNode presetNode in node.GetNodes(presetNodeName))
{
// Attempt to create the Preset
try
{
PQSCache.PQSPreset preset = new PQSCache.PQSPreset();
preset.Load(presetNode);
if (PQSCache.PresetList.presets.Any(p => p.name == preset.name))
{
Logger.Default.Log("[Kopernicus]: Configuration.Loader: Failed to load Preset: " + preset.name);
continue;
}
PQSCache.PresetList.presets.Add(preset);

// Display name
String displayName = preset.name;
if (presetNode.HasValue("displayName"))
{
displayName = presetNode.GetValue("displayName");
}
Templates.PresetDisplayNames.Add(displayName);
Logger.Default.Log("[Kopernicus]: Configuration.Loader: Loaded Preset: " + preset.name);
}
catch
{
Logger.Default.Log("[Kopernicus]: Configuration.Loader: Failed to load Preset: " + presetNode.GetValue("name"));
throw new Exception("Failed to load Asteroid: " + presetNode.GetValue("name"));
}
}

// Glue all the orbits together in the defined pattern
foreach (KeyValuePair<String, Body> body in bodies)
{
@@ -300,7 +334,7 @@ void IParserEventSubscriber.PostApply(ConfigNode node)

// Sort by distance from parent (discover how this effects local bodies)
RecursivelySortBodies(systemPrefab.rootBody);

// Fix doubled flightGlobals
List<Int32> numbers = new List<Int32>() { 0, 1 };
Int32 index = bodies.Sum(b => b.Value.generatedBody.flightGlobalsIndex);
8 changes: 8 additions & 0 deletions src/Kopernicus/RuntimeUtility/RuntimeUtility.cs
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@
using System.Linq;
using System.Reflection;
using Kopernicus.OnDemand;
using KSP.UI.Screens.Settings.Controls;
using UnityEngine;

namespace Kopernicus
@@ -340,6 +341,13 @@ void LateUpdate()
body.afg.lightDot = Mathf.Clamp01(Vector3.Dot(planet2cam, body.afg.mainCamera.transform.position - star_.transform.position) * body.afg.dawnFactor);
body.afg.GetComponent<Renderer>().material.SetFloat("_lightDot", body.afg.lightDot);
}

// Update the names of the presets in the settings dialog
foreach (SettingsTerrainDetail detail in Resources.FindObjectsOfTypeAll<SettingsTerrainDetail>())
{
detail.displayStringValue = true;
detail.stringValues = Templates.PresetDisplayNames.ToArray();
}
}

// Status
14 changes: 13 additions & 1 deletion src/Kopernicus/Templates.cs
Original file line number Diff line number Diff line change
@@ -25,6 +25,7 @@

using System;
using System.Collections.Generic;
using KSP.Localization;
using UnityEngine;

namespace Kopernicus
@@ -53,7 +54,10 @@ public class Templates

// Whether the main menu body should be randomized
public static List<String> randomMainMenuBodies { get; set; }


// The localized names of the presets
public static List<String> PresetDisplayNames { get; set; }

// Initialisation
static Templates()
{
@@ -68,6 +72,14 @@ static Templates()

// Random Main Menu bodies
randomMainMenuBodies = new List<String>();

// Presets
PresetDisplayNames = new List<String>
{
Localizer.Format("#autoLOC_6001506"),
Localizer.Format("#autoLOC_6001507"),
Localizer.Format("#autoLOC_6001508")
};
}
}
}

0 comments on commit 7ebb846

Please sign in to comment.