Repository navigation
Conversation
vincentfretin
left a comment
There was a problem hiding this comment.
That's a change we talked in January right?
Can you please give me again the scenario you have that is not covered by the persistent system? If it's possible to add an example with your case that will help, and probably additional unit test cases to cover the changes.
| var networkId = entityData.networkId; | ||
| var el = NAF.schemas.getCachedTemplate(entityData.template); | ||
| try { | ||
| const exists = document.getElementById(networkId); |
There was a problem hiding this comment.
For me the name exists means it's a boolean, I'd prefer existingEl.
There was a problem hiding this comment.
Add the log NAF.log.write('Creating remote entity', entityData); we already have abvove only if existingEl is null, and add another log if it already exists.
|
|
||
| if (!el) { | ||
| throw new Error(`Failed to create element for template: ${template}`); | ||
| } |
There was a problem hiding this comment.
NAF.schemas.getCachedTemplate(template) already log an error if there is no template, so just return here maybe?
| if (entityData.isFirstSync) { | ||
| this.initPosition(el, components); | ||
| this.initRotation(el, components); | ||
| } |
There was a problem hiding this comment.
Why do you check isFirstSync here? If the entity moved, you still want to sync it right?
| } catch (error) { | ||
| console.error('Error creating remote entity:', error); | ||
| return null; | ||
| } |
There was a problem hiding this comment.
The try catch is not needed if you don't throw your own error.
| } | ||
|
|
||
| initPosition(entity, componentData) { | ||
| if (!entity) return; |
There was a problem hiding this comment.
This added check shouldn't be needed if you return before calling initPosition.
| } | ||
|
|
||
| initRotation(entity, componentData) { | ||
| if (!entity) return; |
There was a problem hiding this comment.
This added check shouldn't be needed if you return before calling initRotation.
| this.el.emit(this.OWNERSHIP_GAINED, this.onOwnershipGainedEvent); | ||
| } else if (!isMine && wasMine) { // Lost ownership | ||
| this.onOwnershipLostEvent.newOwner = data.owner; | ||
| this.el.emit(this.OWNERSHIP_LOST, this.onOwnershipLostEvent); |
There was a problem hiding this comment.
Not sure about all the changes here. We already have the some OWNERSHIP_LOST event emitted in networkUpdate. Is is emitted twice now?
|
|
||
| if (isMine && !wasMine) { // Gained ownership | ||
| this.removeLerp(); | ||
| this.syncAll(undefined, true); |
There was a problem hiding this comment.
Why do you always full sync now with the second param isFirstSync to true.
No description provided.