More error handling stuff
This commit is contained in:
		@@ -11,7 +11,8 @@ module.exports =  {
 | 
				
			|||||||
      name: "Shift",
 | 
					      name: "Shift",
 | 
				
			||||||
      type: "number",
 | 
					      type: "number",
 | 
				
			||||||
      required: true,
 | 
					      required: true,
 | 
				
			||||||
      inline: true
 | 
					      inline: true,
 | 
				
			||||||
 | 
					      default: "0"
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  output: true,
 | 
					  output: true,
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -25,7 +25,7 @@ module.exports =  {
 | 
				
			|||||||
    .filter((pair)=>(pair.length == 2))
 | 
					    .filter((pair)=>(pair.length == 2))
 | 
				
			||||||
    .map((pair)=>(parseInt(pair, 16)))
 | 
					    .map((pair)=>(parseInt(pair, 16)))
 | 
				
			||||||
    .map((int)=>(String.fromCharCode(int)))
 | 
					    .map((int)=>(String.fromCharCode(int)))
 | 
				
			||||||
    .join("")
 | 
					    .join("");
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  pageBlock: {
 | 
					  pageBlock: {
 | 
				
			||||||
    html: "",
 | 
					    html: "",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,19 +10,13 @@ module.exports =  {
 | 
				
			|||||||
    offset: {
 | 
					    offset: {
 | 
				
			||||||
      name: "Offset",
 | 
					      name: "Offset",
 | 
				
			||||||
      type: "text",
 | 
					      type: "text",
 | 
				
			||||||
      required: true,
 | 
					      required: false,
 | 
				
			||||||
      inline: false
 | 
					      inline: false,
 | 
				
			||||||
 | 
					      default: "0"
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  output: true,
 | 
					  output: true,
 | 
				
			||||||
  execute: function({letters, offset}, elem){
 | 
					  execute: function({letters, offset}, elem){
 | 
				
			||||||
    if(!offset){
 | 
					 | 
				
			||||||
      offset = 0;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    else{
 | 
					 | 
				
			||||||
      offset = parseInt(offset);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return letters
 | 
					    return letters
 | 
				
			||||||
    .split("")
 | 
					    .split("")
 | 
				
			||||||
    .map((char)=>(char.charCodeAt(0)))
 | 
					    .map((char)=>(char.charCodeAt(0)))
 | 
				
			||||||
@@ -35,7 +29,7 @@ module.exports =  {
 | 
				
			|||||||
        return asciiVal - 97;
 | 
					        return asciiVal - 97;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
    .map((num)=>(num + offset))
 | 
					    .map((num)=>(num + parseInt(offset)))
 | 
				
			||||||
    .map((num)=>(((num%26)+26)%26))
 | 
					    .map((num)=>(((num%26)+26)%26))
 | 
				
			||||||
    .join(",");
 | 
					    .join(",");
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -10,34 +10,20 @@ module.exports =  {
 | 
				
			|||||||
    offset: {
 | 
					    offset: {
 | 
				
			||||||
      name: "Offset",
 | 
					      name: "Offset",
 | 
				
			||||||
      type: "text",
 | 
					      type: "text",
 | 
				
			||||||
      required: true,
 | 
					      required: false,
 | 
				
			||||||
      inline: false
 | 
					      inline: false,
 | 
				
			||||||
 | 
					      default: "0"
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  output: true,
 | 
					  output: true,
 | 
				
			||||||
  execute: function({nums, offset}, elem){
 | 
					  execute: function({nums, offset}, elem){
 | 
				
			||||||
    if(!offset){
 | 
					 | 
				
			||||||
      offset = 0;
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
    else{
 | 
					 | 
				
			||||||
      offset = parseInt(offset);
 | 
					 | 
				
			||||||
    }
 | 
					 | 
				
			||||||
 | 
					 | 
				
			||||||
    return nums
 | 
					    return nums
 | 
				
			||||||
    .split(",")
 | 
					    .split(",")
 | 
				
			||||||
    .filter((num)=>(num))
 | 
					    .filter((num)=>(num))
 | 
				
			||||||
    .map((num)=>(parseInt(num)))
 | 
					    .map((num)=>(parseInt(num)))
 | 
				
			||||||
    .filter((num)=>(!isNaN(num)))
 | 
					    .filter((num)=>(!isNaN(num)))
 | 
				
			||||||
    .map((num)=>(num - offset))
 | 
					    .map((num)=>(num - parseInt(offset)))
 | 
				
			||||||
    .map((num)=>(num%52))
 | 
					    .map((num)=>((num%52)+52)%52)
 | 
				
			||||||
    .map((num)=>{
 | 
					 | 
				
			||||||
      if(num < 0){
 | 
					 | 
				
			||||||
        return 52 + num;
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
      else{
 | 
					 | 
				
			||||||
        return num;
 | 
					 | 
				
			||||||
      }
 | 
					 | 
				
			||||||
    })
 | 
					 | 
				
			||||||
    .map((num)=>{
 | 
					    .map((num)=>{
 | 
				
			||||||
      if(num < 26){
 | 
					      if(num < 26){
 | 
				
			||||||
        asciiOffset = 97;
 | 
					        asciiOffset = 97;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,7 +5,7 @@ var blocks = require("./blocks");
 | 
				
			|||||||
function resolveOutput(block, cache){
 | 
					function resolveOutput(block, cache){
 | 
				
			||||||
  try{
 | 
					  try{
 | 
				
			||||||
    var inputValues = {};
 | 
					    var inputValues = {};
 | 
				
			||||||
    var error = "";
 | 
					    $(block.elem).find(".error").html("");
 | 
				
			||||||
    for(var input in block.inputs){
 | 
					    for(var input in block.inputs){
 | 
				
			||||||
      if(block.inputs[input].joined){ //if it's joined to something else
 | 
					      if(block.inputs[input].joined){ //if it's joined to something else
 | 
				
			||||||
        if(block.inputs[input].joined in cache){ //if output of other block is already in cache
 | 
					        if(block.inputs[input].joined in cache){ //if output of other block is already in cache
 | 
				
			||||||
@@ -19,17 +19,22 @@ function resolveOutput(block, cache){
 | 
				
			|||||||
      else if(block.inputs[input].value){ //if value is already set, just save that
 | 
					      else if(block.inputs[input].value){ //if value is already set, just save that
 | 
				
			||||||
        inputValues[input] = block.inputs[input].value;
 | 
					        inputValues[input] = block.inputs[input].value;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
      if(blocks[block.type].inputs[input].required && !(inputValues[input])){ //if input is required and is missing
 | 
					      if(!inputValues[input]){ //if currently missing/blank
 | 
				
			||||||
 | 
					        if(blocks[block.type].inputs[input].default){ //if a default is present, use that
 | 
				
			||||||
 | 
					          inputValues[input] = blocks[block.type].inputs[input].default;
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					        else if(blocks[block.type].inputs[input].required){ //otherwise, throw an error
 | 
				
			||||||
          throw "A required input is missing";
 | 
					          throw "A required input is missing";
 | 
				
			||||||
        }
 | 
					        }
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    var output = blocks[block.type].execute(inputValues, block);
 | 
					    var output = blocks[block.type].execute(inputValues, block);
 | 
				
			||||||
    cache[block.id] = output;
 | 
					    cache[block.id] = output;
 | 
				
			||||||
    return output;
 | 
					    return output;
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  catch(err){
 | 
					  catch(err){ //if there is an error, display it
 | 
				
			||||||
    console.log("ERROR", err);
 | 
					    $(block.elem).find(".error").html(err);
 | 
				
			||||||
    return "";
 | 
					    return "";
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -12,6 +12,7 @@
 | 
				
			|||||||
  <div class="main">
 | 
					  <div class="main">
 | 
				
			||||||
    <div>
 | 
					    <div>
 | 
				
			||||||
      <div class="title">{{block.name}}</div>
 | 
					      <div class="title">{{block.name}}</div>
 | 
				
			||||||
 | 
					      <div class="error"></div>
 | 
				
			||||||
      {{{block.pageBlock.html}}}
 | 
					      {{{block.pageBlock.html}}}
 | 
				
			||||||
    </div>
 | 
					    </div>
 | 
				
			||||||
  </div>
 | 
					  </div>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -61,6 +61,10 @@ body{
 | 
				
			|||||||
      >.title{
 | 
					      >.title{
 | 
				
			||||||
        text-align: center;
 | 
					        text-align: center;
 | 
				
			||||||
      }
 | 
					      }
 | 
				
			||||||
 | 
					      >.error{
 | 
				
			||||||
 | 
					        color: red;
 | 
				
			||||||
 | 
					        text-align: center;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  >.output{
 | 
					  >.output{
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user