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; }
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")); }
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)); }
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); } } }); }
public IEnumerable<KspPartObject> LookupSoftDependencies (KspPartObject dependency) => craft.Children<KspPartObject> ().Where (part => HasSoftDependency (part, dependency));
private List<KspPartLinkProperty> FindPartLinks (KspPartObject part, List<KspPartObject> dependencies) { return part.Properties.OfType<KspPartLinkProperty> ().Where (link => dependencies.Contains (link.Part)).ToList (); }
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; }
public KspPartLinkProperty(String name, String prefix, KspPartObject part, bool isIdReference = false) : base(name) { this.Prefix = prefix; this.Part = part; this.IsIdReference = isIdReference; }