Exemplo n.º 1
0
        public static string GetDialogue(string npc, string area, string scene, int id = -1)
        {
            if (!_sceneTree.ContainsKey(npc))
            {
                return($"Missing npc {npc}");
            }

            DialogueNPC dn = _sceneTree[npc];

            DialogueArea a = dn.GetArea(area);

            if (a == null)
            {
                return($"Missing area {area}");
            }

            DialogueScene s = a.GetScene(scene);

            if (s == null)
            {
                return($"Missing scene {scene}");
            }

            return(ReplaceKeys(s.GetDialogue(id)));
        }
Exemplo n.º 2
0
        private static DialogueScene GetScene(string npc, string area, string scene)
        {
            DialogueNPC dn = SceneTree[npc];

            DialogueArea a = dn.GetArea(area);

            return(a.GetScene(scene));
        }
Exemplo n.º 3
0
        public static void Reload()
        {
            var assembly = Assembly.GetExecutingAssembly();

            string path = $"{assembly.GetName().Name}.{DialogueFilePath}_{Enum.GetName(GlobalState.CurrentLanguage.GetType(), GlobalState.CurrentLanguage)}.txt";

            ParseState state = ParseState.START;

            Dictionary <string, DialogueNPC> newSceneTree = new Dictionary <string, DialogueNPC>();

            DialogueNPC npc      = null;
            string      npcName  = "";
            string      areaName = "";
            string      scene    = "";

            List <string> dialogue = new List <string>();
            int?          loopID   = null;
            bool          alignTop = false;

            using Stream stream       = assembly.GetManifestResourceStream(path);
            using StreamReader reader = new StreamReader(stream);
            while (!reader.EndOfStream)
            {
                string line = reader.ReadLine().Trim();

                if (line.StartsWith("#"))
                {
                    continue;
                }

                switch (state)
                {
                case ParseState.START:
                    if (line.StartsWith("npc"))
                    {
                        npc     = new DialogueNPC();
                        state   = ParseState.NPC;
                        npcName = GetName(line);
                        newSceneTree.Add(npcName, npc);
                    }
                    break;

                case ParseState.NPC:
                    if (line == "does reset")
                    {
                        npc.doesReset = true;
                        continue;
                    }
                    if (line == "end npc")
                    {
                        state = ParseState.START;
                        continue;
                    }
                    if (line.StartsWith("area"))
                    {
                        areaName = GetName(line);
                        state    = ParseState.AREA;
                        npc.AddArea(areaName);
                    }
                    break;

                case ParseState.AREA:
                    if (line == "end area")
                    {
                        state = ParseState.NPC;
                        continue;
                    }
                    if (line.StartsWith("scene"))
                    {
                        scene = GetName(line);
                        state = ParseState.SCENE;

                        loopID   = null;
                        dialogue = new List <string>();
                        alignTop = false;
                    }
                    break;

                case ParseState.SCENE:
                    if (string.IsNullOrWhiteSpace(line))
                    {
                        continue;
                    }

                    if (line == "TOP")
                    {
                        alignTop = true;
                        continue;
                    }
                    if (line == "end scene")
                    {
                        state = ParseState.AREA;
                        DialogueScene s = new(alignTop, loopID, dialogue);
                        npc.GetArea(areaName).AddScene(scene, s);
                        if (SceneTree != null)
                        {
                            s.state = GetScene(npcName, areaName, scene).state;
                        }
                        continue;
                    }
                    if (line == "LOOP")
                    {
                        loopID = dialogue.Count;
                        continue;
                    }
                    dialogue.Add(line);
                    break;
                }
            }
            SceneTree = newSceneTree;
        }