static public Dialogue CreateDialogueFile(string path, Package package = null)
        {
            string projectDirectory = Path.Combine(System.Environment.CurrentDirectory, Project.GetFilePath());
            string filePath         = "";

            try
            {
                filePath = Utility.GetRelativePath(path, projectDirectory);
            }
            catch (System.UriFormatException)
            {
                filePath = path;    //In case the given path is already relative (or consider it as relative if it's invalid)
            }

            Dialogue dialogue = new Dialogue();

            dialogue.Init(Path.GetDirectoryName(filePath), Path.GetFileNameWithoutExtension(filePath));
            dialogue.Package = (package != null) ? package : Project.GetDefaultPackage();
            if (AddDialogue(dialogue))
            {
                DialogueNodeRoot root = new DialogueNodeRoot();
                dialogue.AddNode(root);
                dialogue.RootNode = root;

                ExporterJson.SaveDialogueFile(Project, dialogue);

                return(dialogue);
            }
            return(null);
        }
Beispiel #2
0
        public void PostLoad(Project project)
        {
            //Resolve links with package
            Package = project.GetPackage(PackageName);
            if (Package == null)
            {
                EditorCore.LogError("Loading a Dialogue without Package (forcing default) : " + GetName(), this);
                Package = project.GetDefaultPackage();
            }

            //Resolve links between nodes
            RootNode = GetNodeByID(RootNodeID) as DialogueNodeRoot;

            foreach (DialogueNode node in ListNodes)
            {
                node.Next = GetNodeByID(node.NextID);
                if (node is DialogueNodeChoice)
                {
                    DialogueNodeChoice nodeChoice = node as DialogueNodeChoice;
                    foreach (int replyID in nodeChoice.RepliesIDs)
                    {
                        DialogueNodeReply nodeReply = GetNodeByID(replyID) as DialogueNodeReply;
                        if (nodeReply != null)
                        {
                            nodeChoice.Replies.Add(nodeReply);
                        }
                    }
                }
                else if (node is DialogueNodeGoto)
                {
                    DialogueNodeGoto nodeGoto = node as DialogueNodeGoto;
                    nodeGoto.Goto = GetNodeByID(nodeGoto.GotoID);
                }
                else if (node is DialogueNodeBranch)
                {
                    DialogueNodeBranch nodebranch = node as DialogueNodeBranch;
                    nodebranch.Branch = GetNodeByID(nodebranch.BranchID);
                }
            }

            EditorCore.OnDialoguePostLoad?.Invoke(this);
        }
Beispiel #3
0
        public void PreSave(Project project)
        {
            //Prepare File
            VersionProject = EditorCore.VersionProject;
            VersionEditor  = EditorVersion.GetVersion();

            if (Package == null)
            {
                EditorCore.LogError("Saving a Dialogue without Package (forcing default) : " + GetName(), this);
                Package = project.GetDefaultPackage();
            }

            if (Package != null)
            {
                PackageName = Package.Name;
            }

            //Sanitize texts
            //dialogue.Comment = EditorCore.SanitizeText(dialogue.Comment);

            //Prepare nodes links
            RootNodeID = (RootNode != null) ? RootNode.ID : DialogueNode.ID_NULL;

            foreach (DialogueNode node in ListNodes)
            {
                node.NextID = (node.Next != null) ? node.Next.ID : DialogueNode.ID_NULL;

                if (node is DialogueNodeSentence)
                {
                    //Generate ID
                    DialogueNodeSentence nodeSentence = node as DialogueNodeSentence;
                    nodeSentence.VoicingID = EditorHelper.GetPrettyNodeVoicingID(this, nodeSentence);

                    //Sanitize texts
                    nodeSentence.Sentence = EditorHelper.SanitizeText(nodeSentence.Sentence);
                    //nodeSentence.Comment = EditorHelper.SanitizeText(nodeSentence.Comment);
                }
                else if (node is DialogueNodeChoice)
                {
                    DialogueNodeChoice nodeChoice = node as DialogueNodeChoice;

                    //Sanitize texts
                    nodeChoice.Choice = EditorHelper.SanitizeText(nodeChoice.Choice);

                    nodeChoice.RepliesIDs.Clear();
                    foreach (DialogueNodeReply nodeReply in nodeChoice.Replies)
                    {
                        //Sanitize texts
                        nodeReply.Reply = EditorHelper.SanitizeText(nodeReply.Reply);

                        nodeChoice.RepliesIDs.Add(nodeReply.ID);
                    }
                }
                else if (node is DialogueNodeGoto)
                {
                    DialogueNodeGoto nodeGoto = node as DialogueNodeGoto;
                    nodeGoto.GotoID = (nodeGoto.Goto != null) ? nodeGoto.Goto.ID : DialogueNode.ID_NULL;
                }
                else if (node is DialogueNodeBranch)
                {
                    DialogueNodeBranch nodeBranch = node as DialogueNodeBranch;
                    nodeBranch.BranchID = (nodeBranch.Branch != null) ? nodeBranch.Branch.ID : DialogueNode.ID_NULL;
                }
            }
        }