Class: Gamefic::Active::Cue

Inherits:
Object
  • Object
show all
Defined in:
lib/gamefic/active/cue.rb

Overview

The object that actors use to perform a scene.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(actor, key, narrative, **context) ⇒ Cue

Returns a new instance of Cue.

Parameters:



26
27
28
29
30
31
# File 'lib/gamefic/active/cue.rb', line 26

def initialize actor, key, narrative, **context
  @actor = actor
  @key = key
  @narrative = narrative
  @context = context
end

Instance Attribute Details

#actorActor (readonly)

Returns:



9
10
11
# File 'lib/gamefic/active/cue.rb', line 9

def actor
  @actor
end

#contextHash (readonly)

Returns:

  • (Hash)


18
19
20
# File 'lib/gamefic/active/cue.rb', line 18

def context
  @context
end

#keyClass<Scene::Base>, Symbol (readonly)

Returns:



12
13
14
# File 'lib/gamefic/active/cue.rb', line 12

def key
  @key
end

#narrativeNarrative (readonly)

Returns:



15
16
17
# File 'lib/gamefic/active/cue.rb', line 15

def narrative
  @narrative
end

#propsProps::Default? (readonly)

Returns:



21
22
23
# File 'lib/gamefic/active/cue.rb', line 21

def props
  @props
end

Instance Method Details

#finishvoid

This method returns an undefined value.



41
42
43
44
# File 'lib/gamefic/active/cue.rb', line 41

def finish
  props&.enter(actor.queue.shift&.strip)
  scene.finish
end

#outputProps::Output

Returns:



47
48
49
# File 'lib/gamefic/active/cue.rb', line 47

def output
  props&.output.clone.freeze || Props::Output::EMPTY
end

#preparevoid

This method returns an undefined value.



65
66
67
68
69
70
71
72
73
# File 'lib/gamefic/active/cue.rb', line 65

def prepare
  props.output.merge!({
                        scene: scene.to_hash,
                        prompt: props.prompt,
                        messages: actor.flush,
                        queue: actor.queue
                      })
  actor.narratives.player_output_blocks.each { |block| block.call actor, props.output }
end

#restartCue

Returns:



52
53
54
# File 'lib/gamefic/active/cue.rb', line 52

def restart
  Cue.new(actor, key, narrative, **context)
end

#sceneScene::Base

Returns:



76
77
78
79
80
81
82
83
# File 'lib/gamefic/active/cue.rb', line 76

def scene
  # @note This method always returns a new instance. Scenes identified
  #   by symbolic keys can be instances of anonymous classes that cannot
  #   be serialized, so memoizing them breaks snapshots.
  narrative&.prepare(key, actor, props, **context) ||
    try_unblocked_class ||
    raise("Failed to cue #{key.inspect} in #{narrative.inspect}")
end

#startvoid

This method returns an undefined value.



34
35
36
37
38
# File 'lib/gamefic/active/cue.rb', line 34

def start
  @props = scene.start
  prepare_output
  actor.rotate_cue
end

#to_sObject



60
61
62
# File 'lib/gamefic/active/cue.rb', line 60

def to_s
  scene.to_s
end

#typeObject



56
57
58
# File 'lib/gamefic/active/cue.rb', line 56

def type
  scene&.type
end