Class: Gamefic::Scene::Custom

Inherits:
Base
  • Object
show all
Defined in:
lib/gamefic/scene/custom.rb

Overview

A Custom Scene allows for complete configuration of its behavior upon instantiation. It is suitable for direct instantiation or subclassing.

Direct Known Subclasses

Conclusion, MultipleChoice, Pause, YesOrNo

Instance Method Summary collapse

Methods inherited from Base

#type

Constructor Details

#initialize {|_self| ... } ⇒ Custom

Returns a new instance of Custom.

Yields:

  • (_self)

Yield Parameters:



7
8
9
# File 'lib/gamefic/scene/custom.rb', line 7

def initialize
  yield self if block_given?
end

Instance Method Details

#data_classObject



11
12
13
# File 'lib/gamefic/scene/custom.rb', line 11

def data_class
  SceneData::Base
end

#finish(actor, input) ⇒ Object

End the scene. This method typically gets called from the plot during the on_update event.



54
55
56
57
# File 'lib/gamefic/scene/custom.rb', line 54

def finish actor, input
  data = finish_data_for(actor, input)
  do_finish_block actor, data
end

#on_finish {|, | ... } ⇒ Object

Define a block to be executed at the end of the scene. The scene data passed to this block will include the character’s input for this turn. Unlike on_start, finish only gets executed once per turn, during the plot’s on_update event.

Yield Parameters:



36
37
38
# File 'lib/gamefic/scene/custom.rb', line 36

def on_finish &block
  @finish = block
end

#on_start {|, | ... } ⇒ Object

Define a block to be executed at the start of the scene. Unlike on_finish, start blocks may be executed more than once per turn, and more than one scene may be started in a single turn. It always gets executed in a plot’s on_ready event and whenever it gets cued. (If the character is already in the scene being cued, on_start does not get repeated.)

Yield Parameters:



24
25
26
# File 'lib/gamefic/scene/custom.rb', line 24

def on_start &block
  @start = block
end

#prompt_for(actor) ⇒ String

Get the text to be displayed to the user when receiving input.

Returns:



62
63
64
65
# File 'lib/gamefic/scene/custom.rb', line 62

def prompt_for actor
  return character_data[actor].prompt unless character_data[actor].nil?
  '>'
end

#start(actor) ⇒ Object

Start the scene. This method typically gets called from the plot during the on_ready event and whenever a character cues a scene.



44
45
46
47
48
# File 'lib/gamefic/scene/custom.rb', line 44

def start actor
  data = start_data_for(actor)
  do_start_block actor, data
  data
end