0.4.8: Fixed bug where deleted elements didn't propogate properly when deleted or disconnected

This commit is contained in:
MatCat 2021-03-11 23:18:57 -08:00
parent 89eb47cacc
commit bdd630e8d5
5 changed files with 71 additions and 5 deletions

View File

@ -14,6 +14,10 @@ LZ-String, Copyright 2013 pieroxy under MIT license https://github.com/pieroxy/l
## Changelog
### 0.4.8
* Fixed bug where disconnects where not propagating properly
### 0.4.7
* Added LZW compression to save files (can be disabled on save)

View File

@ -100,6 +100,14 @@ class elementContainer {
return isHigh;
}
clearRedraw() {
for (let a = 0; a < this.Elements.length; a++) {
this.Elements[a].redraw = false;
}
}
toJSON(key) {
let elements = new Array();
for (let a = 0; a < this.Elements.length; a++) {

View File

@ -98,6 +98,8 @@ class Element extends CanvasTools {
this.NoOutput = false;
this.OutputLink = 0;
this._Container = _Container;
this.Disconnecting = false;
this.redraw = true;
let inputProperty = new ElementProperty("Inputs","int",{CBObject: this,CBFunction: "ChangeInputs"},2,Inputs,false,2);
this.Properties.push(inputProperty);
@ -199,6 +201,7 @@ class Element extends CanvasTools {
this.getProperty("Inputs").CurrentValue = inputs;
this.Height = inputs*25;
if (this.Height < 60) this.Height = 60;
this.redraw = true;
}
Delete() {
@ -221,6 +224,7 @@ class Element extends CanvasTools {
}
}
} else {
this.Disconnecting = true;
for (let a = 0; a < this.OutputConnections.length; a++) {
this.LogicEngine.RecursionCount = 0;
this.OutputConnections[a].Element.setInput(this.OutputConnections[a].Input, false);
@ -228,6 +232,7 @@ class Element extends CanvasTools {
a--;
}
}
this.redraw = true;
}
MouseDown(mousePos) {
@ -426,12 +431,12 @@ class Element extends CanvasTools {
}
}
setInput(Input,Value) {
let oldOutput = this.getOutput();
if (Value) {
Value = true;
} else {
Value = false;
}
let oldInput = this.Inputs[Input];
if (Input < this.totalInputs()) {
this.Inputs[Input] = Value;
} else {
@ -440,13 +445,17 @@ class Element extends CanvasTools {
let isHigh = this._Container.isHigh(this,Input);
if (isHigh !== false) this.Inputs[Input] = true;
if (isHigh === false) this.Inputs[Input] = false;
if (oldInput != this.Inputs[Input]) {
this.redraw = true;
this.setConnections();
}
}
getOutput(Output=0) {
/*
Should return true or false
*/
if (this.Disconnecting) return 0;
return false;
}
@ -552,11 +561,13 @@ class ICInput extends Element {
}
setInput(notused = 0,value) {
if (notused > 0) return;
if (value === false) this.Input = false;
if (value !== false) this.Input = true;
this.Inputs[0] = this.Input;
this.redraw = true;
if (!this.Task.Enabled) {
this.Task.LastCall = 0;
@ -568,6 +579,7 @@ class ICInput extends Element {
this.Output = this.Input;
this.Task.Enabled = false;
this.Task.LastCall = 0;
this.redraw = true;
for (let a = 0; a < this.OutputConnections.length; a++) {
this.LogicEngine.RecursionCount = 0;
@ -581,6 +593,7 @@ class ICInput extends Element {
}
getOutput(Output=0) {
if (super.getOutput() === 0) return false;
return this.Output;
}
@ -640,6 +653,7 @@ class ICOutput extends Element {
if (value === false) this.Input = false;
if (value !== false) this.Input = true;
this.Inputs[0] = this.Input;
this.redraw = true;
if (!this.Task.Enabled) {
this.Task.LastCall = 0;
@ -651,6 +665,8 @@ class ICOutput extends Element {
this.Output = this.Input;
this.Task.Enabled = false;
this.Task.LastCall = 0;
this.redraw = true;
for (let a = 0; a < this.OutputConnections.length; a++) {
this.LogicEngine.RecursionCount = 0;
this.OutputConnections[a].Element.setInput(this.OutputConnections[a].Input, this.getOutput());
@ -663,6 +679,7 @@ class ICOutput extends Element {
}
getOutput(Output=0) {
if (super.getOutput() === 0) return false;
return this.Output;
}
@ -776,12 +793,14 @@ class ICElement extends Element {
// No need to worry about recursion as this goes to an input element which is buffered
Value = this._Container.isHigh(this,Input);
this.Inputs[Input] = (Value === false) ? false : true;
this.redraw = true;
this.InputConnections[Input].toElement.setInput(0,Value);
}
return false;
}
getOutput(Output = 0) {
if (super.getOutput() === 0) return false;
if (this.Outputs.length >= Output) {
return this.Outputs[Output].fromElement.getOutput(this.Outputs[Output].Input);
}
@ -866,6 +885,7 @@ class ClockElement extends Element {
}
getOutput(Output=0) {
if (super.getOutput() === 0) return false;
return this.Output;
}
@ -980,6 +1000,7 @@ class PulseElement extends Element {
}
getOutput(Output=0) {
if (super.getOutput() === 0) return false;
return this.Output;
}
@ -989,6 +1010,8 @@ class PulseElement extends Element {
Value = this._Container.isHigh(this,Input);
//super.setInput(Input, Value);
this.Inputs[Input] = (Value === false) ? false : true;
this.redraw = true;
if (this.Inputs[0] && !this.Task.Enabled) {
this.Output = true;
for (let a = 0; a < this.OutputConnections.length;a++) {
@ -1103,6 +1126,7 @@ class DelayElement extends Element {
}
getOutput(Output=0) {
if (super.getOutput() === 0) return false;
return this.Output;
}
@ -1112,6 +1136,8 @@ class DelayElement extends Element {
if (this.Inputs[Input] == (Value === false) ? false : true) return;
//super.setInput(Input, Value);
this.Inputs[Input] = Value;
this.redraw = true;
if (this.Inputs[0] && !this.Task.Enabled) {
this.InputStart = Date.now();
this.InputEnd = 0;
@ -1259,6 +1285,7 @@ class output4bitDisplay extends Element {
Value = this._Container.isHigh(this,Input);
this.Inputs[Input] = (Value !== false) ? 1 : 0;
let outchar = (this.Inputs[3] << 3) + (this.Inputs[2] << 2) + (this.Inputs[1] << 1) + (this.Inputs[0]);
this.redraw = true;
this.OutputChar = (outchar);
switch (outchar) {
@ -1319,6 +1346,7 @@ class inputElement extends Element {
}
getOutput(Output=0) {
if (super.getOutput() === 0) return false;
return this.Output;
}
@ -1560,6 +1588,8 @@ class InputKeypad extends inputElement {
ClockTick() {
console.log("Keypad clear signal");
this.Outputs[7] = false;
this.redraw = true;
for (let a = 0; a < this.OutputConnections.length; a++) {
this.LogicEngine.RecursionCount = 0;
this.OutputConnections[a].Element.setInput(this.OutputConnections[a].Input, this.getOutput(this.OutputConnections[a].Output));
@ -1567,6 +1597,7 @@ class InputKeypad extends inputElement {
}
getOutput(Output = 0) {
if (super.getOutput() === 0) return false;
return (this.Outputs[Output]) ? true : false;
}
@ -1622,6 +1653,8 @@ class FlipFlopJK extends Element {
let oldOutput = this.Outputs[0];
let oldOutput2 = this.Outputs[1];
this.Inputs[Input] = Value;
this.redraw = true;
if (this.Inputs[1]) {
if (!this.Inputs[0] && this.Inputs[2]) {
// set Q low
@ -1643,6 +1676,7 @@ class FlipFlopJK extends Element {
}
getOutput(Output=0) {
if (super.getOutput() === 0) return false;
return this.Outputs[Output];
}
drawElement(x,y,ctx) {
@ -1686,6 +1720,8 @@ class FlipFlopSR extends Element {
let oldOutput = this.Outputs[0];
let oldOutput2 = this.Outputs[1];
this.Inputs[Input] = Value;
this.redraw = true;
if (this.Inputs[1]) {
if (!this.Inputs[0] && this.Inputs[2]) {
// set Q low
@ -1703,6 +1739,7 @@ class FlipFlopSR extends Element {
}
getOutput(Output=0) {
if (super.getOutput() === 0) return false;
return this.Outputs[Output];
}
drawElement(x,y,ctx) {
@ -1746,6 +1783,8 @@ class FlipFlopT extends Element {
let oldOutput = this.Outputs[0];
let oldOutput2 = this.Outputs[1];
this.Inputs[Input] = Value;
this.redraw = true;
if (this.Inputs[0] && this.Inputs[1]) {
this.Outputs[0] = !this.Outputs[0];
this.Outputs[1] = !this.Outputs[0];
@ -1756,6 +1795,7 @@ class FlipFlopT extends Element {
}
getOutput(Output=0) {
if (super.getOutput() === 0) return false;
return this.Outputs[Output];
}
drawElement(x,y,ctx) {
@ -1800,6 +1840,8 @@ class FlipFlopD extends Element {
let oldOutput2 = this.Outputs[1];
let oldInput = this.Inputs[1];
this.Inputs[Input] = Value;
this.redraw = true;
if (this.Inputs[1] && !oldInput) {
this.Outputs[0] = this.Inputs[0];
this.Outputs[1] = !this.Outputs[0];
@ -1810,6 +1852,7 @@ class FlipFlopD extends Element {
}
getOutput(Output=0) {
if (super.getOutput() === 0) return false;
return this.Outputs[Output];
}
drawElement(x,y,ctx) {
@ -1832,6 +1875,7 @@ class LogicAND extends Element {
}
getOutput(Output=0) {
if (super.getOutput() === 0) return false;
let ANDResult = true;
for (let a = 0; a < this.totalInputs();a++) {
if (!this.Inputs[a]) ANDResult = false;
@ -1874,13 +1918,16 @@ class LogicNAND extends LogicAND {
this.Name = "NAND";
this.Width = this.Width + 10;
}
getOutput(Output=0) {
if (this.Disconnecting) return false;
if (super.getOutput()) {
return false;
} else {
return true;
}
}
drawElement(x,y,ctx) {
let xOffset = 20;
let shadowColor = this.LogicEngine.Settings.ShadowColor;
@ -1927,6 +1974,7 @@ class LogicOR extends Element {
}
getOutput(Output=0) {
if (super.getOutput() === 0) return false;
let ORResult = false;
for (let a = 0; a < this.totalInputs();a++) {
if (this.Inputs[a]) ORResult = true;
@ -1974,6 +2022,7 @@ class LogicNOR extends LogicOR {
this.Width = this.Width + 10;
}
getOutput(Output=0) {
if (super.getOutput() === 0) return false;
if (super.getOutput()) {
return false;
} else {
@ -2029,6 +2078,7 @@ class LogicXOR extends Element {
}
getOutput(Output=0) {
if (super.getOutput() === 0) return false;
let ORResult = false;
if ( (this.Inputs[0] && !this.Inputs[1]) || (!this.Inputs[0] && this.Inputs[1]) ) ORResult = true;
return ORResult;
@ -2092,6 +2142,7 @@ class LogicXNOR extends Element {
}
getOutput(Output=0) {
if (super.getOutput() === 0) return false;
let ORResult = false;
if ( (this.Inputs[0] && !this.Inputs[1]) || (!this.Inputs[0] && this.Inputs[1]) ) ORResult = true;
return !ORResult;
@ -2166,6 +2217,7 @@ class LogicNOT extends Element {
}
getOutput(Output=0) {
if (super.getOutput() === 0) return false;
if (this.Inputs[0]) return false;
return true;
}
@ -2228,6 +2280,7 @@ class LogicBuffer extends Element {
}
getOutput(Output=0) {
if (super.getOutput() === 0) return false;
return this.Output;
}
@ -2237,6 +2290,8 @@ class LogicBuffer extends Element {
Value = this._Container.isHigh(this,Input);
if (Value !== false) Value = true;
this.Inputs[Input] = Value;
this.redraw = true;
if (!this.Task.Enabled) {
this.Task.LastCall = 0;
this.Task.Enabled = true;

View File

@ -351,6 +351,7 @@ class LogicEngine {
this.ActiveContainer.Selected[a].X = actualPosX;
this.ActiveContainer.Selected[a].Y = actualPosY;
this.ActiveContainer.Selected[a].redraw = true;
}
}
@ -522,8 +523,6 @@ class LogicEngine {
y: 0,
InProgress: false
};
}
Link(input = 0) {

View File

@ -2,7 +2,7 @@
MatCat BrowserLogic Simulator
*/
let Version = "0.4.7";
let Version = "0.4.8";
let spanVersion = document.getElementById("version");
spanVersion.innerText = Version;
// get the canvas and get the engine object going