diff --git a/Settings.json b/Settings.json new file mode 100644 index 0000000..272f1d7 --- /dev/null +++ b/Settings.json @@ -0,0 +1,4 @@ +{ + "LoadDefaultValidators": "True", + "logLevel": "Debug" +} \ No newline at end of file diff --git a/source/ColorChanger/IColorComponent.cs b/source/ColorChanger/IColorComponent.cs index eb61799..a3e6fd3 100644 --- a/source/ColorChanger/IColorComponent.cs +++ b/source/ColorChanger/IColorComponent.cs @@ -2,8 +2,14 @@ namespace CustomComponents { + /// + /// component has specific color + /// interface IColorComponent { + /// + /// color of component + /// UIColor Color { get; } } } diff --git a/source/ColorChanger/MechComponentRef_GetUIColor_Patch.cs b/source/ColorChanger/MechComponentRef_GetUIColor_Patch.cs index 0426562..4ad7a42 100644 --- a/source/ColorChanger/MechComponentRef_GetUIColor_Patch.cs +++ b/source/ColorChanger/MechComponentRef_GetUIColor_Patch.cs @@ -5,7 +5,7 @@ namespace CustomComponents { [HarmonyPatch(typeof(MechComponentRef), "GetUIColor")] - public static class MechComponentRef_GetUIColor + internal static class MechComponentRef_GetUIColor { [HarmonyPostfix] diff --git a/source/Control.cs b/source/Control.cs index 61ead06..2eb04f5 100644 --- a/source/Control.cs +++ b/source/Control.cs @@ -6,26 +6,33 @@ using System.Collections.Generic; using BattleTech.Data; using System.Text.RegularExpressions; +using BattleTech; namespace CustomComponents { public static class Control { - internal static Mod mod; + public static Mod mod; + public static CustomCompoentSettings settings = new CustomCompoentSettings(); public static void Init(string directory, string settingsJSON) { mod = new Mod(directory); + try { // mod.LoadSettings(settings); + mod.LoadSettings(settings); var harmony = HarmonyInstance.Create("io.github.denadan.CustomComponents"); harmony.PatchAll(Assembly.GetExecutingAssembly()); RegisterCustomTypes(Assembly.GetExecutingAssembly()); - Validator.RegisterValidator(WeighLimitedController.ValidateMech); - Validator.RegisterAddValidator(typeof(IWeightLimited), WeighLimitedController.ValidateAdd); + if (settings.LoadDefaultValidators) + { + Validator.RegisterValidator(WeighLimitedController.ValidateMech); + Validator.RegisterAddValidator(typeof(IWeightLimited), WeighLimitedController.ValidateAdd); + } // logging output can be found under BATTLETECH\BattleTech_Data\output_log.txt // or also under yourmod/log.txt @@ -49,6 +56,11 @@ internal static ICustomComponent CreateNew(string custom_type) private static Dictionary descriptors = new Dictionary(); + + /// + /// register custom types for your assamble + /// + /// public static void RegisterCustomTypes(Assembly assembly) { var desc_list = from type in assembly.GetTypes() @@ -81,7 +93,8 @@ public static bool LoaderPatch(DataManager.ResourceLoadRequest loader, return true; string custom_type = custom.Result("$1"); - Control.mod.Logger.Log("Loading custom: " + custom_type); + + Control.mod.Logger.LogDebug("Loading custom: " + custom_type); var custom_obj = Control.CreateNew(custom_type) as ICustomComponent; if (custom_obj == null || !(custom_obj is T)) @@ -97,6 +110,8 @@ public static bool LoaderPatch(DataManager.ResourceLoadRequest loader, resource = custom_obj as T; Traverse.Create(loader).Method("TryLoadDependencies", resource).GetValue(); + if(custom_obj is MechComponentDef) + Control.mod.Logger.LogDebug("Loaded: " + (custom_obj as MechComponentDef).Description.Id); return false; } diff --git a/source/CustomCompoentSettings.cs b/source/CustomCompoentSettings.cs new file mode 100644 index 0000000..b0e0f48 --- /dev/null +++ b/source/CustomCompoentSettings.cs @@ -0,0 +1,12 @@ +using System; +using System.Collections.Generic; +using System.Text; +using DynModLib; + +namespace CustomComponents +{ + public class CustomCompoentSettings : ModSettings + { + public bool LoadDefaultValidators = true; + } +} diff --git a/source/CustomComponent.cs b/source/CustomComponent.cs index 8b25315..19680d7 100644 --- a/source/CustomComponent.cs +++ b/source/CustomComponent.cs @@ -1,10 +1,11 @@ -using BattleTech; -using System; +using System; using System.Reflection; namespace CustomComponents { - + /// + /// basic interface for custom component + /// public interface ICustomComponent { string CustomType { get; } @@ -12,6 +13,10 @@ public interface ICustomComponent string ToJson(); } + /// + /// mark class as custom component + /// + [AttributeUsage(AttributeTargets.Class)] public class CustomAttribute : Attribute { public string CustomType { get; set; } @@ -22,7 +27,7 @@ public CustomAttribute(string CustomType) } } - public class CustomComponentDescriptor + internal class CustomComponentDescriptor { public string CustomName { get; private set; } public Type ActualType { get; private set; } diff --git a/source/CustomComponents.csproj b/source/CustomComponents.csproj index 54363b9..3ee7e0c 100644 --- a/source/CustomComponents.csproj +++ b/source/CustomComponents.csproj @@ -72,6 +72,7 @@ + diff --git a/source/CustomTypes/CustomAmmunitionBoxDef.cs b/source/CustomTypes/CustomAmmunitionBoxDef.cs index 6e0a471..3b44ce3 100644 --- a/source/CustomTypes/CustomAmmunitionBoxDef.cs +++ b/source/CustomTypes/CustomAmmunitionBoxDef.cs @@ -7,6 +7,10 @@ namespace CustomComponents { + /// + /// Custom ammobox definition + /// + /// Your type public class CustomAmmunitionBoxDef : BattleTech.AmmunitionBoxDef, ICustomComponent where T : CustomAmmunitionBoxDef { diff --git a/source/HarmonyNested/HarmonyNestedAttribute.cs b/source/HarmonyNested/HarmonyNestedAttribute.cs index 1ab84b0..9234672 100644 --- a/source/HarmonyNested/HarmonyNestedAttribute.cs +++ b/source/HarmonyNested/HarmonyNestedAttribute.cs @@ -6,9 +6,11 @@ namespace CustomComponents { + /// + /// mark a patch for private nested class + /// public class HarmonyNestedAttribute : HarmonyPatch { - public HarmonyNestedAttribute(Type baseType, string nestedType, string method, Type[] parameters = null) : base(null, method, null) { @@ -19,7 +21,7 @@ public HarmonyNestedAttribute(Type baseType, string nestedType, string method, T this.info.parameter = parameters; this.info.methodName = method; - Control.mod.Logger.Log(string.Format("Type: {0}\tMethod: {1}", + Control.mod.Logger.LogDebug(string.Format("Type: {0}\tMethod: {1}", this.info.originalType, this.info.methodName)); } } diff --git a/source/Test/TestUpgradeDef.cs b/source/Test/TestUpgradeDef.cs index f5f073b..1e829f6 100644 --- a/source/Test/TestUpgradeDef.cs +++ b/source/Test/TestUpgradeDef.cs @@ -9,7 +9,6 @@ public class TestUpgradeDef : CustomUpgradeDef, IColorComponent public TestUpgradeDef() { - } } diff --git a/source/TypePatch/AmmoBoxPatch.cs b/source/TypePatch/AmmoBoxPatch.cs index 3d3d91c..eee3372 100644 --- a/source/TypePatch/AmmoBoxPatch.cs +++ b/source/TypePatch/AmmoBoxPatch.cs @@ -5,7 +5,7 @@ namespace CustomComponents { [HarmonyNested(typeof(DataManager), "AmmunitionBoxDefLoadRequest", "OnLoadedWithJSON")] - public static class DataManager_AmmunitionBoxDef_Patch + internal static class DataManager_AmmunitionBoxDef_Patch { public static bool Prefix(DataManager.ResourceLoadRequest __instance, string json, ref AmmunitionBoxDef ___resource) @@ -17,7 +17,7 @@ public static bool Prefix(DataManager.ResourceLoadRequest __in } [HarmonyPatch(typeof(AmmunitionBoxDef), "ToJSON")] - public static class AmmunitionBoxDef_ToJSON_Patch + internal static class AmmunitionBoxDef_ToJSON_Patch { public static bool Prefix(AmmunitionBoxDef __instance, ref string __result) { diff --git a/source/TypePatch/HeatSinkPatch.cs b/source/TypePatch/HeatSinkPatch.cs index 3e14b45..fafc869 100644 --- a/source/TypePatch/HeatSinkPatch.cs +++ b/source/TypePatch/HeatSinkPatch.cs @@ -5,7 +5,7 @@ namespace CustomComponents { [HarmonyNested(typeof(DataManager), "HeatSinkDefLoadRequest", "OnLoadedWithJSON")] - public static class DataManager_HeatSink_Patch + internal static class DataManager_HeatSink_Patch { public static bool Prefix(DataManager.ResourceLoadRequest __instance, string json, ref HeatSinkDef ___resource) @@ -17,7 +17,7 @@ public static bool Prefix(DataManager.ResourceLoadRequest __instanc } [HarmonyPatch(typeof(HeatSinkDef), "ToJSON")] - public static class HeatSinkDef_ToJSON_Patch + internal static class HeatSinkDef_ToJSON_Patch { public static bool Prefix(HeatSinkDef __instance, ref string __result) { diff --git a/source/TypePatch/JumpJetPatch.cs b/source/TypePatch/JumpJetPatch.cs index 0412667..6224d68 100644 --- a/source/TypePatch/JumpJetPatch.cs +++ b/source/TypePatch/JumpJetPatch.cs @@ -5,7 +5,7 @@ namespace CustomComponents { [HarmonyNested(typeof(DataManager), "JumpJetDefLoadRequest", "OnLoadedWithJSON")] - public static class DataManager_JumpJet_Patch + internal static class DataManager_JumpJet_Patch { public static bool Prefix(DataManager.ResourceLoadRequest __instance, string json, ref JumpJetDef ___resource) @@ -17,7 +17,7 @@ public static bool Prefix(DataManager.ResourceLoadRequest __instance } [HarmonyPatch(typeof(JumpJetDef), "ToJSON")] - public static class JumpJetDef_ToJSON_Patch + internal static class JumpJetDef_ToJSON_Patch { public static bool Prefix(JumpJetDef __instance, ref string __result) { diff --git a/source/TypePatch/UpgradePatch.cs b/source/TypePatch/UpgradePatch.cs index e104f10..b473a4f 100644 --- a/source/TypePatch/UpgradePatch.cs +++ b/source/TypePatch/UpgradePatch.cs @@ -5,7 +5,7 @@ namespace CustomComponents { [HarmonyNested(typeof(DataManager), "UpgradeDefLoadRequest", "OnLoadedWithJSON")] - public static class DataManager_Upgrade_Patch + internal static class DataManager_Upgrade_Patch { public static bool Prefix(DataManager.ResourceLoadRequest __instance, string json, ref UpgradeDef ___resource) @@ -17,7 +17,7 @@ public static bool Prefix(DataManager.ResourceLoadRequest __instance } [HarmonyPatch(typeof(UpgradeDef), "ToJSON")] - public static class UpgradeDef_ToJSON_Patch + internal static class UpgradeDef_ToJSON_Patch { public static bool Prefix(UpgradeDef __instance, ref string __result) { diff --git a/source/TypePatch/WeaponDefPatch.cs b/source/TypePatch/WeaponDefPatch.cs index 64334f4..4428d6e 100644 --- a/source/TypePatch/WeaponDefPatch.cs +++ b/source/TypePatch/WeaponDefPatch.cs @@ -5,7 +5,7 @@ namespace CustomComponents { [HarmonyNested(typeof(DataManager), "WeaponDefLoadRequest", "OnLoadedWithJSON")] - public static class DataManager_WeaponDef_Patch + internal static class DataManager_WeaponDef_Patch { public static bool Prefix(DataManager.ResourceLoadRequest __instance, string json, ref WeaponDef ___resource) @@ -17,7 +17,7 @@ public static bool Prefix(DataManager.ResourceLoadRequest __instance, } [HarmonyPatch(typeof(WeaponDef), "ToJSON")] - public static class WeaponDef_ToJSON_Patch + internal static class WeaponDef_ToJSON_Patch { public static bool Prefix(WeaponDef __instance, ref string __result) { diff --git a/source/Validators/Validator.cs b/source/Validators/Validator.cs index eb354e3..ba65f5d 100644 --- a/source/Validators/Validator.cs +++ b/source/Validators/Validator.cs @@ -4,26 +4,31 @@ using System; using System.Collections.Generic; using System.Linq; -using System.Text; namespace CustomComponents { - public delegate bool ValidateAddDelegate(MechComponentDef component, MechLabLocationWidget widget, - bool current_result, ref string errorMessage, MechLabPanel mechlab); - - public delegate void ValidateMechDelegate(Dictionary> errors, - MechValidationLevel validationLevel, MechDef mechDef); - + /// + /// Static class to make validation + /// public static class Validator { static Dictionary add_validators = new Dictionary(); static List validators = new List(); + /// + /// register new AddValidator + /// + /// + /// public static void RegisterAddValidator(Type type, ValidateAddDelegate validator) { add_validators.Add(type, validator); } + /// + /// register new mech validator + /// + /// public static void RegisterValidator(ValidateMechDelegate validator) { validators.Add(validator); @@ -71,7 +76,7 @@ MechLabPanel ___mechLab } [HarmonyPatch(typeof(MechValidationRules), "ValidateMechDef")] - public static class MechValidationRulesValidate_ValidateMech_Patch + internal static class MechValidationRulesValidate_ValidateMech_Patch { public static void Postfix(Dictionary> __result, MechValidationLevel validationLevel, MechDef mechDef) diff --git a/source/Validators/ValidatorInterfaces.cs b/source/Validators/ValidatorInterfaces.cs index c08ce92..266f38b 100644 --- a/source/Validators/ValidatorInterfaces.cs +++ b/source/Validators/ValidatorInterfaces.cs @@ -4,15 +4,56 @@ namespace CustomComponents { + /// + /// component check if it can be added to this location + /// public interface IValidateAdd { + /// + /// validation check + /// + /// location, where check + /// result of previous checks + /// message, that show as warning if cannot add item + /// + /// bool ValidateAdd(MechLabLocationWidget widget, bool current_result, ref string errorMessage, MechLabPanel mechlab); } - + /// + /// component need to validate mech state + /// public interface IMechValidate { + /// + /// validate mech + /// + /// list of errors + /// level of validation + /// mech to check void ValidateMech(Dictionary> errors, MechValidationLevel validationLevel, MechDef mechDef); } + + /// + /// delegate for "component can be added" validation + /// + /// component to validate + /// location to add + /// resulr of previous сруслы + /// error message + /// + /// + public delegate bool ValidateAddDelegate(MechComponentDef component, MechLabLocationWidget widget, + bool current_result, ref string errorMessage, MechLabPanel mechlab); + + /// + /// delegate for mech valudation + /// + /// list of errors + /// level of validation + /// mech to validate + public delegate void ValidateMechDelegate(Dictionary> errors, + MechValidationLevel validationLevel, MechDef mechDef); + } \ No newline at end of file diff --git a/source/WeightLimitation/IWeightLimited.cs b/source/WeightLimitation/IWeightLimited.cs index 2d7b5c8..9fae4dd 100644 --- a/source/WeightLimitation/IWeightLimited.cs +++ b/source/WeightLimitation/IWeightLimited.cs @@ -1,12 +1,17 @@ -using System; -using System.Collections.Generic; -using System.Text; - -namespace CustomComponents +namespace CustomComponents { + /// + /// component limited to mech tonnage + /// public interface IWeightLimited { + /// + /// minimum allowed tonnage + /// int MinTonnage { get; } + /// + /// maximum allowed tonnage + /// int MaxTonnage { get; } } } diff --git a/source/WeightLimitation/MechLabInventoryWidget_ApplyFiltering_Patch.cs b/source/WeightLimitation/MechLabInventoryWidget_ApplyFiltering_Patch.cs index f30efc4..208becd 100644 --- a/source/WeightLimitation/MechLabInventoryWidget_ApplyFiltering_Patch.cs +++ b/source/WeightLimitation/MechLabInventoryWidget_ApplyFiltering_Patch.cs @@ -6,9 +6,9 @@ namespace CustomComponents { [HarmonyPatch(typeof(MechLabInventoryWidget), "ApplyFiltering")] - public static class MechLabInventoryWidget_ApplyFiltering + internal static class MechLabInventoryWidget_ApplyFiltering { - public static void Postfix(MechLabInventoryWidget __instance, float ___mechTonnage, + internal static void Postfix(MechLabInventoryWidget __instance, float ___mechTonnage, List ___localInventory) { foreach (var item in ___localInventory) diff --git a/source/WeightLimitation/WeighLimitedController.cs b/source/WeightLimitation/WeighLimitedController.cs index 88857ba..c974f98 100644 --- a/source/WeightLimitation/WeighLimitedController.cs +++ b/source/WeightLimitation/WeighLimitedController.cs @@ -7,7 +7,7 @@ namespace CustomComponents { internal static class WeighLimitedController { - public static bool ValidateAdd(MechComponentDef component, MechLabLocationWidget widget, + internal static bool ValidateAdd(MechComponentDef component, MechLabLocationWidget widget, bool current_result, ref string errorMessage, MechLabPanel mechlab) { if (!current_result) @@ -29,7 +29,7 @@ public static bool ValidateAdd(MechComponentDef component, MechLabLocationWidget return true; } - public static void ValidateMech(Dictionary> errors, + internal static void ValidateMech(Dictionary> errors, MechValidationLevel validationLevel, MechDef mechDef) { foreach (var component in mechDef.Inventory.Where(i => i.Def != null).Select(i => i.Def).OfType())