Class: Gamefic::Scene::MultipleChoice
- 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
Instance Attribute Summary collapse
-
#index ⇒ Integer
readonly
The zero-based index of the selected option.
-
#invalid_message ⇒ String
The text to display when an invalid selection is received.
-
#number ⇒ Integer
readonly
The one-based index of the selected option.
-
#selection ⇒ String
readonly
The full text of the selected option.
Attributes inherited from Base
#actor, #data, #input, #prompt, #type
Instance Method Summary collapse
- #finish ⇒ Object
-
#options ⇒ Array<String>
The array of available options.
- #post_initialize ⇒ Object
- #state ⇒ Object
Methods inherited from Base
#[], #finished?, #initialize, #on_finish, on_start, #start, start_block, subclass, #tracked=, #tracked?, tracked?, #update
Methods included from Gamefic::Serialize
#serialized_class, string_to_constant, #to_serial
Constructor Details
This class inherits a constructor from Gamefic::Scene::Base
Instance Attribute Details
#index ⇒ Integer (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_message ⇒ String
The text to display when an invalid selection is received.
51 52 53 |
# File 'lib/gamefic/scene/multiple_choice.rb', line 51 def @invalid_message ||= 'That is not a valid choice.' end |
#number ⇒ Integer (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 |
#selection ⇒ String (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
#finish ⇒ Object
32 33 34 35 36 37 38 39 |
# File 'lib/gamefic/scene/multiple_choice.rb', line 32 def finish get_choice if selection.nil? actor.tell else super end end |
#options ⇒ Array<String>
The array of available options.
44 45 46 |
# File 'lib/gamefic/scene/multiple_choice.rb', line 44 def @options ||= [] end |
#post_initialize ⇒ Object
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 |
#state ⇒ Object
55 56 57 |
# File 'lib/gamefic/scene/multiple_choice.rb', line 55 def state super.merge options: end |