Did stuff

This commit is contained in:
Tim Stallard 2017-04-03 09:24:31 +01:00
parent 26718bc39f
commit d9efbf4c43
7 changed files with 97 additions and 13 deletions

View File

@ -32,7 +32,6 @@
"node-uuid": "^1.4.7",
"sass-loader": "^6.0.1",
"style-loader": "^0.13.1",
"uuid": "^3.0.1",
"webpack": "^2.2.1",
"webpack-dev-server": "^2.3.0"
}

View File

@ -33,8 +33,8 @@ module.exports = {
}
if(!require("./util/coPrime.js")(a, 26)){
throw "a and 26 must be coprime";
return "";
console.log(a, 26, "not coprime");
}
var lookupTable = [];

View File

@ -2,7 +2,8 @@ module.exports = {
name: "Output",
inputs: {
input: {
name: "Input"
name: "Input",
type: "text"
}
},
output: false,

View File

@ -1,6 +1,7 @@
var diagram = require("./diagram");
var events = require("./events.js");
var blocks = require("./blocks");
var blockModels = require("./blocks");
var typeConversion = require("./typeConversion.js");
function resolveOutput(block, cache){
try{
@ -19,17 +20,21 @@ 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(!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;
if(inputValues[input]){ //if input is present, check and convert into type
inputValues[input] = typeConversion[blockModels[block.type].inputs[input].type](inputValues[input]);
}
else if(blocks[block.type].inputs[input].required){ //otherwise, throw an error
else{ //currently missing/blank
if(blockModels[block.type].inputs[input].required){ //if required, throw an error
throw "A required input is missing";
}
else if(blockModels[block.type].inputs[input].default){ //otherwise, if a default is present, use that
inputValues[input] = blockModels[block.type].inputs[input].default;
}
}
}
var output = blocks[block.type].execute(inputValues, block);
var output = blockModels[block.type].execute(inputValues, block);
cache[block.id] = output;
return output;
}

View File

@ -1,5 +1,6 @@
var blocks = require("../blocks");
var events = require("../events");
var $ = require("jquery");
module.exports = function(newBlock){
var newBlockElement = $(

View File

@ -8,8 +8,18 @@ function blockPositionChange(event){ //fired when a block is moved or added
var block = diagram.state.filter((block)=>(block.dragging))[0];
if(block){
//change position to the event coordinates plus the offset, factoring in the relative positioning of the items on the workspace
block.position.x = event.pageX - $("#workspace").position().left - block.offset.x;
block.position.y = event.pageY - $("#workspace").position().top - block.offset.y;
block.position.x = window.scrollX + event.clientX - $("#workspace").position().left - block.offset.x;
block.position.y = window.scrollY + event.clientY - $("#workspace").position().top - block.offset.y;
if(offY){
//when off y-axis, move to sit edge of block on axis
block.position.y = window.scrollY + window.innerHeight - $(block.elem).height() - $("#workspace").position().top;
}
if(offX){
//when off y-axis, move to sit edge of block on axis
block.position.x = window.scrollX + window.innerWidth - $(block.elem).width() - $("#workspace").position().left;
}
$("#workspace>.block#" + block.id).css({ //apply new position to element
left: block.position.x,
@ -61,9 +71,10 @@ $("#workspace").on("mousedown", ".block>.main,.block>.inputs", function(event){
$("#workspace").on("mouseup", ".block>.main,.block>.inputs", function(event){
diagram.state.filter((block)=>(block.id == $(this).parent().attr("id")))[0].dragging = false;
offX = false;
offY = false;
});
$(document).on("mousemove", function(event){
event.preventDefault();
blockPositionChange(event);
@ -89,3 +100,56 @@ $(document).on("contextmenu", function(event){
event.preventDefault();
return false;
});
var timer;
var lastevent;
var startevent;
var offY = false;
var offX = false;
$(document).on("mousemove", ".block", function(e){
if(diagram.state.filter((block)=>(block.id == $(this).attr("id"))).filter((block)=>(block.dragging)).length){
//block is being dragged
lastevent = e;
if(!offY){
if(($(this).offset().top + $(this).height() - window.scrollY) > window.innerHeight){
//block has just moved off the page, start scrolling
startevent = e;
offY = true;
}
}
else{
if(e.clientY < startevent.clientY){
//user has moved the block back from the boundary, stop
offY = false;
blockPositionChange(lastevent);
}
}
if(!offX){
if(($(this).offset().left + $(this).width() - window.scrollX) > window.innerWidth){
//block has just moved off the page, start scrolling
startevent = e;
offX = true;
}
}
else{
if(e.clientX < startevent.clientX){
//user has moved the block back from the boundary, stop
offX = false;
blockPositionChange(lastevent);
}
}
}
});
timer = setInterval(function(){
if(offY){ //scroll in y-direction and update blocks if block is moved off in that direction
window.scrollBy(0, 2);
}
if(offX){ //scroll in x-direction and update blocks if block is moved off in that direction
window.scrollBy(2, 0);
}
if(offX || offY){ //if off in either direction, move the block on the page
blockPositionChange(lastevent);
}
}, 3);

14
src/typeConversion.js Normal file
View File

@ -0,0 +1,14 @@
module.exports = {
text: function(input){
if(typeof input != "string"){
throw "Invalid input type - should be a string.";
}
return input;
},
number: function(input){
if(isNaN(parseInt(input))){
throw "Invalid input type - should be a string.";
}
return parseInt(input);
}
}