added ability to have multipul boards

This commit is contained in:
2025-08-18 15:18:56 -06:00
parent 4e9b70f68c
commit ae650db3f9

50
main.js
View File

@@ -87,6 +87,55 @@ function setPec(pecTemplate=null, targetIndex=null) {
targetPec.appendChild(pecTemplate.DOM);
}
function repopBoards (current=0) {
//app.boards;
//app.currentBoards;
//app.menu;
// Normally we only want <, but we want an extra
// iteration here for the "add new board" element
for (var i = 0; i <= app.boards.length; i++) {
var boardTab = document.getElementById("board"+i);
if (null == boardTab) {
boardTab = document.createElement("span");
boardTab.setAttribute("id", "board"+i);
boardTab.classList.add("board_tab");
app.gui.menu.appendChild(boardTab);
}
// Clear event listeners
var oldTab = boardTab;
boardTab = oldTab.cloneNode(true);
oldTab.parentNode.replaceChild(boardTab, oldTab);
// not sure how memory safe the above lines are
var name = "Board "+i;
if (i == app.boards.length) {
name = "+";
boardTab.addEventListener("click",(e)=>{
var current = app.boards.findIndex(i=>i==app.currentBoard);
app.boards.push(new pecBoard());
repopBoards(current);
repopGrid(app.currentBoard);
});
} else {
if (current != i) {
boardTab.classList.remove("active_board");
boardTab.addEventListener("click", (e)=>{
var sourceID = ((e.currentTarget.getAttribute("id")).split("board"))[1];
app.currentBoard = app.boards[sourceID];
repopBoards(sourceID);
repopGrid(app.currentBoard);
});
} else {
boardTab.classList.add("active_board");
}
if (undefined != app.boards[i].name) {
name = app.boards[i].name;
}
}
boardTab.innerText = name;
console.log(boardTab);
}
}
function repopGrid (board=null) {
if (null == board) { return systemMsg("repopGrid was not provided data",2); }
if (!(board instanceof pecBoard)) { return systemMsg("repopGrid was not provided data of type pecBoard",2); }
@@ -146,6 +195,7 @@ for (var x = 0; x < 16; x++) {
app.boards = [];
app.boards.push(new pecBoard());
app.currentBoard = app.boards[0];
repopBoards(0);
repopGrid(app.currentBoard);
// Populate Library