forked from Simnation/Main
Update main.js
This commit is contained in:
parent
53578d1af6
commit
8bcfbb815c
1 changed files with 35 additions and 5 deletions
|
@ -2,6 +2,8 @@ import { fetchNui } from './fetchNui.js';
|
|||
import { Global } from '../../lang/global.js';
|
||||
|
||||
let config;
|
||||
// Eine Variable, um ausstehende Spielerdaten zu speichern
|
||||
let pendingPlayerData = null;
|
||||
|
||||
/**
|
||||
* Get element by id
|
||||
|
@ -42,7 +44,19 @@ const closeFunction = () => {
|
|||
* @param playerData {Object}
|
||||
**/
|
||||
const openIdCard = (playerData) => {
|
||||
// Überprüfen, ob config und config.Licenses existieren
|
||||
if (!config || !config.Licenses) {
|
||||
console.error('Config oder Licenses nicht initialisiert. Bitte stellen Sie sicher, dass configData vor playerData gesendet wird.');
|
||||
return;
|
||||
}
|
||||
|
||||
// Überprüfen, ob der cardtype gültig ist
|
||||
const license = config.Licenses[playerData.cardtype];
|
||||
if (!license) {
|
||||
console.error(`Lizenztyp "${playerData.cardtype}" nicht in der Konfiguration gefunden`);
|
||||
return;
|
||||
}
|
||||
|
||||
const elements = {
|
||||
lastname: playerData.lastname,
|
||||
name: playerData.firstname,
|
||||
|
@ -67,16 +81,32 @@ const openIdCard = (playerData) => {
|
|||
};
|
||||
|
||||
const autoClose = () => {
|
||||
if (!config.IdCardSettings.autoClose.status) return;
|
||||
if (!config || !config.IdCardSettings || !config.IdCardSettings.autoClose || !config.IdCardSettings.autoClose.status) return;
|
||||
setTimeout(closeFunction, config.IdCardSettings.autoClose.time);
|
||||
};
|
||||
|
||||
window.addEventListener('message', (event) => {
|
||||
const { type, playerData, configData } = event.data;
|
||||
if (type === 'playerData') {
|
||||
openIdCard(playerData);
|
||||
} else if (type === 'configData') {
|
||||
|
||||
if (type === 'configData') {
|
||||
config = configData;
|
||||
|
||||
// Wenn es ausstehende Spielerdaten gibt, verarbeiten Sie diese jetzt
|
||||
if (pendingPlayerData) {
|
||||
openIdCard(pendingPlayerData);
|
||||
pendingPlayerData = null;
|
||||
}
|
||||
}
|
||||
else if (type === 'playerData') {
|
||||
// Wenn die Konfiguration bereits geladen ist, öffnen Sie die ID-Karte
|
||||
if (config) {
|
||||
openIdCard(playerData);
|
||||
}
|
||||
// Andernfalls speichern Sie die Spielerdaten für später
|
||||
else {
|
||||
pendingPlayerData = playerData;
|
||||
console.log('Konfiguration noch nicht geladen. Spielerdaten werden für später gespeichert.');
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
|
@ -87,6 +117,6 @@ window.addEventListener('load', () => {
|
|||
});
|
||||
|
||||
document.addEventListener('keydown', (e) => {
|
||||
if (e.key !== config.IdCardSettings.closeKey) return;
|
||||
if (!config || !config.IdCardSettings || e.key !== config.IdCardSettings.closeKey) return;
|
||||
closeFunction();
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue