fixed rng

This commit is contained in:
MasterGordon 2024-10-18 18:12:02 +02:00
parent 42ad2204f7
commit d1c7d4d0da
3 changed files with 9 additions and 5 deletions

BIN
bun.lockb

Binary file not shown.

View File

@ -40,6 +40,7 @@
"pixi.js": "^7.0.0", "pixi.js": "^7.0.0",
"pixi.js-legacy": "^7.4.2", "pixi.js-legacy": "^7.4.2",
"prom-client": "^15.1.3", "prom-client": "^15.1.3",
"random-seed": "^0.3.0",
"react": "^18.3.1", "react": "^18.3.1",
"react-confetti-boom": "^1.0.0", "react-confetti-boom": "^1.0.0",
"react-dom": "^18.3.1", "react-dom": "^18.3.1",
@ -49,11 +50,11 @@
"zod": "^3.23.8" "zod": "^3.23.8"
}, },
"devDependencies": { "devDependencies": {
"vite-imagetools": "^7.0.4",
"tailwindcss": "^4.0.0-alpha.26",
"@eslint/compat": "^1.2.0", "@eslint/compat": "^1.2.0",
"@eslint/js": "^9.12.0", "@eslint/js": "^9.12.0",
"@tailwindcss/vite": "next",
"@types/bun": "latest", "@types/bun": "latest",
"@types/random-seed": "^0.3.5",
"@types/react": "^18.3.11", "@types/react": "^18.3.11",
"@types/react-dom": "^18.3.1", "@types/react-dom": "^18.3.1",
"@vitejs/plugin-react-swc": "^3.7.1", "@vitejs/plugin-react-swc": "^3.7.1",
@ -62,9 +63,10 @@
"eslint-plugin-react": "^7.37.1", "eslint-plugin-react": "^7.37.1",
"eslint-plugin-react-hooks": "5.0.0", "eslint-plugin-react-hooks": "5.0.0",
"globals": "^15.11.0", "globals": "^15.11.0",
"tailwindcss": "^4.0.0-alpha.26",
"typescript": "^5.6.3", "typescript": "^5.6.3",
"typescript-eslint": "^8.8.1", "typescript-eslint": "^8.8.1",
"vite": "^5.4.8", "vite": "^5.4.8",
"@tailwindcss/vite": "next" "vite-imagetools": "^7.0.4"
} }
} }

View File

@ -42,7 +42,8 @@ import "@pixi/canvas-sprite-tiling";
import "@pixi/canvas-sprite"; import "@pixi/canvas-sprite";
import "@pixi/canvas-text"; import "@pixi/canvas-text";
import { themes } from "../themes"; import { themes } from "../themes";
import { hashStr, weightedPickRandom } from "../../shared/utils"; import { weightedPickRandom } from "../../shared/utils";
import gen from "random-seed";
interface BoardProps { interface BoardProps {
className?: string; className?: string;
@ -280,10 +281,11 @@ const Tile = ({
const resolveSprite = useCallback( const resolveSprite = useCallback(
(lt: LoadedTexture) => { (lt: LoadedTexture) => {
if (Array.isArray(lt)) { if (Array.isArray(lt)) {
const rng = gen.create(game.uuid + ";" + x + ";" + y);
return weightedPickRandom( return weightedPickRandom(
lt, lt,
(i) => i.weight, (i) => i.weight,
(tw) => hashStr(game.uuid + ";" + x + ";" + y) * tw, (tw) => rng.floatBetween(0, tw),
).sprite; ).sprite;
} }
return lt; return lt;