2026-04-15 22:30:01 +02:00

117 lines
3.3 KiB
JavaScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

// ═══════════════════════════════════════════════════
// MercyV Bike NUI Script
// ═══════════════════════════════════════════════════
function postNUI(event, data) {
return $.post(`https://${GetParentResourceName()}/${event}`, JSON.stringify(data || {}));
}
const app = new Vue({
data: {
show: false, // WICHTIG: immer false beim Start
showAdmin: false,
isAdmin: false,
bikes: [],
selected: null,
claimed: false,
claimedModel: null,
npc: {
model: 'a_m_m_beach_01',
x: 0,
y: 0,
z: 0,
heading: 0,
},
};
},
mounted() {
// Vue ist gemountet - div kann jetzt gesteuert werden
document.getElementById('app').style.display = '';
},
methods: {
close() {
this.show = false;
this.showAdmin = false;
this.selected = null;
postNUI('close');
},
claimBike() {
if (!this.selected) return;
postNUI('claimBike', { model: this.selected });
},
selectBike(model) {
this.selected = this.selected === model ? null : model;
},
openAdmin() {
this.showAdmin = true;
},
closeAdmin() {
this.showAdmin = false;
postNUI('close');
},
capturePos() {
postNUI('capturePos', {});
},
saveNPC() {
postNUI('saveNPC', { ...this.npc });
},
},
el: '#app'
});
// ── Message Handler ────────────────────────────────
window.addEventListener('message', function(event) {
const msg = event.data;
switch (msg.action) {
case 'OPEN':
app.show = true;
app.showAdmin = false;
app.bikes = msg.bikes || [];
app.isAdmin = msg.isAdmin || false;
app.selected = null;
break;
case 'OPEN_ADMIN':
app.show = true;
app.showAdmin = true;
app.isAdmin = true;
if (msg.captured) {
app.npc.x = Math.round(msg.captured.x * 100) / 100;
app.npc.y = Math.round(msg.captured.y * 100) / 100;
app.npc.z = Math.round(msg.captured.z * 100) / 100;
app.npc.heading = Math.round(msg.captured.heading * 100) / 100;
}
break;
case 'CLOSE':
app.show = false;
app.showAdmin = false;
break;
case 'SET_ADMIN':
app.isAdmin = msg.isAdmin;
break;
case 'SET_CLAIM_STATUS':
app.claimed = msg.claimed;
app.claimedModel = msg.model || null;
break;
}
});
// ESC schließt Panel
document.addEventListener('keydown', function(e) {
if (e.key === 'Escape' && app.show) {
app.close();
}
});