Class: Gamefic::Scene::MultipleChoice

Inherits:
Custom show all
Defined in:
lib/gamefic/scene/multiple_choice.rb

Overview

Provide a list of options and process the selection in the scene’s finish block. After the scene is finished, the :active scene will be cued unless some other scene has already been prepared or cued.

The finish block’s input parameter receives a MultipleChoice::Input object instead of a String.

Direct Known Subclasses

MultipleScene

Instance Attribute Summary collapse

Attributes inherited from Base

#actor, #data, #input, #prompt, #type

Instance Method Summary collapse

Methods inherited from Base

#[], #finished?, #initialize, #on_finish, on_start, #start, start_block, subclass, #tracked=, #tracked?, tracked?, #update

Constructor Details

This class inherits a constructor from Gamefic::Scene::Base

Instance Attribute Details

#indexInteger (readonly)

The zero-based index of the selected option.



13
14
15
# File 'lib/gamefic/scene/multiple_choice.rb', line 13

def index
  @index
end

#invalid_messageString

The text to display when an invalid selection is received.



52
53
54
# File 'lib/gamefic/scene/multiple_choice.rb', line 52

def invalid_message
  @invalid_message ||= 'That is not a valid choice.'
end

#numberNumber (readonly)

The one-based index of the selected option.



18
19
20
# File 'lib/gamefic/scene/multiple_choice.rb', line 18

def number
  @number
end

#selectionString (readonly)

The full text of the selected option.



23
24
25
# File 'lib/gamefic/scene/multiple_choice.rb', line 23

def selection
  @selection
end

Instance Method Details

#finishObject



32
33
34
35
36
37
38
39
40
# File 'lib/gamefic/scene/multiple_choice.rb', line 32

def finish
  get_choice
  if selection.nil?
    actor.tell invalid_message
    tell_options
  else
    super
  end
end

#optionsArray<String>

The array of available options.



45
46
47
# File 'lib/gamefic/scene/multiple_choice.rb', line 45

def options
  @options ||= []
end

#post_initializeObject



27
28
29
30
# File 'lib/gamefic/scene/multiple_choice.rb', line 27

def post_initialize
  self.type = 'MultipleChoice'
  self.prompt = 'Enter a choice:'
end

#stateObject



56
57
58
# File 'lib/gamefic/scene/multiple_choice.rb', line 56

def state
  super.merge options: options
end