Skip to content

Commit

Permalink
Fix grid bug
Browse files Browse the repository at this point in the history
was caused by hull tier upgrade input and hull tier inventory being named the same
  • Loading branch information
MegaPiggy committed Sep 27, 2024
1 parent deac734 commit 745610c
Show file tree
Hide file tree
Showing 4 changed files with 70 additions and 7 deletions.
50 changes: 44 additions & 6 deletions Winch/Util/GridConfigUtil.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using System.Linq;
using UnityEngine;
using UnityEngine.AddressableAssets;
using Winch.Core;
using Winch.Data.GridConfig;
Expand All @@ -25,13 +26,43 @@ internal static bool PopulateCellGroupConfigFromMetaWithConverter(UnstructedCell
internal static List<string> VanillaGridConfigIDList = new();
internal static Dictionary<GridKey, string> VanillaGridKeyDict = new();

internal static void CreateTier1()
{
if (!GameManager.Instance.GameConfigData.gridConfigs.ContainsKey(GridKeyExtra.UPGRADE_T1_HULL))
{
var tier1 = ScriptableObject.CreateInstance<GridConfiguration>().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<GridConfiguration>(AddressablesUtil.GetLocations<GridConfiguration>("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);
});
Expand Down Expand Up @@ -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<GridConfiguration> list)
{
foreach (var gridConfig in ModdedGridConfigDict.Values)
Expand Down Expand Up @@ -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()
Expand Down
3 changes: 3 additions & 0 deletions Winch/Util/QuestUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<QuestGridConfig> result)
Expand Down
18 changes: 17 additions & 1 deletion Winch/Util/UpgradeUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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];
}
});
}

Expand Down Expand Up @@ -123,12 +133,18 @@ internal static void PopulateUpgradeData(IList<UpgradeData> 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<IDeferredUpgradeData>())
{
Expand Down
6 changes: 6 additions & 0 deletions Winch/Util/WinchExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 745610c

Please sign in to comment.