From ab970d025e99c8be31a49ddcf69126bb7da4ae14 Mon Sep 17 00:00:00 2001 From: Robin Leroy Date: Sat, 15 Feb 2025 18:36:59 +0100 Subject: [PATCH] Persist per-frame hiding. --- ksp_plugin_adapter/interface.cs | 41 ++++++++++++++++++++++++++++++- ksp_plugin_adapter/main_window.cs | 25 ++++++++++++++++++- 2 files changed, 64 insertions(+), 2 deletions(-) diff --git a/ksp_plugin_adapter/interface.cs b/ksp_plugin_adapter/interface.cs index a11f0fea21..65c8285689 100644 --- a/ksp_plugin_adapter/interface.cs +++ b/ksp_plugin_adapter/interface.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.Linq; using System.Runtime.InteropServices; @@ -94,7 +95,7 @@ internal interface IReferenceFrameParameters { int[] SecondaryIndices { get; set; } } -internal partial class PlottingFrameParameters : IReferenceFrameParameters { +internal partial class PlottingFrameParameters : IReferenceFrameParameters, IConfigNode { public PlottingFrameParameters() { primary_index = new int[]{}; secondary_index = new int[]{}; @@ -123,6 +124,44 @@ public override int GetHashCode() => primary_index.DefaultIfEmpty(-1).First(), secondary_index.DefaultIfEmpty(-1).First()).GetHashCode(); + public void Load(ConfigNode node) { + if (!Enum.TryParse(node.GetUniqueValue("extension"), + out FrameType extension)) { + Log.Fatal("Bad FrameType " + node.GetUniqueValue("extension")); + } + Extension = extension; + if (!int.TryParse(node.GetUniqueValue("centre_index"), out centre_index)) { + Log.Fatal("Bad centre_index " + node.GetUniqueValue("centre_index")); + } + var primary_indices = new List(); + foreach (string value in node.GetValues("primary_indices")) { + if (!int.TryParse(value, out int i)) { + Log.Fatal("Bad primary_indices " + value); + } + primary_indices.Add(i); + } + primary_index = primary_indices.ToArray(); + var secondary_indices = new List(); + foreach (string value in node.GetValues("secondary_indices")) { + if (!int.TryParse(value, out int i)) { + Log.Fatal("Bad secondary_indices " + value); + } + secondary_indices.Add(i); + } + secondary_index = secondary_indices.ToArray(); + } + + public void Save(ConfigNode node) { + node.AddValue("extension", Extension.ToString()); + node.AddValue("centre_index", centre_index); + foreach (int i in primary_index) { + node.AddValue("primary_indices", i); + } + foreach (int i in secondary_index) { + node.AddValue("secondary_indices", i); + } + } + public static bool operator ==(PlottingFrameParameters left, IReferenceFrameParameters right) { if ((object)left == null && (object)right == null) { diff --git a/ksp_plugin_adapter/main_window.cs b/ksp_plugin_adapter/main_window.cs index 6b554b1138..33ad7e4a0d 100644 --- a/ksp_plugin_adapter/main_window.cs +++ b/ksp_plugin_adapter/main_window.cs @@ -82,6 +82,23 @@ public override void Load(ConfigNode node) { history_length_.value = Convert.ToDouble(history_length_value); } + frames_that_hide_unpinned_celestials.Clear(); + foreach (ConfigNode frame_node in + node.GetNodes("frames_that_hide_unpinned_celestials")) { + var frame = new PlottingFrameParameters(); + frame.Load(frame_node); + frames_that_hide_unpinned_celestials.Add(frame); + } + + frames_that_hide_unpinned_markers.Clear(); + foreach (ConfigNode frame_node in + node.GetNodes("frames_that_hide_unpinned_markers")) { + var frame = new PlottingFrameParameters(); + frame.Load(frame_node); + frames_that_hide_unpinned_markers.Add(frame); + } + + string buffered_logging_value = node.GetAtMostOneValue("buffered_logging"); if (buffered_logging_value != null) { buffered_logging_ = Convert.ToInt32(buffered_logging_value); @@ -105,7 +122,6 @@ public override void Load(ConfigNode node) { if (must_record_journal_value != null) { must_record_journal_ = Convert.ToBoolean(must_record_journal_value); } - Log.SetBufferedLogging(buffered_logging_); Log.SetSuppressedLogging(suppressed_logging_); Log.SetStderrLogging(stderr_logging_); @@ -128,6 +144,13 @@ public override void Save(ConfigNode node) { createIfNotFound : true); node.SetValue("history_length", history_length, createIfNotFound : true); + foreach (var frame in frames_that_hide_unpinned_celestials) { + frame.Save(node.AddNode("frames_that_hide_unpinned_celestials")); + } + foreach (var frame in frames_that_hide_unpinned_markers) { + frame.Save(node.AddNode("frames_that_hide_unpinned_markers")); + } + node.SetValue("buffered_logging", buffered_logging_, createIfNotFound : true);