2025-03-15 10:34:01 +01:00
|
|
|
import { RawLevel } from "./types";
|
2025-03-13 14:14:00 +01:00
|
|
|
|
2025-03-16 17:45:29 +01:00
|
|
|
import _backgrounds from "./data/backgrounds.json";
|
2025-03-13 14:14:00 +01:00
|
|
|
const backgrounds = _backgrounds as string[];
|
2025-03-15 10:34:01 +01:00
|
|
|
export function getLevelBackground(level: RawLevel) {
|
2025-04-03 15:15:00 +02:00
|
|
|
return backgrounds[hashCode(level.name) % backgrounds.length];
|
2025-03-14 16:13:43 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
export function hashCode(string: string) {
|
|
|
|
let hash = 0;
|
|
|
|
for (let i = 0; i < string.length; i++) {
|
|
|
|
let code = string.charCodeAt(i);
|
|
|
|
hash = (hash << 5) - hash + code;
|
|
|
|
hash = hash & hash; // Convert to 32bit integer
|
|
|
|
}
|
|
|
|
return Math.abs(hash);
|
|
|
|
}
|