Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="nodes"></param>
        /// <param name="groups"></param>
        /// <param name="rawData">Represents the current contents of the file. Reference is not held. A copy is made.</param>
        /// <param name="file"></param>
        /// <param name="serializer"></param>
        /// <param name="errors"></param>
        /// <param name="nodeFactory"></param>
        /// <param name="generateAudio"></param>
        /// <param name="getDocumentSource"></param>
        /// <param name="audioProvider"></param>
        public ConversationFile(Id <FileInProject> id, IEnumerable <GraphAndUI <NodeUIData> > nodes, IEnumerable <NodeGroup> groups, MemoryStream rawData, DocumentPath file, ISerializer <TData> serializer,
                                ReadOnlyCollection <LoadError> errors, INodeFactory nodeFactory, GenerateAudio generateAudio,
                                Func <IDynamicEnumParameter, object, DynamicEnumParameter.Source> getDocumentSource, IAudioLibrary audioProvider, UpToDateFile.BackEnd backEnd)
            : base(nodes, groups, errors, nodeFactory, generateAudio, getDocumentSource, audioProvider)
        {
            Id           = id;
            m_file       = new SaveableFileUndoable(rawData, file.FileInfo, SaveTo, backEnd);
            m_serializer = serializer;

            foreach (var node in m_nodes)
            {
                //TODO: AUDIO: Why are we automatically decorrupting specifically audio parameters?
                var audios = node.Data.Parameters.OfType <IAudioParameter>();
                foreach (var aud in audios)
                {
                    if (aud.Corrupted)
                    {
                        var val = generateAudio(this);
                        aud.SetValueAction(val).Value.Redo();
                        m_file.ChangeNoUndo();
                        audioProvider.UpdateUsage(val);
                    }
                }
                node.UpdateRendererCorruption();
            }
        }
Ejemplo n.º 2
0
        private SimpleUndoPair InnerAddNodes(IEnumerable <ConversationNode> nodes, IEnumerable <NodeGroup> groups, ILocalizationEngine localization)
        {
            List <Action> undoActions = new List <Action>();
            List <Action> redoActions = new List <Action>();

            //Set up actions for adding/removing the nodes
            foreach (var node in nodes)
            {
                var            n       = node;
                SimpleUndoPair actions = n.GetNodeRemoveActions();

                //Ensure that the localization engine is up to date in terms of usage of localized data
                foreach (var parameter in n.Data.Parameters.OfType <ILocalizedStringParameter>())
                {
                    if (parameter.Value != null)
                    {
                        SimpleUndoPair clearLocalization = localization.ClearLocalizationAction(Id <LocalizedStringType> .ConvertFrom(parameter.TypeId), parameter.Value);
                        undoActions.Add(clearLocalization.Redo);
                        redoActions.Add(clearLocalization.Undo);
                    }
                }

                var containingGroups = m_groups.Where(g => g.Contents.Contains(n.Data.NodeId)).Evaluate();
                redoActions.Add(() =>
                {
                    m_nodes.Add(n);
                    m_audioProvider.UpdateUsage(n);
                    foreach (var group in containingGroups)
                    {
                        group.Contents.Add(n.Data.NodeId);
                    }
                    actions.Undo(); //Undo the node removal
                });
                undoActions.Add(() =>
                {
                    if (CanRemoveFromData(n, PromptNodeDeletion))
                    {
                        m_nodes.Remove(n);
                    }
                    foreach (var group in containingGroups)
                    {
                        group.Contents.Remove(n.Data.NodeId);
                    }
                    actions.Redo(); //Redo the node removal
                    NodesDeleted.Execute();
                });
            }

            //Set up actions for adding/removing nodes from other groups that are gaining/losing their grouping due to removing/adding new groups
            foreach (var group in groups)
            {
                foreach (var node in group.Contents)
                {
                    var n   = node;
                    var old = m_groups.SingleOrDefault(g => g.Contents.Contains(n));
                    if (old != null)
                    {
                        undoActions.Add(() => old.Contents.Add(n));
                        redoActions.Add(() => old.Contents.Remove(n));
                    }
                }
            }

            //Set up actions for adding/removing the groups
            undoActions.Add(() =>
            {
                foreach (var group in groups.Reverse())
                {
                    m_groups.Remove(group);
                }
            });
            redoActions.Add(() =>
            {
                m_groups.AddRange(groups);
            });

            return(new SimpleUndoPair
            {
                Undo = () => { using (m_audioProvider.SuppressUpdates()) foreach (Action action in undoActions)
                                   {
                                       action();
                                   }
                },
                Redo = () => { using (m_audioProvider.SuppressUpdates()) foreach (Action action in redoActions)
                                   {
                                       action();
                                   }
                },
            });
        }