/// <summary>
 ///   Creates a deep copy of the specified blueprint.
 /// </summary>
 /// <param name="original">Original blueprint to copy.</param>
 public Blueprint(Blueprint original)
 {
     this.AttributeTable = new AttributeTable(original.AttributeTable);
     this.ComponentTypes = new List<Type>(original.ComponentTypes);
     this.Parent = original.Parent;
     this.ParentId = original.ParentId;
 }
        public void TestCopyConstructorParentId()
        {
            // Try to copy blueprint.
            var newBlueprint = new Blueprint(this.blueprint);

            // Check that parent id was copied.
            Assert.AreEqual(newBlueprint.ParentId, ParentId);
        }
 public void SetUp()
 {
     this.testGame = new Game();
     BlueprintManager blueprintManager = new BlueprintManager();
     Blueprint blueprint = new Blueprint();
     blueprint.ComponentTypes.Add(typeof(TestComponent));
     blueprintManager.AddBlueprint(TestBlueprintId, blueprint);
     this.testGame.BlueprintManager = blueprintManager;
 }
        /// <summary>
        ///   Resolves the parent reference in the specified blueprint by searching in the specified
        ///   available blueprint manager.
        /// </summary>
        /// <param name="blueprint">Blueprint to resolve parent reference for.</param>
        /// <param name="blueprintManager">Blueprint manager to use to search for parent blueprints.</param>
        /// <exception cref="KeyNotFoundException">Thrown if parent couldn't be resolved.</exception>
        public static void ResolveParent(Blueprint blueprint, IBlueprintManager blueprintManager)
        {
            if (string.IsNullOrEmpty(blueprint.ParentId) || blueprint.Parent != null)
            {
                return;
            }

            blueprint.Parent = blueprintManager.GetBlueprint(blueprint.ParentId);
        }
        /// <summary>
        ///   Tries to resolve the parent reference in the specified blueprint by searching in the specified
        ///   available blueprint manager.
        /// </summary>
        /// <param name="blueprint">Blueprint to try to resolve parent reference for.</param>
        /// <param name="blueprintManager">Blueprint manager to use to search for parent blueprints.</param>
        /// <returns><c>true</c>, if the parent blueprint could be found, and <c>false</c> otherwise.</returns>
        public static bool TryResolveParent(Blueprint blueprint, IBlueprintManager blueprintManager)
        {
            if (string.IsNullOrEmpty(blueprint.ParentId) || blueprint.Parent != null)
            {
                return true;
            }

            Blueprint parentBlueprint;
            bool foundParent = blueprintManager.TryGetBlueprint(blueprint.ParentId, out parentBlueprint);
            blueprint.Parent = parentBlueprint;
            return foundParent;
        }
 public void SetUp()
 {
     this.blueprint = new Blueprint { ParentId = ParentId };
 }
 public void SetUp()
 {
     this.blueprintManager = new BlueprintManager();
     this.blueprint = new Blueprint();
     this.blueprintManager.AddBlueprint(this.blueprintId, this.blueprint);
 }
        /// <summary>
        ///   Adds the blueprint with the specified id to the first child blueprint manager.
        /// </summary>
        /// <param name="blueprintId">Id of the new blueprint to add.</param>
        /// <param name="blueprint">New blueprint to add.</param>
        public void AddBlueprint(string blueprintId, Blueprint blueprint)
        {
            var child = this.children.FirstOrDefault();

            if (child == null)
            {
                throw new InvalidOperationException("No child blueprint manager to add blueprint to!");
            }

            // TODO(np): Specify which blueprint manager to add to.
            child.AddBlueprint(blueprintId, blueprint);
        }
        private List<Type> GetDerivedBlueprintComponentsRecursively(Blueprint blueprint, List<Type> componentTypes)
        {
            componentTypes.AddRange(blueprint.ComponentTypes);

            if (!string.IsNullOrEmpty(blueprint.ParentId))
            {
                var parentBlueprint = this.GetBlueprint(blueprint.ParentId);
                this.GetDerivedBlueprintComponentsRecursively(parentBlueprint, componentTypes);
            }

            return componentTypes;
        }
        /// <summary>
        ///   Searches for the blueprint with the specified id. Returns if the blueprint was found.
        /// </summary>
        /// <param name="blueprintId">Id of blueprint to search for.</param>
        /// <param name="blueprint">Parameter to write found blueprint to.</param>
        /// <returns>True if the blueprint was found; otherwise, false.</returns>
        public bool TryGetBlueprint(string blueprintId, out Blueprint blueprint)
        {
            foreach (IBlueprintManager child in this.children)
            {
                if (child.TryGetBlueprint(blueprintId, out blueprint))
                {
                    return true;
                }
            }

            blueprint = null;
            return false;
        }
 /// <summary>
 ///   Gets the list of components of the specified blueprint and all of its children.
 /// </summary>
 /// <param name="blueprint">Blueprint to get the inherited components of.</param>
 /// <returns>list of components of the specified blueprint and all of its children.</returns>
 public List<Type> GetDerivedBlueprintComponents(Blueprint blueprint)
 {
     return this.GetDerivedBlueprintComponentsRecursively(blueprint, new List<Type>());
 }
 private bool Equals(Blueprint other)
 {
     return this.AttributeTable.Equals(other.AttributeTable)
            && CollectionUtils.SequenceEqual(this.ComponentTypes, other.ComponentTypes);
 }
        private void OnGUI()
        {
            // Reload blueprints if missing.
            if (blueprintManager == null)
            {
                // Load blueprints.
                LoadBlueprints();
            }

            string removedBlueprintId = null;
            Type removedComponentType = null;

            // Summary.
            GUILayout.Label("Summary", EditorStyles.boldLabel);
            EditorGUILayout.LabelField("Blueprint file:", blueprintFileName);
            EditorGUILayout.LabelField("Selected blueprint:", this.selectedBlueprintId);

            if (GUILayout.Button("Save Blueprints"))
            {
                SaveBlueprints();
            }

            EditorGUILayout.BeginHorizontal();
            {
                this.blueprintListScrollPosition = EditorGUILayout.BeginScrollView(
                    this.blueprintListScrollPosition, false, true);
                EditorGUILayout.BeginVertical(GUILayout.Width(200f));
                {
                    // List blueprints.
                    GUILayout.Label("Blueprints", EditorStyles.boldLabel);

                    foreach (var namedBlueprint in blueprintManager.Blueprints)
                    {
                        EditorGUILayout.BeginHorizontal();
                        {
                            // Remove blueprint button.
                            if (this.GUILayoutButtonRemove())
                            {
                                removedBlueprintId = namedBlueprint.Key;
                            }

                            // Select blueprint button.
                            if (GUILayout.Button(namedBlueprint.Key))
                            {
                                this.selectedBlueprintId = namedBlueprint.Key;
                                this.selectedBlueprint =
                                    hierarchicalBlueprintManager.GetBlueprint(this.selectedBlueprintId);
                            }
                        }
                        EditorGUILayout.EndHorizontal();
                    }

                    // Add blueprint button.
                    EditorGUILayout.BeginHorizontal();
                    {
                        this.newBlueprintId = EditorGUILayout.TextField("Add blueprint:", this.newBlueprintId);

                        if (this.GUILayoutButtonAdd())
                        {
                            try
                            {
                                var blueprint = new Blueprint();
                                blueprintManager.AddBlueprint(this.newBlueprintId, blueprint);
                            }
                            catch (ArgumentException e)
                            {
                                EditorUtility.DisplayDialog("Error", e.Message, "Close");
                            }
                        }
                    }
                    EditorGUILayout.EndHorizontal();
                }
                EditorGUILayout.EndVertical();
                EditorGUILayout.EndScrollView();

                this.blueprintDetailsScrollPosition =
                    EditorGUILayout.BeginScrollView(this.blueprintDetailsScrollPosition, false, true);
                EditorGUILayout.BeginVertical();
                {
                    if (this.selectedBlueprint != null)
                    {
                        // Components.
                        GUILayout.Label("Components", EditorStyles.boldLabel);

                        EditorGUILayout.BeginHorizontal();
                        {
                            // Current components.
                            EditorGUILayout.BeginVertical();
                            {
                                GUILayout.Label("Current", EditorStyles.boldLabel);

                                // Show parent blueprint components, but don't allow to remove them.
                                foreach (var componentType in this.selectedBlueprint.GetAllComponentTypes().Except(this.selectedBlueprint.ComponentTypes))
                                {
                                    GUILayout.Label(componentType.Name);
                                }

                                // Show blueprint components.
                                foreach (var componentType in this.selectedBlueprint.ComponentTypes)
                                {
                                    EditorGUILayout.BeginHorizontal();
                                    {
                                        // Remove component button.
                                        if (this.GUILayoutButtonRemove())
                                        {
                                            removedComponentType = componentType;
                                        }

                                        GUILayout.Label(componentType.Name);
                                    }
                                    EditorGUILayout.EndHorizontal();
                                }
                            }
                            EditorGUILayout.EndVertical();

                            // New components.
                            EditorGUILayout.BeginVertical();
                            {
                                GUILayout.Label("Other", EditorStyles.boldLabel);

                                foreach (var componentType in
                                    inspectorTypeTable.Types().Except(this.selectedBlueprint.GetAllComponentTypes()))
                                {
                                    EditorGUILayout.BeginHorizontal();
                                    {
                                        // Add component button.
                                        if (this.GUILayoutButtonAdd())
                                        {
                                            this.selectedBlueprint.ComponentTypes.Add(componentType);
                                        }

                                        GUILayout.Label(componentType.Name);
                                    }
                                    EditorGUILayout.EndHorizontal();
                                }
                            }
                            EditorGUILayout.EndVertical();
                        }
                        EditorGUILayout.EndHorizontal();

                        // Attributes.
                        GUILayout.Label("Attributes", EditorStyles.boldLabel);

                        EditorGUIUtils.BlueprintComponentsField(this.selectedBlueprint, this.selectedBlueprint.AttributeTable, inspectorTypeTable, hierarchicalBlueprintManager);
                    }
                }
                EditorGUILayout.EndVertical();
                EditorGUILayout.EndScrollView();
            }
            EditorGUILayout.EndHorizontal();

            // Remove data, if user wants to.
            if (removedBlueprintId != null)
            {
                blueprintManager.RemoveBlueprint(removedBlueprintId);

                this.selectedBlueprint = null;
                this.selectedBlueprintId = string.Empty;
            }

            if (this.selectedBlueprint != null && removedComponentType != null)
            {
                this.selectedBlueprint.ComponentTypes.Remove(removedComponentType);
            }
        }
 /// <summary>
 ///   Gets the list of components of the specified blueprint and all of its children.
 /// </summary>
 /// <param name="blueprint">Blueprint to get the inherited components of.</param>
 /// <returns>list of components of the specified blueprint and all of its children.</returns>
 public List <Type> GetDerivedBlueprintComponents(Blueprint blueprint)
 {
     return(this.GetDerivedBlueprintComponentsRecursively(blueprint, new List <Type>()));
 }