Colorblind mode fixes

This commit is contained in:
Lynn
2022-01-27 22:13:39 +01:00
parent 51453990bf
commit 4a07e05759
5 changed files with 29 additions and 52 deletions

View File

@@ -2,11 +2,7 @@ import { Clue } from "./clue";
import { Row, RowState } from "./Row"; import { Row, RowState } from "./Row";
import { maxGuesses } from "./util"; import { maxGuesses } from "./util";
interface aboutProps { export function About() {
color: boolean;
}
export function About(props: aboutProps) {
return ( return (
<div className="App-about"> <div className="App-about">
<p> <p>
@@ -32,21 +28,19 @@ export function About(props: aboutProps) {
{ clue: Clue.Correct, letter: "r" }, { clue: Clue.Correct, letter: "r" },
{ clue: Clue.Elsewhere, letter: "d" }, { clue: Clue.Elsewhere, letter: "d" },
]} ]}
color={props.color}
/> />
<p> <p>
<b>W</b> and <b>O</b> aren't in the target word at all. <b>W</b> and <b>O</b> aren't in the target word at all.
</p> </p>
<p> <p>
<b className={props.color ? "orange-bg" : "green-bg"}>R</b> is correct! <b className={"green-bg"}>R</b> is correct! The third letter is{" "}
The third letter is{" "} <b className={"green-bg"}>R</b>
<b className={props.color ? "orange-bg" : "green-bg"}>R</b>
.<br /> .<br />
<strong>(There may still be a second R in the word.)</strong> <strong>(There may still be a second R in the word.)</strong>
</p> </p>
<p> <p>
<b className={props.color ? "blue-bg" : "yellow-bg"}>D</b> occurs{" "} <b className={"yellow-bg"}>D</b> occurs <em>elsewhere</em> in the target
<em>elsewhere</em> in the target word. word.
<br /> <br />
<strong>(Perhaps more than once. 🤔)</strong> <strong>(Perhaps more than once. 🤔)</strong>
</p> </p>
@@ -64,7 +58,6 @@ export function About(props: aboutProps) {
{ clue: Clue.Absent, letter: "k" }, { clue: Clue.Absent, letter: "k" },
]} ]}
annotation={"So close!"} annotation={"So close!"}
color={props.color}
/> />
<Row <Row
rowState={RowState.LockedIn} rowState={RowState.LockedIn}
@@ -76,7 +69,6 @@ export function About(props: aboutProps) {
{ clue: Clue.Correct, letter: "t" }, { clue: Clue.Correct, letter: "t" },
]} ]}
annotation={"Got it!"} annotation={"Got it!"}
color={props.color}
/> />
<p> <p>
Report issues{" "} Report issues{" "}

View File

@@ -121,35 +121,18 @@ table.Game-rows > tbody {
outline: none; outline: none;
} }
.Row-letter-color.letter-correct {
border: 2px solid rgba(0, 0, 0, 0.3);
background-color: #f5793a;
color: white !important;
}
.letter-correct { .letter-correct {
border: 2px solid rgba(0, 0, 0, 0.3); border: 2px solid rgba(0, 0, 0, 0.3);
background-color: rgb(87, 172, 120); background-color: rgb(87, 172, 120);
color: white !important; color: white !important;
} }
.Row-letter-color.letter-elsewhere {
border: 2px dotted rgba(0, 0, 0, 0.3);
background-color: #85c0f9;
color: white !important;
}
.letter-elsewhere { .letter-elsewhere {
border: 2px dotted rgba(0, 0, 0, 0.3); border: 2px dotted rgba(0, 0, 0, 0.3);
background-color: #e9c601; background-color: #e9c601;
color: white !important; color: white !important;
} }
.Row-letter-color.letter-absent {
border: 2px solid transparent;
background-color: rgb(162, 162, 162);
color: white !important;
}
.letter-absent { .letter-absent {
border: 2px solid transparent; border: 2px solid transparent;
background-color: rgb(162, 162, 162); background-color: rgb(162, 162, 162);
@@ -210,16 +193,10 @@ a:active {
.App-about b.green-bg { .App-about b.green-bg {
background-color: rgb(87, 172, 120); background-color: rgb(87, 172, 120);
} }
.App-about b.orange-bg {
background-color: #f5793a;
}
.App-about b.yellow-bg { .App-about b.yellow-bg {
background-color: #e9c601; background-color: #e9c601;
} }
.App-about b.blue-bg {
background-color: #85c0f9;
}
.Game-seed-info { .Game-seed-info {
opacity: 0.5; opacity: 0.5;
@@ -276,3 +253,13 @@ a:active {
.top-right a + a { .top-right a + a {
margin-inline-start: 8px; margin-inline-start: 8px;
} }
.App-container.color-blind .letter-correct,
.App-container.color-blind .App-about b.green-bg {
background-color: #f5793a;
}
.App-container.color-blind .letter-elsewhere,
.App-container.color-blind .App-about b.yellow-bg {
background-color: #85c0f9;
}

View File

@@ -33,7 +33,7 @@ function App() {
window.matchMedia && window.matchMedia &&
window.matchMedia("(prefers-color-scheme: dark)").matches; window.matchMedia("(prefers-color-scheme: dark)").matches;
const [dark, setDark] = useSetting<boolean>("dark", prefersDark); const [dark, setDark] = useSetting<boolean>("dark", prefersDark);
const [color, setColor] = useSetting<boolean>("color", false); const [colorBlind, setColorBlind] = useSetting<boolean>("colorblind", false);
const [difficulty, setDifficulty] = useSetting<number>("difficulty", 0); const [difficulty, setDifficulty] = useSetting<number>("difficulty", 0);
useEffect(() => { useEffect(() => {
@@ -57,7 +57,7 @@ function App() {
); );
return ( return (
<div className="App-container"> <div className={"App-container" + (colorBlind ? " color-blind" : "")}>
<h1> <h1>
<span <span
style={{ style={{
@@ -99,7 +99,7 @@ function App() {
{seed ? "Random" : "Today's"} {seed ? "Random" : "Today's"}
</a> </a>
</div> </div>
{page === "about" && <About color={color} />} {page === "about" && <About />}
{page === "settings" && ( {page === "settings" && (
<div className="Settings"> <div className="Settings">
<div className="Settings-setting"> <div className="Settings-setting">
@@ -113,15 +113,12 @@ function App() {
</div> </div>
<div className="Settings-setting"> <div className="Settings-setting">
<input <input
id="color-setting" id="colorblind-setting"
type="checkbox" type="checkbox"
checked={color} checked={colorBlind}
onChange={() => { onChange={() => setColorBlind((x: boolean) => !x)}
console.log("set color to ", !color);
setColor((x: boolean) => !x);
}}
/> />
<label htmlFor="color-setting">Color Blind Mode</label> <label htmlFor="colorblind-setting">Color blind mode</label>
</div> </div>
<div className="Settings-setting"> <div className="Settings-setting">
<input <input
@@ -160,7 +157,7 @@ function App() {
maxGuesses={maxGuesses} maxGuesses={maxGuesses}
hidden={page !== "game"} hidden={page !== "game"}
difficulty={difficulty} difficulty={difficulty}
color={color} colorBlind={colorBlind}
/> />
</div> </div>
); );

View File

@@ -25,7 +25,7 @@ interface GameProps {
maxGuesses: number; maxGuesses: number;
hidden: boolean; hidden: boolean;
difficulty: Difficulty; difficulty: Difficulty;
color: boolean; colorBlind: boolean;
} }
const targets = targetList.slice(0, targetList.indexOf("murky") + 1); // Words no rarer than this one const targets = targetList.slice(0, targetList.indexOf("murky") + 1); // Words no rarer than this one
@@ -220,7 +220,6 @@ function Game(props: GameProps) {
: RowState.Pending : RowState.Pending
} }
cluedLetters={cluedLetters} cluedLetters={cluedLetters}
color={props.color}
/> />
); );
}); });
@@ -297,13 +296,16 @@ function Game(props: GameProps) {
</button>{" "} </button>{" "}
<button <button
onClick={() => { onClick={() => {
const emoji = props.colorBlind
? ["⬛", "🟦", "🟧"]
: ["⬛", "🟨", "🟩"];
share( share(
getChallengeUrl(target), getChallengeUrl(target),
"Result copied to clipboard!", "Result copied to clipboard!",
guesses guesses
.map((guess) => .map((guess) =>
clue(guess, target) clue(guess, target)
.map((c) => ["⬛", "🟨", "🟩"][c.clue ?? 0]) .map((c) => emoji[c.clue ?? 0])
.join("") .join("")
) )
.join("\n") .join("\n")

View File

@@ -11,7 +11,6 @@ interface RowProps {
wordLength: number; wordLength: number;
cluedLetters: CluedLetter[]; cluedLetters: CluedLetter[];
annotation?: string; annotation?: string;
color: boolean;
} }
export function Row(props: RowProps) { export function Row(props: RowProps) {
@@ -21,7 +20,7 @@ export function Row(props: RowProps) {
.concat(Array(props.wordLength).fill({ clue: Clue.Absent, letter: "" })) .concat(Array(props.wordLength).fill({ clue: Clue.Absent, letter: "" }))
.slice(0, props.wordLength) .slice(0, props.wordLength)
.map(({ clue, letter }, i) => { .map(({ clue, letter }, i) => {
let letterClass = props.color ? "Row-letter-color" : "Row-letter"; let letterClass = "Row-letter";
if (isLockedIn && clue !== undefined) { if (isLockedIn && clue !== undefined) {
letterClass += " " + clueClass(clue); letterClass += " " + clueClass(clue);
} }