Skip to content

Commit 8f2686a

Browse files
committed
more conditions, to have same API as old version, for backwards compatibility
1 parent 650dc66 commit 8f2686a

2 files changed

Lines changed: 64 additions & 0 deletions

File tree

src/Util/FsmUtil.cs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -798,27 +798,47 @@ public static void ReplaceAllActions(this FsmState state, params FsmStateAction[
798798
/// <param name="toState">The new endpoint of the transition</param>
799799
/// <returns>bool that indicates whether the change was successful</returns>
800800
[PublicAPI]
801+
#if OLD_HK_VERSION_HAVE_FALSE_WHEN_MAPI_UPDATED
802+
public static void ChangeTransition(this PlayMakerFSM fsm, string stateName, string eventName, string toState) => fsm.GetState(stateName)!.ChangeTransition(eventName, toState);
803+
#else
801804
public static bool ChangeTransition(this PlayMakerFSM fsm, string stateName, string eventName, string toState) => fsm.GetState(stateName)!.ChangeTransition(eventName, toState);
805+
#endif
802806

803807
/// <inheritdoc cref="ChangeTransition(PlayMakerFSM, string, string, string)"/>
804808
[PublicAPI]
809+
#if OLD_HK_VERSION_HAVE_FALSE_WHEN_MAPI_UPDATED
810+
public static void ChangeTransition(this Fsm fsm, string stateName, string eventName, string toState) => fsm.GetState(stateName)!.ChangeTransition(eventName, toState);
811+
#else
805812
public static bool ChangeTransition(this Fsm fsm, string stateName, string eventName, string toState) => fsm.GetState(stateName)!.ChangeTransition(eventName, toState);
813+
#endif
806814

807815
/// <inheritdoc cref="ChangeTransition(PlayMakerFSM, string, string, string)"/>
808816
/// <param name="state">The fsm state</param>
809817
/// <param name="eventName">The event of the transition</param>
810818
/// <param name="toState">The new endpoint of the transition</param>
811819
[PublicAPI]
820+
#if OLD_HK_VERSION_HAVE_FALSE_WHEN_MAPI_UPDATED
821+
public static void ChangeTransition(this FsmState state, string eventName, string toState)
822+
#else
812823
public static bool ChangeTransition(this FsmState state, string eventName, string toState)
824+
#endif
813825
{
814826
var transition = state.GetTransition(eventName);
815827
if (transition == null)
816828
{
829+
#if OLD_HK_VERSION_HAVE_FALSE_WHEN_MAPI_UPDATED
830+
return;
831+
#else
817832
return false;
833+
#endif
818834
}
819835
transition.ToState = toState;
820836
transition.ToFsmState = state.Fsm.GetState(toState);
837+
#if OLD_HK_VERSION_HAVE_FALSE_WHEN_MAPI_UPDATED
838+
return;
839+
#else
821840
return true;
841+
#endif
822842
}
823843

824844
/// <summary>
@@ -990,22 +1010,38 @@ public static void RemoveTransitionsTo(this Fsm fsm, string toState)
9901010
/// <param name="stateName">The name of the state with the action</param>
9911011
/// <param name="index">The index of the action</param>
9921012
[PublicAPI]
1013+
#if OLD_HK_VERSION_HAVE_FALSE_WHEN_MAPI_UPDATED
1014+
public static void RemoveAction(this PlayMakerFSM fsm, string stateName, int index) => fsm.GetState(stateName)!.RemoveAction(index);
1015+
#else
9931016
public static bool RemoveAction(this PlayMakerFSM fsm, string stateName, int index) => fsm.GetState(stateName)!.RemoveAction(index);
1017+
#endif
9941018

9951019
/// <inheritdoc cref="RemoveAction(PlayMakerFSM, string, int)"/>
9961020
[PublicAPI]
1021+
#if OLD_HK_VERSION_HAVE_FALSE_WHEN_MAPI_UPDATED
1022+
public static void RemoveAction(this Fsm fsm, string stateName, int index) => fsm.GetState(stateName)!.RemoveAction(index);
1023+
#else
9971024
public static bool RemoveAction(this Fsm fsm, string stateName, int index) => fsm.GetState(stateName)!.RemoveAction(index);
1025+
#endif
9981026

9991027
/// <inheritdoc cref="RemoveAction(PlayMakerFSM, string, int)"/>
10001028
/// <param name="state">The fsm state</param>
10011029
/// <param name="index">The index of the action</param>
10021030
[PublicAPI]
1031+
#if OLD_HK_VERSION_HAVE_FALSE_WHEN_MAPI_UPDATED
1032+
public static void RemoveAction(this FsmState state, int index)
1033+
#else
10031034
public static bool RemoveAction(this FsmState state, int index)
1035+
#endif
10041036
{
10051037
FsmStateAction[] origActions = state.Actions;
10061038
if (index < 0 || index >= origActions.Length)
10071039
{
1040+
#if OLD_HK_VERSION_HAVE_FALSE_WHEN_MAPI_UPDATED
1041+
return;
1042+
#else
10081043
return false;
1044+
#endif
10091045
}
10101046
FsmStateAction[] newActions = new FsmStateAction[origActions.Length - 1];
10111047
int newActionsCount = newActions.Length;
@@ -1020,7 +1056,11 @@ public static bool RemoveAction(this FsmState state, int index)
10201056
}
10211057

10221058
state.Actions = newActions;
1059+
#if OLD_HK_VERSION_HAVE_FALSE_WHEN_MAPI_UPDATED
1060+
return;
1061+
#else
10231062
return true;
1063+
#endif
10241064
}
10251065

10261066
/// <summary>

src/Util/FsmUtilObsolete.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -406,17 +406,29 @@ public static partial class FsmUtil
406406
/// <inheritdoc cref="ChangeTransition(PlayMakerFSM, string, string, string)"/>
407407
[PublicAPI]
408408
[Obsolete("Use method `ChangeTransition(PlayMakerFSM, string, string, string)` instead!")]
409+
#if OLD_HK_VERSION_HAVE_FALSE_WHEN_MAPI_UPDATED
410+
public static void ChangeFsmTransition(this PlayMakerFSM fsm, string stateName, string eventName, string toState) => ChangeTransition(fsm, stateName, eventName, toState);
411+
#else
409412
public static bool ChangeFsmTransition(this PlayMakerFSM fsm, string stateName, string eventName, string toState) => ChangeTransition(fsm, stateName, eventName, toState);
413+
#endif
410414

411415
/// <inheritdoc cref="ChangeTransition(Fsm, string, string, string)"/>
412416
[PublicAPI]
413417
[Obsolete("Use method `ChangeTransition(Fsm, string, string, string)` instead!")]
418+
#if OLD_HK_VERSION_HAVE_FALSE_WHEN_MAPI_UPDATED
419+
public static void ChangeFsmTransition(this Fsm fsm, string stateName, string eventName, string toState) => ChangeTransition(fsm, stateName, eventName, toState);
420+
#else
414421
public static bool ChangeFsmTransition(this Fsm fsm, string stateName, string eventName, string toState) => ChangeTransition(fsm, stateName, eventName, toState);
422+
#endif
415423

416424
/// <inheritdoc cref="ChangeTransition(FsmState, string, string)"/>
417425
[PublicAPI]
418426
[Obsolete("Use method `ChangeTransition(FsmState, string, string)` instead!")]
427+
#if OLD_HK_VERSION_HAVE_FALSE_WHEN_MAPI_UPDATED
428+
public static void ChangeFsmTransition(this FsmState state, string eventName, string toState) => ChangeTransition(state, eventName, toState);
429+
#else
419430
public static bool ChangeFsmTransition(this FsmState state, string eventName, string toState) => ChangeTransition(state, eventName, toState);
431+
#endif
420432

421433
/// <inheritdoc cref="ChangeGlobalTransition(PlayMakerFSM, string, string)"/>
422434
[PublicAPI]
@@ -506,17 +518,29 @@ public static partial class FsmUtil
506518
/// <inheritdoc cref="RemoveAction(PlayMakerFSM, string, int)"/>
507519
[PublicAPI]
508520
[Obsolete("Use method `RemoveAction(PlayMakerFSM, string, int)` instead!")]
521+
#if OLD_HK_VERSION_HAVE_FALSE_WHEN_MAPI_UPDATED
522+
public static void RemoveFsmAction(this PlayMakerFSM fsm, string stateName, int index) => RemoveAction(fsm, stateName, index);
523+
#else
509524
public static bool RemoveFsmAction(this PlayMakerFSM fsm, string stateName, int index) => RemoveAction(fsm, stateName, index);
525+
#endif
510526

511527
/// <inheritdoc cref="RemoveAction(Fsm, string, int)"/>
512528
[PublicAPI]
513529
[Obsolete("Use method `RemoveAction(Fsm, string, int)` instead!")]
530+
#if OLD_HK_VERSION_HAVE_FALSE_WHEN_MAPI_UPDATED
531+
public static void RemoveFsmAction(this Fsm fsm, string stateName, int index) => RemoveAction(fsm, stateName, index);
532+
#else
514533
public static bool RemoveFsmAction(this Fsm fsm, string stateName, int index) => RemoveAction(fsm, stateName, index);
534+
#endif
515535

516536
/// <inheritdoc cref="RemoveAction(FsmState, int)"/>
517537
[PublicAPI]
518538
[Obsolete("Use method `RemoveAction(FsmState, int)` instead!")]
539+
#if OLD_HK_VERSION_HAVE_FALSE_WHEN_MAPI_UPDATED
540+
public static void RemoveFsmAction(this FsmState state, int index) => RemoveAction(state, index);
541+
#else
519542
public static bool RemoveFsmAction(this FsmState state, int index) => RemoveAction(state, index);
543+
#endif
520544

521545
/// <inheritdoc cref="RemoveActionsOfType{TAction}(PlayMakerFSM)"/>
522546
[PublicAPI]

0 commit comments

Comments
 (0)