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 included from Gamefic::Scriptable::Scenes

#default_conclusion, #default_scene

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from Narrative

#cast, inherited, restore, #save, #turn, #uncast

Methods included from Scriptable

#included_scripts, #pick, #pick!

Methods included from Gamefic::Scriptable::Syntaxes

#interpret, #syntaxes

Methods included from Gamefic::Scriptable::Seeds

#construct, #make, #seed

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

#synonyms, #syntaxes

Methods included from Gamefic::Scripting::Scenes

#default_conclusion, #default_scene, #introductions, #named_scenes, #scene_class, #scenes

Methods included from Gamefic::Scripting::Responses

#responses, #responses_for

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

#unproxy

Constructor Details

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

Returns a new instance of Subplot.

Parameters:



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

#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

Class Method Details

.configObject



92
93
94
# File 'lib/gamefic/subplot.rb', line 92

def config
  Proxy::Config.new
end

.persist!Object



33
34
35
# File 'lib/gamefic/subplot.rb', line 33

def self.persist!
  @persistent = true
end

.persistent?Boolean

Returns:

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

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:



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

#concludeObject



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

Returns:

  • (Boolean)


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

def concluding?
  return super unless persistent?

  @concluded
end

#configureObject

Subclasses can override this method to handle additional configuration options.



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

def configure; end

#inspectObject



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

Returns:

  • (Boolean)


41
42
43
# File 'lib/gamefic/subplot.rb', line 41

def persistent?
  self.class.persistent?
end

#prepareObject



83
84
85
# File 'lib/gamefic/subplot.rb', line 83

def prepare(...)
  super || plot.prepare(...)
end

#seedsObject



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

def seeds
  super - plot.seeds
end