Skip to content

Commit

Permalink
Update for 0.1.4 KSP 2
Browse files Browse the repository at this point in the history
  • Loading branch information
blacksheepcosmo committed Aug 30, 2023
1 parent c09237b commit c050440
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 52 deletions.
43 changes: 43 additions & 0 deletions FFTProject/FFT - Backup.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?xml version="1.0" encoding="utf-8"?>
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<LangVersion>latest</LangVersion>
<ImplicitUsings>true</ImplicitUsings>
<AssemblyName>com.github.cvusmo.fancyfueltanks</AssemblyName>
<Product>FFT</Product>
<Description>Fancy Fuel Tanks</Description>
<Version>0.1.4</Version>
<RestoreAdditionalProjectSources>
https://nuget.spacewarp.org/v3/index.json
</RestoreAdditionalProjectSources>
<RootNamespace>FFT</RootNamespace>
<ModId Condition="'$(ModId)'==''">FFT</ModId>
<PackageProjectUrl>https://github.com/cvusmo/FFT</PackageProjectUrl>
<RepositoryUrl></RepositoryUrl>
<PackageTags>KSP2-mods</PackageTags>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
<Optimize>True</Optimize>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="BepInEx.Analyzers" Version="1.0.8" PrivateAssets="all" />
<PackageReference Include="BepInEx.AssemblyPublicizer.MSBuild" Version="0.4.1" PrivateAssets="all" />
<PackageReference Include="BepInEx.Core" Version="5.*" />
<PackageReference Include="BepInEx.PluginInfoProps" Version="2.*" />
<PackageReference Include="HarmonyX" Version="2.10.1" />
<PackageReference Include="SpaceWarp" Version="1.4.*" />
<PackageReference Include="UnityEngine.Modules" Version="2020.3.33.1" IncludeAssets="compile" />
</ItemGroup>
<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>..\..\..\..\..\..\..\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program 2\KSP2_x64_Data\Managed\Assembly-CSharp.dll</HintPath>
<Publicize>true</Publicize>
<Private>false</Private>
</Reference>
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent">
<Exec Command="rm -rf &quot;$(ProjectDir)..\$(ConfigurationName)\&quot;&#xA;echo d | xcopy /y /s &quot;$(ProjectDir)..\$(ModId)\&quot; &quot;$(ProjectDir)..\$(ConfigurationName)\BepInEx\plugins\$(ModId)\&quot;&#xA;echo f | xcopy /y &quot;$(TargetPath)&quot; &quot;$(ProjectDir)..\$(ConfigurationName)\BepInEx\plugins\$(ModId)\$(ModId).dll&quot;&#xA;if $(ConfigurationName) == Debug echo f | xcopy /y &quot;$(TargetDir)$(TargetName).pdb&quot; &quot;$(ProjectDir)..\$(ConfigurationName)\BepInEx\plugins\$(ModId)\$(ModId).pdb&quot;&#xA;xcopy /y &quot;$(ProjectDir)..\LICENSE&quot; &quot;$(ProjectDir)..\$(ConfigurationName)\BepInEx\plugins\$(ModId)\&quot;&#xA;echo f | xcopy /y &quot;$(ProjectDir)..\README.md&quot; &quot;$(ProjectDir)..\$(ConfigurationName)\BepInEx\plugins\$(ModId)\README.txt&quot;" />
</Target>
</Project>
2 changes: 1 addition & 1 deletion FFTProject/FFT.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
<ItemGroup>
<Reference Include="Assembly-CSharp">
<HintPath>C:\Program Files (x86)\Steam\steamapps\common\Kerbal Space Program 2\KSP2_x64_Data\Managed\Assembly-CSharp.dll</HintPath>
<Publicize>true</Publicize>
<Publicize>true</Publicize>
<Private>false</Private>
</Reference>
</ItemGroup>
Expand Down
66 changes: 16 additions & 50 deletions FFTProject/Modules/Module_VentValve.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
using FFT.Utilities;
using KSP.Sim.Definitions;
using UnityEngine;
using VFX;

namespace FFT.Modules
{
Expand All @@ -14,17 +13,16 @@ public class Module_VentValve : PartBehaviourModule

[SerializeField] private FuelTankDefinitions _fuelTankDefinitions;
[SerializeField] private VentValveDefinitions _ventValveDefinitions;
[SerializeField] private GameObject VentValveVFX;
[SerializeField] private GameObject CoolingVFX;

public Dictionary<string, GameObject> fuelTankDict = new Dictionary<string, GameObject>();

public DynamicGravityForVFX DynamicGravityVent, DynamicGravityCooling;
public Animator Animator;
public ParticleSystem PSVentValveVFX, PSCoolingVFX;
public Material vaporShaderMaterial;
private Material _cachedMaterial;
private Data_VentValve _dataVentValve;
private Data_ValveParts _dataValveParts;
private Data_FuelTanks _dataFuelTanks;
private Renderer _cachedRenderer;

internal float ASL, AGL, VV, HV, DP, SP, AT, ET, FL;
internal bool InAtmo = true;
Expand All @@ -37,9 +35,11 @@ public class Module_VentValve : PartBehaviourModule
public override void OnInitialize()
{
base.OnInitialize();
_cachedRenderer = GetComponent<Renderer>();
_cachedMaterial = _cachedRenderer.material;
AddDataModules();

if (PartBackingMode == PartBackingModes.Flight) //PartBackingMode == PartBackingModes.Flight
if (PartBackingMode == PartBackingModes.Flight)
{
LazyInitializeVFX();
}
Expand All @@ -66,21 +66,9 @@ public override void AddDataModules()

Debug.Log("Added Data Modules.");
}

private void LazyInitializeVFX()
{
Debug.Log("Module_VentValveVFX has started.");
if (PSVentValveVFX == null && VentValveVFX != null)
{
PSVentValveVFX = VentValveVFX.GetComponentInChildren<ParticleSystem>();
DynamicGravityVent = VentValveVFX.GetComponentInChildren<DynamicGravityForVFX>();
}

if (PSCoolingVFX == null && CoolingVFX != null)
{
PSCoolingVFX = CoolingVFX.GetComponentInChildren<ParticleSystem>();
DynamicGravityCooling = CoolingVFX.GetComponentInParent<DynamicGravityForVFX>();
}

if (Animator == null)
{
Expand Down Expand Up @@ -160,48 +148,26 @@ private void UpdateVFX()
double scaledFuelPercentage = vesselData.FuelPercentage / 100.0;
FL = _dataVentValve.VFXFuelPercentage.Evaluate((float)scaledFuelPercentage);
Animator.SetFloat("FL", FL);
}
internal void StartVFX()
{
if (VentValveVFX != null)
{
var emission = PSVentValveVFX.emission;
emission.enabled = true;
PSVentValveVFX.Play();
}
if (CoolingVFX != null)
{
var emission = PSCoolingVFX.emission;
emission.enabled = true;
PSCoolingVFX.Play();
}

}
internal void StopVFX()
{
if (VentValveVFX != null)
{
var emission = PSVentValveVFX.emission;
emission.enabled = false;
PSVentValveVFX.Stop();
}
if (CoolingVFX != null)
{
var emission = PSCoolingVFX.emission;
emission.enabled = false;
PSCoolingVFX.Stop();
}
_cachedMaterial.SetFloat("_ASL", ASL);
_cachedMaterial.SetFloat("_AGL", AGL);

Material vaporShaderMaterial = _cachedRenderer.material;
vaporShaderMaterial.SetFloat("_ASL", ASL);
vaporShaderMaterial.SetFloat("_AGL", AGL);
}
internal void Activate()
{
StartVFX();
_cachedMaterial.SetFloat("_IsVFXActive", 0.0f);
vaporShaderMaterial.SetFloat("_IsVFXActive", 1.0f);
RefreshDataAndVFX();
ActivateModule = true;
Debug.Log("Module_VentValve activated.");
}
internal void Deactivate()
{
StopVFX();
_cachedMaterial.SetFloat("_IsVFXActive", 1.0f);
vaporShaderMaterial.SetFloat("_IsVFXActive", 0.0f);
ActivateModule = false;
Debug.Log("Module_VentValve deactivated.");
}
Expand Down
2 changes: 1 addition & 1 deletion FFTProject/Utilities/Utility.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public static class Utility
public static GameState GameState;
public static VesselSituations VesselSituations { get; private set; }
public static MessageCenter MessageCenter { get; private set; }
public static double UniversalTime => GameManager.Instance.Game.UniverseModel.UniversalTime;
public static double UniverseTime => GameManager.Instance.Game.UniverseModel.UniverseTime;
public static void Initialize()
{
RefreshGameManager();
Expand Down

0 comments on commit c050440

Please sign in to comment.