コード例 #1
0
        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;
 }
コード例 #3
0
        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}";
コード例 #9
0
 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;
 }