Skip to content

Commit

Permalink
Persist per-frame hiding.
Browse files Browse the repository at this point in the history
  • Loading branch information
eggrobin committed Feb 15, 2025
1 parent 2268bf7 commit ab970d0
Show file tree
Hide file tree
Showing 2 changed files with 64 additions and 2 deletions.
41 changes: 40 additions & 1 deletion ksp_plugin_adapter/interface.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;

Expand Down Expand Up @@ -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[]{};
Expand Down Expand Up @@ -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<int>();
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<int>();
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) {
Expand Down
25 changes: 24 additions & 1 deletion ksp_plugin_adapter/main_window.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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_);
Expand All @@ -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);
Expand Down

0 comments on commit ab970d0

Please sign in to comment.