I am creating a simple concept where I have a small menu to choose a tool from and then I can click and drag to build.
For example, I click on the rails tool and then I can click and move the mouse to create a rail segment.
I'm coding it something like this(missing some variables for temp values and objects):
var toolSelected = false;//if I click the rails button, it changes to 'rails'
renderer.domElement.addEventListener('mousedown', function(event){
//here I check which is the tool selected
if(toolSelected === 'rails'){
//create rail object starting in event coordinates
}
});
renderer.domElement.addEventListener('mousemove', function(event){
//here I check which is the tool selected
if(toolSelected === 'rails'){
//pass the mouse movement to the rail object to update end coordinates position so I can drag and see the potential rail
}
});
renderer.domElement.addEventListener('mouseup', function(event){
//here I check which is the tool selected
if(toolSelected === 'rails'){
//indicate that the rail should be finished and build it with the mouse up coordinates
}
});
The question is, is there a better or recommended way to structure these mouse events? Or do I have to, under each mouse event, check which tool is selected and perform the appropriate actions?