Update project organization and fix constraint but

This commit is contained in:
Andrew Cassidy 2024-06-06 21:57:34 -07:00
parent 166d2858db
commit 9c914a1d66
6 changed files with 65 additions and 114 deletions

1
.gitignore vendored
View File

@ -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

View File

@ -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;
}
}

View File

@ -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<IConstraint> constraints;
private List<IConstraint> _constraints;
public override void OnLoad(ConfigNode node)
{
base.OnLoad(node);
constraints = new List<IConstraint>();
_constraints = new List<IConstraint>();
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--);
}
}
}
}

View File

@ -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)]

View File

@ -1,17 +1,14 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{0A087745-0E2B-4D11-9431-C2D4191DD510}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Restock</RootNamespace>
<AssemblyName>Restock</AssemblyName>
<TargetFrameworkVersion>v4.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<Deterministic>true</Deterministic>
<TargetFramework>net48</TargetFramework>
<LangVersion>8</LangVersion>
<IsPackable>false</IsPackable>
<PlatformTarget>x64</PlatformTarget>
<NoWarn>1701;1702;CS0649;CS1591</NoWarn>
<AssemblyVersion>1.0.0.0</AssemblyVersion>
<AssemblyTitle>Restock</AssemblyTitle>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
@ -43,33 +40,6 @@
<Private>False</Private>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Constraints\CopyPositionConstraint.cs" />
<Compile Include="Constraints\CopyRotationConstraint.cs" />
<Compile Include="Constraints\IConstraint.cs" />
<Compile Include="Constraints\LookAtConstraint.cs" />
<Compile Include="InstallChecker.cs" />
<Compile Include="LaunchClampGirderFactory.cs" />
<Compile Include="MaterialModifiers\ColorPropertyMaterialModifier.cs" />
<Compile Include="MaterialModifiers\FloatPropertyMaterialModifier.cs" />
<Compile Include="MaterialModifiers\IMaterialModifier.cs" />
<Compile Include="MaterialModifiers\MaterialModifierParser.cs" />
<Compile Include="MaterialModifiers\TexturePropertyMaterialModifier.cs" />
<Compile Include="ModuleRestockDeployableMeshHider.cs" />
<Compile Include="ModuleRestockLaunchClamp.cs" />
<Compile Include="ModuleRestockEnhancedLight.cs" />
<Compile Include="ModuleRestockRCSGlow.cs" />
<Compile Include="ModuleRestockLinkedMesh.cs" />
<Compile Include="ModuleRestockDepthMask.cs" />
<Compile Include="ModuleRestockHeatEffects.cs" />
<Compile Include="ModuleRestockISRUAnimation.cs" />
<Compile Include="ModuleRestockConstraints.cs" />
<Compile Include="ModuleRestockModifyFairingMaterials.cs" />
<Compile Include="ModuleRestockModifyMaterials.cs" />
<Compile Include="PartModuleExtensions.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="ResourceBlacklist.cs" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<PropertyGroup>
<PostBuildEvent>sh -e -c "cp -v '$(TargetPath)' '$(SolutionDir)/../Distribution/Restock/GameData/ReStock/Plugins'"</PostBuildEvent>