mirror of
https://github.com/publiclab/image-sequencer.git
synced 2025-12-14 20:30:01 +01:00
Updated Readme and Code Comments
This commit is contained in:
@@ -28,6 +28,17 @@ ImageSequencer = function ImageSequencer(options) {
|
||||
}
|
||||
}
|
||||
|
||||
function copy(a) {
|
||||
if (!typeof(a) == "object") return a;
|
||||
if (objTypeOf(a) == "Array") return a.slice();
|
||||
if (objTypeOf(a) == "Object") return JSON.parse(JSON.stringify(a));
|
||||
return a;
|
||||
}
|
||||
|
||||
function makeArray(input) {
|
||||
return (objTypeOf(input)=="Array")?input:[input];
|
||||
}
|
||||
|
||||
var image,
|
||||
steps = [],
|
||||
modules = require('./Modules'),
|
||||
@@ -37,14 +48,14 @@ ImageSequencer = function ImageSequencer(options) {
|
||||
// if (options.imageSelect || options.inBrowser) addStep('image-select');
|
||||
// else if (options.imageUrl) loadImage(imageUrl);
|
||||
|
||||
function addStep(image, name, o) {
|
||||
function addStep(image, name, o_) {
|
||||
log('\x1b[36m%s\x1b[0m','adding step \"' + name + '\" to \"' + image + '\".');
|
||||
|
||||
o = o || {};
|
||||
o = {};
|
||||
o.id = options.sequencerCounter++; //Gives a Unique ID to each step
|
||||
o.name = o.name || name;
|
||||
o.selector = o.selector || 'ismod-' + name;
|
||||
o.container = o.container || options.selector;
|
||||
o.name = o_.name || name;
|
||||
o.selector = o_.selector || 'ismod-' + name;
|
||||
o.container = o_.container || options.selector;
|
||||
o.image = image;
|
||||
|
||||
var module = modules[name](o);
|
||||
@@ -61,38 +72,52 @@ ImageSequencer = function ImageSequencer(options) {
|
||||
else defaultSetupModule.apply(module); // run default setup() in scope of module (is this right?)
|
||||
|
||||
// tell the UI that a step has been added.
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
function addSteps(){
|
||||
argtype = [];
|
||||
args = [];
|
||||
json_q = {};
|
||||
for (i in images) {
|
||||
lastimage = i;
|
||||
}
|
||||
for (var arg in arguments) {
|
||||
argtype.push(objTypeOf(arguments[arg]));
|
||||
args.push(copy(arguments[arg]));
|
||||
}
|
||||
if (arguments.length == 1) {
|
||||
if(argtype[0] == "Object")
|
||||
if (args.length == 1) {
|
||||
if(objTypeOf(args[0]) == "Object") //addSteps(JSON)
|
||||
json_q = arguments[0];
|
||||
else
|
||||
for (i in images)
|
||||
json_q[i] = (argtype[0]=="Array")?arguments[0]:[arguments[0]];
|
||||
else { //addSteps(name) => addSteps([image],[name])
|
||||
args.splice(0,0,[]);
|
||||
for (img in images) args[0].push(img);
|
||||
}
|
||||
}
|
||||
else if (arguments.length == 2) {
|
||||
if(argtype[1]=="String") arguments[1] = [arguments[1]];
|
||||
if(argtype[0]=="String")
|
||||
json_q[arguments[0]] = arguments[1];
|
||||
else if(argtype[0]=="Array")
|
||||
for (var i in arguments[0]) {
|
||||
json_q[arguments[0][i]] = arguments[1];
|
||||
if (args.length == 2) {
|
||||
//addSteps(name,o) => addSteps([image],[name],o)
|
||||
if (objTypeOf(args[1])=="Object") {
|
||||
args.splice(0,0,[]);
|
||||
for (img in images) args[0].push(img);
|
||||
}
|
||||
else { //addSteps(image,name) => addSteps([image],[name],o)
|
||||
args[2] = {};
|
||||
}
|
||||
}
|
||||
if (args.length == 3) { //addSteps(image,name,o) => addSteps(JSON)
|
||||
args[0] = makeArray(args[0]);
|
||||
args[1] = makeArray(args[1]);
|
||||
for (img in args[0]) {
|
||||
json_q[args[0][img]] = [];
|
||||
for (step in args[1]) {
|
||||
json_q[args[0][img]].push({
|
||||
name: args[1][step],
|
||||
o: args[2]
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
for (i in json_q)
|
||||
for (j in json_q[i])
|
||||
addStep.call(this,i,json_q[i][j]);
|
||||
addStep.call(this,i,json_q[i][j].name,json_q[i][j].o);
|
||||
|
||||
}
|
||||
|
||||
@@ -109,32 +134,32 @@ ImageSequencer = function ImageSequencer(options) {
|
||||
function removeSteps(image,index) {
|
||||
run = {};
|
||||
this_ = this;
|
||||
args = [];
|
||||
for(var arg in arguments) args.push(copy(arguments[arg]));
|
||||
json_q = {};
|
||||
|
||||
if(arguments.length==2) {
|
||||
removeStep(image,index);
|
||||
run[image] = index;
|
||||
}
|
||||
else if(arguments.length==1) {
|
||||
if (typeof(arguments[0])=="number" || objTypeOf(arguments[0])=="Array") {
|
||||
indx = arguments[0];
|
||||
arguments[0] = {};
|
||||
for (img in this_.images) arguments[0][img] = indx;
|
||||
if(args.length==1) {
|
||||
if (objTypeOf(args[0])=="Object") { //removeSteps(JSON)
|
||||
json_q = args[0];
|
||||
}
|
||||
else { //removeSteps(index) => removeSteps([image],[index])
|
||||
args.splice(0,0,[]);
|
||||
for(img in images) args[0].push(img);
|
||||
}
|
||||
if (objTypeOf(arguments[0])=='Object') {
|
||||
for (img in arguments[0]) {
|
||||
var indexes = arguments[0][img];
|
||||
if (typeof(indexes) == "number")
|
||||
{removeStep(img,indexes); run[img]=indexes;}
|
||||
else if (objTypeOf(indexes) == "Array") {
|
||||
indexes = indexes.sort(function(a,b){return b-a});
|
||||
run[img] = indexes[indexes.length-1];
|
||||
for (i in indexes)
|
||||
removeStep(img,indexes[i]);
|
||||
}
|
||||
}
|
||||
} // end if argument is object
|
||||
}
|
||||
|
||||
if(args.length==2) { //removeSteps(image,index) => removeSteps(JSON)
|
||||
args[0] = makeArray(args[0]);
|
||||
args[1] = makeArray(args[1]);
|
||||
for(img in args[0]) {
|
||||
json_q[args[0][img]] = args[1];
|
||||
}
|
||||
}
|
||||
for (img in json_q) {
|
||||
indices = json_q[img].sort(function(a,b){return b-a});
|
||||
run[img] = indices[indices.length-1];
|
||||
for (i in indices)
|
||||
removeStep(img,indices[i]);
|
||||
}
|
||||
this.run(run)
|
||||
}
|
||||
|
||||
@@ -229,10 +254,16 @@ ImageSequencer = function ImageSequencer(options) {
|
||||
this_ = this;
|
||||
runimg = {};
|
||||
json_q = {};
|
||||
args = [];
|
||||
for (var arg in arguments) args.push(copy(arguments[arg]));
|
||||
for (var arg in args)
|
||||
if(objTypeOf(args[arg]) == "Function")
|
||||
var callback = args.splice(arg,1)[0];
|
||||
for (image in images) {
|
||||
runimg[image] = 0;
|
||||
}
|
||||
function drawStep(drawarray,pos) {
|
||||
if(pos==drawarray.length) if(objTypeOf(callback)=='Function') callback();
|
||||
if(pos>=drawarray.length) return true;
|
||||
image = drawarray[pos].image;
|
||||
i = drawarray[pos].i;
|
||||
|
||||
Reference in New Issue
Block a user