24 lines
537 B
JavaScript
24 lines
537 B
JavaScript
const {all, idFrom: idFromRaw} = require('./packets.scwp');
|
|
|
|
let hasMapped = false;
|
|
const packetTo = new Map();
|
|
|
|
function mapPacketsToMs() {
|
|
const entries = Object.entries(all());
|
|
for (let i = 0; i < entries.length; i++) {
|
|
const [, M] = entries[i];
|
|
const {default: Packet} = M;
|
|
packetTo.set(Packet, M);
|
|
}
|
|
}
|
|
|
|
export function idFrom(Packet) {
|
|
if (!hasMapped) {
|
|
mapPacketsToMs();
|
|
hasMapped = true;
|
|
}
|
|
return idFromRaw(packetTo.get(Packet));
|
|
}
|
|
|
|
module.hot?.accept(['./packets.scwp'], () => hasMapped = false);
|