change away to availability status

This commit is contained in:
Piotr 'pwh' Hanusiak 2022-04-14 11:03:58 +02:00
parent 45e254b931
commit 8f0b02a9c8
12 changed files with 60 additions and 50 deletions

View File

@ -146,7 +146,7 @@ export class GameRoom {
position, position,
false, false,
this.positionNotifier, this.positionNotifier,
joinRoomMessage.getAway(), joinRoomMessage.getStatus(),
socket, socket,
joinRoomMessage.getTagList(), joinRoomMessage.getTagList(),
joinRoomMessage.getVisitcardurl(), joinRoomMessage.getVisitcardurl(),

View File

@ -5,6 +5,7 @@ import { Movable } from "../Model/Movable";
import { PositionNotifier } from "../Model/PositionNotifier"; import { PositionNotifier } from "../Model/PositionNotifier";
import { ServerDuplexStream } from "grpc"; import { ServerDuplexStream } from "grpc";
import { import {
AvailabilityStatus,
BatchMessage, BatchMessage,
CompanionMessage, CompanionMessage,
FollowAbortMessage, FollowAbortMessage,
@ -32,7 +33,7 @@ export class User implements Movable {
private position: PointInterface, private position: PointInterface,
public silent: boolean, public silent: boolean,
private positionNotifier: PositionNotifier, private positionNotifier: PositionNotifier,
private away: boolean, private status: AvailabilityStatus,
public readonly socket: UserSocket, public readonly socket: UserSocket,
public readonly tags: string[], public readonly tags: string[],
public readonly visitCardUrl: string | null, public readonly visitCardUrl: string | null,
@ -90,8 +91,8 @@ export class User implements Movable {
return this.outlineColor; return this.outlineColor;
} }
public isAway(): boolean { public getStatus(): AvailabilityStatus {
return this.away; return this.status;
} }
get following(): User | undefined { get following(): User | undefined {
@ -134,9 +135,9 @@ export class User implements Movable {
} }
this.voiceIndicatorShown = details.getShowvoiceindicator()?.getValue(); this.voiceIndicatorShown = details.getShowvoiceindicator()?.getValue();
const away = details.getAway(); const status = details.getStatus();
if (away) { if (status !== undefined) {
this.away = away.getValue(); this.status = status;
} }
const playerDetails = new SetPlayerDetailsMessage(); const playerDetails = new SetPlayerDetailsMessage();
@ -147,8 +148,8 @@ export class User implements Movable {
if (this.voiceIndicatorShown !== undefined) { if (this.voiceIndicatorShown !== undefined) {
playerDetails.setShowvoiceindicator(new BoolValue().setValue(this.voiceIndicatorShown)); playerDetails.setShowvoiceindicator(new BoolValue().setValue(this.voiceIndicatorShown));
} }
if (details.getAway() !== undefined) { if (details.getStatus() !== undefined) {
playerDetails.setAway(new BoolValue().setValue(this.away)); playerDetails.setStatus(details.getStatus());
} }
this.positionNotifier.updatePlayerDetails(this, playerDetails); this.positionNotifier.updatePlayerDetails(this, playerDetails);

View File

@ -328,7 +328,7 @@ export class SocketManager {
userJoinedZoneMessage.setUserid(thing.id); userJoinedZoneMessage.setUserid(thing.id);
userJoinedZoneMessage.setUseruuid(thing.uuid); userJoinedZoneMessage.setUseruuid(thing.uuid);
userJoinedZoneMessage.setName(thing.name); userJoinedZoneMessage.setName(thing.name);
userJoinedZoneMessage.setAway(thing.isAway()); userJoinedZoneMessage.setStatus(thing.getStatus());
userJoinedZoneMessage.setCharacterlayersList(ProtobufUtils.toCharacterLayerMessages(thing.characterLayers)); userJoinedZoneMessage.setCharacterlayersList(ProtobufUtils.toCharacterLayerMessages(thing.characterLayers));
userJoinedZoneMessage.setPosition(ProtobufUtils.toPositionMessage(thing.getPosition())); userJoinedZoneMessage.setPosition(ProtobufUtils.toPositionMessage(thing.getPosition()));
userJoinedZoneMessage.setFromzone(this.toProtoZone(fromZone)); userJoinedZoneMessage.setFromzone(this.toProtoZone(fromZone));
@ -656,7 +656,7 @@ export class SocketManager {
userJoinedMessage.setUserid(thing.id); userJoinedMessage.setUserid(thing.id);
userJoinedMessage.setUseruuid(thing.uuid); userJoinedMessage.setUseruuid(thing.uuid);
userJoinedMessage.setName(thing.name); userJoinedMessage.setName(thing.name);
userJoinedMessage.setAway(thing.isAway()); userJoinedMessage.setStatus(thing.getStatus());
userJoinedMessage.setCharacterlayersList(ProtobufUtils.toCharacterLayerMessages(thing.characterLayers)); userJoinedMessage.setCharacterlayersList(ProtobufUtils.toCharacterLayerMessages(thing.characterLayers));
userJoinedMessage.setPosition(ProtobufUtils.toPositionMessage(thing.getPosition())); userJoinedMessage.setPosition(ProtobufUtils.toPositionMessage(thing.getPosition()));
if (thing.visitCardUrl) { if (thing.visitCardUrl) {

View File

@ -1,6 +1,7 @@
import type { SignalData } from "simple-peer"; import type { SignalData } from "simple-peer";
import type { RoomConnection } from "./RoomConnection"; import type { RoomConnection } from "./RoomConnection";
import type { BodyResourceDescriptionInterface } from "../Phaser/Entity/PlayerTextures"; import type { BodyResourceDescriptionInterface } from "../Phaser/Entity/PlayerTextures";
import { AvailabilityStatus } from "../Messages/ts-proto-generated/protos/messages";
export interface PointInterface { export interface PointInterface {
x: number; x: number;
@ -14,7 +15,7 @@ export interface MessageUserPositionInterface {
name: string; name: string;
characterLayers: BodyResourceDescriptionInterface[]; characterLayers: BodyResourceDescriptionInterface[];
position: PointInterface; position: PointInterface;
away: boolean; status: AvailabilityStatus;
visitCardUrl: string | null; visitCardUrl: string | null;
companion: string | null; companion: string | null;
userUuid: string; userUuid: string;
@ -30,7 +31,7 @@ export interface MessageUserJoined {
name: string; name: string;
characterLayers: BodyResourceDescriptionInterface[]; characterLayers: BodyResourceDescriptionInterface[];
position: PointInterface; position: PointInterface;
away: boolean; status: AvailabilityStatus;
visitCardUrl: string | null; visitCardUrl: string | null;
companion: string | null; companion: string | null;
userUuid: string; userUuid: string;

View File

@ -41,6 +41,7 @@ import {
SetPlayerDetailsMessage as SetPlayerDetailsMessageTsProto, SetPlayerDetailsMessage as SetPlayerDetailsMessageTsProto,
PingMessage as PingMessageTsProto, PingMessage as PingMessageTsProto,
CharacterLayerMessage, CharacterLayerMessage,
AvailabilityStatus,
} from "../Messages/ts-proto-generated/protos/messages"; } from "../Messages/ts-proto-generated/protos/messages";
import { Subject } from "rxjs"; import { Subject } from "rxjs";
import { selectCharacterSceneVisibleStore } from "../Stores/SelectCharacterStore"; import { selectCharacterSceneVisibleStore } from "../Stores/SelectCharacterStore";
@ -520,9 +521,9 @@ export class RoomConnection implements RoomConnection {
this.socket.send(bytes); this.socket.send(bytes);
} }
public emitPlayerAway(away: boolean): void { public emitPlayerStatusChange(status: AvailabilityStatus): void {
const message = SetPlayerDetailsMessageTsProto.fromPartial({ const message = SetPlayerDetailsMessageTsProto.fromPartial({
away, status,
}); });
const bytes = ClientToServerMessageTsProto.encode({ const bytes = ClientToServerMessageTsProto.encode({
message: { message: {
@ -670,7 +671,7 @@ export class RoomConnection implements RoomConnection {
characterLayers, characterLayers,
visitCardUrl: message.visitCardUrl, visitCardUrl: message.visitCardUrl,
position: ProtobufClientUtils.toPointInterface(position), position: ProtobufClientUtils.toPointInterface(position),
away: message.away, status: message.status,
companion: companion ? companion.name : null, companion: companion ? companion.name : null,
userUuid: message.userUuid, userUuid: message.userUuid,
outlineColor: message.hasOutline ? message.outlineColor : undefined, outlineColor: message.hasOutline ? message.outlineColor : undefined,

View File

@ -1,16 +1,11 @@
import { AvailabilityStatus } from "../../Messages/ts-proto-generated/protos/messages";
import { Easing } from "../../types"; import { Easing } from "../../types";
export enum PlayerStatus {
Online = "Online",
Silenced = "Silenced",
Away = "Away",
}
export class PlayerStatusDot extends Phaser.GameObjects.Container { export class PlayerStatusDot extends Phaser.GameObjects.Container {
private statusImage: Phaser.GameObjects.Image; private statusImage: Phaser.GameObjects.Image;
private statusImageOutline: Phaser.GameObjects.Image; private statusImageOutline: Phaser.GameObjects.Image;
private status: PlayerStatus; private status: AvailabilityStatus;
private readonly COLORS = { private readonly COLORS = {
online: 0x8cc43f, online: 0x8cc43f,
@ -19,12 +14,13 @@ export class PlayerStatusDot extends Phaser.GameObjects.Container {
awayOutline: 0x875d13, awayOutline: 0x875d13,
silenced: 0xe74c3c, silenced: 0xe74c3c,
silencedOutline: 0xc0392b, silencedOutline: 0xc0392b,
never: 0xff00ff,
}; };
constructor(scene: Phaser.Scene, x: number, y: number) { constructor(scene: Phaser.Scene, x: number, y: number) {
super(scene, x, y); super(scene, x, y);
this.status = PlayerStatus.Online; this.status = AvailabilityStatus.ONLINE;
this.statusImage = this.scene.add.image(0, 0, "iconStatusIndicatorInside"); this.statusImage = this.scene.add.image(0, 0, "iconStatusIndicatorInside");
this.statusImageOutline = this.scene.add.image(0, 0, "iconStatusIndicatorOutline"); this.statusImageOutline = this.scene.add.image(0, 0, "iconStatusIndicatorOutline");
@ -36,7 +32,7 @@ export class PlayerStatusDot extends Phaser.GameObjects.Container {
this.scene.add.existing(this); this.scene.add.existing(this);
} }
public setStatus(status: PlayerStatus, instant: boolean = false): void { public setStatus(status: AvailabilityStatus, instant: boolean = false): void {
if (this.status === status) { if (this.status === status) {
return; return;
} }
@ -73,12 +69,14 @@ export class PlayerStatusDot extends Phaser.GameObjects.Container {
private getColors(): { filling: number; outline: number } { private getColors(): { filling: number; outline: number } {
switch (this.status) { switch (this.status) {
case PlayerStatus.Online: case AvailabilityStatus.ONLINE:
return { filling: this.COLORS.online, outline: this.COLORS.onlineOutline }; return { filling: this.COLORS.online, outline: this.COLORS.onlineOutline };
case PlayerStatus.Away: case AvailabilityStatus.AWAY:
return { filling: this.COLORS.away, outline: this.COLORS.awayOutline }; return { filling: this.COLORS.away, outline: this.COLORS.awayOutline };
case PlayerStatus.Silenced: case AvailabilityStatus.SILENCED:
return { filling: this.COLORS.silenced, outline: this.COLORS.silencedOutline }; return { filling: this.COLORS.silenced, outline: this.COLORS.silencedOutline };
default:
return { filling: this.COLORS.never, outline: this.COLORS.never };
} }
} }
} }

View File

@ -100,9 +100,8 @@ import type { CoWebsite } from "../../WebRtc/CoWebsite/CoWesbite";
import CancelablePromise from "cancelable-promise"; import CancelablePromise from "cancelable-promise";
import { Deferred } from "ts-deferred"; import { Deferred } from "ts-deferred";
import { SuperLoaderPlugin } from "../Services/SuperLoaderPlugin"; import { SuperLoaderPlugin } from "../Services/SuperLoaderPlugin";
import { PlayerDetailsUpdatedMessage } from "../../Messages/ts-proto-generated/protos/messages"; import { AvailabilityStatus, PlayerDetailsUpdatedMessage } from "../../Messages/ts-proto-generated/protos/messages";
import { privacyShutdownStore } from "../../Stores/PrivacyShutdownStore"; import { privacyShutdownStore } from "../../Stores/PrivacyShutdownStore";
import { PlayerStatus } from "../Components/PlayerStatusDot";
export interface GameSceneInitInterface { export interface GameSceneInitInterface {
initPosition: PointInterface | null; initPosition: PointInterface | null;
reconnecting: boolean; reconnecting: boolean;
@ -710,7 +709,8 @@ export class GameScene extends DirtyScene {
}); });
this.privacyShutdownStoreUnsubscribe = privacyShutdownStore.subscribe((away) => { this.privacyShutdownStoreUnsubscribe = privacyShutdownStore.subscribe((away) => {
this.connection?.emitPlayerAway(away); // TODO: Might be a problem with SILENCED here
this.connection?.emitPlayerStatusChange(away ? AvailabilityStatus.AWAY : AvailabilityStatus.ONLINE);
}); });
Promise.all([ Promise.all([
@ -771,7 +771,7 @@ export class GameScene extends DirtyScene {
characterLayers: message.characterLayers, characterLayers: message.characterLayers,
name: message.name, name: message.name,
position: message.position, position: message.position,
away: message.away, status: message.status,
visitCardUrl: message.visitCardUrl, visitCardUrl: message.visitCardUrl,
companion: message.companion, companion: message.companion,
userUuid: message.userUuid, userUuid: message.userUuid,
@ -1956,8 +1956,8 @@ ${escapedMessage}
if (addPlayerData.outlineColor !== undefined) { if (addPlayerData.outlineColor !== undefined) {
player.setApiOutlineColor(addPlayerData.outlineColor); player.setApiOutlineColor(addPlayerData.outlineColor);
} }
if (addPlayerData.away !== undefined) { if (addPlayerData.status !== undefined) {
player.setStatus(addPlayerData.away ? PlayerStatus.Away : PlayerStatus.Online, true); player.setStatus(addPlayerData.status, true);
} }
this.MapPlayers.add(player); this.MapPlayers.add(player);
this.MapPlayersByKey.set(player.userId, player); this.MapPlayersByKey.set(player.userId, player);
@ -2108,8 +2108,8 @@ ${escapedMessage}
if (message.details?.showVoiceIndicator !== undefined) { if (message.details?.showVoiceIndicator !== undefined) {
character.showTalkIcon(message.details?.showVoiceIndicator); character.showTalkIcon(message.details?.showVoiceIndicator);
} }
if (message.details?.away !== undefined) { if (message.details?.status !== undefined) {
character.setStatus(message.details?.away ? PlayerStatus.Away : PlayerStatus.Online); character.setStatus(message.details?.status);
} }
} }

View File

@ -1,3 +1,4 @@
import { AvailabilityStatus } from "../../Messages/ts-proto-generated/protos/messages";
import type { BodyResourceDescriptionInterface } from "../Entity/PlayerTextures"; import type { BodyResourceDescriptionInterface } from "../Entity/PlayerTextures";
export interface PlayerInterface { export interface PlayerInterface {
@ -7,7 +8,7 @@ export interface PlayerInterface {
visitCardUrl: string | null; visitCardUrl: string | null;
companion: string | null; companion: string | null;
userUuid: string; userUuid: string;
away: boolean; status: AvailabilityStatus;
color?: string; color?: string;
outlineColor?: number; outlineColor?: number;
} }

View File

@ -2,6 +2,7 @@ import { writable } from "svelte/store";
import type { PlayerInterface } from "../Phaser/Game/PlayerInterface"; import type { PlayerInterface } from "../Phaser/Game/PlayerInterface";
import type { RoomConnection } from "../Connexion/RoomConnection"; import type { RoomConnection } from "../Connexion/RoomConnection";
import { getRandomColor } from "../WebRtc/ColorGenerator"; import { getRandomColor } from "../WebRtc/ColorGenerator";
import { AvailabilityStatus } from "../Messages/ts-proto-generated/protos/messages";
let idCount = 0; let idCount = 0;
@ -28,7 +29,7 @@ function createPlayersStore() {
visitCardUrl: message.visitCardUrl, visitCardUrl: message.visitCardUrl,
companion: message.companion, companion: message.companion,
userUuid: message.userUuid, userUuid: message.userUuid,
away: message.away, status: message.status,
color: getRandomColor(), color: getRandomColor(),
}); });
return users; return users;
@ -58,7 +59,7 @@ function createPlayersStore() {
characterLayers: [], characterLayers: [],
visitCardUrl: null, visitCardUrl: null,
companion: null, companion: null,
away: false, status: AvailabilityStatus.ONLINE,
userUuid: "dummy", userUuid: "dummy",
color: getRandomColor(), color: getRandomColor(),
}); });

View File

@ -121,7 +121,7 @@
"rotation":0, "rotation":0,
"text": "text":
{ {
"text":"Get into silent zone to show status dot for your WOKA", "text":"Get into silent zone to show red status dot for your WOKA",
"wrap":true "wrap":true
}, },
"type":"", "type":"",

View File

@ -4,6 +4,12 @@ import "google/protobuf/wrappers.proto";
/*********** PARTIAL MESSAGES **************/ /*********** PARTIAL MESSAGES **************/
enum AvailabilityStatus {
ONLINE = 0;
SILENCED = 1;
AWAY = 2;
}
message PositionMessage { message PositionMessage {
int32 x = 1; int32 x = 1;
int32 y = 2; int32 y = 2;
@ -53,7 +59,7 @@ message SetPlayerDetailsMessage {
google.protobuf.UInt32Value outlineColor = 3; google.protobuf.UInt32Value outlineColor = 3;
google.protobuf.BoolValue removeOutlineColor = 4; google.protobuf.BoolValue removeOutlineColor = 4;
google.protobuf.BoolValue showVoiceIndicator = 5; google.protobuf.BoolValue showVoiceIndicator = 5;
google.protobuf.BoolValue away = 6; AvailabilityStatus status = 6;
} }
message UserMovesMessage { message UserMovesMessage {
@ -207,7 +213,7 @@ message UserJoinedMessage {
string userUuid = 7; string userUuid = 7;
uint32 outlineColor = 8; uint32 outlineColor = 8;
bool hasOutline = 9; bool hasOutline = 9;
bool away = 10; AvailabilityStatus status = 10;
} }
message UserLeftMessage { message UserLeftMessage {
@ -346,7 +352,7 @@ message JoinRoomMessage {
CompanionMessage companion = 8; CompanionMessage companion = 8;
string visitCardUrl = 9; string visitCardUrl = 9;
string userRoomToken = 10; string userRoomToken = 10;
bool away = 11; AvailabilityStatus status = 11;
} }
message UserJoinedZoneMessage { message UserJoinedZoneMessage {
@ -360,7 +366,7 @@ message UserJoinedZoneMessage {
string userUuid = 8; string userUuid = 8;
uint32 outlineColor = 9; uint32 outlineColor = 9;
bool hasOutline = 10; bool hasOutline = 10;
bool away = 11; AvailabilityStatus status = 11;
} }
message UserLeftZoneMessage { message UserLeftZoneMessage {

View File

@ -18,6 +18,7 @@ import {
ErrorMessage, ErrorMessage,
PlayerDetailsUpdatedMessage, PlayerDetailsUpdatedMessage,
SetPlayerDetailsMessage, SetPlayerDetailsMessage,
AvailabilityStatus,
} 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";
@ -49,7 +50,7 @@ export class UserDescriptor {
private name: string, private name: string,
private characterLayers: CharacterLayerMessage[], private characterLayers: CharacterLayerMessage[],
private position: PositionMessage, private position: PositionMessage,
private away: boolean, private status: AvailabilityStatus,
private visitCardUrl: string | null, private visitCardUrl: string | null,
private companion?: CompanionMessage, private companion?: CompanionMessage,
private outlineColor?: number private outlineColor?: number
@ -70,7 +71,7 @@ export class UserDescriptor {
message.getName(), message.getName(),
message.getCharacterlayersList(), message.getCharacterlayersList(),
position, position,
message.getAway(), message.getStatus(),
message.getVisitcardurl(), message.getVisitcardurl(),
message.getCompanion(), message.getCompanion(),
message.getHasoutline() ? message.getOutlinecolor() : undefined message.getHasoutline() ? message.getOutlinecolor() : undefined
@ -91,9 +92,9 @@ export class UserDescriptor {
} else { } else {
this.outlineColor = playerDetails.getOutlinecolor()?.getValue(); this.outlineColor = playerDetails.getOutlinecolor()?.getValue();
} }
const away = playerDetails.getAway(); const status = playerDetails.getStatus();
if (away) { if (status !== undefined) {
this.away = away.getValue(); this.status = status;
} }
} }
@ -104,7 +105,7 @@ export class UserDescriptor {
userJoinedMessage.setName(this.name); userJoinedMessage.setName(this.name);
userJoinedMessage.setCharacterlayersList(this.characterLayers); userJoinedMessage.setCharacterlayersList(this.characterLayers);
userJoinedMessage.setPosition(this.position); userJoinedMessage.setPosition(this.position);
userJoinedMessage.setAway(this.away); userJoinedMessage.setStatus(this.status);
if (this.visitCardUrl) { if (this.visitCardUrl) {
userJoinedMessage.setVisitcardurl(this.visitCardUrl); userJoinedMessage.setVisitcardurl(this.visitCardUrl);
} }