Skip to content

Commit

Permalink
fix users
Browse files Browse the repository at this point in the history
  • Loading branch information
MrVauxs committed Nov 22, 2024
1 parent 5dc05e5 commit d237ae0
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 10 deletions.
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ and this project adheres to [Semantic Versioning](<https://semver.org/spec/v2.0.
## [Unreleased]

## [0.9.4] - 2024-11-22

### Fixed

- Worked around user ownership being buggy for imported adventure characters.

## [0.9.3] - 2024-09-21

### Changed
Expand Down Expand Up @@ -463,8 +469,10 @@ and this project adheres to [Semantic Versioning](<https://semver.org/spec/v2.0.
- Moved internal structure
- Pre-release versions to be semver compliant

[Unreleased]: https://github.com/MrVauxs/pf2e-graphics/compare/v0.9.2...HEAD
[0.9.2]: https://github.com/MrVauxs/pf2e-graphics/compare/v0.9.0...v0.9.2
[Unreleased]: https://github.com/MrVauxs/pf2e-graphics/compare/v0.9.4...HEAD
[0.9.4]: https://github.com/MrVauxs/pf2e-graphics/compare/v0.9.3...v0.9.4
[0.9.3]: https://github.com/MrVauxs/pf2e-graphics/compare/v0.9.2...v0.9.3
[0.9.2]: https://github.com/MrVauxs/pf2e-graphics/compare/v0.9.1...v0.9.2
[0.9.1]: https://github.com/MrVauxs/pf2e-graphics/compare/v0.9.0...v0.9.1
[0.9.0]: https://github.com/MrVauxs/pf2e-graphics/compare/v0.8.3...v0.9.0
[0.8.3]: https://github.com/MrVauxs/pf2e-graphics/compare/v0.8.2...v0.8.3
Expand Down
29 changes: 21 additions & 8 deletions src/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -50,15 +50,28 @@ export function getPlayerOwners(actor: ActorPF2e): UserPF2e[] {
return game.users.contents;
}

// If "nobody" owns it, whoever is the primaryUpdater (read: GM) does.
if (Object.entries(actor.ownership).filter((([,v]) => v !== 0)).length === 1) {
return [actor.primaryUpdater || game.user];
}

// Check the ownership IDs, check if there is a player owner, yes, ignore GMs, no, count only GMs.
return Object.keys(actor.ownership).filter(x => x !== 'default').filter(x => actor.hasPlayerOwner
? !game.users.get(x)?.hasRole('GAMEMASTER')
: game.users.get(x)?.hasRole('GAMEMASTER')).map(x => game.users.get(x, { strict: true }));
const owners = Object.keys(actor.ownership)
.filter(x => x !== 'default')
.filter(x => actor.hasPlayerOwner
? !game.users.get(x)?.hasRole('GAMEMASTER')
: game.users.get(x)?.hasRole('GAMEMASTER'))
.map(x => game.users.get(x))
.filter(nonNullable);

if (owners.length) {
return owners;
} else {
// If "nobody" owns it, whoever is the primaryUpdater (read: GM) does.
// This should handle weirdos like { ownership: { default: 0 } }
if (actor.primaryUpdater) {
log('Could not determine owner, defaulting to primaryUpdater.');
return [actor.primaryUpdater];
} else {
log('Could not determine owner nor found the primaryUpdater, defaulting to all GMs.');
return game.users.filter(x => x.isGM);
}
}
}

export function camelToSpaces(string: string): string {
Expand Down

0 comments on commit d237ae0

Please sign in to comment.