0.2.11: Added delay element

This commit is contained in:
MatCat 2021-02-23 01:54:42 -08:00
parent 59386209fe
commit 6067c9f22a
4 changed files with 101 additions and 3 deletions

View File

@ -12,8 +12,10 @@ To be decided, but at this moment this code is open source and free to use for n
## Changelog
### 0.2.10
### 0.2.11
* Added Delay element
### 0.2.10
* New elements will now do overlap detection on placement
* Newly placed elements will now be selected

View File

@ -45,7 +45,8 @@
<input type="button" id="btn_AddSWITCH" value="|- SWITCH"/><br />
<input type="button" id="btn_AddBTN" value="[o] BUTTON"/><br />
<input type="button" id="btn_AddCLK" value="🕑 Clock"/><br />
<input type="button" id="btn_AddPULSE" value="_|\_ Pulse"/><br />
<input type="button" id="btn_AddPULSE" value="|\__ Pulse"/><br />
<input type="button" id="btn_AddDELAY" value="__|\ Delay"/><br />
<input type="button" id="btn_Delete" value="🗑 Delete"/>
</div>
</div>

View File

@ -642,6 +642,95 @@ class PulseElement extends Element {
}
}
class DelayElement extends Element {
ClockTick() {
if (this.Output) {
this.Output = false;
this.Task.Enabled = false;
this.Task.LastCall = Date.now();
this.Task.Time = this.Period;
} else {
this.Output = true;
this.Task.Enabled = false;
if (this.InputEnd > 0) {
this.Task.Time = this.InputEnd - this.InputStart;
this.Task.Enabled = true;
}
this.Task.LastCall = Date.now();
}
for (let a = 0; a < this.OutputConnections.length; a++) {
this.LogicEngine.RecursionCount = 0;
this.OutputConnections[a].Element.setInput(this.OutputConnections[a].Input, this.getOutput());
}
}
Delete() {
super.Delete();
this.LogicEngine.Scheduler.deleteTask(this.Task);
}
getOutput() {
return this.Output;
}
setInput(Input, Value) {
if (Input > 0) return;
if (this.Inputs[Input] == Value) return;
//super.setInput(Input, Value);
this.Inputs[Input] = Value;
if (this.Inputs[0] && !this.Task.Enabled) {
this.InputStart = Date.now();
this.InputEnd = 0;
this.Output = false;
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.Task.LastCall = Date.now();
this.Task.Enabled = true;
} else {
this.InputEnd = Date.now();
if (!this.Task.Enabled) {
this.Task.LastCall = Date.now();
this.Task.Time = (this.InputEnd - this.InputStart) - (Date.now() - this.InputEnd);
this.Task.Enabled = true;
}
}
}
constructor(logicengine) {
super(logicengine,1);
this.removeProperty("Inputs");
this.Name = "Delay";
this.Period = 100;
this.Output = false;
this.Width = 100;
this.Task = new Task("DelayTask","CLOCK",0,this.Period,this.ClockTick.bind(this));
this.Task.Enabled = false;
this.removeProperty("Inputs");
let periodProperty = new ElementProperty("Period","int",{CBObject: this,CBFunction: "setPeriod"},100,false,false,4,999999);
this.Properties.push(periodProperty);
this.InputStart = 0;
this.InputEnd = 0;
this.Inputs[0] = false;
}
setPeriod(period) {
this.Period = parseInt(period);
this.Task.Time = parseInt(period);
this.getProperty("Period").CurrentValue = parseInt(period);
}
drawElement(x, y, ctx) {
this.drawBorderBox(ctx, x+10,y,this.Width-20,this.Height,1,"#000","#f7e979",this.LogicEngine.Settings.ShadowColor);
this.drawTextCentered(ctx,x,y+5,this.Width,12,this.Period + "ms","10px Console");
if (this.Task.Enabled) this.drawTextCentered(ctx,x,y+this.Height-16,this.Width,12,(this.Task.Time - (Date.now() - this.Task.LastCall)) + "ms","10px Console");
this.drawTextCentered(ctx,x,y,this.Width,this.Height,this.Designator,"12px Console","#000");
this.drawInputs(ctx,x,y);
this.drawOutputs(ctx,x,y);
}
}
class inputElement extends Element {
constructor(logicengine) {

View File

@ -2,7 +2,7 @@
MatCat BrowserLogic Simulator
*/
let Version = "0.2.10";
let Version = "0.2.11";
let spanVersion = document.getElementById("version");
spanVersion.innerText = Version;
// get the canvas and get the engine object going
@ -111,6 +111,12 @@ btn_AddPulse.addEventListener('click', function(evt) {
logicEngine.Scheduler.addTask(pulse.Task);
}, false);
let btn_AddDelay = document.getElementById("btn_AddDELAY");
btn_AddDelay.addEventListener('click', function(evt) {
let delay = addElement(DelayElement,[]);
logicEngine.Scheduler.addTask(delay.Task);
}, false);
function CheckForWelcomeCookie() {
if (getCookie("hidewelcomescreen")) {
let WelcomeScreen = document.getElementById("WelcomeWindow");