Allow rare challenge words
This commit is contained in:
19
src/Game.tsx
19
src/Game.tsx
@@ -4,7 +4,7 @@ import dictionary from "./dictionary.json";
|
|||||||
import { Clue, clue, describeClue, violation } from "./clue";
|
import { Clue, clue, describeClue, violation } from "./clue";
|
||||||
import { Keyboard } from "./Keyboard";
|
import { Keyboard } from "./Keyboard";
|
||||||
import targetList from "./targets.json";
|
import targetList from "./targets.json";
|
||||||
import { pick, resetRng, seed, speak, urlParam } from "./util";
|
import { dictionarySet, pick, resetRng, seed, speak, urlParam } from "./util";
|
||||||
import { decode, encode } from "./base64";
|
import { decode, encode } from "./base64";
|
||||||
|
|
||||||
enum GameState {
|
enum GameState {
|
||||||
@@ -31,19 +31,24 @@ function randomTarget(wordLength: number): string {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function getChallengeUrl(target: string): string {
|
function getChallengeUrl(target: string): string {
|
||||||
return window.location.origin + window.location.pathname + "?challenge=" + encode(target);
|
return (
|
||||||
|
window.location.origin +
|
||||||
|
window.location.pathname +
|
||||||
|
"?challenge=" +
|
||||||
|
encode(target)
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
let challengeString = "";
|
let initChallenge = "";
|
||||||
let challengeError = false;
|
let challengeError = false;
|
||||||
try {
|
try {
|
||||||
challengeString = decode(urlParam("challenge") ?? "").toLowerCase();
|
initChallenge = decode(urlParam("challenge") ?? "").toLowerCase();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.warn(e);
|
console.warn(e);
|
||||||
challengeError = true;
|
challengeError = true;
|
||||||
}
|
}
|
||||||
if (challengeString && !targets.includes(challengeString)) {
|
if (initChallenge && !dictionarySet.has(initChallenge)) {
|
||||||
challengeString = "";
|
initChallenge = "";
|
||||||
challengeError = true;
|
challengeError = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -56,7 +61,7 @@ function Game(props: GameProps) {
|
|||||||
? `Invalid challenge string, playing random game.`
|
? `Invalid challenge string, playing random game.`
|
||||||
: `Make your first guess!`
|
: `Make your first guess!`
|
||||||
);
|
);
|
||||||
const [challenge, setChallenge] = useState<string>(challengeString);
|
const [challenge, setChallenge] = useState<string>(initChallenge);
|
||||||
const [wordLength, setWordLength] = useState(
|
const [wordLength, setWordLength] = useState(
|
||||||
challenge ? challenge.length : 5
|
challenge ? challenge.length : 5
|
||||||
);
|
);
|
||||||
|
|||||||
Reference in New Issue
Block a user