Migrate proj object int lib/proj-ui.js

Modulize that sucker
This commit is contained in:
Matt 2016-06-18 20:06:57 -04:00
parent 38cd0ed1e4
commit 8b483ce2ef
2 changed files with 75 additions and 72 deletions

74
app/lib/proj-ui.js Normal file
View File

@ -0,0 +1,74 @@
var proj = {};
proj.queue = {};
proj.lock = false;
proj.init = function () {
'use strict';
proj.listen();
};
proj.set = function (dir, callback) {
'use strict';
var obj;
if (proj.lock) {
return false;
}
obj = {
dir : dir,
id : uuid.v4()
};
ipcRenderer.sendSync('proj', obj);
if (typeof callback !== 'undefined') {
obj.callback = callback;
}
proj.queue[obj.id] = obj;
proj.lock = true;
};
proj.move = function (callback) {
'use strict';
var obj;
if (proj.lock) {
return false;
}
obj = {
frame : true,
id : uuid.v4()
};
ipcRenderer.sendSync('proj', obj);
if (typeof callback !== 'undefined') {
obj.callback = callback;
}
proj.queue[obj.id] = obj;
proj.lock = true;
};
proj.end = function (c, id, ms) {
'use strict';
if (c === mcopy.cfg.arduino.cmd.proj_forward) {
mcopy.state.projector.direction = true;
} else if (c === mcopy.cfg.arduino.cmd.proj_backward) {
mcopy.state.projector.direction = false;
} else if (c === mcopy.cfg.arduino.cmd.projector) {
if (mcopy.state.projector.direction) {
mcopy.state.projector.pos += 1;
} else {
mcopy.state.projector.pos -= 1;
}
}
if (typeof proj.queue[id] !== 'undefined') {
if (typeof proj.queue[id].callback !== 'undefined') {
proj.queue[id].callback(ms);
}
delete proj.queue[id];
proj.lock = false;
}
};
proj.listen = function () {
'use strict';
ipcRenderer.on('proj', function (event, arg) {
proj.end(arg.cmd, arg.id, arg.ms);
return event.returnValue = true;
});
};
module.exports = proj;

View File

@ -8,7 +8,7 @@ var remote = require('remote'),
ipcRenderer = require('electron').ipcRenderer, ipcRenderer = require('electron').ipcRenderer,
mcopy = {}, mcopy = {},
light = require('./lib/light-ui.js'), light = require('./lib/light-ui.js'),
proj = {}, proj = require('./lib/proj-ui.js'),
cam = {}, cam = {},
nav = {}, nav = {},
seq = require('./lib/seq-ui.js'), seq = require('./lib/seq-ui.js'),
@ -59,77 +59,6 @@ mcopy.state = {
//mcopy.gui.updateState(); //mcopy.gui.updateState();
proj.queue = {};
proj.lock = false;
proj.init = function () {
'use strict';
proj.listen();
};
proj.set = function (dir, callback) {
'use strict';
var obj;
if (proj.lock) {
return false;
}
obj = {
dir : dir,
id : uuid.v4()
};
ipcRenderer.sendSync('proj', obj);
if (typeof callback !== 'undefined') {
obj.callback = callback;
}
proj.queue[obj.id] = obj;
proj.lock = true;
};
proj.move = function (callback) {
'use strict';
var obj;
if (proj.lock) {
return false;
}
obj = {
frame : true,
id : uuid.v4()
};
ipcRenderer.sendSync('proj', obj);
if (typeof callback !== 'undefined') {
obj.callback = callback;
}
proj.queue[obj.id] = obj;
proj.lock = true;
};
proj.end = function (c, id, ms) {
'use strict';
if (c === mcopy.cfg.arduino.cmd.proj_forward) {
mcopy.state.projector.direction = true;
} else if (c === mcopy.cfg.arduino.cmd.proj_backward) {
mcopy.state.projector.direction = false;
} else if (c === mcopy.cfg.arduino.cmd.projector) {
if (mcopy.state.projector.direction) {
mcopy.state.projector.pos += 1;
} else {
mcopy.state.projector.pos -= 1;
}
}
if (typeof proj.queue[id] !== 'undefined') {
if (typeof proj.queue[id].callback !== 'undefined') {
proj.queue[id].callback(ms);
}
delete proj.queue[id];
proj.lock = false;
}
};
proj.listen = function () {
'use strict';
ipcRenderer.on('proj', function (event, arg) {
proj.end(arg.cmd, arg.id, arg.ms);
return event.returnValue = true;
});
};
cam.queue = {}; cam.queue = {};
cam.lock = false; cam.lock = false;
cam.init = function () { cam.init = function () {