Esempio n. 1
0
        public Frame(string background, string image, string next, string music, string nameText, string text, string nextText, string cameraDirection, FrameImagePosition imagePosition, ConditionNode[] nextConditional, MicroscriptNode[] nextMicroscript, FrameOptions options, FrameScripts scripts, DialogueScene parentScene, Frame baseFrame, JToken rawData, IReadOnlyDictionary <string, object> extraData)
        {
            Background      = background;
            Image           = image;
            Next            = next;
            Music           = music;
            NameText        = nameText;
            Text            = text;
            NextText        = nextText;
            CameraDirection = cameraDirection;
            ImagePosition   = imagePosition;

            //I'm not sure why we clone these but I'm not fixing it in Dialogue 1.5
            if (nextConditional != null && nextConditional.Length > 0)
            {
                NextConditional = (ConditionNode[])nextConditional.Clone();
            }

            if (nextMicroscript != null && nextMicroscript.Length > 0)
            {
                NextMicroscript = (MicroscriptNode[])nextMicroscript.Clone();
            }

            Options = options;
            Scripts = scripts;

            ParentScene = parentScene;
            BaseFrame   = baseFrame;
            RawData     = rawData;

            ExtraData = extraData ?? new Dictionary <string, object>();
        }
Esempio n. 2
0
        public Frame(string background, string image, string next, string music, string nameText, string text, string nextText, string cameraDirection, FrameImagePosition imagePosition, ConditionNode[] nextConditional, MicroscriptNode[] nextMicroscript)
        {
            Background      = background;
            Image           = image;
            Next            = next;
            Music           = music;
            NameText        = nameText;
            Text            = text;
            NextText        = nextText;
            CameraDirection = cameraDirection;
            ImagePosition   = imagePosition;

            if (nextConditional != null && nextConditional.Length > 0)
            {
                NextConditional = (ConditionNode[])nextConditional.Clone();
            }

            if (nextMicroscript != null && nextMicroscript.Length > 0)
            {
                NextMicroscript = (MicroscriptNode[])nextMicroscript.Clone();
            }
        }
Esempio n. 3
0
        public static DialogueScene LoadDialogueFromString(string dialogueName, string text)
        {
            JObject jo = JObject.Parse(text);
            //Debug.Log(jo);

            //parse root node (scene)
            string             sBackground = string.Empty;
            string             sImage      = string.Empty;
            string             sMusic      = string.Empty;
            string             sNext       = string.Empty;
            string             sText       = string.Empty;
            string             sName       = string.Empty;
            string             sNextText   = string.Empty;
            string             sCameraDir  = string.Empty;
            FrameImagePosition sPosition   = FrameImagePosition.Center;

            if (jo["background"] != null)
            {
                sBackground = jo["background"].Value <string>();
            }
            if (jo["image"] != null)
            {
                sImage = jo["image"].Value <string>();
            }
            if (jo["music"] != null)
            {
                sMusic = jo["music"].Value <string>();
            }
            if (jo["default"] != null)
            {
                sNext = jo["default"].Value <string>();
            }
            if (jo["text"] != null)
            {
                sText = jo["text"].Value <string>();
            }
            if (jo["nameText"] != null)
            {
                sName = jo["nameText"].Value <string>();
            }
            if (jo["nextText"] != null)
            {
                sNextText = jo["nextText"].Value <string>();
            }
            if (jo["position"] != null)
            {
                if (Enum.TryParse(jo["position"].Value <string>(), true, out FrameImagePosition pos))
                {
                    sPosition = pos;
                }
            }
            Frame baseFrame = new Frame(sBackground, sImage, sNext, sMusic, sName, sText, sNextText, sCameraDir, sPosition, null, null);

            //parse frames
            Dictionary <string, Frame> frames = new Dictionary <string, Frame>();

            frames.Add(dialogueName, baseFrame);
            JObject jf = (JObject)jo["frames"];

            foreach (var x in jf)
            {
                try
                {
                    string key   = x.Key;
                    JToken value = x.Value;
                    Frame  f     = DialogueParser.ParseSingleFrame(value, baseFrame);
                    frames.Add(key, f);
                }
                catch (Exception e)
                {
                    Debug.Log($"Failed to parse frame \"{x.Key}\" in scene \"{dialogueName}\"!");
                    Debug.LogException(e);
                }
            }

            return(new DialogueScene(frames, sNext, sMusic));
        }
Esempio n. 4
0
        public static Frame ParseSingleFrame(JToken jt, Frame baseFrame)
        {
            string             background = baseFrame.Background;
            string             image      = baseFrame.Image;
            string             next       = baseFrame.Next;
            string             music      = baseFrame.Music;
            string             nameText   = baseFrame.NameText;
            string             text       = baseFrame.Text;
            string             nextText   = baseFrame.NextText;
            string             type       = null;
            string             cameraDir  = baseFrame.CameraDirection;
            FrameImagePosition position   = FrameImagePosition.Center;

            if (jt["background"] != null)
            {
                background = jt["background"].Value <string>();
            }
            if (jt["image"] != null)
            {
                image = jt["image"].Value <string>();
            }
            if (jt["next"] != null)
            {
                next = jt["next"].Value <string>();
            }
            if (jt["music"] != null)
            {
                music = jt["music"].Value <string>();
            }
            if (jt["nameText"] != null)
            {
                nameText = jt["nameText"].Value <string>();
            }
            if (jt["text"] != null)
            {
                text = jt["text"].Value <string>();
            }
            if (jt["nextText"] != null)
            {
                nextText = jt["nextText"].Value <string>();
            }
            if (jt["type"] != null)
            {
                type = jt["type"].Value <string>();
            }
            if (jt["cameraDir"] != null)
            {
                cameraDir = jt["cameraDir"].Value <string>();
            }

            if (jt["position"] != null)
            {
                if (Enum.TryParse(jt["position"].Value <string>(), true, out FrameImagePosition pos))
                {
                    position = pos;
                }
            }


            //load/parse conditionals and microscripts
            ConditionNode[]   conditional = null;
            MicroscriptNode[] microscript = null;

            if (jt["conditional"] != null)
            {
                List <ConditionNode> cList = new List <ConditionNode>();
                JArray ja = (JArray)jt["conditional"];
                foreach (var x in ja)
                {
                    try
                    {
                        cList.Add(ParseConditionNode(x));
                    }
                    catch (Exception e)
                    {
                        Debug.LogException(e);
                    }
                }
                conditional = cList.ToArray();
            }

            if (jt["microscript"] != null)
            {
                //TODO parse microscripts
                List <MicroscriptNode> nList = new List <MicroscriptNode>();
                JArray ja = (JArray)jt["microscript"];
                foreach (var x in ja)
                {
                    try
                    {
                        nList.Add(ParseMicroscript(x));
                    }
                    catch (Exception e)
                    {
                        Debug.LogWarning(e);
                    }
                }
                microscript = nList.ToArray();
            }

            if (type == "choice")
            {
                //parse choices if choice frame
                List <ChoiceNode> choices = new List <ChoiceNode>();
                JArray            ja      = (JArray)jt["choices"];
                foreach (var x in ja)
                {
                    choices.Add(ParseChoiceNode(x));
                }
                return(new ChoiceFrame(background, image, next, music, nameText, text, nextText, cameraDir, position, choices.ToArray(), conditional, microscript));
            }
            else if (type == "text")
            {
                return(new TextFrame(background, image, next, music, nameText, text, nextText, cameraDir, position, conditional, microscript));
            }
            else if (type == "blank")
            {
                return(new BlankFrame(background, image, next, music, nameText, text, nextText, cameraDir, position, conditional, microscript));
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Esempio n. 5
0
        public static Frame ParseSingleFrame(JToken jt, Frame baseFrame, DialogueScene parentScene)
        {
            string             background = baseFrame.Background;
            string             image      = baseFrame.Image;
            string             next       = baseFrame.Next;
            string             music      = baseFrame.Music;
            string             nameText   = baseFrame.NameText;
            string             text       = baseFrame.Text;
            string             nextText   = baseFrame.NextText;
            string             type       = null;
            string             cameraDir  = baseFrame.CameraDirection;
            FrameScripts       scripts    = new FrameScripts();
            FrameOptions       options    = new FrameOptions();
            FrameImagePosition position   = GameParams.UseDialoguePositionInheritance ? baseFrame.ImagePosition : FrameImagePosition.Center;
            IReadOnlyDictionary <string, object> extraData = null;

            if (jt["background"] != null)
            {
                background = jt["background"].Value <string>();
            }
            if (jt["image"] != null)
            {
                image = jt["image"].Value <string>();
            }
            if (jt["next"] != null)
            {
                next = jt["next"].Value <string>();
            }
            if (jt["music"] != null)
            {
                music = jt["music"].Value <string>();
                if (music == null)
                {
                    music = string.Empty;
                }
            }
            if (jt["nameText"] != null)
            {
                nameText = jt["nameText"].Value <string>();
            }
            if (jt["text"] != null)
            {
                text = jt["text"].Value <string>();
            }
            if (jt["nextText"] != null)
            {
                nextText = jt["nextText"].Value <string>();
            }
            if (jt["type"] != null)
            {
                type = jt["type"].Value <string>();
            }
            if (jt["cameraDir"] != null)
            {
                cameraDir = jt["cameraDir"].Value <string>();
            }

            if (jt["position"] != null)
            {
                if (Enum.TryParse(jt["position"].Value <string>(), true, out FrameImagePosition pos))
                {
                    position = pos;
                }
            }


            //load/parse conditionals and microscripts
            ConditionNode[]   conditional = null;
            MicroscriptNode[] microscript = null;

            if (jt["conditional"] != null)
            {
                List <ConditionNode> cList = new List <ConditionNode>();
                JArray ja = (JArray)jt["conditional"];
                foreach (var x in ja)
                {
                    try
                    {
                        cList.Add(ParseConditionNode(x));
                    }
                    catch (Exception e)
                    {
                        Debug.LogException(e);
                    }
                }
                conditional = cList.ToArray();
            }

            if (jt["microscript"] != null)
            {
                //TODO parse microscripts
                List <MicroscriptNode> nList = new List <MicroscriptNode>();
                JArray ja = (JArray)jt["microscript"];
                foreach (var x in ja)
                {
                    try
                    {
                        nList.Add(ParseMicroscript(x));
                    }
                    catch (Exception e)
                    {
                        Debug.LogWarning(e);
                    }
                }
                microscript = nList.ToArray();
            }

            //load/parse options and scripts nodes
            if (!jt["options"].IsNullOrEmpty())
            {
                options = ParseFrameOptions(jt["options"], baseFrame.Options);
            }
            else
            {
                options = new FrameOptions(baseFrame.Options); //because FrameOptions implements IReadOnlyDictionary this actually works
            }

            if (!jt["scripts"].IsNullOrEmpty())
            {
                scripts = ParseFrameScripts(jt["scripts"], baseFrame.Scripts);
            }
            else
            {
                scripts = new FrameScripts(baseFrame.Scripts); //TODO correctness?
            }

            if (!jt["ExtraData"].IsNullOrEmpty())
            {
                extraData = ParseExtraData(jt["ExtraData"], baseFrame.ExtraData);
            }
            else
            {
                extraData = baseFrame.ExtraData;
            }

            if (type == "choice")
            {
                //parse choices if choice frame
                List <ChoiceNode> choices = new List <ChoiceNode>();
                JArray            ja      = (JArray)jt["choices"];
                foreach (var x in ja)
                {
                    choices.Add(ParseChoiceNode(x));
                }
                return(new ChoiceFrame(background, image, next, music, nameText, text, nextText, cameraDir, position, choices.ToArray(), conditional, microscript, options, scripts, parentScene, baseFrame, jt, extraData));
            }
            else if (type == "image")
            {
                bool  allowSkip = true, hideSkip = false, useTimer = false;
                float timeToShow = 0;

                if (!jt["allowSkip"].IsNullOrEmpty() && jt["allowSkip"].Type == JTokenType.Boolean)
                {
                    allowSkip = jt["allowSkip"].ToObject <bool>();
                }

                if (!jt["hideSkip"].IsNullOrEmpty() && jt["hideSkip"].Type == JTokenType.Boolean)
                {
                    hideSkip = jt["hideSkip"].ToObject <bool>();
                }

                if (!jt["useTimer"].IsNullOrEmpty() && jt["useTimer"].Type == JTokenType.Boolean)
                {
                    useTimer = jt["useTimer"].ToObject <bool>();
                }

                if (!jt["timeToShow"].IsNullOrEmpty())
                {
                    timeToShow = jt["timeToShow"].ToObject <float>();
                }

                return(new ImageFrame(background, image, next, music, nameText, text, nextText, cameraDir, position, allowSkip, hideSkip, timeToShow, useTimer, conditional, microscript, options, scripts, parentScene, baseFrame, jt, extraData));
            }
            else if (type == "text")
            {
                bool  allowSkip = true, useTimer = false;
                float timeToShow = 0;

                if (!jt["allowSkip"].IsNullOrEmpty() && jt["allowSkip"].Type == JTokenType.Boolean)
                {
                    allowSkip = jt["allowSkip"].ToObject <bool>();
                }

                if (!jt["useTimer"].IsNullOrEmpty() && jt["useTimer"].Type == JTokenType.Boolean)
                {
                    useTimer = jt["useTimer"].ToObject <bool>();
                }

                if (!jt["timeToShow"].IsNullOrEmpty())
                {
                    timeToShow = jt["timeToShow"].ToObject <float>();
                }

                return(new TextFrame(background, image, next, music, nameText, text, nextText, cameraDir, position, allowSkip, timeToShow, useTimer, conditional, microscript, options, scripts, parentScene, baseFrame, jt, extraData));
            }
            else if (type == "blank")
            {
                return(new BlankFrame(background, image, next, music, nameText, text, nextText, cameraDir, position, conditional, microscript, options, scripts, parentScene, baseFrame, jt, extraData));
            }
            else
            {
                throw new NotImplementedException();
            }
        }
Esempio n. 6
0
 public ChoiceFrame(string background, string image, string next, string music, string nameText, string text, string nextText, string cameraDir, FrameImagePosition imagePosition, ChoiceNode[] choices, ConditionNode[] nextConditional, MicroscriptNode[] nextMicroscript, FrameOptions options, FrameScripts scripts, DialogueScene parentScene, Frame baseFrame, JToken rawData, IReadOnlyDictionary <string, object> extraData)
     : base(background, image, next, music, nameText, text, nextText, cameraDir, imagePosition, nextConditional, nextMicroscript, options, scripts, parentScene, baseFrame, rawData, extraData)
 {
     Choices = (ChoiceNode[])choices.Clone();
 }
Esempio n. 7
0
 public ImageFrame(string background, string image, string next, string music, string nameText, string text, string nextText, string cameraDir, FrameImagePosition imagePosition, bool allowSkip, bool hideSkip, float timeToShow, bool useTimer, ConditionNode[] nextConditional, MicroscriptNode[] nextMicroscript, FrameOptions options, FrameScripts scripts, DialogueScene parentScene, Frame baseFrame, JToken rawData, IReadOnlyDictionary <string, object> extraData)
     : base(background, image, next, music, nameText, text, nextText, cameraDir, imagePosition, nextConditional, nextMicroscript, options, scripts, parentScene, baseFrame, rawData, extraData)
 {
     AllowSkip  = allowSkip;
     HideSkip   = hideSkip;
     TimeToShow = timeToShow;
     UseTimer   = useTimer;
 }
Esempio n. 8
0
 public ChoiceFrame(string background, string image, string next, string music, string nameText, string text, string nextText, string cameraDir, FrameImagePosition imagePosition, ChoiceNode[] choices, ConditionNode[] nextConditional, MicroscriptNode[] nextMicroscript)
     : base(background, image, next, music, nameText, text, nextText, cameraDir, imagePosition, nextConditional, nextMicroscript)
 {
     Choices = (ChoiceNode[])choices.Clone();
 }
Esempio n. 9
0
 public TextFrame(string background, string image, string next, string music, string nameText, string text, string nextText, string cameraDir, FrameImagePosition imagePosition, ConditionNode[] nextConditional, MicroscriptNode[] nextMicroscript)
     : base(background, image, next, music, nameText, text, nextText, cameraDir, imagePosition, nextConditional, nextMicroscript)
 {
 }