forked from thesam73/wordle
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathshare.ts
48 lines (45 loc) · 1.31 KB
/
share.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import { getGuessStatuses } from './statuses'
import { solutionIndex } from './words'
import { GAME_TITLE } from '../constants/strings'
import { MAX_CHALLENGES } from '../constants/settings'
export const shareStatus = (
guesses: string[],
lost: boolean,
isHardMode: boolean,
isDarkMode: boolean,
isHighContrastMode: boolean
) => {
navigator.clipboard.writeText(
`${GAME_TITLE} ${solutionIndex} ${
lost ? 'X' : guesses.length
}/${MAX_CHALLENGES}${isHardMode ? '*' : ''}\n\n` +
generateEmojiGrid(guesses, getEmojiTiles(isDarkMode, isHighContrastMode))
)
}
export const generateEmojiGrid = (guesses: string[], tiles: string[]) => {
return guesses
.map((guess) => {
const status = getGuessStatuses(guess)
return guess
.split('')
.map((_, i) => {
switch (status[i]) {
case 'correct':
return tiles[0]
case 'present':
return tiles[1]
default:
return tiles[2]
}
})
.join('')
})
.join('\n')
}
const getEmojiTiles = (isDarkMode: boolean, isHighContrastMode: boolean) => {
let tiles: string[] = []
tiles.push(isHighContrastMode ? '🟧' : '🟩')
tiles.push(isHighContrastMode ? '🟦' : '🟨')
tiles.push(isDarkMode ? '⬛' : '⬜')
return tiles
}