added unreachable scene/action warnings

This commit is contained in:
Rudis Muiznieks 2015-07-19 17:19:40 -05:00
parent 4fc90cf8b7
commit f6021557fc
9 changed files with 65 additions and 2 deletions

View File

@ -1,6 +1,7 @@
namespace Ficdown.Console
{
using System;
using System.Linq;
using System.IO;
using Microsoft.SqlServer.Server;
using Parser;
@ -115,6 +116,11 @@
var story = parser.ParseStory(storyText);
story.Orphans.ToList().ForEach(o =>
{
Console.Error.WriteLine("Warning (line {0}): {1} {2} is unreachable", o.LineNumber, o.Type, o.Name);
});
IRenderer rend;
switch (format)
{

View File

@ -4,6 +4,7 @@
namespace Ficdown.Parser
{
using System;
using System.Linq;
using System.Collections.Generic;
using Model.Parser;
using Parser;
@ -38,7 +39,19 @@ namespace Ficdown.Parser
var blocks = BlockHandler.ExtractBlocks(lines);
var story = BlockHandler.ParseBlocks(blocks);
GameTraverser.Story = story;
return StateResolver.Resolve(GameTraverser.Enumerate(), 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;
}
}
}

View File

@ -84,6 +84,7 @@
<Compile Include="Model\Parser\Line.cs" />
<Compile Include="Model\Parser\FicdownException.cs" />
<Compile Include="Parser\ParserExtensions.cs" />
<Compile Include="Model\Parser\Orphan.cs" />
</ItemGroup>
<ItemGroup>
<None Include="packages.config" />
@ -109,4 +110,4 @@
<Target Name="AfterBuild">
</Target>
-->
</Project>
</Project>

View File

@ -0,0 +1,9 @@
namespace Ficdown.Parser.Model.Parser
{
public class Orphan
{
public string Type { get; set; }
public string Name { get; set; }
public int LineNumber { get; set; }
}
}

View File

@ -8,5 +8,6 @@
public string Description { get; set; }
public string FirstPage { get; set; }
public IEnumerable<ResolvedPage> Pages { get; set; }
public IEnumerable<Orphan> Orphans { get; set; }
}
}

View File

@ -6,5 +6,6 @@
public string Toggle { get; set; }
public string Description { get; set; }
public int LineNumber { get; set; }
public bool Visited { get; set; }
}
}

View File

@ -10,5 +10,6 @@
public string Description { get; set; }
public IDictionary<string, bool> Conditions { get; set; }
public int LineNumber { get; set; }
public bool Visited { get; set; }
}
}

View File

@ -1,10 +1,12 @@
namespace Ficdown.Parser.Player
{
using System;
using System.Collections.Generic;
using System.Linq;
using Model.Player;
using Model.Story;
using Parser;
using Action = Model.Story.Action;
internal class GameTraverser : IGameTraverser
{
@ -13,6 +15,7 @@
private IDictionary<string, PageState> _processed;
private IDictionary<string, PageState> _compressed;
private IDictionary<int, Action> _actionMatrix;
private bool _wasRun = false;
private Story _story;
public Story Story
@ -29,8 +32,29 @@
}
}
public IEnumerable<Scene> OrphanedScenes
{
get
{
if(!_wasRun) throw new Exception("Call Enumerate() before getting orphans");
return _story.Scenes.SelectMany(l => l.Value, (l, s) => s).Where(s => !s.Visited);
}
}
public IEnumerable<Action> OrphanedActions
{
get
{
if(!_wasRun) throw new Exception("Call Enumerate() before getting orphans");
return _actionMatrix.Values.Where(a => !a.Visited);
}
}
public IEnumerable<PageState> Enumerate()
{
if(_wasRun) throw new Exception("Can't call Enumerate() more than once");
_wasRun = true;
// generate comprehensive enumeration
var initial = _manager.InitialState;
@ -97,11 +121,16 @@
private void ProcessState(StateQueueItem currentState)
{
currentState.Page.Scene.Visited = true;
var states = new HashSet<string>();
var anchors = Utilities.GetInstance(currentState.Page.Scene.Name, currentState.Page.Scene.LineNumber).ParseAnchors(currentState.Page.Scene.Description).ToList();
foreach (var action in GetActionsForPage(currentState.Page))
{
action.Visited = true;
anchors.AddRange(Utilities.GetInstance(action.Toggle, action.LineNumber).ParseAnchors(action.Description));
}
var conditionals =
anchors.SelectMany(
a => a.Href.Conditions != null ? a.Href.Conditions.Select(c => c.Key) : new string[] {})

View File

@ -8,5 +8,7 @@
{
Story Story { get; set; }
IEnumerable<PageState> Enumerate();
IEnumerable<Scene> OrphanedScenes { get; }
IEnumerable<Action> OrphanedActions { get; }
}
}