Select Git revision
programs.js 9.34 KiB
const fs = require('fs')
const Reps = require('./reps.js')
const JSUnit = require('./lib/jsunit.js')
let isStateKey = JSUnit.isStateKey
function newProgram(name) {
var program = {
description: {
name: name,
id: name
},
modules: {}
}
return program
}
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) {
program.description.counter = 0
} else {
program.description.counter++
}
// make unique name, or recall from program save
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
/* ---------------------------------- */
// WARN! Corner Case should Go Away or Improve at next spiral
if (mod.description.isLink) {
for (mdlName in program.modules) {
if (program.modules[mdlName].description.isLink) {
console.log("PRGMEM ONLY BIG ENOUGH FOR ONE LINK")
//process.exit()
}
}
}
// end corner case code
/* ---------------------------------- */
// input need references for later hookup
for (key in mod.inputs) {
mod.inputs[key].parentId = mod.description.id
mod.inputs[key].key = key
}
// state updating, begs for update
for (key in mod.state) {
if (key == 'onChange' | key == 'emitChange' | key == 'emitters') {
//console.log('rolling past change fn')
} else {
mod.state['_' + key] = mod.state[key]
mod.state[key] = {}
writeStateObject(mod, key)