Changeset - 3ffadb9f00cd
[Not reviewed]
default
0 1 0
drewp@bigasterisk.com - 7 years ago 2018-06-08 05:52:52
drewp@bigasterisk.com
forgot a 2018
Ignore-this: b1dbaaf9ac317601ec0e9006907204a1
1 file changed with 1 insertions and 1 deletions:
0 comments (0 inline, 0 general)
light9/web/live/live.coffee
Show inline comments
 
@@ -116,97 +116,97 @@ coffeeElementSetup(class Light9LiveDevic
 
  attrRow: (devAttr) ->
 
    U = (x) => @graph.Uri(x)
 
    dataType = @graph.uriValue(devAttr, U(':dataType'))
 
    daRow = {
 
      uri: devAttr
 
      dataType: dataType
 
      showColorPicker: dataType.equals(U(':color'))
 
      }
 
    if dataType.equals(U(':color'))
 
      daRow.useColor = true
 
    else if dataType.equals(U(':choice'))
 
      daRow.useChoice = true
 
      choiceUris = @graph.sortedUris(@graph.objects(devAttr, U(':choice')))
 
      daRow.choices = ({uri: x, label: @graph.labelOrTail(x)} for x in choiceUris)
 
      daRow.choiceSize = Math.min(choiceUris.length + 1, 10)
 
    else
 
      daRow.useSlider = true
 
      daRow.max = 1
 
      if dataType.equals(U(':angle'))
 
        # varies
 
        daRow.max = 1
 
    return daRow
 
      
 
  clear: ->
 
    for lc in @shadowRoot.querySelectorAll("light9-live-control")
 
      lc.clear()
 
    
 
)
 

	
 
class GraphToControls
 
  # More efficient bridge between liveControl widgets and graph edits,
 
  # as opposed to letting each widget scan the graph and push lots of
 
  # tiny patches to it.
 
  constructor: (@graph) ->
 

	
 
    # Registered graphValueChanged funcs, by dev+attr
 
    @onChanged = {}
 

	
 
    # The settings we're showing (or would like to but the widget
 
    # isn't registered yet):
 
    # dev+attr : {setting: Uri, onChangeFunc: f, jsValue: str_or_float}
 
    @settings = new Map()
 

	
 
    @effect = null
 

	
 
  ctxForEffect: (effect) ->
 
    @graph.Uri(effect.value.replace(
 
      "light9.bigasterisk.com/effect",
 
      "light9.bigasterisk.com/show/dance2017/effect"))
 
      "light9.bigasterisk.com/show/dance2018/effect"))
 
      
 
  setEffect: (effect) ->
 
    @clearSettings()
 
    @effect = effect
 
    @ctx = @ctxForEffect(@effect)
 
    # are these going to pile up? consider @graph.triggerHandler('GTC sync')
 
    @graph.runHandler(@syncFromGraph.bind(@), 'GraphToControls sync')
 

	
 
  newEffect: ->
 
    # wrong- this should be our editor's scratch effect, promoted to a
 
    # real one when you name it.
 
    U = (x) => @graph.Uri(x)
 
    effect = @graph.nextNumberedResource(U('http://light9.bigasterisk.com/effect/effect'))
 
    ctx = @ctxForEffect(effect)
 
    quad = (s, p, o) => @graph.Quad(s, p, o, ctx)
 

	
 
    addQuads = [
 
      quad(effect, U('rdf:type'), U(':Effect'))
 
      quad(effect, U('rdfs:label'), @graph.Literal(effect.value.replace(/.*\//, "")))
 
      quad(effect, U(':publishAttr'), U(':strength'))
 
    ]
 
    patch = {addQuads: addQuads, delQuads: []}
 
    log('init new effect', patch)
 
    @graph.applyAndSendPatch(patch)
 
    return effect
 

	
 
  addSettingsRow: (device, deviceAttr, setting, value) ->
 
    key = device.value + " " + deviceAttr.value
 
    @settings.set(key, {
 
      setting: setting,
 
      onChangeFunc: @onChanged[key],
 
      jsValue: value
 
    })
 
                                                                              
 
  syncFromGraph: ->
 
    U = (x) => @graph.Uri(x)
 
    return if not @effect
 
    
 
    toClear = new Map(@settings)
 
    
 
    for setting in @graph.objects(@effect, U(':setting'))
 
      dev = @graph.uriValue(setting, U(':device'))
 
      devAttr = @graph.uriValue(setting, U(':deviceAttr'))
 
      key = dev.value + " " + devAttr.value
 

	
 
      pred = valuePred(@graph, devAttr)
 
      try
 
        value = @graph.floatValue(setting, pred)
0 comments (0 inline, 0 general)