Merge pull request #764 from redbirdly/main
This commit is contained in:
commit
86a7308019
|
|
@ -1,19 +1,86 @@
|
||||||
// CircuitCore: adds circuits to sandboxels, logicgates.js is required
|
// CircuitCore: adds circuits to sandboxels, logicgates.js is required
|
||||||
|
|
||||||
/*if (!enabledMods.includes("mods/betterSettings.js")) { enabledMods.unshift("mods/betterSettings.js"); localStorage.setItem("enabledMods", JSON.stringify(enabledMods)); window.location.reload() };
|
if (!enabledMods.includes("mods/betterSettings.js")) { enabledMods.unshift("mods/betterSettings.js"); localStorage.setItem("enabledMods", JSON.stringify(enabledMods)); window.location.reload() };
|
||||||
|
if (!enabledMods.includes("mods/logicgates.js")) { enabledMods.unshift("mods/logicgates.js"); localStorage.setItem("enabledMods", JSON.stringify(enabledMods)); window.location.reload() };
|
||||||
|
var lightmapEnabled = enabledMods.includes("mods/lightmap.js") || enabledMods.includes("mods/fast_lightmap.js");
|
||||||
|
|
||||||
var cc_settingsTab = new SettingsTab("CircuitCore");
|
var cc_settingsTab = new SettingsTab("CircuitCore");
|
||||||
var cc_setting1 = new Setting("Default Memory Fill; 0=empty,1=random,2=fill custom,3=custom data", "mem_fill", settingType.NUMBER, false, "The default method used to initialize ROM/RAM memory devices");
|
var cc_setting1 = new Setting("If true then circuits will emit heat", "mem_fill", settingType.BOOLEAN, false, defaultValue=true);
|
||||||
var cc_setting2 = new Setting("Example Setting 2", "element", settingType.TEXT, false, "2");
|
//var cc_setting2 = new Setting("Example Setting 2", "element", settingType.TEXT, false, "2");
|
||||||
cc_settingsTab.registerSettings("Default Memory Fill", cc_setting1);
|
cc_settingsTab.registerSettings("OverHeating", cc_setting1);
|
||||||
cc_settingsTab.registerSettings("Setting 2", cc_setting2);
|
//cc_settingsTab.registerSettings("Setting 2", cc_setting2);
|
||||||
settingsManager.registerTab(cc_settingsTab);*/
|
settingsManager.registerTab(cc_settingsTab);
|
||||||
|
|
||||||
var dataVisualizationPalette16 = [
|
var dataVisualizationPalette16 = [
|
||||||
"#000000", "#ff0000", "#ff7700", "#ffff00", "#00ff00", "#00ffff", "#0000ff", "#ff00ff",
|
"#000000", "#ff0000", "#ff7700", "#ffff00", "#00ff00", "#00ffff", "#0000ff", "#ff00ff",
|
||||||
"#777777", "#770000", "#773300", "#777700", "#007700", "#007777", "#000077", "#770077",
|
"#777777", "#770000", "#773300", "#777700", "#007700", "#007777", "#000077", "#770077",
|
||||||
];
|
];
|
||||||
|
|
||||||
|
function hueLerp(value) {
|
||||||
|
// Clamp the value between -50 and 400
|
||||||
|
if (value < -50) value = -50;
|
||||||
|
if (value > 400) value = 400;
|
||||||
|
|
||||||
|
let r, g, b;
|
||||||
|
|
||||||
|
if (value <= 300) {
|
||||||
|
// Interpolate between blue and red
|
||||||
|
let t = (value + 50) / 350; // Normalize value from -50 to 300 to a 0-1 range
|
||||||
|
r = Math.round(255 * t);
|
||||||
|
g = 0;
|
||||||
|
b = Math.round(255 * (1 - t));
|
||||||
|
} else {
|
||||||
|
// Interpolate between red and white
|
||||||
|
let t = (value - 300) / 100; // Normalize value from 300 to 400 to a 0-1 range
|
||||||
|
r = 255;
|
||||||
|
g = Math.round(255 * t);
|
||||||
|
b = Math.round(255 * t);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Convert RGB values to a hex string
|
||||||
|
return "#" + ((1 << 24) + (r << 16) + (g << 8) + b).toString(16).slice(1).toUpperCase();
|
||||||
|
}
|
||||||
|
|
||||||
|
function cc_rgbToArray(colorString) {
|
||||||
|
if (typeof colorString !== 'string') {
|
||||||
|
console.error('Invalid colorString:', colorString);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (colorString.startsWith('rgb')) {
|
||||||
|
return colorString.slice(4, -1).split(',').map(val => parseInt(val.trim()));
|
||||||
|
} else if (colorString.startsWith('#')) {
|
||||||
|
let hex = colorString.slice(1);
|
||||||
|
|
||||||
|
// Handle shorthand hex (e.g., #03F)
|
||||||
|
if (hex.length === 3) {
|
||||||
|
hex = hex.split('').map(char => char + char).join('');
|
||||||
|
}
|
||||||
|
|
||||||
|
if (hex.length !== 6) {
|
||||||
|
console.error('Invalid hex color:', colorString);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
const r = parseInt(hex.slice(0, 2), 16);
|
||||||
|
const g = parseInt(hex.slice(2, 4), 16);
|
||||||
|
const b = parseInt(hex.slice(4, 6), 16);
|
||||||
|
|
||||||
|
return [r, g, b];
|
||||||
|
} else {
|
||||||
|
console.error('Invalid color format:', colorString);
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function cc_arrayToRgbString(rgbArray) {
|
||||||
|
return `rgb(${rgbArray.join(', ')})`;
|
||||||
|
}
|
||||||
|
|
||||||
|
function cc_scaleList(numbers, scale) {
|
||||||
|
return numbers.map(number => number * scale);
|
||||||
|
}
|
||||||
|
|
||||||
function binaryArrayToNumber(binaryArray) {
|
function binaryArrayToNumber(binaryArray) {
|
||||||
return binaryArray.reduce((acc, bit, index) => acc + bit * Math.pow(2, (binaryArray.length - 1) - index), 0);
|
return binaryArray.reduce((acc, bit, index) => acc + bit * Math.pow(2, (binaryArray.length - 1) - index), 0);
|
||||||
}
|
}
|
||||||
|
|
@ -152,7 +219,7 @@ function setPin(pixel, pins, index, value, rotation=pixel.circuitRotation) {
|
||||||
// Circuits
|
// Circuits
|
||||||
elements.four_bit_enabler_circuit = {
|
elements.four_bit_enabler_circuit = {
|
||||||
centered: true,
|
centered: true,
|
||||||
tick: function(pixel) {
|
cc_stableTick: function(pixel) {
|
||||||
var pins = [
|
var pins = [
|
||||||
// Data inputs (D0-D3)
|
// Data inputs (D0-D3)
|
||||||
[-3, -2, true], // D0
|
[-3, -2, true], // D0
|
||||||
|
|
@ -209,7 +276,7 @@ elements.four_bit_enabler_circuit = {
|
||||||
|
|
||||||
elements.randomizer = {
|
elements.randomizer = {
|
||||||
color: "#FFCCFF",
|
color: "#FFCCFF",
|
||||||
tick: function(pixel) {
|
cc_stableTick: function(pixel) {
|
||||||
for (var i = 0; i < adjacentCoords.length; i++) {
|
for (var i = 0; i < adjacentCoords.length; i++) {
|
||||||
var coord = adjacentCoords[i];
|
var coord = adjacentCoords[i];
|
||||||
var x = pixel.x + coord[0];
|
var x = pixel.x + coord[0];
|
||||||
|
|
@ -230,7 +297,7 @@ elements.randomizer = {
|
||||||
}
|
}
|
||||||
|
|
||||||
elements.four_bit_randomizer_circuit = {
|
elements.four_bit_randomizer_circuit = {
|
||||||
tick: function(pixel) {
|
cc_stableTick: function(pixel) {
|
||||||
var pins = [
|
var pins = [
|
||||||
// Clock input
|
// Clock input
|
||||||
[0, -2, true], // Clock
|
[0, -2, true], // Clock
|
||||||
|
|
@ -278,9 +345,51 @@ elements.four_bit_randomizer_circuit = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
var tempVar = 0;
|
||||||
|
elements.temperature_sensor = {
|
||||||
|
behavior: behaviors.WALL,
|
||||||
|
onSelect: function() {
|
||||||
|
var answertemp = Number(prompt("Set your target temperature:",(tempVar||undefined)));
|
||||||
|
if (!answertemp) { return }
|
||||||
|
tempVar = answertemp;
|
||||||
|
},
|
||||||
|
hoverStat: function(pixel) {
|
||||||
|
return `TargetTmp: {pixel.targetTemp}`;
|
||||||
|
},
|
||||||
|
cc_stableTick: function(pixel) {
|
||||||
|
if (pixel.start === pixelTicks){
|
||||||
|
pixel.targetTemp = tempVar;
|
||||||
|
}
|
||||||
|
|
||||||
|
pixel.color = hueLerp(pixel.targetTemp);
|
||||||
|
|
||||||
|
pixel.active = pixel.temp >= pixel.targetTemp;
|
||||||
|
var neighbors = getNeighbors(pixel);
|
||||||
|
for (var i = 0;i < neighbors.length;i++) {
|
||||||
|
var neighbor = neighbors[i];
|
||||||
|
|
||||||
|
// Check if it's a wire
|
||||||
|
if (elements[neighbor.element].conduct > 0 && pixel.active) {
|
||||||
|
neighbor.charge = 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Check if it's a logic wire (logicgates.js)
|
||||||
|
if (neighbor.lstate != undefined) {
|
||||||
|
if (pixel.active) {
|
||||||
|
neighbor.lstate = 2;
|
||||||
|
neighbor.color = pixelColorPick(neighbor, "#ffe49c");
|
||||||
|
} else {
|
||||||
|
neighbor.lstate = -2;
|
||||||
|
neighbor.color = pixelColorPick(neighbor, "#3d4d2c");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/*elements.ROM_circuit = {
|
/*elements.ROM_circuit = {
|
||||||
previewSize: false,
|
previewSize: false,
|
||||||
tick: function(pixel) {
|
cc_stableTick: function(pixel) {
|
||||||
var romWidth = 16;
|
var romWidth = 16;
|
||||||
var romHeight = 16;
|
var romHeight = 16;
|
||||||
|
|
||||||
|
|
@ -358,16 +467,17 @@ function general_encoder(inputBits) {
|
||||||
|
|
||||||
// Define input pins
|
// Define input pins
|
||||||
for (var i = 0; i < inputBits; i++) {
|
for (var i = 0; i < inputBits; i++) {
|
||||||
pins.push([-Math.floor(circuitWidth / 2) + 1 + 2 * i, outputBits + 1, true]);
|
pins.push([Math.floor(circuitWidth / 2) - 1 - (2 * i), outputBits + 1, true]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define output pins
|
// Define output pins
|
||||||
for (var i = 0; i < outputBits; i++) {
|
for (var i = 0; i < outputBits; i++) {
|
||||||
pins.push([Math.floor(circuitWidth / 2) + 1, -outputBits + 1 + 2 * i, false]); // Right outputs
|
pins.push([Math.floor(circuitWidth / 2) + 1, outputBits - 1 - (2 * i), false]); // Right outputs
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Mirrored outputs
|
||||||
for (var i = 0; i < outputBits; i++) {
|
for (var i = 0; i < outputBits; i++) {
|
||||||
pins.push([-Math.floor(circuitWidth / 2) - 1, -outputBits + 1 + 2 * i, false]); // Left outputs
|
pins.push([-Math.floor(circuitWidth / 2) - 1, outputBits - 1 - (2 * i), false]); // Left outputs
|
||||||
}
|
}
|
||||||
|
|
||||||
initializeCircuit(pixel, pins, circuitWidth, circuitHeight);
|
initializeCircuit(pixel, pins, circuitWidth, circuitHeight);
|
||||||
|
|
@ -392,22 +502,22 @@ function general_encoder(inputBits) {
|
||||||
|
|
||||||
// Define a 2-to-1 encoder using the general_encoder function
|
// Define a 2-to-1 encoder using the general_encoder function
|
||||||
elements.two_to_one_encoder_circuit = {
|
elements.two_to_one_encoder_circuit = {
|
||||||
tick: general_encoder(2)
|
cc_stableTick: general_encoder(2)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Define a 4-to-2 encoder using the general_encoder function
|
// Define a 4-to-2 encoder using the general_encoder function
|
||||||
elements.four_to_two_encoder_circuit = {
|
elements.four_to_two_encoder_circuit = {
|
||||||
tick: general_encoder(4)
|
cc_stableTick: general_encoder(4)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Define an 8-to-3 encoder using the general_encoder function
|
// Define an 8-to-3 encoder using the general_encoder function
|
||||||
elements.eight_to_three_encoder_circuit = {
|
elements.eight_to_three_encoder_circuit = {
|
||||||
tick: general_encoder(8)
|
cc_stableTick: general_encoder(8)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Define a 16-to-4 encoder using the general_encoder function
|
// Define a 16-to-4 encoder using the general_encoder function
|
||||||
elements.sixteen_to_four_encoder_circuit = {
|
elements.sixteen_to_four_encoder_circuit = {
|
||||||
tick: general_encoder(16)
|
cc_stableTick: general_encoder(16)
|
||||||
};
|
};
|
||||||
|
|
||||||
function general_demultiplexer(selectorBits) {
|
function general_demultiplexer(selectorBits) {
|
||||||
|
|
@ -427,7 +537,7 @@ function general_demultiplexer(selectorBits) {
|
||||||
|
|
||||||
// Define output pins
|
// Define output pins
|
||||||
for (var i = 0; i < outputCount; i++) {
|
for (var i = 0; i < outputCount; i++) {
|
||||||
pins.push([Math.floor(circuitWidth / 2) + 1, -Math.floor(circuitHeight / 2) + 1 + 2 * i, false]);
|
pins.push([Math.floor(circuitWidth / 2) + 1, Math.floor(circuitHeight / 2) - 1 - (2 * i), false]);
|
||||||
}
|
}
|
||||||
|
|
||||||
initializeCircuit(pixel, pins, circuitWidth, circuitHeight);
|
initializeCircuit(pixel, pins, circuitWidth, circuitHeight);
|
||||||
|
|
@ -450,22 +560,22 @@ function general_demultiplexer(selectorBits) {
|
||||||
|
|
||||||
// Define a 1-to-2 demultiplexer using the general_demultiplexer function
|
// Define a 1-to-2 demultiplexer using the general_demultiplexer function
|
||||||
elements.one_to_two_demultiplexer_circuit = {
|
elements.one_to_two_demultiplexer_circuit = {
|
||||||
tick: general_demultiplexer(1)
|
cc_stableTick: general_demultiplexer(1)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Define a 1-to-4 demultiplexer using the general_demultiplexer function
|
// Define a 1-to-4 demultiplexer using the general_demultiplexer function
|
||||||
elements.one_to_four_demultiplexer_circuit = {
|
elements.one_to_four_demultiplexer_circuit = {
|
||||||
tick: general_demultiplexer(2)
|
cc_stableTick: general_demultiplexer(2)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Define a 1-to-8 demultiplexer using the general_demultiplexer function
|
// Define a 1-to-8 demultiplexer using the general_demultiplexer function
|
||||||
elements.one_to_eight_demultiplexer_circuit = {
|
elements.one_to_eight_demultiplexer_circuit = {
|
||||||
tick: general_demultiplexer(3)
|
cc_stableTick: general_demultiplexer(3)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Define a 1-to-16 demultiplexer using the general_demultiplexer function
|
// Define a 1-to-16 demultiplexer using the general_demultiplexer function
|
||||||
elements.one_to_sixteen_demultiplexer_circuit = {
|
elements.one_to_sixteen_demultiplexer_circuit = {
|
||||||
tick: general_demultiplexer(4)
|
cc_stableTick: general_demultiplexer(4)
|
||||||
};
|
};
|
||||||
|
|
||||||
function general_decoder(inputBits) {
|
function general_decoder(inputBits) {
|
||||||
|
|
@ -477,16 +587,16 @@ function general_decoder(inputBits) {
|
||||||
|
|
||||||
// Define input pins
|
// Define input pins
|
||||||
for (var i = 0; i < inputBits; i++) {
|
for (var i = 0; i < inputBits; i++) {
|
||||||
pins.push([-Math.floor(circuitWidth / 2) + 1 + 2 * i, outputCount + 1, true]);
|
pins.push([Math.floor(circuitWidth / 2) - 1 - (2 * i), outputCount + 1, true]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define output pins
|
// Define output pins
|
||||||
for (var i = 0; i < outputCount; i++) {
|
for (var i = 0; i < outputCount; i++) {
|
||||||
pins.push([Math.floor(circuitWidth / 2) + 1, -outputCount + 1 + 2 * i, false]); // Right outputs
|
pins.push([Math.floor(circuitWidth / 2) + 1, outputCount - 1 - (2 * i), false]); // Right outputs
|
||||||
}
|
}
|
||||||
|
|
||||||
for (var i = 0; i < outputCount; i++) {
|
for (var i = 0; i < outputCount; i++) {
|
||||||
pins.push([-Math.floor(circuitWidth / 2) - 1, -outputCount + 1 + 2 * i, false]); // Left outputs
|
pins.push([-Math.floor(circuitWidth / 2) - 1, outputCount - 1 - (2 * i), false]); // Left outputs
|
||||||
}
|
}
|
||||||
|
|
||||||
initializeCircuit(pixel, pins, circuitWidth, circuitHeight);
|
initializeCircuit(pixel, pins, circuitWidth, circuitHeight);
|
||||||
|
|
@ -509,19 +619,19 @@ function general_decoder(inputBits) {
|
||||||
}
|
}
|
||||||
|
|
||||||
elements.one_to_two_decoder_circuit = {
|
elements.one_to_two_decoder_circuit = {
|
||||||
tick: general_decoder(1)
|
cc_stableTick: general_decoder(1)
|
||||||
};
|
};
|
||||||
|
|
||||||
elements.two_to_four_decoder_circuit = {
|
elements.two_to_four_decoder_circuit = {
|
||||||
tick: general_decoder(2)
|
cc_stableTick: general_decoder(2)
|
||||||
};
|
};
|
||||||
|
|
||||||
elements.three_to_eight_decoder_circuit = {
|
elements.three_to_eight_decoder_circuit = {
|
||||||
tick: general_decoder(3)
|
cc_stableTick: general_decoder(3)
|
||||||
};
|
};
|
||||||
|
|
||||||
elements.four_to_sixteen_decoder_circuit = {
|
elements.four_to_sixteen_decoder_circuit = {
|
||||||
tick: general_decoder(4)
|
cc_stableTick: general_decoder(4)
|
||||||
};
|
};
|
||||||
|
|
||||||
function general_multiplexer(inputLines) {
|
function general_multiplexer(inputLines) {
|
||||||
|
|
@ -533,12 +643,12 @@ function general_multiplexer(inputLines) {
|
||||||
|
|
||||||
// Define selector pins
|
// Define selector pins
|
||||||
for (var i = 0; i < selectorBits; i++) {
|
for (var i = 0; i < selectorBits; i++) {
|
||||||
pins.push([-Math.floor(circuitWidth / 2) + 1 + 2 * i, inputLines + 1, true]);
|
pins.push([Math.floor(circuitWidth / 2) - 1 - (2 * i), inputLines + 1, true]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define input data pins
|
// Define input data pins
|
||||||
for (var i = 0; i < inputLines; i++) {
|
for (var i = 0; i < inputLines; i++) {
|
||||||
pins.push([-Math.floor(circuitWidth / 2) - 1, -inputLines + 1 + 2 * i, true]);
|
pins.push([-Math.floor(circuitWidth / 2) - 1, inputLines - 1 - (2 * i), true]);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Define output pin
|
// Define output pin
|
||||||
|
|
@ -560,32 +670,32 @@ function general_multiplexer(inputLines) {
|
||||||
|
|
||||||
// Define a 2-input multiplexer using the general_multiplexer function
|
// Define a 2-input multiplexer using the general_multiplexer function
|
||||||
elements.two_to_one_multiplexer_circuit = {
|
elements.two_to_one_multiplexer_circuit = {
|
||||||
tick: general_multiplexer(2)
|
cc_stableTick: general_multiplexer(2)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Define a 4-input multiplexer using the general_multiplexer function
|
// Define a 4-input multiplexer using the general_multiplexer function
|
||||||
elements.four_to_one_multiplexer_circuit = {
|
elements.four_to_one_multiplexer_circuit = {
|
||||||
tick: general_multiplexer(4)
|
cc_stableTick: general_multiplexer(4)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Define an 8-input multiplexer using the general_multiplexer function
|
// Define an 8-input multiplexer using the general_multiplexer function
|
||||||
elements.eight_to_one_multiplexer_circuit = {
|
elements.eight_to_one_multiplexer_circuit = {
|
||||||
tick: general_multiplexer(8)
|
cc_stableTick: general_multiplexer(8)
|
||||||
};
|
};
|
||||||
|
|
||||||
// Define an 8-input multiplexer using the general_multiplexer function
|
// Define an 8-input multiplexer using the general_multiplexer function
|
||||||
elements.sixteen_to_one_multiplexer_circuit = {
|
elements.sixteen_to_one_multiplexer_circuit = {
|
||||||
tick: general_multiplexer(16)
|
cc_stableTick: general_multiplexer(16)
|
||||||
};
|
};
|
||||||
|
|
||||||
elements.four_bit_PISO_shift_register_circuit = {
|
elements.four_bit_PISO_shift_register_circuit = {
|
||||||
tick: function(pixel) {
|
cc_stableTick: function(pixel) {
|
||||||
var pins = [
|
var pins = [
|
||||||
// Data inputs (D0-D3)
|
// Data inputs (D0-D3)
|
||||||
[-3, -3, true], // D0
|
|
||||||
[-1, -3, true], // D1
|
|
||||||
[1, -3, true], // D2
|
|
||||||
[3, -3, true], // D3
|
[3, -3, true], // D3
|
||||||
|
[1, -3, true], // D2
|
||||||
|
[-1, -3, true], // D1
|
||||||
|
[-3, -3, true], // D0
|
||||||
|
|
||||||
// Control input (Load/Shift Enable)
|
// Control input (Load/Shift Enable)
|
||||||
[-5, -1, true], // Load/Shift Enable
|
[-5, -1, true], // Load/Shift Enable
|
||||||
|
|
@ -656,7 +766,7 @@ elements.four_bit_PISO_shift_register_circuit = {
|
||||||
};
|
};
|
||||||
|
|
||||||
elements.four_bit_SIPO_shift_register_circuit = {
|
elements.four_bit_SIPO_shift_register_circuit = {
|
||||||
tick: function(pixel) {
|
cc_stableTick: function(pixel) {
|
||||||
var pins = [
|
var pins = [
|
||||||
// Serial input (Data In)
|
// Serial input (Data In)
|
||||||
[-2, -3, true], // Data In
|
[-2, -3, true], // Data In
|
||||||
|
|
@ -665,10 +775,10 @@ elements.four_bit_SIPO_shift_register_circuit = {
|
||||||
[-2, -1, true], // Clock
|
[-2, -1, true], // Clock
|
||||||
|
|
||||||
// Parallel outputs (Q0-Q3)
|
// Parallel outputs (Q0-Q3)
|
||||||
[2, -3, false], // Q0
|
[2, 3, false], // Q3
|
||||||
[2, -1, false], // Q1
|
|
||||||
[2, 1, false], // Q2
|
[2, 1, false], // Q2
|
||||||
[2, 3, false] // Q3
|
[2, -1, false], // Q1
|
||||||
|
[2, -3, false] // Q0
|
||||||
];
|
];
|
||||||
|
|
||||||
initializeCircuit(pixel, pins, 3, 9);
|
initializeCircuit(pixel, pins, 3, 9);
|
||||||
|
|
@ -699,7 +809,7 @@ elements.four_bit_SIPO_shift_register_circuit = {
|
||||||
};
|
};
|
||||||
|
|
||||||
elements.four_bit_program_counter_circuit = {
|
elements.four_bit_program_counter_circuit = {
|
||||||
tick: function(pixel) {
|
cc_stableTick: function(pixel) {
|
||||||
var pins = [
|
var pins = [
|
||||||
// Data inputs (D0-D3)
|
// Data inputs (D0-D3)
|
||||||
[-3, -3, true], // D0
|
[-3, -3, true], // D0
|
||||||
|
|
@ -771,7 +881,7 @@ elements.four_bit_program_counter_circuit = {
|
||||||
};
|
};
|
||||||
|
|
||||||
elements.four_bit_register_circuit = {
|
elements.four_bit_register_circuit = {
|
||||||
tick: function(pixel) {
|
cc_stableTick: function(pixel) {
|
||||||
var pins = [
|
var pins = [
|
||||||
// Data inputs (D0-D3)
|
// Data inputs (D0-D3)
|
||||||
[-3, -3, true], // D0
|
[-3, -3, true], // D0
|
||||||
|
|
@ -831,7 +941,7 @@ elements.four_bit_register_circuit = {
|
||||||
};
|
};
|
||||||
|
|
||||||
elements.SR_latch_circuit = {
|
elements.SR_latch_circuit = {
|
||||||
tick: function(pixel) {
|
cc_stableTick: function(pixel) {
|
||||||
var pins = [
|
var pins = [
|
||||||
[0, -2, true], // Input: Set
|
[0, -2, true], // Input: Set
|
||||||
[0, 2, true], // Input: Reset
|
[0, 2, true], // Input: Reset
|
||||||
|
|
@ -849,7 +959,7 @@ elements.SR_latch_circuit = {
|
||||||
};
|
};
|
||||||
|
|
||||||
elements.T_flip_flop_circuit = {
|
elements.T_flip_flop_circuit = {
|
||||||
tick: function(pixel) {
|
cc_stableTick: function(pixel) {
|
||||||
var pins = [
|
var pins = [
|
||||||
[0, -2, true], // Input: Toggle (T)
|
[0, -2, true], // Input: Toggle (T)
|
||||||
[2, 0, false], // Output (Q)
|
[2, 0, false], // Output (Q)
|
||||||
|
|
@ -880,7 +990,7 @@ elements.T_flip_flop_circuit = {
|
||||||
};
|
};
|
||||||
|
|
||||||
elements.D_latch_circuit = {
|
elements.D_latch_circuit = {
|
||||||
tick: function(pixel) {
|
cc_stableTick: function(pixel) {
|
||||||
var pins = [
|
var pins = [
|
||||||
[0, -2, true], // Input: Data
|
[0, -2, true], // Input: Data
|
||||||
[2, 0, true], // Input: Enable
|
[2, 0, true], // Input: Enable
|
||||||
|
|
@ -902,7 +1012,7 @@ elements.D_latch_circuit = {
|
||||||
};
|
};
|
||||||
|
|
||||||
elements.D_flip_flop_circuit = {
|
elements.D_flip_flop_circuit = {
|
||||||
tick: function(pixel) {
|
cc_stableTick: function(pixel) {
|
||||||
var pins = [
|
var pins = [
|
||||||
[0, -2, true], // Input: Data
|
[0, -2, true], // Input: Data
|
||||||
[2, 0, true], // Input: Enable
|
[2, 0, true], // Input: Enable
|
||||||
|
|
@ -941,7 +1051,7 @@ elements.D_flip_flop_circuit = {
|
||||||
};
|
};
|
||||||
|
|
||||||
elements.four_bit_D_latch_circuit = {
|
elements.four_bit_D_latch_circuit = {
|
||||||
tick: function(pixel) {
|
cc_stableTick: function(pixel) {
|
||||||
var pins = [
|
var pins = [
|
||||||
// Data inputs (D0-D3)
|
// Data inputs (D0-D3)
|
||||||
[-3, -2, true], // D0
|
[-3, -2, true], // D0
|
||||||
|
|
@ -990,7 +1100,7 @@ elements.four_bit_D_latch_circuit = {
|
||||||
};
|
};
|
||||||
|
|
||||||
elements.four_bit_D_flip_flop_circuit = {
|
elements.four_bit_D_flip_flop_circuit = {
|
||||||
tick: function(pixel) {
|
cc_stableTick: function(pixel) {
|
||||||
var pins = [
|
var pins = [
|
||||||
// Data inputs (D0-D3)
|
// Data inputs (D0-D3)
|
||||||
[-3, -2, true], // D0
|
[-3, -2, true], // D0
|
||||||
|
|
@ -1047,22 +1157,22 @@ elements.four_bit_D_flip_flop_circuit = {
|
||||||
};
|
};
|
||||||
|
|
||||||
elements.four_bit_incrementer_circuit = {
|
elements.four_bit_incrementer_circuit = {
|
||||||
tick: function(pixel) {
|
cc_stableTick: function(pixel) {
|
||||||
var pins = [
|
var pins = [
|
||||||
// 4-bit number inputs (N0-N3)
|
// 4-bit number inputs (N0-N3)
|
||||||
[-3, -2, true], // N0
|
|
||||||
[-1, -2, true], // N1
|
|
||||||
[1, -2, true], // N2
|
|
||||||
[3, -2, true], // N3
|
[3, -2, true], // N3
|
||||||
|
[1, -2, true], // N2
|
||||||
|
[-1, -2, true], // N1
|
||||||
|
[-3, -2, true], // N0
|
||||||
|
|
||||||
// Increment control input (INC)
|
// Increment control input (INC)
|
||||||
[-5, 0, true], // Increment (INC)
|
[-5, 0, true], // Increment (INC)
|
||||||
|
|
||||||
// Outputs (Q0-Q3)
|
// Outputs (Q0-Q3)
|
||||||
[-3, 2, false], // Q0
|
|
||||||
[-1, 2, false], // Q1
|
|
||||||
[1, 2, false], // Q2
|
|
||||||
[3, 2, false], // Q3
|
[3, 2, false], // Q3
|
||||||
|
[1, 2, false], // Q2
|
||||||
|
[-1, 2, false], // Q1
|
||||||
|
[-3, 2, false], // Q0
|
||||||
|
|
||||||
// Carry out
|
// Carry out
|
||||||
[5, 0, false] // Carry out (COUT)
|
[5, 0, false] // Carry out (COUT)
|
||||||
|
|
@ -1104,28 +1214,28 @@ elements.four_bit_incrementer_circuit = {
|
||||||
};
|
};
|
||||||
|
|
||||||
elements.four_bit_adder_circuit = {
|
elements.four_bit_adder_circuit = {
|
||||||
tick: function(pixel) {
|
cc_stableTick: function(pixel) {
|
||||||
var pins = [
|
var pins = [
|
||||||
// First 4-bit number (A)
|
// First 4-bit number (A)
|
||||||
[-7, -2, true], // A0
|
|
||||||
[-5, -2, true], // A1
|
|
||||||
[-3, -2, true], // A2
|
|
||||||
[-1, -2, true], // A3
|
[-1, -2, true], // A3
|
||||||
|
[-3, -2, true], // A2
|
||||||
|
[-5, -2, true], // A1
|
||||||
|
[-7, -2, true], // A0
|
||||||
|
|
||||||
// Second 4-bit number (B)
|
// Second 4-bit number (B)
|
||||||
[1, -2, true], // B0
|
|
||||||
[3, -2, true], // B1
|
|
||||||
[5, -2, true], // B2
|
|
||||||
[7, -2, true], // B3
|
[7, -2, true], // B3
|
||||||
|
[5, -2, true], // B2
|
||||||
|
[3, -2, true], // B1
|
||||||
|
[1, -2, true], // B0
|
||||||
|
|
||||||
// Carry-in (C_in)
|
// Carry-in (C_in)
|
||||||
[9, 0, true], // Carry-in (C_in)
|
[9, 0, true], // Carry-in (C_in)
|
||||||
|
|
||||||
// Output sum (S)
|
// Output sum (S)
|
||||||
[-7, 2, false], // S0
|
|
||||||
[-5, 2, false], // S1
|
|
||||||
[-3, 2, false], // S2
|
|
||||||
[-1, 2, false], // S3
|
[-1, 2, false], // S3
|
||||||
|
[-3, 2, false], // S2
|
||||||
|
[-5, 2, false], // S1
|
||||||
|
[-7, 2, false], // S0
|
||||||
[1, 2, false], // Carry Out (C4)
|
[1, 2, false], // Carry Out (C4)
|
||||||
];
|
];
|
||||||
|
|
||||||
|
|
@ -1190,27 +1300,68 @@ function general_clock(speed, s2) {
|
||||||
|
|
||||||
elements.slow_clock = {
|
elements.slow_clock = {
|
||||||
color: "#BB66BB",
|
color: "#BB66BB",
|
||||||
tick: general_clock(64, 32),
|
cc_stableTick: general_clock(64, 32),
|
||||||
}
|
}
|
||||||
|
|
||||||
elements.medium_clock = {
|
elements.medium_clock = {
|
||||||
color: "#DD88DD",
|
color: "#DD88DD",
|
||||||
tick: general_clock(32, 16),
|
cc_stableTick: general_clock(32, 16),
|
||||||
}
|
}
|
||||||
|
|
||||||
elements.fast_clock = {
|
elements.fast_clock = {
|
||||||
color: "#FFAAFF",
|
color: "#FFAAFF",
|
||||||
tick: general_clock(16, 8),
|
cc_stableTick: general_clock(16, 8),
|
||||||
}
|
}
|
||||||
|
|
||||||
elements.very_fast_clock = {
|
elements.very_fast_clock = {
|
||||||
color: "#FFCCFF",
|
color: "#FFCCFF",
|
||||||
tick: general_clock(8, 4),
|
cc_stableTick: general_clock(8, 4),
|
||||||
}
|
}
|
||||||
|
|
||||||
elements.fast_clock = {
|
elements.custom_RGB_led = {
|
||||||
color: "#FFAAFF",
|
cc_stableTick: function(pixel) {
|
||||||
tick: general_clock(16, 8),
|
var pins = [
|
||||||
|
// RGB values
|
||||||
|
[-2, -1, true], // R0
|
||||||
|
[-2, 1, true], // R1
|
||||||
|
[1, -2, true], // G0
|
||||||
|
[-1, -2, true], // G1
|
||||||
|
[2, -1, true], // B0
|
||||||
|
[2, 1, true], // B1
|
||||||
|
];
|
||||||
|
|
||||||
|
initializeCircuit(pixel, pins, 3, 3);
|
||||||
|
|
||||||
|
// Read inputs
|
||||||
|
var l = [
|
||||||
|
checkPin(pixel, pins, 0),
|
||||||
|
checkPin(pixel, pins, 1),
|
||||||
|
checkPin(pixel, pins, 2),
|
||||||
|
checkPin(pixel, pins, 3),
|
||||||
|
checkPin(pixel, pins, 4),
|
||||||
|
checkPin(pixel, pins, 5)
|
||||||
|
];
|
||||||
|
|
||||||
|
var color = { color: cc_scaleList([(l[0] * 2) + l[1], (l[2] * 2) + l[3], (l[4] * 2) + l[5]], (255 / 3) * 10) };
|
||||||
|
|
||||||
|
if (lightmapEnabled && color.color[0] && color.color[1], color.color[2]) {
|
||||||
|
lightmap[Math.floor(pixel.y / lightmapScale)][Math.floor(pixel.x / lightmapScale)] = color;
|
||||||
|
}
|
||||||
|
var scaledColor = cc_scaleList(color.color, 0.1);
|
||||||
|
|
||||||
|
// pixelMap[pixel.x][pixel.y].color = scaledColor;
|
||||||
|
for (let dx = -1; dx <= 1; dx++) {
|
||||||
|
for (let dy = -1; dy <= 1; dy++) {
|
||||||
|
var nx = pixel.x + dx;
|
||||||
|
var ny = pixel.y + dy;
|
||||||
|
|
||||||
|
if (pixelMap[nx] && pixelMap[nx][ny]) {
|
||||||
|
var n = ((2 - (Math.abs(dx) + Math.abs(dy))) + 4) / 6;
|
||||||
|
pixelMap[nx][ny].color = cc_arrayToRgbString(cc_scaleList(scaledColor, n));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var addDisplayCallback = function(pixel, pins, w, h) {
|
var addDisplayCallback = function(pixel, pins, w, h) {
|
||||||
|
|
@ -1228,13 +1379,13 @@ var addDisplayCallback = function(pixel, pins, w, h) {
|
||||||
}
|
}
|
||||||
|
|
||||||
elements.simple_seven_segment_display = {
|
elements.simple_seven_segment_display = {
|
||||||
tick: function(pixel) {
|
cc_stableTick: function(pixel) {
|
||||||
var pins = [
|
var pins = [
|
||||||
// Data inputs (D0-D3)
|
// Data inputs (D0-D3)
|
||||||
[-1, 1, true], // D0
|
[-1, 7, true],
|
||||||
[-1, 3, true], // D1
|
[-1, 5, true],
|
||||||
[-1, 5, true], // D2
|
[-1, 3, true],
|
||||||
[-1, 7, true], // D3
|
[-1, 1, true],
|
||||||
];
|
];
|
||||||
|
|
||||||
initializeCircuit(pixel, pins, 5, 9, false, pixel.circuitRotation, addDisplayCallback);
|
initializeCircuit(pixel, pins, 5, 9, false, pixel.circuitRotation, addDisplayCallback);
|
||||||
|
|
@ -1270,18 +1421,18 @@ elements.simple_seven_segment_display = {
|
||||||
};
|
};
|
||||||
|
|
||||||
elements.simple_double_seven_segment_display = {
|
elements.simple_double_seven_segment_display = {
|
||||||
tick: function(pixel) {
|
cc_stableTick: function(pixel) {
|
||||||
var pins = [
|
var pins = [
|
||||||
// Data inputs (D0-D3)
|
// Data inputs (D0-D3)
|
||||||
[-1, 1, true], // D0
|
[-1, 7, true],
|
||||||
[-1, 3, true], // D1
|
[-1, 5, true],
|
||||||
[-1, 5, true], // D2
|
[-1, 3, true],
|
||||||
[-1, 7, true], // D3
|
[-1, 1, true],
|
||||||
|
|
||||||
[1, -1, true], // D2-0
|
[7, -1, true],
|
||||||
[3, -1, true], // D2-1
|
[5, -1, true],
|
||||||
[5, -1, true], // D2-2
|
[3, -1, true],
|
||||||
[7, -1, true], // D2-3
|
[1, -1, true],
|
||||||
];
|
];
|
||||||
|
|
||||||
initializeCircuit(pixel, pins, 9, 9, false, pixel.circuitRotation, addDisplayCallback);
|
initializeCircuit(pixel, pins, 9, 9, false, pixel.circuitRotation, addDisplayCallback);
|
||||||
|
|
@ -1337,6 +1488,117 @@ elements.simple_double_seven_segment_display = {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function general_display(w, h) {
|
||||||
|
return function(pixel) {
|
||||||
|
var pins = [];
|
||||||
|
|
||||||
|
// X input (X0-Xn)
|
||||||
|
for (var i = 0; i < Math.ceil(Math.log2(w)); i++) {
|
||||||
|
pins.push([-1, (Math.ceil(Math.log2(w)) - i) * 2 - 1, true]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Y input (Y0-Yn)
|
||||||
|
for (var i = 0; i < Math.ceil(Math.log2(h)); i++) {
|
||||||
|
pins.push([(Math.ceil(Math.log2(h)) - i) * 2 - 1, -1, true]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Color input
|
||||||
|
pins.push([11, -1, true]);
|
||||||
|
|
||||||
|
// Reset pin
|
||||||
|
pins.push([13, -1, true]);
|
||||||
|
|
||||||
|
// Clock input
|
||||||
|
pins.push([15, -1, true]);
|
||||||
|
|
||||||
|
// Initialize the circuit with the necessary pins
|
||||||
|
initializeCircuit(pixel, pins, w + 2, h + 2, false, pixel.circuitRotation, addDisplayCallback);
|
||||||
|
|
||||||
|
// Read inputs
|
||||||
|
var X = [];
|
||||||
|
for (var i = 0; i < Math.ceil(Math.log2(w)); i++) {
|
||||||
|
X.push(checkPin(pixel, pins, i));
|
||||||
|
}
|
||||||
|
|
||||||
|
var Y = [];
|
||||||
|
for (var i = 0; i < Math.ceil(Math.log2(h)); i++) {
|
||||||
|
Y.push(checkPin(pixel, pins, Math.ceil(Math.log2(w)) + i));
|
||||||
|
}
|
||||||
|
|
||||||
|
var color = checkPin(pixel, pins, pins.length - 3);
|
||||||
|
var reset = checkPin(pixel, pins, pins.length - 2);
|
||||||
|
var clock = checkPin(pixel, pins, pins.length - 1);
|
||||||
|
|
||||||
|
// Decode X and Y inputs to determine the pixel position
|
||||||
|
var x_pos = 0;
|
||||||
|
for (var i = 0; i < X.length; i++) {
|
||||||
|
x_pos += (X[i] ? 1 : 0) << i;
|
||||||
|
}
|
||||||
|
|
||||||
|
var y_pos = 0;
|
||||||
|
for (var i = 0; i < Y.length; i++) {
|
||||||
|
y_pos += (Y[i] ? 1 : 0) << i;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Display dimension check
|
||||||
|
if (x_pos >= w || y_pos >= h) return;
|
||||||
|
|
||||||
|
var px = pixel.x + 1 + x_pos; // Adjust for the display position
|
||||||
|
var py = pixel.y + 1 + y_pos;
|
||||||
|
|
||||||
|
// Handle reset functionality
|
||||||
|
if (reset) {
|
||||||
|
for (var y = 1; y <= h; y++) {
|
||||||
|
for (var x = 1; x <= w; x++) {
|
||||||
|
var reset_px = pixel.x + x;
|
||||||
|
var reset_py = pixel.y + y;
|
||||||
|
if (pixelMap[reset_px] && pixelMap[reset_px][reset_py] && pixelMap[reset_px][reset_py].element == "art") {
|
||||||
|
pixelMap[reset_px][reset_py].color = "rgb(16, 230, 120)";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Update display on clock pulse
|
||||||
|
if (clock) {
|
||||||
|
if (pixelMap[px] && pixelMap[px][py] && pixelMap[px][py].element == "art") {
|
||||||
|
// Set the pixel color
|
||||||
|
pixelMap[px][py].color = color ? "rgb(16, 230, 120)" : "rgb(16, 230, 120)";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
elements.basic_mono_display_8x8 = {
|
||||||
|
cc_stableTick: general_display(8, 8),
|
||||||
|
};
|
||||||
|
|
||||||
|
elements.basic_mono_display_16x8 = {
|
||||||
|
cc_stableTick: general_display(16, 8),
|
||||||
|
};
|
||||||
|
|
||||||
|
elements.basic_mono_display_16x16 = {
|
||||||
|
cc_stableTick: general_display(16, 16),
|
||||||
|
};
|
||||||
|
|
||||||
|
elements.basic_mono_display_32x16 = {
|
||||||
|
cc_stableTick: general_display(32, 16),
|
||||||
|
};
|
||||||
|
|
||||||
|
elements.basic_mono_display_32x32 = {
|
||||||
|
cc_stableTick: general_display(32, 32),
|
||||||
|
};
|
||||||
|
|
||||||
|
elements.basic_mono_display_64x32 = {
|
||||||
|
cc_stableTick: general_display(64, 32),
|
||||||
|
};
|
||||||
|
|
||||||
|
elements.basic_mono_display_64x64 = {
|
||||||
|
cc_stableTick: general_display(64, 64),
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
function malfunction_chip(pixel) {
|
function malfunction_chip(pixel) {
|
||||||
var emptySpaces = [];
|
var emptySpaces = [];
|
||||||
|
|
||||||
|
|
@ -1367,6 +1629,19 @@ function malfunction_chip(pixel) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//elements.display = {
|
||||||
|
// color: "#444444",
|
||||||
|
// category: "logic",
|
||||||
|
// state: "solid",
|
||||||
|
// behavior: behaviors.WALL,
|
||||||
|
// hoverStat: function(pixel) {
|
||||||
|
// return `Circuit: ${pixel.corePosition}`;
|
||||||
|
// },
|
||||||
|
// cc_stableTick: function(pixel) {
|
||||||
|
//
|
||||||
|
// }
|
||||||
|
//};
|
||||||
|
|
||||||
elements.circuit_material = {
|
elements.circuit_material = {
|
||||||
color: "#444444",
|
color: "#444444",
|
||||||
category: "logic",
|
category: "logic",
|
||||||
|
|
@ -1375,9 +1650,9 @@ elements.circuit_material = {
|
||||||
hoverStat: function(pixel) {
|
hoverStat: function(pixel) {
|
||||||
return `Circuit: ${pixel.corePosition}`;
|
return `Circuit: ${pixel.corePosition}`;
|
||||||
},
|
},
|
||||||
tick: function(pixel) {
|
cc_stableTick: function(pixel) {
|
||||||
// Make it that extreme temperatures can stop the chip from working (for realism)
|
// Make it that extreme temperatures can stop the chip from working (for realism)
|
||||||
if (Math.random() < 0.003) { // Chance to check for temperature or nearby particles
|
if (Math.random() < 0.003 && cc_setting1.value) { // Chance to check for temperature or nearby particles
|
||||||
// Check temperature
|
// Check temperature
|
||||||
if (pixel.temp > 120) {
|
if (pixel.temp > 120) {
|
||||||
// Replace the circuit core with lead if overheating
|
// Replace the circuit core with lead if overheating
|
||||||
|
|
@ -1415,7 +1690,7 @@ elements.input_pin = {
|
||||||
stateHigh: "lead",
|
stateHigh: "lead",
|
||||||
tempHigh: 570,
|
tempHigh: 570,
|
||||||
behavior: behaviors.WALL,
|
behavior: behaviors.WALL,
|
||||||
tick: function(pixel) {
|
cc_stableTick: function(pixel) {
|
||||||
pixel.active = false;
|
pixel.active = false;
|
||||||
var neighbors = getNeighbors(pixel);
|
var neighbors = getNeighbors(pixel);
|
||||||
for (var i = 0;i < neighbors.length;i++) {
|
for (var i = 0;i < neighbors.length;i++) {
|
||||||
|
|
@ -1436,7 +1711,7 @@ elements.output_pin = {
|
||||||
stateHigh: "lead",
|
stateHigh: "lead",
|
||||||
tempHigh: 570,
|
tempHigh: 570,
|
||||||
behavior: behaviors.WALL,
|
behavior: behaviors.WALL,
|
||||||
tick: function(pixel) {
|
cc_stableTick: function(pixel) {
|
||||||
var neighbors = getNeighbors(pixel);
|
var neighbors = getNeighbors(pixel);
|
||||||
for (var i = 0;i < neighbors.length;i++) {
|
for (var i = 0;i < neighbors.length;i++) {
|
||||||
var neighbor = neighbors[i];
|
var neighbor = neighbors[i];
|
||||||
|
|
@ -1482,7 +1757,7 @@ elements.logic_corrupt = {
|
||||||
elements.logic_corrupter_machine = {
|
elements.logic_corrupter_machine = {
|
||||||
color: "#DD33DD",
|
color: "#DD33DD",
|
||||||
category: "logic",
|
category: "logic",
|
||||||
tick: function(pixel) {
|
cc_stableTick: function(pixel) {
|
||||||
var radius = 10
|
var radius = 10
|
||||||
for (var y = pixel.y - radius; y < pixel.y + radius; y++) {
|
for (var y = pixel.y - radius; y < pixel.y + radius; y++) {
|
||||||
for (var x = pixel.x - radius; x < pixel.x + radius; x++) {
|
for (var x = pixel.x - radius; x < pixel.x + radius; x++) {
|
||||||
|
|
@ -1528,6 +1803,7 @@ var circuits = [
|
||||||
{ circuit: elements.four_bit_enabler_circuit, color: cc_BROWN, size: [9, 3, true] },
|
{ circuit: elements.four_bit_enabler_circuit, color: cc_BROWN, size: [9, 3, true] },
|
||||||
{ circuit: elements.randomizer, color: cc_BROWN },
|
{ circuit: elements.randomizer, color: cc_BROWN },
|
||||||
{ circuit: elements.four_bit_randomizer_circuit, color: cc_BROWN, size: [9, 3, true] },
|
{ circuit: elements.four_bit_randomizer_circuit, color: cc_BROWN, size: [9, 3, true] },
|
||||||
|
{ circuit: elements.temperature_sensor, color: cc_BROWN },
|
||||||
// ROM/RAM: red
|
// ROM/RAM: red
|
||||||
// { circuit: elements.ROM_circuit, color: cc_RED, size: [18, 18, false] },
|
// { circuit: elements.ROM_circuit, color: cc_RED, size: [18, 18, false] },
|
||||||
// Encoders and de-multiplexers: orange
|
// Encoders and de-multiplexers: orange
|
||||||
|
|
@ -1572,23 +1848,32 @@ var circuits = [
|
||||||
{ circuit: elements.medium_clock },
|
{ circuit: elements.medium_clock },
|
||||||
{ circuit: elements.fast_clock },
|
{ circuit: elements.fast_clock },
|
||||||
{ circuit: elements.very_fast_clock },
|
{ circuit: elements.very_fast_clock },
|
||||||
{ circuit: elements.very_fast_clock },
|
|
||||||
// Displays/visual circuits: white
|
// Displays/visual circuits: white
|
||||||
{ circuit: elements.simple_seven_segment_display, color: cc_WHITE, size: [5, 9, false] },
|
{ circuit: elements.simple_seven_segment_display, color: cc_WHITE, size: [5, 9, false] },
|
||||||
{ circuit: elements.simple_double_seven_segment_display, color: cc_WHITE, size: [9, 9, false] },
|
{ circuit: elements.simple_double_seven_segment_display, color: cc_WHITE, size: [9, 9, false] },
|
||||||
|
{ circuit: elements.custom_RGB_led, color: cc_WHITE, size: [3, 3, true] },
|
||||||
|
{ circuit: elements.basic_mono_display_8x8, color: cc_WHITE, size: [10, 10, false] },
|
||||||
|
{ circuit: elements.basic_mono_display_16x8, color: cc_WHITE, size: [18, 10, false] },
|
||||||
|
{ circuit: elements.basic_mono_display_16x16, color: cc_WHITE, size: [18, 18, false] },
|
||||||
|
{ circuit: elements.basic_mono_display_32x16, color: cc_WHITE, size: [34, 18, false] },
|
||||||
|
{ circuit: elements.basic_mono_display_32x32, color: cc_WHITE, size: [34, 34, false] },
|
||||||
|
{ circuit: elements.basic_mono_display_64x32, color: cc_WHITE, size: [66, 34, false] },
|
||||||
|
{ circuit: elements.basic_mono_display_64x64, color: cc_WHITE, size: [66, 66, false] },
|
||||||
];
|
];
|
||||||
|
|
||||||
circuits.forEach(circuitInfo => {
|
circuits.forEach(circuitInfo => {
|
||||||
if (circuitInfo.color) {circuitInfo.circuit.color = circuitInfo.color;}
|
if (circuitInfo.color) {circuitInfo.circuit.color = circuitInfo.color;}
|
||||||
circuitInfo.circuit.category = "logic";
|
circuitInfo.circuit.category = "logic";
|
||||||
circuitInfo.circuit.maxSize = 1;
|
circuitInfo.circuit.maxSize = 1;
|
||||||
|
circuitInfo.circuit.behavior = behaviors.WALL;
|
||||||
|
circuitInfo.circuit.state = "solid";
|
||||||
circuitInfo.circuit.isCircuitCore = true;
|
circuitInfo.circuit.isCircuitCore = true;
|
||||||
circuitInfo.circuit.previewSize = circuitInfo.size;
|
circuitInfo.circuit.previewSize = circuitInfo.size;
|
||||||
|
|
||||||
// Exclude circuits without a frame
|
// Exclude circuits without a frame
|
||||||
if (circuitInfo.size) {
|
if (circuitInfo.size) {
|
||||||
var previousCircuitTick = circuitInfo.circuit.tick;
|
var previousCircuitTick = circuitInfo.circuit.cc_stableTick;
|
||||||
circuitInfo.circuit.tick = function(pixel) {
|
circuitInfo.circuit.cc_stableTick = function(pixel) {
|
||||||
previousCircuitTick(pixel);
|
previousCircuitTick(pixel);
|
||||||
|
|
||||||
// Don't constantly check
|
// Don't constantly check
|
||||||
|
|
@ -1606,7 +1891,10 @@ circuits.forEach(circuitInfo => {
|
||||||
deletePixel(pixel.x, pixel.y);
|
deletePixel(pixel.x, pixel.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
pixel.temp += Math.random(0, 5);
|
// Check if circuit overheating is enabled
|
||||||
|
if (cc_setting1.value) {
|
||||||
|
pixel.temp += Math.random(0.5);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1658,12 +1946,16 @@ function drawCircuitExtras() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
runAfterLoad(() => {
|
function runLogicTick() {
|
||||||
var originalDrawPixels3 = drawPixels;
|
for (var i = 0;i < currentPixels.length;i++) {
|
||||||
drawPixels = function(forceTick=false) {
|
var pixel = currentPixels[i];
|
||||||
originalDrawPixels3(forceTick);
|
if (elements[pixel.element].category == "logic") {
|
||||||
drawCircuitExtras();
|
if (elements[pixel.element].cc_stableTick) {
|
||||||
return true;
|
elements[pixel.element].cc_stableTick(pixel);
|
||||||
};
|
}
|
||||||
});
|
}
|
||||||
resetInterval(tps);
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
renderPostPixel(drawCircuitExtras);
|
||||||
|
runEveryTick(runLogicTick);
|
||||||
|
|
|
||||||
|
|
@ -0,0 +1 @@
|
||||||
|
Object.keys(elements).forEach((element)=>{if (elements[element].category == "life") {delete elements[element]}})
|
||||||
|
|
@ -1,14 +1,14 @@
|
||||||
// RedBirdly's mod to draw lines between transmitters/receivers
|
// RedBirdly's mod to draw lines between transmitters/receivers
|
||||||
// logicgates.js required
|
// logicgates.js or wifi.js required
|
||||||
|
|
||||||
let logicReceivers = [];
|
let logicReceivers = [];
|
||||||
let logicTransmitters = [];
|
let logicTransmitters = [];
|
||||||
// let receivers = [];
|
let receivers = [];
|
||||||
// let transmitters = [];
|
let transmitters = [];
|
||||||
|
|
||||||
function updateLogicLists() {
|
function updateLogicLists() {
|
||||||
// receivers = [];
|
receivers = [];
|
||||||
// transmitters = [];
|
transmitters = [];
|
||||||
logicReceivers = [];
|
logicReceivers = [];
|
||||||
logicTransmitters = [];
|
logicTransmitters = [];
|
||||||
|
|
||||||
|
|
@ -18,11 +18,11 @@ function updateLogicLists() {
|
||||||
logicReceivers.push(pixel);
|
logicReceivers.push(pixel);
|
||||||
} else if (pixel.element === "logic_transmitter") {
|
} else if (pixel.element === "logic_transmitter") {
|
||||||
logicTransmitters.push(pixel);
|
logicTransmitters.push(pixel);
|
||||||
} /*else if (pixel.element === "receiver") {
|
} else if (pixel.element === "receiver") {
|
||||||
receivers.push(pixel);
|
receivers.push(pixel);
|
||||||
} else if (pixel.element === "transmitter") {
|
} else if (pixel.element === "transmitter") {
|
||||||
transmitters.push(pixel);
|
transmitters.push(pixel);
|
||||||
}*/
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -67,12 +67,21 @@ function drawLinks() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Iterate through transmitters and receivers to draw lines for linked channels
|
||||||
|
for (const transmitter of transmitters) {
|
||||||
|
for (const receiver of receivers) {
|
||||||
|
if (transmitter._channel === receiver._channel) {
|
||||||
|
ctx.beginPath();
|
||||||
|
ctx.moveTo(transmitter.x * pixelSize + pixelSizeHalf, transmitter.y * pixelSize + pixelSizeHalf);
|
||||||
|
ctx.lineTo(receiver.x * pixelSize + pixelSizeHalf, receiver.y * pixelSize + pixelSizeHalf);
|
||||||
|
ctx.strokeStyle = "RGBA(0,0,255,0.2)";
|
||||||
|
ctx.lineWidth = 2;
|
||||||
|
ctx.stroke();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
var originalDrawPixels2 = drawPixels;
|
renderPostPixel(updateLogicLists);
|
||||||
drawPixels = function(forceTick=false) {
|
renderPostPixel(drawLinks);
|
||||||
originalDrawPixels2(forceTick);
|
|
||||||
updateLogicLists();
|
|
||||||
drawLinks();
|
|
||||||
};
|
|
||||||
resetInterval(tps);
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue