Skip to content

Commit

Permalink
GetShopDataGridConfig
Browse files Browse the repository at this point in the history
  • Loading branch information
MegaPiggy committed Sep 13, 2024
1 parent cf242c7 commit 1e77ada
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 2 deletions.
16 changes: 15 additions & 1 deletion Winch/Data/Shop/ModdedShopData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}
29 changes: 28 additions & 1 deletion Winch/Util/ShopUtil.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ internal static bool PopulateDialogueLinkedShopDataFromMetaWithConverter(Dialogu
}

internal static List<string> KeepInStockItems = new();
internal static Dictionary<GridKey, ModdedShopDataGridConfig> ModdedShopDataGridConfigDict = new();
internal static Dictionary<GridKey, ShopDataGridConfig> AllShopDataGridConfigDict = new();
internal static Dictionary<string, ModdedShopData> ModdedShopDataDict = new();
internal static Dictionary<string, ShopData> AllShopDataDict = new();
Expand Down Expand Up @@ -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());
}
}

Expand Down Expand Up @@ -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
{
Expand Down

0 comments on commit 1e77ada

Please sign in to comment.