Commit a6d9e8ab authored by Jake Read's avatar Jake Read

nearly hooking up again

parent 9572e704
......@@ -15,9 +15,34 @@ This project serves the developement environment / api we use to write and repre
## For MW
- GIFS
- load a program
- drag around
- zoom in and out
- add a module
- hook events up
- rm events
- rm modules
- change settings
- *don't forget*
- onload, load state...
- when hooking back to server, server.emitChange(key) ... from writeStateObject
- does state copy over successfully from loaded mod?
- this spiral
- entire programs read into UI
- hook sever-and-back
- for event hookup
- for module add
- for state push-down
- re-hook state push-down
- can req and add to program new modules
- can req to load new program
- can req to save this program
- next spiral
- programs come in chunk-wise and get placed
- programs are modules are heirarchical
- fundament
- the basic unit is a .js file having inputs, outputs, and state objects
......
This diff is collapsed.
......@@ -2,68 +2,56 @@
function writeStateRep(container, rep, key) {
var variable = rep.state[key]
if (variable.isButton) {
console.log('BUTTON!')
var li = document.createElement('li')
li.appendChild(document.createTextNode(variable.label))
li.addEventListener('click', function() {
// invert
if (rep.state[key].isPressed) {
rep.state[key].isPressed = false
} else {
rep.state[key].isPressed = true
}
putState(rep)
})
container.appendChild(li)
return li
} else if (variable.isMultiLine) {
console.log('MULTILINE!')
var li = document.createElement('li')
li.appendChild(document.createTextNode(variable.label))
li.appendChild(document.createElement('br'))
var txtArea = document.createElement('textarea')
txtArea.rows = variable.rows
txtArea.cols = 27
txtArea.value = variable.value
txtArea.addEventListener('change', function(){
rep.state[key].value = txtArea.value
putState(rep)
})
li.appendChild(txtArea)
container.appendChild(li)
return txtArea
} else {
if (typeof variable == 'string') {
switch (variable.type) {
case 'button':
console.log('BUTTON!')
var li = document.createElement('li')
li.appendChild(document.createTextNode(key))
var input = document.createElement('input')
input.type = 'text'
input.size = 24
input.value = variable
input.addEventListener('change', function() {
rep.state[key] = input.value
li.appendChild(document.createTextNode(variable.label))
li.addEventListener('click', function() {
// invert
if (rep.state[key].isPressed) {
rep.state[key].isPressed = false
} else {
rep.state[key].isPressed = true
}
putState(rep)
})
li.appendChild(input)
container.appendChild(li)
return input
} else if (typeof variable == 'number') {
return li
break
case 'multiline':
console.log('MULTILINE!')
var li = document.createElement('li')
li.appendChild(document.createTextNode(key))
var input = document.createElement('input')
input.type = 'text'
input.size = 24
input.value = variable.toString()
input.addEventListener('change', function() {
rep.state[key] = parseFloat(input.value)
li.appendChild(document.createTextNode(variable.label))
li.appendChild(document.createElement('br'))
var txtArea = document.createElement('textarea')
txtArea.rows = variable.rows
txtArea.cols = 27
txtArea.value = variable.value
txtArea.addEventListener('change', function() {
rep.state[key].value = txtArea.value
putState(rep)
})
li.appendChild(input)
li.appendChild(txtArea)
container.appendChild(li)
return input
} else if (typeof variable == 'object') {
if (Array.isArray(variable)) {
return txtArea
break
default:
if (typeof variable == 'string') {
var li = document.createElement('li')
li.appendChild(document.createTextNode(key))
var input = document.createElement('input')
input.type = 'text'
input.size = 24
input.value = variable
input.addEventListener('change', function() {
rep.state[key] = input.value
putState(rep)
})
li.appendChild(input)
container.appendChild(li)
return input
} else if (typeof variable == 'number') {
var li = document.createElement('li')
li.appendChild(document.createTextNode(key))
var input = document.createElement('input')
......@@ -71,20 +59,36 @@ function writeStateRep(container, rep, key) {
input.size = 24
input.value = variable.toString()
input.addEventListener('change', function() {
var arr = input.value.split(',')
arr.forEach(function(element, index, array) {
array[index] = parseFloat(element)
})
rep.state[key] = arr
rep.state[key] = parseFloat(input.value)
putState(rep)
})
li.appendChild(input)
container.appendChild(li)
return input
} else if (typeof variable == 'object') {
if (Array.isArray(variable)) {
var li = document.createElement('li')
li.appendChild(document.createTextNode(key))
var input = document.createElement('input')
input.type = 'text'
input.size = 24
input.value = variable.toString()
input.addEventListener('change', function() {
var arr = input.value.split(',')
arr.forEach(function(element, index, array) {
array[index] = parseFloat(element)
})
rep.state[key] = arr
putState(rep)
})
li.appendChild(input)
container.appendChild(li)
return input
}
} else {
console.log("unui'd type:", typeof variable)
}
} else {
console.log("unui'd type:", typeof variable)
}
break
}
}
......@@ -123,7 +127,6 @@ function newBezier(x1, y1, x2, y2) {
return bz
}
function redrawBezier(bz) {
var bl = Math.sqrt(Math.pow((bz.x1 - bz.x2), 2) + Math.pow((bz.y1 - bz.y2), 2)) * 0.6
var ps = 'M ' + bz.x1 + ' ' + bz.y1 + ' C ' + (bz.x1 + bl) + ' ' + bz.y1
......
//
//
// new node controller
// new node controller / HEAP
//
// main.js
//
......@@ -18,27 +18,11 @@
RULES:
*/
/*
SERVER
modules are objects having inputs, outputs, and state
programs are assemblies of modules
*/
/*
------------------------------------------------------
PROGRAM AS API
------------------------------------------------------
*/
// 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')
......@@ -59,46 +43,7 @@ PROGRAM REPRESENT
*/
//console.log('modules at prgmem start', modules)
function putReps() {
var reps = new Array()
for (mod in modules) {
reps.push(makeRep(modules[mod]))
}
socketSend('add reps', reps)
}
function makeRep(mod) {
// scrape for only things we'll want to represent
var rep = {
id: mod.id,
desc: mod.description,
inputs: mod.inputs,
outputs: mod.outputs,
state: {}
}
// holds UI information - to load mods at location
if (mod.ui != null) {
rep.ui = mod.ui
}
for (var key in mod.state) {
if (isStateKey(key)) {
rep.state[key] = mod.state[key]
}
}
return rep
}
function putRep(mod) {
socketSend('add rep', makeRep(mod))
}
function changeRep(mod) {
socketSend('change rep', makeRep(mod))
}
/*
// update state from UI to server
function changeState(data) {
......@@ -188,23 +133,6 @@ function putLink(data) {
changeRep(fromModule)
}
function buildMenu() {
var tree = {}
var dir = fs.readdirSync('./src')
for (i in dir) {
tree[dir[i]] = {}
var subdir = fs.readdirSync('./src/' + dir[i])
for (j in subdir) {
// find js files
if (subdir[j].slice(-3) === '.js') {
var obj = {}
obj.path = './src/' + dir[i] + '/' + subdir[j]
tree[dir[i]][subdir[j].slice(0, -3)] = obj
}
}
}
return tree
}
*/
// put
\ No newline at end of file
const JSUnit = require('./lib/jsunit.js')
let isStateKey = JSUnit.isStateKey
function makeRepFromModule(mdl) {
var rep = {
description: {
......
......@@ -23,10 +23,6 @@
{
"parentId": "delay-2",
"key": "thru"
},
{
"parentId": "logger-3",
"key": "thru"
}
]
}
......
......@@ -8,13 +8,15 @@ const http = require('http').Server(app)
// websocket, to share program representations with the client (and back)
const WebSocket = require('ws')
const Reps = require('./reps.js')
/*
SERVER AND WS SETUP
SERVER AND WS SETUP --------------------------------------------------
*/
var program = null
var program = null
var sckt = null
function startHttp() {
......@@ -45,7 +47,6 @@ function startWs() {
// say hello
socketSend('console', 'hello client')
// send current config as list of all modules
uiInit()
console.log('socket open on 8081')
ws.on('message', (evt) => {
socketRecv(evt)
......@@ -53,6 +54,22 @@ function startWs() {
})
}
/*
HOOKUP REF TO TL ------------------------------------------------------
*/
function assignProgram(prgm) {
program = prgm
}
/*
RECV / SEND PORTALS ---------------------------------------------------
*/
function socketRecv(evt) {
var recv = JSON.parse(evt)
var type = recv.type
......@@ -63,25 +80,27 @@ function socketRecv(evt) {
case 'console':
console.log('RECV CONSOLE:', data)
break
case 'get menu':
var tree = buildMenu()
socketSend('put menu', tree)
case 'get current program':
uiRequestCurrentProgram()
break
case 'get module menu':
uiRequestModuleMenu()
break
case 'load program':
uiRequestLoadProgram()
break
case 'add module':
addModule(data)
case 'put module':
uiRequestNewModule(data)
break
case 'put state':
changeState(data)
uiRequestStateChange(data)
break
case 'put link':
putLink(data)
uiRequestLinkChange(data)
// id:output > id:input
break
case 'put ui':
changeUi(data)
break
case 'rm link':
// id:output > id:input
uiRequestUiChange(data)
break
default:
console.log('ERR server recv with non recognized type', recv)
......@@ -100,18 +119,84 @@ function socketSend(type, data) {
}
}
function assignProgram(prgm){
program = prgm
}
/*
HEAP -> UI HANDLES ---------------------------------------------------
*/
// runs when browser first loads
function uiInit(){
function uiRequestCurrentProgram() {
// make reps from program and send the list
console.log("BRWSER LOADED")
console.log(program)
console.log('SEND PROGRAMS TO UI')
var prgRep = {
description: {
name: program.description.name,
id: program.description.id,
path: program.description.path
},
modules: {}
}
for (mdlName in program.modules) {
var mdlRep = Reps.makeFromModule(program.modules[mdlName])
prgRep.modules[mdlName] = mdlRep
}
socketSend('put program', prgRep)
}
function uiRequestModuleMenu() {
var availableSourceRep = {}
var dir = fs.readdirSync('./src')
for (i in dir) {
availableSourceRep[dir[i]] = {}
var subdir = fs.readdirSync('./src/' + dir[i])
for (j in subdir) {
// find js files
if (subdir[j].slice(-3) === '.js') {
var obj = {}
obj.path = './src/' + dir[i] + '/' + subdir[j]
availableSourceRep[dir[i]][subdir[j].slice(0, -3)] = obj
}
}
}
socketSend('put module menu', availableSourceRep)
}
/*
UI -> HEAP HANDLES ---------------------------------------------------
*/
function uiRequestLoadProgram(data){
console.log('UI REQUEST TO OPEN NEW PROGRAM', data)
}
function uiRequestNewModule(data) {
console.log('UI REQUEST ADD MODULE TO PROGRAM', data)
}
function uiRequestStateChange(data) {
console.log('UI REQUEST CHANGE STATE IN MODULE', data)
// do state.obj.emit
}
function uiRequestLinkChange(data) {
console.log('UI REQUEST ADD EVENT LINK', data)
}
function uiRequestUiChange(data) {
console.log('UI REQUEST ADD / CHANGE UI INFO TO MODULE', data)
// do it in module.description
}
/*
EXPORTS --------------------------------------------------------------
*/
module.exports = {
startHttp: startHttp,
......
Markdown is supported
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