Skip to content

Commit 44ca4c9

Browse files
committed
feat(patching): introduce combat phase extension for card model
- Added a new extension method to determine if a card model's owner is in the "Play" turn phase, improving clarity and reusability. - Refactored existing logic in `ModCardHandOutlinePatchHelper` to utilize the new extension method for better readability and maintainability. - Enhanced the overall structure of combat phase checks within the patching logic.
1 parent 7243602 commit 44ca4c9

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

Scaffolding/Cards/HandOutline/Patches/ModCardHandOutlinePatchHelper.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
using MegaCrit.Sts2.Core.Combat;
44
using MegaCrit.Sts2.Core.Models;
55
using MegaCrit.Sts2.Core.Nodes.Cards.Holders;
6+
using STS2RitsuLib.Scaffolding.Combat;
67

78
namespace STS2RitsuLib.Scaffolding.Cards.HandOutline.Patches
89
{
@@ -30,7 +31,7 @@ internal static void ApplyHighlight(NHandCardHolder holder, CardModel model, Mod
3031
if (CombatManager.Instance is not { IsInProgress: true })
3132
return;
3233

33-
var inPlayPhase = model.Owner?.PlayerCombatState?.Phase == PlayerTurnPhase.Play;
34+
var inPlayPhase = model.IsOwnerPlayPhase();
3435
var shouldGlowRed = inPlayPhase && model.ShouldGlowRed;
3536
var shouldGlowGold = inPlayPhase && model.CanPlay() && model.ShouldGlowGold;
3637
var vanillaShow = model.CanPlay() || shouldGlowRed || shouldGlowGold;
@@ -52,7 +53,7 @@ internal static void ApplyFlash(NHandCardHolder holder, CardModel model, ModCard
5253
!GodotObject.IsInstanceValid(flash))
5354
return;
5455

55-
var inPlayPhase = model.Owner?.PlayerCombatState?.Phase == PlayerTurnPhase.Play;
56+
var inPlayPhase = model.IsOwnerPlayPhase();
5657
var shouldGlowRed = inPlayPhase && model.ShouldGlowRed;
5758
var shouldGlowGold = inPlayPhase && model.CanPlay() && model.ShouldGlowGold;
5859
var vanillaShow = model.CanPlay() || shouldGlowRed || shouldGlowGold;
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
using MegaCrit.Sts2.Core.Combat;
2+
using MegaCrit.Sts2.Core.Models;
3+
4+
namespace STS2RitsuLib.Scaffolding.Combat
5+
{
6+
/// <summary>
7+
/// Compatibility helpers for querying the current player turn phase.
8+
/// </summary>
9+
public static class CombatTurnPhaseExtensions
10+
{
11+
/// <summary>
12+
/// Returns whether <paramref name="model" />'s owner is currently in the "Play" turn phase.
13+
/// </summary>
14+
public static bool IsOwnerPlayPhase(this CardModel model)
15+
{
16+
ArgumentNullException.ThrowIfNull(model);
17+
18+
#if !STS2_AT_LEAST_0_104_0
19+
return CombatManager.Instance.IsPlayPhase;
20+
#else
21+
return model.Owner?.PlayerCombatState?.Phase == PlayerTurnPhase.Play;
22+
#endif
23+
}
24+
}
25+
}

0 commit comments

Comments
 (0)