-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.is
337 lines (308 loc) · 9.83 KB
/
index.is
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
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
/// @ 0.13.2
/**
* Misskey Wordle v0.1.4 (Build 1039)
* Code itself is (c) Osaka Prefectural Tondabayashi Junior and Senior High School
* "Misskey Wordle" is not affiliated with "Wordle" by NYTimes in any way.
* Original Author: @[email protected]
*
* Licensed under CC BY-NC-SA 4.0. Learn more at https://creativecommons.org/licenses/by-nc-sa/4.0/
*
* この下には解答が記載されています。注意!
*
*
* この下には解答が記載されています。注意!
*
*
* この下には解答が記載されています。注意!
* (大事なことなので3回言いました)
**/
/** Wordleの情報(自動アップデート) */
let wordleData = {
answer: "rover",
quizNo: 1039,
date: "2024-04-23"
}
/** ローカライズ */
var uiText = {}
if (LOCALE.incl('ja')) {
uiText = {
charMismatch: "単語の文字数語りません",
charNotAllowed: "使用できない文字が含まれています",
errorDiagDescription: "5文字の単語を入力してください",
textInputLabel: "5文字の単語を入力",
confirmButton: "たしかめる",
correct: "正解!",
gameOver: "挑戦失敗…",
shareButton: "投稿する",
shareButtonOther: "他サーバーへの共有"
}
} else {
uiText = {
charMismatch: "The number of characters in the word is incorrect",
charNotAllowed: "The word contains characters that are not allowed",
errorDiagDescription: "Enter a 5-letter English word",
textInputLabel: "Enter a 5-letter English word",
confirmButton: "Confirm",
correct: "Correct!",
gameOver: "Game over...",
shareButton: "Share",
shareButtonOther: "Share to other servers"
}
}
/** 挑戦限度回数 */
let attemptLimit = 6
/** 現在のフォーム入力内容 */
var currentInput = ""
/** 入力内容保持(単語は小文字) */
let trials = []
/**
* 入力内容のヒント(以下の文字を「ncnwc」のように記述する)
* n ... not in any spot
* w ... used, but in another spot
* c ... used and in correct spot
*/
let trialOutcomes = []
/**
* アルファベット表(入力検証用)
*/
let alphabetLowerCase = "abcdefghijklmnopqrstuvwxyz"
let alphabetUpperCase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
// ヒント画面描画
@renderHintModule() {
var mfm = []
for let i, attemptLimit {
if (i < trials.len) {
let trialA = trials[i].split()
let outA = []
for let j, trialA.len {
var char = alphabetUpperCase.pick(alphabetLowerCase.index_of(trialA[j]))
if (trialOutcomes[i].pick(j) == 'n') {
outA.push(`$[bg.color=787c7e $[fg.color=fff {char} ]]`)
} else if (trialOutcomes[i].pick(j) == 'w') {
outA.push(`$[bg.color=c9b458 $[fg.color=fff {char} ]]`)
} else if (trialOutcomes[i].pick(j) == 'c') {
outA.push(`$[bg.color=6aaa64 $[fg.color=fff {char} ]]`)
}
}
mfm.push(outA.join(" "))
} else {
mfm.push("$[bg.color=d3d6da _ ] $[bg.color=d3d6da _ ] $[bg.color=d3d6da _ ] $[bg.color=d3d6da _ ] $[bg.color=d3d6da _ ]")
}
}
mfm = `**{mfm.join(`{Str:lf}{Str:lf}`)}**`
Ui:get('hintModule').update({
children: [
Ui:C:mfm({
text: `<center>{mfm}</center>`
font: "monospace"
})
]
})
}
// シェア用テキスト生成
@createShareText() {
var result = ""
if (trialOutcomes[trialOutcomes.len - 1] != "ccccc") {
result = `X/{attemptLimit}`
} else {
result = `{trialOutcomes.len}/{attemptLimit}`
}
let header =`Wordle {wordleData.quizNo} {result}{Str:lf}`
var tiles = []
for let i, trialOutcomes.len {
let outA = []
let tileA = trialOutcomes[i].split()
for let j, tileA.len {
if (tileA[j] == 'n') {
outA.push('⬜')
} else if (tileA[j] == 'w') {
outA.push('🟨')
} else if (tileA[j] == 'c') {
outA.push('🟩')
}
}
tiles.push(outA.join(" "))
}
tiles = tiles.join(Str:lf)
return `{header}{Str:lf}{tiles}{Str:lf}#MisskeyWordle {THIS_URL}`
}
// #region encodeURIComponent
//---------------------------------------------------
// MIT License
// Copyright © 2023-2024 Kur0den0010
// https://opensource.org/licenses/mit-license.php
//---------------------------------------------------
@encodeURIComponent(content) {
let noEncode = [
45, 46 48, 49, 50, 51, 52, 53,
54, 55, 56, 57, 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,
95, 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, 126
]
let utf8Arr = content.to_arr().map(@(v){
v.to_utf8_byte_arr()
})
let urlStrs = []
each let a, utf8Arr {
if a.len == 1 && noEncode.incl(a[0]) {
let normalStr = Str:from_utf8_bytes(a)
urlStrs.push(normalStr)
continue
}
each let v, a {
let hexCode = Num:to_hex(v)
let text = if hexCode.len == 1 {`%0{hexCode}`}
else {`%{hexCode}`}
urlStrs.push(text)
}
}
return urlStrs.join()
}
// #endregion encodeURIComponent
// 回答検証
@sendTrial() {
if (currentInput == "") {
print("currentInput is empty")
return null
}
// 文字数
if (currentInput.len != 5) {
Mk:dialog(
uiText.charMismatch
uiText.errorDiagDescription
"warn"
)
return null
}
var currentInputArray = currentInput.split()
var currentInputFeedback = [null, null, null, null, null]
for let i, currentInputArray.len {
var char = currentInputArray[i]
// アルファベット 検証
if (Core:and(!alphabetLowerCase.incl(char), !alphabetUpperCase.incl(char))) {
Mk:dialog(
uiText.charNotAllowed
uiText.errorDiagDescription
"warn"
)
return null
}
// 小文字に強制
if (alphabetUpperCase.incl(char)) {
currentInputArray[i] = alphabetLowerCase.pick(alphabetUpperCase.index_of(char))
char = alphabetLowerCase.pick(alphabetUpperCase.index_of(char))
}
let answerArray = wordleData.answer.split()
if (answerArray[i] == char) {
// 回答検証(C)
currentInputFeedback[i] = "c"
} else if (answerArray.incl(char)) {
// 回答検証(W)
currentInputFeedback[i] = "w"
} else {
// 回答検証(N)
currentInputFeedback[i] = "n"
}
}
// データ保存
trials.push(currentInputArray.join())
trialOutcomes.push(currentInputFeedback.join())
// 再描画
renderHintModule()
// フォームクリア
Ui:get('textModule').update({
children: [
Ui:C:textInput({
onInput: @(value) {
currentInput = value
}
label: uiText.textInputLabel
})
Ui:C:button({
text: uiText.confirmButton
primary: true
onClick: @() {
sendTrial()
}
})
]
})
if (currentInputFeedback.join() == 'ccccc') {
// 正解
Ui:get('textModule').update({
children: [
Ui:C:mfm({
text: `<center>$[x2 $[fg.color=f00 **{uiText.correct}**]]</center>`
})
Ui:C:postFormButton({
text: uiText.shareButton
primary: true
rounded: true
form: {
text: createShareText()
}
})
Ui:C:mfm({
text: `<center>[{uiText.shareButtonOther}](https://misskey-hub.net/share/?text={encodeURIComponent(createShareText())})</center>`
})
]
})
} else if (trialOutcomes.len >= attemptLimit) {
// 挑戦限度超過
Ui:get('textModule').update({
children: [
Ui:C:mfm({
text: `<center>$[x2 $[fg.color=00f **{uiText.gameOver}**]]</center>`
})
Ui:C:postFormButton({
text: uiText.shareButton
primary: true
rounded: true
form: {
text: createShareText()
}
})
Ui:C:mfm({
text: `<center>[{uiText.shareButtonOther}](https://misskey-hub.net/share/?text={encodeURIComponent(createShareText())})</center>`
})
]
})
}
}
// 初回レンダリング
Ui:render([
Ui:C:mfm({ text: `<center>***Wordle***{Str:lf}No.{wordleData.quizNo} / {wordleData.date}</center>` })
Ui:C:container({
borderWidth: 4
padding: 18
rounded: true
bgColor: 'var(--bg, #884)'
} 'hintModule')
Ui:C:container({
children: [
Ui:C:textInput({
onInput: @(value) {
currentInput = value
}
label: uiText.textInputLabel
})
Ui:C:button({
text: uiText.confirmButton
primary: true
onClick: @() {
sendTrial()
}
})
]
borderWidth: 4
padding: 18
rounded: true
bgColor: 'var(--bg, #884)'
align: 'center'
} 'textModule')
])
renderHintModule()