-
-
Notifications
You must be signed in to change notification settings - Fork 4.5k
Fix for 22822 ComputedStates example #23655
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||
|---|---|---|---|---|
|
|
@@ -54,6 +54,9 @@ impl ComputedStates for InGame { | |||
| // Our computed state depends on `AppState`, so we need to specify it as the SourceStates type. | ||||
| type SourceStates = AppState; | ||||
|
|
||||
| // This is necessary to prevent `setup_game` from running when the app is already in `AppState::InGame` | ||||
| // and only `paused` and `turbo` are changed | ||||
| const ALLOW_SAME_STATE_TRANSITIONS: bool = false; | ||||
| // The compute function takes in the `SourceStates` | ||||
| fn compute(sources: AppState) -> Option<Self> { | ||||
| // You might notice that InGame has no values - instead, in this case, the `State<InGame>` resource only exists | ||||
|
|
@@ -80,6 +83,7 @@ struct TurboMode; | |||
|
|
||||
| impl ComputedStates for TurboMode { | ||||
| type SourceStates = AppState; | ||||
| const ALLOW_SAME_STATE_TRANSITIONS: bool = false; | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you verify that you actually don’t need this line:
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. TurboMode can be re-entered (via activating turbo then pausing). This produces duplicate UI elements that overlap and thus don't cause visual artifacts.
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ah I see, I overlooked that, thank you for pointing that out |
||||
|
|
||||
| fn compute(sources: AppState) -> Option<Self> { | ||||
| match sources { | ||||
|
|
@@ -107,6 +111,7 @@ enum IsPaused { | |||
|
|
||||
| impl ComputedStates for IsPaused { | ||||
| type SourceStates = AppState; | ||||
| const ALLOW_SAME_STATE_TRANSITIONS: bool = false; | ||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If you verify that you actually don’t need this line:
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While IsPaused cannot be re-entered it is tied to an OnEnter system that performs command.spawn calls like the other computed states. This line could be removed and retain proper behavior but I believe the example is stronger by keeping it. |
||||
|
|
||||
| fn compute(sources: AppState) -> Option<Self> { | ||||
| // Here we convert from our [`AppState`] to all potential [`IsPaused`] versions. | ||||
|
|
||||
Uh oh!
There was an error while loading. Please reload this page.