From 8bcfbb815cf60669807624663d3d466633ada74d Mon Sep 17 00:00:00 2001 From: Nordi98 Date: Mon, 4 Aug 2025 05:48:00 +0200 Subject: [PATCH] Update main.js --- resources/[tools]/um-idcard/web/js/main.js | 40 +++++++++++++++++++--- 1 file changed, 35 insertions(+), 5 deletions(-) diff --git a/resources/[tools]/um-idcard/web/js/main.js b/resources/[tools]/um-idcard/web/js/main.js index 6bcddc74e..9bcfc3179 100644 --- a/resources/[tools]/um-idcard/web/js/main.js +++ b/resources/[tools]/um-idcard/web/js/main.js @@ -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(); });