use case instead of ifs
This commit is contained in:
		
							parent
							
								
									9858c47a14
								
							
						
					
					
						commit
						beee6a46b4
					
				@ -18,27 +18,31 @@ function handleMoonslicer(message) {
 | 
			
		||||
  console.log('Hit0: ' + hit0 + ' Hit1: ' + hit1);
 | 
			
		||||
 | 
			
		||||
  var old_text = textarea.value;
 | 
			
		||||
  if (hit0 == 20 || hit1 == 20) {
 | 
			
		||||
 | 
			
		||||
  new Set([hit0, hit1]).forEach( function(die_val) {
 | 
			
		||||
    switch (die_val) {
 | 
			
		||||
      case 20:
 | 
			
		||||
        textarea.value = "&{template:npcdmg} {{damage=1}} {{dmg1flag=1}} {{dmg1=+[[1d6]]}} {{dmg1type=Ice}}";
 | 
			
		||||
    submit_button.click();
 | 
			
		||||
  }
 | 
			
		||||
  if (hit0 == 19 || hit1 == 19) {
 | 
			
		||||
        break;
 | 
			
		||||
      case 19:
 | 
			
		||||
        textarea.value = "&{template:npcdmg} {{damage=1}} {{dmg1flag=1}} {{dmg1=+[[1d4]]}} {{dmg1type=Ice}}";
 | 
			
		||||
    submit_button.click();
 | 
			
		||||
        break;
 | 
			
		||||
      case 2:
 | 
			
		||||
        textarea.value = "&{template:npcdmg} {{damage=1}} {{dmg1flag=1}} {{dmg1=[[floor(1d4/2)]]}} {{dmg1type=Ice to self}}";
 | 
			
		||||
        break;
 | 
			
		||||
      case 1:
 | 
			
		||||
        textarea.value = "&{template:npcdmg} {{damage=1}} {{dmg1flag=1}} {{dmg1=[[floor(1d6/2)]]}} {{dmg1type=Ice to self}}";
 | 
			
		||||
        break;
 | 
			
		||||
    }
 | 
			
		||||
  if (hit0 == 2 || hit1 == 2) {
 | 
			
		||||
    textarea.value = "&{template:npcdmg} {{damage=1}} {{dmg1flag=1}} {{dmg1=[[floor(1d4/2)]]}} {{dmg1type=Ice to self}}}";
 | 
			
		||||
    submit_button.click();
 | 
			
		||||
  } 
 | 
			
		||||
  if (hit0 == 1 || hit1 == 1) {
 | 
			
		||||
    textarea.value = "&{template:npcdmg} {{damage=1}} {{dmg1flag=1}} {{dmg1=[[1d6]]} {{dmg1type=Ice to self}}}";
 | 
			
		||||
    submit_button.click();
 | 
			
		||||
  }
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  textarea.value = old_text;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
Send a message to the page script.
 | 
			
		||||
 *  Figure out what to do with the messages we find in the textchat area
 | 
			
		||||
 */
 | 
			
		||||
function handleMutation(mutation) {
 | 
			
		||||
  mutation.addedNodes.forEach( function(message) {
 | 
			
		||||
@ -52,9 +56,9 @@ function handleMutation(mutation) {
 | 
			
		||||
  });
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
/*
 | 
			
		||||
Add messagePageScript() as a listener to click events on
 | 
			
		||||
the "from-content-script" element.
 | 
			
		||||
 *  Watch for changes to the textchat content area
 | 
			
		||||
 */ 
 | 
			
		||||
var textchat = document.getElementById("textchat");
 | 
			
		||||
var content = textchat.getElementsByClassName("content")[0];
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user