mod/mod.js

75 lines
2.6 KiB
JavaScript
Raw 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",
behavior: behaviors.wall, // Fixed: lowercase 'wall'
2026-03-11 09:56:10 -04:00
category: "machines",
state: "solid",
2026-03-11 09:58:40 -04:00
conduct: 1, // Added: allows receiving power
2026-03-11 09:56:10 -04:00
properties: {
2026-03-11 09:58:40 -04:00
delay: 30, // Delay in ticks
timer: 0, // Current countdown
powered: false // Is receiving power from below?
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 09:58:40 -04:00
pixel.color = "#A0522D"; // Flash lighter
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 09:58:40 -04:00
pixel.color = "#654321"; // Flash darker
}
else if (!receivingPower || pixel.timer >= pixel.delay) {
// Reset color when not adjusting
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) {
// Just started receiving power
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));
pixel.color = `rgb(${r}, 69, 19)`;
}
// 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 09:58:40 -04:00
pixel.color = "#FFD700"; // Gold = outputting
2026-03-11 09:56:10 -04:00
}
} else {
2026-03-11 09:58:40 -04:00
// Lost power, reset
pixel.powered = false;
pixel.timer = 0;
2026-03-11 09:56:10 -04:00
}
}
};