Merge branch 'develop' of github.com:thecodingmachine/workadventure into develop
This commit is contained in:
@@ -1,36 +1,41 @@
|
||||
import { AvailabilityStatus } from "../../Messages/ts-proto-generated/protos/messages";
|
||||
import { Easing } from "../../types";
|
||||
|
||||
export class PlayerStatusDot extends Phaser.GameObjects.Container {
|
||||
private graphics: Phaser.GameObjects.Graphics;
|
||||
private statusImage: Phaser.GameObjects.Image;
|
||||
private statusImageOutline: Phaser.GameObjects.Image;
|
||||
|
||||
private away: boolean;
|
||||
private status: AvailabilityStatus;
|
||||
|
||||
private readonly COLORS = {
|
||||
// online: 0x00ff00,
|
||||
// away: 0xffff00,
|
||||
online: 0x8cc43f,
|
||||
onlineOutline: 0x427a25,
|
||||
away: 0xf5931e,
|
||||
awayOutline: 0x875d13,
|
||||
private readonly COLORS: Record<AvailabilityStatus, { filling: number; outline: number }> = {
|
||||
[AvailabilityStatus.AWAY]: { filling: 0xf5931e, outline: 0x875d13 },
|
||||
[AvailabilityStatus.ONLINE]: { filling: 0x8cc43f, outline: 0x427a25 },
|
||||
[AvailabilityStatus.SILENT]: { filling: 0xe74c3c, outline: 0xc0392b },
|
||||
[AvailabilityStatus.JITSI]: { filling: 0x8cc43f, outline: 0x427a25 },
|
||||
[AvailabilityStatus.UNRECOGNIZED]: { filling: 0xffffff, outline: 0xffffff },
|
||||
[AvailabilityStatus.UNCHANGED]: { filling: 0xffffff, outline: 0xffffff },
|
||||
};
|
||||
|
||||
constructor(scene: Phaser.Scene, x: number, y: number) {
|
||||
super(scene, x, y);
|
||||
|
||||
this.away = false;
|
||||
this.status = AvailabilityStatus.ONLINE;
|
||||
|
||||
this.statusImage = this.scene.add.image(0, 0, "iconStatusIndicatorInside");
|
||||
this.statusImageOutline = this.scene.add.image(0, 0, "iconStatusIndicatorOutline");
|
||||
|
||||
this.add([this.statusImage, this.statusImageOutline]);
|
||||
|
||||
this.graphics = this.scene.add.graphics();
|
||||
this.add(this.graphics);
|
||||
this.redraw();
|
||||
|
||||
this.scene.add.existing(this);
|
||||
}
|
||||
|
||||
public setAway(away: boolean = true, instant: boolean = false): void {
|
||||
if (this.away === away) {
|
||||
public setStatus(status: AvailabilityStatus, instant: boolean = false): void {
|
||||
if (this.status === status || status === AvailabilityStatus.UNCHANGED) {
|
||||
return;
|
||||
}
|
||||
this.away = away;
|
||||
this.status = status;
|
||||
if (instant) {
|
||||
this.redraw();
|
||||
} else {
|
||||
@@ -56,10 +61,8 @@ export class PlayerStatusDot extends Phaser.GameObjects.Container {
|
||||
}
|
||||
|
||||
private redraw(): void {
|
||||
this.graphics.clear();
|
||||
this.graphics.fillStyle(this.away ? this.COLORS.away : this.COLORS.online);
|
||||
this.graphics.lineStyle(1, this.away ? this.COLORS.awayOutline : this.COLORS.onlineOutline);
|
||||
this.graphics.fillCircle(0, 0, 3);
|
||||
this.graphics.strokeCircle(0, 0, 3);
|
||||
const colors = this.COLORS[this.status];
|
||||
this.statusImage.setTintFill(colors.filling);
|
||||
this.statusImageOutline.setTintFill(colors.outline);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -9,7 +9,6 @@ import { Companion } from "../Companion/Companion";
|
||||
import type { GameScene } from "../Game/GameScene";
|
||||
import { DEPTH_INGAME_TEXT_INDEX } from "../Game/DepthIndexes";
|
||||
import type OutlinePipelinePlugin from "phaser3-rex-plugins/plugins/outlinepipeline-plugin.js";
|
||||
import { isSilentStore } from "../../Stores/MediaStore";
|
||||
import { lazyLoadPlayerCharacterTextures } from "./PlayerTexturesLoadingManager";
|
||||
import { TexturesHelper } from "../Helpers/TexturesHelper";
|
||||
import type { PictureStore } from "../../Stores/PictureStore";
|
||||
@@ -20,6 +19,7 @@ import type CancelablePromise from "cancelable-promise";
|
||||
import { TalkIcon } from "../Components/TalkIcon";
|
||||
import { Deferred } from "ts-deferred";
|
||||
import { PlayerStatusDot } from "../Components/PlayerStatusDot";
|
||||
import { AvailabilityStatus } from "../../Messages/ts-proto-generated/protos/messages";
|
||||
|
||||
const playerNameY = -25;
|
||||
const interactiveRadius = 35;
|
||||
@@ -236,8 +236,8 @@ export abstract class Character extends Container implements OutlineableInterfac
|
||||
this.talkIcon.show(show, forceClose);
|
||||
}
|
||||
|
||||
public setAwayStatus(away: boolean = true, instant: boolean = false): void {
|
||||
this.statusDot.setAway(away, instant);
|
||||
public setStatus(status: AvailabilityStatus, instant: boolean = false): void {
|
||||
this.statusDot.setStatus(status, instant);
|
||||
}
|
||||
|
||||
public addCompanion(name: string, texturePromise?: CancelablePromise<string>): void {
|
||||
@@ -355,13 +355,6 @@ export abstract class Character extends Container implements OutlineableInterfac
|
||||
super.destroy();
|
||||
}
|
||||
|
||||
isSilent() {
|
||||
isSilentStore.set(true);
|
||||
}
|
||||
noSilent() {
|
||||
isSilentStore.set(false);
|
||||
}
|
||||
|
||||
playEmote(emote: string) {
|
||||
this.cancelPreviousEmote();
|
||||
const emoteY = -45;
|
||||
|
||||
@@ -22,9 +22,9 @@ export type layerChangeCallback = (
|
||||
allLayersOnNewPosition: Array<ITiledMapLayer>
|
||||
) => void;
|
||||
|
||||
export type zoneChangeCallback = (
|
||||
zonesChangedByAction: Array<ITiledMapObject>,
|
||||
allZonesOnNewPosition: Array<ITiledMapObject>
|
||||
export type areaChangeCallback = (
|
||||
areasChangedByAction: Array<ITiledMapObject>,
|
||||
allAreasOnNewPosition: Array<ITiledMapObject>
|
||||
) => void;
|
||||
|
||||
/**
|
||||
@@ -54,8 +54,8 @@ export class GameMap {
|
||||
|
||||
private enterLayerCallbacks = Array<layerChangeCallback>();
|
||||
private leaveLayerCallbacks = Array<layerChangeCallback>();
|
||||
private enterZoneCallbacks = Array<zoneChangeCallback>();
|
||||
private leaveZoneCallbacks = Array<zoneChangeCallback>();
|
||||
private enterAreaCallbacks = Array<areaChangeCallback>();
|
||||
private leaveAreaCallbacks = Array<areaChangeCallback>();
|
||||
|
||||
private tileNameMap = new Map<string, number>();
|
||||
|
||||
@@ -63,7 +63,9 @@ export class GameMap {
|
||||
public readonly flatLayers: ITiledMapLayer[];
|
||||
public readonly tiledObjects: ITiledMapObject[];
|
||||
public readonly phaserLayers: TilemapLayer[] = [];
|
||||
public readonly zones: ITiledMapObject[] = [];
|
||||
public readonly areas: ITiledMapObject[] = [];
|
||||
|
||||
private readonly areasPositionOffsetY: number = 16;
|
||||
|
||||
public exitUrls: Array<string> = [];
|
||||
|
||||
@@ -76,7 +78,8 @@ export class GameMap {
|
||||
) {
|
||||
this.flatLayers = flattenGroupLayersMap(map);
|
||||
this.tiledObjects = this.getObjectsFromLayers(this.flatLayers);
|
||||
this.zones = this.tiledObjects.filter((object) => object.type === "zone");
|
||||
// NOTE: We leave "zone" for legacy reasons
|
||||
this.areas = this.tiledObjects.filter((object) => ["zone", "area"].includes(object.type));
|
||||
|
||||
let depth = -2;
|
||||
for (const layer of this.flatLayers) {
|
||||
@@ -148,7 +151,10 @@ export class GameMap {
|
||||
public setPosition(x: number, y: number) {
|
||||
this.oldPosition = this.position;
|
||||
this.position = { x, y };
|
||||
this.triggerZonesChange();
|
||||
const areasChanged = this.triggerAreasChange();
|
||||
if (areasChanged) {
|
||||
this.triggerAllProperties();
|
||||
}
|
||||
|
||||
this.oldKey = this.key;
|
||||
|
||||
@@ -201,21 +207,17 @@ export class GameMap {
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a callback called when the user moves inside another zone.
|
||||
*
|
||||
* @deprecated
|
||||
* Registers a callback called when the user moves inside another area.
|
||||
*/
|
||||
public onEnterZone(callback: zoneChangeCallback) {
|
||||
this.enterZoneCallbacks.push(callback);
|
||||
public onEnterArea(callback: areaChangeCallback) {
|
||||
this.enterAreaCallbacks.push(callback);
|
||||
}
|
||||
|
||||
/**
|
||||
* Registers a callback called when the user moves outside another zone.
|
||||
*
|
||||
* @deprecated
|
||||
* Registers a callback called when the user moves outside another area.
|
||||
*/
|
||||
public onLeaveZone(callback: zoneChangeCallback) {
|
||||
this.leaveZoneCallbacks.push(callback);
|
||||
public onLeaveArea(callback: areaChangeCallback) {
|
||||
this.leaveAreaCallbacks.push(callback);
|
||||
}
|
||||
|
||||
public findLayer(layerName: string): ITiledMapLayer | undefined {
|
||||
@@ -437,55 +439,56 @@ export class GameMap {
|
||||
}
|
||||
|
||||
/**
|
||||
* We use Tiled Objects with type "zone" as zones with defined x, y, width and height for easier event triggering.
|
||||
* We use Tiled Objects with type "area" as areas with defined x, y, width and height for easier event triggering.
|
||||
* @returns If there were any areas changes
|
||||
*/
|
||||
private triggerZonesChange(): void {
|
||||
const zonesByOldPosition = this.oldPosition
|
||||
? this.zones.filter((zone) => {
|
||||
if (!this.oldPosition) {
|
||||
return false;
|
||||
}
|
||||
return MathUtils.isOverlappingWithRectangle(this.oldPosition, zone);
|
||||
})
|
||||
: [];
|
||||
private triggerAreasChange(): boolean {
|
||||
const areasByOldPosition = this.getAreasOnPosition(this.oldPosition, this.areasPositionOffsetY);
|
||||
const areasByNewPosition = this.getAreasOnPosition(this.position, this.areasPositionOffsetY);
|
||||
|
||||
const zonesByNewPosition = this.position
|
||||
? this.zones.filter((zone) => {
|
||||
if (!this.position) {
|
||||
return false;
|
||||
}
|
||||
return MathUtils.isOverlappingWithRectangle(this.position, zone);
|
||||
})
|
||||
: [];
|
||||
const enterAreas = new Set(areasByNewPosition);
|
||||
const leaveAreas = new Set(areasByOldPosition);
|
||||
|
||||
const enterZones = new Set(zonesByNewPosition);
|
||||
const leaveZones = new Set(zonesByOldPosition);
|
||||
|
||||
enterZones.forEach((zone) => {
|
||||
if (leaveZones.has(zone)) {
|
||||
leaveZones.delete(zone);
|
||||
enterZones.delete(zone);
|
||||
enterAreas.forEach((area) => {
|
||||
if (leaveAreas.has(area)) {
|
||||
leaveAreas.delete(area);
|
||||
enterAreas.delete(area);
|
||||
}
|
||||
});
|
||||
|
||||
if (enterZones.size > 0) {
|
||||
const zonesArray = Array.from(enterZones);
|
||||
for (const callback of this.enterZoneCallbacks) {
|
||||
callback(zonesArray, zonesByNewPosition);
|
||||
let areasChange = false;
|
||||
if (enterAreas.size > 0) {
|
||||
const areasArray = Array.from(enterAreas);
|
||||
for (const callback of this.enterAreaCallbacks) {
|
||||
callback(areasArray, areasByNewPosition);
|
||||
}
|
||||
areasChange = true;
|
||||
}
|
||||
|
||||
if (leaveZones.size > 0) {
|
||||
const zonesArray = Array.from(leaveZones);
|
||||
for (const callback of this.leaveZoneCallbacks) {
|
||||
callback(zonesArray, zonesByNewPosition);
|
||||
if (leaveAreas.size > 0) {
|
||||
const areasArray = Array.from(leaveAreas);
|
||||
for (const callback of this.leaveAreaCallbacks) {
|
||||
callback(areasArray, areasByNewPosition);
|
||||
}
|
||||
areasChange = true;
|
||||
}
|
||||
return areasChange;
|
||||
}
|
||||
|
||||
private getProperties(key: number): Map<string, string | boolean | number> {
|
||||
const properties = new Map<string, string | boolean | number>();
|
||||
|
||||
for (const area of this.getAreasOnPosition(this.position, this.areasPositionOffsetY)) {
|
||||
if (area.properties !== undefined) {
|
||||
for (const property of area.properties) {
|
||||
if (property.value === undefined) {
|
||||
continue;
|
||||
}
|
||||
properties.set(property.name, property.value);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (const layer of this.flatLayers) {
|
||||
if (layer.type !== "tilelayer") {
|
||||
continue;
|
||||
@@ -524,6 +527,17 @@ export class GameMap {
|
||||
return properties;
|
||||
}
|
||||
|
||||
private getAreasOnPosition(position?: { x: number; y: number }, offsetY: number = 0): ITiledMapObject[] {
|
||||
return position
|
||||
? this.areas.filter((area) => {
|
||||
if (!position) {
|
||||
return false;
|
||||
}
|
||||
return MathUtils.isOverlappingWithRectangle({ x: position.x, y: position.y + offsetY }, area);
|
||||
})
|
||||
: [];
|
||||
}
|
||||
|
||||
private getTileProperty(index: number): Array<ITiledMapProperty> {
|
||||
if (this.tileSetPropertyMap[index]) {
|
||||
return this.tileSetPropertyMap[index];
|
||||
|
||||
@@ -7,6 +7,7 @@ export enum GameMapProperties {
|
||||
EXIT_URL = "exitUrl",
|
||||
EXIT_SCENE_URL = "exitSceneUrl",
|
||||
FONT_FAMILY = "font-family",
|
||||
FOCUSABLE = "focusable",
|
||||
JITSI_ADMIN_ROOM_TAG = "jitsiRoomAdminTag",
|
||||
JITSI_CONFIG = "jitsiConfig",
|
||||
JITSI_INTERFACE_CONFIG = "jitsiInterfaceConfig",
|
||||
@@ -15,6 +16,7 @@ export enum GameMapProperties {
|
||||
JITSI_TRIGGER_MESSAGE = "jitsiTriggerMessage",
|
||||
JITSI_URL = "jitsiUrl",
|
||||
JITSI_WIDTH = "jitsiWidth",
|
||||
JITSI_NO_PREFIX = "jitsiNoPrefix",
|
||||
NAME = "name",
|
||||
OPEN_TAB = "openTab",
|
||||
OPEN_WEBSITE = "openWebsite",
|
||||
@@ -36,4 +38,5 @@ export enum GameMapProperties {
|
||||
URL = "url",
|
||||
WRITABLE_BY = "writableBy",
|
||||
ZONE = "zone",
|
||||
ZOOM_MARGIN = "zoom_margin",
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import { layoutManagerActionStore } from "../../Stores/LayoutManagerStore";
|
||||
import { localUserStore } from "../../Connexion/LocalUserStore";
|
||||
import { get } from "svelte/store";
|
||||
import { ON_ACTION_TRIGGER_BUTTON, ON_ICON_TRIGGER_BUTTON } from "../../WebRtc/LayoutManager";
|
||||
import type { ITiledMapLayer } from "../Map/ITiledMap";
|
||||
import type { ITiledMapProperty } from "../Map/ITiledMap";
|
||||
import { GameMapProperties } from "./GameMapProperties";
|
||||
import type { CoWebsite } from "../../WebRtc/CoWebsite/CoWesbite";
|
||||
import { SimpleCoWebsite } from "../../WebRtc/CoWebsite/SimpleCoWebsite";
|
||||
@@ -17,15 +17,28 @@ import { audioManagerFileStore, audioManagerVisibilityStore } from "../../Stores
|
||||
import { iframeListener } from "../../Api/IframeListener";
|
||||
import { Room } from "../../Connexion/Room";
|
||||
import LL from "../../i18n/i18n-svelte";
|
||||
import { inJitsiStore, silentStore } from "../../Stores/MediaStore";
|
||||
|
||||
interface OpenCoWebsite {
|
||||
actionId: string;
|
||||
coWebsite?: CoWebsite;
|
||||
}
|
||||
|
||||
/**
|
||||
* Either Layer or Object within Objects Layer in Tiled
|
||||
*/
|
||||
export interface ITiledPlace {
|
||||
name: string;
|
||||
properties?: ITiledMapProperty[];
|
||||
x?: number;
|
||||
y?: number;
|
||||
width?: number;
|
||||
height?: number;
|
||||
}
|
||||
|
||||
export class GameMapPropertiesListener {
|
||||
private coWebsitesOpenByLayer = new Map<ITiledMapLayer, OpenCoWebsite>();
|
||||
private coWebsitesActionTriggerByLayer = new Map<ITiledMapLayer, string>();
|
||||
private coWebsitesOpenByPlace = new Map<ITiledPlace, OpenCoWebsite>();
|
||||
private coWebsitesActionTriggerByPlace = new Map<ITiledPlace, string>();
|
||||
|
||||
constructor(private scene: GameScene, private gameMap: GameMap) {}
|
||||
|
||||
@@ -65,9 +78,14 @@ export class GameMapPropertiesListener {
|
||||
coWebsiteManager.closeCoWebsite(coWebsite);
|
||||
}
|
||||
});
|
||||
inJitsiStore.set(false);
|
||||
} else {
|
||||
const openJitsiRoomFunction = () => {
|
||||
const roomName = jitsiFactory.getRoomName(newValue.toString(), this.scene.instance);
|
||||
let addPrefix = true;
|
||||
if (allProps.get(GameMapProperties.JITSI_NO_PREFIX)) {
|
||||
addPrefix = false;
|
||||
}
|
||||
const roomName = jitsiFactory.getRoomName(newValue.toString(), this.scene.roomUrl, addPrefix);
|
||||
const jitsiUrl = allProps.get(GameMapProperties.JITSI_URL) as string | undefined;
|
||||
|
||||
if (JITSI_PRIVATE_MODE && !jitsiUrl) {
|
||||
@@ -103,11 +121,15 @@ export class GameMapPropertiesListener {
|
||||
uuid: "jitsi",
|
||||
type: "message",
|
||||
message: message,
|
||||
callback: () => openJitsiRoomFunction(),
|
||||
callback: () => {
|
||||
openJitsiRoomFunction();
|
||||
inJitsiStore.set(true);
|
||||
},
|
||||
userInputManager: this.scene.userInputManager,
|
||||
});
|
||||
} else {
|
||||
openJitsiRoomFunction();
|
||||
inJitsiStore.set(true);
|
||||
}
|
||||
}
|
||||
});
|
||||
@@ -144,11 +166,9 @@ export class GameMapPropertiesListener {
|
||||
|
||||
this.gameMap.onPropertyChange(GameMapProperties.SILENT, (newValue) => {
|
||||
if (newValue === undefined || newValue === false || newValue === "") {
|
||||
this.scene.connection?.setSilent(false);
|
||||
this.scene.CurrentPlayer.noSilent();
|
||||
silentStore.set(false);
|
||||
} else {
|
||||
this.scene.connection?.setSilent(true);
|
||||
this.scene.CurrentPlayer.isSilent();
|
||||
silentStore.set(true);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -179,199 +199,247 @@ export class GameMapPropertiesListener {
|
||||
}
|
||||
});
|
||||
|
||||
// Open a new co-website by the property.
|
||||
this.gameMap.onEnterLayer((newLayers) => {
|
||||
const handler = () => {
|
||||
newLayers.forEach((layer) => {
|
||||
if (!layer.properties) {
|
||||
return;
|
||||
}
|
||||
|
||||
let openWebsiteProperty: string | undefined;
|
||||
let allowApiProperty: boolean | undefined;
|
||||
let websitePolicyProperty: string | undefined;
|
||||
let websiteWidthProperty: number | undefined;
|
||||
let websitePositionProperty: number | undefined;
|
||||
let websiteTriggerProperty: string | undefined;
|
||||
let websiteTriggerMessageProperty: string | undefined;
|
||||
let websiteHintProperty: string | undefined;
|
||||
|
||||
layer.properties.forEach((property) => {
|
||||
switch (property.name) {
|
||||
case GameMapProperties.OPEN_WEBSITE:
|
||||
openWebsiteProperty = property.value as string | undefined;
|
||||
break;
|
||||
case GameMapProperties.OPEN_WEBSITE_ALLOW_API:
|
||||
allowApiProperty = property.value as boolean | undefined;
|
||||
break;
|
||||
case GameMapProperties.OPEN_WEBSITE_POLICY:
|
||||
websitePolicyProperty = property.value as string | undefined;
|
||||
break;
|
||||
case GameMapProperties.OPEN_WEBSITE_WIDTH:
|
||||
websiteWidthProperty = property.value as number | undefined;
|
||||
break;
|
||||
case GameMapProperties.OPEN_WEBSITE_POSITION:
|
||||
websitePositionProperty = property.value as number | undefined;
|
||||
break;
|
||||
case GameMapProperties.OPEN_WEBSITE_TRIGGER:
|
||||
websiteTriggerProperty = property.value as string | undefined;
|
||||
break;
|
||||
case GameMapProperties.OPEN_WEBSITE_TRIGGER_MESSAGE:
|
||||
websiteTriggerMessageProperty = property.value as string | undefined;
|
||||
break;
|
||||
case GameMapProperties.OPEN_WEBSITE_HINT:
|
||||
websiteHintProperty = property.value as string | undefined;
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
if (!openWebsiteProperty) {
|
||||
return;
|
||||
}
|
||||
|
||||
const actionId = "openWebsite-" + (Math.random() + 1).toString(36).substring(7);
|
||||
|
||||
if (this.coWebsitesOpenByLayer.has(layer)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const coWebsiteOpen: OpenCoWebsite = {
|
||||
actionId: actionId,
|
||||
};
|
||||
|
||||
this.coWebsitesOpenByLayer.set(layer, coWebsiteOpen);
|
||||
|
||||
const loadCoWebsiteFunction = (coWebsite: CoWebsite) => {
|
||||
coWebsiteManager.loadCoWebsite(coWebsite).catch(() => {
|
||||
console.error("Error during loading a co-website: " + coWebsite.getUrl());
|
||||
});
|
||||
|
||||
layoutManagerActionStore.removeAction(actionId);
|
||||
};
|
||||
|
||||
const openCoWebsiteFunction = () => {
|
||||
const coWebsite = new SimpleCoWebsite(
|
||||
new URL(openWebsiteProperty ?? "", this.scene.MapUrlFile),
|
||||
allowApiProperty,
|
||||
websitePolicyProperty,
|
||||
websiteWidthProperty,
|
||||
false,
|
||||
websiteHintProperty
|
||||
);
|
||||
|
||||
coWebsiteOpen.coWebsite = coWebsite;
|
||||
|
||||
coWebsiteManager.addCoWebsiteToStore(coWebsite, websitePositionProperty);
|
||||
|
||||
loadCoWebsiteFunction(coWebsite);
|
||||
};
|
||||
|
||||
if (
|
||||
localUserStore.getForceCowebsiteTrigger() ||
|
||||
websiteTriggerProperty === ON_ACTION_TRIGGER_BUTTON
|
||||
) {
|
||||
if (!websiteTriggerMessageProperty) {
|
||||
websiteTriggerMessageProperty = get(LL).trigger.cowebsite();
|
||||
}
|
||||
|
||||
this.coWebsitesActionTriggerByLayer.set(layer, actionId);
|
||||
|
||||
layoutManagerActionStore.addAction({
|
||||
uuid: actionId,
|
||||
type: "message",
|
||||
message: websiteTriggerMessageProperty,
|
||||
callback: () => openCoWebsiteFunction(),
|
||||
userInputManager: this.scene.userInputManager,
|
||||
});
|
||||
} else if (websiteTriggerProperty === ON_ICON_TRIGGER_BUTTON) {
|
||||
const coWebsite = new SimpleCoWebsite(
|
||||
new URL(openWebsiteProperty ?? "", this.scene.MapUrlFile),
|
||||
allowApiProperty,
|
||||
websitePolicyProperty,
|
||||
websiteWidthProperty,
|
||||
false,
|
||||
websiteHintProperty
|
||||
);
|
||||
|
||||
coWebsiteOpen.coWebsite = coWebsite;
|
||||
|
||||
coWebsiteManager.addCoWebsiteToStore(coWebsite, websitePositionProperty);
|
||||
}
|
||||
|
||||
if (!websiteTriggerProperty) {
|
||||
openCoWebsiteFunction();
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
handler();
|
||||
this.onEnterPlaceHandler(newLayers);
|
||||
});
|
||||
|
||||
// Close opened co-websites on leave the layer who contain the property.
|
||||
this.gameMap.onLeaveLayer((oldLayers) => {
|
||||
const handler = () => {
|
||||
oldLayers.forEach((layer) => {
|
||||
if (!layer.properties) {
|
||||
return;
|
||||
}
|
||||
this.onLeavePlaceHandler(oldLayers);
|
||||
});
|
||||
|
||||
let openWebsiteProperty: string | undefined;
|
||||
let websiteTriggerProperty: string | undefined;
|
||||
this.gameMap.onEnterArea((newAreas) => {
|
||||
this.onEnterPlaceHandler(newAreas);
|
||||
});
|
||||
|
||||
layer.properties.forEach((property) => {
|
||||
switch (property.name) {
|
||||
case GameMapProperties.OPEN_WEBSITE:
|
||||
openWebsiteProperty = property.value as string | undefined;
|
||||
break;
|
||||
case GameMapProperties.OPEN_WEBSITE_TRIGGER:
|
||||
websiteTriggerProperty = property.value as string | undefined;
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
if (!openWebsiteProperty) {
|
||||
return;
|
||||
}
|
||||
|
||||
const coWebsiteOpen = this.coWebsitesOpenByLayer.get(layer);
|
||||
|
||||
if (!coWebsiteOpen) {
|
||||
return;
|
||||
}
|
||||
|
||||
const coWebsite = coWebsiteOpen.coWebsite;
|
||||
|
||||
if (coWebsite) {
|
||||
coWebsiteManager.closeCoWebsite(coWebsite);
|
||||
}
|
||||
|
||||
this.coWebsitesOpenByLayer.delete(layer);
|
||||
|
||||
if (!websiteTriggerProperty) {
|
||||
return;
|
||||
}
|
||||
|
||||
const actionStore = get(layoutManagerActionStore);
|
||||
const actionTriggerUuid = this.coWebsitesActionTriggerByLayer.get(layer);
|
||||
|
||||
if (!actionTriggerUuid) {
|
||||
return;
|
||||
}
|
||||
|
||||
const action =
|
||||
actionStore && actionStore.length > 0
|
||||
? actionStore.find((action) => action.uuid === actionTriggerUuid)
|
||||
: undefined;
|
||||
|
||||
if (action) {
|
||||
layoutManagerActionStore.removeAction(actionTriggerUuid);
|
||||
}
|
||||
|
||||
this.coWebsitesActionTriggerByLayer.delete(layer);
|
||||
});
|
||||
};
|
||||
|
||||
handler();
|
||||
this.gameMap.onLeaveArea((oldAreas) => {
|
||||
this.onLeavePlaceHandler(oldAreas);
|
||||
});
|
||||
}
|
||||
|
||||
private onEnterPlaceHandler(places: ITiledPlace[]): void {
|
||||
places.forEach((place) => {
|
||||
this.handleOpenWebsitePropertiesOnEnter(place);
|
||||
this.handleFocusablePropertiesOnEnter(place);
|
||||
});
|
||||
}
|
||||
|
||||
private onLeavePlaceHandler(places: ITiledPlace[]): void {
|
||||
places.forEach((place) => {
|
||||
if (!place.properties) {
|
||||
return;
|
||||
}
|
||||
|
||||
this.handleOpenWebsitePropertiesOnLeave(place);
|
||||
this.handleFocusablePropertiesOnLeave(place);
|
||||
});
|
||||
}
|
||||
|
||||
private handleOpenWebsitePropertiesOnEnter(place: ITiledPlace): void {
|
||||
if (!place.properties) {
|
||||
return;
|
||||
}
|
||||
let openWebsiteProperty: string | undefined;
|
||||
let allowApiProperty: boolean | undefined;
|
||||
let websitePolicyProperty: string | undefined;
|
||||
let websiteWidthProperty: number | undefined;
|
||||
let websitePositionProperty: number | undefined;
|
||||
let websiteTriggerProperty: string | undefined;
|
||||
let websiteTriggerMessageProperty: string | undefined;
|
||||
let websiteHintProperty: string | undefined;
|
||||
|
||||
place.properties.forEach((property) => {
|
||||
switch (property.name) {
|
||||
case GameMapProperties.OPEN_WEBSITE:
|
||||
openWebsiteProperty = property.value as string | undefined;
|
||||
break;
|
||||
case GameMapProperties.OPEN_WEBSITE_ALLOW_API:
|
||||
allowApiProperty = property.value as boolean | undefined;
|
||||
break;
|
||||
case GameMapProperties.OPEN_WEBSITE_POLICY:
|
||||
websitePolicyProperty = property.value as string | undefined;
|
||||
break;
|
||||
case GameMapProperties.OPEN_WEBSITE_WIDTH:
|
||||
websiteWidthProperty = property.value as number | undefined;
|
||||
break;
|
||||
case GameMapProperties.OPEN_WEBSITE_POSITION:
|
||||
websitePositionProperty = property.value as number | undefined;
|
||||
break;
|
||||
case GameMapProperties.OPEN_WEBSITE_TRIGGER:
|
||||
websiteTriggerProperty = property.value as string | undefined;
|
||||
break;
|
||||
case GameMapProperties.OPEN_WEBSITE_TRIGGER_MESSAGE:
|
||||
websiteTriggerMessageProperty = property.value as string | undefined;
|
||||
break;
|
||||
case GameMapProperties.OPEN_WEBSITE_HINT:
|
||||
websiteHintProperty = property.value as string | undefined;
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
if (!openWebsiteProperty) {
|
||||
return;
|
||||
}
|
||||
|
||||
const actionId = "openWebsite-" + (Math.random() + 1).toString(36).substring(7);
|
||||
|
||||
if (this.coWebsitesOpenByPlace.has(place)) {
|
||||
return;
|
||||
}
|
||||
|
||||
const coWebsiteOpen: OpenCoWebsite = {
|
||||
actionId: actionId,
|
||||
};
|
||||
|
||||
this.coWebsitesOpenByPlace.set(place, coWebsiteOpen);
|
||||
|
||||
const loadCoWebsiteFunction = (coWebsite: CoWebsite) => {
|
||||
coWebsiteManager.loadCoWebsite(coWebsite).catch(() => {
|
||||
console.error("Error during loading a co-website: " + coWebsite.getUrl());
|
||||
});
|
||||
|
||||
layoutManagerActionStore.removeAction(actionId);
|
||||
};
|
||||
|
||||
const openCoWebsiteFunction = () => {
|
||||
const coWebsite = new SimpleCoWebsite(
|
||||
new URL(openWebsiteProperty ?? "", this.scene.MapUrlFile),
|
||||
allowApiProperty,
|
||||
websitePolicyProperty,
|
||||
websiteWidthProperty,
|
||||
false,
|
||||
websiteHintProperty
|
||||
);
|
||||
|
||||
coWebsiteOpen.coWebsite = coWebsite;
|
||||
|
||||
coWebsiteManager.addCoWebsiteToStore(coWebsite, websitePositionProperty);
|
||||
|
||||
loadCoWebsiteFunction(coWebsite);
|
||||
};
|
||||
|
||||
if (localUserStore.getForceCowebsiteTrigger() || websiteTriggerProperty === ON_ACTION_TRIGGER_BUTTON) {
|
||||
if (!websiteTriggerMessageProperty) {
|
||||
websiteTriggerMessageProperty = get(LL).trigger.cowebsite();
|
||||
}
|
||||
|
||||
this.coWebsitesActionTriggerByPlace.set(place, actionId);
|
||||
|
||||
layoutManagerActionStore.addAction({
|
||||
uuid: actionId,
|
||||
type: "message",
|
||||
message: websiteTriggerMessageProperty,
|
||||
callback: () => openCoWebsiteFunction(),
|
||||
userInputManager: this.scene.userInputManager,
|
||||
});
|
||||
} else if (websiteTriggerProperty === ON_ICON_TRIGGER_BUTTON) {
|
||||
const coWebsite = new SimpleCoWebsite(
|
||||
new URL(openWebsiteProperty ?? "", this.scene.MapUrlFile),
|
||||
allowApiProperty,
|
||||
websitePolicyProperty,
|
||||
websiteWidthProperty,
|
||||
false,
|
||||
websiteHintProperty
|
||||
);
|
||||
|
||||
coWebsiteOpen.coWebsite = coWebsite;
|
||||
|
||||
coWebsiteManager.addCoWebsiteToStore(coWebsite, websitePositionProperty);
|
||||
}
|
||||
|
||||
if (!websiteTriggerProperty) {
|
||||
openCoWebsiteFunction();
|
||||
}
|
||||
}
|
||||
|
||||
private handleFocusablePropertiesOnEnter(place: ITiledPlace): void {
|
||||
if (!place.properties) {
|
||||
return;
|
||||
}
|
||||
if (place.x === undefined || place.y === undefined || !place.height || !place.width) {
|
||||
return;
|
||||
}
|
||||
const focusable = place.properties.find((property) => property.name === GameMapProperties.FOCUSABLE);
|
||||
if (focusable && focusable.value === true) {
|
||||
const zoomMargin = place.properties.find((property) => property.name === GameMapProperties.ZOOM_MARGIN);
|
||||
this.scene.getCameraManager().enterFocusMode(
|
||||
{
|
||||
x: place.x + place.width * 0.5,
|
||||
y: place.y + place.height * 0.5,
|
||||
width: place.width,
|
||||
height: place.height,
|
||||
},
|
||||
zoomMargin ? Math.max(0, Number(zoomMargin.value)) : undefined
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
private handleOpenWebsitePropertiesOnLeave(place: ITiledPlace): void {
|
||||
if (!place.properties) {
|
||||
return;
|
||||
}
|
||||
|
||||
let openWebsiteProperty: string | undefined;
|
||||
let websiteTriggerProperty: string | undefined;
|
||||
|
||||
place.properties.forEach((property) => {
|
||||
switch (property.name) {
|
||||
case GameMapProperties.OPEN_WEBSITE:
|
||||
openWebsiteProperty = property.value as string | undefined;
|
||||
break;
|
||||
case GameMapProperties.OPEN_WEBSITE_TRIGGER:
|
||||
websiteTriggerProperty = property.value as string | undefined;
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
||||
if (!openWebsiteProperty) {
|
||||
return;
|
||||
}
|
||||
|
||||
const coWebsiteOpen = this.coWebsitesOpenByPlace.get(place);
|
||||
|
||||
if (!coWebsiteOpen) {
|
||||
return;
|
||||
}
|
||||
|
||||
const coWebsite = coWebsiteOpen.coWebsite;
|
||||
|
||||
if (coWebsite) {
|
||||
coWebsiteManager.closeCoWebsite(coWebsite);
|
||||
}
|
||||
|
||||
this.coWebsitesOpenByPlace.delete(place);
|
||||
|
||||
if (!websiteTriggerProperty) {
|
||||
return;
|
||||
}
|
||||
|
||||
const actionStore = get(layoutManagerActionStore);
|
||||
const actionTriggerUuid = this.coWebsitesActionTriggerByPlace.get(place);
|
||||
|
||||
if (!actionTriggerUuid) {
|
||||
return;
|
||||
}
|
||||
|
||||
const action =
|
||||
actionStore && actionStore.length > 0
|
||||
? actionStore.find((action) => action.uuid === actionTriggerUuid)
|
||||
: undefined;
|
||||
|
||||
if (action) {
|
||||
layoutManagerActionStore.removeAction(actionTriggerUuid);
|
||||
}
|
||||
|
||||
this.coWebsitesActionTriggerByPlace.delete(place);
|
||||
}
|
||||
|
||||
private handleFocusablePropertiesOnLeave(place: ITiledPlace): void {
|
||||
if (!place.properties) {
|
||||
return;
|
||||
}
|
||||
const focusable = place.properties.find((property) => property.name === GameMapProperties.FOCUSABLE);
|
||||
if (focusable && focusable.value === true) {
|
||||
this.scene.getCameraManager().leaveFocusMode(this.scene.CurrentPlayer, 1000);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -92,7 +92,7 @@ import { followUsersColorStore } from "../../Stores/FollowStore";
|
||||
import { GameSceneUserInputHandler } from "../UserInput/GameSceneUserInputHandler";
|
||||
import { locale } from "../../i18n/i18n-svelte";
|
||||
import { i18nJson } from "../../i18n/locales";
|
||||
import { localVolumeStore } from "../../Stores/MediaStore";
|
||||
import { availabilityStatusStore, localVolumeStore } from "../../Stores/MediaStore";
|
||||
import { StringUtils } from "../../Utils/StringUtils";
|
||||
import { startLayerNamesStore } from "../../Stores/StartLayerNamesStore";
|
||||
import { JitsiCoWebsite } from "../../WebRtc/CoWebsite/JitsiCoWebsite";
|
||||
@@ -102,7 +102,6 @@ import CancelablePromise from "cancelable-promise";
|
||||
import { Deferred } from "ts-deferred";
|
||||
import { SuperLoaderPlugin } from "../Services/SuperLoaderPlugin";
|
||||
import { PlayerDetailsUpdatedMessage } from "../../Messages/ts-proto-generated/protos/messages";
|
||||
import { privacyShutdownStore } from "../../Stores/PrivacyShutdownStore";
|
||||
export interface GameSceneInitInterface {
|
||||
initPosition: PointInterface | null;
|
||||
reconnecting: boolean;
|
||||
@@ -186,7 +185,6 @@ export class GameScene extends DirtyScene {
|
||||
private biggestAvailableAreaStoreUnsubscribe!: () => void;
|
||||
MapUrlFile: string;
|
||||
roomUrl: string;
|
||||
instance: string;
|
||||
|
||||
currentTick!: number;
|
||||
lastSentTick!: number; // The last tick at which a position was sent.
|
||||
@@ -235,7 +233,6 @@ export class GameScene extends DirtyScene {
|
||||
});
|
||||
this.Terrains = [];
|
||||
this.groups = new Map<number, Sprite>();
|
||||
this.instance = room.getInstance();
|
||||
|
||||
this.MapUrlFile = MapUrlFile;
|
||||
this.roomUrl = room.key;
|
||||
@@ -252,6 +249,8 @@ export class GameScene extends DirtyScene {
|
||||
this.listenToIframeEvents();
|
||||
|
||||
this.load.image("iconTalk", "/resources/icons/icon_talking.png");
|
||||
this.load.image("iconStatusIndicatorInside", "/resources/icons/icon_status_indicator_inside.png");
|
||||
this.load.image("iconStatusIndicatorOutline", "/resources/icons/icon_status_indicator_outline.png");
|
||||
|
||||
if (touchScreenManager.supportTouchScreen) {
|
||||
this.load.image(joystickBaseKey, joystickBaseImg);
|
||||
@@ -697,6 +696,11 @@ export class GameScene extends DirtyScene {
|
||||
this.tryChangeShowVoiceIndicatorState(this.jitsiDominantSpeaker && this.jitsiParticipantsCount > 1);
|
||||
});
|
||||
|
||||
availabilityStatusStore.subscribe((status) => {
|
||||
this.connection?.emitPlayerStatusChange(status);
|
||||
this.CurrentPlayer.setStatus(status);
|
||||
});
|
||||
|
||||
this.emoteUnsubscribe = emoteStore.subscribe((emote) => {
|
||||
if (emote) {
|
||||
this.CurrentPlayer?.playEmote(emote.unicode);
|
||||
@@ -723,10 +727,6 @@ export class GameScene extends DirtyScene {
|
||||
}
|
||||
});
|
||||
|
||||
this.privacyShutdownStoreUnsubscribe = privacyShutdownStore.subscribe((away) => {
|
||||
this.connection?.emitPlayerAway(away);
|
||||
});
|
||||
|
||||
Promise.all([
|
||||
this.connectionAnswerPromiseDeferred.promise as Promise<unknown>,
|
||||
...scriptPromises,
|
||||
@@ -785,7 +785,7 @@ export class GameScene extends DirtyScene {
|
||||
characterLayers: message.characterLayers,
|
||||
name: message.name,
|
||||
position: message.position,
|
||||
away: message.away,
|
||||
status: message.status,
|
||||
visitCardUrl: message.visitCardUrl,
|
||||
companion: message.companion,
|
||||
userUuid: message.userUuid,
|
||||
@@ -925,38 +925,15 @@ export class GameScene extends DirtyScene {
|
||||
});
|
||||
});
|
||||
|
||||
this.gameMap.onEnterZone((zones) => {
|
||||
for (const zone of zones) {
|
||||
const focusable = zone.properties?.find((property) => property.name === "focusable");
|
||||
if (focusable && focusable.value === true) {
|
||||
const zoomMargin = zone.properties?.find((property) => property.name === "zoom_margin");
|
||||
this.cameraManager.enterFocusMode(
|
||||
{
|
||||
x: zone.x + zone.width * 0.5,
|
||||
y: zone.y + zone.height * 0.5,
|
||||
width: zone.width,
|
||||
height: zone.height,
|
||||
},
|
||||
zoomMargin ? Math.max(0, Number(zoomMargin.value)) : undefined
|
||||
);
|
||||
break;
|
||||
}
|
||||
}
|
||||
zones.forEach((zone) => {
|
||||
iframeListener.sendEnterZoneEvent(zone.name);
|
||||
this.gameMap.onEnterArea((areas) => {
|
||||
areas.forEach((area) => {
|
||||
iframeListener.sendEnterAreaEvent(area.name);
|
||||
});
|
||||
});
|
||||
|
||||
this.gameMap.onLeaveZone((zones) => {
|
||||
for (const zone of zones) {
|
||||
const focusable = zone.properties?.find((property) => property.name === "focusable");
|
||||
if (focusable && focusable.value === true) {
|
||||
this.cameraManager.leaveFocusMode(this.CurrentPlayer, 1000);
|
||||
break;
|
||||
}
|
||||
}
|
||||
zones.forEach((zone) => {
|
||||
iframeListener.sendLeaveZoneEvent(zone.name);
|
||||
this.gameMap.onLeaveArea((areas) => {
|
||||
areas.forEach((area) => {
|
||||
iframeListener.sendLeaveAreaEvent(area.name);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1993,8 +1970,8 @@ export class GameScene extends DirtyScene {
|
||||
if (addPlayerData.outlineColor !== undefined) {
|
||||
player.setApiOutlineColor(addPlayerData.outlineColor);
|
||||
}
|
||||
if (addPlayerData.away !== undefined) {
|
||||
player.setAwayStatus(addPlayerData.away, true);
|
||||
if (addPlayerData.status !== undefined) {
|
||||
player.setStatus(addPlayerData.status, true);
|
||||
}
|
||||
this.MapPlayers.add(player);
|
||||
this.MapPlayersByKey.set(player.userId, player);
|
||||
@@ -2145,8 +2122,8 @@ export class GameScene extends DirtyScene {
|
||||
if (message.details?.showVoiceIndicator !== undefined) {
|
||||
character.showTalkIcon(message.details?.showVoiceIndicator);
|
||||
}
|
||||
if (message.details?.away !== undefined) {
|
||||
character.setAwayStatus(message.details?.away);
|
||||
if (message.details?.status !== undefined) {
|
||||
character.setStatus(message.details?.status);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2190,13 +2167,10 @@ export class GameScene extends DirtyScene {
|
||||
}
|
||||
|
||||
public enableMediaBehaviors() {
|
||||
const silent = this.gameMap.getCurrentProperties().get(GameMapProperties.SILENT);
|
||||
this.connection?.setSilent(!!silent);
|
||||
mediaManager.showMyCamera();
|
||||
}
|
||||
|
||||
public disableMediaBehaviors() {
|
||||
this.connection?.setSilent(true);
|
||||
mediaManager.hideMyCamera();
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
import { AvailabilityStatus } from "../../Messages/ts-proto-generated/protos/messages";
|
||||
import type { BodyResourceDescriptionInterface } from "../Entity/PlayerTextures";
|
||||
|
||||
export interface PlayerInterface {
|
||||
@@ -7,7 +8,7 @@ export interface PlayerInterface {
|
||||
visitCardUrl: string | null;
|
||||
companion: string | null;
|
||||
userUuid: string;
|
||||
away: boolean;
|
||||
status: AvailabilityStatus;
|
||||
color?: string;
|
||||
outlineColor?: number;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ export class PlayerMovement {
|
||||
const y =
|
||||
(this.endPosition.y - this.startPosition.y) * ((tick - this.startTick) / (this.endTick - this.startTick)) +
|
||||
this.startPosition.y;
|
||||
//console.log('Computed position ', x, y)
|
||||
return {
|
||||
x,
|
||||
y,
|
||||
|
||||
@@ -67,4 +67,20 @@ export class TexturesHelper {
|
||||
rectangleTexture.generateTexture(textureKey, width, height);
|
||||
rectangleTexture.destroy();
|
||||
}
|
||||
|
||||
public static createCircleTexture(
|
||||
scene: Phaser.Scene,
|
||||
textureKey: string,
|
||||
radius: number,
|
||||
color: number,
|
||||
outlineColor?: number,
|
||||
outlineThickness?: number
|
||||
): void {
|
||||
const circleTexture = scene.add.graphics().fillStyle(color, 1).fillCircle(radius, radius, radius);
|
||||
if (outlineColor) {
|
||||
circleTexture.lineStyle(outlineThickness ?? 1, outlineColor).strokeCircle(radius, radius, radius);
|
||||
}
|
||||
circleTexture.generateTexture(textureKey, radius * 2, radius * 2);
|
||||
circleTexture.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,6 @@ export class Player extends Character {
|
||||
companionTexturePromise?: CancelablePromise<string>
|
||||
) {
|
||||
super(Scene, x, y, texturesPromise, name, direction, moving, 1, true, companion, companionTexturePromise);
|
||||
this.statusDot.setVisible(false);
|
||||
//the current player model should be push away by other players to prevent conflict
|
||||
this.getBody().setImmovable(false);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user