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;
|
2014-08-09 15:18:31 -05:00
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
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-09 15:18:31 -05:00
|
|
|
|
public IEnumerable<ResolvedPage> 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-09 15:18:31 -05:00
|
|
|
|
GameTraverser.Story = BlockHandler.ParseBlocks(blocks);
|
|
|
|
|
return StateResolver.Resolve(GameTraverser.Enumerate());
|
2014-06-29 23:04:51 -05:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|