Merge branch 'main' of https://github.com/MasterGordon/minesweeper into main
This commit is contained in:
commit
d1dae6aba9
|
|
@ -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"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -3,21 +3,6 @@ export const pickRandom = <T>(arr: T[]) => {
|
||||||
return arr[index];
|
return arr[index];
|
||||||
};
|
};
|
||||||
|
|
||||||
function bashHashStr(str: string) {
|
|
||||||
let hash = 5381,
|
|
||||||
i = str.length;
|
|
||||||
|
|
||||||
while (i) {
|
|
||||||
hash = (hash * 33) ^ str.charCodeAt(--i);
|
|
||||||
}
|
|
||||||
|
|
||||||
return hash >>> 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
export const hashStr = (str: string) => {
|
|
||||||
return Number(`0.${bashHashStr(str)}`);
|
|
||||||
};
|
|
||||||
|
|
||||||
export const weightedPickRandom = <T>(
|
export const weightedPickRandom = <T>(
|
||||||
arr: T[],
|
arr: T[],
|
||||||
getWeight: (item: T) => number = () => 1,
|
getWeight: (item: T) => number = () => 1,
|
||||||
|
|
|
||||||
|
|
@ -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;
|
||||||
|
|
|
||||||
|
|
@ -51,7 +51,7 @@ export const mainWithSpecials = (
|
||||||
const [main, ...specials] = sprites;
|
const [main, ...specials] = sprites;
|
||||||
return [
|
return [
|
||||||
{ weight: 1, sprite: main },
|
{ weight: 1, sprite: main },
|
||||||
...specials.map((sprite) => ({ weight: 0.3, sprite })),
|
...specials.map((sprite) => ({ weight: 0.05, sprite })),
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue