listening to lockGroupMessage on front
This commit is contained in:
parent
d43c8d181a
commit
ef22d4ba20
@ -6,6 +6,7 @@ import {
|
|||||||
EmoteCallback,
|
EmoteCallback,
|
||||||
EntersCallback,
|
EntersCallback,
|
||||||
LeavesCallback,
|
LeavesCallback,
|
||||||
|
LockGroupCallback,
|
||||||
MovesCallback,
|
MovesCallback,
|
||||||
PlayerDetailsUpdatedCallback,
|
PlayerDetailsUpdatedCallback,
|
||||||
} from "_Model/Zone";
|
} from "_Model/Zone";
|
||||||
@ -22,6 +23,7 @@ import {
|
|||||||
VariableMessage,
|
VariableMessage,
|
||||||
VariableWithTagMessage,
|
VariableWithTagMessage,
|
||||||
ServerToClientMessage,
|
ServerToClientMessage,
|
||||||
|
LockGroupMessage,
|
||||||
} from "../Messages/generated/messages_pb";
|
} from "../Messages/generated/messages_pb";
|
||||||
import { ProtobufUtils } from "../Model/Websocket/ProtobufUtils";
|
import { ProtobufUtils } from "../Model/Websocket/ProtobufUtils";
|
||||||
import { RoomSocket, ZoneSocket } from "src/RoomManager";
|
import { RoomSocket, ZoneSocket } from "src/RoomManager";
|
||||||
@ -66,6 +68,7 @@ export class GameRoom {
|
|||||||
onMoves: MovesCallback,
|
onMoves: MovesCallback,
|
||||||
onLeaves: LeavesCallback,
|
onLeaves: LeavesCallback,
|
||||||
onEmote: EmoteCallback,
|
onEmote: EmoteCallback,
|
||||||
|
onLockGroup: LockGroupCallback,
|
||||||
onPlayerDetailsUpdated: PlayerDetailsUpdatedCallback
|
onPlayerDetailsUpdated: PlayerDetailsUpdatedCallback
|
||||||
) {
|
) {
|
||||||
// A zone is 10 sprites wide.
|
// A zone is 10 sprites wide.
|
||||||
@ -76,6 +79,7 @@ export class GameRoom {
|
|||||||
onMoves,
|
onMoves,
|
||||||
onLeaves,
|
onLeaves,
|
||||||
onEmote,
|
onEmote,
|
||||||
|
onLockGroup,
|
||||||
onPlayerDetailsUpdated
|
onPlayerDetailsUpdated
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
@ -90,6 +94,7 @@ export class GameRoom {
|
|||||||
onMoves: MovesCallback,
|
onMoves: MovesCallback,
|
||||||
onLeaves: LeavesCallback,
|
onLeaves: LeavesCallback,
|
||||||
onEmote: EmoteCallback,
|
onEmote: EmoteCallback,
|
||||||
|
onLockGroup: LockGroupCallback,
|
||||||
onPlayerDetailsUpdated: PlayerDetailsUpdatedCallback
|
onPlayerDetailsUpdated: PlayerDetailsUpdatedCallback
|
||||||
): Promise<GameRoom> {
|
): Promise<GameRoom> {
|
||||||
const mapDetails = await GameRoom.getMapDetails(roomUrl);
|
const mapDetails = await GameRoom.getMapDetails(roomUrl);
|
||||||
@ -105,6 +110,7 @@ export class GameRoom {
|
|||||||
onMoves,
|
onMoves,
|
||||||
onLeaves,
|
onLeaves,
|
||||||
onEmote,
|
onEmote,
|
||||||
|
onLockGroup,
|
||||||
onPlayerDetailsUpdated
|
onPlayerDetailsUpdated
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -544,6 +550,12 @@ export class GameRoom {
|
|||||||
this.positionNotifier.emitEmoteEvent(user, emoteEventMessage);
|
this.positionNotifier.emitEmoteEvent(user, emoteEventMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public emitLockGroupMessage(user: User, lockGroupMessage: LockGroupMessage) {
|
||||||
|
console.log("D2 GAME ROOM EMIT LOCK GROUP MESSAGE");
|
||||||
|
console.log(lockGroupMessage.getGroupid());
|
||||||
|
this.positionNotifier.emitLockGroupEvent(user, lockGroupMessage);
|
||||||
|
}
|
||||||
|
|
||||||
public addRoomListener(socket: RoomSocket) {
|
public addRoomListener(socket: RoomSocket) {
|
||||||
this.roomListeners.add(socket);
|
this.roomListeners.add(socket);
|
||||||
}
|
}
|
||||||
|
@ -12,6 +12,7 @@ import {
|
|||||||
EmoteCallback,
|
EmoteCallback,
|
||||||
EntersCallback,
|
EntersCallback,
|
||||||
LeavesCallback,
|
LeavesCallback,
|
||||||
|
LockGroupCallback,
|
||||||
MovesCallback,
|
MovesCallback,
|
||||||
PlayerDetailsUpdatedCallback,
|
PlayerDetailsUpdatedCallback,
|
||||||
Zone,
|
Zone,
|
||||||
@ -20,7 +21,7 @@ import { Movable } from "_Model/Movable";
|
|||||||
import { PositionInterface } from "_Model/PositionInterface";
|
import { PositionInterface } from "_Model/PositionInterface";
|
||||||
import { ZoneSocket } from "../RoomManager";
|
import { ZoneSocket } from "../RoomManager";
|
||||||
import { User } from "../Model/User";
|
import { User } from "../Model/User";
|
||||||
import { EmoteEventMessage, SetPlayerDetailsMessage } from "../Messages/generated/messages_pb";
|
import { EmoteEventMessage, LockGroupMessage, SetPlayerDetailsMessage } from "../Messages/generated/messages_pb";
|
||||||
|
|
||||||
interface ZoneDescriptor {
|
interface ZoneDescriptor {
|
||||||
i: number;
|
i: number;
|
||||||
@ -50,6 +51,7 @@ export class PositionNotifier {
|
|||||||
private onUserMoves: MovesCallback,
|
private onUserMoves: MovesCallback,
|
||||||
private onUserLeaves: LeavesCallback,
|
private onUserLeaves: LeavesCallback,
|
||||||
private onEmote: EmoteCallback,
|
private onEmote: EmoteCallback,
|
||||||
|
private onLockGroup: LockGroupCallback,
|
||||||
private onPlayerDetailsUpdated: PlayerDetailsUpdatedCallback
|
private onPlayerDetailsUpdated: PlayerDetailsUpdatedCallback
|
||||||
) {}
|
) {}
|
||||||
|
|
||||||
@ -111,6 +113,7 @@ export class PositionNotifier {
|
|||||||
this.onUserMoves,
|
this.onUserMoves,
|
||||||
this.onUserLeaves,
|
this.onUserLeaves,
|
||||||
this.onEmote,
|
this.onEmote,
|
||||||
|
this.onLockGroup,
|
||||||
this.onPlayerDetailsUpdated,
|
this.onPlayerDetailsUpdated,
|
||||||
i,
|
i,
|
||||||
j
|
j
|
||||||
@ -137,6 +140,14 @@ export class PositionNotifier {
|
|||||||
zone.emitEmoteEvent(emoteEventMessage);
|
zone.emitEmoteEvent(emoteEventMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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);
|
||||||
|
}
|
||||||
|
|
||||||
public *getAllUsersInSquareAroundZone(zone: Zone): Generator<User> {
|
public *getAllUsersInSquareAroundZone(zone: Zone): Generator<User> {
|
||||||
const zoneDescriptor = this.getZoneDescriptorFromCoordinates(zone.x, zone.y);
|
const zoneDescriptor = this.getZoneDescriptorFromCoordinates(zone.x, zone.y);
|
||||||
for (const d of getNearbyDescriptorsMatrix(zoneDescriptor)) {
|
for (const d of getNearbyDescriptorsMatrix(zoneDescriptor)) {
|
||||||
|
@ -7,12 +7,14 @@ import {
|
|||||||
EmoteEventMessage,
|
EmoteEventMessage,
|
||||||
SetPlayerDetailsMessage,
|
SetPlayerDetailsMessage,
|
||||||
PlayerDetailsUpdatedMessage,
|
PlayerDetailsUpdatedMessage,
|
||||||
|
LockGroupMessage,
|
||||||
} from "../Messages/generated/messages_pb";
|
} from "../Messages/generated/messages_pb";
|
||||||
|
|
||||||
export type EntersCallback = (thing: Movable, fromZone: Zone | null, listener: ZoneSocket) => void;
|
export type EntersCallback = (thing: Movable, fromZone: Zone | null, listener: ZoneSocket) => void;
|
||||||
export type MovesCallback = (thing: Movable, position: PositionInterface, listener: ZoneSocket) => void;
|
export type MovesCallback = (thing: Movable, position: PositionInterface, listener: ZoneSocket) => void;
|
||||||
export type LeavesCallback = (thing: Movable, newZone: Zone | null, listener: ZoneSocket) => void;
|
export type LeavesCallback = (thing: Movable, newZone: Zone | null, listener: ZoneSocket) => void;
|
||||||
export type EmoteCallback = (emoteEventMessage: EmoteEventMessage, listener: ZoneSocket) => void;
|
export type EmoteCallback = (emoteEventMessage: EmoteEventMessage, listener: ZoneSocket) => void;
|
||||||
|
export type LockGroupCallback = (lockGroupMessage: LockGroupMessage, listener: ZoneSocket) => void;
|
||||||
export type PlayerDetailsUpdatedCallback = (
|
export type PlayerDetailsUpdatedCallback = (
|
||||||
playerDetailsUpdatedMessage: PlayerDetailsUpdatedMessage,
|
playerDetailsUpdatedMessage: PlayerDetailsUpdatedMessage,
|
||||||
listener: ZoneSocket
|
listener: ZoneSocket
|
||||||
@ -27,6 +29,7 @@ export class Zone {
|
|||||||
private onMoves: MovesCallback,
|
private onMoves: MovesCallback,
|
||||||
private onLeaves: LeavesCallback,
|
private onLeaves: LeavesCallback,
|
||||||
private onEmote: EmoteCallback,
|
private onEmote: EmoteCallback,
|
||||||
|
private onLockGroup: LockGroupCallback,
|
||||||
private onPlayerDetailsUpdated: PlayerDetailsUpdatedCallback,
|
private onPlayerDetailsUpdated: PlayerDetailsUpdatedCallback,
|
||||||
public readonly x: number,
|
public readonly x: number,
|
||||||
public readonly y: number
|
public readonly y: number
|
||||||
@ -108,6 +111,13 @@ 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public updatePlayerDetails(user: User, playerDetails: SetPlayerDetailsMessage) {
|
public updatePlayerDetails(user: User, playerDetails: SetPlayerDetailsMessage) {
|
||||||
const playerDetailsUpdatedMessage = new PlayerDetailsUpdatedMessage();
|
const playerDetailsUpdatedMessage = new PlayerDetailsUpdatedMessage();
|
||||||
playerDetailsUpdatedMessage.setUserid(user.id);
|
playerDetailsUpdatedMessage.setUserid(user.id);
|
||||||
|
@ -138,6 +138,7 @@ const roomManager: IRoomManagerServer = {
|
|||||||
);
|
);
|
||||||
} else if (message.hasLockgroupmessage()) {
|
} else if (message.hasLockgroupmessage()) {
|
||||||
socketManager.handleLockGroupMessage(
|
socketManager.handleLockGroupMessage(
|
||||||
|
room,
|
||||||
user,
|
user,
|
||||||
message.getLockgroupmessage() as LockGroupMessage
|
message.getLockgroupmessage() as LockGroupMessage
|
||||||
);
|
);
|
||||||
|
@ -285,6 +285,8 @@ export class SocketManager {
|
|||||||
this.onClientLeave(thing, newZone, listener),
|
this.onClientLeave(thing, newZone, listener),
|
||||||
(emoteEventMessage: EmoteEventMessage, listener: ZoneSocket) =>
|
(emoteEventMessage: EmoteEventMessage, listener: ZoneSocket) =>
|
||||||
this.onEmote(emoteEventMessage, listener),
|
this.onEmote(emoteEventMessage, listener),
|
||||||
|
(lockGroupMessage: LockGroupMessage, listener: ZoneSocket) =>
|
||||||
|
this.onLockGroup(lockGroupMessage, listener),
|
||||||
(playerDetailsUpdatedMessage: PlayerDetailsUpdatedMessage, listener: ZoneSocket) =>
|
(playerDetailsUpdatedMessage: PlayerDetailsUpdatedMessage, listener: ZoneSocket) =>
|
||||||
this.onPlayerDetailsUpdated(playerDetailsUpdatedMessage, listener)
|
this.onPlayerDetailsUpdated(playerDetailsUpdatedMessage, listener)
|
||||||
)
|
)
|
||||||
@ -388,6 +390,16 @@ export class SocketManager {
|
|||||||
emitZoneMessage(subMessage, client);
|
emitZoneMessage(subMessage, client);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
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) {
|
private onPlayerDetailsUpdated(playerDetailsUpdatedMessage: PlayerDetailsUpdatedMessage, client: ZoneSocket) {
|
||||||
const subMessage = new SubToPusherMessage();
|
const subMessage = new SubToPusherMessage();
|
||||||
subMessage.setPlayerdetailsupdatedmessage(playerDetailsUpdatedMessage);
|
subMessage.setPlayerdetailsupdatedmessage(playerDetailsUpdatedMessage);
|
||||||
@ -892,9 +904,17 @@ export class SocketManager {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
handleLockGroupMessage(user: User, message: LockGroupMessage) {
|
handleLockGroupMessage(room: GameRoom, user: User, message: LockGroupMessage) {
|
||||||
console.log(`lock group: ${message.getLock()}`);
|
console.log("D1 HANDLE LOCK GROUP MESSAGE");
|
||||||
user.group?.lock(message.getLock());
|
const group = user.group;
|
||||||
|
if (!group) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
group.lock(message.getLock());
|
||||||
|
const lockGroupMessage = new LockGroupMessage();
|
||||||
|
lockGroupMessage.setLock(message.getLock());
|
||||||
|
lockGroupMessage.setGroupid(message.getGroupid());
|
||||||
|
room.emitLockGroupMessage(user, lockGroupMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,6 +25,7 @@ describe("PositionNotifier", () => {
|
|||||||
leaveTriggered = true;
|
leaveTriggered = true;
|
||||||
},
|
},
|
||||||
() => {},
|
() => {},
|
||||||
|
() => {},
|
||||||
() => {}
|
() => {}
|
||||||
);
|
);
|
||||||
|
|
||||||
@ -132,6 +133,7 @@ describe("PositionNotifier", () => {
|
|||||||
leaveTriggered = true;
|
leaveTriggered = true;
|
||||||
},
|
},
|
||||||
() => {},
|
() => {},
|
||||||
|
() => {},
|
||||||
() => {}
|
() => {}
|
||||||
);
|
);
|
||||||
|
|
||||||
|
@ -48,6 +48,11 @@ export interface GroupCreatedUpdatedMessageInterface {
|
|||||||
locked: boolean;
|
locked: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export interface LockGroupMessageInterface {
|
||||||
|
groupId: number;
|
||||||
|
locked: boolean;
|
||||||
|
}
|
||||||
|
|
||||||
export interface GroupUsersUpdateMessageInterface {
|
export interface GroupUsersUpdateMessageInterface {
|
||||||
groupId: number;
|
groupId: number;
|
||||||
userIds: number[];
|
userIds: number[];
|
||||||
|
@ -40,6 +40,7 @@ import {
|
|||||||
PositionMessage_Direction,
|
PositionMessage_Direction,
|
||||||
SetPlayerDetailsMessage as SetPlayerDetailsMessageTsProto,
|
SetPlayerDetailsMessage as SetPlayerDetailsMessageTsProto,
|
||||||
PingMessage as PingMessageTsProto,
|
PingMessage as PingMessageTsProto,
|
||||||
|
LockGroupMessage,
|
||||||
} from "../Messages/ts-proto-generated/messages";
|
} from "../Messages/ts-proto-generated/messages";
|
||||||
import { Subject } from "rxjs";
|
import { Subject } from "rxjs";
|
||||||
|
|
||||||
@ -101,6 +102,9 @@ export class RoomConnection implements RoomConnection {
|
|||||||
private readonly _groupUsersUpdateMessageStream = new Subject<GroupUsersUpdateMessageInterface>();
|
private readonly _groupUsersUpdateMessageStream = new Subject<GroupUsersUpdateMessageInterface>();
|
||||||
public readonly groupUsersUpdateMessageStream = this._groupUsersUpdateMessageStream.asObservable();
|
public readonly groupUsersUpdateMessageStream = this._groupUsersUpdateMessageStream.asObservable();
|
||||||
|
|
||||||
|
private readonly _lockGroupMessageStream = new Subject<LockGroupMessage>();
|
||||||
|
public readonly lockGroupMessageStream = this._lockGroupMessageStream.asObservable();
|
||||||
|
|
||||||
private readonly _groupDeleteMessageStream = new Subject<GroupDeleteMessageTsProto>();
|
private readonly _groupDeleteMessageStream = new Subject<GroupDeleteMessageTsProto>();
|
||||||
public readonly groupDeleteMessageStream = this._groupDeleteMessageStream.asObservable();
|
public readonly groupDeleteMessageStream = this._groupDeleteMessageStream.asObservable();
|
||||||
|
|
||||||
@ -264,6 +268,10 @@ export class RoomConnection implements RoomConnection {
|
|||||||
this._emoteEventMessageStream.next(subMessage.emoteEventMessage);
|
this._emoteEventMessageStream.next(subMessage.emoteEventMessage);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
case "lockGroupMessage": {
|
||||||
|
this._lockGroupMessageStream.next(subMessage.lockGroupMessage);
|
||||||
|
break;
|
||||||
|
}
|
||||||
case "playerDetailsUpdatedMessage": {
|
case "playerDetailsUpdatedMessage": {
|
||||||
this._playerDetailsUpdatedMessageStream.next(subMessage.playerDetailsUpdatedMessage);
|
this._playerDetailsUpdatedMessageStream.next(subMessage.playerDetailsUpdatedMessage);
|
||||||
break;
|
break;
|
||||||
@ -403,8 +411,6 @@ export class RoomConnection implements RoomConnection {
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "groupUsersUpdateMessage": {
|
case "groupUsersUpdateMessage": {
|
||||||
console.log("GOT GROUP USERS UPDATE MESSAGE");
|
|
||||||
console.log(message.groupUsersUpdateMessage);
|
|
||||||
this._groupUsersUpdateMessageStream.next(message.groupUsersUpdateMessage);
|
this._groupUsersUpdateMessageStream.next(message.groupUsersUpdateMessage);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -51,6 +51,7 @@ import { PathfindingManager } from "../../Utils/PathfindingManager";
|
|||||||
import { ActivatablesManager } from "./ActivatablesManager";
|
import { ActivatablesManager } from "./ActivatablesManager";
|
||||||
import type {
|
import type {
|
||||||
GroupCreatedUpdatedMessageInterface,
|
GroupCreatedUpdatedMessageInterface,
|
||||||
|
LockGroupMessageInterface,
|
||||||
MessageUserMovedInterface,
|
MessageUserMovedInterface,
|
||||||
MessageUserPositionInterface,
|
MessageUserPositionInterface,
|
||||||
OnConnectInterface,
|
OnConnectInterface,
|
||||||
@ -132,6 +133,11 @@ interface DeleteGroupEventInterface {
|
|||||||
groupId: number;
|
groupId: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface LockGroupEventInterface {
|
||||||
|
type: "LockGroupEvent";
|
||||||
|
event: LockGroupMessageInterface;
|
||||||
|
}
|
||||||
|
|
||||||
interface PlayerDetailsUpdatedInterface {
|
interface PlayerDetailsUpdatedInterface {
|
||||||
type: "PlayerDetailsUpdated";
|
type: "PlayerDetailsUpdated";
|
||||||
details: PlayerDetailsUpdatedMessageInterface;
|
details: PlayerDetailsUpdatedMessageInterface;
|
||||||
@ -147,6 +153,7 @@ export class GameScene extends DirtyScene {
|
|||||||
mapFile!: ITiledMap;
|
mapFile!: ITiledMap;
|
||||||
animatedTiles!: AnimatedTiles;
|
animatedTiles!: AnimatedTiles;
|
||||||
groups: Map<number, Sprite>;
|
groups: Map<number, Sprite>;
|
||||||
|
currentPlayerGroupId?: number;
|
||||||
circleTexture!: CanvasTexture;
|
circleTexture!: CanvasTexture;
|
||||||
circleRedTexture!: CanvasTexture;
|
circleRedTexture!: CanvasTexture;
|
||||||
pendingEvents = new Queue<
|
pendingEvents = new Queue<
|
||||||
@ -156,6 +163,7 @@ export class GameScene extends DirtyScene {
|
|||||||
| UserMovedEventInterface
|
| UserMovedEventInterface
|
||||||
| GroupCreatedUpdatedEventInterface
|
| GroupCreatedUpdatedEventInterface
|
||||||
| DeleteGroupEventInterface
|
| DeleteGroupEventInterface
|
||||||
|
| LockGroupEventInterface
|
||||||
| PlayerDetailsUpdatedInterface
|
| PlayerDetailsUpdatedInterface
|
||||||
>();
|
>();
|
||||||
private initPosition: PositionInterface | null = null;
|
private initPosition: PositionInterface | null = null;
|
||||||
@ -225,6 +233,7 @@ export class GameScene extends DirtyScene {
|
|||||||
});
|
});
|
||||||
this.Terrains = [];
|
this.Terrains = [];
|
||||||
this.groups = new Map<number, Sprite>();
|
this.groups = new Map<number, Sprite>();
|
||||||
|
this.currentPlayerGroupId = undefined;
|
||||||
this.instance = room.getInstance();
|
this.instance = room.getInstance();
|
||||||
|
|
||||||
this.MapUrlFile = MapUrlFile;
|
this.MapUrlFile = MapUrlFile;
|
||||||
@ -720,13 +729,17 @@ export class GameScene extends DirtyScene {
|
|||||||
);
|
);
|
||||||
|
|
||||||
this.input.keyboard.on("keydown-L", (event: Event) => {
|
this.input.keyboard.on("keydown-L", (event: Event) => {
|
||||||
console.log("group locked");
|
if (this.currentPlayerGroupId !== undefined) {
|
||||||
this.connection?.emitLockGroup(1, true);
|
console.log("group locked");
|
||||||
|
this.connection?.emitLockGroup(this.currentPlayerGroupId, true);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
this.input.keyboard.on("keydown-U", (event: Event) => {
|
this.input.keyboard.on("keydown-U", (event: Event) => {
|
||||||
console.log("group unlocked");
|
if (this.currentPlayerGroupId !== undefined) {
|
||||||
this.connection?.emitLockGroup(1, false);
|
console.log("group unlocked");
|
||||||
|
this.connection?.emitLockGroup(this.currentPlayerGroupId, false);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -792,7 +805,6 @@ export class GameScene extends DirtyScene {
|
|||||||
|
|
||||||
this.connection.groupUpdateMessageStream.subscribe(
|
this.connection.groupUpdateMessageStream.subscribe(
|
||||||
(groupPositionMessage: GroupCreatedUpdatedMessageInterface) => {
|
(groupPositionMessage: GroupCreatedUpdatedMessageInterface) => {
|
||||||
console.log(groupPositionMessage);
|
|
||||||
this.shareGroupPosition(groupPositionMessage);
|
this.shareGroupPosition(groupPositionMessage);
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
@ -805,6 +817,10 @@ export class GameScene extends DirtyScene {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.connection.lockGroupMessageStream.subscribe((message) => {
|
||||||
|
this.lockGroup(message);
|
||||||
|
});
|
||||||
|
|
||||||
this.connection.onServerDisconnected(() => {
|
this.connection.onServerDisconnected(() => {
|
||||||
console.log("Player disconnected from server. Reloading scene.");
|
console.log("Player disconnected from server. Reloading scene.");
|
||||||
this.cleanupClosingScene();
|
this.cleanupClosingScene();
|
||||||
@ -838,6 +854,12 @@ export class GameScene extends DirtyScene {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
this.connection.groupUsersUpdateMessageStream.subscribe((message) => {
|
||||||
|
this.currentPlayerGroupId = message.groupId;
|
||||||
|
console.log("GOT GROUP USERS UPDATE MESSAGE");
|
||||||
|
console.log(message);
|
||||||
|
});
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Triggered when we receive the JWT token to connect to Jitsi
|
* Triggered when we receive the JWT token to connect to Jitsi
|
||||||
*/
|
*/
|
||||||
@ -1820,19 +1842,22 @@ ${escapedMessage}
|
|||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case "GroupCreatedUpdatedEvent":
|
case "GroupCreatedUpdatedEvent":
|
||||||
console.log("CREATE OR UPDATE GROUP");
|
|
||||||
this.doShareGroupPosition(event.event);
|
this.doShareGroupPosition(event.event);
|
||||||
break;
|
break;
|
||||||
// TODO: CALL THIS ON GROUP LOCK CHANGE
|
|
||||||
// case "GroupCreatedUpdatedEvent":
|
|
||||||
// this.doShareGroupPosition(event.event);
|
|
||||||
// break;
|
|
||||||
case "DeleteGroupEvent":
|
|
||||||
this.doDeleteGroup(event.groupId);
|
|
||||||
break;
|
|
||||||
case "PlayerDetailsUpdated":
|
case "PlayerDetailsUpdated":
|
||||||
this.doUpdatePlayerDetails(event.details);
|
this.doUpdatePlayerDetails(event.details);
|
||||||
break;
|
break;
|
||||||
|
case "DeleteGroupEvent": {
|
||||||
|
this.doDeleteGroup(event.groupId);
|
||||||
|
if (this.currentPlayerGroupId === event.groupId) {
|
||||||
|
this.currentPlayerGroupId = undefined;
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case "LockGroupEvent": {
|
||||||
|
this.doLockGroup(event.event);
|
||||||
|
break;
|
||||||
|
}
|
||||||
default: {
|
default: {
|
||||||
const tmp: never = event;
|
const tmp: never = event;
|
||||||
}
|
}
|
||||||
@ -2027,6 +2052,21 @@ ${escapedMessage}
|
|||||||
this.groups.delete(groupId);
|
this.groups.delete(groupId);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
lockGroup(event: LockGroupMessageInterface): void {
|
||||||
|
this.pendingEvents.enqueue({
|
||||||
|
type: "LockGroupEvent",
|
||||||
|
event,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
doLockGroup(event: LockGroupMessageInterface): void {
|
||||||
|
const group = this.groups.get(event.groupId);
|
||||||
|
if (!group) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
group.setTexture(event.lock ? "circleSprite-red" : "circleSprite-white");
|
||||||
|
}
|
||||||
|
|
||||||
doUpdatePlayerDetails(message: PlayerDetailsUpdatedMessageInterface): void {
|
doUpdatePlayerDetails(message: PlayerDetailsUpdatedMessageInterface): void {
|
||||||
const character = this.MapPlayersByKey.get(message.userId);
|
const character = this.MapPlayersByKey.get(message.userId);
|
||||||
if (character === undefined) {
|
if (character === undefined) {
|
||||||
|
@ -434,6 +434,7 @@ message SubToPusherMessage {
|
|||||||
EmoteEventMessage emoteEventMessage = 9;
|
EmoteEventMessage emoteEventMessage = 9;
|
||||||
ErrorMessage errorMessage = 10;
|
ErrorMessage errorMessage = 10;
|
||||||
PlayerDetailsUpdatedMessage playerDetailsUpdatedMessage = 11;
|
PlayerDetailsUpdatedMessage playerDetailsUpdatedMessage = 11;
|
||||||
|
LockGroupMessage lockGroupMessage = 12;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -18,6 +18,7 @@ import {
|
|||||||
ErrorMessage,
|
ErrorMessage,
|
||||||
PlayerDetailsUpdatedMessage,
|
PlayerDetailsUpdatedMessage,
|
||||||
SetPlayerDetailsMessage,
|
SetPlayerDetailsMessage,
|
||||||
|
LockGroupMessage,
|
||||||
} from "../Messages/generated/messages_pb";
|
} from "../Messages/generated/messages_pb";
|
||||||
import { ClientReadableStream } from "grpc";
|
import { ClientReadableStream } from "grpc";
|
||||||
import { PositionDispatcher } from "_Model/PositionDispatcher";
|
import { PositionDispatcher } from "_Model/PositionDispatcher";
|
||||||
@ -32,7 +33,7 @@ export interface ZoneEventListener {
|
|||||||
onGroupEnters(group: GroupDescriptor, listener: ExSocketInterface): void;
|
onGroupEnters(group: GroupDescriptor, listener: ExSocketInterface): void;
|
||||||
onGroupMoves(group: GroupDescriptor, listener: ExSocketInterface): void;
|
onGroupMoves(group: GroupDescriptor, listener: ExSocketInterface): void;
|
||||||
onGroupLeaves(groupId: number, listener: ExSocketInterface): void;
|
onGroupLeaves(groupId: number, listener: ExSocketInterface): void;
|
||||||
// onGroupLock(groupId: number, listener: ExSocketInterface): void;
|
onLockGroup(lockGroupMessage: LockGroupMessage, listener: ExSocketInterface): void;
|
||||||
onEmote(emoteMessage: EmoteEventMessage, listener: ExSocketInterface): void;
|
onEmote(emoteMessage: EmoteEventMessage, listener: ExSocketInterface): void;
|
||||||
onError(errorMessage: ErrorMessage, listener: ExSocketInterface): void;
|
onError(errorMessage: ErrorMessage, listener: ExSocketInterface): void;
|
||||||
onPlayerDetailsUpdated(playerDetailsUpdatedMessage: PlayerDetailsUpdatedMessage, listener: ExSocketInterface): void;
|
onPlayerDetailsUpdated(playerDetailsUpdatedMessage: PlayerDetailsUpdatedMessage, listener: ExSocketInterface): void;
|
||||||
@ -246,9 +247,9 @@ export class Zone {
|
|||||||
} else if (message.hasEmoteeventmessage()) {
|
} else if (message.hasEmoteeventmessage()) {
|
||||||
const emoteEventMessage = message.getEmoteeventmessage() as EmoteEventMessage;
|
const emoteEventMessage = message.getEmoteeventmessage() as EmoteEventMessage;
|
||||||
this.notifyEmote(emoteEventMessage);
|
this.notifyEmote(emoteEventMessage);
|
||||||
} else if (message.hasEmoteeventmessage()) {
|
} else if (message.hasLockgroupmessage()) {
|
||||||
const emoteEventMessage = message.getEmoteeventmessage() as EmoteEventMessage;
|
const lockGroupMessage = message.getLockgroupmessage() as LockGroupMessage;
|
||||||
this.notifyEmote(emoteEventMessage);
|
this.notifyLockGroup(lockGroupMessage);
|
||||||
} else if (message.hasPlayerdetailsupdatedmessage()) {
|
} else if (message.hasPlayerdetailsupdatedmessage()) {
|
||||||
const playerDetailsUpdatedMessage =
|
const playerDetailsUpdatedMessage =
|
||||||
message.getPlayerdetailsupdatedmessage() as PlayerDetailsUpdatedMessage;
|
message.getPlayerdetailsupdatedmessage() as PlayerDetailsUpdatedMessage;
|
||||||
@ -359,6 +360,12 @@ export class Zone {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private notifyLockGroup(lockGroupMessage: LockGroupMessage) {
|
||||||
|
for (const listener of this.listeners) {
|
||||||
|
this.socketListener.onLockGroup(lockGroupMessage, listener);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private notifyPlayerDetailsUpdated(playerDetailsUpdatedMessage: PlayerDetailsUpdatedMessage) {
|
private notifyPlayerDetailsUpdated(playerDetailsUpdatedMessage: PlayerDetailsUpdatedMessage) {
|
||||||
for (const listener of this.listeners) {
|
for (const listener of this.listeners) {
|
||||||
if (listener.userId === playerDetailsUpdatedMessage.getUserid()) {
|
if (listener.userId === playerDetailsUpdatedMessage.getUserid()) {
|
||||||
|
@ -306,6 +306,13 @@ export class SocketManager implements ZoneEventListener {
|
|||||||
emitInBatch(listener, subMessage);
|
emitInBatch(listener, subMessage);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
onLockGroup(lockGroupMessage: LockGroupMessage, listener: ExSocketInterface): void {
|
||||||
|
const subMessage = new SubMessage();
|
||||||
|
subMessage.setLockgroupmessage(lockGroupMessage);
|
||||||
|
|
||||||
|
emitInBatch(listener, subMessage);
|
||||||
|
}
|
||||||
|
|
||||||
onPlayerDetailsUpdated(
|
onPlayerDetailsUpdated(
|
||||||
playerDetailsUpdatedMessage: PlayerDetailsUpdatedMessage,
|
playerDetailsUpdatedMessage: PlayerDetailsUpdatedMessage,
|
||||||
listener: ExSocketInterface
|
listener: ExSocketInterface
|
||||||
|
Loading…
Reference in New Issue
Block a user