Yarn is a singleton object that serves as a container for the story.

It captures and processes user input in the form of keyboard entry, mouse clicks, and drag and drop.

  1. User input is packaged into a twist object, containg the input text, viewpoint (typically "player"), and moment in time from the yarn's clock.
  2. The twist is pushed to the yarn's history array. (The history array is used for redo/undo purposes.)
  3. The plotpoint associated with the input event is unfolded with the twist as the argument.

    A plotpoint has a narration property which may be text or a Phrase. A plotpoint has an unfold method.

    A Plotpoint unfolds a twist and returns zero or more episodes in an array.

    An episode is a call-back function. Optionally, a numeric value may be assigned to the episode's salience property and a moment may be assigned for defered execution.

    The default behavior of a plotpoint's unfold method is to send the twist to each plotpoint in the plotpoint's subplot, gather any episodes generated by the subplot into an array sorted by salience and return

    The main plotpoint

    1. calls the parser to analyze the input
    2. create a twist consisting of the user's parsed input (i.e., the command)
    3. unfolds each command's plotpoint and concats the returned episodes
    4. introduces the most salient episode to the yarn's storyline.
    5. calls Yarn's tell method with the view point of the twist.
      1. The yarn's tell method: For each associated with the current viewpoint, check the clock has advanced far enought that the episode's moment equals or is less than the current episode. Execute the episode. If the episode returns a falsy value, remove it from the storyline. Advance the yarn's clock one tick. Repeat until the queue for the current viewpoint is exhausted.