From 9db98c30a59c4eb0f476362cc8b7c83b5f86efa1 Mon Sep 17 00:00:00 2001 From: MatCat Date: Sun, 21 Feb 2021 02:21:27 -0800 Subject: [PATCH] 0.2.1: Fixed input property constraints and added NOT gate --- README.md | 4 ++++ index.html | 1 + js/logicengine.js | 28 +++++++++++++++++++++++++++- js/main.js | 9 ++++++++- 4 files changed, 40 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d3565bb..0a373b2 100644 --- a/README.md +++ b/README.md @@ -12,6 +12,10 @@ To be decided, but at this moment this code is open source and free to use for n ## Changelog +### 0.2.1 +* Fixed input property constraints on elements +* Added NOT gate + ### 0.2.0 * Switched to a dark theme * Added left hand toolbar diff --git a/index.html b/index.html index 057b4fe..b023c58 100644 --- a/index.html +++ b/index.html @@ -36,6 +36,7 @@


+


diff --git a/js/logicengine.js b/js/logicengine.js index 67aae09..9d87f9b 100644 --- a/js/logicengine.js +++ b/js/logicengine.js @@ -205,7 +205,7 @@ class Element extends CanvasTools { this.Properties = new Array(); this.LogicEngine = logicengine; - let inputProperty = new ElementProperty("Inputs","int",{CBObject: this,CBFunction: "ChangeInputs"},2,Inputs); + let inputProperty = new ElementProperty("Inputs","int",{CBObject: this,CBFunction: "ChangeInputs"},2,Inputs,false,2); this.Properties.push(inputProperty); } @@ -454,6 +454,7 @@ class inputElement extends Element { this.Name = "InputElement"; this.Output = false; this.Width = 100; + this.removeProperty("Inputs"); } getOutput() { @@ -579,6 +580,7 @@ class LogicXOR extends Element { constructor(logicengine) { super(logicengine,2); // Only 2 inputs on XOR this.Name = "XOR"; + this.removeProperty("Inputs"); } getOutput() { @@ -602,6 +604,7 @@ class LogicXNOR extends Element { constructor(logicengine) { super(logicengine,2); // Only 2 inputs on XOR this.Name = "XNOR"; + this.removeProperty("Inputs"); } getOutput() { @@ -621,6 +624,29 @@ class LogicXNOR extends Element { } } +class LogicNOT extends Element { + constructor(logicengine) { + super(logicengine,1); // Only 1 inputs on NOT + this.Name = "NOT"; + this.removeProperty("Inputs"); + } + + getOutput() { + if (this.Inputs[0]) return false; + return true; + } + + drawElement(x,y,ctx) { + let drawWidth = this.Width; + let drawHeight = this.Height; + + this.drawBorderBox(ctx, x,y,drawWidth,drawHeight); + this.drawTextCentered(ctx,x,y,drawWidth,drawHeight,"|>🞄"); + this.drawInputs(ctx,x,y); + this.drawOutputs(ctx,x,y); + } +} + class elementContainer { constructor() { diff --git a/js/main.js b/js/main.js index 32b801d..3b545ca 100644 --- a/js/main.js +++ b/js/main.js @@ -2,7 +2,7 @@ MatCat BrowserLogic Simulator */ -let Version = "0.2.0"; +let Version = "0.2.1"; let spanVersion = document.getElementById("version"); spanVersion.innerText = Version; // get the canvas and get the engine object going @@ -91,6 +91,13 @@ btn_AddXNOR.addEventListener('click', function(evt) { logicEngine.ActiveContainer.AddElement(newXNOR); }, false); +btn_AddNOT.addEventListener('click', function(evt) { + let newNOT = new LogicNOT(logicEngine); + newNOT.X = 20; + newNOT.Y = 20; + logicEngine.ActiveContainer.AddElement(newNOT); +}, false); + let btn_AddSWITCH = document.getElementById("btn_AddSWITCH"); btn_AddSWITCH.addEventListener('click', function(evt) { let newSWITCH = new InputSwitch(logicEngine);