Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
b63c115
using non conditional logical ORs ( | instead of || ) for the editor …
AMPW-german Jun 22, 2025
b8b9b62
* Allow launchsites to be unregistered to rename them from KC
AMPW-german Jun 23, 2025
646a7cb
changed a few access modifiers
AMPW-german Jun 26, 2025
8a6c568
* Added groupcenter saving to the scenario module
AMPW-german Jul 24, 2025
18fba0d
* It's now checked if there is an ActiveVessel before reseting the lo…
AMPW-german Jul 25, 2025
0dd4eb4
* Checks the instance count before getting the first item when saving…
AMPW-german Jul 29, 2025
58db328
* Added a group offset editor to move the instances offset but not th…
AMPW-german Jul 29, 2025
d80f5ca
* Added range limits to the group editor
AMPW-german Jul 29, 2025
84f275e
* Changed the ksp assembly version to v1.11.0 to have the newest KK v…
AMPW-german Jul 29, 2025
7f70b60
* Added mapdecals to the scenario module
AMPW-german Jul 30, 2025
697fc39
* Made mapdecal editor text fields functional input fields
AMPW-german Aug 3, 2025
5d7508f
* Set the active instance/group to null in the editor overview window…
AMPW-german Aug 22, 2025
ea04e7c
* Show savegame groups in the group editor
AMPW-german Aug 24, 2025
9275d76
Only draw bases from the current body, if the bases are not occluded …
AMPW-german Aug 30, 2025
9a060f2
Merge branch 'master' into master
AMPW-german Aug 30, 2025
049786c
Update KerbalKonstructs.csproj
AMPW-german Aug 30, 2025
b4a39fd
Fix formatting
AMPW-german Aug 30, 2025
8652d6f
Fixed the map icons to use the correct object when checking if it's f…
AMPW-german Aug 30, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
66 changes: 38 additions & 28 deletions src/Core/Config/ConfigParser.cs
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
using System;
using System.Collections.Generic;
using System.IO;
using System.IO.Compression;
using System.Linq;
using UnityEngine;
using System.IO.Compression;


namespace KerbalKonstructs.Core
Expand Down Expand Up @@ -328,7 +328,6 @@ internal static void LoadAllMapDecals()
Log.Normal("Rebuilding PQS sphere on: " + body.name);
body.pqsController.RebuildSphere();
}

}

/// <summary>
Expand All @@ -337,6 +336,7 @@ internal static void LoadAllMapDecals()
/// <param name="instance"></param>
internal static void SaveMapDecalInstance(MapDecalInstance instance)
{
if (instance.isInSavegame) return;

if (!Directory.Exists(KSPUtil.ApplicationRootPath + "GameData/" + KerbalKonstructs.newInstancePath))
{
Expand All @@ -346,7 +346,7 @@ internal static void SaveMapDecalInstance(MapDecalInstance instance)
if (instance.configPath == null)
{
instance.configPath = KerbalKonstructs.newInstancePath + "/KK_MapDecal_" + instance.Name + ".cfg";
if (System.IO.File.Exists(instance.configPath))
if (System.IO.File.Exists(KSPUtil.ApplicationRootPath + "GameData/" + instance.configPath))
{
instance.configPath = KerbalKonstructs.newInstancePath + "/KK_MapDecal_" + instance.Name + "_" + Guid.NewGuid() + ".cfg";
}
Expand Down Expand Up @@ -416,34 +416,40 @@ internal static void SaveInstanceByCfg(string pathname)
}

Log.Debug("Saving File: " + pathname);
StaticInstance[] allInstances = StaticDatabase.allStaticInstances.Where(instance => instance.configPath == pathname).ToArray();
StaticInstance firstInstance = allInstances.First();
ConfigNode instanceConfig = null;
StaticInstance[] allInstances = StaticDatabase.allStaticInstances.Where(instance => instance.configPath == pathname && !instance.isInSavegame).ToArray();

ConfigNode staticNode = new ConfigNode("STATIC");

if (firstInstance.configUrl == null) //this are newly spawned instances
if (allInstances.Length > 0)
{
instanceConfig = new ConfigNode("STATIC");
instanceConfig.AddValue("pointername", firstInstance.model.name);
}
else
{
//instanceConfig = GameDatabase.Instance.GetConfigNode(firstInstance.configUrl.url);
//instanceConfig.RemoveNodes("Instances");
//instanceConfig.RemoveValues();
instanceConfig = new ConfigNode("STATIC");
instanceConfig.AddValue("pointername", firstInstance.model.name);
StaticInstance firstInstance = allInstances.First();
ConfigNode instanceConfig = null;

}

staticNode.AddNode(instanceConfig);
foreach (StaticInstance instance in allInstances)
{
ConfigNode inst = new ConfigNode("Instances");
ConfigParser.WriteInstanceConfig(instance, inst);
instanceConfig.nodes.Add(inst);
if (firstInstance.configUrl == null) //this are newly spawned instances
{
instanceConfig = new ConfigNode("STATIC");
instanceConfig.AddValue("pointername", firstInstance.model.name);
}
else
{
//instanceConfig = GameDatabase.Instance.GetConfigNode(firstInstance.configUrl.url);
//instanceConfig.RemoveNodes("Instances");
//instanceConfig.RemoveValues();
instanceConfig = new ConfigNode("STATIC");
instanceConfig.AddValue("pointername", firstInstance.model.name);

}

staticNode.AddNode(instanceConfig);
foreach (StaticInstance instance in allInstances)
{
ConfigNode inst = new ConfigNode("Instances");
ConfigParser.WriteInstanceConfig(instance, inst);
instanceConfig.nodes.Add(inst);
}
}

staticNode.Save(KSPUtil.ApplicationRootPath + "GameData/" + pathname, "Generated by Kerbal Konstructs");
}

Expand Down Expand Up @@ -483,6 +489,8 @@ internal static void ExportAllGroups()

foreach (GroupCenter group in StaticDatabase.allGroupCenters)
{
if (group.isInSavegame) continue;

parsedModels.Clear();

if (!System.IO.Directory.Exists(basePath))
Expand All @@ -505,6 +513,8 @@ internal static void ExportAllGroups()
}
foreach (StaticInstance instance in group.childInstances)
{
if (instance.isInSavegame) continue;

if (parsedModels.Contains(instance.model.name))
{
continue;
Expand Down Expand Up @@ -562,9 +572,9 @@ internal static void CreateZips()

string basePath = KSPUtil.ApplicationRootPath + "GameData/KerbalKonstructs/ExportedInstances/" + exportTime;
string allFileName = "AllExports" + DateTime.Now.ToString("_yyyy-MMdd-HHmm-ss") + ".zip";
ZipFile.CreateFromDirectory(basePath, KSPUtil.ApplicationRootPath + "GameData/KerbalKonstructs/ExportedInstances/"+ allFileName, System.IO.Compression.CompressionLevel.Fastest, false);


ZipFile.CreateFromDirectory(basePath, KSPUtil.ApplicationRootPath + "GameData/KerbalKonstructs/ExportedInstances/" + allFileName, System.IO.Compression.CompressionLevel.Fastest, false);

foreach (string dirname in Directory.GetDirectories(basePath))
{
Expand All @@ -579,7 +589,7 @@ internal static void CreateZips()
ZipFile.CreateFromDirectory(dirname, groupFilename, System.IO.Compression.CompressionLevel.Fastest, true);
Directory.Delete(dirname, true);
}
}
}

}
}
4 changes: 2 additions & 2 deletions src/Core/LaunchSites/LaunchSiteManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -479,7 +479,7 @@ internal static void RegisterMHLaunchSites(EditorFacility facility)
/// Removes the launchSite from the facilities
/// </summary>
/// <param name="site"></param>
internal static void UnregisterLaunchSite(KKLaunchSite site)
public static void UnregisterLaunchSite(KKLaunchSite site)
{
if (site.isOpen)
{
Expand Down Expand Up @@ -510,7 +510,7 @@ internal static void UnregisterLaunchSite(KKLaunchSite site)
/// Deletes a LaunchSite from the internal Database
/// </summary>
/// <param name="site2delete"></param>
internal static void DeleteLaunchSite(KKLaunchSite site2delete)
public static void DeleteLaunchSite(KKLaunchSite site2delete)
{
if (launchSites.Contains(site2delete))
{
Expand Down
5 changes: 5 additions & 0 deletions src/Core/MapDecals/DecalsDatabase.cs
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,11 @@ internal static void DeleteMapDecalInstance(MapDecalInstance instance)
_allMapDecalInstances.Remove(instance);
allMapDecalInstances = _allMapDecalInstances.ToArray();
Log.Debug("MapDecal instace " + instance.Name + " removed from Database");

if (instance.configPath != null && System.IO.File.Exists(KSPUtil.ApplicationRootPath + "GameData/" + instance.configPath))
{
System.IO.File.Delete(KSPUtil.ApplicationRootPath + "GameData/" + instance.configPath);
}
}
}

Expand Down
2 changes: 2 additions & 0 deletions src/Core/MapDecals/MapDecalInstance.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,8 @@ public class MapDecalInstance
[CFGSetting]
public string Group = "Ungrouped";

public bool isInSavegame = false;


internal MapDecalsMap heighMap = null;
internal MapDecalsMap colormapMap = null;
Expand Down
46 changes: 24 additions & 22 deletions src/Core/StaticGroup/GroupCenter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,32 +34,32 @@ public class GroupCenter
[CFGSetting]
public bool SeaLevelAsReference = false;
[CFGSetting]
internal double RefLatitude = 361d;
public double RefLatitude = 361d;
[CFGSetting]
internal double RefLongitude = 361d;
public double RefLongitude = 361d;


public UrlDir.UrlConfig configUrl;
public String configPath = null;

internal GameObject gameObject;
public GameObject gameObject;
internal PQSCity pqsCity;
private Vector3 origScale = new Vector3(1, 1, 1);

internal List<StaticInstance> childInstances = new List<StaticInstance>();
internal bool isActive = true;
public List<StaticInstance> childInstances = new List<StaticInstance>();
public bool isActive = true;

internal List<KKLaunchSite> launchsites = new List<KKLaunchSite>();
public List<KKLaunchSite> launchsites = new List<KKLaunchSite>();

internal bool hidden = false;
internal bool isBuiltIn = false;
internal bool isInSavegame = false;
public bool hidden = false;
public bool isBuiltIn = false;
public bool isInSavegame = false;





internal bool isHidden
public bool isHidden
{
get
{
Expand Down Expand Up @@ -197,7 +197,7 @@ internal void UpdateRotation2Heading()

}

internal void RenameGroup(string newName)
public void RenameGroup(string newName)
{
StaticDatabase.RemoveGroupCenter(this);
Group = newName;
Expand All @@ -212,7 +212,7 @@ internal void RenameGroup(string newName)

}

internal void AddInstance(StaticInstance instance)
public void AddInstance(StaticInstance instance)
{
if (!childInstances.Contains(instance))
{
Expand All @@ -222,7 +222,7 @@ internal void AddInstance(StaticInstance instance)
}


internal void RemoveInstance(StaticInstance instance)
public void RemoveInstance(StaticInstance instance)
{
if (childInstances.Contains(instance))
{
Expand All @@ -232,7 +232,7 @@ internal void RemoveInstance(StaticInstance instance)



internal void SetInstancesEnabled(bool isInRange)
public void SetInstancesEnabled(bool isInRange)
{
if (isInRange == isActive)
{
Expand Down Expand Up @@ -262,7 +262,7 @@ internal void SetInstancesEnabled(bool isInRange)
/// </summary>
/// <param name="distance"></param>
/// <param name="maxDistance"></param>
internal void CheckIfInRange(float distance, float maxDistance)
public void CheckIfInRange(float distance, float maxDistance)
{

if (distance < 5000 && isHidden)
Expand All @@ -277,7 +277,7 @@ internal void CheckIfInRange(float distance, float maxDistance)
SetInstancesEnabled(isInRange);
}

internal static void ActivateInstance(StaticInstance instance)
public static void ActivateInstance(StaticInstance instance)
{
switch (instance.FacilityType)
{
Expand All @@ -296,7 +296,7 @@ internal static void ActivateInstance(StaticInstance instance)
}
}

internal static void DeActivateInstance(StaticInstance instance)
public static void DeActivateInstance(StaticInstance instance)
{
switch (instance.FacilityType)
{
Expand All @@ -316,7 +316,7 @@ internal static void DeActivateInstance(StaticInstance instance)
}


internal void Update()
public void Update()
{
if (pqsCity != null)
{
Expand Down Expand Up @@ -444,13 +444,15 @@ internal void CopyGroup(GroupCenter sourceGroup)
}


internal void DeleteGroupCenter()
public void DeleteGroupCenter()
{
foreach (StaticInstance child in childInstances.ToArray())
{
KerbalKonstructs.instance.DeleteInstance(child);
}

if (StaticsEditorGUI.GetActiveGroup() == this) StaticsEditorGUI.SetActiveGroup(null);

StaticDatabase.RemoveGroupCenter(this);
// check later when saving if this file is empty

Expand All @@ -469,15 +471,15 @@ internal void SetReference()
pqsCity.repositionToSphereSurfaceAddHeight = !SeaLevelAsReference;
}

internal double surfaceHeight
public double surfaceHeight
{
get
{
return (CelestialBody.pqsController.GetSurfaceHeight(CelestialBody.GetRelSurfaceNVector(RefLatitude, RefLongitude).normalized * CelestialBody.Radius) - CelestialBody.pqsController.radius);
}
}

internal string dbKey
public string dbKey
{
get
{
Expand All @@ -488,7 +490,7 @@ internal string dbKey
}
}

internal float heading
public float heading
{
get
{
Expand Down
5 changes: 4 additions & 1 deletion src/Core/StaticObjects/StaticInstance.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using KerbalKonstructs.Modules;
using KerbalKonstructs.UI;
using System;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -121,7 +122,7 @@ internal GameObject mesh

internal GroupCenter groupCenter = null;

internal bool isInSavegame = false;
public bool isInSavegame = false;

internal bool isDestroyed = false;

Expand Down Expand Up @@ -634,6 +635,8 @@ internal void Deactivate()

internal void Destroy()
{
if (StaticsEditorGUI.selectedObject == this) StaticsEditorGUI.selectedObject = null;

if (groupCenter != null)
{
groupCenter.RemoveInstance(this);
Expand Down
Loading