Skip to content

Commit de0dc08

Browse files
authored
(Read description) Adds a find mode
It modifies drawPixels to add a "find mode" that causes the currently selected element to pulsate red and yellow. To toggle it, pull up the info for the element "find_toggle" and click the magenta text in the description.
1 parent b7bd1f2 commit de0dc08

1 file changed

Lines changed: 80 additions & 0 deletions

File tree

‎mods/find.js‎

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
var style = document.createElement('style');
2+
style.type = 'text/css';
3+
style.id = 'findStatusStylesheet';
4+
style.innerHTML = '.findStatus { color: #E11; text-decoration: none; }';
5+
document.getElementsByTagName('head')[0].appendChild(style);
6+
7+
find = false;
8+
9+
findElement = "sand";
10+
11+
findColorPulseTimer = 0;
12+
13+
function marasi(number) {
14+
return Math.min(255,Math.round(Math.abs(Math.sin(number) * 255)));
15+
};
16+
17+
function updateFindDescription() {
18+
elements.find_toggle.desc = "<em>I'm running out of keybinds</em><br/><br/><span class=\"findStatus\">If this text is green or underlined, find mode is on.</span> <span onclick=toggleFind() style=\"color: #ff00ff;\";>Click here</span> to toggle find mode. This highlights the currently selected element.";
19+
};
20+
21+
function toggleFind() {
22+
if(find != true) {
23+
find = true;
24+
document.getElementById("findStatusStylesheet").innerHTML = '.findStatus { color: #1E1; text-decoration: underline; }'; //Displayed info doen't update until it's pulled up again, so I'm using CSS to dynamically change the color of an element.
25+
} else {
26+
find = false;
27+
document.getElementById("findStatusStylesheet").innerHTML = '.findStatus { color: #E11; text-decoration: none; }';
28+
};
29+
updateFindDescription();
30+
};
31+
32+
oldDrawPixels2 = drawPixels;
33+
34+
suffixFunction2 = function() {
35+
// newCurrentPixels = shuffled currentPixels
36+
var newCurrentPixels = currentPixels;
37+
var pixelsFirst = [];
38+
var pixelsLast = [];
39+
var canvas = document.getElementById("game");
40+
var ctx = canvas.getContext("2d");
41+
42+
for (var i = 0; i < newCurrentPixels.length; i++) {
43+
pixel = newCurrentPixels[i];
44+
//if (pixelMap[pixel.x][pixel.y] == undefined || currentPixels.indexOf(pixel) == -1) {continue}
45+
if (pixel.del) {continue};
46+
if (elements[pixel.element].isGas) {
47+
pixelsLast.push(pixel);
48+
} else {
49+
pixelsFirst.push(pixel);
50+
};
51+
};
52+
53+
var pixelDrawList = pixelsFirst.concat(pixelsLast);
54+
for (var i = 0; i < pixelDrawList.length; i++) {
55+
pixel = pixelDrawList[i];
56+
if (pixelMap[pixel.x][pixel.y] == undefined) {continue};
57+
if (find === true) { //if in find view
58+
if(pixel.element === currentElement) {
59+
ctx.fillStyle = "rgb(255," + marasi(findColorPulseTimer / 10) + ",0)";
60+
ctx.fillRect(pixel.x*pixelSize, pixel.y*pixelSize, pixelSize, pixelSize);
61+
};
62+
};
63+
};
64+
65+
findColorPulseTimer++;
66+
}
67+
68+
drawPixels = function(forceTick=false) {
69+
oldDrawPixels2(forceTick);
70+
suffixFunction2();
71+
};
72+
73+
elements.find_toggle = {
74+
color: ["#000000", "#000000", "#000000", "#000000", "#ff0000", "#ff0000", "#ff0000", "#ff0000"],
75+
name: "find toggle (look at info)",
76+
behavior: behaviors.SELFDELETE,
77+
category: "tools",
78+
excludeRandom: true,
79+
desc: "<em>I'm running out of keybinds</em><br/><br/><span class=\"findStatus\">If this text is green or underlined, find mode is on.</span> <span onclick=toggleFind() style=\"color: #ff00ff;\";>Click here</span> to toggle find mode. This highlights the currently selected element.",
80+
};

0 commit comments

Comments
 (0)