mod/mod.js

72 lines
2.3 KiB
JavaScript
Raw Permalink Normal View History

2026-03-11 09:58:40 -04:00
// my1stmod.js - Configurable delay gate for Sandboxels
2026-03-11 09:56:10 -04:00
elements.delay_gate = {
2026-03-11 09:58:40 -04:00
color: "#8B4513",
2026-03-11 10:03:52 -04:00
behavior: behaviors.wall,
2026-03-11 09:56:10 -04:00
category: "machines",
state: "solid",
2026-03-11 10:03:52 -04:00
conduct: 1,
2026-03-11 09:56:10 -04:00
properties: {
2026-03-11 10:03:52 -04:00
delay: 30,
timer: 0,
powered: false
2026-03-11 09:56:10 -04:00
},
tick: function(pixel) {
2026-03-11 09:58:40 -04:00
// Initialize properties
2026-03-11 09:56:10 -04:00
if (pixel.delay === undefined) pixel.delay = 30;
if (pixel.timer === undefined) pixel.timer = 0;
if (pixel.powered === undefined) pixel.powered = false;
2026-03-11 09:58:40 -04:00
// Check power from below (input)
2026-03-11 09:56:10 -04:00
let below = getPixel(pixel.x, pixel.y + 1);
2026-03-11 09:58:40 -04:00
let receivingPower = below && (below.charge || below.chargeCD);
2026-03-11 09:56:10 -04:00
2026-03-11 09:58:40 -04:00
// Check side inputs for delay adjustment
2026-03-11 09:56:10 -04:00
let left = getPixel(pixel.x - 1, pixel.y);
let right = getPixel(pixel.x + 1, pixel.y);
2026-03-11 09:58:40 -04:00
// Left side = decrease delay (minimum 5)
2026-03-11 09:56:10 -04:00
if (left && (left.charge || left.chargeCD) && pixel.delay > 5) {
pixel.delay--;
2026-03-11 10:03:52 -04:00
pixel.color = "#A0522D";
2026-03-11 09:56:10 -04:00
}
2026-03-11 09:58:40 -04:00
// Right side = increase delay (maximum 300)
else if (right && (right.charge || right.chargeCD) && pixel.delay < 300) {
2026-03-11 09:56:10 -04:00
pixel.delay++;
2026-03-11 10:03:52 -04:00
pixel.color = "#654321";
2026-03-11 09:58:40 -04:00
}
else if (!receivingPower || pixel.timer >= pixel.delay) {
pixel.color = "#8B4513";
2026-03-11 09:56:10 -04:00
}
2026-03-11 09:58:40 -04:00
// Main delay logic
2026-03-11 09:56:10 -04:00
if (receivingPower) {
if (!pixel.powered) {
pixel.powered = true;
pixel.timer = 0;
}
pixel.timer++;
2026-03-11 09:58:40 -04:00
// Visual progress indication
if (pixel.timer < pixel.delay) {
let progress = pixel.timer / pixel.delay;
let r = Math.floor(139 + (100 * progress));
2026-03-11 10:03:52 -04:00
pixel.color = "rgb(" + r + ", 69, 19)";
2026-03-11 09:58:40 -04:00
}
// Output when delay reached
2026-03-11 09:56:10 -04:00
if (pixel.timer >= pixel.delay) {
let above = getPixel(pixel.x, pixel.y - 1);
2026-03-11 09:58:40 -04:00
if (above && elements[above.element].conduct) {
2026-03-11 09:56:10 -04:00
above.charge = 1;
2026-03-11 09:58:40 -04:00
above.chargeCD = 5;
2026-03-11 09:56:10 -04:00
}
2026-03-11 10:03:52 -04:00
pixel.color = "#FFD700";
2026-03-11 09:56:10 -04:00
}
} else {
2026-03-11 09:58:40 -04:00
pixel.powered = false;
pixel.timer = 0;
2026-03-11 09:56:10 -04:00
}
}
};