Newer
Older
TheVengeance-Project-IADE-Unity2D / Assets / Ink / Editor / Tools / Player Window / InkHistoryContentItem.cs
  1. using System;
  2. using System.Collections.Generic;
  3. using Ink.Runtime;
  4. using UnityEngine;
  5. namespace Ink.UnityIntegration.Debugging {
  6. [System.Serializable]
  7. public class InkHistoryContentItem {
  8. public enum ContentType {
  9. PresentedContent,
  10. ChooseChoice,
  11. PresentedChoice,
  12. EvaluateFunction,
  13. CompleteEvaluateFunction,
  14. ChoosePathString,
  15. Warning,
  16. Error,
  17. DebugNote
  18. }
  19. public string content;
  20. public List<string> tags;
  21. public ContentType contentType;
  22. // Creating a datetime from a long is slightly expensive (it can happen many times in a frame). To fix this we cache the result once converted.
  23. [SerializeField] JsonDateTime _serializableTime;
  24. [NonSerialized] bool hasDeserializedTime;
  25. [NonSerialized] DateTime _time;
  26. public DateTime time {
  27. get {
  28. if (!hasDeserializedTime) {
  29. _time = _serializableTime;
  30. hasDeserializedTime = true;
  31. }
  32. return _time;
  33. } private set {
  34. _time = value;
  35. _serializableTime = value;
  36. }
  37. }
  38. InkHistoryContentItem (string text, ContentType contentType) {
  39. this.content = text;
  40. this.contentType = contentType;
  41. this.time = DateTime.Now;
  42. }
  43. InkHistoryContentItem (string text, List<string> tags, ContentType contentType) {
  44. this.content = text;
  45. this.tags = tags;
  46. this.contentType = contentType;
  47. this.time = DateTime.Now;
  48. }
  49. public static InkHistoryContentItem CreateForContent (string choiceText, List<string> tags) {
  50. return new InkHistoryContentItem(choiceText, tags, InkHistoryContentItem.ContentType.PresentedContent);
  51. }
  52. public static InkHistoryContentItem CreateForPresentChoice (Choice choice) {
  53. return new InkHistoryContentItem(choice.text.Trim(), choice.tags, InkHistoryContentItem.ContentType.PresentedChoice);
  54. }
  55. public static InkHistoryContentItem CreateForMakeChoice (Choice choice) {
  56. return new InkHistoryContentItem(choice.text.Trim(), choice.tags, InkHistoryContentItem.ContentType.ChooseChoice);
  57. }
  58. public static InkHistoryContentItem CreateForEvaluateFunction (string functionInfoText) {
  59. return new InkHistoryContentItem(functionInfoText, InkHistoryContentItem.ContentType.EvaluateFunction);
  60. }
  61. public static InkHistoryContentItem CreateForCompleteEvaluateFunction (string functionInfoText) {
  62. return new InkHistoryContentItem(functionInfoText, InkHistoryContentItem.ContentType.CompleteEvaluateFunction);
  63. }
  64. public static InkHistoryContentItem CreateForChoosePathString (string choosePathStringText) {
  65. return new InkHistoryContentItem(choosePathStringText, InkHistoryContentItem.ContentType.ChoosePathString);
  66. }
  67. public static InkHistoryContentItem CreateForWarning (string warningText) {
  68. return new InkHistoryContentItem(warningText, InkHistoryContentItem.ContentType.Warning);
  69. }
  70. public static InkHistoryContentItem CreateForError (string errorText) {
  71. return new InkHistoryContentItem(errorText, InkHistoryContentItem.ContentType.Error);
  72. }
  73. public static InkHistoryContentItem CreateForDebugNote (string noteText) {
  74. return new InkHistoryContentItem(noteText, InkHistoryContentItem.ContentType.DebugNote);
  75. }
  76. struct JsonDateTime {
  77. public long value;
  78. public static implicit operator DateTime(JsonDateTime jdt) {
  79. return DateTime.FromFileTime(jdt.value);
  80. }
  81. public static implicit operator JsonDateTime(DateTime dt) {
  82. JsonDateTime jdt = new JsonDateTime();
  83. jdt.value = dt.ToFileTime();
  84. return jdt;
  85. }
  86. }
  87. }
  88. }