Skip to content
This repository has been archived by the owner on Jun 10, 2022. It is now read-only.

Commit

Permalink
Actors with orphaned ownership will properly update upon new authorit…
Browse files Browse the repository at this point in the history
…ative user (#743)
  • Loading branch information
norybiak authored Apr 8, 2021
1 parent 59c975a commit 04786b3
Showing 1 changed file with 19 additions and 20 deletions.
39 changes: 19 additions & 20 deletions packages/sdk/src/core/contextInternal.ts
Original file line number Diff line number Diff line change
Expand Up @@ -68,14 +68,12 @@ export class ContextInternal {

public onSetAuthoritative = (userId: Guid) => {
this._rigidBodyOrphanSet.forEach(
(value) => {
if (value === this._rigidBodyDefaultOwner) {
const actor = this.actorSet.get(value);
actor.owner = userId;

this._rigidBodyOwnerMap.set(value, userId);
}
})
(actorId) => {
const actor = this.actorSet.get(actorId);
actor.owner = userId;
this._rigidBodyOwnerMap.set(actorId, userId);
}
)
this._rigidBodyOrphanSet.clear();
this._rigidBodyDefaultOwner = userId;
};
Expand Down Expand Up @@ -531,22 +529,23 @@ export class ContextInternal {
this.context.emitter.emit('user-left', user);

if (userId !== this._rigidBodyDefaultOwner) {
this._rigidBodyOwnerMap.forEach( (value, key) => {
if (value === userId) {
const actor = this.actorSet.get(key);
actor.owner = this._rigidBodyDefaultOwner;
this._rigidBodyOwnerMap.set(key, this._rigidBodyDefaultOwner);
this._rigidBodyOwnerMap.forEach(
(ownerId, actorId) => {
if (ownerId === userId) {
const actor = this.actorSet.get(actorId);
actor.owner = this._rigidBodyDefaultOwner;
this._rigidBodyOwnerMap.set(actorId, this._rigidBodyDefaultOwner);
}
}
})
)
} else {
this._rigidBodyOwnerMap.forEach(
(value, key) => {
if (value === userId) {
const actor = this.actorSet.get(key);
actor.owner = this._rigidBodyDefaultOwner;
this._rigidBodyOrphanSet.add(key);
(ownerId, actorId) => {
if (ownerId === userId) {
this._rigidBodyOrphanSet.add(actorId);
}
})
}
)
}
}
}
Expand Down

0 comments on commit 04786b3

Please sign in to comment.