ed
This commit is contained in:
parent
600d79af31
commit
5d11084641
136 changed files with 12007 additions and 584 deletions
105
resources/[freizeit]/[gym]/ps-ui/web/utils/eventHandler.ts
Normal file
105
resources/[freizeit]/[gym]/ps-ui/web/utils/eventHandler.ts
Normal file
|
@ -0,0 +1,105 @@
|
|||
import { hideStatusBar, showStatusBar } from '../src/stores/StatusBarStores';
|
||||
import { hideUi, showComponent, showUi } from '../src/stores/GeneralStores';
|
||||
import { showInput } from './../src/stores/InputStores';
|
||||
|
||||
import { onMount, onDestroy } from 'svelte';
|
||||
import fetchNui from './fetch';
|
||||
import { UIComponentsEnum } from './../src/enums/UIComponentsEnum';
|
||||
import { currentActiveGameDetails, currentGameActive, gameSettings, setupGame } from '../src/stores/GameLauncherStore';
|
||||
import { showImage } from './../src/stores/ImageStore';
|
||||
import { addNotification } from './../src/stores/NotificationStore';
|
||||
import { hideDrawTextMenu, showDrawTextMenu } from '../src/stores/DrawTextStore';
|
||||
import { closeInteractionMenu, setupInteractionMenu } from '../src/stores/MenuStores';
|
||||
import { initializeCircleGame, setupCircleGame } from '../src/stores/CircleGameStore';
|
||||
|
||||
interface nuiMessage {
|
||||
action: string;
|
||||
data: {[key: string]: any};
|
||||
}
|
||||
|
||||
export function EventHandler() {
|
||||
function mainEvent(event: nuiMessage) {
|
||||
showUi.set(true);
|
||||
switch (event.data.action) {
|
||||
case 'ShowStatusBar':
|
||||
showStatusBar(event.data.data as any);
|
||||
break;
|
||||
case 'UpdateStatusBar':
|
||||
showStatusBar(event.data.data as any);
|
||||
break;
|
||||
case 'HideStatusBar':
|
||||
hideStatusBar();
|
||||
break;
|
||||
case 'ShowMenu':
|
||||
setupInteractionMenu(event.data.data as any)
|
||||
break;
|
||||
case 'HideMenu':
|
||||
closeInteractionMenu();
|
||||
break;
|
||||
case 'ShowInput':
|
||||
showInput(event.data.data as any);
|
||||
break;
|
||||
case 'ShowImage':
|
||||
showImage(event.data.data as any);
|
||||
break;
|
||||
case 'hideUi':
|
||||
hideUi();
|
||||
break;
|
||||
case 'ShowNotification':
|
||||
addNotification(event.data.data as any);
|
||||
break;
|
||||
case 'ShowDrawTextMenu':
|
||||
showDrawTextMenu(event.data.data as any);
|
||||
break;
|
||||
case 'HideDrawTextMenu':
|
||||
hideDrawTextMenu();
|
||||
break;
|
||||
case 'CircleGame':
|
||||
initializeCircleGame()
|
||||
setupCircleGame(event.data.data)
|
||||
break;
|
||||
case 'MemoryGame':
|
||||
case 'Scramber':
|
||||
case 'NumberMaze':
|
||||
case 'GameLauncher':
|
||||
setupGame(event.data.data as any);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
onMount(() => window.addEventListener('message', mainEvent));
|
||||
onDestroy(() => window.removeEventListener('message', mainEvent));
|
||||
}
|
||||
|
||||
export function handleKeyUp(event: KeyboardEvent) {
|
||||
const charCode = event.key;
|
||||
if (charCode == 'Escape') {
|
||||
showComponent.subscribe((component: UIComponentsEnum) => {
|
||||
switch (component) {
|
||||
case UIComponentsEnum.Input:
|
||||
fetchNui('input-close', { ok: true });
|
||||
break;
|
||||
case UIComponentsEnum.Menu:
|
||||
closeInteractionMenu();
|
||||
break;
|
||||
case UIComponentsEnum.Image:
|
||||
fetchNui('minigame:callback', true);
|
||||
break;
|
||||
case UIComponentsEnum.Game:
|
||||
currentGameActive.set(null);
|
||||
currentActiveGameDetails.set(null);
|
||||
gameSettings.set({
|
||||
game: '',
|
||||
gameName: '',
|
||||
gameDescription: '',
|
||||
amountOfAnswers: 0,
|
||||
gameTime: 0,
|
||||
maxAnswersIncorrect: 0,
|
||||
triggerEvent: '',
|
||||
});
|
||||
break;
|
||||
}
|
||||
});
|
||||
hideUi();
|
||||
}
|
||||
}
|
28
resources/[freizeit]/[gym]/ps-ui/web/utils/fetch.ts
Normal file
28
resources/[freizeit]/[gym]/ps-ui/web/utils/fetch.ts
Normal file
|
@ -0,0 +1,28 @@
|
|||
export default async function fetchNui(eventName: string, data: unknown = {}) {
|
||||
const options = {
|
||||
method: 'post',
|
||||
headers: {
|
||||
'Content-Type': 'application/json; charset=UTF-8',
|
||||
},
|
||||
body: JSON.stringify(data),
|
||||
};
|
||||
|
||||
const getResourceName = () => {
|
||||
try {
|
||||
// @ts-ignore
|
||||
return window.GetParentResourceName();
|
||||
} catch (err) {
|
||||
return 'ps-ui';
|
||||
}
|
||||
};
|
||||
|
||||
const resourceName = getResourceName();
|
||||
|
||||
try {
|
||||
const resp = await fetch(
|
||||
`https://${resourceName}/${eventName}`,
|
||||
options
|
||||
);
|
||||
return await resp.json();
|
||||
} catch (err) {}
|
||||
}
|
45
resources/[freizeit]/[gym]/ps-ui/web/utils/mockEvent.ts
Normal file
45
resources/[freizeit]/[gym]/ps-ui/web/utils/mockEvent.ts
Normal file
|
@ -0,0 +1,45 @@
|
|||
import type { IImage } from './../src/interfaces/IImage';
|
||||
export default function mockEventCall(data: unknown = {}) {
|
||||
window.dispatchEvent(new MessageEvent('message', { data }));
|
||||
}
|
||||
|
||||
export function newMemoryGameMock() {
|
||||
setTimeout(() => {
|
||||
mockEventCall({
|
||||
action: 'MemoryGame',
|
||||
data: {
|
||||
game: 'MemoryGame',
|
||||
amountOfAnswers: 1,
|
||||
gameTime: 5,
|
||||
maxAnswersIncorrect: 2,
|
||||
triggerEvent: '',
|
||||
},
|
||||
});
|
||||
}, 100);
|
||||
}
|
||||
|
||||
export function showImageMock() {
|
||||
setTimeout(() => {
|
||||
mockEventCall({
|
||||
action: 'ShowImage',
|
||||
data: {
|
||||
show: true,
|
||||
url: 'https://i.ytimg.com/vi/7V15_-32iCU/maxresdefault.jpg',
|
||||
},
|
||||
});
|
||||
}, 100);
|
||||
}
|
||||
|
||||
export function notificationMock() {
|
||||
setTimeout(() => {
|
||||
mockEventCall({
|
||||
action: 'ShowNotification',
|
||||
data: {
|
||||
text: 'New notification',
|
||||
type: 'ps-notification-success',
|
||||
icon: 'fa-solid fa-times',
|
||||
length: 5000,
|
||||
},
|
||||
});
|
||||
}, 500);
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue