From 1e77ada8f291d7cb947279b8558268f5e0b8b90f Mon Sep 17 00:00:00 2001 From: Noah Pilarski Date: Fri, 13 Sep 2024 13:17:52 -0400 Subject: [PATCH] GetShopDataGridConfig --- Winch/Data/Shop/ModdedShopData.cs | 16 +++++++++++++++- Winch/Util/ShopUtil.cs | 29 ++++++++++++++++++++++++++++- 2 files changed, 43 insertions(+), 2 deletions(-) diff --git a/Winch/Data/Shop/ModdedShopData.cs b/Winch/Data/Shop/ModdedShopData.cs index 3a8e1ed2..3a760e12 100644 --- a/Winch/Data/Shop/ModdedShopData.cs +++ b/Winch/Data/Shop/ModdedShopData.cs @@ -17,5 +17,19 @@ internal void Populate() } } - public static implicit operator ShopRestocker.ShopDataGridConfig(ModdedShopData shopData) => new ModdedShopDataGridConfig(shopData); + private ModdedShopDataGridConfig shopDataGridConfig; + public ModdedShopDataGridConfig ToShopDataGridConfig() + { + if (shopDataGridConfig == null) + shopDataGridConfig = new ModdedShopDataGridConfig(this); + else + { + shopDataGridConfig.gridKey = gridKey; + shopDataGridConfig.shopData = this; + } + return shopDataGridConfig; + } + + public static implicit operator ShopRestocker.ShopDataGridConfig(ModdedShopData shopData) => shopData.ToShopDataGridConfig(); + public static implicit operator ModdedShopDataGridConfig(ModdedShopData shopData) => shopData.ToShopDataGridConfig(); } diff --git a/Winch/Util/ShopUtil.cs b/Winch/Util/ShopUtil.cs index 50ff8b5a..f3b8fa2d 100644 --- a/Winch/Util/ShopUtil.cs +++ b/Winch/Util/ShopUtil.cs @@ -36,6 +36,7 @@ internal static bool PopulateDialogueLinkedShopDataFromMetaWithConverter(Dialogu } internal static List KeepInStockItems = new(); + internal static Dictionary ModdedShopDataGridConfigDict = new(); internal static Dictionary AllShopDataGridConfigDict = new(); internal static Dictionary ModdedShopDataDict = new(); internal static Dictionary AllShopDataDict = new(); @@ -67,13 +68,38 @@ public static ShopData GetShopData(string id) return null; } + public static ModdedShopDataGridConfig GetModdedShopDataGridConfig(GridKey gridKey) + { + if (gridKey == GridKey.NONE) + return null; + + if (ModdedShopDataGridConfigDict.TryGetValue(gridKey, out ModdedShopDataGridConfig shop)) + return shop; + else + return null; + } + + public static ShopDataGridConfig GetShopDataGridConfig(GridKey gridKey) + { + if (gridKey == GridKey.NONE) + return null; + + if (AllShopDataGridConfigDict.TryGetValue(gridKey, out var shop)) + return shop; + + if (ModdedShopDataGridConfigDict.TryGetValue(gridKey, out var moddedShop)) + return moddedShop; + + return null; + } + internal static void AddModdedShopData(ShopRestocker restocker) { restocker.itemIdsToKeep.AddRange(KeepInStockItems); foreach (var shopData in ModdedShopDataDict.Values) { shopData.Populate(); - restocker.shopDataGridConfigs.Add(shopData); + restocker.shopDataGridConfigs.Add(shopData.ToShopDataGridConfig()); } } @@ -117,6 +143,7 @@ internal static void AddShopDataFromMeta(string metaPath) if (PopulateShopDataFromMetaWithConverter(shopData, meta)) { ModdedShopDataDict.Add(id, shopData); + ModdedShopDataGridConfigDict.Add(shopData.gridKey, shopData.ToShopDataGridConfig()); } else {