1
0
mirror of https://github.com/tobspr/shapez.io.git synced 2026-03-02 03:39:21 +00:00

Initial commit

This commit is contained in:
Tobias Springer
2020-05-09 16:45:23 +02:00
commit 93c6ea683d
304 changed files with 56031 additions and 0 deletions

View File

@@ -0,0 +1,16 @@
// We clamp high deltas so 30 fps is fairly ok
const bgFps = 30;
const desiredMsDelay = 1000 / bgFps;
let lastTick = 0;
function tick() {
const now = performance.now();
const delta = now - lastTick;
lastTick = now;
// @ts-ignore
postMessage({ delta });
}
setInterval(tick, desiredMsDelay);

View File

@@ -0,0 +1,48 @@
import { compressX64 } from "../core/lzstring";
import { globalConfig } from "../core/config";
import { sha1 } from "../core/sensitive_utils.encrypt";
function accessNestedPropertyReverse(obj, keys) {
let result = obj;
for (let i = keys.length - 1; i >= 0; --i) {
result = result[keys[i]];
}
return result;
}
const rusha = require("rusha");
const salt = accessNestedPropertyReverse(globalConfig, ["file", "info"]);
const encryptKey = globalConfig.info.sgSalt;
onmessage = function (event) {
const { jobId, job, data } = event.data;
const result = performJob(job, data);
// @ts-ignore
postMessage({
jobId,
result,
});
};
function performJob(job, data) {
switch (job) {
case "compressX64": {
return compressX64(data);
}
case "compressWithChecksum": {
const checksum = rusha
.createHash()
.update(data + encryptKey)
.digest("hex");
return compressX64(checksum + data);
}
case "compressFile": {
const checksum = sha1(data.text + salt);
return data.compressionPrefix + compressX64(checksum + data.text);
}
default:
throw new Error("Webworker: Unknown job: " + job);
}
}