Class: Gamefic::Subplot
Overview
Subplots are disposable plots that run inside a parent plot. They can be started and concluded at any time during the parent plot’s runtime.
Instance Attribute Summary collapse
- #config ⇒ Hash readonly
- #plot ⇒ Plot readonly
Attributes included from Gamefic::Scriptable::Scenes
#default_conclusion, #default_scene
Class Method Summary collapse
Instance Method Summary collapse
-
#branch(subplot_class = Gamefic::Subplot, introduce: [], **config) ⇒ Gamefic::Subplot
Start a new subplot based on the provided class.
- #conclude ⇒ Object
- #concluding? ⇒ Boolean
-
#configure ⇒ Object
Subclasses can override this method to handle additional configuration options.
-
#initialize(plot, introduce: [], **config) ⇒ Subplot
constructor
A new instance of Subplot.
- #inspect ⇒ Object
- #introduce(player) ⇒ Object
- #persistent? ⇒ Boolean
- #prepare ⇒ Object
- #seeds ⇒ Object
Methods inherited from Narrative
#cast, inherited, restore, #save, #turn, #uncast
Methods included from Scriptable
#included_scripts, #pick, #pick!
Methods included from Gamefic::Scriptable::Syntaxes
Methods included from Gamefic::Scriptable::Seeds
Methods included from Gamefic::Scriptable::Scenes
#active_choice, #block, #conclusion, #introduction, #introductions, #multiple_choice, #named_scenes, #pause, #scene_classes, #scene_classes_map, #scenes, #select_default_conclusion, #select_default_scene, #yes_or_no
Methods included from Gamefic::Scriptable::Responses
#meta, #respond, #responses, #responses_for, #verbs
Methods included from Gamefic::Scriptable::Queries
#available, #children, #descendants, #extended, #global, #integer, #myself, #parent, #plaintext, #siblings
Methods included from Gamefic::Scriptable::Hooks
#after_command, #after_commands, #before_command, #before_commands, #conclude_blocks, #on_conclude, #on_player_conclude, #on_player_output, #on_player_ready, #on_player_update, #on_ready, #on_update, #player_conclude_blocks, #player_output_blocks, #ready_blocks, #update_blocks
Methods included from Scripting
#find_and_bind, included, #included_scripts
Methods included from Gamefic::Scripting::Syntaxes
Methods included from Gamefic::Scripting::Scenes
#default_conclusion, #default_scene, #introductions, #named_scenes, #scene_class, #scenes
Methods included from Gamefic::Scripting::Responses
Methods included from Gamefic::Scripting::Hooks
#after_commands, #before_commands, #conclude_blocks, #player_conclude_blocks, #player_output_blocks, #ready_blocks, #update_blocks
Methods included from Gamefic::Scripting::Entities
#destroy, #entities, #find, #make, #pick, #pick!, #players
Methods included from Gamefic::Scripting::Proxies
Constructor Details
#initialize(plot, introduce: [], **config) ⇒ Subplot
Returns a new instance of Subplot.
19 20 21 22 23 24 25 26 27 |
# File 'lib/gamefic/subplot.rb', line 19 def initialize plot, introduce: [], **config @plot = plot @config = config configure @config.freeze super() @concluded = false [introduce].flatten.each { |plyr| self.introduce plyr } end |
Instance Attribute Details
#config ⇒ Hash (readonly)
11 12 13 |
# File 'lib/gamefic/subplot.rb', line 11 def config @config end |
Class Method Details
.persist! ⇒ Object
33 34 35 |
# File 'lib/gamefic/subplot.rb', line 33 def self.persist! @persistent = true end |
.persistent? ⇒ Boolean
37 38 39 |
# File 'lib/gamefic/subplot.rb', line 37 def self.persistent? @persistent ||= false end |
Instance Method Details
#branch(subplot_class = Gamefic::Subplot, introduce: [], **config) ⇒ Gamefic::Subplot
A subplot’s host is always the base plot, regardless of whether it was branched from another subplot.
Start a new subplot based on the provided class.
64 65 66 |
# File 'lib/gamefic/subplot.rb', line 64 def branch subplot_class = Gamefic::Subplot, introduce: [], **config plot.branch subplot_class, introduce: introduce, **config end |
#conclude ⇒ Object
45 46 47 48 49 50 51 52 53 |
# File 'lib/gamefic/subplot.rb', line 45 def conclude conclude_blocks.each(&:call) players.each do |plyr| player_conclude_blocks.each { |blk| blk[plyr] } uncast plyr end entities.each { |ent| destroy ent } @concluded = true end |
#concluding? ⇒ Boolean
73 74 75 76 77 |
# File 'lib/gamefic/subplot.rb', line 73 def concluding? return super unless persistent? @concluded end |
#configure ⇒ Object
Subclasses can override this method to handle additional configuration options.
71 |
# File 'lib/gamefic/subplot.rb', line 71 def configure; end |
#inspect ⇒ Object
87 88 89 |
# File 'lib/gamefic/subplot.rb', line 87 def inspect "#<#{self.class}>" end |
#introduce(player) ⇒ Object
79 80 81 |
# File 'lib/gamefic/subplot.rb', line 79 def introduce(player) @concluded ? player : super end |
#persistent? ⇒ Boolean
41 42 43 |
# File 'lib/gamefic/subplot.rb', line 41 def persistent? self.class.persistent? end |
#prepare ⇒ Object
83 84 85 |
# File 'lib/gamefic/subplot.rb', line 83 def prepare(...) super || plot.prepare(...) end |
#seeds ⇒ Object
29 30 31 |
# File 'lib/gamefic/subplot.rb', line 29 def seeds super - plot.seeds end |