diff --git a/Winch/Util/GridConfigUtil.cs b/Winch/Util/GridConfigUtil.cs index f5f5c95..cf63db0 100644 --- a/Winch/Util/GridConfigUtil.cs +++ b/Winch/Util/GridConfigUtil.cs @@ -1,5 +1,6 @@ using System.Collections.Generic; using System.Linq; +using UnityEngine; using UnityEngine.AddressableAssets; using Winch.Core; using Winch.Data.GridConfig; @@ -25,13 +26,43 @@ internal static bool PopulateCellGroupConfigFromMetaWithConverter(UnstructedCell internal static List VanillaGridConfigIDList = new(); internal static Dictionary VanillaGridKeyDict = new(); + internal static void CreateTier1() + { + if (!GameManager.Instance.GameConfigData.gridConfigs.ContainsKey(GridKeyExtra.UPGRADE_T1_HULL)) + { + var tier1 = ScriptableObject.CreateInstance().Rename("Tier1HullInput").DontDestroyOnLoad(); + tier1.mainItemType = ItemType.GENERAL; + tier1.mainItemSubtype = ItemSubtype.MATERIAL; + GameManager.Instance.GameConfigData.gridConfigs.Add(GridKeyExtra.UPGRADE_T1_HULL, tier1); + } + } + + internal static void SpecialVanillaGridHandler(GridKey key, GridConfiguration value) + { + switch (key) + { + case GridKey.UPGRADE_T2_HULL: + case GridKey.UPGRADE_T3_HULL: + case GridKey.UPGRADE_T4_HULL: + case GridKey.UPGRADE_T5_HULL: + value.name += "Input"; + break; + } + } + internal static void Initialize() { Addressables.LoadAssetsAsync(AddressablesUtil.GetLocations("GridConfigData"), gridConfig => VanillaGridConfigIDList.SafeAdd(gridConfig.name)); - GameManager.Instance.GameConfigData.gridConfigs.AddOrChange(GridKeyExtra.UPGRADE_T1_HULL, GameManager.Instance.GameConfigData.hullTierGridConfigs[0]); + + GameManager.Instance.GameConfigData.hullTierGridConfigs.ForEach( + gridConfig => VanillaGridConfigIDList.SafeAdd(gridConfig.name)); + + CreateTier1(); + GameManager.Instance.GameConfigData.gridConfigs.ForEach(kvp => { + SpecialVanillaGridHandler(kvp.Key, kvp.Value); VanillaGridConfigIDList.Add(kvp.Value.name); VanillaGridKeyDict.Add(kvp.Key, kvp.Value.name); }); @@ -76,6 +107,18 @@ public static DeferredGridConfiguration GetModdedGridConfiguration(string id) return null; } + public static bool TryGetGridConfiguration(GridKey gridKey, out GridConfiguration gridConfig) + { + gridConfig = null; + if (gridKey == GridKey.NONE) + return false; + + if (GameManager.Instance.GameConfigData.gridConfigs.TryGetValue(gridKey, out gridConfig)) + return true; + + return false; + } + internal static void AddModdedGridConfigurations(IList list) { foreach (var gridConfig in ModdedGridConfigDict.Values) @@ -108,11 +151,6 @@ internal static void FixGridConfigurations() // Change grid configurations to the addressable ones foreach (var kvp in GameManager.Instance.GameConfigData.gridConfigs.Where(kvp => VanillaGridKeyDict.ContainsKey(kvp.Key) && (kvp.Value == null || (kvp.Value != null && AllGridConfigDict.ContainsKey(kvp.Value.name)))).ToArray()) GameManager.Instance.GameConfigData.gridConfigs.AddOrChange(kvp.Key, AllGridConfigDict[VanillaGridKeyDict[kvp.Key]]); - GameManager.Instance.GameConfigData.hullTierGridConfigs[0] = GameManager.Instance.GameConfigData.gridConfigs[GridKeyExtra.UPGRADE_T1_HULL]; - GameManager.Instance.GameConfigData.hullTierGridConfigs[1] = GameManager.Instance.GameConfigData.gridConfigs[GridKey.UPGRADE_T2_HULL]; - GameManager.Instance.GameConfigData.hullTierGridConfigs[2] = GameManager.Instance.GameConfigData.gridConfigs[GridKey.UPGRADE_T3_HULL]; - GameManager.Instance.GameConfigData.hullTierGridConfigs[3] = GameManager.Instance.GameConfigData.gridConfigs[GridKey.UPGRADE_T4_HULL]; - GameManager.Instance.GameConfigData.hullTierGridConfigs[4] = GameManager.Instance.GameConfigData.gridConfigs[GridKey.UPGRADE_T5_HULL]; } internal static void ClearGridConfigurations() diff --git a/Winch/Util/QuestUtil.cs b/Winch/Util/QuestUtil.cs index e9bfa1a..a6167da 100644 --- a/Winch/Util/QuestUtil.cs +++ b/Winch/Util/QuestUtil.cs @@ -290,6 +290,9 @@ internal static void PopulateQuestGridConfig(string key, QuestGridConfig value) { AllQuestGridConfigDict.SafeAdd(key, value); WinchCore.Log.Debug($"Added quest grid config {key} to AllQuestGridConfigDict"); + + if (GridConfigUtil.TryGetGridConfiguration(value.gridKey, out GridConfiguration gridConfig)) + value.gridConfiguration = gridConfig; } internal static void PopulateQuestGridConfigs(IList result) diff --git a/Winch/Util/UpgradeUtil.cs b/Winch/Util/UpgradeUtil.cs index 14b21e8..bd71f18 100644 --- a/Winch/Util/UpgradeUtil.cs +++ b/Winch/Util/UpgradeUtil.cs @@ -31,7 +31,17 @@ internal static void Initialize() upgradeData => { VanillaUpgradeIDList.SafeAdd(upgradeData.id); - if (upgradeData.gridConfig != null) QuestUtil.VanillaQuestGridConfigIDList.SafeAdd(upgradeData.gridConfig.name); + if (upgradeData.gridConfig != null) + { + QuestUtil.VanillaQuestGridConfigIDList.SafeAdd(upgradeData.gridConfig.name); + GridConfigUtil.VanillaGridConfigIDList.SafeAdd(upgradeData.gridConfig.gridConfiguration.name); + + if (GameManager.Instance.GameConfigData.TryGetGridConfigForKey(upgradeData.gridConfig.gridKey, out GridConfiguration gridConfig)) + upgradeData.gridConfig.gridConfiguration = gridConfig; + + if (upgradeData is HullUpgradeData hullUpgradeData && GameManager.Instance.GameConfigData.hullTierGridConfigs.Count >= hullUpgradeData.tier) + hullUpgradeData.hullGridConfiguration = GameManager.Instance.GameConfigData.hullTierGridConfigs[hullUpgradeData.tier - 1]; + } }); } @@ -123,12 +133,18 @@ internal static void PopulateUpgradeData(IList result) { AllHullUpgradeDataDict.SafeAdd(hullUpgradeData.id, hullUpgradeData); WinchCore.Log.Debug($"Added upgrade data {hullUpgradeData.id} to AllHullUpgradeDataDict"); + + if (hullUpgradeData is not DeferredHullUpgradeData && GameManager.Instance.GameConfigData.hullTierGridConfigs.Count >= hullUpgradeData.tier) + hullUpgradeData.hullGridConfiguration = GameManager.Instance.GameConfigData.hullTierGridConfigs[hullUpgradeData.tier - 1]; } if (upgradeData is SlotUpgradeData slotUpgradeData) { AllSlotUpgradeDataDict.SafeAdd(slotUpgradeData.id, slotUpgradeData); WinchCore.Log.Debug($"Added upgrade data {slotUpgradeData.id} to AllSlotUpgradeDataDict"); } + + if (GameManager.Instance.GameConfigData.TryGetGridConfigForKey(upgradeData.gridConfig.gridKey, out GridConfiguration gridConfig)) + upgradeData.gridConfig.gridConfiguration = gridConfig; } foreach (var upgradeData in ModdedUpgradeDataDict.Values.OfType()) { diff --git a/Winch/Util/WinchExtensions.cs b/Winch/Util/WinchExtensions.cs index 482091f..edd5e5e 100644 --- a/Winch/Util/WinchExtensions.cs +++ b/Winch/Util/WinchExtensions.cs @@ -1327,6 +1327,12 @@ public static void ConstructUpgradeTooltip(this TooltipUI tooltipUI, UpgradeData public static bool TryGetGridConfigForKey(this GameConfigData gameConfigData, GridKey key, out GridConfiguration gridConfig) { + if (key == GridKey.NONE) + { + gridConfig = null; + return false; + } + return gameConfigData.gridConfigs.TryGetValue(key, out gridConfig) && gridConfig != null; }