Exemplo n.º 1
0
        public static MonologueNode ParseNode(JToken jt)
        {
            string line  = string.Empty;
            string audio = null;

            if (jt["line"] != null)
            {
                line = jt["line"].Value <string>();
            }

            if (jt["audio"] != null)
            {
                audio = jt["audio"].Value <string>();
            }

            List <Conditional> cList = new List <Conditional>();

            if (jt["conditions"] != null)
            {
                JArray conditionJArray = (JArray)jt["conditions"];
                foreach (JToken conditionJT in conditionJArray)
                {
                    try
                    {
                        cList.Add(DialogueParser.ParseSingleCondition(conditionJT));
                    }
                    catch (Exception e)
                    {
                        Debug.LogException(e);
                    }
                }
            }

            List <MicroscriptNode> mList = new List <MicroscriptNode>();

            if (jt["microscripts"] != null)
            {
                JArray microscriptJArray = (JArray)jt["microscripts"];
                foreach (JToken microscriptJT in microscriptJArray)
                {
                    try
                    {
                        mList.Add(DialogueParser.ParseMicroscript(microscriptJT));
                    }
                    catch (Exception e)
                    {
                        Debug.LogException(e);
                    }
                }
            }

            return(new MonologueNode(line, audio, cList.ToArray(), mList.ToArray()));
        }
Exemplo n.º 2
0
        /// <summary>
        /// Gets a dialogue by name
        /// </summary>
        public DialogueScene GetDialogue(string name)
        {
            DialogueScene ds;

            if (!LoadedDialogues.TryGetValue(name, out ds))
            {
                ds = DialogueParser.LoadDialogue(name);
                LoadedDialogues.Add(name, ds);
                CDebug.LogEx("Loaded new dialogue " + name, LogLevel.Verbose, this);
            }
            return(ds);
        }
Exemplo n.º 3
0
        internal static DialogueScene GetDialogue(string name)
        {
            DialogueScene ds;

            if (!Instance.LoadedDialogues.TryGetValue(name, out ds))
            {
                ds = DialogueParser.LoadDialogue(name);
                Instance.LoadedDialogues.Add(name, ds);
                CDebug.LogEx("Loaded new dialogue " + name, LogLevel.Verbose, Instance);
            }
            return(ds);
        }
Exemplo n.º 4
0
        private void LoadAll()
        {
            if (CoreParams.LoadPolicy != DataLoadPolicy.OnStart)
            {
                return;
            }

            int dialoguesLoaded = 0, monologuesLoaded = 0;

            TextAsset[] tas = CoreUtils.LoadResources <TextAsset>("Data/Dialogue/");
            foreach (var ta in tas)
            {
                try
                {
                    LoadedDialogues.Add(ta.name, DialogueParser.LoadDialogueFromString(ta.name, ta.text));
                    CDebug.LogEx("Loaded dialogue " + ta.name, LogLevel.Verbose, this);
                    dialoguesLoaded++;
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                }
            }

            TextAsset[] tasm = CoreUtils.LoadResources <TextAsset>("Data/Monologue/");
            foreach (var ta in tasm)
            {
                try
                {
                    LoadedMonologues.Add(ta.name, MonologueParser.LoadMonologueFromString(ta.text));
                    CDebug.LogEx("Loaded monologue " + ta.name, LogLevel.Verbose, this);
                    monologuesLoaded++;
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                }
            }

            Log($"Loaded {dialoguesLoaded} dialogues, {monologuesLoaded} monologues");
        }
Exemplo n.º 5
0
        private void LoadFromTextAssets(IEnumerable <TextAsset> dialogueAssets, IEnumerable <TextAsset> monologueAssets)
        {
            int dialoguesLoaded = 0, monologuesLoaded = 0;

            foreach (var ta in dialogueAssets)
            {
                try
                {
                    LoadedDialogues[ta.name] = DialogueParser.LoadDialogueFromString(ta.name, ta.text);
                    if (ConfigState.Instance.UseVerboseLogging)
                    {
                        CDebug.LogEx("Loaded dialogue " + ta.name, LogLevel.Verbose, this);
                    }
                    dialoguesLoaded++;
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                }
            }

            foreach (var ta in monologueAssets)
            {
                try
                {
                    LoadedMonologues[ta.name] = MonologueParser.LoadMonologueFromString(ta.text);
                    if (ConfigState.Instance.UseVerboseLogging)
                    {
                        CDebug.LogEx("Loaded monologue " + ta.name, LogLevel.Verbose, this);
                    }
                    monologuesLoaded++;
                }
                catch (Exception e)
                {
                    Debug.LogException(e);
                }
            }

            Log($"Loaded {dialoguesLoaded} dialogues, {monologuesLoaded} monologues");
        }
Exemplo n.º 6
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));
        }