-
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 #11 from cvusmo/dev
Dev
- Loading branch information
Showing
27 changed files
with
1,302 additions
and
563 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
using KSP.Messages; | ||
|
||
namespace FFT.Controllers.Interfaces | ||
{ | ||
public interface IListener | ||
{ | ||
public interface IGameStateListener | ||
{ | ||
event Action<GameStateEnteredMessage> GameStateEntered; | ||
event Action<GameStateLeftMessage> GameStateLeft; | ||
} | ||
|
||
public interface IVesselSituationListener | ||
{ | ||
event Action<VesselSituationChangedMessage> VesselSituationChanged; | ||
} | ||
} | ||
} |
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,9 @@ | ||
namespace FFT.Controllers.Interfaces | ||
{ | ||
public interface ILoadModule | ||
{ | ||
void Boot(); | ||
void PreLoad(); | ||
void Load(); | ||
} | ||
} |
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,7 @@ | ||
namespace FFT.Controllers.Interfaces | ||
{ | ||
public interface IModuleController | ||
{ | ||
void SetLoadModule(ILoadModule loadModule); | ||
} | ||
} |
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,12 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace FFT.Controllers.Interfaces | ||
{ | ||
public interface IResetModule | ||
{ | ||
void Reset(); | ||
void Unload(); | ||
} | ||
} |
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,13 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Text; | ||
|
||
namespace FFT.Controllers.Interfaces | ||
{ | ||
public interface IStartModule | ||
{ | ||
void StartVentValve(); | ||
void ActivateModule(ModuleController.ModuleType moduleType); | ||
void DeactivateModule(ModuleController.ModuleType moduleType); | ||
} | ||
} |
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,93 @@ | ||
//|=====================Summary========================|0| | ||
//| Ensures that the correct module gets loaded |1| | ||
//|by cvusmo===========================================|4| | ||
//|====================================================|1| | ||
|
||
using BepInEx.Logging; | ||
using FFT.Controllers.Interfaces; | ||
using FFT.Managers; | ||
using FFT.Modules; | ||
using FFT.Utilities; | ||
using Newtonsoft.Json; | ||
using System; | ||
|
||
namespace FFT.Controllers | ||
{ | ||
[JsonObject(MemberSerialization.OptIn)] | ||
public class LoadModule : ILoadModule | ||
{ | ||
[JsonProperty] | ||
public bool EnableVFX { get; private set; } = true; | ||
|
||
private static readonly object _lock = new object(); | ||
private readonly ManualLogSource _logger = BepInEx.Logging.Logger.CreateLogSource("LoadModule: "); | ||
|
||
internal RefreshVesselData.RefreshActiveVessel RefreshActiveVessel => RefreshVesselData.Instance.RefreshActiveVesselInstance; | ||
|
||
private Manager _manager; | ||
private MessageManager _messageManager; | ||
private ConditionsManager _conditionsManager; | ||
private ModuleController _moduleController; | ||
private StartModule _startModule; | ||
private ResetModule _resetModule; | ||
private Module_VentValve _moduleVentValve; | ||
|
||
public event Action ModuleResetRequested; | ||
|
||
private static LoadModule _instance; | ||
private static readonly Lazy<LoadModule> _lazyInstance = new Lazy<LoadModule>(() => new LoadModule()); | ||
public static LoadModule Instance | ||
{ | ||
get | ||
{ | ||
if (_instance == null) | ||
{ | ||
_instance = _lazyInstance.Value; | ||
_instance.InitializeDependencies(); | ||
} | ||
return _instance; | ||
} | ||
} | ||
private LoadModule() { } | ||
public void InitializeDependencies() | ||
{ | ||
_manager = Manager.Instance; | ||
_messageManager = MessageManager.Instance; | ||
_conditionsManager = ConditionsManager.Instance; | ||
_moduleController = ModuleController.Instance; | ||
_startModule = StartModule.Instance; | ||
_resetModule = ResetModule.Instance; | ||
_moduleVentValve = new Module_VentValve(); | ||
} | ||
public void Boot() | ||
{ | ||
Utility.RefreshGameManager(); | ||
if (RefreshActiveVessel.IsFlightActive && EnableVFX) | ||
{ | ||
_logger.LogInfo("Booting Module_VentValve"); | ||
_moduleController.SetModuleState(ModuleController.ModuleType.ModuleVentValve, true); | ||
PreLoad(); | ||
} | ||
} | ||
public void PreLoad() | ||
{ | ||
Utility.RefreshGameManager(); | ||
if (_moduleController.GetModuleState(ModuleController.ModuleType.ModuleVentValve)) | ||
{ | ||
_logger.LogInfo("Preloading Module_VentValve"); | ||
_moduleVentValve = new Module_VentValve(); | ||
Load(); | ||
} | ||
} | ||
public void Load() | ||
{ | ||
Utility.RefreshGameManager(); | ||
if (RefreshActiveVessel.IsFlightActive && _moduleController.GetModuleState(ModuleController.ModuleType.ModuleVentValve)) | ||
{ | ||
_logger.LogInfo("Loading Module_VentValve"); | ||
_messageManager.SubscribeToMessages(); | ||
_moduleController.IsModuleLoaded = true; | ||
} | ||
} | ||
} | ||
} |
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,88 @@ | ||
//|=====================Summary========================|0| | ||
//| Dictionary for module types |1| | ||
//|by cvusmo===========================================|4| | ||
//|====================================================|1| | ||
using FFT.Controllers.Interfaces; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
|
||
namespace FFT.Controllers | ||
{ | ||
public sealed class ModuleController | ||
{ | ||
private readonly Dictionary<ModuleType, bool> moduleStates = new Dictionary<ModuleType, bool>(); | ||
private static ModuleController _instance; | ||
private static readonly object _lock = new object(); | ||
public enum ModuleType | ||
{ | ||
Default = 0, | ||
ModuleVentValve = 1, | ||
ModuleOne = 2, | ||
ModuleTwo = 3, | ||
ModuleThree = 4, | ||
ModuleFour = 5 | ||
} | ||
internal bool IsModuleLoaded { get; set; } | ||
internal bool ShouldResetModule { get; set; } | ||
internal static ModuleController Instance | ||
{ | ||
get | ||
{ | ||
if (_instance == null) | ||
{ | ||
lock (_lock) | ||
{ | ||
if (_instance == null) | ||
{ | ||
_instance = new ModuleController(); | ||
} | ||
} | ||
} | ||
return _instance; | ||
} | ||
} | ||
private ModuleController() | ||
{ | ||
InitializeModuleStates(); | ||
} | ||
private void InitializeModuleStates() | ||
{ | ||
foreach (ModuleType moduleType in Enum.GetValues(typeof(ModuleType))) | ||
{ | ||
moduleStates[moduleType] = false; | ||
} | ||
} | ||
internal void SetModuleState(ModuleType type, bool state) | ||
{ | ||
if (!moduleStates.ContainsKey(type)) | ||
{ | ||
throw new ArgumentException($"Unsupported ModuleType: {type}"); | ||
} | ||
|
||
moduleStates[type] = state; | ||
} | ||
internal bool GetModuleState(ModuleType type) | ||
{ | ||
if (moduleStates.TryGetValue(type, out bool state)) | ||
{ | ||
return state; | ||
} | ||
throw new ArgumentException($"Unsupported ModuleType: {type}"); | ||
} | ||
internal void SetVentValveState(bool state) | ||
{ | ||
SetModuleState(ModuleType.ModuleVentValve, state); | ||
} | ||
internal void ResetAllModuleStates() | ||
{ | ||
foreach (var key in moduleStates.Keys.ToList()) | ||
{ | ||
moduleStates[key] = false; | ||
} | ||
|
||
IsModuleLoaded = false; | ||
ShouldResetModule = false; | ||
} | ||
} | ||
} |
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,89 @@ | ||
//|=====================Summary========================|0| | ||
//| Resets the ConditionsManager to its default states |1| | ||
//|by cvusmo===========================================|4| | ||
//|====================================================|1| | ||
using FFT.Controllers.Interfaces; | ||
using FFT.Managers; | ||
using FFT.Utilities; | ||
using Newtonsoft.Json; | ||
|
||
namespace FFT.Controllers | ||
{ | ||
[JsonObject(MemberSerialization.OptIn)] | ||
public class ResetModule : IResetModule | ||
{ | ||
public event Action ModuleResetRequested = delegate { }; | ||
|
||
private readonly ConditionsManager _conditionsManager; | ||
private readonly Manager _manager; | ||
private readonly ModuleController _moduleController; | ||
private readonly RefreshVesselData _vesselData; | ||
private bool? _isFlightActiveCache; | ||
|
||
private static readonly object _lock = new object(); | ||
private static ResetModule _instance; | ||
public ResetModule( | ||
ConditionsManager conditionsManager, | ||
Manager manager, | ||
ModuleController moduleController, | ||
RefreshVesselData vesselData) | ||
{ | ||
_conditionsManager = conditionsManager; | ||
_manager = manager; | ||
_moduleController = moduleController; | ||
_vesselData = vesselData; | ||
} | ||
public static ResetModule Instance | ||
{ | ||
get | ||
{ | ||
if (_instance == null) | ||
{ | ||
lock (_lock) | ||
{ | ||
if (_instance == null) | ||
{ | ||
_instance = new ResetModule(ConditionsManager.Instance, Manager.Instance, ModuleController.Instance, new RefreshVesselData()); | ||
} | ||
} | ||
} | ||
return _instance; | ||
} | ||
} | ||
public void Reset() | ||
{ | ||
if (!_moduleController.ShouldResetModule) return; | ||
|
||
if (Utility.VesselSituations == KSP.Sim.impl.VesselSituations.PreLaunch || | ||
Utility.VesselSituations == KSP.Sim.impl.VesselSituations.Landed || | ||
Utility.VesselSituations == KSP.Sim.impl.VesselSituations.Flying) | ||
{ | ||
ModuleResetRequested.Invoke(); | ||
} | ||
|
||
_moduleController.ShouldResetModule = false; | ||
_moduleController.IsModuleLoaded = false; | ||
} | ||
public void Unload() | ||
{ | ||
bool isFlightCurrentlyActive = _vesselData.RefreshActiveVesselInstance.IsFlightActive; | ||
|
||
if (_isFlightActiveCache.HasValue && !_isFlightActiveCache.Value || | ||
!_isFlightActiveCache.HasValue && !isFlightCurrentlyActive) | ||
{ | ||
_isFlightActiveCache = false; | ||
_manager.Logger.LogInfo("Unloading Module"); | ||
|
||
if (_moduleController.GetModuleState(ModuleController.ModuleType.ModuleVentValve)) | ||
{ | ||
Reset(); | ||
_manager.Logger.LogInfo("Reset Module_VentValve"); | ||
} | ||
} | ||
else | ||
{ | ||
_isFlightActiveCache = true; | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.