export class itemSelector {
constructor(containerSelector, entities){
this.containerSelector = containerSelector;
this.container = document.querySelector(containerSelector);
if(!this.container) throw new Error("Could not find container "+container);
this.entities = entities;
this.direction = 0;
// populate container
let cont = this.container;
let HTML = "";
HTML += "
";
HTML += "";
HTML += "Name: ";
HTML += "";
HTML += "
";
// direction selector
HTML += "";
HTML += "
Direction:
";
HTML += "
Press R to rotate
";
HTML += "
0
"
HTML += "
";
// write styles
let styles = {
".header > h2":{
color:"white",
},
".blackText":{
color:"black",
},
".blackText > option":{
color:"black",
}
}
// turn style object into style tag
HTML += "";
// handle direction keyboard event
Mousetrap.bind('r', ()=>this.rotate());
}
rotate(){
this.direction = (this.direction + 2) % 8;
// update display
document.querySelector("#directionDisplay").innerHTML = this.direction;
}
getItem(){
let name = document.querySelector(this.containerSelector+" > .itemSelector > select").value;
let direction = this.direction;
return {name, direction};
}
}