Class: Gamefic::Subplot

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

Attributes inherited from Narrative

#rulebook

Class Method Summary collapse

Instance Method Summary collapse

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

#unproxy

Methods included from Gamefic::Scriptable::Entities

#destroy, #entities, #entity_vault, #find, #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:



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

#configHash (readonly)

Returns:

  • (Hash)


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

def config
  @config
end

#plotPlot (readonly)

Returns:



16
17
18
# File 'lib/gamefic/subplot.rb', line 16

def plot
  @plot
end

Class Method Details

.configObject



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

Returns:

  • (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

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:



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

#concludeObject



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

Returns:

  • (Boolean)


88
89
90
91
92
# File 'lib/gamefic/subplot.rb', line 88

def concluding?
  return super unless persistent?

  @concluded
end

#configureObject

Subclasses can override this method to handle additional configuration options.



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

def configure; end

#included_blocksObject



43
44
45
# File 'lib/gamefic/subplot.rb', line 43

def included_blocks
  super - plot.included_blocks
end

#inspectObject



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

Returns:

  • (Boolean)


39
40
41
# File 'lib/gamefic/subplot.rb', line 39

def persistent?
  self.class.persistent?
end

#readyObject



47
48
49
50
# File 'lib/gamefic/subplot.rb', line 47

def ready
  super
  conclude if concluding?
end