Update mod.js
This commit is contained in:
parent
34efe7c35a
commit
b2e2cd2316
115
mod.js
115
mod.js
|
|
@ -1,61 +1,46 @@
|
||||||
// my1stmod.js - A configurable delay element for Sandboxels
|
// my1stmod.js - Configurable delay gate for Sandboxels
|
||||||
// When powered from the bottom, it waits for a delay then outputs power to the top
|
|
||||||
// When powered from the sides, it changes the delay duration
|
|
||||||
|
|
||||||
elements.delay_gate = {
|
elements.delay_gate = {
|
||||||
color: "#8B4513", // Saddle brown color
|
color: "#8B4513",
|
||||||
behavior: [
|
behavior: behaviors.wall, // Fixed: lowercase 'wall'
|
||||||
["XX","SH:delay_gate","XX"], // Top: outputs shock to above
|
|
||||||
["SH:delay_gate","XX","SH:delay_gate"], // Sides: accept input to change delay
|
|
||||||
["XX","SH","XX"] // Bottom: accept power input
|
|
||||||
],
|
|
||||||
category: "machines",
|
category: "machines",
|
||||||
state: "solid",
|
state: "solid",
|
||||||
conduct: 1, // Conducts electricity
|
conduct: 1, // Added: allows receiving power
|
||||||
properties: {
|
properties: {
|
||||||
delay: 30, // Default delay in ticks (0.5 seconds at 60fps)
|
delay: 30, // Delay in ticks
|
||||||
timer: 0, // Current timer count
|
timer: 0, // Current countdown
|
||||||
powered: false // Is currently receiving power?
|
powered: false // Is receiving power from below?
|
||||||
},
|
},
|
||||||
tick: function(pixel) {
|
tick: function(pixel) {
|
||||||
// Initialize properties if not set
|
// Initialize properties
|
||||||
if (pixel.delay === undefined) pixel.delay = 30;
|
if (pixel.delay === undefined) pixel.delay = 30;
|
||||||
if (pixel.timer === undefined) pixel.timer = 0;
|
if (pixel.timer === undefined) pixel.timer = 0;
|
||||||
if (pixel.powered === undefined) pixel.powered = false;
|
if (pixel.powered === undefined) pixel.powered = false;
|
||||||
|
|
||||||
// Check for power input from below (pixel.y + 1)
|
// Check power from below (input)
|
||||||
let below = getPixel(pixel.x, pixel.y + 1);
|
let below = getPixel(pixel.x, pixel.y + 1);
|
||||||
let receivingPower = false;
|
let receivingPower = below && (below.charge || below.chargeCD);
|
||||||
|
|
||||||
if (below && (below.charge || below.chargeCD)) {
|
// Check side inputs for delay adjustment
|
||||||
receivingPower = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Check for side inputs to adjust delay (left = decrease, right = increase)
|
|
||||||
let left = getPixel(pixel.x - 1, pixel.y);
|
let left = getPixel(pixel.x - 1, pixel.y);
|
||||||
let right = getPixel(pixel.x + 1, pixel.y);
|
let right = getPixel(pixel.x + 1, pixel.y);
|
||||||
|
|
||||||
// Left side powered = decrease delay (faster)
|
// Left side = decrease delay (minimum 5)
|
||||||
if (left && (left.charge || left.chargeCD) && pixel.delay > 5) {
|
if (left && (left.charge || left.chargeCD) && pixel.delay > 5) {
|
||||||
pixel.delay--;
|
pixel.delay--;
|
||||||
// Visual feedback - flash lighter
|
pixel.color = "#A0522D"; // Flash lighter
|
||||||
pixel.color = "#A0522D";
|
|
||||||
setTimeout(() => {
|
|
||||||
if (pixel) pixel.color = "#8B4513";
|
|
||||||
}, 100);
|
|
||||||
}
|
}
|
||||||
|
// Right side = increase delay (maximum 300)
|
||||||
// Right side powered = increase delay (slower)
|
else if (right && (right.charge || right.chargeCD) && pixel.delay < 300) {
|
||||||
if (right && (right.charge || right.chargeCD) && pixel.delay < 300) {
|
|
||||||
pixel.delay++;
|
pixel.delay++;
|
||||||
// Visual feedback - flash darker
|
pixel.color = "#654321"; // Flash darker
|
||||||
pixel.color = "#654321";
|
}
|
||||||
setTimeout(() => {
|
else if (!receivingPower || pixel.timer >= pixel.delay) {
|
||||||
if (pixel) pixel.color = "#8B4513";
|
// Reset color when not adjusting
|
||||||
}, 100);
|
pixel.color = "#8B4513";
|
||||||
}
|
}
|
||||||
|
|
||||||
// Handle power delay logic
|
// Main delay logic
|
||||||
if (receivingPower) {
|
if (receivingPower) {
|
||||||
if (!pixel.powered) {
|
if (!pixel.powered) {
|
||||||
// Just started receiving power
|
// Just started receiving power
|
||||||
|
|
@ -63,52 +48,28 @@ elements.delay_gate = {
|
||||||
pixel.timer = 0;
|
pixel.timer = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Increment timer while powered
|
|
||||||
pixel.timer++;
|
pixel.timer++;
|
||||||
|
|
||||||
// Check if delay reached
|
// Visual progress indication
|
||||||
if (pixel.timer >= pixel.delay) {
|
if (pixel.timer < pixel.delay) {
|
||||||
// Output power to above
|
|
||||||
let above = getPixel(pixel.x, pixel.y - 1);
|
|
||||||
if (above && above.conduct) {
|
|
||||||
above.charge = 1;
|
|
||||||
above.chargeCD = 5; // Charge cooldown
|
|
||||||
}
|
|
||||||
// Visual indicator - turn yellow when outputting
|
|
||||||
pixel.color = "#FFD700";
|
|
||||||
} else {
|
|
||||||
// Waiting state - pulsing color based on progress
|
|
||||||
let progress = pixel.timer / pixel.delay;
|
let progress = pixel.timer / pixel.delay;
|
||||||
let r = Math.floor(139 + (255 - 139) * progress);
|
let r = Math.floor(139 + (100 * progress));
|
||||||
let g = Math.floor(69 + (215 - 69) * progress);
|
pixel.color = `rgb(${r}, 69, 19)`;
|
||||||
let b = Math.floor(19 + (0 - 19) * progress);
|
}
|
||||||
pixel.color = `rgb(${r},${g},${b})`;
|
|
||||||
|
// Output when delay reached
|
||||||
|
if (pixel.timer >= pixel.delay) {
|
||||||
|
let above = getPixel(pixel.x, pixel.y - 1);
|
||||||
|
if (above && elements[above.element].conduct) {
|
||||||
|
above.charge = 1;
|
||||||
|
above.chargeCD = 5;
|
||||||
|
}
|
||||||
|
pixel.color = "#FFD700"; // Gold = outputting
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// No power input
|
// Lost power, reset
|
||||||
if (pixel.powered) {
|
pixel.powered = false;
|
||||||
// Just lost power, reset
|
pixel.timer = 0;
|
||||||
pixel.powered = false;
|
|
||||||
pixel.timer = 0;
|
|
||||||
pixel.color = "#8B4513";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
|
||||||
|
|
||||||
// Optional: Add a tool to manually set delay values
|
|
||||||
elements.delay_setter = {
|
|
||||||
color: "#4B0082",
|
|
||||||
tool: function(pixel) {
|
|
||||||
if (pixel.element === "delay_gate") {
|
|
||||||
// Cycle through preset delays: 10, 30, 60, 120, 300 ticks
|
|
||||||
const delays = [10, 30, 60, 120, 300];
|
|
||||||
let currentIdx = delays.indexOf(pixel.delay);
|
|
||||||
let nextIdx = (currentIdx + 1) % delays.length;
|
|
||||||
pixel.delay = delays[nextIdx];
|
|
||||||
logMessage(`Delay set to ${pixel.delay} ticks`);
|
|
||||||
}
|
|
||||||
},
|
|
||||||
category: "tools",
|
|
||||||
desc: "Click on a Delay Gate to cycle through delay presets"
|
|
||||||
};
|
};
|
||||||
Loading…
Reference in New Issue