Last active
March 27, 2022 16:24
-
-
Save MaPePeR/25959df376340a13dbe7e7fad689e5c6 to your computer and use it in GitHub Desktop.
Javascript snippet to color the keys on the note-keyboard based on previous guesses. See https://fubargames.se/squardle/
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
makeBlueNote = ((function (oldMakeBlueNote) { | |
const BLUE=0,BLACK=1, YELLOW=2, RED=3, ORANGE=4; | |
function getLetterColorFromHint(color, isHorizontal, isVertical) { | |
if (color == 'green') { | |
return BLUE; | |
} | |
if (color == 'blacker') { | |
return BLACK; | |
} | |
if (color == 'white') { | |
return BLACK; | |
} | |
if (color.startsWith('yellow')) { | |
return isHorizontal ? YELLOW : BLACK; | |
} | |
if (color.startsWith('redder')) { | |
return isVertical ? RED : BLACK; | |
} | |
if (color.startsWith('orange')) { | |
if (isHorizontal) return YELLOW; | |
if (isVertical) return RED; | |
return BLACK; | |
} | |
throw new Exception("Not reachable?"); | |
} | |
function colorMix(oldColor, newColor) { | |
if (!oldColor) return newColor; | |
if (oldColor == newColor) return oldColor; | |
if (newColor == BLUE) return oldColor; | |
if (oldColor == BLACK || newColor == BLACK) return BLACK; | |
if (oldColor == ORANGE/* && (newColor == RED || newColor == YELLOW || newColor == ORANGE)*/) return ORANGE; | |
if (oldColor == RED && newColor == YELLOW) return ORANGE; | |
if (oldColor == YELLOW && newColor == RED) return ORANGE; | |
throw new Exception("Not reachable?"); | |
} | |
function handleCell(xx, yy, isHorizontal, isVertical, letters) { | |
for (let guess of smallSquares[xx][yy]) { | |
if (!guess[LETTER_DIV]) continue; | |
const letter = guess[LETTER_DIV].firstChild.src.substr(-5, 1); | |
const color = guess[SQUARE_DIV].firstChild.src.substring(guess[SQUARE_DIV].firstChild.src.lastIndexOf('/') + 1, guess[SQUARE_DIV].firstChild.src.length - 4); | |
letters[letter] = colorMix(letters[letter], getLetterColorFromHint(color, isHorizontal, isVertical)); | |
} | |
} | |
function getNoteLetterColors(xx, yy) { | |
const letters = {}; | |
handleCell(xx, yy, false, false, letters); | |
//Check row | |
for (let x = 0; x < 5; ++x) { | |
if (x == xx || (x==1 || x==3) && (yy==1 || yy==3)) { | |
continue; | |
} | |
handleCell(x, yy, true, false, letters); | |
} | |
for (let y = 0; y < 5; ++y) { | |
if (y == yy || (xx==1 || xx==3) && (y==1 || y==3)) { | |
continue; | |
} | |
handleCell(xx, y, false, true, letters); | |
} | |
return letters; | |
} | |
return function(xx, yy) { | |
oldMakeBlueNote(xx, yy); | |
if (gameState = 3) { | |
const colors = { | |
0: "graphics/blue.png", | |
1: "graphics/black.png", | |
2: 'graphics/yellow.png', | |
3: 'graphics/red.png', | |
4: 'graphics/orange.png', | |
} | |
letterColors = getNoteLetterColors(xx, yy); | |
for (let bok=0; bok<alpha.length; bok++) { | |
if(keyboardColorMemory[bok] != "graphics/black.png") { | |
setKeyColor(alpha.charAt(bok), colors[letterColors[alpha.charAt(bok)] || 0]); | |
} | |
} | |
} | |
} | |
})(makeBlueNote)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment