- namespace Ink {
- public struct Stats {
- public int words;
- public int knots;
- public int stitches;
- public int functions;
- public int choices;
- public int gathers;
- public int diverts;
- public static Stats Generate(Ink.Parsed.Story story) {
- var stats = new Stats();
- var allText = story.FindAll<Ink.Parsed.Text>();
-
- stats.words = 0;
- foreach(var text in allText) {
- var wordsInThisStr = 0;
- var wasWhiteSpace = true;
- foreach(var c in text.text) {
- if( c == ' ' || c == '\t' || c == '\n' || c == '\r' ) {
- wasWhiteSpace = true;
- } else if( wasWhiteSpace ) {
- wordsInThisStr++;
- wasWhiteSpace = false;
- }
- }
- stats.words += wordsInThisStr;
- }
- var knots = story.FindAll<Ink.Parsed.Knot>();
- stats.knots = knots.Count;
- stats.functions = 0;
- foreach(var knot in knots)
- if (knot.isFunction) stats.functions++;
- var stitches = story.FindAll<Ink.Parsed.Stitch>();
- stats.stitches = stitches.Count;
- var choices = story.FindAll<Ink.Parsed.Choice>();
- stats.choices = choices.Count;
-
-
- var gathers = story.FindAll<Ink.Parsed.Gather>(g => g.debugMetadata != null);
- stats.gathers = gathers.Count;
-
-
-
-
-
-
-
-
- var diverts = story.FindAll<Ink.Parsed.Divert>();
- stats.diverts = diverts.Count - 1;
- return stats;
- }
- }
- }