From d6e26ca0b9166c01ed8a98051435bf54f15fb3d6 Mon Sep 17 00:00:00 2001 From: mushymato Date: Sun, 17 Nov 2024 15:33:54 -0500 Subject: [PATCH] block non trinket tinker trinkets from the special machine methods --- TrinketTinker/Effects/TrinketTinkerEffect.cs | 17 +++++++++++++++++ TrinketTinker/Extras/ItemQuery.cs | 19 +++++++++++++++++-- TrinketTinker/Extras/TrinketColorizer.cs | 4 ++++ TrinketTinker/ModEntry.cs | 6 ++++++ 4 files changed, 44 insertions(+), 2 deletions(-) diff --git a/TrinketTinker/Effects/TrinketTinkerEffect.cs b/TrinketTinker/Effects/TrinketTinkerEffect.cs index a042997..fcfb44a 100644 --- a/TrinketTinker/Effects/TrinketTinkerEffect.cs +++ b/TrinketTinker/Effects/TrinketTinkerEffect.cs @@ -389,4 +389,21 @@ public void SetVariant(Trinket trinket, int variant) trinket.ParentSheetIndex = Data.Variants[variant].TrinketSpriteIndex; return; } + + /// Reset trinket variant icon to modData value + /// + /// + public void ResetVariant(Trinket trinket) + { + if (Data == null || Data.Variants.Count == 0) + return; + if (trinket.modData.TryGetValue(ModData_Variant, out string variantStr)) + { + int variant = int.Parse(variantStr); + if (variant >= Data.Variants.Count) + variant = 0; + if (Data.Variants[variant].TrinketSpriteIndex > 0) + trinket.ParentSheetIndex = Data.Variants[variant].TrinketSpriteIndex; + } + } } diff --git a/TrinketTinker/Extras/ItemQuery.cs b/TrinketTinker/Extras/ItemQuery.cs index a7e14a1..936e365 100644 --- a/TrinketTinker/Extras/ItemQuery.cs +++ b/TrinketTinker/Extras/ItemQuery.cs @@ -1,4 +1,5 @@ using StardewValley; +using StardewValley.Delegates; using StardewValley.Internal; using StardewValley.ItemTypeDefinitions; using StardewValley.Objects.Trinkets; @@ -8,9 +9,10 @@ namespace TrinketTinker.Extras; public static class ItemQuery { - public static readonly string ItemQuery_CREATE_TRINKET = $"{ModEntry.ModId}_CREATE_TRINKET"; - public static readonly string ItemQuery_CREATE_TRINKET_ALL_VARIANTS = + public static string ItemQuery_CREATE_TRINKET => $"{ModEntry.ModId}_CREATE_TRINKET"; + public static string ItemQuery_CREATE_TRINKET_ALL_VARIANTS = $"{ModEntry.ModId}_CREATE_TRINKET_ALL_VARIANTS"; + public static string GameStateQuery_INPUT_IS_TINKER => $"{ModEntry.ModId}_INPUT_IS_TINKER"; private const string RANDOM = "R"; private const string ALL = "A"; @@ -169,4 +171,17 @@ Action logError } return createdTrinkets; } + + /// + /// Check that the input item is a trinket using TrinketTinkerEffect + /// + /// + /// + /// + public static bool INPUT_IS_TINKER(string[] query, GameStateQueryContext context) + { + if (context.InputItem == null) + return false; + return context.InputItem is Trinket trinket && trinket.GetEffect() is TrinketTinkerEffect; + } } diff --git a/TrinketTinker/Extras/TrinketColorizer.cs b/TrinketTinker/Extras/TrinketColorizer.cs index 68169af..f8010a3 100644 --- a/TrinketTinker/Extras/TrinketColorizer.cs +++ b/TrinketTinker/Extras/TrinketColorizer.cs @@ -102,6 +102,7 @@ public static void Edit_MachineData(IAssetData asset) Trigger = MachineOutputTrigger.ItemPlacedInMachine, RequiredCount = 1, RequiredTags = ["category_trinket"], + Condition = ItemQuery.GameStateQuery_INPUT_IS_TINKER, }, ], OutputItem = @@ -137,6 +138,7 @@ public static void Edit_MachineData(IAssetData asset) Trigger = MachineOutputTrigger.ItemPlacedInMachine, RequiredCount = 1, RequiredTags = ["category_trinket"], + Condition = ItemQuery.GameStateQuery_INPUT_IS_TINKER, }, ]; newRule.OutputItem = @@ -245,6 +247,7 @@ out int? overrideMinutesUntilReady Trinket output = (Trinket)inputItem.getOne(); if (output.GetEffect() is not TrinketTinkerEffect effect2) return null; + if (!effect2.RerollLevel(output, effect1.GeneralStat)) { if (!probe) @@ -255,6 +258,7 @@ out int? overrideMinutesUntilReady } return null; } + effect2.ResetVariant(output); if (!probe) { diff --git a/TrinketTinker/ModEntry.cs b/TrinketTinker/ModEntry.cs index cfd2e50..fb6b6c1 100644 --- a/TrinketTinker/ModEntry.cs +++ b/TrinketTinker/ModEntry.cs @@ -68,6 +68,12 @@ private void OnGameLaunched(object? sender, GameLaunchedEventArgs e) ItemQuery.ItemQuery_CREATE_TRINKET_ALL_VARIANTS, ItemQuery.CREATE_TRINKET_ALL_VARIANTS ); + + // Add GSQ for checking trinket is for this mod + GameStateQuery.Register( + ItemQuery.GameStateQuery_INPUT_IS_TINKER, + ItemQuery.INPUT_IS_TINKER + ); } private static void OnAssetRequested(object? sender, AssetRequestedEventArgs e)