Moved GroupUpdateMessage to protobuf
This commit is contained in:
parent
57545a96a5
commit
76d3779438
5 changed files with 76 additions and 33 deletions
|
@ -2,7 +2,7 @@ import Axios from "axios";
|
|||
import {API_URL} from "./Enum/EnvironmentVariable";
|
||||
import {MessageUI} from "./Logger/MessageUI";
|
||||
import {
|
||||
BatchMessage,
|
||||
BatchMessage, GroupUpdateMessage,
|
||||
PositionMessage,
|
||||
SetPlayerDetailsMessage, UserMovedMessage,
|
||||
UserMovesMessage,
|
||||
|
@ -78,7 +78,7 @@ export interface PositionInterface {
|
|||
|
||||
export interface GroupCreatedUpdatedMessageInterface {
|
||||
position: PositionInterface,
|
||||
groupId: string
|
||||
groupId: number
|
||||
}
|
||||
|
||||
export interface WebRtcStartMessageInterface {
|
||||
|
@ -301,10 +301,31 @@ export class Connection implements Connection {
|
|||
}
|
||||
|
||||
public onGroupUpdatedOrCreated(callback: (groupCreateUpdateMessage: GroupCreatedUpdatedMessageInterface) => void): void {
|
||||
this.socket.on(EventMessage.GROUP_CREATE_UPDATE, callback);
|
||||
// TODO: READ THIS FROM BINARY FORMAT
|
||||
// TODO: READ THIS FROM BINARY FORMAT
|
||||
// TODO: READ THIS FROM BINARY FORMAT
|
||||
// TODO: CHANGE THIS EVENT TO BE PART OF THE BATCHES
|
||||
// TODO: CHANGE THIS EVENT TO BE PART OF THE BATCHES
|
||||
// TODO: CHANGE THIS EVENT TO BE PART OF THE BATCHES
|
||||
// TODO: CHANGE THIS EVENT TO BE PART OF THE BATCHES
|
||||
// TODO: CHANGE THIS EVENT TO BE PART OF THE BATCHES
|
||||
this.socket.on(EventMessage.GROUP_CREATE_UPDATE, (buffer: ArrayBuffer) => {
|
||||
const message = GroupUpdateMessage.deserializeBinary(new Uint8Array(buffer));
|
||||
const position = message.getPosition();
|
||||
if (position === undefined) {
|
||||
throw new Error('Missing position in GROUP_CREATE_UPDATE');
|
||||
}
|
||||
|
||||
const groupCreateUpdateMessage: GroupCreatedUpdatedMessageInterface = {
|
||||
groupId: message.getGroupid(),
|
||||
position: position.toObject()
|
||||
}
|
||||
|
||||
callback(groupCreateUpdateMessage);
|
||||
});
|
||||
}
|
||||
|
||||
public onGroupDeleted(callback: (groupId: string) => void): void {
|
||||
public onGroupDeleted(callback: (groupId: number) => void): void {
|
||||
this.socket.on(EventMessage.GROUP_DELETE, callback)
|
||||
}
|
||||
|
||||
|
|
|
@ -80,7 +80,7 @@ interface GroupCreatedUpdatedEventInterface {
|
|||
|
||||
interface DeleteGroupEventInterface {
|
||||
type: 'DeleteGroupEvent'
|
||||
groupId: string
|
||||
groupId: number
|
||||
}
|
||||
|
||||
export class GameScene extends Phaser.Scene implements CenterListener {
|
||||
|
@ -93,7 +93,7 @@ export class GameScene extends Phaser.Scene implements CenterListener {
|
|||
Layers!: Array<Phaser.Tilemaps.StaticTilemapLayer>;
|
||||
Objects!: Array<Phaser.Physics.Arcade.Sprite>;
|
||||
mapFile!: ITiledMap;
|
||||
groups: Map<string, Sprite>;
|
||||
groups: Map<number, Sprite>;
|
||||
startX!: number;
|
||||
startY!: number;
|
||||
circleTexture!: CanvasTexture;
|
||||
|
@ -149,7 +149,7 @@ export class GameScene extends Phaser.Scene implements CenterListener {
|
|||
|
||||
this.GameManager = gameManager;
|
||||
this.Terrains = [];
|
||||
this.groups = new Map<string, Sprite>();
|
||||
this.groups = new Map<number, Sprite>();
|
||||
this.instance = instance;
|
||||
|
||||
this.MapKey = MapKey;
|
||||
|
@ -237,7 +237,7 @@ export class GameScene extends Phaser.Scene implements CenterListener {
|
|||
this.shareGroupPosition(groupPositionMessage);
|
||||
})
|
||||
|
||||
connection.onGroupDeleted((groupId: string) => {
|
||||
connection.onGroupDeleted((groupId: number) => {
|
||||
try {
|
||||
this.deleteGroup(groupId);
|
||||
} catch (e) {
|
||||
|
@ -1108,14 +1108,14 @@ export class GameScene extends Phaser.Scene implements CenterListener {
|
|||
}
|
||||
}
|
||||
|
||||
deleteGroup(groupId: string): void {
|
||||
deleteGroup(groupId: number): void {
|
||||
this.pendingEvents.enqueue({
|
||||
type: "DeleteGroupEvent",
|
||||
groupId
|
||||
});
|
||||
}
|
||||
|
||||
doDeleteGroup(groupId: string): void {
|
||||
doDeleteGroup(groupId: number): void {
|
||||
const group = this.groups.get(groupId);
|
||||
if(!group){
|
||||
return;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue