Added inline inputs (blocks still need updating)
This commit is contained in:
		@@ -1,8 +1,14 @@
 | 
				
			|||||||
module.exports =  {
 | 
					module.exports =  {
 | 
				
			||||||
  name: "Caesar",
 | 
					  name: "Caesar",
 | 
				
			||||||
  inputs: {
 | 
					  inputs: {
 | 
				
			||||||
    text: "Text",
 | 
					    text: {
 | 
				
			||||||
    shift: "Shift"
 | 
					      name: "Text"
 | 
				
			||||||
 | 
					    },
 | 
				
			||||||
 | 
					    shift: {
 | 
				
			||||||
 | 
					      name: "Shift",
 | 
				
			||||||
 | 
					      inline: true,
 | 
				
			||||||
 | 
					      type: "number"
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  output: true,
 | 
					  output: true,
 | 
				
			||||||
  execute: function({text, shift}, elem){
 | 
					  execute: function({text, shift}, elem){
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,7 +1,9 @@
 | 
				
			|||||||
module.exports =  {
 | 
					module.exports =  {
 | 
				
			||||||
  name: "Output",
 | 
					  name: "Output",
 | 
				
			||||||
  inputs: {
 | 
					  inputs: {
 | 
				
			||||||
    input: "Input"
 | 
					    input: {
 | 
				
			||||||
 | 
					      name: "Input"
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
  },
 | 
					  },
 | 
				
			||||||
  output: false,
 | 
					  output: false,
 | 
				
			||||||
  execute: function({input}, block){
 | 
					  execute: function({input}, block){
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -5,12 +5,17 @@ var blocks = require("./blocks");
 | 
				
			|||||||
function resolveOutput(block, cache){
 | 
					function resolveOutput(block, cache){
 | 
				
			||||||
  var inputValues = {};
 | 
					  var inputValues = {};
 | 
				
			||||||
  for(var input in block.inputs){
 | 
					  for(var input in block.inputs){
 | 
				
			||||||
    if(block.inputs[input] in cache){
 | 
					    if(block.inputs[input].joined){ //if it's joined to something else
 | 
				
			||||||
      inputValues[input] = cache[block.inputs[input]];
 | 
					      if(block.inputs[input].joined in cache){ //if output of other block is already in cache
 | 
				
			||||||
 | 
					        inputValues[input] = cache[block.inputs[input].joined];
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
 | 
					      else{
 | 
				
			||||||
 | 
					        var inputBlock = diagram.state.filter((diagramBlock)=>(diagramBlock.id == block.inputs[input].joined))[0]; //find block instance
 | 
				
			||||||
 | 
					        inputValues[input] = resolveOutput(inputBlock, cache); //calculate and store output
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
    else{
 | 
					    else if(block.inputs[input].value){ //if value is already set, just save that
 | 
				
			||||||
      var inputBlock = diagram.state.filter((diagramBlock)=>(diagramBlock.id == block.inputs[input]))[0];
 | 
					      inputValues[input] = block.inputs[input].value;
 | 
				
			||||||
      inputValues[input] = resolveOutput(inputBlock, cache);
 | 
					 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,4 +1,5 @@
 | 
				
			|||||||
var blocks = require("../blocks");
 | 
					var blocks = require("../blocks");
 | 
				
			||||||
 | 
					var events = require("../events");
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module.exports = function(newBlock){
 | 
					module.exports = function(newBlock){
 | 
				
			||||||
  var newBlockElement = $(
 | 
					  var newBlockElement = $(
 | 
				
			||||||
@@ -7,14 +8,26 @@ module.exports = function(newBlock){
 | 
				
			|||||||
      instance: newBlock
 | 
					      instance: newBlock
 | 
				
			||||||
    })
 | 
					    })
 | 
				
			||||||
  ).appendTo("#workspace");
 | 
					  ).appendTo("#workspace");
 | 
				
			||||||
 | 
					  newBlockElement.find(".inputs input").keyup(function(){
 | 
				
			||||||
 | 
					    //when input field is updated, save the value to the block object and emit event for updates
 | 
				
			||||||
 | 
					    var inputId = $(this).parent().attr("id");
 | 
				
			||||||
 | 
					    if(!newBlock.inputs[inputId]){
 | 
				
			||||||
 | 
					      newBlock.inputs[inputId] = {};
 | 
				
			||||||
 | 
					    }
 | 
				
			||||||
 | 
					    newBlock.inputs[inputId].value = $(this).val();
 | 
				
			||||||
 | 
					    events.emit("inputChanged");
 | 
				
			||||||
 | 
					  });
 | 
				
			||||||
  newBlock.elem = newBlockElement;
 | 
					  newBlock.elem = newBlockElement;
 | 
				
			||||||
  if(blocks[newBlock.type].size){
 | 
					  if(blocks[newBlock.type].size){
 | 
				
			||||||
 | 
					    //if the block declaration contains a non-standard size, resize it
 | 
				
			||||||
    newBlockElement.css({
 | 
					    newBlockElement.css({
 | 
				
			||||||
      height: blocks[newBlock.type].size.height,
 | 
					      height: blocks[newBlock.type].size.height,
 | 
				
			||||||
      width: blocks[newBlock.type].size.width
 | 
					      width: blocks[newBlock.type].size.width
 | 
				
			||||||
    });
 | 
					    });
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  if(newBlock.position){
 | 
					  if(newBlock.position){
 | 
				
			||||||
 | 
					    //if this block instance already has a position, place it there
 | 
				
			||||||
 | 
					    //this will only be used for importing
 | 
				
			||||||
    newBlockElement.css({
 | 
					    newBlockElement.css({
 | 
				
			||||||
      top: newBlock.position.y,
 | 
					      top: newBlock.position.y,
 | 
				
			||||||
      left: newBlock.position.x
 | 
					      left: newBlock.position.x
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,7 +1,12 @@
 | 
				
			|||||||
<div class="block" data-type="{{block.type}}" id="{{instance.id}}">
 | 
					<div class="block" data-type="{{block.type}}" id="{{instance.id}}">
 | 
				
			||||||
  <div class="inputs">
 | 
					  <div class="inputs">
 | 
				
			||||||
    {{#each block.inputs as |desc name|}}
 | 
					    {{#each block.inputs as |input id|}}
 | 
				
			||||||
      <div id="{{name}}">{{desc}}</div>
 | 
					      <div id="{{id}}">
 | 
				
			||||||
 | 
					        {{input.name}}
 | 
				
			||||||
 | 
					        {{#if input.inline}}
 | 
				
			||||||
 | 
					          <input type="{{input.type}}" size="4" value="{{lookup (lookup ../instance.inputs id) "value"}}"></input>
 | 
				
			||||||
 | 
					        {{/if}}
 | 
				
			||||||
 | 
					      </div>
 | 
				
			||||||
    {{/each}}
 | 
					    {{/each}}
 | 
				
			||||||
  </div>
 | 
					  </div>
 | 
				
			||||||
  <div class="main">
 | 
					  <div class="main">
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -32,7 +32,15 @@ $("#blocks").on("mousedown", ".block>.main,.block>.inputs", function(event){
 | 
				
			|||||||
      y: event.pageY - $(this).parent().offset().top
 | 
					      y: event.pageY - $(this).parent().offset().top
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    type: $(this).parent().data("type"),
 | 
					    type: $(this).parent().data("type"),
 | 
				
			||||||
    inputs: {},
 | 
					    inputs:
 | 
				
			||||||
 | 
					      Object.keys(blocks[$(this).parent().data("type")].inputs) //get block ids
 | 
				
			||||||
 | 
					      .reduce((inputs, input)=>{ //turn this into an object
 | 
				
			||||||
 | 
					        inputs[input] = {
 | 
				
			||||||
 | 
					          joined: "",
 | 
				
			||||||
 | 
					          value: ""
 | 
				
			||||||
 | 
					        };
 | 
				
			||||||
 | 
					        return inputs;
 | 
				
			||||||
 | 
					      }, {}),
 | 
				
			||||||
    properties: {}
 | 
					    properties: {}
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  diagram.state.push(newBlock);
 | 
					  diagram.state.push(newBlock);
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -50,7 +50,7 @@ $("#workspace").on("mouseup", ".block>.inputs>div", function(event){
 | 
				
			|||||||
    endBlock = $(this).parent().parent().attr("id");
 | 
					    endBlock = $(this).parent().parent().attr("id");
 | 
				
			||||||
    endInput = $(this).attr("id");
 | 
					    endInput = $(this).attr("id");
 | 
				
			||||||
    var endBlockInstance = diagram.state.filter((block)=>(block.id == endBlock))[0];
 | 
					    var endBlockInstance = diagram.state.filter((block)=>(block.id == endBlock))[0];
 | 
				
			||||||
    endBlockInstance.inputs[endInput] = startBlock;
 | 
					    endBlockInstance.inputs[endInput].joined = startBlock;
 | 
				
			||||||
    drawJoiningLines();
 | 
					    drawJoiningLines();
 | 
				
			||||||
    events.emit("newJoin");
 | 
					    events.emit("newJoin");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -62,7 +62,7 @@ $("#workspace").on("mousedown", ".block>.inputs>div", function(event){
 | 
				
			|||||||
    var blockId = $(this).parent().parent().attr("id")
 | 
					    var blockId = $(this).parent().parent().attr("id")
 | 
				
			||||||
    var input = $(this).attr("id");
 | 
					    var input = $(this).attr("id");
 | 
				
			||||||
    var block = diagram.state.filter((block)=>(block.id == blockId))[0];
 | 
					    var block = diagram.state.filter((block)=>(block.id == blockId))[0];
 | 
				
			||||||
    delete block.inputs[input];
 | 
					    block.inputs[input].joined = "";
 | 
				
			||||||
    drawJoiningLines();
 | 
					    drawJoiningLines();
 | 
				
			||||||
    events.emit("joinRemove");
 | 
					    events.emit("joinRemove");
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
@@ -76,25 +76,27 @@ function drawJoiningLines(){
 | 
				
			|||||||
  $(".line").remove();
 | 
					  $(".line").remove();
 | 
				
			||||||
  for(var endBlock of diagram.state){
 | 
					  for(var endBlock of diagram.state){
 | 
				
			||||||
    for(var input in endBlock.inputs){
 | 
					    for(var input in endBlock.inputs){
 | 
				
			||||||
      startBlockId = endBlock.inputs[input];
 | 
					      if(endBlock.inputs[input].joined){
 | 
				
			||||||
      startBlock = diagram.state.filter((block)=>(block.id == startBlockId))[0];
 | 
					        startBlockId = endBlock.inputs[input].joined;
 | 
				
			||||||
      lineId = startBlock.id + "-" + endBlock.id + "-" + input;
 | 
					        startBlock = diagram.state.filter((block)=>(block.id == startBlockId))[0];
 | 
				
			||||||
      if($("#" + lineId).length){
 | 
					        lineId = startBlock.id + "-" + endBlock.id + "-" + input;
 | 
				
			||||||
        var line = $("#" + lineId)
 | 
					        if($("#" + lineId).length){
 | 
				
			||||||
      }
 | 
					          var line = $("#" + lineId)
 | 
				
			||||||
      else{
 | 
					        }
 | 
				
			||||||
        var line = $("<div class='line' id='" + lineId + "'></div>").appendTo($("#workspace"));
 | 
					        else{
 | 
				
			||||||
      }
 | 
					          var line = $("<div class='line' id='" + lineId + "'></div>").appendTo($("#workspace"));
 | 
				
			||||||
 | 
					        }
 | 
				
			||||||
 | 
					
 | 
				
			||||||
      outputElem = $("#" + startBlock.id).find(".output").eq(0);
 | 
					        outputElem = $("#" + startBlock.id).find(".output").eq(0);
 | 
				
			||||||
      inputElem = $("#" + endBlock.id).find(".inputs>#" + input).eq(0);
 | 
					        inputElem = $("#" + endBlock.id).find(".inputs>#" + input).eq(0);
 | 
				
			||||||
      moveLine(
 | 
					        moveLine(
 | 
				
			||||||
        line,
 | 
					          line,
 | 
				
			||||||
        startBlock.position.x + (outputElem.outerWidth()/2),
 | 
					          startBlock.position.x + (outputElem.outerWidth()/2),
 | 
				
			||||||
        startBlock.position.y + outputElem.position().top + outputElem.outerHeight(),
 | 
					          startBlock.position.y + outputElem.position().top + outputElem.outerHeight(),
 | 
				
			||||||
        endBlock.position.x + inputElem.position().left + (inputElem.outerWidth()/2),
 | 
					          endBlock.position.x + inputElem.position().left + (inputElem.outerWidth()/2),
 | 
				
			||||||
        endBlock.position.y
 | 
					          endBlock.position.y
 | 
				
			||||||
      );
 | 
					        );
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -45,6 +45,9 @@ body{
 | 
				
			|||||||
      text-align: center;
 | 
					      text-align: center;
 | 
				
			||||||
      padding-top: 5px;
 | 
					      padding-top: 5px;
 | 
				
			||||||
      padding-bottom: 5px;
 | 
					      padding-bottom: 5px;
 | 
				
			||||||
 | 
					      >input{
 | 
				
			||||||
 | 
					        width: 40px;
 | 
				
			||||||
 | 
					      }
 | 
				
			||||||
    }
 | 
					    }
 | 
				
			||||||
  }
 | 
					  }
 | 
				
			||||||
  .main{
 | 
					  .main{
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user