Beispiel #1
0
        public ResolvedStory ParseStory(string storyText)
        {
            var lines = storyText.Split(new[] { "\n", "\r\n" }, StringSplitOptions.None);

            _logger.Debug($"Parsed {lines.Length} lines.");
            var blocks = BlockHandler.ExtractBlocks(lines);

            _logger.Debug($"Extracted {blocks.Count()} blocks.");
            var story = BlockHandler.ParseBlocks(blocks);

            _logger.Debug("Finished initial story breakdown.");

            // dupe scene sanity check
            foreach (var key in story.Scenes.Keys)
            {
                foreach (var scene in story.Scenes[key])
                {
                    foreach (var otherScene in story.Scenes[key].Where(s => s != scene))
                    {
                        if ((scene.Conditions == null && otherScene.Conditions == null) ||
                            (scene.Conditions != null && otherScene.Conditions != null &&
                             scene.Conditions.Count == otherScene.Conditions.Count &&
                             !scene.Conditions.Except(otherScene.Conditions).Any()))
                        {
                            Warnings.Add(new FicdownException(scene.Name, string.Format("Scene defined again on line {0}", otherScene.LineNumber), scene.LineNumber));
                        }
                    }
                }
            }

            GameTraverser.Story = story;
            var resolved = StateResolver.Resolve(GameTraverser.Enumerate(), story);

            resolved.Orphans = GameTraverser.OrphanedScenes.Select(o => new Orphan
            {
                Type       = "Scene",
                Name       = o.Name,
                LineNumber = o.LineNumber
            }).Union(GameTraverser.OrphanedActions.Select(o => new Orphan
            {
                Type       = "Action",
                Name       = o.Toggle,
                LineNumber = o.LineNumber
            }));
            return(resolved);
        }
Beispiel #2
0
        public ResolvedStory ParseStory(string storyText)
        {
            var lines  = storyText.Split(new[] { "\n", "\r\n" }, StringSplitOptions.None);
            var blocks = BlockHandler.ExtractBlocks(lines);
            var story  = BlockHandler.ParseBlocks(blocks);

            GameTraverser.Story = story;
            var resolved = StateResolver.Resolve(GameTraverser.Enumerate(), story);

            resolved.Orphans = GameTraverser.OrphanedScenes.Select(o => new Orphan
            {
                Type       = "Scene",
                Name       = o.Name,
                LineNumber = o.LineNumber
            }).Union(GameTraverser.OrphanedActions.Select(o => new Orphan
            {
                Type       = "Action",
                Name       = o.Toggle,
                LineNumber = o.LineNumber
            }));
            return(resolved);
        }