From f720f4eaa692d35ffa7b2cb85171bf823a01b49f Mon Sep 17 00:00:00 2001 From: felixs-alt <114471609+felixs-alt@users.noreply.github.com> Date: Wed, 27 Sep 2023 09:52:10 +0200 Subject: [PATCH] Update flipflop.js --- mods/flipflop.js | 45 ++++++++++++++++++++++++++++++++++++++++----- 1 file changed, 40 insertions(+), 5 deletions(-) diff --git a/mods/flipflop.js b/mods/flipflop.js index 025d727a..8fd63d85 100644 --- a/mods/flipflop.js +++ b/mods/flipflop.js @@ -15,11 +15,10 @@ elements.flipflop = { let Output = pixelMap[pixel.x+1][pixel.y] let Input = pixelMap[pixel.x-1][pixel.y] if (typeof Output !== "undefined" && typeof Input !== "undefined") { - console.log(pixel.cooldown) - if (Input.charge == 0 && pixel.cooldown == 1) { + if (Input.charge == undefined && pixel.cooldown == 1) { pixel.cooldown = 0 } - if (Input.charge > 0.5 && pixel.cooldown == 0) { + if (Input.charge > 0 && pixel.cooldown == 0) { pixel.cooldown = 1 if (pixel.powerstate == "true") { pixel.powerstate = "false" @@ -29,8 +28,44 @@ elements.flipflop = { pixel.color = "#94CF0D" Output.charge = 1 } - } else { - Output.charge = 0 + } else if (cooldown == 0) { + Output.charge = undefined + } + } + } +}; +elements.flipflop = { + properties: { + powerstate: "false", + cooldown: 0, + }, + name: "Flip Flop", + color: "#CF300D", + state: "solid", + category: "machines", + tick: function(pixel) { + doHeat(pixel) + doBurning(pixel) + doElectricity(pixel) + + let Output = pixelMap[pixel.x+1][pixel.y] + let Input = pixelMap[pixel.x-1][pixel.y] + if (typeof Output !== "undefined" && typeof Input !== "undefined") { + if (Input.charge == undefined && pixel.cooldown == 1) { + pixel.cooldown = 0 + } + if (Input.charge > 0 && pixel.cooldown == 0) { + pixel.cooldown = 1 + if (pixel.powerstate == "true") { + pixel.powerstate = "false" + pixel.color = "#CF300D" + } else if (pixel.powerstate == "false") { + pixel.powerstate = "true" + pixel.color = "#94CF0D" + Output.charge = 1 + } + } else if (cooldown == 0) { + Output.charge = undefined } } }