Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: remove architecture layer skipping in InGameUILogic #20

Merged
merged 1 commit into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 2 additions & 9 deletions src/in_game_ui/InGameUI.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,17 +45,10 @@ public void OnResolved() {

InGameUIBinding = InGameUILogic.Bind();

// TODO: Move the access to the game repo to the state machine.

InGameUIBinding
.Handle((in InGameUILogic.Output.NumCoinsCollectedChanged output) =>
SetCoinsLabel(
output.NumCoinsCollected, GameRepo.NumCoinsAtStart.Value
)
)
.Handle((in InGameUILogic.Output.NumCoinsAtStartChanged output) =>
.Handle((in InGameUILogic.Output.NumCoinsChanged output) =>
SetCoinsLabel(
GameRepo.NumCoinsCollected.Value, output.NumCoinsAtStart
output.NumCoinsCollected, output.NumCoinsAtStart
)
);

Expand Down
8 changes: 2 additions & 6 deletions src/in_game_ui/state/InGameUILogic.Output.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,8 @@ namespace GameDemo;

public partial class InGameUILogic {
public static class Output {
public readonly record struct NumCoinsCollectedChanged(
int NumCoinsCollected
);

public readonly record struct NumCoinsAtStartChanged(
int NumCoinsAtStart
public readonly record struct NumCoinsChanged(
int NumCoinsCollected, int NumCoinsAtStart
);
}
}
4 changes: 2 additions & 2 deletions src/in_game_ui/state/InGameUILogic.State.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@ public State() {
}

public void OnNumCoinsCollected(int numCoinsCollected) =>
Output(new Output.NumCoinsCollectedChanged(numCoinsCollected));
Output(new Output.NumCoinsChanged(numCoinsCollected, Get<IGameRepo>().NumCoinsAtStart.Value));

public void OnNumCoinsAtStart(int numCoinsAtStart) =>
Output(new Output.NumCoinsAtStartChanged(numCoinsAtStart));
Output(new Output.NumCoinsChanged(Get<IGameRepo>().NumCoinsCollected.Value, numCoinsAtStart));
}
}
4 changes: 2 additions & 2 deletions test/src/in_game_ui/InGameUITest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void NumCoinsCollectedChanged() {
_coinsLabel.SetupSet(label => label.Text = "1/2");

_binding.Output(
new InGameUILogic.Output.NumCoinsCollectedChanged(1)
new InGameUILogic.Output.NumCoinsChanged(1, 2)
);

_coinsLabel.VerifyAll();
Expand All @@ -86,7 +86,7 @@ public void NumCoinsAtStartChanged() {
_coinsLabel.SetupSet(label => label.Text = "1/2");

_binding.Output(
new InGameUILogic.Output.NumCoinsAtStartChanged(2)
new InGameUILogic.Output.NumCoinsChanged(1, 2)
);

_coinsLabel.VerifyAll();
Expand Down
12 changes: 10 additions & 2 deletions test/src/in_game_ui/state/InGameUILogicStateTest.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,19 +58,27 @@ public void Subscribes() {

[Test]
public void OnNumCoinsCollectedOutputs() {
var numCoinsAtStart = new AutoProp<int>(10);
_gameRepo.Setup(repo => repo.NumCoinsAtStart)
.Returns(numCoinsAtStart);

_state.OnNumCoinsCollected(5);

_context.Outputs.ShouldBe(new object[] {
new InGameUILogic.Output.NumCoinsCollectedChanged(5)
new InGameUILogic.Output.NumCoinsChanged(5, 10)
});
}

[Test]
public void OnNumCoinsAtStartOutputs() {
var numCoinsCollected = new AutoProp<int>(5);
_gameRepo.Setup(repo => repo.NumCoinsCollected)
.Returns(numCoinsCollected);

_state.OnNumCoinsAtStart(10);

_context.Outputs.ShouldBe(new object[] {
new InGameUILogic.Output.NumCoinsAtStartChanged(10)
new InGameUILogic.Output.NumCoinsChanged(5, 10)
});
}
}
Loading