Merge branch 'develop' of github.com:thecodingmachine/workadventure into main
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
import VirtualJoystick from 'phaser3-rex-plugins/plugins/virtualjoystick.js';
|
||||
import {waScaleManager} from "../Services/WaScaleManager";
|
||||
import {DEPTH_INGAME_TEXT_INDEX} from "../Game/DepthIndexes";
|
||||
import VirtualJoystick from "phaser3-rex-plugins/plugins/virtualjoystick.js";
|
||||
import { waScaleManager } from "../Services/WaScaleManager";
|
||||
import { DEPTH_INGAME_TEXT_INDEX } from "../Game/DepthIndexes";
|
||||
|
||||
//the assets were found here: https://hannemann.itch.io/virtual-joystick-pack-free
|
||||
export const joystickBaseKey = 'joystickBase';
|
||||
export const joystickBaseImg = 'resources/objects/joystickSplitted.png';
|
||||
export const joystickThumbKey = 'joystickThumb';
|
||||
export const joystickThumbImg = 'resources/objects/smallHandleFilledGrey.png';
|
||||
export const joystickBaseKey = "joystickBase";
|
||||
export const joystickBaseImg = "resources/objects/joystickSplitted.png";
|
||||
export const joystickThumbKey = "joystickThumb";
|
||||
export const joystickThumbImg = "resources/objects/smallHandleFilledGrey.png";
|
||||
|
||||
const baseSize = 50;
|
||||
const thumbSize = 25;
|
||||
@@ -20,15 +20,27 @@ export class MobileJoystick extends VirtualJoystick {
|
||||
x: -1000,
|
||||
y: -1000,
|
||||
radius: radius * window.devicePixelRatio,
|
||||
base: scene.add.image(0, 0, joystickBaseKey).setDisplaySize(baseSize * window.devicePixelRatio, baseSize * window.devicePixelRatio).setDepth(DEPTH_INGAME_TEXT_INDEX),
|
||||
thumb: scene.add.image(0, 0, joystickThumbKey).setDisplaySize(thumbSize * window.devicePixelRatio, thumbSize * window.devicePixelRatio).setDepth(DEPTH_INGAME_TEXT_INDEX),
|
||||
base: scene.add
|
||||
.image(0, 0, joystickBaseKey)
|
||||
.setDisplaySize(
|
||||
(baseSize / waScaleManager.zoomModifier) * window.devicePixelRatio,
|
||||
(baseSize / waScaleManager.zoomModifier) * window.devicePixelRatio
|
||||
)
|
||||
.setDepth(DEPTH_INGAME_TEXT_INDEX),
|
||||
thumb: scene.add
|
||||
.image(0, 0, joystickThumbKey)
|
||||
.setDisplaySize(
|
||||
(thumbSize / waScaleManager.zoomModifier) * window.devicePixelRatio,
|
||||
(thumbSize / waScaleManager.zoomModifier) * window.devicePixelRatio
|
||||
)
|
||||
.setDepth(DEPTH_INGAME_TEXT_INDEX),
|
||||
enable: true,
|
||||
dir: "8dir",
|
||||
});
|
||||
this.visible = false;
|
||||
this.enable = false;
|
||||
|
||||
this.scene.input.on('pointerdown', (pointer: Phaser.Input.Pointer) => {
|
||||
this.scene.input.on("pointerdown", (pointer: Phaser.Input.Pointer) => {
|
||||
if (!pointer.wasTouch) {
|
||||
return;
|
||||
}
|
||||
@@ -44,7 +56,7 @@ export class MobileJoystick extends VirtualJoystick {
|
||||
this.enable = false;
|
||||
}
|
||||
});
|
||||
this.scene.input.on('pointerup', () => {
|
||||
this.scene.input.on("pointerup", () => {
|
||||
this.visible = false;
|
||||
this.enable = false;
|
||||
});
|
||||
@@ -52,10 +64,16 @@ export class MobileJoystick extends VirtualJoystick {
|
||||
this.scene.scale.on(Phaser.Scale.Events.RESIZE, this.resizeCallback);
|
||||
}
|
||||
|
||||
private resize() {
|
||||
this.base.setDisplaySize(baseSize / waScaleManager.zoomModifier * window.devicePixelRatio, baseSize / waScaleManager.zoomModifier * window.devicePixelRatio);
|
||||
this.thumb.setDisplaySize(thumbSize / waScaleManager.zoomModifier * window.devicePixelRatio, thumbSize / waScaleManager.zoomModifier * window.devicePixelRatio);
|
||||
this.setRadius(radius / waScaleManager.zoomModifier * window.devicePixelRatio);
|
||||
public resize() {
|
||||
this.base.setDisplaySize(this.getDisplaySizeByElement(baseSize), this.getDisplaySizeByElement(baseSize));
|
||||
this.thumb.setDisplaySize(this.getDisplaySizeByElement(thumbSize), this.getDisplaySizeByElement(thumbSize));
|
||||
this.setRadius(
|
||||
(radius / (waScaleManager.zoomModifier * waScaleManager.uiScalingFactor)) * window.devicePixelRatio
|
||||
);
|
||||
}
|
||||
|
||||
private getDisplaySizeByElement(element: integer): integer {
|
||||
return (element / (waScaleManager.zoomModifier * waScaleManager.uiScalingFactor)) * window.devicePixelRatio;
|
||||
}
|
||||
|
||||
public destroy() {
|
||||
|
||||
@@ -1,90 +0,0 @@
|
||||
|
||||
const IGNORED_KEYS = new Set([
|
||||
'Esc',
|
||||
'Escape',
|
||||
'Alt',
|
||||
'Meta',
|
||||
'Control',
|
||||
'Ctrl',
|
||||
'Space',
|
||||
'Backspace'
|
||||
])
|
||||
|
||||
export class TextInput extends Phaser.GameObjects.BitmapText {
|
||||
private minUnderLineLength = 4;
|
||||
private underLine: Phaser.GameObjects.Text;
|
||||
private domInput = document.createElement('input');
|
||||
|
||||
constructor(scene: Phaser.Scene, x: number, y: number, maxLength: number, text: string,
|
||||
onChange: (text: string) => void) {
|
||||
super(scene, x, y, 'main_font', text, 32);
|
||||
this.setOrigin(0.5).setCenterAlign();
|
||||
this.scene.add.existing(this);
|
||||
|
||||
const style = {fontFamily: 'Arial', fontSize: "32px", color: '#ffffff'};
|
||||
this.underLine = this.scene.add.text(x, y+1, this.getUnderLineBody(text.length), style);
|
||||
this.underLine.setOrigin(0.5);
|
||||
|
||||
this.domInput.maxLength = maxLength;
|
||||
this.domInput.style.opacity = "0";
|
||||
if (text) {
|
||||
this.domInput.value = text;
|
||||
}
|
||||
|
||||
this.domInput.addEventListener('keydown', event => {
|
||||
if (IGNORED_KEYS.has(event.key)) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (!/[a-zA-Z0-9:.!&?()+-]/.exec(event.key)) {
|
||||
event.preventDefault();
|
||||
}
|
||||
});
|
||||
|
||||
this.domInput.addEventListener('input', (event) => {
|
||||
if (event.defaultPrevented) {
|
||||
return;
|
||||
}
|
||||
this.text = this.domInput.value;
|
||||
this.underLine.text = this.getUnderLineBody(this.text.length);
|
||||
onChange(this.text);
|
||||
});
|
||||
|
||||
document.body.append(this.domInput);
|
||||
this.focus();
|
||||
}
|
||||
|
||||
private getUnderLineBody(textLength:number): string {
|
||||
if (textLength < this.minUnderLineLength) textLength = this.minUnderLineLength;
|
||||
let text = '_______';
|
||||
for (let i = this.minUnderLineLength; i < textLength; i++) {
|
||||
text += '__';
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
getText(): string {
|
||||
return this.text;
|
||||
}
|
||||
|
||||
setX(x: number): this {
|
||||
super.setX(x);
|
||||
this.underLine.x = x;
|
||||
return this;
|
||||
}
|
||||
|
||||
setY(y: number): this {
|
||||
super.setY(y);
|
||||
this.underLine.y = y+1;
|
||||
return this;
|
||||
}
|
||||
|
||||
focus() {
|
||||
this.domInput.focus();
|
||||
}
|
||||
|
||||
destroy(): void {
|
||||
super.destroy();
|
||||
this.domInput.remove();
|
||||
}
|
||||
}
|
||||
@@ -32,7 +32,6 @@ import type { RoomConnection } from "../../Connexion/RoomConnection";
|
||||
import { Room } from "../../Connexion/Room";
|
||||
import { jitsiFactory } from "../../WebRtc/JitsiFactory";
|
||||
import { urlManager } from "../../Url/UrlManager";
|
||||
import { audioManager } from "../../WebRtc/AudioManager";
|
||||
import { TextureError } from "../../Exception/TextureError";
|
||||
import { localUserStore } from "../../Connexion/LocalUserStore";
|
||||
import { HtmlUtils } from "../../WebRtc/HtmlUtils";
|
||||
@@ -84,6 +83,11 @@ import { biggestAvailableAreaStore } from "../../Stores/BiggestAvailableAreaStor
|
||||
import { SharedVariablesManager } from "./SharedVariablesManager";
|
||||
import { playersStore } from "../../Stores/PlayersStore";
|
||||
import { chatVisibilityStore } from "../../Stores/ChatStore";
|
||||
import {
|
||||
audioManagerFileStore,
|
||||
audioManagerVisibilityStore,
|
||||
audioManagerVolumeStore,
|
||||
} from "../../Stores/AudioManagerStore";
|
||||
import { PropertyUtils } from "../Map/PropertyUtils";
|
||||
import Tileset = Phaser.Tilemaps.Tileset;
|
||||
import { userIsAdminStore } from "../../Stores/GameStore";
|
||||
@@ -727,12 +731,12 @@ export class GameScene extends DirtyScene {
|
||||
this.simplePeer.registerPeerConnectionListener({
|
||||
onConnect(peer) {
|
||||
//self.openChatIcon.setVisible(true);
|
||||
audioManager.decreaseVolume();
|
||||
audioManagerVolumeStore.setTalking(true);
|
||||
},
|
||||
onDisconnect(userId: number) {
|
||||
if (self.simplePeer.getNbConnections() === 0) {
|
||||
//self.openChatIcon.setVisible(false);
|
||||
audioManager.restoreVolume();
|
||||
audioManagerVolumeStore.setTalking(false);
|
||||
}
|
||||
},
|
||||
});
|
||||
@@ -898,14 +902,16 @@ export class GameScene extends DirtyScene {
|
||||
const volume = allProps.get(AUDIO_VOLUME_PROPERTY) as number | undefined;
|
||||
const loop = allProps.get(AUDIO_LOOP_PROPERTY) as boolean | undefined;
|
||||
newValue === undefined
|
||||
? audioManager.unloadAudio()
|
||||
: audioManager.playAudio(newValue, this.getMapDirUrl(), volume, loop);
|
||||
? audioManagerFileStore.unloadAudio()
|
||||
: audioManagerFileStore.playAudio(newValue, this.getMapDirUrl(), volume, loop);
|
||||
audioManagerVisibilityStore.set(!(newValue === undefined));
|
||||
});
|
||||
// TODO: This legacy property should be removed at some point
|
||||
this.gameMap.onPropertyChange("playAudioLoop", (newValue, oldValue) => {
|
||||
newValue === undefined
|
||||
? audioManager.unloadAudio()
|
||||
: audioManager.playAudio(newValue, this.getMapDirUrl(), undefined, true);
|
||||
? audioManagerFileStore.unloadAudio()
|
||||
: audioManagerFileStore.playAudio(newValue, this.getMapDirUrl(), undefined, true);
|
||||
audioManagerVisibilityStore.set(!(newValue === undefined));
|
||||
});
|
||||
|
||||
this.gameMap.onPropertyChange("zone", (newValue, oldValue) => {
|
||||
@@ -1362,7 +1368,7 @@ export class GameScene extends DirtyScene {
|
||||
}
|
||||
|
||||
this.stopJitsi();
|
||||
audioManager.unloadAudio();
|
||||
audioManagerFileStore.unloadAudio();
|
||||
// We are completely destroying the current scene to avoid using a half-backed instance when coming back to the same map.
|
||||
this.connection?.closeConnection();
|
||||
this.simplePeer?.closeAllConnections();
|
||||
|
||||
Reference in New Issue
Block a user