Exemple #1
0
 private static void RepairClearDocking(KmlPartDock dock1, KmlPartDock dock2)
 {
     try
     {
         KmlNode module = dock1.GetChildNode("MODULE", "ModuleDockingNode");
         module.GetAttrib("state").Value = "Ready";
         //module.GetAttrib("dockUId").Value = "";
         KmlNode events = module.GetChildNode("EVENTS");
         events.GetChildNode("Undock").GetAttrib("active").Value           = "False";
         events.GetChildNode("UndockSameVessel").GetAttrib("active").Value = "False";
         if (dock2 != null)
         {
             module = dock2.GetChildNode("MODULE", "ModuleDockingNode");
             module.GetAttrib("state").Value = "Ready";
             //module.GetAttrib("dockUId").Value = "";
             events = module.GetChildNode("EVENTS");
             events.GetChildNode("Undock").GetAttrib("active").Value           = "False";
             events.GetChildNode("UndockSameVessel").GetAttrib("active").Value = "False";
         }
         System.Windows.MessageBox.Show("Successfully reset docking to ready. Please save and reload to see the rebuilt part structure.");
         // TODO KmlPartDock:RepairClearDocking(): Refresh structure without save / reload
     }
     catch (NullReferenceException)
     {
         System.Windows.MessageBox.Show("Couldn't reset docking node, there are sub-nodes missing.\n" +
                                        "You should copy a MODULE node from a functional state 'Ready' part.\n");
     }
 }
Exemple #2
0
 private static void RepairDockerDockee(KmlPartDock docker, KmlPartDock dockee)
 {
     if (docker.ParentPart == dockee || dockee.ParentPart == docker)
     {
         bool dockerOk = false;
         bool dockeeOk = false;
         try
         {
             KmlNode module = docker.GetChildNode("MODULE", "ModuleDockingNode");
             module.GetAttrib("state").Value   = "Docked (docker)";
             module.GetAttrib("dockUId").Value = dockee.Uid;
             KmlNode events = module.GetChildNode("EVENTS");
             events.GetChildNode("Undock").GetAttrib("active").Value           = "True";
             events.GetChildNode("UndockSameVessel").GetAttrib("active").Value = "False";
             if (module.GetChildNode("DOCKEDVESSEL") == null)
             {
                 System.Windows.MessageBox.Show("Couldn't find sub-node DOCKEDVESSEL, you should try to copy it from older save files.");
             }
             else
             {
                 dockerOk = true;
             }
         }
         catch (NullReferenceException)
         {
             System.Windows.MessageBox.Show("Couldn't fix docker node, there are sub-nodes missing.\n" +
                                            "You should copy a MODULE node from a functional 'Docked (docker)' part.\n" +
                                            "Docker should be: " + docker);
         }
         try
         {
             KmlNode module = dockee.GetChildNode("MODULE", "ModuleDockingNode");
             module.GetAttrib("state").Value   = "Docked (dockee)";
             module.GetAttrib("dockUId").Value = docker.Uid;
             KmlNode events = module.GetChildNode("EVENTS");
             events.GetChildNode("Undock").GetAttrib("active").Value           = "False";
             events.GetChildNode("UndockSameVessel").GetAttrib("active").Value = "False";
             dockeeOk = true;
         }
         catch (NullReferenceException)
         {
             System.Windows.MessageBox.Show("Couldn't fix dockee node, there are sub-nodes missing.\n" +
                                            "You should copy a MODULE node from a functional 'Docked (dockee)' part.\n" +
                                            "Dockee should be: " + dockee);
         }
         if (dockerOk && dockeeOk)
         {
             System.Windows.MessageBox.Show("Successfully repaired docker-dockee. Please save and reload to see the rebuilt part structure.");
             // TODO KmlPartDock:RepairDockerDockee(): Refresh structure without save / reload
         }
     }
     else
     {
         RepairSameVesselChoose(docker, dockee);
     }
 }
Exemple #3
0
 private static void RepairSameVesselDockee(KmlPartDock same, KmlPartDock dockee)
 {
     if (same.ParentPart == dockee || dockee.ParentPart == same)
     {
         RepairDependingWhosParent(same, dockee);
     }
     else
     {
         bool sameOk   = false;
         bool dockeeOk = false;
         try
         {
             KmlNode module = same.GetChildNode("MODULE", "ModuleDockingNode");
             module.GetAttrib("state").Value   = "Docked (same vessel)";
             module.GetAttrib("dockUId").Value = dockee.Uid;
             KmlNode events = module.GetChildNode("EVENTS");
             events.GetChildNode("Undock").GetAttrib("active").Value           = "False";
             events.GetChildNode("UndockSameVessel").GetAttrib("active").Value = "True";
             sameOk = true;
         }
         catch (NullReferenceException)
         {
             System.Windows.MessageBox.Show("Couldn't fix same vessel docking node, there are sub-nodes missing.\n" +
                                            "You should copy a MODULE node from a functional 'Docked (same vessel)' part.\n" +
                                            "Same vessel dock should be: " + same);
         }
         try
         {
             KmlNode module = dockee.GetChildNode("MODULE", "ModuleDockingNode");
             module.GetAttrib("state").Value   = "Docked (dockee)";
             module.GetAttrib("dockUId").Value = same.Uid;
             KmlNode events = module.GetChildNode("EVENTS");
             events.GetChildNode("Undock").GetAttrib("active").Value           = "False";
             events.GetChildNode("UndockSameVessel").GetAttrib("active").Value = "False";
             dockeeOk = true;
         }
         catch (NullReferenceException)
         {
             System.Windows.MessageBox.Show("Couldn't fix dockee node, there are sub-nodes missing.\n" +
                                            "You should copy a MODULE node from a functional 'Docked (dockee)' part.\n" +
                                            "Dockee should be: " + dockee);
         }
         if (sameOk && dockeeOk)
         {
             System.Windows.MessageBox.Show("Successfully repaired same vessel docking. Please save and reload to see the rebuilt part structure.");
             // TODO KmlPartDock:RepairDockerDockee(): Refresh structure without save / reload
         }
     }
 }
Exemple #4
0
 private static void RepairClearDocking(KmlPartDock dock1, KmlPartDock dock2)
 {
     try
     {
         KmlNode module = dock1.GetChildNode("MODULE", "ModuleDockingNode");
         module.GetAttrib("state").Value = "Ready";
         //module.GetAttrib("dockUId").Value = "";
         KmlNode events = module.GetChildNode("EVENTS");
         events.GetChildNode("Undock").GetAttrib("active").Value           = "False";
         events.GetChildNode("UndockSameVessel").GetAttrib("active").Value = "False";
         Syntax.Info(dock1, "Successfully reset docking to ready");
     }
     catch (NullReferenceException)
     {
         Syntax.Warning(dock1, "Couldn't reset docking node, there are sub-nodes missing.\n" +
                        "You should copy a MODULE node from a functional state 'Ready' part.\n");
     }
     if (dock2 != null)
     {
         try
         {
             KmlNode module = dock2.GetChildNode("MODULE", "ModuleDockingNode");
             module.GetAttrib("state").Value = "Ready";
             //module.GetAttrib("dockUId").Value = "";
             KmlNode events = module.GetChildNode("EVENTS");
             events.GetChildNode("Undock").GetAttrib("active").Value           = "False";
             events.GetChildNode("UndockSameVessel").GetAttrib("active").Value = "False";
             Syntax.Info(dock2, "Successfully reset docking to ready");
         }
         catch (NullReferenceException)
         {
             Syntax.Warning(dock2, "Couldn't reset docking node, there are sub-nodes missing.\n" +
                            "You should copy a MODULE node from a functional state 'Ready' part\n");
         }
     }
     if (dock1.Parent is KmlVessel)
     {
         BuildAttachmentStructure((dock1.Parent as KmlVessel).Parts);
     }
 }
Exemple #5
0
        private static void RepairGrappling(KmlPartDock grapple, KmlPart part)
        {
            int grappleIndex = -1;
            int partIndex    = -1;

            if (grapple.Parent is KmlVessel)
            {
                bool      dockedVesselOk = true;
                KmlVessel vessel         = (KmlVessel)grapple.Parent;
                grappleIndex = vessel.Parts.IndexOf(grapple);
                partIndex    = vessel.Parts.IndexOf(part);
                try
                {
                    KmlNode module = grapple.GetOrCreateChildNode("MODULE", "ModuleGrappleNode");
                    module.GetOrCreateAttrib("isEnabled", "True");
                    //module.GetOrCreateAttrib("stagingEnabled").Value = "False"; // True?!?
                    module.GetOrCreateAttrib("state").Value   = "Grappled";
                    module.GetOrCreateAttrib("dockUId").Value = part.Uid;
                    KmlNode events = module.GetOrCreateChildNode("EVENTS");
                    events.GetOrCreateChildNode("Release").GetOrCreateAttrib("active").Value           = "True";
                    events.GetOrCreateChildNode("ReleaseSameVessel").GetOrCreateAttrib("active").Value = "False";
                    events.GetOrCreateChildNode("Decouple").GetOrCreateAttrib("active").Value          = "False";
                    module.GetOrCreateChildNode("ACTIONS");

                    KmlNode dockedVessel      = module.GetOrCreateChildNode("DOCKEDVESSEL");
                    KmlNode dockedVesselOther = module.GetOrCreateChildNode("DOCKEDVESSEL_Other");

                    string vesselName;
                    string vesselRootUId;
                    string defaultName;
                    if (grapple.Parent is KmlVessel)
                    {
                        vesselName    = (grapple.Parent as KmlVessel).Name;
                        vesselRootUId = (grapple.Parent as KmlVessel).RootPart.Uid;
                        defaultName   = vesselName + " Grappled - repaired by KML";
                    }
                    else
                    {
                        vesselName = "Unknown Vessel - repaired by KML";
                        if (part.ParentPart == grapple)
                        {
                            vesselRootUId = grapple.Uid;
                        }
                        else
                        {
                            vesselRootUId = part.Uid;
                        }
                        defaultName = "Unknown Grappled - repaired by KML";
                    }

                    string thisName;
                    string otherName;
                    string thisUid;
                    string otherUid;
                    if (part.ParentPart == grapple)
                    {
                        thisName  = vesselName;
                        thisUid   = vesselRootUId;
                        otherName = defaultName;
                        otherUid  = part.Uid;
                    }
                    else
                    {
                        thisName  = defaultName;
                        thisUid   = grapple.Uid;
                        otherName = vesselName;
                        otherUid  = vesselRootUId;
                    }
                    if (dockedVessel.GetAttrib("vesselName") == null)
                    {
                        KmlAttrib attrib = dockedVessel.GetOrCreateAttrib("vesselName", thisName);
                        attrib.AttribValueChanged += grapple.DockedVesselName_Changed;
                        grapple.DockedVesselName_Changed(attrib, new System.Windows.RoutedEventArgs());
                    }
                    if (dockedVessel.GetAttrib("vesselType") == null)
                    {
                        KmlAttrib attrib = dockedVessel.GetOrCreateAttrib("vesselType", "6");
                        attrib.AttribValueChanged += grapple.DockedVesselType_Changed;
                        grapple.DockedVesselType_Changed(attrib, new System.Windows.RoutedEventArgs());
                    }
                    dockedVessel.GetOrCreateAttrib("rootUId", thisUid);
                    if (dockedVesselOther.GetAttrib("vesselName") == null)
                    {
                        KmlAttrib attrib = dockedVesselOther.GetOrCreateAttrib("vesselName", otherName);
                        attrib.AttribValueChanged += grapple.DockedVesselOtherName_Changed;
                        grapple.DockedVesselOtherName_Changed(attrib, new System.Windows.RoutedEventArgs());
                    }
                    if (dockedVesselOther.GetAttrib("vesselType") == null)
                    {
                        KmlAttrib attrib = dockedVesselOther.GetOrCreateAttrib("vesselType", "6");
                        attrib.AttribValueChanged += grapple.DockedVesselOtherType_Changed;
                        grapple.DockedVesselOtherType_Changed(attrib, new System.Windows.RoutedEventArgs());
                    }
                    dockedVesselOther.GetOrCreateAttrib("rootUId", otherUid);

                    module = grapple.GetOrCreateChildNode("MODULE", "ModuleAnimateGeneric");
                    module.GetOrCreateAttrib("animSwitch").Value = "False";
                    module.GetOrCreateAttrib("animTime").Value   = "1";
                    events = module.GetOrCreateChildNode("EVENTS");
                    KmlNode toggle = events.GetOrCreateChildNode("Toggle");
                    toggle.GetOrCreateAttrib("active").Value  = "False";
                    toggle.GetOrCreateAttrib("guiName").Value = "Disarm";
                    if (part.ParentPart == grapple)
                    {
                        RepairGrappleAttachment(part, grappleIndex);
                    }
                    else if (grapple.ParentPart == part)
                    {
                        RepairGrappleAttachment(grapple, partIndex);
                    }
                    else
                    {
                        // TODO KmlPartDock:RepairGrappling(): Is there a 'Grappled (same vessel)'?
                    }
                    if (dockedVesselOk)
                    {
                        Syntax.Info(grapple, "Successfully repaired grappling");
                        BuildAttachmentStructure(vessel.Parts);
                    }
                }
                catch (NullReferenceException)
                {
                    Syntax.Warning(grapple, "Couldn't fix grappling node, there are sub-nodes missing.\n" +
                                   "You should copy a MODULE node from a functional state 'Grappled' part\n" +
                                   "grappled part should be: " + part);
                }
            }
            else
            {
                Syntax.Warning(grapple, "Could not search for connected parts, parent vessel is not valid");
            }
        }
Exemple #6
0
 private static void RepairDockerDockee(KmlPartDock docker, KmlPartDock dockee)
 {
     if (docker.ParentPart == dockee || dockee.ParentPart == docker)
     {
         bool dockerOk = false;
         bool dockeeOk = false;
         try
         {
             KmlNode module = docker.GetOrCreateChildNode("MODULE", "ModuleDockingNode");
             module.GetOrCreateAttrib("isEnabled", "True");
             module.GetOrCreateAttrib("crossfeed", "True");
             module.GetOrCreateAttrib("stagingEnabled").Value = "False";
             module.GetOrCreateAttrib("state").Value          = "Docked (docker)";
             module.GetOrCreateAttrib("dockUId").Value        = dockee.Uid;
             KmlNode events = module.GetOrCreateChildNode("EVENTS");
             events.GetOrCreateChildNode("Undock").GetOrCreateAttrib("active").Value           = "True";
             events.GetOrCreateChildNode("UndockSameVessel").GetOrCreateAttrib("active").Value = "False";
             events.GetOrCreateChildNode("Decouple").GetOrCreateAttrib("active").Value         = "False";
             module.GetOrCreateChildNode("ACTIONS");
             KmlNode dockedVessel = module.GetOrCreateChildNode("DOCKEDVESSEL");
             string  defaultName;
             if (docker.Parent is KmlVessel)
             {
                 defaultName = (docker.Parent as KmlVessel).Name + " Docker - repaired by KML";
             }
             else
             {
                 defaultName = "Unknown Docker - repaired by KML";
             }
             if (dockedVessel.GetAttrib("vesselName") == null)
             {
                 KmlAttrib attrib = dockedVessel.GetOrCreateAttrib("vesselName", defaultName);
                 attrib.AttribValueChanged += docker.DockedVesselName_Changed;
                 docker.DockedVesselName_Changed(attrib, new System.Windows.RoutedEventArgs());
             }
             if (dockedVessel.GetAttrib("vesselType") == null)
             {
                 KmlAttrib attrib = dockedVessel.GetOrCreateAttrib("vesselType", "6");
                 attrib.AttribValueChanged += docker.DockedVesselType_Changed;
                 docker.DockedVesselType_Changed(attrib, new System.Windows.RoutedEventArgs());
             }
             dockedVessel.GetOrCreateAttrib("rootUId", docker.Uid);
             dockerOk = true;
         }
         catch (NullReferenceException)
         {
             Syntax.Warning(docker, "Couldn't fix docker node, there are sub-nodes missing.\n" +
                            "You should copy a MODULE node from a functional 'Docked (docker)' part.\n" +
                            "Docker should be: " + docker);
         }
         try
         {
             KmlNode module = dockee.GetOrCreateChildNode("MODULE", "ModuleDockingNode");
             module.GetOrCreateAttrib("isEnabled", "True");
             module.GetOrCreateAttrib("crossfeed", "True");
             module.GetOrCreateAttrib("stagingEnabled").Value = "False";
             module.GetOrCreateAttrib("state").Value          = "Docked (dockee)";
             module.GetOrCreateAttrib("dockUId").Value        = docker.Uid;
             KmlNode events = module.GetOrCreateChildNode("EVENTS");
             events.GetOrCreateChildNode("Undock").GetOrCreateAttrib("active").Value           = "False";
             events.GetOrCreateChildNode("UndockSameVessel").GetOrCreateAttrib("active").Value = "False";
             events.GetOrCreateChildNode("Decouple").GetOrCreateAttrib("active").Value         = "False";
             module.GetOrCreateChildNode("ACTIONS");
             KmlNode dockedVessel = module.GetOrCreateChildNode("DOCKEDVESSEL");
             string  defaultName;
             string  defaultUId;
             if (dockee.Parent is KmlVessel)
             {
                 defaultName = (dockee.Parent as KmlVessel).Name;
                 defaultUId  = (dockee.Parent as KmlVessel).RootPart.Uid;
             }
             else
             {
                 defaultName = "Unknown Dockee - repaired by KML";
                 defaultUId  = dockee.Uid;
             }
             if (dockedVessel.GetAttrib("vesselName") == null)
             {
                 KmlAttrib attrib = dockedVessel.GetOrCreateAttrib("vesselName", defaultName);
                 attrib.AttribValueChanged += dockee.DockedVesselName_Changed;
                 docker.DockedVesselName_Changed(attrib, new System.Windows.RoutedEventArgs());
             }
             if (dockedVessel.GetAttrib("vesselType") == null)
             {
                 KmlAttrib attrib = dockedVessel.GetOrCreateAttrib("vesselType", "6");
                 attrib.AttribValueChanged += dockee.DockedVesselType_Changed;
                 docker.DockedVesselType_Changed(attrib, new System.Windows.RoutedEventArgs());
             }
             dockedVessel.GetOrCreateAttrib("rootUId", defaultUId);
             dockeeOk = true;
         }
         catch (NullReferenceException)
         {
             Syntax.Warning(dockee, "Couldn't fix dockee node, there are sub-nodes missing.\n" +
                            "You should copy a MODULE node from a functional 'Docked (dockee)' part.\n" +
                            "Dockee should be: " + dockee);
         }
         if (dockerOk && dockeeOk)
         {
             Syntax.Info(docker, "Successfully repaired docker-dockee");
             if (docker.Parent is KmlVessel)
             {
                 BuildAttachmentStructure((docker.Parent as KmlVessel).Parts);
             }
         }
     }
     else
     {
         RepairSameVesselChoose(docker, dockee);
     }
 }
Exemple #7
0
        private static void RepairGrappling(KmlPartDock grapple, KmlPart part)
        {
            int grappleIndex = -1;
            int partIndex    = -1;

            if (grapple.Parent == null || !(grapple.Parent is KmlVessel))
            {
                System.Windows.MessageBox.Show("Could not search for connected parts, parent vessel is not valid");
            }
            else
            {
                bool      dockedVesselOk = true;
                KmlVessel vessel         = (KmlVessel)grapple.Parent;
                grappleIndex = vessel.Parts.IndexOf(grapple);
                partIndex    = vessel.Parts.IndexOf(part);
                try
                {
                    KmlNode module = grapple.GetChildNode("MODULE", "ModuleGrappleNode");
                    module.GetAttrib("state").Value   = "Grappled";
                    module.GetAttrib("dockUId").Value = part.Uid;
                    KmlNode events = module.GetChildNode("EVENTS");
                    events.GetChildNode("Release").GetAttrib("active").Value           = "True";
                    events.GetChildNode("ReleaseSameVessel").GetAttrib("active").Value = "False";
                    if (module.GetChildNode("DOCKEDVESSEL") == null)
                    {
                        System.Windows.MessageBox.Show("Couldn't find sub-node DOCKEDVESSEL, you should try to copy it from older save file.");
                        dockedVesselOk = false;
                    }
                    if (module.GetChildNode("DOCKEDVESSEL_other") == null)
                    {
                        System.Windows.MessageBox.Show("Couldn't find sub-node DOCKEDVESSEL_other, you should try to copy it from older save file.");
                        dockedVesselOk = false;
                    }
                    module = grapple.GetChildNode("MODULE", "ModuleAnimateGeneric");
                    module.GetAttrib("animSwitch").Value = "False";
                    module.GetAttrib("animTime").Value   = "1";
                    events = module.GetChildNode("EVENTS");
                    KmlNode toggle = events.GetChildNode("Toggle");
                    toggle.GetAttrib("active").Value  = "False";
                    toggle.GetAttrib("guiName").Value = "Disarm";
                    if (part.ParentPart == grapple)
                    {
                        RepairGrappleAttachment(part, grappleIndex);
                    }
                    else if (grapple.ParentPart == part)
                    {
                        RepairGrappleAttachment(grapple, partIndex);
                    }
                    else
                    {
                        // TODO KmlPartDock:RepairGrappling(): Is there a 'Grappled (same vessel)'?
                    }
                    if (dockedVesselOk)
                    {
                        // Maybe RepairGrappleAttachment()  will cause a message to save and reload
                        System.Windows.MessageBox.Show("Successfully repaired grappling. Please save and reload to see the rebuilt part structure.");
                        // TODO KmlPartDock:RepairGrappling(): Refresh structure without save / reload
                    }
                }
                catch (NullReferenceException)
                {
                    System.Windows.MessageBox.Show("Couldn't fix grappling node, there are sub-nodes missing.\n" +
                                                   "You should copy a MODULE node from a functional state 'Grappled' part.\n" +
                                                   "grappled part should be: " + part);
                }
            }
        }