Newer
Older
//
// Jake Read at the Center for Bits and Atoms
// (c) Massachusetts Institute of Technology 2018
//
// This work may be reproduced, modified, distributed, performed, and
// displayed for any purpose, but must acknowledge the mods
// project. Copyright is retained and must be preserved. The work is
// provided as is; no warranty is provided, and users accept all
// liability.
------------------------------------------------------
------------------------------------------------------
// nodes are objects having inputs, outputs, and state
// nodes can be made up of other nodes
// a node originates somewhere,
// is it a JSON, or a txt .js file ? loadProgram and loadModule ...
// it wants to be an object that gets 'read' in ...
const Reps = require('./reps.js')
const Programs = require('./programs.js')
const View = require('./views.js')
View.startHttp()
View.startWs()
*/
//console.log('modules at prgmem start', modules)
function putReps() {
// scrape for only things we'll want to represent
var rep = {
id: mod.id,
inputs: mod.inputs,
outputs: mod.outputs,
state: {}
}
// holds UI information - to load mods at location
for (var key in mod.state) {
if (isStateKey(key)) {
return rep
}
function putRep(mod) {
socketSend('add rep', makeRep(mod))
}
socketSend('change rep', makeRep(mod))
}
// update state from UI to server
function changeState(data) {
// of one module
// should just recv all state, walk tree for differences
var oldState = modules[data.id].state
var newState = data.state
// rep only holds proper key-values w/o emitters, _values etc
if (oldState[key].isButton) {
if (oldState[key].isPressed != newState[key].isPressed) {
console.log('CHANGE BUTTON STATE', key, 'to', newState[key], 'in', data.id)
// this will trigger some 'onChange' f'ns
// that might change some state
// to prevent quickly changing it back, we'll exit now (one state change from UI per trx)
} else if (oldState[key].isMultiLine) {
if (oldState[key].value != newState[key].value) {
console.log('CHANGE MULTILINE STATE', key, 'to', newState[key].value, 'in', data.id)
oldState[key].value = newState[key].value
return true
console.log('CHANGE STATE', key, 'to', newState[key], 'in', data.id)
oldState[key] = newState[key]
return true
console.log("NO UI")
mod.ui = {}
}
mod.ui = data.ui
console.log('CHANGE UI', mod.id, mod.ui)
}
function setUiPos(module, left, top) {
if (module.ui == null) {
module.ui = {}
}
module.ui.left = left
module.ui.top = top
}
// push new state from server to UI
function putState(mod) {
// push just the state to the individual mod
for (var key in mod.state) {
if (isStateKey(key)) {
socketSend('change state', data)
function putLink(data) {
var fromModule = modules.find((module) => {
return module.id === data.from.id
})
var toModule = modules.find((module) => {
return module.id === data.to.id
})
if (fromModule.outputs[data.from.output].isLinked(toModule.inputs[data.to.input])) {
console.log("HOOKDOWN")
fromModule.outputs[data.from.output].remove(toModule.inputs[data.to.input])
fromModule.outputs[data.from.output].attach(toModule.inputs[data.to.input])
// replace it
changeRep(fromModule)
tree[dir[i]] = {}
var subdir = fs.readdirSync('./src/' + dir[i])
var obj = {}
obj.path = './src/' + dir[i] + '/' + subdir[j]
tree[dir[i]][subdir[j].slice(0, -3)] = obj
}
}
}