Added additional init stuff, fixed event listener refs

This commit is contained in:
2025-08-12 16:10:23 -06:00
parent 149abb716a
commit d76a0fd6eb
2 changed files with 28 additions and 6 deletions

26
main.js
View File

@@ -139,10 +139,26 @@ for (var x = 0; x < 16; x++) {
thisPec.id = name; thisPec.id = name;
clearPec(x); clearPec(x);
app.gui.view.appendChild(thisPec); app.gui.view.appendChild(thisPec);
thisPec.addEventListener("click", (p,x)=>{
app.currentPec = p;
app.currentPecIndex = x;
app.gui.library.root.classList.add("focused");
}, thisPec, x);
} }
// Create our initial board
app.boards = [];
app.boards.push(new pecBoard());
app.currentBoard = app.boards[0];
repopGrid(app.currentBoard);
// Populate Library
app.library = [];
app.library.push(new pec("No",""));
app.library.push(new pec("Up",""));
app.library.push(new pec("More",""));
app.library.push(new pec("Drink",""));
app.library.push(new pec("Food",""));
// add more here
app.library.forEach((p,i)=>{
var newPec = document.createElement("span");
newPec.classList.add("pecSlot");
newPec.innerText = p.word;
newPec.id = "lPec"+i;
newPec.addEventListener("click", useThisPec);
app.gui.library.body.appendChild(newPec);
});

View File

@@ -7,15 +7,21 @@ class pec {
this.image = image; // Add image processing here this.image = image; // Add image processing here
this.utterance = new SpeechSynthesisUtterance(this.word); this.utterance = new SpeechSynthesisUtterance(this.word);
var root = document.createElement("div"); var root = document.createElement("div");
root.draggable = true;
root.classList.add("pec"); root.classList.add("pec");
var img = document.createElement("img"); var img = document.createElement("img");
img.src = me.image; img.src = me.image;
img.classList.add("pecImage"); img.classList.add("pecImage");
root.appendChild(img); root.appendChild(img);
var name = document.createElement("span"); var name = document.createElement("span");
name.innerText = word;
name.classList.add("pecNane"); name.classList.add("pecNane");
root.appendChild(name); root.appendChild(name);
root.addEventListener("click",()=>{ window.speechSynthisis.speak(me.utterance); }); root.mom = this;
root.addEventListener("click",(e)=>{
var targ = e.currentTarget.mom;
window.speechSynthesis.speak(targ.utterance);
});
this.DOM = root; this.DOM = root;
} }
} }