BrowserLogic/js/main.js

151 lines
4.6 KiB
JavaScript
Raw Normal View History

2021-02-19 16:47:37 -05:00
/*
MatCat BrowserLogic Simulator
*/
let Version = "0.3.0";
let spanVersion = document.getElementById("version");
spanVersion.innerText = Version;
2021-02-19 16:47:37 -05:00
// get the canvas and get the engine object going
let lCanvasElement = document.getElementById("LogicPlane");
let logicEngine = new LogicEngine(lCanvasElement);
// Get the game Tick going, this will be 4ms for now which is the fastest that is supported
// by the HTML5 spec!
setInterval(logicEngine.Scheduler.Tick.bind(logicEngine.Scheduler), 4);
2021-02-19 16:47:37 -05:00
window.addEventListener('resize', function(evt) {
logicEngine.Resize(evt);
}, false);
window.addEventListener('keydown', function(evt) {
2021-02-19 16:47:37 -05:00
logicEngine.Key_Press(evt);
}, false);
lCanvasElement.addEventListener('mousedown', function(evt) {
logicEngine.Mouse_Down(evt);
}, false);
lCanvasElement.addEventListener('mouseup', function(evt) {
logicEngine.Mouse_Up(evt);
}, false);
window.addEventListener('mousemove', function(evt) {
2021-02-19 16:47:37 -05:00
logicEngine.Mouse_Move(evt);
}, false);
// Get the engine going
logicEngine.StartEngine();
// Setup interface buttons
2021-02-22 02:29:12 -05:00
let btn_CloseWelcome = document.getElementById("btn_CloseWelcome");
btn_CloseWelcome.addEventListener('click', function(evt) {
let WelcomeScreen = document.getElementById("WelcomeWindow");
let DarkOverlay = document.getElementById("darkout-overlay");
WelcomeScreen.style.display = "none";
DarkOverlay.style.display = "none";
let chk_dontDisplayWelcome = document.getElementById("chk_dontDisplayWelcome");
if (chk_dontDisplayWelcome.checked) {
setCookie("hidewelcomescreen","true",3600);
}
}, false);
2021-02-19 16:47:37 -05:00
let btn_Delete = document.getElementById("btn_Delete");
btn_Delete.addEventListener('click', function(evt) {
logicEngine.Key_Press({key: "Delete"});
}, false);
let btn_AddAND = document.getElementById("btn_AddAND");
btn_AddAND.addEventListener('click', function(evt) {
addElement(null,LogicAND, [2]);
2021-02-19 16:47:37 -05:00
}, false);
let btn_AddNAND = document.getElementById("btn_AddNAND");
btn_AddNAND.addEventListener('click', function(evt) {
addElement(null,LogicNAND, [2]);
2021-02-19 16:47:37 -05:00
}, false);
let btn_AddOR = document.getElementById("btn_AddOR");
btn_AddOR.addEventListener('click', function(evt) {
addElement(null,LogicOR, [2]);
2021-02-19 16:47:37 -05:00
}, false);
let btn_AddNOR = document.getElementById("btn_AddNOR");
btn_AddNOR.addEventListener('click', function(evt) {
addElement(null,LogicNOR, [2]);
2021-02-19 16:47:37 -05:00
}, false);
let btn_AddXOR = document.getElementById("btn_AddXOR");
btn_AddXOR.addEventListener('click', function(evt) {
addElement(null,LogicXOR,[]);
2021-02-19 16:47:37 -05:00
}, false);
let btn_AddXNOR = document.getElementById("btn_AddXNOR");
btn_AddXNOR.addEventListener('click', function(evt) {
addElement(null,LogicXNOR,[]);
2021-02-19 16:47:37 -05:00
}, false);
let btn_AddNOT = document.getElementById("btn_AddNOT");
btn_AddNOT.addEventListener('click', function(evt) {
addElement(null,LogicNOT,[]);
}, false);
let btn_AddBUFFER = document.getElementById("btn_AddBUFFER");
btn_AddBUFFER.addEventListener('click', function(evt) {
let logicBuffer = addElement(null,LogicBuffer,[]);
}, false);
let btn_AddSWITCH = document.getElementById("btn_AddSWITCH");
btn_AddSWITCH.addEventListener('click', function(evt) {
addElement(null,InputSwitch,[]);
2021-02-19 16:47:37 -05:00
}, false);
let btn_AddBTN = document.getElementById("btn_AddBTN");
btn_AddBTN.addEventListener('click', function(evt) {
addElement(null,InputButton,[]);
}, false);
let btn_AddCLK = document.getElementById("btn_AddCLK");
btn_AddCLK.addEventListener('click', function(evt) {
let clk = addElement(null,ClockElement,[]);
}, false);
2021-02-19 16:47:37 -05:00
let btn_AddPulse = document.getElementById("btn_AddPULSE");
btn_AddPulse.addEventListener('click', function(evt) {
let pulse = addElement(null,PulseElement,[]);
}, false);
2021-02-23 04:54:42 -05:00
let btn_AddDelay = document.getElementById("btn_AddDELAY");
btn_AddDelay.addEventListener('click', function(evt) {
let delay = addElement(null,DelayElement,[]);
}, false);
let btn_Save = document.getElementById("btn_Save");
btn_Save.addEventListener('click', function(evt) {
download("mydeign.LogicParts",createSaveState(logicEngine.ActiveContainer));
});
let file_Load = document.getElementById("file_Load");
let btn_Load = document.getElementById("btn_Load");
btn_Load.addEventListener('click', function(evt) {
file_Load.click();
});
file_Load.addEventListener('change', function(evt) {
let fread = new FileReader();
fread.onload = (function (theFile) {
return function (e) {
try {
let restoredata = JSON.parse(e.target.result);
if (!loadsave(restoredata)) {
alert("Bad file!");
}
} catch (ex) {
alert("Bad file!");
}
}
})(evt.target.files[0]);
fread.readAsText(evt.target.files[0]);
2021-02-23 04:54:42 -05:00
}, false);
2021-02-22 02:29:12 -05:00
CheckForWelcomeCookie();