From a0205bf682ef301922c99c587aa493bd4b7c68ea Mon Sep 17 00:00:00 2001 From: Hanusiak Piotr Date: Wed, 2 Mar 2022 17:00:43 +0100 Subject: [PATCH] cleanup --- back/src/Model/GameRoom.ts | 2 - back/src/Model/PositionNotifier.ts | 2 - back/src/Model/Zone.ts | 1 - back/src/RoomManager.ts | 2 - back/src/Services/SocketManager.ts | 15 ++------ front/src/Components/CameraControls.svelte | 30 ++++++++++++++- front/src/Components/images/lock.svg | 1 + .../images/lock.svg:Zone.Identifier | 3 ++ front/src/Connexion/ConnexionModels.ts | 2 +- front/src/Phaser/Game/GameScene.ts | 37 ++++++++----------- front/src/Stores/CurrentPlayerGroupStore.ts | 4 ++ messages/protos/messages.proto | 1 - pusher/src/Model/Zone.ts | 1 - 13 files changed, 57 insertions(+), 44 deletions(-) create mode 100644 front/src/Components/images/lock.svg create mode 100644 front/src/Components/images/lock.svg:Zone.Identifier create mode 100644 front/src/Stores/CurrentPlayerGroupStore.ts diff --git a/back/src/Model/GameRoom.ts b/back/src/Model/GameRoom.ts index d6a6c7c2..74284ab2 100644 --- a/back/src/Model/GameRoom.ts +++ b/back/src/Model/GameRoom.ts @@ -551,8 +551,6 @@ export class GameRoom { } public emitLockGroupMessage(user: User, lockGroupMessage: LockGroupMessage) { - console.log("D2 GAME ROOM EMIT LOCK GROUP MESSAGE"); - console.log(lockGroupMessage.getGroupid()); this.positionNotifier.emitLockGroupEvent(user, lockGroupMessage); } diff --git a/back/src/Model/PositionNotifier.ts b/back/src/Model/PositionNotifier.ts index ad7334f9..6e1fb195 100644 --- a/back/src/Model/PositionNotifier.ts +++ b/back/src/Model/PositionNotifier.ts @@ -143,8 +143,6 @@ export class PositionNotifier { public emitLockGroupEvent(user: User, lockGroupMessage: LockGroupMessage) { const zoneDesc = this.getZoneDescriptorFromCoordinates(user.getPosition().x, user.getPosition().y); const zone = this.getZone(zoneDesc.i, zoneDesc.j); - console.log("D3 emit from ZONE"); - console.log(lockGroupMessage.getGroupid()); zone.emitLockGroupEvent(lockGroupMessage); } diff --git a/back/src/Model/Zone.ts b/back/src/Model/Zone.ts index 35bb4660..4f49ff55 100644 --- a/back/src/Model/Zone.ts +++ b/back/src/Model/Zone.ts @@ -112,7 +112,6 @@ export class Zone { } public emitLockGroupEvent(lockGroupMessage: LockGroupMessage) { - console.log("D4 ZONE ON LOCK GROUP CALLBACK"); for (const listener of this.listeners) { this.onLockGroup(lockGroupMessage, listener); } diff --git a/back/src/RoomManager.ts b/back/src/RoomManager.ts index 6a091054..8a840c15 100644 --- a/back/src/RoomManager.ts +++ b/back/src/RoomManager.ts @@ -155,8 +155,6 @@ const roomManager: IRoomManagerServer = { user, setPlayerDetailsMessage as SetPlayerDetailsMessage ); - } else if (message.hasLockgroupmessage()) { - console.log("===== GOT LOCK GROUP MESSAGE FROM CLIENT ====="); } else { throw new Error("Unhandled message type"); } diff --git a/back/src/Services/SocketManager.ts b/back/src/Services/SocketManager.ts index aaa373fb..2bfe7cf2 100644 --- a/back/src/Services/SocketManager.ts +++ b/back/src/Services/SocketManager.ts @@ -70,7 +70,6 @@ function emitZoneMessage(subMessage: SubToPusherMessage, socket: ZoneSocket): vo // TODO: should we batch those every 100ms? const batchMessage = new BatchToPusherMessage(); batchMessage.addPayload(subMessage); - socket.write(batchMessage); } @@ -277,8 +276,9 @@ export class SocketManager { }, MINIMUM_DISTANCE, GROUP_RADIUS, - (thing: Movable, fromZone: Zone | null, listener: ZoneSocket) => - this.onZoneEnter(thing, fromZone, listener), + (thing: Movable, fromZone: Zone | null, listener: ZoneSocket) => { + this.onZoneEnter(thing, fromZone, listener); + }, (thing: Movable, position: PositionInterface, listener: ZoneSocket) => this.onClientMove(thing, position, listener), (thing: Movable, newZone: Zone | null, listener: ZoneSocket) => @@ -393,17 +393,12 @@ export class SocketManager { private onLockGroup(lockGroupMessage: LockGroupMessage, client: ZoneSocket) { const subMessage = new SubToPusherMessage(); subMessage.setLockgroupmessage(lockGroupMessage); - console.log("D5 SOCKET MANAGER ON LOCK GROUP"); - console.log(lockGroupMessage.getGroupid()); - console.log(lockGroupMessage.getLock()); - emitZoneMessage(subMessage, client); } private onPlayerDetailsUpdated(playerDetailsUpdatedMessage: PlayerDetailsUpdatedMessage, client: ZoneSocket) { const subMessage = new SubToPusherMessage(); subMessage.setPlayerdetailsupdatedmessage(playerDetailsUpdatedMessage); - emitZoneMessage(subMessage, client); } @@ -433,7 +428,6 @@ export class SocketManager { const subMessage = new SubToPusherMessage(); subMessage.setGroupleftzonemessage(groupDeleteMessage); - emitZoneMessage(subMessage, client); //user.emitInBatch(subMessage); } @@ -445,7 +439,6 @@ export class SocketManager { const subMessage = new SubToPusherMessage(); subMessage.setUserleftzonemessage(userLeftMessage); - emitZoneMessage(subMessage, client); } @@ -667,6 +660,7 @@ export class SocketManager { const groupUpdateMessage = new GroupUpdateZoneMessage(); groupUpdateMessage.setGroupid(thing.getId()); groupUpdateMessage.setPosition(ProtobufUtils.toPointMessage(thing.getPosition())); + groupUpdateMessage.setLocked(thing.isLocked()); const subMessage = new SubToPusherMessage(); subMessage.setGroupupdatezonemessage(groupUpdateMessage); @@ -905,7 +899,6 @@ export class SocketManager { } handleLockGroupMessage(room: GameRoom, user: User, message: LockGroupMessage) { - console.log("D1 HANDLE LOCK GROUP MESSAGE"); const group = user.group; if (!group) { return; diff --git a/front/src/Components/CameraControls.svelte b/front/src/Components/CameraControls.svelte index bfe1d9d0..7b189aff 100644 --- a/front/src/Components/CameraControls.svelte +++ b/front/src/Components/CameraControls.svelte @@ -10,12 +10,14 @@ import layoutPresentationImg from "./images/layout-presentation.svg"; import layoutChatImg from "./images/layout-chat.svg"; import followImg from "./images/follow.svg"; + import lockImg from "./images/lock.svg"; import { LayoutMode } from "../WebRtc/LayoutManager"; import { peerStore } from "../Stores/PeerStore"; import { onDestroy } from "svelte"; import { embedScreenLayout } from "../Stores/EmbedScreensStore"; import { followRoleStore, followStateStore, followUsersStore } from "../Stores/FollowStore"; import { gameManager } from "../Phaser/Game/GameManager"; + import { currentPlayerGroupIdStore, currentPlayerGroupLockStateStore } from "../Stores/CurrentPlayerGroupStore"; const gameScene = gameManager.getCurrentGameScene(); @@ -70,6 +72,15 @@ } } + function lockClick() { + console.log($currentPlayerGroupIdStore); + console.log($currentPlayerGroupLockStateStore); + if ($currentPlayerGroupIdStore === undefined) { + return; + } + gameScene.connection?.emitLockGroup($currentPlayerGroupIdStore, !$currentPlayerGroupLockStateStore); + } + let isSilent: boolean; const unsubscribeIsSilent = isSilentStore.subscribe((value) => { isSilent = value; @@ -95,6 +106,15 @@ +
+ +
+
\ No newline at end of file diff --git a/front/src/Components/images/lock.svg:Zone.Identifier b/front/src/Components/images/lock.svg:Zone.Identifier new file mode 100644 index 00000000..053d1127 --- /dev/null +++ b/front/src/Components/images/lock.svg:Zone.Identifier @@ -0,0 +1,3 @@ +[ZoneTransfer] +ZoneId=3 +HostUrl=about:internet diff --git a/front/src/Connexion/ConnexionModels.ts b/front/src/Connexion/ConnexionModels.ts index 5b41e602..167624e6 100644 --- a/front/src/Connexion/ConnexionModels.ts +++ b/front/src/Connexion/ConnexionModels.ts @@ -50,7 +50,7 @@ export interface GroupCreatedUpdatedMessageInterface { export interface LockGroupMessageInterface { groupId: number; - locked: boolean; + lock: boolean; } export interface GroupUsersUpdateMessageInterface { diff --git a/front/src/Phaser/Game/GameScene.ts b/front/src/Phaser/Game/GameScene.ts index 7b92a5d1..8b2112b9 100644 --- a/front/src/Phaser/Game/GameScene.ts +++ b/front/src/Phaser/Game/GameScene.ts @@ -77,6 +77,7 @@ import { userIsAdminStore } from "../../Stores/GameStore"; import { contactPageStore } from "../../Stores/MenuStore"; import type { WasCameraUpdatedEvent } from "../../Api/Events/WasCameraUpdatedEvent"; import { audioManagerFileStore } from "../../Stores/AudioManagerStore"; +import { currentPlayerGroupIdStore, currentPlayerGroupLockStateStore } from "../../Stores/CurrentPlayerGroupStore"; import EVENT_TYPE = Phaser.Scenes.Events; import Texture = Phaser.Textures.Texture; @@ -153,7 +154,6 @@ export class GameScene extends DirtyScene { mapFile!: ITiledMap; animatedTiles!: AnimatedTiles; groups: Map; - currentPlayerGroupId?: number; circleTexture!: CanvasTexture; circleRedTexture!: CanvasTexture; pendingEvents = new Queue< @@ -185,6 +185,7 @@ export class GameScene extends DirtyScene { private volumeStoreUnsubscribers: Map = new Map(); private localVolumeStoreUnsubscriber: Unsubscriber | undefined; private followUsersColorStoreUnsubscribe!: Unsubscriber; + private currentPlayerGroupIdStoreUnsubscribe!: Unsubscriber; private biggestAvailableAreaStoreUnsubscribe!: () => void; MapUrlFile: string; @@ -226,6 +227,7 @@ export class GameScene extends DirtyScene { private loader: Loader; private lastCameraEvent: WasCameraUpdatedEvent | undefined; private firstCameraUpdateSent: boolean = false; + private currentPlayerGroupId?: number; constructor(private room: Room, MapUrlFile: string, customKey?: string | undefined) { super({ @@ -233,7 +235,6 @@ export class GameScene extends DirtyScene { }); this.Terrains = []; this.groups = new Map(); - this.currentPlayerGroupId = undefined; this.instance = room.getInstance(); this.MapUrlFile = MapUrlFile; @@ -717,6 +718,10 @@ export class GameScene extends DirtyScene { } }); + this.currentPlayerGroupIdStoreUnsubscribe = currentPlayerGroupIdStore.subscribe((groupId) => { + this.currentPlayerGroupId = groupId; + }); + Promise.all([this.connectionAnswerPromise as Promise, ...scriptPromises]) .then(() => { this.scene.wake(); @@ -727,20 +732,6 @@ export class GameScene extends DirtyScene { e ) ); - - this.input.keyboard.on("keydown-L", (event: Event) => { - if (this.currentPlayerGroupId !== undefined) { - console.log("group locked"); - this.connection?.emitLockGroup(this.currentPlayerGroupId, true); - } - }); - - this.input.keyboard.on("keydown-U", (event: Event) => { - if (this.currentPlayerGroupId !== undefined) { - console.log("group unlocked"); - this.connection?.emitLockGroup(this.currentPlayerGroupId, false); - } - }); } /** @@ -855,9 +846,8 @@ export class GameScene extends DirtyScene { }); this.connection.groupUsersUpdateMessageStream.subscribe((message) => { - this.currentPlayerGroupId = message.groupId; - console.log("GOT GROUP USERS UPDATE MESSAGE"); - console.log(message); + // TODO: how else can we deduce our current group? + currentPlayerGroupIdStore.set(message.groupId); }); /** @@ -1849,9 +1839,8 @@ ${escapedMessage} break; case "DeleteGroupEvent": { this.doDeleteGroup(event.groupId); - if (this.currentPlayerGroupId === event.groupId) { - this.currentPlayerGroupId = undefined; - } + currentPlayerGroupIdStore.set(undefined); + currentPlayerGroupLockStateStore.set(undefined); break; } case "LockGroupEvent": { @@ -2033,6 +2022,9 @@ ${escapedMessage} sprite.setDisplayOrigin(48, 48); this.add.existing(sprite); this.groups.set(groupPositionMessage.groupId, sprite); + if (this.currentPlayerGroupId === groupPositionMessage.groupId) { + currentPlayerGroupLockStateStore.set(groupPositionMessage.locked); + } return sprite; } @@ -2064,6 +2056,7 @@ ${escapedMessage} if (!group) { return; } + currentPlayerGroupLockStateStore.set(event.lock); group.setTexture(event.lock ? "circleSprite-red" : "circleSprite-white"); } diff --git a/front/src/Stores/CurrentPlayerGroupStore.ts b/front/src/Stores/CurrentPlayerGroupStore.ts new file mode 100644 index 00000000..cda46325 --- /dev/null +++ b/front/src/Stores/CurrentPlayerGroupStore.ts @@ -0,0 +1,4 @@ +import { writable } from "svelte/store"; + +export const currentPlayerGroupIdStore = writable(undefined); +export const currentPlayerGroupLockStateStore = writable(undefined); diff --git a/messages/protos/messages.proto b/messages/protos/messages.proto index 4708f37d..3db0da95 100644 --- a/messages/protos/messages.proto +++ b/messages/protos/messages.proto @@ -324,7 +324,6 @@ message ServerToClientMessage { FollowConfirmationMessage followConfirmationMessage = 22; FollowAbortMessage followAbortMessage = 23; GroupUsersUpdateMessage groupUsersUpdateMessage = 24; - LockGroupMessage lockGroupMessage = 25; } } diff --git a/pusher/src/Model/Zone.ts b/pusher/src/Model/Zone.ts index 50d684a1..451597b9 100644 --- a/pusher/src/Model/Zone.ts +++ b/pusher/src/Model/Zone.ts @@ -155,7 +155,6 @@ export class GroupDescriptor { groupUpdateMessage.setGroupsize(this.groupSize); groupUpdateMessage.setPosition(this.position); groupUpdateMessage.setLocked(this.locked); - return groupUpdateMessage; } }