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

Make ownership checks consistent between All Players and explicit assignment #4404

Merged

Conversation

kwvanderlinde
Copy link
Collaborator

@kwvanderlinde kwvanderlinde commented Nov 16, 2023

Identify the Bug or Feature request

Fixes #4403
Fixes #4362

Description of the Change

These new methods are added to Token for easier ownership checks:

  • isOwnedByAny(Collection<String>) playerIds) to check if a token has any owners out of a set of possible owners.
  • isOwnedByNone() to check if a token has not owners.

These allow replacing existing and inconsistent uses of Token.getOwners(), ensuring that the All Players setting is respected across the board. The remaining uses of Token.getOwners() are needed to display and manipulate the owner list, or - in the case of the getTokens() macro function - to check very specific conditions.

These bug fixes were done using the new methods:

Possible Drawbacks

For getTokens(), if any framework code is relying on excluding All Players ownership, it will need updating.

Documentation Notes

N/A

Release Notes

  • Fixed token ownership so that being owned by all players is more consistent with giving explicit ownership.

This change is Reviewable

- `Token.isOwnedByAny(Collection<String>)` check if any provided players own the token.
- `Token.isOwnedByNone()` if the token is not owned by anyone.

Both of these respect `Token.isOwnedByAll()` so it doesn't have to be checked separately.

These places were simplified as a result:
- `AppUtil.ownedByOnePlayer()`
- `EditTokenDialog.commit()`

Also `TokenPropertyFunctions.getOwners()` was simplified, but that was possible without these new methods.
We had checks to ensure that lib:tokens owned by any players did not have their onCampaignLoad even executed. But the
check didn't `continue` the correct loop, so outside of `Token.isOwnedByAll()`, it had no effect. This changes that to
use `Token.isOwnedByAny()`, and now the right loop is naturally manipulated.

Also removes some unecessary nesting of blocks and an unused method.
The existing check marked macros as trusted if the library had no listed owners, but did not consider whether it was
owned by _All Players_. The updated version does that implicitly by using `Token.isOwnedByNone()`.
The existing check did not return tokens that were owned by _All Players_. The new check handles this implicitly via
`Token.isOwnedByAny()`.
Also move some check out of the inner loop so we save on a bunch of unnecessary work.
@cwisniew cwisniew added this pull request to the merge queue Nov 17, 2023
@cwisniew cwisniew added the bug label Nov 17, 2023
Merged via the queue into RPTools:develop with commit 8265216 Nov 17, 2023
4 checks passed
@kwvanderlinde kwvanderlinde deleted the bugfix/4362-4403-ownership-problems branch November 17, 2023 03:48
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
2 participants