Class: Gamefic::Scene::ActiveChoice
- Inherits:
-
MultipleChoice
- Object
- Base
- MultipleChoice
- Gamefic::Scene::ActiveChoice
- Defined in:
- lib/gamefic/scene/active_choice.rb
Overview
A scene that presents a list of optional choices. The scene can still attempt to process input that does not match any of the options.
Authors can use the ‘without_selection` class method to select one of three actions to take when the user does not enter one of the options: `:perform`, `:recue`, or `:continue`.
Constant Summary collapse
- WITHOUT_SELECTION_ACTIONS =
%i[perform recue continue].freeze
Instance Attribute Summary
Attributes inherited from Base
#actor, #context, #name, #narrative, #props
Class Method Summary collapse
- .inherited(klass) ⇒ Object
- .type ⇒ Object
-
.without_selection(action) ⇒ Object
Select the behavior for input that does not match a selectable option.
- .without_selection_action ⇒ Symbol
Instance Method Summary collapse
Methods inherited from MultipleChoice
Methods inherited from Base
finish_blocks, #initialize, on_finish, on_start, props_class, #rename, rename, #start, start_blocks, #to_hash, #type
Constructor Details
This class inherits a constructor from Gamefic::Scene::MultipleChoice
Class Method Details
.inherited(klass) ⇒ Object
54 55 56 57 |
# File 'lib/gamefic/scene/active_choice.rb', line 54 def self.inherited(klass) super klass.without_selection without_selection_action end |
.type ⇒ Object
27 28 29 |
# File 'lib/gamefic/scene/active_choice.rb', line 27 def self.type 'ActiveChoice' end |
.without_selection(action) ⇒ Object
Select the behavior for input that does not match a selectable option. The available settings are ‘:perform`, `:recue`, and `:continue`.
-
‘:perform` - Skip the `on_finish` blocks and try to perform the input as a command. This is the default behavior.
-
‘:recue` - Restart the scene until the user makes a valid selection. This is the same behavior as a `MultipleChoice` scene.
-
‘:continue` - Execute the `on_finish` blocks regardless of whether the input matches an option.
42 43 44 45 46 47 |
# File 'lib/gamefic/scene/active_choice.rb', line 42 def self.without_selection(action) WITHOUT_SELECTION_ACTIONS.include?(action) || raise(ArgumentError, "without_selection_action must be one of #{WITHOUT_SELECTION_ACTIONS.map(&:inspect).join_or}") @without_selection_action = action end |
.without_selection_action ⇒ Symbol
50 51 52 |
# File 'lib/gamefic/scene/active_choice.rb', line 50 def self.without_selection_action @without_selection_action ||= :perform end |
Instance Method Details
#finish ⇒ Object
17 18 19 20 21 |
# File 'lib/gamefic/scene/active_choice.rb', line 17 def finish return super if props.selected? send(self.class.without_selection_action) end |
#without_selection_action ⇒ Object
23 24 25 |
# File 'lib/gamefic/scene/active_choice.rb', line 23 def without_selection_action self.class.without_selection_action end |