Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
TheLazySquid
GitHub Repository: TheLazySquid/GimkitCheat
Path: blob/main/src/stores.ts
8160 views
1
import { writable } from 'svelte/store';
2
import { getUnsafeWindow } from './utils';
3
import socketManager from './network/socketManager';
4
import { IColyseusMessage } from './types';
5
6
export const showHud = writable(true);
7
export const storesLoaded = writable(false);
8
9
getUnsafeWindow().storesLoaded = storesLoaded;
10
11
export const playerId = writable<null | string>(null);
12
13
socketManager.addEventListener('colyseusMessage', ((event: CustomEvent<IColyseusMessage>) => {
14
if(event.detail.type !== 'AUTH_ID') return;
15
16
playerId.set(event.detail.message);
17
console.log("[GC] Got player id: " + event.detail.message)
18
}) as any);
19
20
export const devicesLoaded = writable(false);
21
22
socketManager.addEventListener('colyseusMessage', (e: any) => {
23
if(e.detail.type === 'DEVICES_STATES_CHANGES') {
24
// it takes a sec for the devices to get applied, for some reason?
25
let checkInterval = setInterval(() => {
26
let devices = getUnsafeWindow()?.stores?.phaser?.scene?.worldManager?.devices?.allDevices;
27
if(!devices) return;
28
if(devices.length >= e.detail.message.changes.length) {
29
clearInterval(checkInterval);
30
devicesLoaded.set(true);
31
}
32
}, 100)
33
}
34
})
35