2014-08-09 15:18:31 -05:00
|
|
|
|
using System.Runtime.CompilerServices;
|
|
|
|
|
[assembly: InternalsVisibleTo("Ficdown.Parser.Tests")]
|
|
|
|
|
|
|
|
|
|
namespace Ficdown.Parser
|
2014-06-29 23:04:51 -05:00
|
|
|
|
{
|
2014-07-01 01:51:08 -05:00
|
|
|
|
using System;
|
2015-07-19 17:19:40 -05:00
|
|
|
|
using System.Linq;
|
2014-08-09 15:18:31 -05:00
|
|
|
|
using Model.Parser;
|
2014-07-02 23:11:36 -05:00
|
|
|
|
using Parser;
|
2014-08-09 15:18:31 -05:00
|
|
|
|
using Player;
|
2014-06-29 23:04:51 -05:00
|
|
|
|
|
|
|
|
|
public class FicdownParser
|
|
|
|
|
{
|
|
|
|
|
private IBlockHandler _blockHandler;
|
2014-08-09 15:18:31 -05:00
|
|
|
|
internal IBlockHandler BlockHandler
|
2014-06-29 23:04:51 -05:00
|
|
|
|
{
|
|
|
|
|
get { return _blockHandler ?? (_blockHandler = new BlockHandler()); }
|
|
|
|
|
set { _blockHandler = value; }
|
|
|
|
|
}
|
|
|
|
|
|
2014-08-09 15:18:31 -05:00
|
|
|
|
private IGameTraverser _gameTraverser;
|
|
|
|
|
internal IGameTraverser GameTraverser
|
|
|
|
|
{
|
|
|
|
|
get { return _gameTraverser ?? (_gameTraverser = new GameTraverser()); }
|
|
|
|
|
set { _gameTraverser = value; }
|
|
|
|
|
}
|
2014-06-30 11:59:56 -05:00
|
|
|
|
|
2014-08-09 15:18:31 -05:00
|
|
|
|
private IStateResolver _stateResolver;
|
|
|
|
|
internal IStateResolver StateResolver
|
2014-06-30 11:59:56 -05:00
|
|
|
|
{
|
2014-07-02 23:11:36 -05:00
|
|
|
|
get { return _stateResolver ?? (_stateResolver = new StateResolver()); }
|
|
|
|
|
set { _stateResolver = value; }
|
2014-06-30 11:59:56 -05:00
|
|
|
|
}
|
|
|
|
|
|
2014-08-10 17:32:13 -05:00
|
|
|
|
public ResolvedStory ParseStory(string storyText)
|
2014-06-29 23:04:51 -05:00
|
|
|
|
{
|
2014-07-01 01:51:08 -05:00
|
|
|
|
var lines = storyText.Split(new[] {"\n", "\r\n"}, StringSplitOptions.None);
|
2014-06-29 23:04:51 -05:00
|
|
|
|
var blocks = BlockHandler.ExtractBlocks(lines);
|
2014-08-10 11:10:21 -05:00
|
|
|
|
var story = BlockHandler.ParseBlocks(blocks);
|
|
|
|
|
GameTraverser.Story = story;
|
2015-07-19 17:19:40 -05:00
|
|
|
|
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;
|
2014-06-29 23:04:51 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|