feat: Implemented emulator installation
feat: Updated romm API version feat: Updated es-de rules feat: Added tabs to game details refactor: returned to global query definitions to help with typescript performance
This commit is contained in:
parent
cf6fff6fac
commit
3750e9ed8f
103 changed files with 4888 additions and 1632 deletions
|
|
@ -1,5 +1,7 @@
|
|||
import { $ } from 'bun';
|
||||
import path from 'node:path';
|
||||
import { createHash } from "node:crypto";
|
||||
import { createReadStream } from "node:fs";
|
||||
|
||||
export function checkRunning (pid: number)
|
||||
{
|
||||
|
|
@ -68,4 +70,44 @@ export async function openExternal (target: string)
|
|||
{
|
||||
return $`open ${target}`.throws(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
export function hashFile (path: string, algorithm: "sha1" | "md5"): Promise<string>
|
||||
{
|
||||
return new Promise((resolve, reject) =>
|
||||
{
|
||||
const hash = createHash(algorithm);
|
||||
const stream = createReadStream(path);
|
||||
|
||||
stream.on("data", (data) => hash.update(data));
|
||||
stream.on("end", () => resolve(hash.digest("hex")));
|
||||
stream.on("error", reject);
|
||||
});
|
||||
}
|
||||
|
||||
export class SeededRandom
|
||||
{
|
||||
seed: number;
|
||||
|
||||
constructor(seed?: number)
|
||||
{
|
||||
this.seed = seed ?? new Date().getTime();
|
||||
}
|
||||
|
||||
next ()
|
||||
{
|
||||
var x = Math.sin(this.seed++) * 10000;
|
||||
return x - Math.floor(x);
|
||||
}
|
||||
}
|
||||
|
||||
export function shuffleInPlace (array: any[], startSeed?: number)
|
||||
{
|
||||
const random = new SeededRandom(startSeed);
|
||||
|
||||
for (let i = array.length - 1; i > 0; i--)
|
||||
{
|
||||
const j = Math.floor(random.next() * (i + 1));
|
||||
[array[i], array[j]] = [array[j], array[i]];
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue