session: unwrap root widget; parser: don't parse arrays

This commit is contained in:
bordun 2018-10-31 11:51:07 +01:00
parent 6ae3ce7f10
commit 7ff0c8a0ce
5 changed files with 51 additions and 59 deletions

View file

@ -818,7 +818,7 @@ var Editor = class Editor {
updateWidgetFromPatch(patch, indexes) {
var [widget, subpatch] = diffToWidget(widgetManager.getWidgetById('root')[0], patch[0]),
var [widget, subpatch] = diffToWidget(widgetManager.getWidgetById('root')[0], patch),
options = {}
if (indexes) {

View file

@ -40,11 +40,9 @@ var SessionManager = class SessionManager {
try {
if (session[0].type != 'root') {
this.session = [{type:'root', tabs:session}]
} else if (session[0].type == 'root'){
this.session = session
}
if (Array.isArray(session)) session = session[0]
if (session.type !== 'root') throw ''
this.session = session
} catch(err) {
@ -180,7 +178,7 @@ var SessionManager = class SessionManager {
}
create() {
this.load([{}],function(){
this.load({type: 'root'},function(){
require('../ui/sidepanel').open()
editor.enable()
editor.select(widgetManager.getWidgetById('root'))

View file

@ -36,74 +36,68 @@ var Parser = class Parser {
index
} = options
if (!Array.isArray(data)) data = [data]
var props = data
for (let i in data) {
// Set default widget type
props.type = tab ? 'tab' : props.type || 'fader'
var props = data[i]
// Safe copy widget's options
let defaults = this.widgets[props.type].defaults()._props()
// Set default widget type
props.type = tab ? 'tab' : props.type || 'fader'
// Set widget's undefined options to default
for (let i in defaults) {
if (i.indexOf('_')!=0 && props[i]===undefined) props[i] = defaults[i]
}
// Safe copy widget's options
let defaults = this.widgets[props.type].defaults()._props()
// Set widget's undefined options to default
for (let i in defaults) {
if (i.indexOf('_')!=0 && props[i]===undefined) props[i] = defaults[i]
// Genrate widget's id, based on its type
if (props.id=='auto' || !props.id ) {
var id
while (!id || widgetManager.getWidgetById(id).length) {
id=props.type+'_'+this.getIterator(props.type)
}
props.id = id
}
// Genrate widget's id, based on its type
if (props.id=='auto' || !props.id ) {
var id
while (!id || widgetManager.getWidgetById(id).length) {
id=props.type+'_'+this.getIterator(props.type)
}
props.id = id
}
// Generate default address
props.address = props.address == 'auto' ? '/' + props.id : props.address
// Generate default address
props.address = props.address == 'auto' ? '/' + props.id : props.address
for (let j in props) {
if (defaults[j] === undefined || j[0] === '_') delete props[j]
}
for (let j in props) {
if (defaults[j] === undefined || j[0] === '_') delete props[j]
}
// create widget
var widget = new this.widgets[props.type]({
container:true,
props,
parent,
parentNode,
reCreateOptions,
children
})
// create widget
var widget = new this.widgets[props.type]({
container:true,
props,
parent,
parentNode,
reCreateOptions,
children
})
widgetManager.addWidget(widget)
widgetManager.addWidget(widget)
widget.created(index)
widget.created(index)
// set widget's initial state
var defaultValue = widget.getProp('default'),
currentValue = widget.getProp('value')
// set widget's initial state
var defaultValue = widget.getProp('default'),
currentValue = widget.getProp('value')
if (currentValue !== '' && currentValue !== undefined) {
if (currentValue !== '' && currentValue !== undefined) {
stateManager.pushValueNewProp(widget.getProp('id'), currentValue)
stateManager.pushValueNewProp(widget.getProp('id'), currentValue)
} else if (defaultValue !== '' && defaultValue !== undefined) {
} else if (defaultValue !== '' && defaultValue !== undefined) {
widget.setValue(defaultValue)
}
parentNode.appendChild(widget.container)
widget.setValue(defaultValue)
}
parentNode.appendChild(widget.container)
// Editor needs to get the container object
if (data && data.length==1) return widget
return widget
}

View file

@ -15,7 +15,7 @@ class Root extends Panel {
traversing: {type: 'boolean', value: false, help: 'Set to `true` to enable traversing gestures in this widget. Set to `smart` or `auto` to limit affected widgets by the type of the first touched widget'},
variables: {type: '*', value: {}, help: 'Defines one or more arbitrary variables that can be inherited by children widgets'},
tabs: {type: 'array', value: [], help: 'Each element of the array must be a tab object'},
tabs: {type: 'array', value: [{}], help: 'Each element of the array must be a tab object'},
id: {type: 'string', value: 'root', help: 'Widgets sharing the same id will act as clones and update each other\'s value(s) without sending extra osc messages' },
value: {type: 'integer', value: '', help: [

View file

@ -3,14 +3,14 @@ var fs = require('fs')
// create tmp session file
var session = [{tabs:[{widgets:[]}]}],
var session = {type: 'root', tabs:[{widgets:[]}]},
sessionPath = 'test-session.json'
require('../scripts/client-shim')
var {widgets} = require('../src/client/app/widgets')
for (let type in widgets) {
session[0].tabs[0].widgets.push({type: type})
session.tabs[0].widgets.push({type: type})
}
fs.writeFileSync(sessionPath, JSON.stringify(session))