diff --git a/.gitignore b/.gitignore index d023a5dd..4238e3be 100644 --- a/.gitignore +++ b/.gitignore @@ -14,3 +14,4 @@ Distribution/Restock/GameData/ReStock/Props/**/*.png Distribution/RestockPlus/GameData/ReStockPlus/Props/**/*.png Distribution/RestockPlus/GameData/ReStockPlus/Spaces/**/*.png Distribution/Restock/GameData/ReStock/RestockPatchDisabler.cfg +Source/Restock/dlls diff --git a/Distribution/Restock/GameData/ReStock/Plugins/Restock.dll b/Distribution/Restock/GameData/ReStock/Plugins/Restock.dll index ecbe241d..f698e1be 100644 Binary files a/Distribution/Restock/GameData/ReStock/Plugins/Restock.dll and b/Distribution/Restock/GameData/ReStock/Plugins/Restock.dll differ diff --git a/Source/Restock/Constraints/LookAtConstraint.cs b/Source/Restock/Constraints/LookAtConstraint.cs index 31a43761..0942dd12 100644 --- a/Source/Restock/Constraints/LookAtConstraint.cs +++ b/Source/Restock/Constraints/LookAtConstraint.cs @@ -1,3 +1,4 @@ +using System; using UnityEngine; namespace Restock.Constraints @@ -21,15 +22,21 @@ namespace Restock.Constraints node.TryGetValue("targetName", ref targetName); rotator = p.FindModelTransform(rotatorsName); + if (rotator == null) + { + throw new Exception($"Missing rotator transform {rotator}"); + } target = p.FindModelTransform(targetName); + if (target == null) + { + throw new Exception($"Missing target transform {target}"); + } } public void Update() { - if (rotator == null || target == null) return; - var lookPos = target.position - rotator.position; - var rotation = Quaternion.LookRotation(lookPos, target.up); + var rotation = Quaternion.LookRotation(lookPos, rotator.up); rotator.rotation = rotation; } } diff --git a/Source/Restock/ModuleRestockConstraints.cs b/Source/Restock/ModuleRestockConstraints.cs index 38e68816..9ba5de01 100644 --- a/Source/Restock/ModuleRestockConstraints.cs +++ b/Source/Restock/ModuleRestockConstraints.cs @@ -1,4 +1,5 @@ -using System.Collections.Generic; +using System; +using System.Collections.Generic; using System.Linq; using Restock.Constraints; @@ -6,67 +7,77 @@ namespace Restock { public class ModuleRestockConstraints : PartModule { - public List constraints; + private List _constraints; public override void OnLoad(ConfigNode node) { base.OnLoad(node); - constraints = new List(); + _constraints = new List(); var cnodes = node.GetNodes(); this.Log($"Loading {cnodes.Length} constraints"); foreach (var cnode in cnodes) { - switch (cnode.name) + try { - //LookAtConstraint - case "CONSTRAINLOOKFX": - case "LOOKATCONSTRAINT": - constraints.Add(new LookAtConstraint(cnode, this.part)); - break; + switch (cnode.name) + { + //LookAtConstraint + case "CONSTRAINLOOKFX": + case "LOOKATCONSTRAINT": + _constraints.Add(new LookAtConstraint(cnode, this.part)); + break; - //CopyPositionConstraint - case "COPYPOSITIONCONSTRAINT": - constraints.Add(new CopyPositionConstraint(cnode, this.part)); - break; + //CopyPositionConstraint + case "COPYPOSITIONCONSTRAINT": + _constraints.Add(new CopyPositionConstraint(cnode, this.part)); + break; - //CopyRotationConstraint - case "COPYROTATIONCONSTRAINT": - constraints.Add(new CopyRotationConstraint(cnode, this.part)); - break; + //CopyRotationConstraint + case "COPYROTATIONCONSTRAINT": + _constraints.Add(new CopyRotationConstraint(cnode, this.part)); + break; + } + } + catch(Exception e) + { + this.LogError($"Exception while loading {cnode.name} Node: {e}"); } } - this.Log($"Loaded {constraints.Count} constraints"); + this.Log($"Loaded {_constraints.Count} constraints"); } public override void OnStart(StartState state) { - if (HighLogic.LoadedSceneIsFlight || HighLogic.LoadedSceneIsEditor) + if (!HighLogic.LoadedSceneIsFlight && !HighLogic.LoadedSceneIsEditor) return; + if (_constraints != null && _constraints.Count != 0) return; + + // I have no idea why this is here but I'm scared to remove it + foreach (var pNode in GameDatabase.Instance.GetConfigs("PART")) { - if (constraints == null || constraints.Count == 0) - { - foreach (UrlDir.UrlConfig pNode in GameDatabase.Instance.GetConfigs("PART")) - { - if (pNode.name.Replace("_", ".") == part.partInfo.name) - { - var cfg = pNode.config; - var node = cfg.GetNodes("MODULE").Single(n => n.GetValue("name") == moduleName); - OnLoad(node); - } - } - } + if (pNode.name.Replace("_", ".") != part.partInfo.name) continue; + var cfg = pNode.config; + var node = cfg.GetNodes("MODULE").Single(n => n.GetValue("name") == moduleName); + OnLoad(node); } } private void LateUpdate() { - if (constraints == null) return; - - foreach (var constraint in constraints) + for (var i = 0; i < _constraints.Count; i++) { - constraint.Update(); + try + { + _constraints[i].Update(); + } + catch (Exception e) + { + this.LogError($"Encountered exception in constraint. Removing the constraint to prevent further errors\n {e}"); + _constraints.RemoveAt(i--); + } + } } } diff --git a/Source/Restock/Properties/AssemblyInfo.cs b/Source/Restock/Properties/AssemblyInfo.cs deleted file mode 100644 index 8a0cb45c..00000000 --- a/Source/Restock/Properties/AssemblyInfo.cs +++ /dev/null @@ -1,38 +0,0 @@ -using System.Reflection; -using System.Runtime.CompilerServices; -using System.Runtime.InteropServices; - -// General Information about an assembly is controlled through the following -// set of attributes. Change these attribute values to modify the information -// associated with an assembly. -[assembly: AssemblyTitle("Restock")] -[assembly: AssemblyDescription("")] -[assembly: AssemblyConfiguration("")] -[assembly: AssemblyCompany("Porktober Revolution")] -[assembly: AssemblyProduct("Restock")] -[assembly: AssemblyCopyright("Copyright © Porktober Revolution 2018")] -[assembly: AssemblyTrademark("")] -[assembly: AssemblyCulture("")] - -// Setting ComVisible to false makes the types in this assembly not visible -// to COM components. If you need to access a type in this assembly from -// COM, set the ComVisible attribute to true on that type. -[assembly: ComVisible(false)] - -// The following GUID is for the ID of the typelib if this project is exposed to COM -[assembly: Guid("0a087745-0e2b-4d11-9431-c2d4191dd510")] - -// Version information for an assembly consists of the following four values: -// -// Major Version -// Minor Version -// Build Number -// Revision -// -// You can specify all the values or you can default the Build and Revision Numbers -// by using the '*' as shown below: -// [assembly: AssemblyVersion("1.0.*")] -[assembly: AssemblyVersion("0.1.0.0")] -[assembly: AssemblyFileVersion("0.1.0.0")] - -[assembly: KSPAssembly("Restock", 0, 1, 0)] diff --git a/Source/Restock/Restock.csproj b/Source/Restock/Restock.csproj index 8baab36c..47ee40bd 100644 --- a/Source/Restock/Restock.csproj +++ b/Source/Restock/Restock.csproj @@ -1,17 +1,14 @@  - + - Debug - AnyCPU - {0A087745-0E2B-4D11-9431-C2D4191DD510} - Library - Properties - Restock - Restock - v4.5 - 512 - true + net48 + 8 + false + x64 + 1701;1702;CS0649;CS1591 + 1.0.0.0 + Restock true @@ -43,33 +40,6 @@ False - - - - - - - - - - - - - - - - - - - - - - - - - - - sh -e -c "cp -v '$(TargetPath)' '$(SolutionDir)/../Distribution/Restock/GameData/ReStock/Plugins'"