Skip to content

Commit 284ec44

Browse files
committed
New sharing
1 parent 0448043 commit 284ec44

File tree

1 file changed

+29
-9
lines changed

1 file changed

+29
-9
lines changed

scripts/index.js

Lines changed: 29 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ const isAlpha = (char) => {
1717
return code >= 97 && code <= 122;
1818
};
1919

20+
// Build emoji progress string from guessProgress: 🟩 for correct, 🟥 for incorrect
21+
function buildGuessString() {
22+
try {
23+
if (!window.gameSesh || !Array.isArray(window.gameSesh.guessProgress)) return '';
24+
return window.gameSesh.guessProgress.map(v => v ? '🟩' : '🟥').join('');
25+
} catch (e) {
26+
console.error('buildGuessString error', e);
27+
return '';
28+
}
29+
}
30+
2031
//function to request random card data from scryfall api
2132
function requestCard(id) {
2233

@@ -151,6 +162,7 @@ function loadCard(data) {
151162
window.gameSesh.end = false;
152163
window.gameSesh.wrongGuess = '';
153164
window.gameSesh.guesses = '';
165+
window.gameSesh.guessProgress = [];
154166
window.gameSesh.tlv = window.game[window.game.mode].lives;
155167

156168
if (window.game.mode == 'daily') {
@@ -285,6 +297,7 @@ function loadGuesses() {
285297
let g = window.gameSesh.guesses;
286298
window.gameSesh.wrongGuess = '';
287299
window.gameSesh.guesses = '';
300+
window.gameSesh.guessProgress = [];
288301
for (var i = 0; i < g.length; i++) {
289302
submitLetter(g.charAt(i));
290303
}
@@ -324,6 +337,11 @@ function submitLetter(char) {
324337
}
325338
}
326339

340+
// record correctness of this guess (incremental method)
341+
if (!Array.isArray(window.gameSesh.guessProgress))
342+
window.gameSesh.guessProgress = [];
343+
window.gameSesh.guessProgress.push(found);
344+
327345

328346
if (!found) { //letter is not in card name
329347
window.gameSesh.wrongGuess += char;
@@ -465,7 +483,8 @@ function gameLostFree() {
465483
text: "Share",
466484
btnClass: 'btn-green',
467485
action: function (linkButton) {
468-
var str = 'Befuddle:\n' + (window.gameSesh.tlv == -1 ? 'Gave Up' : ('X/' + window.gameSesh.tlv)) +
486+
let str = 'Befuddle:\n' + buildGuessString() + '\n' +
487+
(window.gameSesh.tlv == -1 ? 'Gave Up' : ('X/' + window.gameSesh.tlv)) +
469488
(window.gameSesh.hideBlanks ? '*' : '');
470489
const url = 'https://befuddle.xyz/?cardId=' + window.mtgCard.id + (window.mtgCard.cf != -1 ? ('&cf=' + window.mtgCard.cf) : '')
471490
clipboardHandler(linkButton, str, url);
@@ -565,7 +584,7 @@ function gameLostDaily() {
565584
action: function (linkButton) {
566585
let d = new Date();
567586
let str =
568-
`Daily Befuddle ${d.toLocaleDateString("en-US")}\nX${(window.gameSesh.hideBlanks ? '*' : '')}`;
587+
`Daily Befuddle ${d.toLocaleDateString("en-US")}\n${buildGuessString()}\nX${(window.gameSesh.hideBlanks ? '*' : '')}`;
569588
clipboardHandler(linkButton, str, 'https://befuddle.xyz/');
570589
return false;
571590
}
@@ -674,7 +693,7 @@ function gameWinDaily() {
674693
action: function (linkButton) {
675694
let d = new Date();
676695
let str =
677-
`Daily Befuddle ${d.toLocaleDateString("en-US")}\n${wr}/${window.game.daily.lives}${(window.gameSesh.hideBlanks ? '*' : '')}`;
696+
`Daily Befuddle ${d.toLocaleDateString("en-US")}\n${buildGuessString()}\n${wr}/${window.game.daily.lives}${(window.gameSesh.hideBlanks ? '*' : '')}`;
678697
clipboardHandler(linkButton, str, 'https://befuddle.xyz/');
679698
return false;
680699
}
@@ -742,7 +761,7 @@ function gameWinFree() {
742761
text: "Share",
743762
btnClass: 'btn-green',
744763
action: function (linkButton) {
745-
var str = 'Befuddle: \n' +
764+
let str = 'Befuddle: \n' + buildGuessString() + '\n' +
746765
wr + (window.gameSesh.tlv == -1 ? (' wrong guess' + (wr == 1 ? '' : 'es')) : ('/' + window.gameSesh.tlv)) +
747766
(window.gameSesh.hideBlanks ? '*' : '');
748767
const url = 'https://befuddle.xyz/?cardId=' + window.mtgCard.id + (window.mtgCard.cf != -1 ? ('&cf=' + window.mtgCard.cf) : '')
@@ -768,8 +787,9 @@ function gameWinFree() {
768787
//handler for the clipboard buttons
769788
// centralised clipboard write + UI update
770789
function _doClipboardWrite(linkButton, str) {
790+
const output = `${str}\n${url}`;
771791
if (navigator.clipboard && navigator.clipboard.writeText) {
772-
navigator.clipboard.writeText(str).then(function () {
792+
navigator.clipboard.writeText(output).then(function () {
773793
linkButton.addClass('displayButton');
774794
linkButton.setText('Copied');
775795
linkButton.addClass('btn-dark');
@@ -782,10 +802,10 @@ function _doClipboardWrite(linkButton, str) {
782802
linkButton.setText('Share');
783803
}, 3000, linkButton);
784804
}, function () {
785-
clipboardError(str);
805+
clipboardError(output);
786806
});
787807
} else {
788-
clipboardError(str);
808+
clipboardError(output);
789809
}
790810
}
791811

@@ -810,14 +830,14 @@ function clipboardHandler(linkButton, str, url) {
810830
}, 3000, linkButton);
811831
}).catch(function () {
812832
// share failed or was cancelled — fall through to clipboard behaviour
813-
_doClipboardWrite(linkButton, str);
833+
_doClipboardWrite(linkButton, str, url);
814834
});
815835

816836
return;
817837
}
818838

819839
// No native share available — use clipboard
820-
_doClipboardWrite(linkButton, str);
840+
_doClipboardWrite(linkButton, str, url);
821841
}
822842

823843
//function to display clipboard error

0 commit comments

Comments
 (0)