|
264 | 264 | to prevent hover and active colors to appear. -->
|
265 | 265 | <div class="color-button-row">
|
266 | 266 | <button class="color-button" style="background-color: #ffffff !Important"
|
267 |
| - onmousedown="setColor('#ffffff')" onclick="setColor('#ffffff')"></button> |
| 267 | + onmousedown="setColor(0)" onclick="setColor(0)"></button> |
268 | 268 | <button class="color-button" style="background-color: #c1c1c1 !Important"
|
269 |
| - onmousedown="setColor('#c1c1c1')" onclick="setColor('#c1c1c1')"></button> |
| 269 | + onmousedown="setColor(1)" onclick="setColor(1)"></button> |
270 | 270 | <button class="color-button" style="background-color: #ef130b !Important"
|
271 |
| - onmousedown="setColor('#ef130b')" onclick="setColor('#ef130b')"></button> |
| 271 | + onmousedown="setColor(2)" onclick="setColor(2)"></button> |
272 | 272 | <button class="color-button" style="background-color: #ff7100 !Important"
|
273 |
| - onmousedown="setColor('#ff7100')" onclick="setColor('#ff7100')"></button> |
| 273 | + onmousedown="setColor(3)" onclick="setColor(3)"></button> |
274 | 274 | <button class="color-button" style="background-color: #ffe400 !Important"
|
275 |
| - onmousedown="setColor('#ffe400')" onclick="setColor('#ffe400')"></button> |
| 275 | + onmousedown="setColor(4)" onclick="setColor(4)"></button> |
276 | 276 | <button class="color-button" style="background-color: #00cc00 !Important"
|
277 |
| - onmousedown="setColor('#00cc00')" onclick="setColor('#00cc00')"></button> |
| 277 | + onmousedown="setColor(5)" onclick="setColor(5)"></button> |
278 | 278 | <button class="color-button" style="background-color: #00b2ff !Important"
|
279 |
| - onmousedown="setColor('#00b2ff')" onclick="setColor('#00b2ff')"></button> |
| 279 | + onmousedown="setColor(6)" onclick="setColor(6)"></button> |
280 | 280 | <button class="color-button" style="background-color: #231fd3 !Important"
|
281 |
| - onmousedown="setColor('#231fd3')" onclick="setColor('#231fd3')"></button> |
| 281 | + onmousedown="setColor(7)" onclick="setColor(7)"></button> |
282 | 282 | <button class="color-button" style="background-color: #a300ba !Important"
|
283 |
| - onmousedown="setColor('#a300ba')" onclick="setColor('#a300ba')"></button> |
| 283 | + onmousedown="setColor(8)" onclick="setColor(8)"></button> |
284 | 284 | <button class="color-button" style="background-color: #d37caa !Important"
|
285 |
| - onmousedown="setColor('#d37caa')" onclick="setColor('#d37caa')"></button> |
| 285 | + onmousedown="setColor(9)" onclick="setColor(9)"></button> |
286 | 286 | <button class="color-button" style="background-color: #a0522d !Important"
|
287 |
| - onmousedown="setColor('#a0522d')" onclick="setColor('#a0522d')"></button> |
| 287 | + onmousedown="setColor(10)" onclick="setColor(10)"></button> |
288 | 288 | <button class="color-button" style="background-color: #592f2a !Important"
|
289 |
| - onmousedown="setColor('#592f2a')" onclick="setColor('#592f2a')"></button> |
| 289 | + onmousedown="setColor(11)" onclick="setColor(11)"></button> |
290 | 290 | <button class="color-button" style="background-color: #ecbcb4 !Important"
|
291 |
| - onmousedown="setColor('#ecbcb4')" onclick="setColor('#ecbcb4')"></button> |
| 291 | + onmousedown="setColor(12)" onclick="setColor(12)"></button> |
292 | 292 | </div>
|
293 | 293 | <div class="color-button-row">
|
294 | 294 | <button class="color-button" style="background-color: #000000 !Important"
|
295 |
| - onmousedown="setColor('#000000')" onclick="setColor('#000000')"></button> |
| 295 | + onmousedown="setColor(13)" onclick="setColor(13)"></button> |
296 | 296 | <button class="color-button" style="background-color: #4c4c4c !Important"
|
297 |
| - onmousedown="setColor('#4c4c4c')" onclick="setColor('#4c4c4c')"></button> |
| 297 | + onmousedown="setColor(14)" onclick="setColor(14)"></button> |
298 | 298 | <button class="color-button" style="background-color: #740b07 !Important"
|
299 |
| - onmousedown="setColor('#740b07')" onclick="setColor('#740b07')"></button> |
| 299 | + onmousedown="setColor(15)" onclick="setColor(15)"></button> |
300 | 300 | <button class="color-button" style="background-color: #c23800 !Important"
|
301 |
| - onmousedown="setColor('#c23800')" onclick="setColor('#c23800')"></button> |
| 301 | + onmousedown="setColor(16)" onclick="setColor(16)"></button> |
302 | 302 | <button class="color-button" style="background-color: #e8a200 !Important"
|
303 |
| - onmousedown="setColor('#e8a200')" onclick="setColor('#e8a200')"></button> |
| 303 | + onmousedown="setColor(17)" onclick="setColor(17)"></button> |
304 | 304 | <button class="color-button" style="background-color: #005510 !Important"
|
305 |
| - onmousedown="setColor('#005510')" onclick="setColor('#005510')"></button> |
| 305 | + onmousedown="setColor(18)" onclick="setColor(18)"></button> |
306 | 306 | <button class="color-button" style="background-color: #00569e !Important"
|
307 |
| - onmousedown="setColor('#00569e')" onclick="setColor('#00569e')"></button> |
| 307 | + onmousedown="setColor(19)" onclick="setColor(19)"></button> |
308 | 308 | <button class="color-button" style="background-color: #0e0865 !Important"
|
309 |
| - onmousedown="setColor('#0e0865')" onclick="setColor('#0e0865')"></button> |
| 309 | + onmousedown="setColor(20)" onclick="setColor(20)"></button> |
310 | 310 | <button class="color-button" style="background-color: #550069 !Important"
|
311 |
| - onmousedown="setColor('#550069')" onclick="setColor('#550069')"></button> |
| 311 | + onmousedown="setColor(21)" onclick="setColor(21)"></button> |
312 | 312 | <button class="color-button" style="background-color: #a75574 !Important"
|
313 |
| - onmousedown="setColor('#a75574')" onclick="setColor('#a75574')"></button> |
| 313 | + onmousedown="setColor(22)" onclick="setColor(22)"></button> |
314 | 314 | <button class="color-button" style="background-color: #63300d !Important"
|
315 |
| - onmousedown="setColor('#63300d')" onclick="setColor('#63300d')"></button> |
| 315 | + onmousedown="setColor(23)" onclick="setColor(23)"></button> |
316 | 316 | <button class="color-button" style="background-color: #492f31 !Important"
|
317 |
| - onmousedown="setColor('#492f31')" onclick="setColor('#492f31')"></button> |
| 317 | + onmousedown="setColor(24)" onclick="setColor(24)"></button> |
318 | 318 | <button class="color-button" style="background-color: #d1a3a4 !Important"
|
319 |
| - onmousedown="setColor('#d1a3a4')" onclick="setColor('#d1a3a4')"></button> |
| 319 | + onmousedown="setColor(25)" onclick="setColor(25)"></button> |
320 | 320 | </div>
|
321 | 321 | </div>
|
322 | 322 | <!--The following buttons als override onmousedown and onmouseup to make
|
|
555 | 555 | let sound = localStorage.getItem("sound") !== "false";
|
556 | 556 | updateSoundIcon();
|
557 | 557 |
|
| 558 | + const colorMap = [ |
| 559 | + {hex: '#ffffff', rgb: hexStringToRgbColorObject('#ffffff')}, |
| 560 | + {hex: '#c1c1c1', rgb: hexStringToRgbColorObject('#c1c1c1')}, |
| 561 | + {hex: '#ef130b', rgb: hexStringToRgbColorObject('#ef130b')}, |
| 562 | + {hex: '#ff7100', rgb: hexStringToRgbColorObject('#ff7100')}, |
| 563 | + {hex: '#ffe400', rgb: hexStringToRgbColorObject('#ffe400')}, |
| 564 | + {hex: '#00cc00', rgb: hexStringToRgbColorObject('#00cc00')}, |
| 565 | + {hex: '#00b2ff', rgb: hexStringToRgbColorObject('#00b2ff')}, |
| 566 | + {hex: '#231fd3', rgb: hexStringToRgbColorObject('#231fd3')}, |
| 567 | + {hex: '#a300ba', rgb: hexStringToRgbColorObject('#a300ba')}, |
| 568 | + {hex: '#d37caa', rgb: hexStringToRgbColorObject('#d37caa')}, |
| 569 | + {hex: '#a0522d', rgb: hexStringToRgbColorObject('#a0522d')}, |
| 570 | + {hex: '#592f2a', rgb: hexStringToRgbColorObject('#592f2a')}, |
| 571 | + {hex: '#ecbcb4', rgb: hexStringToRgbColorObject('#ecbcb4')}, |
| 572 | + {hex: '#000000', rgb: hexStringToRgbColorObject('#000000')}, |
| 573 | + {hex: '#4c4c4c', rgb: hexStringToRgbColorObject('#4c4c4c')}, |
| 574 | + {hex: '#740b07', rgb: hexStringToRgbColorObject('#740b07')}, |
| 575 | + {hex: '#c23800', rgb: hexStringToRgbColorObject('#c23800')}, |
| 576 | + {hex: '#e8a200', rgb: hexStringToRgbColorObject('#e8a200')}, |
| 577 | + {hex: '#005510', rgb: hexStringToRgbColorObject('#005510')}, |
| 578 | + {hex: '#00569e', rgb: hexStringToRgbColorObject('#00569e')}, |
| 579 | + {hex: '#0e0865', rgb: hexStringToRgbColorObject('#0e0865')}, |
| 580 | + {hex: '#550069', rgb: hexStringToRgbColorObject('#550069')}, |
| 581 | + {hex: '#a75574', rgb: hexStringToRgbColorObject('#a75574')}, |
| 582 | + {hex: '#63300d', rgb: hexStringToRgbColorObject('#63300d')}, |
| 583 | + {hex: '#492f31', rgb: hexStringToRgbColorObject('#492f31')}, |
| 584 | + {hex: '#d1a3a4', rgb: hexStringToRgbColorObject('#d1a3a4')} |
| 585 | + ]; |
| 586 | + |
558 | 587 | const set_dummy_word_hints = () => {
|
559 | 588 | // Dummy wordhint to prevent layout changes.
|
560 | 589 | applyWordHints([{
|
|
881 | 910 | chooseToolNoUpdate(rubber);
|
882 | 911 | }
|
883 | 912 |
|
884 |
| - let localColor; |
885 |
| - setColorNoUpdate(sessionStorage.getItem("local_color") ?? "#000000"); |
| 913 | + let localColor, localColorIndex; |
886 | 914 |
|
887 |
| - updateDrawingStateUI(); |
| 915 | + function indexToHexColor(index) { |
| 916 | + return colorMap[index].hex; |
| 917 | + } |
888 | 918 |
|
889 |
| - function setColor(colorAsHex) { |
890 |
| - setColorNoUpdate(colorAsHex); |
| 919 | + function indexToRgbColor(index) { |
| 920 | + return colorMap[index].rgb; |
| 921 | + } |
| 922 | + |
| 923 | + function setColor(index) { |
| 924 | + setColorNoUpdate(index); |
891 | 925 |
|
892 | 926 | // If we select a new color, we assume we don't want to use the
|
893 | 927 | // rubber anymore and automatically switch to the pen.
|
|
902 | 936 | }
|
903 | 937 | }
|
904 | 938 |
|
905 |
| - function setColorNoUpdate(colorAsHex) { |
906 |
| - localColor = hexStringToRgbColorObject(colorAsHex); |
907 |
| - sessionStorage.setItem("local_color", colorAsHex); |
| 939 | + function setColorNoUpdate(index) { |
| 940 | + localColorIndex = index; |
| 941 | + localColor = indexToRgbColor(index); |
| 942 | + sessionStorage.setItem("local_color", JSON.stringify(index)); |
908 | 943 | }
|
909 | 944 |
|
| 945 | + setColorNoUpdate(JSON.parse(sessionStorage.getItem("local_color")) ?? 13 /* black*/); |
| 946 | + updateDrawingStateUI(); |
| 947 | + |
910 | 948 | function setLineWidth(value) {
|
911 | 949 | setLineWidthNoUpdate(value);
|
912 | 950 | updateDrawingStateUI();
|
|
1242 | 1280 | appendMessage("non-guessing-player-message", parsed.data.author, parsed.data.content);
|
1243 | 1281 | } else if (parsed.type === "line") {
|
1244 | 1282 | drawLine(context, parsed.data.x, parsed.data.y,
|
1245 |
| - parsed.data.x2, parsed.data.y2, parsed.data.color, |
| 1283 | + parsed.data.x2, parsed.data.y2, |
| 1284 | + indexToRgbColor(parsed.data.color), |
1246 | 1285 | parsed.data.width);
|
1247 | 1286 | } else if (parsed.type === "fill") {
|
1248 | 1287 | if (floodfillUint8ClampedArray(
|
1249 | 1288 | imageData.data,
|
1250 | 1289 | parsed.data.x,
|
1251 | 1290 | parsed.data.y,
|
1252 |
| - parsed.data.color, |
| 1291 | + indexToRgbColor(parsed.data.color), |
1253 | 1292 | imageData.width,
|
1254 | 1293 | imageData.height)) {
|
1255 | 1294 | context.putImageData(imageData, 0, 0);
|
|
1771 | 1810 | floodfillUint8ClampedArray(
|
1772 | 1811 | imageData.data,
|
1773 | 1812 | drawData.x, drawData.y,
|
1774 |
| - drawData.color, |
| 1813 | + indexToRgbColor(drawData.color), |
1775 | 1814 | imageData.width, imageData.height);
|
1776 | 1815 | } else if (drawElement.type === "line") {
|
1777 | 1816 | _drawLine(
|
1778 | 1817 | drawData.x, drawData.y,
|
1779 | 1818 | drawData.x2, drawData.y2,
|
1780 |
| - drawData.color, |
| 1819 | + indexToRgbColor(drawData.color), |
1781 | 1820 | drawData.width);
|
1782 | 1821 | } else {
|
1783 | 1822 | console.log("Unknown draw element type: " + drawData.type);
|
|
1874 | 1913 | //clicked and 0 won't be the uninitialized state.
|
1875 | 1914 | if (allowDrawing && event.button === 0) {
|
1876 | 1915 | if (localTool === fillBucket) {
|
1877 |
| - fillAndSendEvent(context, event.offsetX, event.offsetY, localColor); |
| 1916 | + fillAndSendEvent(context, event.offsetX, event.offsetY, localColorIndex); |
1878 | 1917 | } else {
|
1879 | 1918 | drawLineAndSendEvent(context, event.offsetX, event.offsetY, event.offsetX, event.offsetY);
|
1880 | 1919 | }
|
|
1973 | 2012 | // Clear initially, as it will be black otherwise.
|
1974 | 2013 | clear(context);
|
1975 | 2014 |
|
1976 |
| - function fillAndSendEvent(context, x, y, color) { |
| 2015 | + function fillAndSendEvent(context, x, y, colorIndex) { |
1977 | 2016 | const xScaled = convertToServerCoordinate(x);
|
1978 | 2017 | const yScaled = convertToServerCoordinate(y);
|
| 2018 | + const color = indexToRgbColor(colorIndex); |
1979 | 2019 | if (floodfillUint8ClampedArray(imageData.data, xScaled, yScaled, color, imageData.width, imageData.height)) {
|
1980 | 2020 | context.putImageData(imageData, 0, 0);
|
1981 | 2021 | const fillInstruction = {
|
1982 | 2022 | type: "fill",
|
1983 | 2023 | data: {
|
1984 | 2024 | x: xScaled,
|
1985 | 2025 | y: yScaled,
|
1986 |
| - color: color |
| 2026 | + color: colorIndex, |
1987 | 2027 | },
|
1988 | 2028 | };
|
1989 | 2029 | socket.send(JSON.stringify(fillInstruction));
|
|
1992 | 2032 |
|
1993 | 2033 | function drawLineAndSendEvent(context, x1, y1, x2, y2) {
|
1994 | 2034 | const color = localTool === rubber ? rubberColor : localColor;
|
| 2035 | + const colorIndex = localTool === rubber ? 0 /* white */ : localColorIndex; |
1995 | 2036 |
|
1996 | 2037 | const x1Scaled = convertToServerCoordinate(x1);
|
1997 | 2038 | const y1Scaled = convertToServerCoordinate(y1);
|
|
2007 | 2048 | y: y1Scaled,
|
2008 | 2049 | x2: x2Scaled,
|
2009 | 2050 | y2: y2Scaled,
|
2010 |
| - color: color, |
| 2051 | + color: colorIndex, |
2011 | 2052 | width: localLineWidth,
|
2012 | 2053 | }
|
2013 | 2054 | };
|
|
0 commit comments