diff --git a/README.md b/README.md index 1ec3780cb8f0cdd0847924ade101b2363026bc80..cb88e27a2ab4e85e2789051305f57966fac0d020 100644 --- a/README.md +++ b/README.md @@ -15,6 +15,10 @@ This project serves the developement environment / api we use to write and repre ## For MW + + - change /src to /modules or /units ? + - bug is -num modules on load + - walk program units and change - rename inout to jsunit - buttons get onClick evt diff --git a/programs.js b/programs.js index 072d432c88d12d2c5bdbf7719e2fe024bdcd483b..9221b386037f741a39f214c966c88cffe0866a7a 100644 --- a/programs.js +++ b/programs.js @@ -5,23 +5,27 @@ const Reps = require('./reps.js') const JSUnit = require('./lib/jsunit.js') let isStateKey = JSUnit.isStateKey -function loadModuleFromSource(program, path) { +function loadModuleFromSource(program, path, id) { // source -> heap if (fs.existsSync(path)) { var src = require(path) var mod = new src() // wants unique module id's - if(program.description.counter == null){ + if (program.description.counter == null) { program.description.counter = 0 } else { - program.description.counter ++ + program.description.counter++ } // make unique name - mod.description.id = mod.description.name + '-' + program.description.counter + if (id) { + mod.description.id = id + } else { + mod.description.id = mod.description.name + '-' + program.description.counter + } mod.description.path = path - + // add to program object program.modules[mod.description.id] = mod @@ -72,7 +76,7 @@ function writeStateObject(mod, key) { // when we change it within the module // this.emitChange(key) // push to external view - if(socket){ + if (socket) { pushState(mod, key) } } @@ -85,13 +89,13 @@ function writeStateObject(mod, key) { }) } -function removeModuleFromProgram(program, id){ +function removeModuleFromProgram(program, id) { // this simple? delete program.modules[id] - for(key in program.modules){ + for (key in program.modules) { var mdl = program.modules[key] - for(otKey in mdl.outputs){ + for (otKey in mdl.outputs) { mdl.outputs[otKey].checkLinks(id) } } @@ -103,11 +107,11 @@ EXTERNAL HOOKS */ -function assignSocket(sckt){ - socket = sckt +function assignSocket(sckt) { + socket = sckt } -function pushState(mod, key){ +function pushState(mod, key) { var data = { id: mod.description.id, key: key, @@ -129,10 +133,10 @@ function saveProgram(prgmem, path) { var mdls = prgmem.modules - for(key in mdls){ + for (key in mdls) { var mdl = mdls[key] var og = Reps.makeFromModule(mdl) - svprgmem.modules[mdl.description.id] = og + svprgmem.modules[mdl.description.id] = og } fs.writeFileSync(path, JSON.stringify(svprgmem, null, 2), 'utf8') @@ -141,7 +145,7 @@ function saveProgram(prgmem, path) { } -function openProgram(path){ +function openProgram(path) { var program = {} // get the .json file as an object @@ -159,13 +163,13 @@ function openProgram(path){ // gonna get those modules from source program.modules = {} - for(key in prgRep.modules){ + for (key in prgRep.modules) { var mdlRep = prgRep.modules[key] - loadModuleFromSource(program, mdlRep.description.path) + loadModuleFromSource(program, mdlRep.description.path, mdlRep.description.id) } // restore saved state and links - for(modName in prgRep.modules){ + for (modName in prgRep.modules) { // keys should be identical for rep and heap // this is the representation that we're opening up from var mdlRep = prgRep.modules[modName] @@ -173,14 +177,20 @@ function openProgram(path){ // this is the actual object, having functions and whatnot var mdl = program.modules[modName] + if (mdl == null) { + console.log('NULL') + console.log('prgRep modules', prgRep.modules) + console.log('program modules', program.modules) + } + // hooking outputs -> inputs - for(outName in mdlRep.outputs){ + for (outName in mdlRep.outputs) { var outRep = mdlRep.outputs[outName] // each has some caller ids - for(nestedInputRep in outRep.calls){ + for (nestedInputRep in outRep.calls) { // conn from tl program -> this hookup var nIRParent = outRep.calls[nestedInputRep].parentId - var nIRKey = outRep.calls[nestedInputRep].key + var nIRKey = outRep.calls[nestedInputRep].key var nI = program.modules[nIRParent].inputs[nIRKey] console.log("ATTACHING", nIRKey, 'to', outName) mdl.outputs[outName].attach(nI) @@ -188,8 +198,8 @@ function openProgram(path){ } // restoring state - for(key in mdlRep.state){ - if(isStateKey(key)){ + for (key in mdlRep.state) { + if (isStateKey(key)) { console.log("STATE - NEEDS WORK", key) // want to do this without asserting the change though // actually, if new paradigm, we don't call .onChange @@ -197,12 +207,14 @@ function openProgram(path){ } } + console.log('mdlRep', mdlRep) + console.log('mdl', mdl) // restore position / UI state - if(mdlRep.description.position != null){ + if (mdlRep.description.position != null) { // ?? mdl.description.position = {} mdl.description.position.left = mdlRep.description.position.left - mdl.description.position.top = mdlRep.description.position.top + mdl.description.position.top = mdlRep.description.position.top } } diff --git a/programs/dmz.json b/programs/dmz.json index f71cd7cdbe4e5e903fba0967ae786d3b1af8962b..3a9b328c88c8887b7408f6509e56f14920803adb 100644 --- a/programs/dmz.json +++ b/programs/dmz.json @@ -97,36 +97,6 @@ "message": "---" } }, - "Breadboard Servo Signal Generator-6": { - "description": { - "id": "Breadboard Servo Signal Generator-6", - "name": "Breadboard Servo Signal Generator", - "alt": "servo", - "path": "./src/hardware/servo.js", - "position": { - "left": 583, - "top": 632 - } - }, - "inputs": { - "packet": { - "accepts": "headless packet" - } - }, - "outputs": { - "packet": { - "emits": "number", - "calls": [] - } - }, - "state": { - "button": { - "type": "button", - "label": "SEND" - }, - "servoVal": 0 - } - }, "delay-7": { "description": { "id": "delay-7",