Commit 3a9e50d2 authored by Jake Read's avatar Jake Read
Browse files

fix bug where not asserting OG module name / id on load from file

parent 404c91f4
...@@ -15,6 +15,10 @@ This project serves the developement environment / api we use to write and repre ...@@ -15,6 +15,10 @@ This project serves the developement environment / api we use to write and repre
## For MW ## For MW
- change /src to /modules or /units ?
- bug is -num modules on load
- walk program units and change - walk program units and change
- rename inout to jsunit - rename inout to jsunit
- buttons get onClick evt - buttons get onClick evt
......
...@@ -5,23 +5,27 @@ const Reps = require('./reps.js') ...@@ -5,23 +5,27 @@ const Reps = require('./reps.js')
const JSUnit = require('./lib/jsunit.js') const JSUnit = require('./lib/jsunit.js')
let isStateKey = JSUnit.isStateKey let isStateKey = JSUnit.isStateKey
function loadModuleFromSource(program, path) { function loadModuleFromSource(program, path, id) {
// source -> heap // source -> heap
if (fs.existsSync(path)) { if (fs.existsSync(path)) {
var src = require(path) var src = require(path)
var mod = new src() var mod = new src()
// wants unique module id's // wants unique module id's
if(program.description.counter == null){ if (program.description.counter == null) {
program.description.counter = 0 program.description.counter = 0
} else { } else {
program.description.counter ++ program.description.counter++
} }
// make unique name // 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 mod.description.path = path
// add to program object // add to program object
program.modules[mod.description.id] = mod program.modules[mod.description.id] = mod
...@@ -72,7 +76,7 @@ function writeStateObject(mod, key) { ...@@ -72,7 +76,7 @@ function writeStateObject(mod, key) {
// when we change it within the module // when we change it within the module
// this.emitChange(key) // this.emitChange(key)
// push to external view // push to external view
if(socket){ if (socket) {
pushState(mod, key) pushState(mod, key)
} }
} }
...@@ -85,13 +89,13 @@ function writeStateObject(mod, key) { ...@@ -85,13 +89,13 @@ function writeStateObject(mod, key) {
}) })
} }
function removeModuleFromProgram(program, id){ function removeModuleFromProgram(program, id) {
// this simple? // this simple?
delete program.modules[id] delete program.modules[id]
for(key in program.modules){ for (key in program.modules) {
var mdl = program.modules[key] var mdl = program.modules[key]
for(otKey in mdl.outputs){ for (otKey in mdl.outputs) {
mdl.outputs[otKey].checkLinks(id) mdl.outputs[otKey].checkLinks(id)
} }
} }
...@@ -103,11 +107,11 @@ EXTERNAL HOOKS ...@@ -103,11 +107,11 @@ EXTERNAL HOOKS
*/ */
function assignSocket(sckt){ function assignSocket(sckt) {
socket = sckt socket = sckt
} }
function pushState(mod, key){ function pushState(mod, key) {
var data = { var data = {
id: mod.description.id, id: mod.description.id,
key: key, key: key,
...@@ -129,10 +133,10 @@ function saveProgram(prgmem, path) { ...@@ -129,10 +133,10 @@ function saveProgram(prgmem, path) {
var mdls = prgmem.modules var mdls = prgmem.modules
for(key in mdls){ for (key in mdls) {
var mdl = mdls[key] var mdl = mdls[key]
var og = Reps.makeFromModule(mdl) 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') fs.writeFileSync(path, JSON.stringify(svprgmem, null, 2), 'utf8')
...@@ -141,7 +145,7 @@ function saveProgram(prgmem, path) { ...@@ -141,7 +145,7 @@ function saveProgram(prgmem, path) {
} }
function openProgram(path){ function openProgram(path) {
var program = {} var program = {}
// get the .json file as an object // get the .json file as an object
...@@ -159,13 +163,13 @@ function openProgram(path){ ...@@ -159,13 +163,13 @@ function openProgram(path){
// gonna get those modules from source // gonna get those modules from source
program.modules = {} program.modules = {}
for(key in prgRep.modules){ for (key in prgRep.modules) {
var mdlRep = prgRep.modules[key] var mdlRep = prgRep.modules[key]
loadModuleFromSource(program, mdlRep.description.path) loadModuleFromSource(program, mdlRep.description.path, mdlRep.description.id)
} }
// restore saved state and links // restore saved state and links
for(modName in prgRep.modules){ for (modName in prgRep.modules) {
// keys should be identical for rep and heap // keys should be identical for rep and heap
// this is the representation that we're opening up from // this is the representation that we're opening up from
var mdlRep = prgRep.modules[modName] var mdlRep = prgRep.modules[modName]
...@@ -173,14 +177,20 @@ function openProgram(path){ ...@@ -173,14 +177,20 @@ function openProgram(path){
// this is the actual object, having functions and whatnot // this is the actual object, having functions and whatnot
var mdl = program.modules[modName] 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 // hooking outputs -> inputs
for(outName in mdlRep.outputs){ for (outName in mdlRep.outputs) {
var outRep = mdlRep.outputs[outName] var outRep = mdlRep.outputs[outName]
// each has some caller ids // each has some caller ids
for(nestedInputRep in outRep.calls){ for (nestedInputRep in outRep.calls) {
// conn from tl program -> this hookup // conn from tl program -> this hookup
var nIRParent = outRep.calls[nestedInputRep].parentId 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] var nI = program.modules[nIRParent].inputs[nIRKey]
console.log("ATTACHING", nIRKey, 'to', outName) console.log("ATTACHING", nIRKey, 'to', outName)
mdl.outputs[outName].attach(nI) mdl.outputs[outName].attach(nI)
...@@ -188,8 +198,8 @@ function openProgram(path){ ...@@ -188,8 +198,8 @@ function openProgram(path){
} }
// restoring state // restoring state
for(key in mdlRep.state){ for (key in mdlRep.state) {
if(isStateKey(key)){ if (isStateKey(key)) {
console.log("STATE - NEEDS WORK", key) console.log("STATE - NEEDS WORK", key)
// want to do this without asserting the change though // want to do this without asserting the change though
// actually, if new paradigm, we don't call .onChange // actually, if new paradigm, we don't call .onChange
...@@ -197,12 +207,14 @@ function openProgram(path){ ...@@ -197,12 +207,14 @@ function openProgram(path){
} }
} }
console.log('mdlRep', mdlRep)
console.log('mdl', mdl)
// restore position / UI state // restore position / UI state
if(mdlRep.description.position != null){ if (mdlRep.description.position != null) {
// ?? // ??
mdl.description.position = {} mdl.description.position = {}
mdl.description.position.left = mdlRep.description.position.left mdl.description.position.left = mdlRep.description.position.left
mdl.description.position.top = mdlRep.description.position.top mdl.description.position.top = mdlRep.description.position.top
} }
} }
......
...@@ -97,36 +97,6 @@ ...@@ -97,36 +97,6 @@
"message": "---" "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": { "delay-7": {
"description": { "description": {
"id": "delay-7", "id": "delay-7",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment