Skip to content
GitLab
Menu
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Jake Read
rndmc
Commits
3a9e50d2
Commit
3a9e50d2
authored
Nov 11, 2018
by
Jake Read
Browse files
fix bug where not asserting OG module name / id on load from file
parent
404c91f4
Changes
3
Hide whitespace changes
Inline
Side-by-side
README.md
View file @
3a9e50d2
...
...
@@ -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
...
...
programs.js
View file @
3a9e50d2
...
...
@@ -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
}
}
...
...
programs/dmz.json
View file @
3a9e50d2
...
...
@@ -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"
,
...
...
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment