Class: Gamefic::Active::Cue
- Inherits:
-
Object
- Object
- Gamefic::Active::Cue
- Defined in:
- lib/gamefic/active/cue.rb
Overview
The object that actors use to perform a scene.
Instance Attribute Summary collapse
- #actor ⇒ Actor readonly
- #context ⇒ Hash readonly
- #key ⇒ Class<Scene::Base>, Symbol readonly
- #narrative ⇒ Narrative readonly
- #props ⇒ Props::Default? readonly
Instance Method Summary collapse
- #finish ⇒ void
-
#initialize(actor, key, narrative, **context) ⇒ Cue
constructor
A new instance of Cue.
- #output ⇒ Props::Output
- #prepare ⇒ void
- #restart ⇒ Cue
- #scene ⇒ Scene::Base
- #start ⇒ void
- #to_s ⇒ Object
- #type ⇒ Object
Constructor Details
#initialize(actor, key, narrative, **context) ⇒ Cue
Returns a new instance of Cue.
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
#context ⇒ Hash (readonly)
18 19 20 |
# File 'lib/gamefic/active/cue.rb', line 18 def context @context end |
#key ⇒ Class<Scene::Base>, Symbol (readonly)
12 13 14 |
# File 'lib/gamefic/active/cue.rb', line 12 def key @key end |
#narrative ⇒ Narrative (readonly)
15 16 17 |
# File 'lib/gamefic/active/cue.rb', line 15 def narrative @narrative end |
#props ⇒ Props::Default? (readonly)
21 22 23 |
# File 'lib/gamefic/active/cue.rb', line 21 def props @props end |
Instance Method Details
#finish ⇒ void
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 |
#output ⇒ Props::Output
47 48 49 |
# File 'lib/gamefic/active/cue.rb', line 47 def output props&.output.clone.freeze || Props::Output::EMPTY end |
#prepare ⇒ void
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 |
#restart ⇒ Cue
52 53 54 |
# File 'lib/gamefic/active/cue.rb', line 52 def restart Cue.new(actor, key, narrative, **context) end |
#scene ⇒ Scene::Base
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 |
#start ⇒ void
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_s ⇒ Object
60 61 62 |
# File 'lib/gamefic/active/cue.rb', line 60 def to_s scene.to_s end |
#type ⇒ Object
56 57 58 |
# File 'lib/gamefic/active/cue.rb', line 56 def type scene&.type end |