engine.d.ts 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. export interface EngineAPI {
  2. /**
  3. * Returns a timestamp representing the last time Engine.play() was called.
  4. * @since 2.0.0
  5. */
  6. readonly lastPlay: number;
  7. /**
  8. * Returns the current state of the engine ("idle", "playing", "rendering").
  9. * States:
  10. * * "idle": The engine is idle, awaiting the triggering of passage navigation—the default state.
  11. * * "playing": Passage navigation has been triggered and a turn is being processed.
  12. * * "rendering": The incoming passage is being rendered and added to the page—takes place during turn processing,
  13. * so implies "playing".
  14. * @since 2.7.0
  15. */
  16. readonly state: "idle" | "playing" | "rendering";
  17. /**
  18. * Moves backward one moment within the full history (past + future), if possible, activating and showing the
  19. * moment moved to. Returns whether the history navigation was successful (should only fail if already at the
  20. * beginning of the full history).
  21. * @since 2.0.0
  22. */
  23. backward(): boolean;
  24. /**
  25. * Moves forward one moment within the full history (past + future), if possible, activating and showing the moment
  26. * moved to. Returns whether the history navigation was successful (should only fail if already at the end of the
  27. * full history).
  28. * @since 2.0.0
  29. */
  30. forward(): boolean;
  31. /**
  32. * Activates the moment at the given offset from the active (present) moment within the full state history and show
  33. * it. Returns whether the history navigation was successful (should only fail if the offset from the active
  34. * (present) moment is not within the bounds of the full history).
  35. * @param offset The offset from the active (present) moment of the moment to go to.
  36. * @since 2.0.0
  37. */
  38. go(offset: number): boolean;
  39. /**
  40. * Activates the moment at the given index within the full state history and show it. Returns whether the history
  41. * navigation was successful (should only fail if the index is not within the bounds of the full history).
  42. * @param index The index of the moment to go to.
  43. * @since 2.0.0
  44. * @example
  45. * Engine.goTo(0) // Goes to the first moment
  46. * Engine.goTo(9) // Goes to the tenth moment
  47. */
  48. goTo(index: number): boolean;
  49. /**
  50. * Returns whether the engine is idle.
  51. * @since 2.16.0
  52. */
  53. isIdle(): boolean;
  54. /**
  55. * Returns whether the engine is processing a turn — i.e. passage navigation has been triggered.
  56. * @since 2.16.0
  57. */
  58. isPlaying(): boolean;
  59. /**
  60. * Returns whether the engine is rendering the incoming passage.
  61. * @since 2.16.0
  62. */
  63. isRendering(): boolean;
  64. /**
  65. * Renders and displays the passage referenced by the given title, optionally without adding a new moment to the
  66. * history.
  67. * @param passageTitle The title of the passage to play.
  68. * @param noHistory Disables the update of the history (i.e. no moment is added to the history).
  69. * @since 2.0.0
  70. */
  71. play(passageTitle: string, noHistory?: boolean): HTMLElement;
  72. /**
  73. * Restarts the story.
  74. *
  75. * WARNING: The player will not be prompted and all unsaved state will be lost.
  76. * NOTE: In general, you should not call this method directly. Instead, call the UI.restart() static method, which
  77. * prompts the player with an OK/Cancel dialog before itself calling Engine.restart(), if they accept.
  78. * @since 2.0.0
  79. */
  80. restart(): void;
  81. /**
  82. * Renders and displays the active (present) moment's associated passage without adding a new moment to the history.
  83. * @since 2.0.0
  84. */
  85. show(): HTMLElement;
  86. }
  87. export {};