Skip to content

Commit

Permalink
Merge pull request #12 from cvusmo/dev
Browse files Browse the repository at this point in the history
Dev
  • Loading branch information
blacksheepcosmo authored Aug 30, 2023
2 parents ccab55a + c050440 commit 6baba10
Show file tree
Hide file tree
Showing 15 changed files with 247 additions and 307 deletions.
15 changes: 12 additions & 3 deletions FFTProject/Controllers/LoadModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@
using FFT.Modules;
using FFT.Utilities;
using Newtonsoft.Json;
using System;

namespace FFT.Controllers
{
Expand All @@ -30,7 +29,12 @@ public class LoadModule : ILoadModule
private ModuleController _moduleController;
private StartModule _startModule;
private ResetModule _resetModule;
private Module_VentValve _moduleVentValve;
private Module_VentValve _moduleVentValve;
private Data_ValveParts _dataValveParts;
private Data_VentValve _dataVentValve;
private Data_FuelTanks _dataFuelTanks;
private FuelTankDefinitions _fuelTankDefinitions;
private VentValveDefinitions _ventValveDefinitions;

public event Action ModuleResetRequested;

Expand Down Expand Up @@ -58,6 +62,11 @@ public void InitializeDependencies()
_startModule = StartModule.Instance;
_resetModule = ResetModule.Instance;
_moduleVentValve = new Module_VentValve();
_dataValveParts = new Data_ValveParts();
_dataVentValve = new Data_VentValve();
_dataFuelTanks = new Data_FuelTanks();
_fuelTankDefinitions = new FuelTankDefinitions();
_ventValveDefinitions = new VentValveDefinitions();
}
public void Boot()
{
Expand Down Expand Up @@ -90,4 +99,4 @@ public void Load()
}
}
}
}
}
6 changes: 1 addition & 5 deletions FFTProject/Controllers/ModuleController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@
//| 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
{
Expand Down Expand Up @@ -85,4 +81,4 @@ internal void ResetAllModuleStates()
ShouldResetModule = false;
}
}
}
}
4 changes: 2 additions & 2 deletions FFTProject/Controllers/StartModule.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ internal StartModule(MessageManager messageManager, ManualLogSource logger)
}
public void StartVentValve()
{
if (DateTime.Now - _lastEventTriggerTime < ThrottleTimeSpan) return; // Throttling
if (DateTime.Now - _lastEventTriggerTime < ThrottleTimeSpan) return;
_lastEventTriggerTime = DateTime.Now;

Utility.RefreshActiveVesselAndCurrentManeuver();
Expand Down Expand Up @@ -91,4 +91,4 @@ public void DeactivateModule(ModuleController.ModuleType moduleType)
}
}
}
}
}
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
50 changes: 17 additions & 33 deletions FFTProject/FFTPlugin.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,10 @@
using FFT.Controllers;
using FFT.Controllers.Interfaces;
using FFT.Managers;
using FFT.Modules;
using FFT.Utilities;
using KSP.Messages;
using SpaceWarp;
using SpaceWarp.API.Mods;
using FFT.Modules;

namespace FFT
{
Expand All @@ -23,6 +22,8 @@ internal class FFTPlugin : BaseSpaceWarpPlugin, IModuleController
public ConfigEntry<bool> FFTConfig { get; private set; }

internal readonly ManualLogSource _logger = BepInEx.Logging.Logger.CreateLogSource("FFTPlugin");
public static FFTPlugin Instance { get; private set; }
public static string Path { get; private set; }

private Manager _manager;
private ConditionsManager _conditionsManager;
Expand All @@ -33,11 +34,6 @@ internal class FFTPlugin : BaseSpaceWarpPlugin, IModuleController
private RefreshVesselData _refreshVesselData;
private ModuleController _moduleController;
private Module_VentValve _moduleVentValve;
private FuelTankDefinitions _fuelTankDefinitions;
private VentValveDefinitions _ventValveDefinitions;
private Data_ValveParts _dataValveParts;
private Data_FuelTanks _dataFuelTanks;
public static FFTPlugin Instance { get; private set; }
public FFTPlugin()
{
if (Instance != null)
Expand All @@ -46,32 +42,19 @@ public FFTPlugin()
}
Instance = this;
}
public static string Path { get; private set; }
public override void OnPreInitialized()
{
FFTPlugin.Path = this.PluginFolderPath;
Path = this.PluginFolderPath;
base.OnPreInitialized();
_logger.LogInfo("OnPreInitialized FFTPlugin.");
}

public override void OnInitialized()
{
base.OnInitialized();
_logger.LogInfo("Initializing FFTPlugin...");

_fuelTankDefinitions = FuelTankDefinitions.Instance;
//_fuelTankDefinitions = new FuelTankDefinitions();
_dataFuelTanks = new Data_FuelTanks();
_ventValveDefinitions = VentValveDefinitions.Instance;
//_ventValveDefinitions = new VentValveDefinitions();
_dataValveParts = new Data_ValveParts();
_logger.LogInfo("Initializing FFTPlugin...");

Config.Bind(
"Fancy Fuel Tanks Settings",
"Enable VFX",
true,
"Fancy Fuel Tanks adds Dynamic Environmental Effects to fuel tanks"
);
Config.Bind("Fancy Fuel Tanks Settings", "Enable VFX", true, "Fancy Fuel Tanks adds Dynamic Environmental Effects to fuel tanks");

try
{
Expand Down Expand Up @@ -101,33 +84,34 @@ public override void OnPostInitialized()
try
{
_conditionsManager = ConditionsManager.Instance;
_logger.LogInfo("ConditionsManager initialized successfully.");

_moduleController = ModuleController.Instance;
_logger.LogInfo("ModuleController initialized successfully.");

_startModule = StartModule.Instance;
_logger.LogInfo("StartModule initialized successfully.");

Manager.InitializeInstance();
_manager = Manager.Instance;
_logger.LogInfo("Manager initialized successfully.");

_refreshVesselData = RefreshVesselData.Instance;
_logger.LogInfo("RefreshVesselData initialized successfully.");

_resetModule = new ResetModule(_conditionsManager, _manager, _moduleController, _refreshVesselData);
_logger.LogInfo("ResetModule initialized successfully.");

_moduleVentValve = new Module_VentValve();
_logger.LogDebug("ModuleVentValve initialized successfully.");

LogInitializationSuccesses();
}
catch (Exception ex)
{
_logger.LogError($"Error during OnPostInitialized: {ex.Message}");
}
}
private void LogInitializationSuccesses()
{
_logger.LogInfo("ConditionsManager initialized successfully.");
_logger.LogInfo("ModuleController initialized successfully.");
_logger.LogInfo("StartModule initialized successfully.");
_logger.LogInfo("Manager initialized successfully.");
_logger.LogInfo("RefreshVesselData initialized successfully.");
_logger.LogInfo("ResetModule initialized successfully.");
_logger.LogDebug("ModuleVentValve initialized successfully.");
}
private void HandleException(Exception ex, string context)
{
_logger.LogError($"Error in {context}: {ex}");
Expand Down
5 changes: 2 additions & 3 deletions FFTProject/Managers/ConditionsManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
using FFT.Utilities;
using KSP.Game;
using KSP.Messages;
using System;

namespace FFT.Managers
{
Expand Down Expand Up @@ -46,7 +45,7 @@ internal ConditionsManager(MessageManager messageManager, ManualLogSource logger
_messageManager.GameStateEntered -= GameStateEnteredHandler;
_messageManager.GameStateLeft -= GameStateLeftHandler;
_messageManager.VesselSituationChanged -= HandleVesselSituationChanged;
}
}
internal void CheckConditionsAndInformManager()
{
if (ConditionsReady())
Expand All @@ -70,7 +69,7 @@ public void HandleModuleLoaded()
public void ResetModuleState()
{
Manager.Instance.OnModuleReset();
}
}
internal void GameStateEnteredHandler(MessageCenterMessage obj)
{
try
Expand Down
13 changes: 12 additions & 1 deletion FFTProject/Managers/Manager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
//|====================================================|1|
using BepInEx.Logging;
using FFT.Controllers;
using FFT.Modules;
using FFT.Utilities;
using KSP.Game;

Expand All @@ -20,6 +21,9 @@ public class Manager
private readonly ModuleController _moduleController;
private readonly LoadModule _loadModule;
private readonly StartModule _startModule;
private readonly ResetModule _resetModule;
private Module_VentValve _ventValveModule;

private bool isModuleLoaded = false;
public static Manager Instance { get; private set; }
private Manager()
Expand All @@ -30,6 +34,8 @@ private Manager()
_messageManager = MessageManager.Instance ?? throw new InvalidOperationException("MessageManager is not initialized.");
_moduleController = ModuleController.Instance ?? throw new InvalidOperationException("ModuleController is not initialized.");
_loadModule = LoadModule.Instance;
_resetModule = ResetModule.Instance ?? throw new InvalidOperationException("ResetModule is not initialized.");

if (_loadModule == null)
{
throw new InvalidOperationException("LoadModule is not initialized.");
Expand Down Expand Up @@ -75,6 +81,10 @@ internal void LoadModuleForFlight()
{
Modules.Add(_loadModule);
}

_ventValveModule = new Module_VentValve();
_ventValveModule.OnInitialize();

isModuleLoaded = true;
}
internal List<LoadModule> InitializeModules()
Expand Down Expand Up @@ -111,7 +121,7 @@ public void UpdateStartModule()

_startModule?.StartVentValve();
Logger.LogDebug("Module started");

_ventValveModule.Activate();
ConditionsManager.Instance.HandleModuleLoaded();
}
internal bool IsStartingModule()
Expand All @@ -123,6 +133,7 @@ internal void OnModuleReset()
{
_moduleController?.ResetAllModuleStates();
Logger.LogInfo("All Modules have been Reset");
_ventValveModule.Deactivate();
}
}
}
33 changes: 17 additions & 16 deletions FFTProject/Modules/Data_FuelTanks.cs
Original file line number Diff line number Diff line change
@@ -1,26 +1,13 @@
using KSP.Sim.Definitions;
using UnityEngine;
using UnityEngine;
using System.Collections.Generic;
using KSP.Sim.Definitions;

namespace FFT.Modules
{
[Serializable]
public class Data_FuelTanks : ModuleData
{
public override Type ModuleType => typeof(Module_VentValve);
public Dictionary<string, GameObject> fuelTankDict;

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

fuelTankDict.Add("CV401", CV401);
fuelTankDict.Add("CV411", CV411);
fuelTankDict.Add("CV421", CV421);
fuelTankDict.Add("SP701", SP701);
fuelTankDict.Add("SR812", SR812);
fuelTankDict.Add("SR812A", SR812A);
fuelTankDict.Add("SR813", SR813);
}

[SerializeField]
public GameObject CV401;
Expand All @@ -37,5 +24,19 @@ public void Awake()
[SerializeField]
public GameObject SR813;

public GameObject GetFuelTank(string tankName)
{
switch (tankName)
{
case "CV401": return CV401;
case "CV411": return CV411;
case "CV421": return CV421;
case "SP701": return SP701;
case "SR812": return SR812;
case "SR812A": return SR812A;
case "SR813": return SR813;
default: return null;
}
}
}
}
Loading

0 comments on commit 6baba10

Please sign in to comment.