-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #113 from chickensoft-games/fix/qol
fix: allow configuring whether `OnEnter` callbacks should run when restoring a state
- Loading branch information
Showing
5 changed files
with
156 additions
and
9 deletions.
There are no files selected for viewing
59 changes: 59 additions & 0 deletions
59
Chickensoft.LogicBlocks.Tests/test/fixtures/SerializableLogicBlockWithOnEnter.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
namespace Chickensoft.LogicBlocks.Tests.Fixtures; | ||
|
||
using Chickensoft.Introspection; | ||
|
||
[Meta, Id("serializable_logic_block_with_on_enter")] | ||
[LogicBlock(typeof(State), Diagram = false)] | ||
public partial class SerializableLogicBlockWithOnEnter : | ||
LogicBlock<SerializableLogicBlockWithOnEnter.State> { | ||
public override Transition GetInitialState() => To<StateA>(); | ||
|
||
public SerializableLogicBlockWithOnEnter() { | ||
Set(new Data()); | ||
} | ||
|
||
public record Data { | ||
public bool AutomaticallyLeaveAOnEnter { get; set; } | ||
} | ||
|
||
public static class Input { | ||
public readonly record struct GoToA; | ||
public readonly record struct GoToB; | ||
} | ||
|
||
public static class Output { | ||
public readonly record struct StateEntered; | ||
public readonly record struct StateAEntered; | ||
public readonly record struct StateBEntered; | ||
} | ||
|
||
[Meta] | ||
public abstract partial record State : StateLogic<State>, | ||
IGet<Input.GoToA>, IGet<Input.GoToB> { | ||
public State() { | ||
this.OnEnter(() => Output(new Output.StateEntered())); | ||
} | ||
|
||
public Transition On(in Input.GoToA input) => To<StateA>(); | ||
public Transition On(in Input.GoToB input) => To<StateB>(); | ||
} | ||
|
||
[Meta, Id("serializable_logic_block_with_on_enter_state_a")] | ||
public partial record StateA : State { | ||
public StateA() { | ||
this.OnEnter(() => { | ||
Output(new Output.StateAEntered()); | ||
if (Get<Data>().AutomaticallyLeaveAOnEnter) { | ||
Input(new Input.GoToB()); | ||
} | ||
}); | ||
} | ||
} | ||
|
||
[Meta, Id("serializable_logic_block_with_on_enter_state_b")] | ||
public partial record StateB : State { | ||
public StateB() { | ||
this.OnEnter(() => Output(new Output.StateBEntered())); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters