Migrate layoutManager in Svelte
This commit is contained in:
parent
3ab069d650
commit
1436b15328
6 changed files with 178 additions and 121 deletions
|
@ -1,6 +1,3 @@
|
|||
import type { UserInputManager } from "../Phaser/UserInput/UserInputManager";
|
||||
import { HtmlUtils } from "./HtmlUtils";
|
||||
|
||||
export enum LayoutMode {
|
||||
// All videos are displayed on the right side of the screen. If there is a screen sharing, it is displayed in the middle.
|
||||
Presentation = "Presentation",
|
||||
|
@ -27,85 +24,3 @@ export const AUDIO_VOLUME_PROPERTY = "audioVolume";
|
|||
export const AUDIO_LOOP_PROPERTY = "audioLoop";
|
||||
|
||||
export type Box = { xStart: number; yStart: number; xEnd: number; yEnd: number };
|
||||
|
||||
class LayoutManager {
|
||||
private actionButtonTrigger: Map<string, Function> = new Map<string, Function>();
|
||||
private actionButtonInformation: Map<string, HTMLDivElement> = new Map<string, HTMLDivElement>();
|
||||
|
||||
public addActionButton(id: string, text: string, callBack: Function, userInputManager: UserInputManager) {
|
||||
//delete previous element
|
||||
this.removeActionButton(id, userInputManager);
|
||||
|
||||
//create div and text html component
|
||||
const p = document.createElement("p");
|
||||
p.classList.add("action-body");
|
||||
p.innerText = text;
|
||||
|
||||
const div = document.createElement("div");
|
||||
div.classList.add("action");
|
||||
div.id = id;
|
||||
div.appendChild(p);
|
||||
|
||||
this.actionButtonInformation.set(id, div);
|
||||
|
||||
const mainContainer = HtmlUtils.getElementByIdOrFail<HTMLDivElement>("main-container");
|
||||
mainContainer.appendChild(div);
|
||||
|
||||
//add trigger action
|
||||
div.onpointerdown = () => callBack();
|
||||
this.actionButtonTrigger.set(id, callBack);
|
||||
userInputManager.addSpaceEventListner(callBack);
|
||||
}
|
||||
|
||||
public removeActionButton(id: string, userInputManager?: UserInputManager) {
|
||||
//delete previous element
|
||||
const previousDiv = this.actionButtonInformation.get(id);
|
||||
if (previousDiv) {
|
||||
previousDiv.remove();
|
||||
this.actionButtonInformation.delete(id);
|
||||
}
|
||||
const previousEventCallback = this.actionButtonTrigger.get(id);
|
||||
if (previousEventCallback && userInputManager) {
|
||||
userInputManager.removeSpaceEventListner(previousEventCallback);
|
||||
}
|
||||
}
|
||||
|
||||
public addInformation(id: string, text: string, callBack?: Function, userInputManager?: UserInputManager) {
|
||||
//delete previous element
|
||||
for (const [key, value] of this.actionButtonInformation) {
|
||||
this.removeActionButton(key, userInputManager);
|
||||
}
|
||||
|
||||
//create div and text html component
|
||||
const p = document.createElement("p");
|
||||
p.classList.add("action-body");
|
||||
p.innerText = text;
|
||||
|
||||
const div = document.createElement("div");
|
||||
div.classList.add("action");
|
||||
div.classList.add(id);
|
||||
div.id = id;
|
||||
div.appendChild(p);
|
||||
|
||||
this.actionButtonInformation.set(id, div);
|
||||
|
||||
const mainContainer = HtmlUtils.getElementByIdOrFail<HTMLDivElement>("main-container");
|
||||
mainContainer.appendChild(div);
|
||||
//add trigger action
|
||||
if (callBack) {
|
||||
div.onpointerdown = () => {
|
||||
callBack();
|
||||
this.removeActionButton(id, userInputManager);
|
||||
};
|
||||
}
|
||||
|
||||
//remove it after 10 sec
|
||||
setTimeout(() => {
|
||||
this.removeActionButton(id, userInputManager);
|
||||
}, 10000);
|
||||
}
|
||||
}
|
||||
|
||||
const layoutManager = new LayoutManager();
|
||||
|
||||
export { layoutManager };
|
||||
|
|
|
@ -1,4 +1,3 @@
|
|||
import { layoutManager } from "./LayoutManager";
|
||||
import { HtmlUtils } from "./HtmlUtils";
|
||||
import type { UserInputManager } from "../Phaser/UserInput/UserInputManager";
|
||||
import { localStreamStore } from "../Stores/MediaStore";
|
||||
|
@ -10,6 +9,8 @@ export type StopScreenSharingCallback = (media: MediaStream) => void;
|
|||
|
||||
import { cowebsiteCloseButtonId } from "./CoWebsiteManager";
|
||||
import { gameOverlayVisibilityStore } from "../Stores/GameOverlayStoreVisibility";
|
||||
import { layoutManagerActionStore, layoutManagerVisibilityStore } from "../Stores/LayoutManagerStore";
|
||||
import { get } from "svelte/store";
|
||||
|
||||
export class MediaManager {
|
||||
startScreenSharingCallBacks: Set<StartScreenSharingCallback> = new Set<StartScreenSharingCallback>();
|
||||
|
@ -23,14 +24,16 @@ export class MediaManager {
|
|||
localStreamStore.subscribe((result) => {
|
||||
if (result.type === "error") {
|
||||
console.error(result.error);
|
||||
layoutManager.addInformation(
|
||||
"warning",
|
||||
"Camera access denied. Click here and check your browser permissions.",
|
||||
() => {
|
||||
layoutManagerActionStore.addAction({
|
||||
type: "warning",
|
||||
message: "Camera access denied. Click here and check your browser permissions.",
|
||||
callback: () => {
|
||||
helpCameraSettingsVisibleStore.set(true);
|
||||
layoutManagerVisibilityStore.set(false);
|
||||
},
|
||||
this.userInputManager
|
||||
);
|
||||
userInputManager: this.userInputManager,
|
||||
});
|
||||
layoutManagerVisibilityStore.set(true);
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
@ -38,14 +41,16 @@ export class MediaManager {
|
|||
screenSharingLocalStreamStore.subscribe((result) => {
|
||||
if (result.type === "error") {
|
||||
console.error(result.error);
|
||||
layoutManager.addInformation(
|
||||
"warning",
|
||||
"Screen sharing denied. Click here and check your browser permissions.",
|
||||
() => {
|
||||
layoutManagerActionStore.addAction({
|
||||
type: "warning",
|
||||
message: "Screen sharing denied. Click here and check your browser permissions.",
|
||||
callback: () => {
|
||||
helpCameraSettingsVisibleStore.set(true);
|
||||
layoutManagerVisibilityStore.set(false);
|
||||
},
|
||||
this.userInputManager
|
||||
);
|
||||
userInputManager: this.userInputManager,
|
||||
});
|
||||
layoutManagerVisibilityStore.set(true);
|
||||
return;
|
||||
}
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue