private static KspObject ReadObjectTree (KspToken token, Action<KspObject, KspToken> addTokenMapping)
        {
            KspObject obj;

            // Treat global tokens as craft object -> needed for .craft file support
            var type = token.IsGlobalToken () ? KspCraftObject.TypeId : token.Name;

            switch (type) {
            case KspCraftObject.TypeId:
                obj = new KspCraftObject (token.IsGlobalToken ());
                break;
            case KspPartObject.TypeId:
                obj = new KspPartObject (token.IsGlobalToken ());
                break;
            default:
                obj = new KspObject (token.Name, token.IsGlobalToken ());
                break;
            }

            foreach (var t in token.Tokens) {
                obj.AddChild (ReadObjectTree (t, addTokenMapping));
            }

            addTokenMapping (obj, token);
            return obj;
        }
예제 #2
0
 public IEnumerable<KspPartObject> LookupHardDependencies (KspPartObject dependency)
 {
     var parts = craft.Children<KspPartObject> ().ToList ();
     var dependencies = new HashSet<KspPartObject> ();
     LookupHardDependencies (parts, dependency, dependencies.Add);
     return dependencies;
 }
        public void CanRetrieveNameOfPartFromNameProperty ()
        {
            // given
            var part = new KspPartObject ()
                .AddProperty (new KspStringProperty ("name", "somePart")) as KspPartObject;

            // when / then
            Assert.That (part.Name, Is.EqualTo ("somePart"));
        }
예제 #4
0
 private static bool HasHardDependency (KspPartObject part, KspPartObject dependency)
 {
     Func<IReadOnlyList<KspPartLinkProperty>, bool> hasHardDependency =
         (refs) => refs.Count > 0 && refs.All (r => Object.Equals (r.Part, dependency));
     
     return hasHardDependency (part.PartLinks (KspPartLinkProperty.Types.Parent)) ||
     hasHardDependency (part.PartLinks (KspPartLinkProperty.Types.Sym)) ||
     hasHardDependency (part.PartLinks (KspPartLinkProperty.Types.SrfN)) ||
     hasHardDependency (part.PartLinks (KspPartLinkProperty.Types.AttN));
 }
예제 #5
0
 private static void LookupHardDependencies (List<KspPartObject> parts, KspPartObject dependency, Func<KspPartObject, bool> addDependency)
 {
     parts.ForEach (currentPart => {
         if (HasHardDependency (currentPart, dependency)) {
             if (addDependency (currentPart)) {
                 LookupHardDependencies (parts, currentPart, addDependency);
             }
         }
     });
 }
예제 #6
0
 public IEnumerable<KspPartObject> LookupSoftDependencies (KspPartObject dependency) =>
     craft.Children<KspPartObject> ().Where (part => HasSoftDependency (part, dependency));
예제 #7
0
 private List<KspPartLinkProperty> FindPartLinks (KspPartObject part, List<KspPartObject> dependencies)
 {
     return part.Properties.OfType<KspPartLinkProperty> ().Where (link => dependencies.Contains (link.Part)).ToList ();
 }
예제 #8
0
 public static String PartObjectToString (KspCraftObject craft, KspPartObject part) => $"[{craft.IdOfChild (part)}]{part.Name}";
 public KspPartLinkProperty (String name, String prefix, KspPartObject part, bool isIdReference = false) : base (name)
 {
     this.Prefix = prefix;
     this.Part = part;
     this.IsIdReference = isIdReference;
 }
예제 #10
0
 public KspPartLinkProperty(String name, String prefix, KspPartObject part, bool isIdReference = false) : base(name)
 {
     this.Prefix        = prefix;
     this.Part          = part;
     this.IsIdReference = isIdReference;
 }