-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.html
255 lines (204 loc) · 11 KB
/
index.html
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="author" content="Dmitry Sharabin" />
<meta name="description" content="Clone of the famous Wordle game built with Mavo." >
<meta name="keywords" content="HTML,CSS,Mavo" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no" />
<!-- Mavo -->
<link rel="stylesheet prefetch" href="https://get.mavo.io/mavo.min.css" />
<script src="https://get.mavo.io/mavo.es5.min.js"></script>
<link rel="stylesheet prefetch" href="style.css" />
<link rel="icon" href='data:image/svg+xml,<svg xmlns="http://www.w3.org/2000/svg" viewBox="0 0 100 100"><text y=".9em" font-size="90">🔮</text></svg>' />
<title>Mavordle</title>
</head>
<body>
<header>
<h1 aria-label="Mavordle">
<img src="https://mavo.io/logo.svg" alt="Mavo logo" /><span>rdle</span>
</h1>
<label mv-app="mode" mv-storage="local" mv-autosave id="mode-switch">
<!-- Why [mv-action] on <input>? It's a workaround because the values of the attempt and correctLetters properties are not recalculated automatically. -->
Practice mode <input type="checkbox" property="practiceMode" mv-action="clear(game.usedLetters, game.guessLetters, game.guesses, game.result)" />
</label>
</header>
<main>
<section mv-app="game" mv-bar="none" class="[if(popup.isShowing or statistics.isShowing, backdrop)] [if(!mode.practiceMode, result)]">
<meta property="hiddenWord" content="[if(isOver, statistics.hiddenWord, commonWords.todaysWord)]" mv-if="false" />
<meta property="hiddenWordLetters" content="[split(hiddenWord, '')]" mv-if="false" />
<meta property="result" />
<meta property="isOver" content="[$today = statistics.date and !mode.practiceMode]" />
<meta property="attempt" content="[count(guesses) + 1]" />
<meta property="guess" content="[join(guessLetters)]" />
<meta property="guessLength" content="[len(guess)]" />
<meta property="guessValid" content="[guess in possibleWords.words or guess in commonWords.words]" />
<meta property="correctLetters" content="[unique(condense(usedLetters where (state = correct and !stateHidden)).letter)]" />
<div id="toolbar" role="toolbar">
<output property class="toast [if(seconds($now) - errorTime < 2, visible)]" role="status">
<meta property="errorTime" />
<p property="message"></p>
</output>
<button id="show-stats" mv-action="set(statistics.isShowing, true) clearif(result, result)" title="Show statistics">
<span class="visually-hidden">Show statistics</span>
</button>
</div>
<div mv-list="usedLetters" mv-value="if(isOver, statistics.usedLetters, list())" mv-initial-items="0">
<div mv-list-item>
<meta property="row" content="[floor($index / 5)]" />
<meta property="thisRowLetters" content="[split(get(guesses, row), '')]" />
<meta property="stateHidden" content="[row >= attempt - 1]" />
<meta property="errorTime" />
<meta property="state"
content="[if(get(hiddenWordLetters, $index mod 5) = letter, correct, if(letter in hiddenWordLetters, if(letter in filter(hiddenWordLetters, hiddenWordLetters = thisRowLetters) and count(filter(hiddenWordLetters, hiddenWordLetters != letter)) = 4, absent, elsewhere), absent))]" />
<span property="letter" style="--row: [row + 1]" class="[if(!stateHidden, state)] [if(row + 1 = attempt and seconds($now) - errorTime <= 1, shake)] [if(($index mod 5 + 1) <= guessLength or row < attempt - 1, idle)]"></span>
</div>
</div>
<div id="keyboard">
<div mv-list="keys" mv-value="keyboardLayout.keys">
<button mv-list-item mv-group
mv-action="if(guessLength < 5, add(group('letter': key), usedLetters) & add(key, guessLetters))"
mv-attribute="none"
id="key-[key]"
class="[if(attempt > 1, if(contains(join(guesses), key), if(key in correctLetters, correct, if(contains(hiddenWord, key), elsewhere, absent))))]"
style="--row: [row]"
disabled="[isOver]">[key]</button>
<button id="bs"
mv-action="deleteif(guessLength > 0, last(game.usedLetters)) delete(last(game.guessLetters))"
style="--row: 3; --column: 9"
disabled="[isOver]"><span class="visually-hidden">Delete last letter</span></button>
<button id="enter" mv-action="
if(0 < guessLength < 5, set(toast.message, 'Not enough letters') & set(toast.errorTime, seconds($now)))
if(guessLength = 5 and !guessValid, set(toast.message, 'Not in word list') & set(errorTime, seconds($now)) & set(toast.errorTime, seconds($now)))
setif(guessLength = 5 and attempt = 6 and guessValid and guess != hiddenWord, result, lost)
setif(guessLength = 5 and guess = hiddenWord, result, won)
if(guessLength = 5 and guessValid, add(guess, guesses) & clear(guessLetters))
if(!mode.practiceMode and result = lost, set(toast.message, hiddenWord) & set(toast.errorTime, 10000 * seconds($now)))
addif(!mode.practiceMode and result = lost, group('guess': 0), statistics.games)
setif(!mode.practiceMode and result = lost, statistics.currentStreak, 0)
addif(!mode.practiceMode and result = won, group('guess': count(guesses)), statistics.games)
setif(!mode.practiceMode and result = won, statistics.currentStreak, statistics.currentStreak + 1)
if(!mode.practiceMode and result,
set(statistics.hiddenWord, hiddenWord) & set(statistics.guesses, guesses) &
set(statistics.states, usedLetters.state) & set(statistics.result, result) &
setif(statistics.currentStreak > statistics.maxStreak, statistics.maxStreak, statistics.currentStreak) &
set(statistics.date, $today)
)
setif(mode.practiceMode and result = lost, popup.message, hiddenWord)
setif(mode.practiceMode and result = won, popup.message, 'You won! 🎉')
setif(mode.practiceMode and result, popup.isShowing, true)
" style="--row: 3; --column: 1" disabled="[isOver]">Enter</button>
</div>
</div>
<div mv-list="guessLetters" mv-initial-items="0" mv-if="false">
<span mv-list-item></span>
</div>
<div mv-list="guesses" mv-value="if(isOver, statistics.guesses, list())" mv-initial-items="0" mv-if="false">
<span mv-list-item></span>
</div>
</section>
<section mv-app="popup" mv-bar="none" class="[if(isShowing, visible)] game-over [game.result]" role="alertdialog" aria-modal="true">
<meta property="isShowing" content="[false]" />
<p property="message"></p>
<button mv-action="
clear(game.guesses, game.usedLetters, game.result)
set(commonWords.index, random(0, count(commonWords.words) - 1))
set(isShowing, false)
">Play again</button>
</section>
<section mv-app="statistics" mv-bar="none" mv-storage="local" mv-plugins="share" mv-autosave class="[if(isShowing, visible)] [game.result]" role="dialog" aria-label="Game statistics">
<meta property="isShowing" content="[$today = date and !mode.practiceMode and game.result != lost]" />
<meta property="date" />
<meta property="result" />
<meta property="hiddenWord" mv-if="false" />
<meta property="guesses" mv-if="false" />
<meta property="states" mv-if="false" />
<button mv-action="set(isShowing, false)"><span class="visually-hidden">Close</span></button>
<p class="info" mv-if="mode.practiceMode">
We donʼt gather statistics in practice mode.
<button mv-action="set(mode.practiceMode, false)">Turn off practice mode</button>
</p>
<article class="stats" mv-if="!mode.practiceMode">
<h2>Statistics</h2>
<meta property="wins" content="[count(games where guess > 0)]" />
<span title="Played" property="played" mv-value="count(games)">0</span>
<span title="Win %">[round(wins / played * 100) or 0]</span>
<span title="Current Streak" property="currentStreak" mv-default>0</span>
<span title="Max Streak" property="maxStreak" mv-default>0</span>
</article>
<article class="guess-distribution" mv-if="!mode.practiceMode">
<h2>Guess Distribution</h2>
<p mv-if="played = 0">No Data</p>
<ol mv-if="played > 0" mv-list="guessCount" mv-value="1 .. 6" style="--max: [if(wins > 0, wins, 'initial')]">
<li mv-list-item mv-attribute="content" style="--value: [value]; [if(value = 0, '--color: initial; --inset: initial;')]">
<span property="value">[count(filter(games, guess = guessCount)) or 0]</span>
</li>
</ol>
</article>
<article mv-if="$today = date and !mode.practiceMode" class="next-mavordle">
<meta property="tomorrow" content="[$today + 1 * day()]" />
<meta property="difference" content="[tomorrow - $now]" />
<h2>Next Mavordle</h2>
<p class="timer">
[digits(2, hours(difference))]:[digits(2, minutes(difference) mod 60)]:[digits(2, seconds(difference) mod 60)]
</p>
<meta property="attempts" content="[if(result = won, count(guesses), X)]" />
<meta property="heading" content="Mavordle [commonWords.index + 1] [attempts]/6" />
<div mv-list mv-value="states" mv-initial-items="0" hidden>
<div mv-list-item="state" mv-attribute="content">
<span property="symbol">[if($index mod 5 = 0, "\n") & if(state = correct, "🟩", if(state = elsewhere, "🟨", "⬜️"))]</span>
</div>
</div>
<button mv-action="share(text: heading & '\n' & join(symbol))">Share</button>
</article>
<div mv-list="usedLetters" mv-value="split(join(guesses), '')" mv-initial-items="0" hidden>
<div mv-list-item>
<span property="letter"></span>
</div>
</div>
<div mv-list="games" mv-initial-items="0">
<div mv-list-item>
<meta property="guess" />
</div>
</div>
</section>
<section mv-app="keyboardLayout" mv-source="keyboard.json" mv-bar="none">
<meta property="keys" mv-if="false" />
</section>
<!-- Credit: https://github.com/tabatkins/wordle-list -->
<section mv-app="possibleWords" mv-source="possibleWords.json" mv-bar="none">
<meta property="words" mv-if="false" />
</section>
<!-- Credit: https://github.com/ewinapun/wordle-master -->
<section mv-app="commonWords" mv-source="commonWords.json" mv-bar="none">
<meta property="startDate" content="2022-02-01" mv-if="false" />
<meta property="words" mv-if="false" />
<meta property="index" content="[if(mode.practiceMode, random(0, count(words) - 1), days($today - startDate) mod count(words))]" mv-if="false" />
<meta property="todaysWord" content="[get(words, index)]" mv-if="false" />
</section>
</main>
<footer>
<section id="ribbon">
Made with <a href="https://mavo.io"><img src="https://mavo.io/logo.svg" alt="Mavo logo" /></a>
</section>
<section id="attribution">
<p>
Built with ❤️ by <a href="https://twitter.com/DmitrySharabin">Dmitry Sharabin</a>. <br />
Source code is on <a href="https://github.com/DmitrySharabin/mavo-wordle">GitHub</a>.
</p>
</section>
</footer>
<script>
// Make the game playable with the keyboard
document.addEventListener("keyup", event => {
let id = event.key === "Backspace" ? "bs" : event.key === "Enter" ? "enter" : "key-" + event.key.toLowerCase();
let button = document.getElementById(id);
if (button) {
event.preventDefault();
button.focus();
button.click();
}
});
</script>
</body>
</html>