disable activation by distance if in JITSI

This commit is contained in:
Hanusiak Piotr 2022-02-07 12:36:33 +01:00
parent bf0d2eb412
commit aec7790875
4 changed files with 39 additions and 16 deletions

View File

@ -11,6 +11,8 @@ export class ActivatablesManager {
private currentPlayer: Player; private currentPlayer: Player;
private canSelectByDistance: boolean = true;
private readonly outlineColor = 0xffff00; private readonly outlineColor = 0xffff00;
private readonly directionalActivationPositionShift = 50; private readonly directionalActivationPositionShift = 50;
@ -49,6 +51,9 @@ export class ActivatablesManager {
} }
public deduceSelectedActivatableObjectByDistance(): void { public deduceSelectedActivatableObjectByDistance(): void {
if (!this.canSelectByDistance) {
return;
}
const newNearestObject = this.findNearestActivatableObject(); const newNearestObject = this.findNearestActivatableObject();
if (this.selectedActivatableObjectByDistance === newNearestObject) { if (this.selectedActivatableObjectByDistance === newNearestObject) {
return; return;
@ -67,18 +72,6 @@ export class ActivatablesManager {
} }
} }
private findNearestActivatableObject(): ActivatableInterface | undefined {
let shortestDistance: number = Infinity;
let closestObject: ActivatableInterface | undefined = undefined;
for (const [object, distance] of this.activatableObjectsDistances.entries()) {
if (object.isActivatable() && object.activationRadius > distance && shortestDistance > distance) {
shortestDistance = distance;
closestObject = object;
}
}
return closestObject;
}
public updateActivatableObjectsDistances(objects: ActivatableInterface[]): void { public updateActivatableObjectsDistances(objects: ActivatableInterface[]): void {
const currentPlayerPos = this.currentPlayer.getDirectionalActivationPosition(this.directionalActivationPositionShift); const currentPlayerPos = this.currentPlayer.getDirectionalActivationPosition(this.directionalActivationPositionShift);
for (const object of objects) { for (const object of objects) {
@ -96,4 +89,33 @@ export class ActivatablesManager {
) )
); );
} }
public disableSelectingByDistance(): void {
this.canSelectByDistance = false;
if (isOutlineable(this.selectedActivatableObjectByDistance)) {
this.selectedActivatableObjectByDistance?.characterFarAwayOutline();
}
this.selectedActivatableObjectByDistance = undefined;
}
public enableSelectingByDistance(): void {
this.canSelectByDistance = true;
}
private findNearestActivatableObject(): ActivatableInterface | undefined {
let shortestDistance: number = Infinity;
let closestObject: ActivatableInterface | undefined = undefined;
for (const [object, distance] of this.activatableObjectsDistances.entries()) {
if (object.isActivatable() && object.activationRadius > distance && shortestDistance > distance) {
shortestDistance = distance;
closestObject = object;
}
}
return closestObject;
}
public isSelectingByDistanceEnabled(): boolean {
return this.canSelectByDistance;
}
} }

View File

@ -957,9 +957,11 @@ export class GameScene extends DirtyScene {
this.gameMap.onPropertyChange(GameMapProperties.JITSI_ROOM, (newValue, oldValue, allProps) => { this.gameMap.onPropertyChange(GameMapProperties.JITSI_ROOM, (newValue, oldValue, allProps) => {
if (newValue === undefined) { if (newValue === undefined) {
this.activatablesManager.enableSelectingByDistance();
layoutManagerActionStore.removeAction("jitsi"); layoutManagerActionStore.removeAction("jitsi");
this.stopJitsi(); this.stopJitsi();
} else { } else {
this.activatablesManager.disableSelectingByDistance();
const openJitsiRoomFunction = () => { const openJitsiRoomFunction = () => {
const roomName = jitsiFactory.getRoomName(newValue.toString(), this.instance); const roomName = jitsiFactory.getRoomName(newValue.toString(), this.instance);
const jitsiUrl = allProps.get(GameMapProperties.JITSI_URL) as string | undefined; const jitsiUrl = allProps.get(GameMapProperties.JITSI_URL) as string | undefined;

View File

@ -53,8 +53,9 @@ export class GameSceneUserInputHandler implements UserInputHandlerInterface {
public handlePointerDownEvent(pointer: Phaser.Input.Pointer, gameObjects: Phaser.GameObjects.GameObject[]): void {} public handlePointerDownEvent(pointer: Phaser.Input.Pointer, gameObjects: Phaser.GameObjects.GameObject[]): void {}
public handleSpaceKeyUpEvent(event: Event): Event { public handleSpaceKeyUpEvent(event: Event): Event {
const activatable = this.gameScene.getActivatablesManager().getSelectedActivatableObject(); const activatableManager = this.gameScene.getActivatablesManager();
if (activatable && activatable.isActivatable()) { const activatable = activatableManager.getSelectedActivatableObject();
if (activatable && activatable.isActivatable() && activatableManager.isSelectingByDistanceEnabled()) {
activatable.activate(); activatable.activate();
} }
return event; return event;

View File

@ -10,8 +10,6 @@ export function createColorStore() {
const updateColor = () => { const updateColor = () => {
console.log('update color');
console.log(pointedByPointer, pointedByCharacter, followColor, apiColor);
set(pointedByPointer ?? pointedByCharacter ?? followColor ?? apiColor); set(pointedByPointer ?? pointedByCharacter ?? followColor ?? apiColor);
}; };