Merge pull request #2005 from thecodingmachine/proto-well-known-types

make use of proto well knows types
This commit is contained in:
David Négrier 2022-03-29 14:40:53 +02:00 committed by GitHub
commit c177173688
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 19 additions and 12 deletions

View File

@ -1,5 +1,5 @@
import { Subject } from "rxjs";
import type { BanUserMessage, SendUserMessage } from "../Messages/ts-proto-generated/messages";
import type { BanUserMessage, SendUserMessage } from "../Messages/ts-proto-generated/protos/messages";
export enum AdminMessageEventTypes {
admin = "message",

View File

@ -43,8 +43,8 @@ export interface PositionInterface {
export interface GroupCreatedUpdatedMessageInterface {
position: PositionInterface;
groupId: number;
groupSize: number;
locked: boolean;
groupSize?: number;
locked?: boolean;
}
export interface GroupUsersUpdateMessageInterface {

View File

@ -41,7 +41,7 @@ import {
SetPlayerDetailsMessage as SetPlayerDetailsMessageTsProto,
PingMessage as PingMessageTsProto,
CharacterLayerMessage,
} from "../Messages/ts-proto-generated/messages";
} from "../Messages/ts-proto-generated/protos/messages";
import { Subject } from "rxjs";
import { selectCharacterSceneVisibleStore } from "../Stores/SelectCharacterStore";
import { gameManager } from "../Phaser/Game/GameManager";

View File

@ -1,4 +1,4 @@
import { PositionMessage, PositionMessage_Direction } from "../Messages/ts-proto-generated/messages";
import { PositionMessage, PositionMessage_Direction } from "../Messages/ts-proto-generated/protos/messages";
import type { PointInterface } from "../Connexion/ConnexionModels";

View File

@ -6,7 +6,7 @@
"proto": "grpc_tools_node_protoc --plugin=protoc-gen-ts=./node_modules/.bin/protoc-gen-ts --grpc_out=generated --js_out=\"import_style=commonjs,binary:generated\" --ts_out=generated -I ./protos protos/*.proto",
"ts-proto": "grpc_tools_node_protoc --plugin=./node_modules/.bin/protoc-gen-ts_proto --ts_proto_out=ts-proto-generated --ts_proto_opt=oneof=unions --ts_proto_opt=esModuleInterop=true protos/*.proto",
"copy-to-back": "rm -rf ../back/src/Messages/generated && cp -rf generated/ ../back/src/Messages/generated",
"copy-to-front-ts-proto": "sed 's/import { Observable } from \"rxjs\";/import type { Observable } from \"rxjs\";/g' ts-proto-generated/protos/messages.ts > ../front/src/Messages/ts-proto-generated/messages.ts",
"copy-to-front-ts-proto": "cp -rf ts-proto-generated/* ../front/src/Messages/ts-proto-generated/ && sed -i 's/import { Observable } from \"rxjs\";/import type { Observable } from \"rxjs\";/g' ../front/src/Messages/ts-proto-generated/protos/messages.ts",
"copy-to-pusher": "rm -rf ../pusher/src/Messages/generated && cp -rf generated/ ../pusher/src/Messages/generated",
"json-copy-to-pusher": "rm -rf ../pusher/src/Messages/JsonMessages/* && cp -rf JsonMessages/* ../pusher/src/Messages/JsonMessages/",
"json-copy-to-back": "rm -rf ../back/src/Messages/JsonMessages/* && cp -rf JsonMessages/* ../back/src/Messages/JsonMessages/",

View File

@ -1,5 +1,7 @@
syntax = "proto3";
import "google/protobuf/wrappers.proto";
/*********** PARTIAL MESSAGES **************/
message PositionMessage {
@ -189,8 +191,8 @@ message BatchMessage {
message GroupUpdateMessage {
int32 groupId = 1;
PointMessage position = 2;
int32 groupSize = 3;
bool locked = 4;
google.protobuf.UInt32Value groupSize = 3;
google.protobuf.BoolValue locked = 4;
}
message GroupDeleteMessage {

View File

@ -22,6 +22,7 @@ import {
import { ClientReadableStream } from "grpc";
import { PositionDispatcher } from "_Model/PositionDispatcher";
import Debug from "debug";
import { BoolValue, UInt32Value } from "google-protobuf/google/protobuf/wrappers_pb";
const debug = Debug("zone");
@ -125,9 +126,9 @@ export class UserDescriptor {
export class GroupDescriptor {
private constructor(
public readonly groupId: number,
private groupSize: number,
private groupSize: number | undefined,
private position: PointMessage,
private locked: boolean
private locked: boolean | undefined
) {}
public static createFromGroupUpdateZoneMessage(message: GroupUpdateZoneMessage): GroupDescriptor {
@ -150,9 +151,13 @@ export class GroupDescriptor {
throw new Error("GroupDescriptor.groupId is not an integer: " + this.groupId);
}
groupUpdateMessage.setGroupid(this.groupId);
groupUpdateMessage.setGroupsize(this.groupSize);
if (this.groupSize !== undefined) {
groupUpdateMessage.setGroupsize(new UInt32Value().setValue(this.groupSize));
}
groupUpdateMessage.setPosition(this.position);
groupUpdateMessage.setLocked(this.locked);
if (this.locked !== undefined) {
groupUpdateMessage.setLocked(new BoolValue().setValue(this.locked));
}
return groupUpdateMessage;
}
}