Add TankManager with module registration and recheck functionality
This commit is contained in:
@@ -1,6 +1,4 @@
|
|||||||
using System;
|
using System.Linq;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Linq;
|
|
||||||
using BepInEx;
|
using BepInEx;
|
||||||
using BepInEx.Configuration;
|
using BepInEx.Configuration;
|
||||||
using HarmonyLib;
|
using HarmonyLib;
|
||||||
@@ -45,6 +43,7 @@ namespace TerraTech {
|
|||||||
ModuleWeaponManager.Setup(Config);
|
ModuleWeaponManager.Setup(Config);
|
||||||
ModuleHeartManager.Setup(Config);
|
ModuleHeartManager.Setup(Config);
|
||||||
ModuleFuelTankManager.Setup(Config);
|
ModuleFuelTankManager.Setup(Config);
|
||||||
|
TankManager.Setup(Config);
|
||||||
|
|
||||||
xpMultiplier =
|
xpMultiplier =
|
||||||
Config.Bind("General", "XP Multiplier", 1f,
|
Config.Bind("General", "XP Multiplier", 1f,
|
||||||
|
53
Projects/TerraTech/TerraTech/TankManager.cs
Normal file
53
Projects/TerraTech/TerraTech/TankManager.cs
Normal 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
@@ -59,6 +59,7 @@
|
|||||||
<Compile Include="ModuleHeartManager.cs" />
|
<Compile Include="ModuleHeartManager.cs" />
|
||||||
<Compile Include="ModuleFuelTankManager.cs" />
|
<Compile Include="ModuleFuelTankManager.cs" />
|
||||||
<Compile Include="ProjectilePatch.cs" />
|
<Compile Include="ProjectilePatch.cs" />
|
||||||
|
<Compile Include="TankManager.cs" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="0Harmony">
|
<Reference Include="0Harmony">
|
||||||
|
Reference in New Issue
Block a user