-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from cvusmo/dev
0.1.3 release
- Loading branch information
Showing
8 changed files
with
341 additions
and
51 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
using FFT.Modules; | ||
using KSP.Sim; | ||
using KSP.Sim.Definitions; | ||
using System; | ||
using UnityEngine; | ||
|
||
namespace FFT.Modules | ||
{ | ||
[Serializable] | ||
public class Data_TriggerVFX : ModuleData | ||
{ | ||
public override Type ModuleType => typeof(Module_TriggerVFX); | ||
|
||
[KSPState] | ||
public AnimationCurve VFXOpacityCurve; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
using System.Collections.Generic; | ||
using UnityEngine; | ||
|
||
public class FuelTankDefinitions : MonoBehaviour | ||
{ | ||
[SerializeField] | ||
private List<GameObject> fuelTankDefintions; | ||
|
||
private Dictionary<string, GameObject> fuelTanksDict = new Dictionary<string, GameObject>(); | ||
private void Awake() | ||
{ | ||
foreach (var tank in fuelTankDefintions) | ||
{ | ||
fuelTanksDict[tank.name] = tank; | ||
} | ||
} | ||
public GameObject GetFuelTank(string tankName) | ||
{ | ||
if (fuelTanksDict.TryGetValue(tankName, out var tank)) | ||
{ | ||
return tank; | ||
} | ||
|
||
return null; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,197 @@ | ||
using KSP.Animation; | ||
using KSP.Game; | ||
using KSP.Messages.PropertyWatchers; | ||
using KSP.Sim.Definitions; | ||
using KSP.Sim.impl; | ||
using KSP.UI; | ||
using UnityEngine; | ||
using VFX; | ||
|
||
namespace FFT.Modules | ||
{ | ||
public class Module_TriggerVFX : PartBehaviourModule | ||
{ | ||
public override Type PartComponentModuleType => typeof(PartComponentModule_TriggerVFX); | ||
|
||
[SerializeField] | ||
public Data_TriggerVFX _dataTriggerVFX; | ||
[SerializeField] | ||
public GameObject CoolingVFX; | ||
[SerializeField] | ||
|
||
public TriggerVFXFromAnimation _triggerVFX; | ||
public DynamicGravityForVFX _gravityForVFX; | ||
public Animator animator; | ||
public ParticleSystem _particleSystem; | ||
public IsActiveVessel _isActiveVessel; | ||
public VesselComponent _vesselComponent; | ||
public bool _wasActive; | ||
private float _fuelLevel; | ||
public GameState _gameState { get; private set; } | ||
public bool IsActive => _isActiveVessel.GetValueBool(); | ||
public override void OnInitialize() | ||
{ | ||
base.OnInitialize(); | ||
|
||
if (PartBackingMode == PartBackingModes.Flight) | ||
{ | ||
if (CoolingVFX) | ||
{ | ||
Awake(); | ||
} | ||
} | ||
} | ||
public void Awake() | ||
{ | ||
FFTPlugin.Logger.LogInfo("Attached to GameObject: " + gameObject.name); | ||
|
||
if (CoolingVFX != null) | ||
{ | ||
_particleSystem = CoolingVFX.GetComponentInChildren<ParticleSystem>(); | ||
if (_particleSystem != null) | ||
{ | ||
FFTPlugin.Logger.LogInfo("Successfully retrieved ParticleSystem."); | ||
} | ||
else | ||
{ | ||
FFTPlugin.Logger.LogError("Could not find ParticleSystem on CoolingVFX."); | ||
} | ||
} | ||
else | ||
{ | ||
FFTPlugin.Logger.LogError("CoolingVFX GameObject is not assigned."); | ||
} | ||
|
||
animator = GetComponentInParent<Animator>(); | ||
|
||
_isActiveVessel = new IsActiveVessel(); | ||
_vesselComponent = new VesselComponent(); | ||
|
||
FFTPlugin.Logger.LogInfo("Module_TriggerVFX has started."); | ||
} | ||
public override void AddDataModules() | ||
{ | ||
base.AddDataModules(); | ||
this._dataTriggerVFX ??= new Data_TriggerVFX(); | ||
this.DataModules.TryAddUnique<Data_TriggerVFX>(this._dataTriggerVFX, out this._dataTriggerVFX); | ||
} | ||
public override void OnModuleFixedUpdate(float fixedDeltaTime) | ||
{ | ||
base.OnModuleFixedUpdate(fixedDeltaTime); | ||
double fillRatioSum = 0; | ||
int count = 0; | ||
|
||
foreach (var container in part.Model.Containers) | ||
{ | ||
foreach (var resourceID in container) | ||
{ | ||
FFTPlugin.Logger.LogInfo("ResourceID Before: " + resourceID); | ||
FFTPlugin.Logger.LogInfo("opacity Before: " + count); | ||
count++; | ||
fillRatioSum += container.GetResourceFillRatio(resourceID); | ||
FFTPlugin.Logger.LogInfo("ResourceID After: " + resourceID); | ||
FFTPlugin.Logger.LogInfo("opacity After: " + count); | ||
} | ||
} | ||
|
||
double fillRatioAverage = fillRatioSum / count; | ||
|
||
float opacity = _dataTriggerVFX.VFXOpacityCurve.Evaluate((float)fillRatioAverage); | ||
|
||
_fuelLevel = opacity; | ||
FFTPlugin.Logger.LogInfo("opacity: " + opacity); | ||
|
||
animator.SetFloat("FuelLevel", _fuelLevel); | ||
FFTPlugin.Logger.LogInfo("Fuel level: " + _fuelLevel); | ||
|
||
if (_fuelLevel < 0) | ||
{ | ||
FFTPlugin.Logger.LogError("Out of Fuel. Fuel level: " + _fuelLevel); | ||
} | ||
|
||
if (IsActive) | ||
{ | ||
if (!FuelLevelExceedsThreshold()) | ||
{ | ||
StopVFX(); | ||
} | ||
else if (!animator.GetCurrentAnimatorStateInfo(0).IsName("CoolingVFX_LOOP")) | ||
{ | ||
StartVFX(); | ||
FFTPlugin.Logger.LogInfo("_triggerVFX: " + _triggerVFX); | ||
} | ||
} | ||
else | ||
{ | ||
StopVFX(); | ||
} | ||
} | ||
private void StartVFX() | ||
{ | ||
FFTPlugin.Logger.LogInfo("StartVFX FuelLevel: " + _fuelLevel); | ||
EnableEmission(); | ||
StartParticleSystem(); | ||
_triggerVFX.enabled = true; | ||
_gravityForVFX.enabled = true; | ||
FFTPlugin.Logger.LogInfo("StartParticleSystem & FL: " + _fuelLevel); | ||
} | ||
private void StopVFX() | ||
{ | ||
FFTPlugin.Logger.LogInfo("StopVFX FuelLevel: " + _fuelLevel); | ||
StopParticleSystem(); | ||
FFTPlugin.Logger.LogInfo("StopParticleSystem FuelLevel: " + _fuelLevel); | ||
} | ||
public void EnableEmission() | ||
{ | ||
if (_particleSystem != null) | ||
{ | ||
var emission = _particleSystem.emission; | ||
emission.enabled = true; | ||
} | ||
else | ||
{ | ||
FFTPlugin.Logger.LogError("_particleSystem is null in EnableEmission"); | ||
} | ||
} | ||
public void DisableEmission() | ||
{ | ||
if (_particleSystem != null) | ||
{ | ||
var emission = _particleSystem.emission; | ||
emission.enabled = false; | ||
} | ||
else | ||
{ | ||
FFTPlugin.Logger.LogError("_particleSystem is null in DisableEmission"); | ||
} | ||
} | ||
public void StartParticleSystem() | ||
{ | ||
if (_particleSystem != null) | ||
{ | ||
EnableEmission(); | ||
_particleSystem.Play(); | ||
} | ||
else | ||
{ | ||
FFTPlugin.Logger.LogError("_particleSystem is null in _particleSystem.Play"); | ||
} | ||
} | ||
public void StopParticleSystem() | ||
{ | ||
if (_particleSystem != null) | ||
{ | ||
DisableEmission(); | ||
_particleSystem.Stop(); | ||
} | ||
else | ||
{ | ||
FFTPlugin.Logger.LogError("_particleSystem is null in _particleSystem.Stop"); | ||
} | ||
} | ||
public bool FuelLevelExceedsThreshold() | ||
{ | ||
return _fuelLevel > 0.8f; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
using FFT.Modules; | ||
using KSP.Sim.impl; | ||
using System; | ||
|
||
namespace FFT.Modules | ||
{ | ||
public class PartComponentModule_TriggerVFX : PartComponentModule | ||
{ | ||
public override Type PartBehaviourModuleType => typeof(Module_TriggerVFX); | ||
} | ||
} |
Oops, something went wrong.