示例#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>();
        }
示例#2
0
        public static FrameOptions ParseFrameOptions(JToken jToken, FrameOptions baseOptions)
        {
            if (jToken.Type != JTokenType.Object)
            {
                throw new InvalidOperationException("JToken must be an object!");
            }

            Dictionary <string, object> dictionary = new Dictionary <string, object>();

            using (var sr = jToken.CreateReader())
            {
                dictionary = JsonSerializer.Create(CoreParams.DefaultJsonSerializerSettings).Deserialize <Dictionary <string, object> >(sr);
            }

            if (baseOptions != null)
            {
                return(new FrameOptions(baseOptions, dictionary));
            }
            return(new FrameOptions(dictionary));
        }
示例#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;
            FrameOptions       sOptions    = new FrameOptions();
            FrameScripts       sScripts    = new FrameScripts();
            IReadOnlyDictionary <string, object> sExtraData = null;

            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 (sMusic == null)
                {
                    sMusic = string.Empty;
                }
            }
            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;
                }
            }
            if (!jo["options"].IsNullOrEmpty())
            {
                sOptions = ParseFrameOptions(jo["options"], null);
            }
            if (!jo["scripts"].IsNullOrEmpty())
            {
                sScripts = ParseFrameScripts(jo["scripts"], null);
            }
            if (!jo["ExtraData"].IsNullOrEmpty())
            {
                sExtraData = ParseExtraData(jo["ExtraData"], null);
            }

            Dictionary <string, Frame> frames = new Dictionary <string, Frame>();
            var scene = new DialogueScene(frames, sNext, sMusic);

            Frame baseFrame = new Frame(sBackground, sImage, sNext, sMusic, sName, sText, sNextText, sCameraDir, sPosition, null, null, sOptions, sScripts, scene, null, jo, sExtraData);

            //parse frames
            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, scene);
                    frames.Add(key, f);
                }
                catch (Exception e)
                {
                    Debug.Log($"Failed to parse frame \"{x.Key}\" in scene \"{dialogueName}\"!");
                    Debug.LogException(e);
                }
            }

            return(scene);
        }
示例#4
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();
            }
        }
示例#5
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();
 }
示例#6
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;
 }
示例#7
0
 public FrameOptions(FrameOptions baseFrameOptions, IEnumerable <KeyValuePair <string, object> > options)
 {
     Options = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase);
     Options.AddRange(baseFrameOptions.Options); //note this does not deep copy!
     Options.AddRangeReplaceExisting(options);   //and neither does this!
 }