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

Move selection logic into a dedicated model #3866

Merged

Conversation

kwvanderlinde
Copy link
Collaborator

@kwvanderlinde kwvanderlinde commented Mar 15, 2023

Identify the Bug or Feature request

Addresses #3759

Description of the Change

The primary motivation here is fixing the linked bug. There was also another bug discovered in the meantime where selection history was not being saved at the right times, resulting in both missing and duplicated entries in the history.

Secondary to that, I took the opportunity to clean up ZoneRenderer with regards to selection. The current selection and selection history are now managed by the SelectionModel class (there is one per ZoneRenderer). In addition to querying the current selection, SelectionModel also provides these bulk operations:

  • replaceSelection(): deselect all tokens and then select the provided tokens.
  • addTokensToSelection(): keep the current selection and add more tokens to it.
  • removeTokensFromSelection(): keep the current selection but deselect the provided tokens.
  • undoSelection(): revert selection to a previous state.

These operations guarantee that history is modified consistently. They also communicate selection changes via a new SelectionChanged event sent through the event bus.

The new event means we no longer need ZoneRenderer.updateAfterSelection(), which needed to be called in ~30 places to keep the selection panel, impersonation panel and HTML views up-to-date. Instead this is now done automatically with each of the components being directly notified of the selection change.

Possible Drawbacks

As usual, it's possible I messed up somewhere that I didn't test.

Documentation Notes

N/A, just a minor bug fix.

Release Notes

  • Fixed a bug where client selections were being cleared when other clients moved tokens.
  • Fixed a bug where the selection undo history included redundant entries.

This change is Reviewable

This fixes two bugs where client selections were being cleared due to other clients moving tokens, and where the
selection history was having redundant entries while missing others.

The bulk of the change is to pull the selection logic out of `ZoneRenderer` and into a new `SelectionModel`. The
`SelectionModel` is solely responsible for maintain selections and the selection undo history. A new `SelectionChanged`
event allows components to react to selection changes without having to be explicitly notified.
Copy link
Contributor

@Phergus Phergus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:lgtm:

Reviewed 14 of 14 files at r1, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @kwvanderlinde)

Copy link
Contributor

@Phergus Phergus left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reviewed 1 of 1 files at r2, all commit messages.
Reviewable status: :shipit: complete! all files reviewed, all discussions resolved (waiting on @kwvanderlinde)

@Phergus Phergus merged commit 670a9e8 into RPTools:develop Mar 16, 2023
@kwvanderlinde kwvanderlinde deleted the bugfix/3759-encapsulated-selection branch March 16, 2023 23:50
@cwisniew cwisniew added the bug label Mar 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
Status: Merged
Development

Successfully merging this pull request may close these issues.

3 participants