-
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 #8 from chickensoft-games/fix/binding-state
fix: support patterns in generator, better support abstract and interface types in binding callbacks
- Loading branch information
Showing
10 changed files
with
69 additions
and
12 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
Chickensoft.LogicBlocks.Generator.Tests/test_cases/Patterns.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,30 @@ | ||
namespace Chickensoft.LogicBlocks.Generator.Tests; | ||
|
||
[StateMachine] | ||
public class Patterns : LogicBlock<Patterns.Input, Patterns.State, LightSwitch.Output> { | ||
public enum Mode { One, Two, Three } | ||
|
||
public override State GetInitialState(Context context) => | ||
new State.One(context); | ||
|
||
public abstract record Input { | ||
public record SetMode(Mode Mode) : Input; | ||
} | ||
|
||
public abstract record State(Context Context) : StateLogic(Context), IGet<Input.SetMode> { | ||
public State On(Input.SetMode input) => input.Mode switch { | ||
Mode.One => new One(Context), | ||
Mode.Two => new Two(Context), | ||
Mode.Three => true switch { | ||
true => new Three(Context), | ||
false => throw new NotImplementedException() | ||
}, | ||
_ => throw new NotImplementedException() | ||
}; | ||
public record One(Context Context) : State(Context); | ||
public record Two(Context Context) : State(Context); | ||
public record Three(Context Context) : State(Context); | ||
} | ||
|
||
public abstract record Output { } | ||
} |
8 changes: 8 additions & 0 deletions
8
Chickensoft.LogicBlocks.Generator.Tests/test_cases/Patterns.g.puml
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,8 @@ | ||
@startuml Patterns | ||
state "Patterns State" as Chickensoft_LogicBlocks_Generator_Tests_Patterns_State { | ||
state "One" as Chickensoft_LogicBlocks_Generator_Tests_Patterns_State_One | ||
state "Two" as Chickensoft_LogicBlocks_Generator_Tests_Patterns_State_Two | ||
state "Three" as Chickensoft_LogicBlocks_Generator_Tests_Patterns_State_Three | ||
} | ||
[*] --> Chickensoft_LogicBlocks_Generator_Tests_Patterns_State_One | ||
@enduml |
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
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