Exemplo n.º 1
0
        public void ReloadElement(ElementSave element)
        {
            string projectRootDirectory = FileManager.GetDirectory(this.FullFileName);

            var gumLoadResult = new GumLoadResult();

            if (element is ScreenSave)
            {
                var matchingReference = ScreenReferences.FirstOrDefault(item => item.Name == element.Name);

                ScreenSave newScreen = matchingReference?.ToElementSave <ScreenSave>(
                    projectRootDirectory, GumProjectSave.ScreenExtension, gumLoadResult);

                if (newScreen != null)
                {
                    Screens.Remove(element as ScreenSave);
                    Screens.Add(newScreen);
                }
            }
            else if (element is ComponentSave)
            {
                var matchingReference = ComponentReferences.FirstOrDefault(item => item.Name == element.Name);

                ComponentSave newComonent = matchingReference?.ToElementSave <ComponentSave>(
                    projectRootDirectory, GumProjectSave.ComponentExtension, gumLoadResult);

                if (newComonent != null)
                {
                    Components.Remove(element as ComponentSave);
                    Components.Add(newComonent);
                }
            }
            else if (element is StandardElementSave)
            {
                var matchingReference = StandardElementReferences.FirstOrDefault(item => item.Name == element.Name);

                StandardElementSave newStandardElement = matchingReference?.ToElementSave <StandardElementSave>(
                    projectRootDirectory, GumProjectSave.ComponentExtension, gumLoadResult);

                if (newStandardElement != null)
                {
                    StandardElements.Remove(element as StandardElementSave);
                    StandardElements.Add(newStandardElement);
                }
            }
        }
Exemplo n.º 2
0
        private void PopulateElementSavesFromReferences(string projectRootDirectory, GumLoadResult result)
        {
            string errors = "";

            Screens.Clear();
            Components.Clear();
            StandardElements.Clear();
            Behaviors.Clear();

            foreach (ElementReference reference in ScreenReferences)
            {
                ScreenSave toAdd = null;
                try
                {
                    toAdd = reference.ToElementSave <ScreenSave>(projectRootDirectory, ScreenExtension, result);
                }
                catch (Exception e)
                {
                    errors += "\nError loading " + reference.Name + ":\n" + e.Message;
                }
                if (toAdd != null)
                {
                    Screens.Add(toAdd);
                }
            }

            foreach (ElementReference reference in ComponentReferences)
            {
                ComponentSave toAdd = null;

                try
                {
                    toAdd = reference.ToElementSave <ComponentSave>(projectRootDirectory, ComponentExtension, result);
                }
                catch (Exception e)
                {
                    errors += "\nError loading " + reference.Name + ":\n" + e.Message;
                }
                if (toAdd != null)
                {
                    Components.Add(toAdd);
                }
            }

            foreach (ElementReference reference in StandardElementReferences)
            {
                StandardElementSave toAdd = null;
                try
                {
                    toAdd = reference.ToElementSave <StandardElementSave>(projectRootDirectory, StandardExtension, result);
                }
                catch (Exception e)
                {
                    errors += "\nError loading " + reference.Name + ":\n" + e.Message;
                }
                if (toAdd != null)
                {
                    StandardElements.Add(toAdd);
                }
            }

            foreach (var reference in BehaviorReferences)
            {
                BehaviorSave toAdd = null;

                try
                {
                    toAdd = reference.ToBehaviorSave(projectRootDirectory);
                }
                catch (Exception e)
                {
                    errors += "\nError loading " + reference.Name + ":\n" + e.Message;
                }
                if (toAdd != null)
                {
                    Behaviors.Add(toAdd);
                }
            }

            result.ErrorMessage += errors;
        }
Exemplo n.º 3
0
 public TreeNode GetTreeNodeFor(StandardElementSave standardElementSave)
 {
     return GetTreeNodeForTag(standardElementSave, RootStandardElementsTreeNode);
 }
        public StandardElementSave AddStandardElementSaveInstance(GumProjectSave gumProjectSave, string type)
        {
            StandardElementSave elementSave = new StandardElementSave();
            elementSave.Initialize(mDefaults[type]);
            elementSave.Name = type;

            
            gumProjectSave.StandardElementReferences.Add( new ElementReference { Name = type, ElementType = ElementType.Standard});
            gumProjectSave.StandardElements.Add( elementSave);

            return elementSave;
        }
Exemplo n.º 5
0
        /// <summary>
        /// Initializes the GumProjectSave for editing in Gum.  This means
        /// adding any variables that are necessary, fixing enumerations, and
        /// checking for other errors.
        /// </summary>
        /// <param name="gumProjectSave">The GumProjectSave</param>
        public static bool Initialize(this GumProjectSave gumProjectSave)
        {
            bool wasModified = false;

            gumProjectSave.ScreenReferences.Sort((first, second) => first.Name.CompareTo(second.Name));
            gumProjectSave.ComponentReferences.Sort((first, second) => first.Name.CompareTo(second.Name));
            gumProjectSave.StandardElementReferences.Sort((first, second) => first.Name.CompareTo(second.Name));

            gumProjectSave.Screens.Sort((first, second) => first.Name.CompareTo(second.Name));
            gumProjectSave.Components.Sort((first, second) => first.Name.CompareTo(second.Name));
            gumProjectSave.StandardElements.Sort((first, second) => first.Name.CompareTo(second.Name));


            // Do StandardElements first
            // because the values here are
            // used by components to set their
            // ignored enum values.
            foreach (StandardElementSave standardElementSave in gumProjectSave.StandardElements)
            {
                StateSave stateSave = StandardElementsManager.Self.GetDefaultStateFor(standardElementSave.Name);
                // this will result in extra variables being
                // added
                wasModified = standardElementSave.Initialize(stateSave) || wasModified;

                stateSave.ParentContainer = standardElementSave;
            }

            foreach (ScreenSave screenSave in gumProjectSave.Screens)
            {
                screenSave.Initialize(null);
            }



            foreach (ComponentSave componentSave in gumProjectSave.Components)
            {
                // June 27, 2012
                // We used to pass
                // null here because
                // passing a non-null
                // variable meant replacing
                // the existing StateSave with
                // the argument StateSave.  However,
                // now when the type of a Component is
                // changed, old values are not removed, but
                // are rather preserved so that changing the
                // type doesn't wipe out old values.
                //componentSave.Initialize(null);

                StateSave           defaultStateSave = null;
                StandardElementSave ses = ObjectFinder.Self.GetRootStandardElementSave(componentSave);
                if (ses != null)
                {
                    defaultStateSave = ses.DefaultState;
                }

                if (componentSave.Initialize(defaultStateSave))
                {
                    wasModified = true;
                }

                if (componentSave.Initialize(StandardElementsManager.Self.DefaultStates["Component"]))
                {
                    wasModified = true;
                }
            }

            if (gumProjectSave.Version < 1)
            {
                // This means that all default variables have SetValue = false
                // We need to fix that
                foreach (StandardElementSave standardElementSave in gumProjectSave.StandardElements)
                {
                    var defaultState = standardElementSave.DefaultState;

                    foreach (var variable in defaultState.Variables)
                    {
                        if (variable.IsState(standardElementSave) == false)
                        {
                            variable.SetsValue = true;
                        }
                    }
                }

                foreach (var component in gumProjectSave.Components)
                {
                    // We only want to do this on components that don't inherit from other components:
                    var baseComponent = ObjectFinder.Self.GetComponent(component.BaseType);

                    if (baseComponent == null)
                    {
                        var defaultState = component.DefaultState;


                        foreach (var variable in defaultState.Variables)
                        {
                            if (variable.IsState(component) == false)
                            {
                                variable.SetsValue = true;
                            }
                        }
                    }
                }

                wasModified = true;
            }

            return(wasModified);
        }