private void LoadAttachedParts(ConfigNode node) { if (node == null) { return; } for (int i = 0; i < node.CountNodes; i++) { AttachedPartInfo attachedPartInfo = new AttachedPartInfo(this, null); attachedPartInfos.Add(attachedPartInfo); attachedPartInfo.Load(i, node); } }
private void UpdateAttachments(List <AttachedPartInfo> attachedPartInfos, bool debugPeriodic) { // Bail out if init failed if (attachedPartInfos == null) { if (debugPeriodic) { print("Empty attach node info list!"); } return; } if (debugPeriodic) { printf("Updating %s/%s parts", attachedPartInfos.Count, part.children.Count); } foreach (AttachNode attachNode in part.attachNodes) { // We can't move attach nodes that are positioned in the cfg file if (attachNode.nodeTransform == null) { if (debugPeriodic) { printf("Skipping %s since it lacks a node transform", attachNode.id); } continue; } // Get the position and rotation of the node transform relative to the part. // The nodeTransform itself will only contain its positions and rotation // relative to the immediate parent in the model PosRot attachNodePosRot = PosRot.GetPosRot(attachNode.nodeTransform, part); // We can't animate decoupling shrouds if (attachNodePosRot == null) { if (debugPeriodic) { printf("Skipping %s since it is a decoupler shroud", attachNode.id); } continue; } // Update the attachNode attachNode.position = attachNodePosRot.position; attachNode.orientation = attachNodePosRot.orientation; } for (int i = 0; i < part.children.Count; i++) { Part child = part.children[i]; // Create new entries in the list if needed if (i >= attachedPartInfos.Count) { if (debug) { printf("Adding child %s [%s]", child.name, i); } attachedPartInfos.Add(new AttachedPartInfo(this, child)); } AttachedPartInfo attachedPartInfo = attachedPartInfos[i]; // Assign parts to info structs newly loaded from a save file if (attachedPartInfo.loaded) { attachedPartInfo.attachedPart = child; attachedPartInfo.loaded = false; if (debug) { printf("Assigning child %s [%s]", attachedPartInfo.attachedPart, i); } } else // Remove stale entries if (attachedPartInfo.attachedPart != child) { if (debug) { printf("Deleting child %s/%s", attachedPartInfo.attachedPart, child.name); } attachedPartInfos.Remove(attachedPartInfo); i--; continue; } if (debugPeriodic) { printf("Updating child %s [%s]", attachedPartInfo, i); } attachedPartInfo.UpdateAttachments(flightState, debug, debugPeriodic); } // Continue deleting surplus entries while (attachedPartInfos.Count > part.children.Count) { AttachedPartInfo attachedPartInfo = attachedPartInfos[part.children.Count]; if (debug) { printf("Deleting child %s [%s]", attachedPartInfo.attachedPart, part.children.Count); } attachedPartInfos.Remove(attachedPartInfo); } }