0.4.5: Keypad now has Switch or Button modes for F keys, as well as Clr output

This commit is contained in:
MatCat 2021-03-08 23:33:20 -08:00
parent a1e9d1200c
commit edda102714
5 changed files with 116 additions and 14 deletions

View File

@ -12,6 +12,11 @@ To be decided, but at this moment this code is open source and free to use for n
## Changelog
### 0.4.5
* Keypad now supports either Switch, or Button mode for Function keys, also has Clear output that pulses for 100ms when Clr is pressed
* Changed max input count for basic elements to 64 (from 12)
### 0.4.4
* Fixed a delinking bug

View File

@ -404,7 +404,7 @@ textarea {
#WelcomeWindow label {
font-size: 0.5em;
}
#PropertiesBox, #CreateICBox, #SaveWindow {
#PropertiesBox, #CreateICBox, #SaveWindow, #HelpWindow {
display: none;
position: absolute;
right: 20px;

View File

@ -150,7 +150,14 @@
</div>
</div>
</div>
<div id="HelpWindow">
<div id="HelpWindowTitle">
MatCat Logic Engine Help
</div>
<div id="helpWindowContent">
</div>
</div>
<div id="darkout-overlay"></div>
<script src="js/globalfunctions.js"></script>
<script src="js/baseclasses.js"></script>

View File

@ -15,7 +15,7 @@ let elementCatalog = new ElementCatalog([ElementCategory_Inputs,
ElementCategory_ICs,
ElementCategory_Other]);
class ElementProperty {
constructor(name,type,callback,defaultValue,currentValue = false,values=false,min=0,max=12) {
constructor(name,type,callback,defaultValue,currentValue = false,values=false,min=0,max=64) {
/*
Types
---------------------------------------
@ -1412,8 +1412,8 @@ class InputKeypad extends inputElement {
this.Name = "Keypad";
this.Height = 210;
this.Width = 200;
this.Outputs = new Array(7);
this.OutputLabels = new Array("O0","O1","O2","O3","F1","F2","F3");
this.Outputs = new Array(false,false,false,false,false,false,false,false);
this.OutputLabels = new Array("O0","O1","O2","O3","F1","F2","F3","Clr");
this.ButtonRows = 5;
this.ButtonColumns = 4;
this.Buttons = new Array(
@ -1423,11 +1423,16 @@ class InputKeypad extends inputElement {
{x: 0, y: 3,Value: 10, Text: "A"}, {x: 1, y: 3,Value: 0, Text: "0"}, {x: 2, y: 3,Value: 11, Text: "B"}, {x: 3, y: 3,Value: 128, Text: "Clr"},
{x: 0, y: 1,Value: 12, Text: "C"}, {x: 1, y: 1,Value: 13, Text: "D"}, {x: 2, y: 1,Value: 14, Text: "E"}, {x: 3, y: 1,Value: 15, Text: "F"}
);
let typeProperty = new ElementProperty("Function Type","list",{CBObject: this,CBFunction: "setType"},true,true,[{Value: true, String: "Switch"},{Value: false, String: "Button"}],0,0);
this.Properties.push(typeProperty);
if (RestoreData) {
if (RestoreData.OutputValues) {
this.Outputs = RestoreData.OutputValues;
}
if (RestoreData.Properties?.length > 0) {
this.Properties[0].CurrentValue = RestoreData.Properties[0].CurrentValue;
}
}
}
@ -1437,6 +1442,55 @@ class InputKeypad extends inputElement {
return superjson;
}
setType(type) {
if (type == "false") type = false;
if (type == "true") type = true;
this.Properties[0].CurrentValue = type;
if (!type) {
this.Outputs[4] = false;
this.Outputs[5] = false;
this.Outputs[6] = 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.OutputConnections[a].Output));
}
}
}
MouseDown(mousePos) {
if (!this.Properties[0].CurrentValue) {
mousePos = this.LogicEngine.getCanvasMousePos(mousePos);
let buttonWidth = 34;
let buttonHeight = 34;
let x = this.X;
let y = this.Y;
for (let pY = 0; pY < this.ButtonRows; pY++) {
for (let pX = 0; pX < this.ButtonColumns; pX++) {
if ((mousePos.x >= (x + (5 * (pX + 1)) + (buttonWidth * pX))) && (mousePos.x <= ((x + (5 * (pX + 1)) + (buttonWidth * pX)) + buttonWidth)) && (mousePos.y >= (y + (5 * (pY + 1)) + (buttonHeight * pY))) && (mousePos.y <= ((y + (5 * (pY + 1)) + (buttonHeight * pY)) + buttonHeight))) {
let button = this.Buttons[(pY * this.ButtonColumns) + pX];
if (button.Value & 0b0010000) this.Outputs[4] = true;
if (button.Value & 0b0100000) this.Outputs[5] = true;
if (button.Value & 0b1000000) this.Outputs[6] = 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));
}
}
}
}
}
}
MouseUp(mousePos) {
if (!this.Properties[0].CurrentValue) {
this.Outputs[4] = false;
this.Outputs[5] = false;
this.Outputs[6] = false;
}
}
MouseClick(mousePos) {
mousePos = this.LogicEngine.getCanvasMousePos(mousePos);
super.MouseClick(mousePos);
@ -1450,14 +1504,30 @@ class InputKeypad extends inputElement {
if ((mousePos.x >= (x + (5*(pX+1))+(buttonWidth*pX))) && (mousePos.x <= ((x + (5*(pX+1))+(buttonWidth*pX)) + buttonWidth)) && (mousePos.y >= (y + (5*(pY+1))+(buttonHeight*pY))) && (mousePos.y <= ((y + (5*(pY+1))+(buttonHeight*pY))+buttonHeight))) {
let button = this.Buttons[(pY*this.ButtonColumns) + pX];
if (button.Value & 0b0000001) this.Outputs[0] = true; else this.Outputs[0] = false;
if (button.Value & 0b0000010) this.Outputs[1] = true; else this.Outputs[1] = false;
if (button.Value & 0b0000100) this.Outputs[2] = true; else this.Outputs[2] = false;
if (button.Value & 0b0001000) this.Outputs[3] = true; else this.Outputs[3] = false;
if (button.Value & 0b0010000) this.Outputs[4] = true;
if (button.Value & 0b0100000) this.Outputs[5] = true;
if (button.Value & 0b1000000) this.Outputs[6] = true;
if (button.Value & 0b10000000) for (let a = 0; a < this.Outputs.length; a++) {this.Outputs[a] = false;}
if (button.Value <= 15) {
if (button.Value & 0b0000001) this.Outputs[0] = true; else this.Outputs[0] = false;
if (button.Value & 0b0000010) this.Outputs[1] = true; else this.Outputs[1] = false;
if (button.Value & 0b0000100) this.Outputs[2] = true; else this.Outputs[2] = false;
if (button.Value & 0b0001000) this.Outputs[3] = true; else this.Outputs[3] = false;
}
if (this.Properties[0].CurrentValue) {
if (button.Value & 0b0010000) this.Outputs[4] = !this.Outputs[4];
if (button.Value & 0b0100000) this.Outputs[5] = !this.Outputs[5];
if (button.Value & 0b1000000) this.Outputs[6] = !this.Outputs[6];
}
if (button.Value & 0b10000000) {
for (let a = 0; a < this.Outputs.length; a++) {
this.Outputs[a] = false;
}
this.Outputs[7] = true;
let tempTimer = new Task("keypadClearTask","Keypad Clear",0,100,this.ClockTick.bind(this),true);
tempTimer.LastCall = Date.now();
tempTimer.Enabled = true;
this.LogicEngine.Scheduler.addTask(tempTimer);
}
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));
@ -1467,6 +1537,15 @@ class InputKeypad extends inputElement {
}
}
ClockTick() {
console.log("Keypad clear signal");
this.Outputs[7] = 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.OutputConnections[a].Output));
}
}
getOutput(Output = 0) {
return (this.Outputs[Output]) ? true : false;
}

View File

@ -2,7 +2,7 @@
MatCat BrowserLogic Simulator
*/
let Version = "0.4.4";
let Version = "0.4.5";
let spanVersion = document.getElementById("version");
spanVersion.innerText = Version;
// get the canvas and get the engine object going
@ -328,13 +328,24 @@ in_GridSize.addEventListener("change", function (evt) {
});
document.addEventListener( "contextmenu", function(evt) {
function showRCM(evt) {
evt.preventDefault();
let rcm = document.getElementById("RightClickMenu");
rcm.style.left = (evt.clientX-40) + "px";
rcm.style.top = (evt.clientY-25) + "px";
rcm.style.display = "block";
}
let leftmenu = document.getElementById("left-menu");
let propwin = document.getElementById("PropertiesBox");
lCanvasElement.addEventListener( "contextmenu", function(evt) {showRCM(evt)});
leftmenu.addEventListener( "contextmenu", function(evt) {showRCM(evt)});
propwin.addEventListener( "contextmenu", function(evt) {showRCM(evt)});
let topbar = document.getElementById("top-bar");
topbar.addEventListener( "contextmenu", function(evt) {
evt.preventDefault();
});
CheckForWelcomeCookie();