 
     @addAnimations([new CollectionAnimation(anims, -1)])
 
+  convertToCode: () ->
+    codes = {}
+    walkTree = (node, base = '') ->
+      if node.child0?
+        walkTree(node.child0, base+'0')
+      if node.child1?
+        walkTree(node.child1, base+'1')
+
+      if node.label? && node.label.length > 0
+        codes[node.label] = base
+    
+    walkTree(@nodes[0])
+
+    construct_queue.push((const: CodeListCollection, add_from: codes))
 
 class WeightedNodeCollection extends NodeCollection
   constructor: (shape) ->

    name: 'tidy',
    action: (c, t) ->
      console.log('tidy trees')
      if c.nodes.length == 1
        n = c.nodes[0]
        c.tidy(n, (x: n.x, y: n.y))
      else
        console.log('not attempting to tidy multiple trees')
  },
  {
    name: 'delete'


    @arrangeCodes(pos.x, pos.y)

  setNodes: (codes, pos) -> @addCodes(codes, pos)

  addCode: (symbol, code) ->
    oldval = @codes[symbol]
    newval = new CodeNode(symbol, code)
