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