Class: Gamefic::Subplot

Inherits:
Narrative show all
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

Attributes inherited from Narrative

#rulebook

Instance Method Summary collapse

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

#proxy, #unproxy

Methods included from Gamefic::Scriptable::Entities

#destroy, #entities, #entity_vault, #make, #pick, #pick!, #player_vault, #players

Methods included from Logging

logger

Constructor Details

#initialize(plot, introduce: [], **config) ⇒ Subplot

Returns a new instance of Subplot.

Parameters:



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

#configHash (readonly)

Returns:

  • (Hash)


11
12
13
# File 'lib/gamefic/subplot.rb', line 11

def config
  @config
end

#plotPlot (readonly)

Returns:



14
15
16
# File 'lib/gamefic/subplot.rb', line 14

def plot
  @plot
end

Instance Method Details

#branch(subplot_class = Gamefic::Subplot, introduce: [], **config) ⇒ Gamefic::Subplot

Note:

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.

Parameters:

Returns:



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

#concludeObject



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

#configureObject

Subclasses can override this method to handle additional configuration options.



66
# File 'lib/gamefic/subplot.rb', line 66

def configure; end

#hydrateObject



72
73
74
75
76
# File 'lib/gamefic/subplot.rb', line 72

def hydrate
  @rulebook = Rulebook.new(self)
  @rulebook.script
  @rulebook.freeze
end

#inspectObject



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

#readyObject



28
29
30
31
# File 'lib/gamefic/subplot.rb', line 28

def ready
  super
  conclude if concluding?
end