1
0
Fork 0
forked from Simnation/Main
This commit is contained in:
Nordi98 2025-06-24 04:26:19 +02:00
parent c01fa3bb74
commit 2ccf477c6c
49 changed files with 6 additions and 2 deletions

View file

@ -0,0 +1,33 @@
import { onMount, onDestroy } from "svelte";
import JobStore from '../stores/JobStore';
import PanelStore from '../stores/PanelStore';
interface nuiMessage {
data: {
action: string,
[key: string]: any,
},
}
export function EventHandler() {
function mainEvent(event: nuiMessage) {
switch (event.data.action) {
case "sendjobs":
JobStore.receiveOpenMessage(event.data as any);
PanelStore.setShow(true);
break;
case "updatejob":
JobStore.recieveUpdateJob(event.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") {
}
}

View file

@ -0,0 +1,26 @@
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-multijob";
}
}
const resourceName = getResourceName();
try {
const resp = await fetch(`https://${resourceName}/${eventName}`, options);
return await resp.json();
} catch(err) {
}
}

View file

@ -0,0 +1,132 @@
import type { JobManifest } from '../types/types';
import type { nuiOpenMessage } from '../stores/JobStore';
export default function mockEventCall(data: unknown = {}) {
window.dispatchEvent(
new MessageEvent("message", {data})
);
};
export function exampleCall() {
setTimeout(() => {
mockEventCall({
action: 'show',
data: {
header: "Some Header!",
},
});
}, 100);
};
export function mockJobMenuOpen() {
const mockJobManifest: JobManifest = {
"whitelist": [
{
name: "police person",
label: "police person",
description: `Generate Lorem lpsum placeholder text.
Select the number of characters, words, sentences or paragraphs, and hit generate!`,
salary: 250,
gradeLabel: "Regular",
grade: 0,
active: 0,
icon: "fa-solid fa-trash-can",
},
{
name: "police chief",
label: "police chief",
description: "Blah blah blah",
salary: 500,
gradeLabel: "Boss",
grade: 0,
active: 1,
icon: "",
},
{
name: "police chief2",
label: "police chief2",
description: "Blah blah blah",
salary: 500,
gradeLabel: "Boss",
grade: 0,
active: 1,
icon: "",
},
{
name: "police chief3",
label: "police chief3",
description: "Blah blah blah",
salary: 500,
gradeLabel: "Boss",
grade: 0,
active: 1,
icon: "",
},
{
name: "police chief4",
label: "police chief4",
description: "Blah blah blah",
salary: 500,
gradeLabel: "Boss",
grade: 0,
active: 1,
icon: "",
},
],
"civilian": [
{
name: "taxi driver",
label: "taxi driver",
description: `Generate Lorem lpsum placeholder text.
Select the number of characters, words, sentences or paragraphs, and hit generate!`,
salary: 150,
gradeLabel: "Regular",
grade: 0,
active: 0,
icon: "",
},
{
name: "murdershot1",
label: "murdershot1",
description: "Take people's order and serve them food",
salary: 100,
gradeLabel: "Cashier",
grade: 0,
active: 0,
icon: "",
},
{
name: "murdershot2",
label: "murdershot2",
description: "Take people's order and serve them food",
salary: 100,
gradeLabel: "Cashier",
grade: 0,
active: 0,
icon: "",
},
{
name: "murdershot3",
label: "murdershot3",
description: "Take people's order and serve them food",
salary: 100,
gradeLabel: "Cashier",
grade: 0,
active: 0,
icon: "",
}
],
}
setTimeout(() => {
let sendData: nuiOpenMessage = {
activeJob: "murdershot1",
jobs: mockJobManifest,
onDuty: true,
side: "right",
}
mockEventCall({
action: 'sendjobs',
...sendData,
});
}, 1000);
}