Merge pull request #908 from ClementVieilly75/FTUEPopup

Unsubscribe to iframeEvents in CleanUpClosingScene
This commit is contained in:
David Négrier 2021-04-19 11:24:43 +02:00 committed by GitHub
commit cb1dcb5786
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 20 additions and 14 deletions

View File

@ -145,7 +145,7 @@ export class GameScene extends ResizableScene implements CenterListener {
// A promise that will resolve when the "create" method is called (signaling loading is ended) // A promise that will resolve when the "create" method is called (signaling loading is ended)
private createPromise: Promise<void>; private createPromise: Promise<void>;
private createPromiseResolve!: (value?: void | PromiseLike<void>) => void; private createPromiseResolve!: (value?: void | PromiseLike<void>) => void;
private iframeSubscriptionList! : Array<Subscription>;
MapUrlFile: string; MapUrlFile: string;
RoomId: string; RoomId: string;
instance: string; instance: string;
@ -772,7 +772,8 @@ export class GameScene extends ResizableScene implements CenterListener {
} }
private listenToIframeEvents(): void { private listenToIframeEvents(): void {
iframeListener.openPopupStream.subscribe((openPopupEvent) => { this.iframeSubscriptionList = [];
this.iframeSubscriptionList.push(iframeListener.openPopupStream.subscribe((openPopupEvent) => {
let objectLayerSquare : ITiledMapObject; let objectLayerSquare : ITiledMapObject;
const targetObjectData = this.getObjectLayerData(openPopupEvent.targetObject); const targetObjectData = this.getObjectLayerData(openPopupEvent.targetObject);
@ -816,7 +817,6 @@ ${escapedMessage}
} }
id++; id++;
} }
this.tweens.add({ this.tweens.add({
targets : domElement , targets : domElement ,
scale : 1, scale : 1,
@ -825,9 +825,9 @@ ${escapedMessage}
}); });
this.popUpElements.set(openPopupEvent.popupId, domElement); this.popUpElements.set(openPopupEvent.popupId, domElement);
}); }));
iframeListener.closePopupStream.subscribe((closePopupEvent) => { this.iframeSubscriptionList.push(iframeListener.closePopupStream.subscribe((closePopupEvent) => {
const popUpElement = this.popUpElements.get(closePopupEvent.popupId); const popUpElement = this.popUpElements.get(closePopupEvent.popupId);
if (popUpElement === undefined) { if (popUpElement === undefined) {
console.error('Could not close popup with ID ', closePopupEvent.popupId,'. Maybe it has already been closed?'); console.error('Could not close popup with ID ', closePopupEvent.popupId,'. Maybe it has already been closed?');
@ -843,23 +843,25 @@ ${escapedMessage}
this.popUpElements.delete(closePopupEvent.popupId); this.popUpElements.delete(closePopupEvent.popupId);
}, },
}); });
}); }));
iframeListener.disablePlayerControlStream.subscribe(()=>{ this.iframeSubscriptionList.push(iframeListener.disablePlayerControlStream.subscribe(()=>{
this.userInputManager.disableControls(); this.userInputManager.disableControls();
}) }));
iframeListener.enablePlayerControlStream.subscribe(()=>{
this.iframeSubscriptionList.push(iframeListener.enablePlayerControlStream.subscribe(()=>{
this.userInputManager.restoreControls(); this.userInputManager.restoreControls();
}) }));
let scriptedBubbleSprite : Sprite; let scriptedBubbleSprite : Sprite;
iframeListener.displayBubbleStream.subscribe(()=>{ this.iframeSubscriptionList.push(iframeListener.displayBubbleStream.subscribe(()=>{
scriptedBubbleSprite = new Sprite(this,this.CurrentPlayer.x + 25,this.CurrentPlayer.y,'circleSprite-white'); scriptedBubbleSprite = new Sprite(this,this.CurrentPlayer.x + 25,this.CurrentPlayer.y,'circleSprite-white');
scriptedBubbleSprite.setDisplayOrigin(48, 48); scriptedBubbleSprite.setDisplayOrigin(48, 48);
this.add.existing(scriptedBubbleSprite); this.add.existing(scriptedBubbleSprite);
}) }));
iframeListener.removeBubbleStream.subscribe(()=>{
this.iframeSubscriptionList.push(iframeListener.removeBubbleStream.subscribe(()=>{
scriptedBubbleSprite.destroy(); scriptedBubbleSprite.destroy();
}) }));
} }
@ -904,6 +906,10 @@ ${escapedMessage}
this.simplePeer.closeAllConnections(); this.simplePeer.closeAllConnections();
this.simplePeer?.unregister(); this.simplePeer?.unregister();
this.messageSubscription?.unsubscribe(); this.messageSubscription?.unsubscribe();
for(const iframeEvents of this.iframeSubscriptionList){
iframeEvents.unsubscribe();
}
} }
private removeAllRemotePlayers(): void { private removeAllRemotePlayers(): void {