Class: Gamefic::Subplot
- Extended by:
- Gamefic::Scriptable::PlotProxies
- Defined in:
- lib/gamefic/subplot.rb
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
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.
- #included_blocks ⇒ Object
-
#initialize(plot, introduce: [], **config) ⇒ Subplot
constructor
A new instance of Subplot.
- #inspect ⇒ Object
- #introduce(player) ⇒ Object
-
#persist(klass, **args) ⇒ Object
Make an entity that persists in the subplot’s parent plot.
- #persistent? ⇒ Boolean
- #ready ⇒ Object
Methods included from Gamefic::Scriptable::PlotProxies
attr_plot, lazy_plot, plot_pick, plot_pick!
Methods inherited from Narrative
#attach, #cast, #detach, #hydrate, inherited, #post_script, #scenes, #script, #seed, #uncast, #update
Methods included from Scriptable
#attr_seed, #blocks, #lazy_attr, #lazy_ivar, #make_seed, #method_missing, #no_scripts, #pick, #pick!, #proxy, #respond_to_missing?, #script, #seed
Methods included from Gamefic::Scriptable::Scenes
#block, #conclusion, #introduction, #multiple_choice, #pause, #preface, #scene, #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
#abstract, #anywhere, #available, #children, #descendants, #myself, #parent, #plaintext, #siblings
Methods included from Gamefic::Scriptable::Proxies
Methods included from Gamefic::Scriptable::Entities
#destroy, #entities, #entity_vault, #find, #make, #pick, #pick!, #player_vault, #players
Methods included from Logging
Constructor Details
#initialize(plot, introduce: [], **config) ⇒ Subplot
Returns a new instance of Subplot.
21 22 23 24 25 26 27 28 29 |
# File 'lib/gamefic/subplot.rb', line 21 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)
13 14 15 |
# File 'lib/gamefic/subplot.rb', line 13 def config @config end |
Class Method Details
.config ⇒ Object
103 104 105 |
# File 'lib/gamefic/subplot.rb', line 103 def config Proxy::Config.new end |
.persist! ⇒ Object
31 32 33 |
# File 'lib/gamefic/subplot.rb', line 31 def self.persist! @persistent = true end |
.persistent? ⇒ Boolean
35 36 37 |
# File 'lib/gamefic/subplot.rb', line 35 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.
79 80 81 |
# File 'lib/gamefic/subplot.rb', line 79 def branch subplot_class = Gamefic::Subplot, introduce: [], **config plot.branch subplot_class, introduce: introduce, **config end |
#conclude ⇒ Object
52 53 54 55 56 57 58 59 60 |
# File 'lib/gamefic/subplot.rb', line 52 def conclude rulebook.run_conclude_blocks players.each do |plyr| rulebook.run_player_conclude_blocks plyr uncast plyr end entities.each { |ent| destroy ent } @concluded = true end |
#concluding? ⇒ Boolean
88 89 90 91 92 |
# File 'lib/gamefic/subplot.rb', line 88 def concluding? return super unless persistent? @concluded end |
#configure ⇒ Object
Subclasses can override this method to handle additional configuration options.
86 |
# File 'lib/gamefic/subplot.rb', line 86 def configure; end |
#included_blocks ⇒ Object
43 44 45 |
# File 'lib/gamefic/subplot.rb', line 43 def included_blocks super - plot.included_blocks end |
#inspect ⇒ Object
98 99 100 |
# File 'lib/gamefic/subplot.rb', line 98 def inspect "#<#{self.class}>" end |
#introduce(player) ⇒ Object
94 95 96 |
# File 'lib/gamefic/subplot.rb', line 94 def introduce player @concluded ? player : super end |
#persist(klass, **args) ⇒ Object
Make an entity that persists in the subplot’s parent plot.
66 67 68 |
# File 'lib/gamefic/subplot.rb', line 66 def persist klass, **args plot.make klass, *args end |
#persistent? ⇒ Boolean
39 40 41 |
# File 'lib/gamefic/subplot.rb', line 39 def persistent? self.class.persistent? end |
#ready ⇒ Object
47 48 49 50 |
# File 'lib/gamefic/subplot.rb', line 47 def ready super conclude if concluding? end |