Newer
Older
TheVengeance-Project-IADE-Unity2D / Assets / Ink / InkLibs / InkCompiler / Stats.cs
  1. namespace Ink {
  2. public struct Stats {
  3. public int words;
  4. public int knots;
  5. public int stitches;
  6. public int functions;
  7. public int choices;
  8. public int gathers;
  9. public int diverts;
  10. public static Stats Generate(Ink.Parsed.Story story) {
  11. var stats = new Stats();
  12. var allText = story.FindAll<Ink.Parsed.Text>();
  13. // Count all the words across all strings
  14. stats.words = 0;
  15. foreach(var text in allText) {
  16. var wordsInThisStr = 0;
  17. var wasWhiteSpace = true;
  18. foreach(var c in text.text) {
  19. if( c == ' ' || c == '\t' || c == '\n' || c == '\r' ) {
  20. wasWhiteSpace = true;
  21. } else if( wasWhiteSpace ) {
  22. wordsInThisStr++;
  23. wasWhiteSpace = false;
  24. }
  25. }
  26. stats.words += wordsInThisStr;
  27. }
  28. var knots = story.FindAll<Ink.Parsed.Knot>();
  29. stats.knots = knots.Count;
  30. stats.functions = 0;
  31. foreach(var knot in knots)
  32. if (knot.isFunction) stats.functions++;
  33. var stitches = story.FindAll<Ink.Parsed.Stitch>();
  34. stats.stitches = stitches.Count;
  35. var choices = story.FindAll<Ink.Parsed.Choice>();
  36. stats.choices = choices.Count;
  37. // Skip implicit gather that's generated at top of story
  38. // (we know which it is because it isn't assigned debug metadata)
  39. var gathers = story.FindAll<Ink.Parsed.Gather>(g => g.debugMetadata != null);
  40. stats.gathers = gathers.Count;
  41. // May not be entirely what you expect.
  42. // Does it nevertheless have value?
  43. // Includes:
  44. // - DONE, END
  45. // - Function calls
  46. // - Some implicitly generated weave diverts
  47. // But we subtract one for the implicit DONE
  48. // at the end of the main flow outside of knots.
  49. var diverts = story.FindAll<Ink.Parsed.Divert>();
  50. stats.diverts = diverts.Count - 1;
  51. return stats;
  52. }
  53. }
  54. }