parseNodeBegin method

dynamic parseNodeBegin(
  1. dynamic line,
  2. dynamic property
)

Implementation

parseNodeBegin(line, property) {
  var nodeName = property[1].trim().replaceFirst(RegExp(r'^"'), '').replace(RegExp(r'"$'), '');

  var nodeAttrs = property[2].split(',').map((attr) {
    return attr.trim().replaceFirst(RegExp(r'^"'), '').replace(RegExp(r'"$'), '');
  }).toList();

  Map<String, dynamic> node = {"name": nodeName};
  var attrs = parseNodeAttr(nodeAttrs);

  Map currentNode = getCurrentNode();

  // a top node
  if (currentIndent == 0) {
    allNodes.add(nodeName, node);
  } else {
    // a subnode

    // if the subnode already exists, append it
    if (currentNode.keys.contains(nodeName)) {
      // special case Pose needs PoseNodes as an array
      if (nodeName == 'PoseNode') {
        currentNode["PoseNode"].add(node);
      } else if (currentNode[nodeName].id != null) {
        currentNode[nodeName] = {};
        currentNode[nodeName][currentNode[nodeName].id] = currentNode[nodeName];
      }

      if (attrs.id != '') currentNode[nodeName][attrs.id] = node;
    } else if (attrs.id is num) {
      currentNode[nodeName] = {};
      currentNode[nodeName][attrs.id] = node;
    } else if (nodeName != 'Properties70') {
      if (nodeName == 'PoseNode') {
        currentNode[nodeName] = [node];
      } else {
        currentNode[nodeName] = node;
      }
    }
  }

  if (attrs.id is num) node["id"] = attrs.id;
  if (attrs.name != '') node["attrName"] = attrs.name;
  if (attrs.type != '') node["attrType"] = attrs.type;

  pushStack(node);
}