Skip to content

Commit 79994a4

Browse files
author
Alex Moon
committed
GL-142 - indicate localised great circle cardinal direction
1 parent f96dc81 commit 79994a4

File tree

19 files changed

+232
-43
lines changed

19 files changed

+232
-43
lines changed

src/components/Guesser.tsx

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ import localeList from "../i18n/messages";
99
import { FormattedMessage } from "react-intl";
1010
import { langNameMap } from "../i18n/locales";
1111
import { AltNames } from "../lib/alternateNames";
12+
import {polygonDirection} from "../util/direction";
1213
const countryData: Country[] = require("../data/country_data.json").features;
1314
const alternateNames: AltNames = require("../data/alternate_names.json");
1415

@@ -99,22 +100,21 @@ export default function Guesser({
99100
e.preventDefault();
100101
setError("");
101102
let guessCountry = runChecks();
103+
let guessAnswerCountry = answerCountry;
102104
if (practiceMode) {
103-
const answerCountry = JSON.parse(
105+
guessAnswerCountry = JSON.parse(
104106
localStorage.getItem("practice") as string
105107
);
106-
if (guessCountry && answerCountry) {
107-
guessCountry["proximity"] = polygonDistance(
108-
guessCountry,
109-
answerCountry
110-
);
111-
setGuesses([...guesses, guessCountry]);
112-
setGuessName("");
113-
return;
114-
}
115108
}
116-
if (guessCountry && answerCountry) {
117-
guessCountry["proximity"] = polygonDistance(guessCountry, answerCountry);
109+
if (guessCountry && guessAnswerCountry) {
110+
guessCountry.proximity = polygonDistance(
111+
guessCountry,
112+
guessAnswerCountry
113+
);
114+
guessCountry.direction = polygonDirection(
115+
guessCountry,
116+
guessAnswerCountry
117+
);
118118
setGuesses([...guesses, guessCountry]);
119119
setGuessName("");
120120
}

src/components/List.tsx

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
import { SyntheticEvent, useContext, useEffect, useState } from "react";
22
import { GlobeMethods } from "react-globe.gl";
3-
import { FormattedMessage } from "react-intl";
3+
import { FormattedMessage, useIntl } from "react-intl";
44
import { LocaleContext } from "../i18n/LocaleContext";
5-
import { Country, LanguageName } from "../lib/country";
5+
import {Country, LanguageName} from "../lib/country";
66
import { Locale } from "../lib/locale";
77
import { answerName } from "../util/answer";
88
import { findCentre, turnGlobe } from "../util/globe";
@@ -95,6 +95,7 @@ export default function List({ guesses, win, globeRef, practiceMode }: Props) {
9595

9696
const [isSortedByDistance, setIsSortedByDistance] = useState(true);
9797
const guessesToDisplay = isSortedByDistance ? orderedGuesses : guesses;
98+
const intl = useIntl();
9899

99100
return (
100101
<div className="md:ml-10 md:mr-0 py-8 dark:text-white z-30 mb-20">
@@ -152,6 +153,12 @@ export default function List({ guesses, win, globeRef, practiceMode }: Props) {
152153
off="miles"
153154
/>
154155
</div>
156+
<div className="flex items-center space-x-1">
157+
<p>
158+
<FormattedMessage id="Game9" />:{" "}
159+
{intl.formatMessage({id:closest?.direction})}
160+
</p>
161+
</div>
155162
<p>
156163
<button
157164
onClick={() => setIsSortedByDistance(!isSortedByDistance)}

src/components/Outline.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import { useContext } from "react";
55
import { ThemeContext } from "../context/ThemeContext";
66
import { getPath } from "../util/svg";
77
import { FormattedMessage } from "react-intl";
8+
import {polygonDirection} from "../util/direction";
89
const countryData: Country[] = require("../data/country_data.json").features;
910

1011
type Props = {
@@ -27,7 +28,14 @@ export default function Outline({ countryName, width }: Props) {
2728
if (!sampleAnswer)
2829
throw new Error("Country in Help screen not found in Country Data");
2930

30-
countryCopy["proximity"] = polygonDistance(countryCopy, sampleAnswer);
31+
countryCopy.proximity = polygonDistance(
32+
countryCopy,
33+
sampleAnswer
34+
);
35+
countryCopy.direction = polygonDirection(
36+
countryCopy,
37+
sampleAnswer
38+
);
3139

3240
const outline = getPath(countryName);
3341

src/i18n/messages/de-DE.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ export const German: Messages = {
4545
Game6: "Das Land wurde schon versucht",
4646
Game7: "Das geheime Land ist {answer}!",
4747
Game8: "Nächste Grenze",
48+
Game9: "Richtung",
49+
N: "Norden",
50+
NE: "Nordosten",
51+
E: "Osten",
52+
SE: "Südosten",
53+
S: "Süden",
54+
SW: "Südwesten",
55+
W: "Westen",
56+
NW: "Nordwesten",
4857
StatsTitle: "Statistiken",
4958
Stats1: "Letzter Sieg",
5059
Stats2: "Heutige Versuche",

src/i18n/messages/en-CA.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,15 @@ export const English: Messages = {
4747
Game6: "Country already guessed",
4848
Game7: "The Mystery Country is {answer}!",
4949
Game8: "Closest border",
50+
Game9: "Direction",
51+
N: "north",
52+
NE: "northeast",
53+
E: "east",
54+
SE: "southeast",
55+
S: "south",
56+
SW: "southwest",
57+
W: "west",
58+
NW: "northwest",
5059
StatsTitle: "Statistics",
5160
Stats1: "Last win",
5261
Stats2: "Today's guesses",

src/i18n/messages/es-MX.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,15 @@ export const Spanish: Messages = {
4242
Game6: "Pais ya adivinado",
4343
Game7: "¡El País Secreto es {answer}!",
4444
Game8: "Frontera más cercana",
45+
Game9: "Dirección",
46+
N: "norte",
47+
NE: "noreste",
48+
E: "este",
49+
SE: "sureste",
50+
S: "sur",
51+
SW: "suroeste",
52+
W: "oeste",
53+
NW: "noroeste",
4554
StatsTitle: "Estadísticas",
4655
Stats1: "Última victoria ",
4756
Stats2: "Intentos de hoy",

src/i18n/messages/fr-FR.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ export const French: Messages = {
4646
Game6: "Pays déjà tenté",
4747
Game7: "Le pays mystère est: {answer}!",
4848
Game8: "Frontière la plus proche",
49+
Game9: "Direction",
50+
N: "nord",
51+
NE: "nord-est",
52+
E: "est",
53+
SE: "sud-este",
54+
S: "sud",
55+
SW: "sud-oueste",
56+
W: "ouest",
57+
NW: "nord-ouest",
4958
StatsTitle: "Statistiques",
5059
Stats1: "Dernière victoire",
5160
Stats2: "Tentatives d'aujourd'hui",

src/i18n/messages/hu-HU.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,15 @@ export const Hungarian: Messages = {
4545
Game6: "Ezt az országot már próbáltad",
4646
Game7: "A keresett ország {answer}!",
4747
Game8: "Legközelebbi határ:",
48+
Game9: "Irány:",
49+
N: "észak",
50+
NE: "észak-kelet",
51+
E: "kelet",
52+
SE: "dél-kelet",
53+
S: "dél",
54+
SW: "dél-nyugat",
55+
W: "nyugat",
56+
NW: "észak-nyugat",
4857
StatsTitle: "Statisztika",
4958
Stats1: "Utolsó nyerés",
5059
Stats2: "Mai próbálkozások",

src/i18n/messages/it_IT.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,15 @@ export const Italian: Messages = {
4646
Game6: "Paese già provato",
4747
Game7: "Il paese misterioso è {answer}!",
4848
Game8: "Confine più vicino",
49+
Game9: "Direzione",
50+
N: "nord",
51+
NE: "nord-est",
52+
E: "est",
53+
SE: "sud-este",
54+
S: "sud",
55+
SW: "sud-ovest",
56+
W: "ovest",
57+
NW: "nord-ovest",
4958
StatsTitle: "Statistiche",
5059
Stats1: "Ultima vittoria",
5160
Stats2: "Tentativi di oggi",

src/i18n/messages/pl-PL.ts

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,15 @@ export const Polish: Messages = {
4141
Game6: "Ten kraj już się pojawił",
4242
Game7: "Tajemniczy Kraj to {answer}!",
4343
Game8: "Najbliższa granica",
44+
Game9: "Kierunek",
45+
N: "północ",
46+
NE: "północny wschód",
47+
E: "wschód",
48+
SE: "południowy wschód",
49+
S: "południe",
50+
SW: "południowy zachód",
51+
W: "zachód",
52+
NW: "północny zachód",
4453
StatsTitle: "Statystyki",
4554
Stats1: "Ostatnie zwycięstwo",
4655
Stats2: "Dzisiejsze próby",

0 commit comments

Comments
 (0)