Skip to content

Commit

Permalink
Merge pull request #2 from chickensoft-games/fix/states-by-id
Browse files Browse the repository at this point in the history
fix: use unique names for states to avoid clashes
  • Loading branch information
definitelyokay committed Jul 23, 2023
2 parents 3018d88 + 8d18288 commit 0582df9
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 26 deletions.
36 changes: 18 additions & 18 deletions Chickensoft.LogicBlocks.Generator.Tests/GeneratorTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,31 @@ public class GeneratorTest {

result.Outputs["ToasterOven.puml.g.cs"].ShouldBe("""
@startuml ToasterOven
state "ToasterOven State" as State {
state Heating {
state Toasting {
Toasting : OnEnter → SetTimer
Toasting : OnExit → ResetTimer
state "ToasterOven" as State {
state "Heating" as Chickensoft_LogicBlocks_Generator_Tests_ToasterOven_State_Heating {
state "Toasting" as Chickensoft_LogicBlocks_Generator_Tests_ToasterOven_State_Toasting {
Chickensoft_LogicBlocks_Generator_Tests_ToasterOven_State_Toasting : OnEnter → SetTimer
Chickensoft_LogicBlocks_Generator_Tests_ToasterOven_State_Toasting : OnExit → ResetTimer
}
state Baking {
Baking : OnEnter → SetTemperature
Baking : OnExit → SetTemperature
state "Baking" as Chickensoft_LogicBlocks_Generator_Tests_ToasterOven_State_Baking {
Chickensoft_LogicBlocks_Generator_Tests_ToasterOven_State_Baking : OnEnter → SetTemperature
Chickensoft_LogicBlocks_Generator_Tests_ToasterOven_State_Baking : OnExit → SetTemperature
}
Heating : OnEnter → TurnHeaterOn
Heating : OnExit → TurnHeaterOff
Chickensoft_LogicBlocks_Generator_Tests_ToasterOven_State_Heating : OnEnter → TurnHeaterOn
Chickensoft_LogicBlocks_Generator_Tests_ToasterOven_State_Heating : OnExit → TurnHeaterOff
}
state DoorOpen {
DoorOpen : OnEnter → TurnLampOn
DoorOpen : OnExit → TurnLampOff
state "DoorOpen" as Chickensoft_LogicBlocks_Generator_Tests_ToasterOven_State_DoorOpen {
Chickensoft_LogicBlocks_Generator_Tests_ToasterOven_State_DoorOpen : OnEnter → TurnLampOn
Chickensoft_LogicBlocks_Generator_Tests_ToasterOven_State_DoorOpen : OnExit → TurnLampOff
}
}

Baking --> Toasting : StartToasting
DoorOpen --> Toasting : CloseDoor
Heating --> DoorOpen : OpenDoor
Toasting --> Baking : StartBaking
Chickensoft_LogicBlocks_Generator_Tests_ToasterOven_State_Baking --> Chickensoft_LogicBlocks_Generator_Tests_ToasterOven_State_Toasting : StartToasting
Chickensoft_LogicBlocks_Generator_Tests_ToasterOven_State_DoorOpen --> Chickensoft_LogicBlocks_Generator_Tests_ToasterOven_State_Toasting : CloseDoor
Chickensoft_LogicBlocks_Generator_Tests_ToasterOven_State_Heating --> Chickensoft_LogicBlocks_Generator_Tests_ToasterOven_State_DoorOpen : OpenDoor
Chickensoft_LogicBlocks_Generator_Tests_ToasterOven_State_Toasting --> Chickensoft_LogicBlocks_Generator_Tests_ToasterOven_State_Baking : StartBaking

[*] --> Toasting
[*] --> Chickensoft_LogicBlocks_Generator_Tests_ToasterOven_State_Toasting
@enduml
""".Clean());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<NoWarn>NU5128</NoWarn>

<Title>LogicBlocks Generator</Title>
<Version>1.1.0</Version>
<Version>1.2.0</Version>
<Description></Description>
<Copyright>© 2023 Chickensoft Games</Copyright>
<Authors>Chickensoft</Authors>
Expand Down
14 changes: 7 additions & 7 deletions Chickensoft.LogicBlocks.Generator/src/LogicBlocksGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ CancellationToken token
foreach (var destStateId in inputToStates.Value) {
var dest = implementation.StatesById[destStateId];
transitions.Add(
$"{state.Name} --> " +
$"{dest.Name} : {implementation.Inputs[inputId].Name}"
$"{state.UmlId} --> " +
$"{dest.UmlId} : {implementation.Inputs[inputId].Name}"
);
}
}
Expand All @@ -337,7 +337,7 @@ CancellationToken token

var initialStateString = implementation.InitialStateId != null
? "[*] --> " +
$"{implementation.StatesById[implementation.InitialStateId].Name}"
$"{implementation.StatesById[implementation.InitialStateId].UmlId}"
: "";

var text = Format($"""
Expand Down Expand Up @@ -372,18 +372,18 @@ int t
if (isMultilineState) {
if (isRoot) {
lines.Add(
$"{Tab(t)}state \"{impl.Name} {graph.Name}\" as {graph.Name} {{"
$"{Tab(t)}state \"{impl.Name}\" as {graph.Name} {{"
);
}
else {
lines.Add($"{Tab(t)}state {graph.Name} {{");
lines.Add($"{Tab(t)}state \"{graph.Name}\" as {graph.UmlId} {{");
}
}
else if (isRoot) {
lines.Add($"{Tab(t)}state \"{impl.Name} {graph.Name}\" as {graph.Name}");
}
else {
lines.Add($"{Tab(t)}state {graph.Name}");
lines.Add($"{Tab(t)}state \"{graph.Name}\" as {graph.UmlId}");
}

foreach (var child in graph.Children) {
Expand All @@ -400,7 +400,7 @@ int t
.OrderBy(output => output);
var line = string.Join(", ", outputs);
lines.Add(
$"{Tab(t + 1)}{graph.Name} : {outputContext.DisplayName}{line}"
$"{Tab(t + 1)}{graph.UmlId} : {outputContext.DisplayName}{line}"
);
}

Expand Down
5 changes: 5 additions & 0 deletions Chickensoft.LogicBlocks.Generator/src/common/models/Models.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ List<LogicBlockGraph> Children
string baseId
) : this(id, name, baseId, new(), new(), new()) { }

public string UmlId => Id
.Replace("global::", "")
.Replace(':', '_')
.Replace('.', '_');

public override string ToString() => Describe(0);

public string Describe(int level) {
Expand Down

0 comments on commit 0582df9

Please sign in to comment.