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 inherited from Narrative
Instance Method Summary collapse
-
#branch(subplot_class = Gamefic::Subplot, introduce: [], **config) ⇒ Gamefic::Subplot
Start a new subplot based on the provided class.
- #conclude ⇒ Object
-
#configure ⇒ Object
Subclasses can override this method to handle additional configuration options.
- #hydrate ⇒ Object
-
#initialize(plot, introduce: [], **config) ⇒ Subplot
constructor
A new instance of Subplot.
- #inspect ⇒ Object
-
#persist(klass, **args) ⇒ Object
Make an entity that persists in the subplot’s parent plot.
- #ready ⇒ Object
Methods inherited from Narrative
#attach, #cast, #concluding?, #detach, inherited, #introduce, #scenes, #uncast, #update
Methods included from Scriptable
#attr_seed, #blocks, #included_blocks, #make_seed, #method_missing, #no_scripts, #respond_to_missing?, #script, #seed
Methods included from Gamefic::Scriptable::Scenes
#block, #conclusion, #introduction, #multiple_choice, #pause, #scenes, #yes_or_no
Methods included from Gamefic::Scriptable::Events
#on_conclude, #on_player_conclude, #on_player_output, #on_player_ready, #on_player_update, #on_ready, #on_update
Methods included from Gamefic::Scriptable::Actions
#after_action, #before_action, #interpret, #meta, #respond, #synonyms, #syntaxes, #verbs
Methods included from Gamefic::Scriptable::Queries
#anywhere, #available, #children, #myself, #parent, #plaintext, #siblings
Methods included from Gamefic::Scriptable::Proxy
Methods included from Gamefic::Scriptable::Entities
#destroy, #entities, #entity_vault, #make, #pick, #pick!, #player_vault, #players
Methods included from Logging
Constructor Details
#initialize(plot, introduce: [], **config) ⇒ Subplot
Returns a new instance of Subplot.
19 20 21 22 23 24 25 26 |
# File 'lib/gamefic/subplot.rb', line 19 def initialize plot, introduce: [], **config @plot = plot @config = config configure @config.freeze super() [introduce].flatten.each { |pl| self.introduce pl } end |
Instance Attribute Details
#config ⇒ Hash (readonly)
11 12 13 |
# File 'lib/gamefic/subplot.rb', line 11 def config @config 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.
59 60 61 |
# File 'lib/gamefic/subplot.rb', line 59 def branch subplot_class = Gamefic::Subplot, introduce: [], **config plot.branch subplot_class, introduce: introduce, **config end |
#conclude ⇒ Object
33 34 35 36 37 38 39 40 |
# File 'lib/gamefic/subplot.rb', line 33 def conclude rulebook.run_conclude_blocks players.each do |plyr| rulebook.run_player_conclude_blocks plyr uncast plyr end entities.each { |ent| destroy ent } end |
#configure ⇒ Object
Subclasses can override this method to handle additional configuration options.
66 |
# File 'lib/gamefic/subplot.rb', line 66 def configure; end |
#hydrate ⇒ Object
72 73 74 75 76 |
# File 'lib/gamefic/subplot.rb', line 72 def hydrate @rulebook = Rulebook.new(self) @rulebook.script @rulebook.freeze end |
#inspect ⇒ Object
68 69 70 |
# File 'lib/gamefic/subplot.rb', line 68 def inspect "#<#{self.class}>" end |
#persist(klass, **args) ⇒ Object
Make an entity that persists in the subplot’s parent plot.
46 47 48 |
# File 'lib/gamefic/subplot.rb', line 46 def persist klass, **args plot.make klass, *args end |
#ready ⇒ Object
28 29 30 31 |
# File 'lib/gamefic/subplot.rb', line 28 def ready super conclude if concluding? end |