Skip to content

Commit

Permalink
block non trinket tinker trinkets from the special machine methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Mushymato committed Nov 17, 2024
1 parent 45d1085 commit d6e26ca
Show file tree
Hide file tree
Showing 4 changed files with 44 additions and 2 deletions.
17 changes: 17 additions & 0 deletions TrinketTinker/Effects/TrinketTinkerEffect.cs
Original file line number Diff line number Diff line change
Expand Up @@ -389,4 +389,21 @@ public void SetVariant(Trinket trinket, int variant)
trinket.ParentSheetIndex = Data.Variants[variant].TrinketSpriteIndex;
return;
}

/// <summary>Reset trinket variant icon to modData value</summary>
/// <param name="trinket"></param>
/// <param name="variant"></param>
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;
}
}
}
19 changes: 17 additions & 2 deletions TrinketTinker/Extras/ItemQuery.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using StardewValley;
using StardewValley.Delegates;
using StardewValley.Internal;
using StardewValley.ItemTypeDefinitions;
using StardewValley.Objects.Trinkets;
Expand All @@ -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";

Expand Down Expand Up @@ -169,4 +171,17 @@ Action<string, string> logError
}
return createdTrinkets;
}

/// <summary>
/// Check that the input item is a trinket using TrinketTinkerEffect
/// </summary>
/// <param name="query"></param>
/// <param name="context"></param>
/// <returns></returns>
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;
}
}
4 changes: 4 additions & 0 deletions TrinketTinker/Extras/TrinketColorizer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand Down Expand Up @@ -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 =
Expand Down Expand Up @@ -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)
Expand All @@ -255,6 +258,7 @@ out int? overrideMinutesUntilReady
}
return null;
}
effect2.ResetVariant(output);

if (!probe)
{
Expand Down
6 changes: 6 additions & 0 deletions TrinketTinker/ModEntry.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down

0 comments on commit d6e26ca

Please sign in to comment.