Add TankManager with module registration and recheck functionality

This commit is contained in:
2025-02-25 14:48:06 +01:00
parent 8fbabf3931
commit 573c517dac
3 changed files with 56 additions and 3 deletions

View File

@@ -1,6 +1,4 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Linq;
using BepInEx;
using BepInEx.Configuration;
using HarmonyLib;
@@ -45,6 +43,7 @@ namespace TerraTech {
ModuleWeaponManager.Setup(Config);
ModuleHeartManager.Setup(Config);
ModuleFuelTankManager.Setup(Config);
TankManager.Setup(Config);
xpMultiplier =
Config.Bind("General", "XP Multiplier", 1f,

View File

@@ -0,0 +1,53 @@
using System;
using System.Collections.Generic;
using BepInEx.Configuration;
using HarmonyLib;
using UnityEngine;
namespace TerraTech {
[HarmonyPatch]
public class TankManager {
public static ConfigEntry<bool> recheck;
public static Dictionary<Type, Func<Module, bool>> moduleManagerMapper =
new Dictionary<Type, Func<Module, bool>>();
public static void Setup(ConfigFile config) {
recheck = config.Bind("Tank", "Recheck", false, new ConfigDescription("Recheck"));
moduleManagerMapper.Add(typeof(ModuleBooster), ModuleBoosterManager.Register);
moduleManagerMapper.Add(typeof(ModuleEnergy), ModuleEnergyManager.Register);
moduleManagerMapper.Add(typeof(ModuleEnergyStore), ModuleEnergyStoreManager.Register);
moduleManagerMapper.Add(typeof(ModuleFuelTank), ModuleFuelTankManager.Register);
moduleManagerMapper.Add(typeof(ModuleGyro), ModuleGyroManager.Register);
moduleManagerMapper.Add(typeof(ModuleHeart), ModuleHeartManager.Register);
moduleManagerMapper.Add(typeof(ModuleItemHolder), ModuleItemHolderManager.Register);
moduleManagerMapper.Add(typeof(ModuleItemProducer), ModuleItemProducerManager.Register);
moduleManagerMapper.Add(typeof(ModuleRemoteCharger), ModuleRemoteChargerManager.Register);
moduleManagerMapper.Add(typeof(ModuleShieldGenerator), ModuleShieldGeneratorManager.Register);
moduleManagerMapper.Add(typeof(ModuleWeaponGun), ModuleWeaponGunManager.Register);
moduleManagerMapper.Add(typeof(ModuleWeapon), ModuleWeaponManager.Register);
moduleManagerMapper.Add(typeof(ModuleWheels), ModuleWheelsManager.Register);
moduleManagerMapper.Add(typeof(ModuleWing), ModuleWingManager.Register);
}
[HarmonyPrefix]
[HarmonyPatch(typeof(Tank), "NotifyAnchor")]
public static void PostfixCreate(Tank __instance, ModuleAnchor anchor, bool anchored) {
if (Main.debug.Value)
Console.WriteLine("TankManager.NotifyAnchor: {0}", __instance);
if (!__instance.ControllableByLocalPlayer)
return;
if (!recheck.Value)
return;
foreach (Transform child in __instance.transform) {
GameObject childObj = child.gameObject;
Component[] components = childObj.GetComponents<Component>();
foreach (Component component in components) {
Func<Module, bool> manager;
if (moduleManagerMapper.TryGetValue(component.GetType(), out manager))
manager(component as Module);
}
}
}
}
}

View File

@@ -59,6 +59,7 @@
<Compile Include="ModuleHeartManager.cs" />
<Compile Include="ModuleFuelTankManager.cs" />
<Compile Include="ProjectilePatch.cs" />
<Compile Include="TankManager.cs" />
</ItemGroup>
<ItemGroup>
<Reference Include="0Harmony">