sandboxels/mods/flipflop.js

37 lines
920 B
JavaScript
Raw Permalink Normal View History

2023-09-26 04:32:09 -04:00
elements.flipflop = {
2023-09-26 07:34:55 -04:00
properties: {
powerstate: "false",
2023-09-27 03:40:09 -04:00
cooldown: 0,
2023-09-26 07:34:55 -04:00
},
2023-09-26 04:32:09 -04:00
name: "Flip Flop",
2023-09-26 04:38:08 -04:00
color: "#CF300D",
2023-09-26 04:32:09 -04:00
state: "solid",
2023-09-26 04:38:08 -04:00
category: "machines",
2023-09-26 04:32:09 -04:00
tick: function(pixel) {
2023-09-27 03:40:09 -04:00
doHeat(pixel)
doBurning(pixel)
doElectricity(pixel)
2023-09-26 04:38:08 -04:00
let Output = pixelMap[pixel.x+1][pixel.y]
let Input = pixelMap[pixel.x-1][pixel.y]
2023-09-27 03:00:30 -04:00
if (typeof Output !== "undefined" && typeof Input !== "undefined") {
2023-09-27 03:52:10 -04:00
if (Input.charge == undefined && pixel.cooldown == 1) {
2023-09-27 03:40:09 -04:00
pixel.cooldown = 0
}
2023-09-27 03:52:10 -04:00
if (Input.charge > 0 && pixel.cooldown == 0) {
2023-09-27 03:40:09 -04:00
pixel.cooldown = 1
2023-09-27 03:00:30 -04:00
if (pixel.powerstate == "true") {
pixel.powerstate = "false"
2023-09-27 03:40:09 -04:00
pixel.color = "#CF300D"
2023-09-27 03:27:39 -04:00
} else if (pixel.powerstate == "false") {
2023-09-27 03:40:09 -04:00
pixel.powerstate = "true"
pixel.color = "#94CF0D"
Output.charge = 1
2023-09-27 03:00:30 -04:00
}
2023-09-27 03:53:14 -04:00
} else if (pixel.cooldown == 0) {
2023-09-27 03:52:10 -04:00
Output.charge = undefined
2023-09-27 03:00:30 -04:00
}
2023-09-26 06:05:49 -04:00
}
2023-09-26 04:32:09 -04:00
}
};