Beispiel #1
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));
        }