From a15d5829379864c7138edff621d6864c5f426d0b Mon Sep 17 00:00:00 2001 From: Thomas Geymayer Date: Sat, 13 Oct 2012 15:20:27 +0200 Subject: [PATCH] Use newly exposed props.Node.addChild method --- Nasal/canvas/PropertyElement.nas | 2 +- Nasal/canvas/api.nas | 28 ++++------------------------ Nasal/props.nas | 1 + 3 files changed, 6 insertions(+), 25 deletions(-) diff --git a/Nasal/canvas/PropertyElement.nas b/Nasal/canvas/PropertyElement.nas index 3b8f2c2b3..edca7ba56 100644 --- a/Nasal/canvas/PropertyElement.nas +++ b/Nasal/canvas/PropertyElement.nas @@ -11,7 +11,7 @@ var PropertyElement = { new: func(node, id) { if( typeof(node) == 'vector' ) - var node = _createNodeWithIndex(node[0], node[1]); + var node = aircraft.makeNode(node[0]).addChild(node[1], 0, 0); else var node = aircraft.makeNode(node); diff --git a/Nasal/canvas/api.nas b/Nasal/canvas/api.nas index 4d3ef046e..2c864a850 100644 --- a/Nasal/canvas/api.nas +++ b/Nasal/canvas/api.nas @@ -1,23 +1,3 @@ -# Helper function to create a node with the first available index for the given -# path relative to the given node -# -var _createNodeWithIndex = func(node, path, min_index = 0) -{ - var node = aircraft.makeNode(node); - - # TODO do we need an upper limit? (50000 seems already seems unreachable) - for(var i = min_index; i < 50000; i += 1) - { - var p = path ~ "[" ~ i ~ "]"; - if( node.getNode(p) == nil ) - return node.getNode(p, 1); - } - - debug.warn("Unable to get child (already 50000 exist)"); - - return nil; -}; - # Internal helper var _createColorNodes = func(parent, name) { @@ -237,8 +217,8 @@ var Element = { # @param vals Default values (Vector of 6 elements) createTransform: func(vals = nil) { - var node = _createNodeWithIndex(me._node, "tf", 1); # tf[0] is reserved for - # setRotation + var node = me._node.addChild("tf", 1); # tf[0] is reserved for + # setRotation return Transform.new(node, vals); }, # Shortcut for setting translation @@ -767,7 +747,7 @@ var Canvas = { # given every texture of the model will be replaced. addPlacement: func(vals) { - var placement = _createNodeWithIndex(me.texture, "placement"); + var placement = me.texture.addChild("placement", 0, 0); placement.setValues(vals); return placement; }, @@ -801,7 +781,7 @@ var new = func(vals) { var m = { parents: [Canvas] }; - m.texture = _createNodeWithIndex(Canvas.property_root, "texture"); + m.texture = Canvas.property_root.addChild("texture", 0, 0); m.color = _createColorNodes(m.texture, "color-background"); m.texture.setValues(vals); diff --git a/Nasal/props.nas b/Nasal/props.nas index d5cedc880..5c8aea147 100644 --- a/Nasal/props.nas +++ b/Nasal/props.nas @@ -14,6 +14,7 @@ var Node = { getParent : func wrap(_getParent(me._g, arg)), getChild : func wrap(_getChild(me._g, arg)), getChildren : func wrap(_getChildren(me._g, arg)), + addChild : func wrap(_addChild(me._g, arg)), removeChild : func wrap(_removeChild(me._g, arg)), removeChildren : func wrap(_removeChildren(me._g, arg)), getAliasTarget : func wrap(_getAliasTarget(me._g, arg)),