Class: Gamefic::Subplot

Inherits:
Object show all
Extended by:
Gamefic::Scriptable::ClassMethods
Includes:
Scriptable, Serialize, World
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 execution.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Gamefic::Scriptable::ClassMethods

blocks, script

Methods included from Serialize

#serialized_class, string_to_constant, #to_serial

Methods included from Scriptable

included, #stage, #theater

Methods included from World::Players

#make_player_character, #player_class, #set_player_class

Methods included from World::Commands

#actions, #after_action, #before_action, #get_default_query, #interpret, #meta, #override, #parse, #respond, #set_default_query, #verbs

Methods included from World::Entities

#destroy, #entities, #make, #pick

Methods included from World::Scenes

#conclusion, #custom, #introduce, #introduction, #multiple_choice, #multiple_scene, #pause, #question, #scene_classes, #yes_or_no

Methods included from World::Callbacks

#before_player_update, #before_player_update_procs, #on_player_conclude, #on_player_ready, #on_player_update, #on_ready, #on_update, #player_conclude_procs, #player_ready_procs, #player_update_procs, #ready_procs, #update_procs

Constructor Details

#initialize(plot, introduce: nil, next_cue: nil, **more) ⇒ Subplot

Returns a new instance of Subplot.

Parameters:



20
21
22
23
24
25
26
27
28
29
30
# File 'lib/gamefic/subplot.rb', line 20

def initialize plot, introduce: nil, next_cue: nil, **more
  @plot = plot
  @next_cue = next_cue
  @concluded = false
  @more = more
  configure **more
  run_scripts
  playbook.freeze
  self.introduce introduce unless introduce.nil?
  @static = [self] + scene_classes + entities
end

Instance Attribute Details

#plotGamefic::Plot (readonly)

Returns:



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

def plot
  @plot
end

Instance Method Details

#cast(cls, args = {}, &block) ⇒ Object



56
57
58
59
60
# File 'lib/gamefic/subplot.rb', line 56

def cast cls, args = {}, &block
  ent = super
  ent.playbooks.push plot.playbook unless ent.playbooks.include?(plot.playbook)
  ent
end

#concludeObject



69
70
71
72
73
74
75
76
77
78
# File 'lib/gamefic/subplot.rb', line 69

def conclude
  @concluded = true
  # Players needed to exit first in case any player_conclude procs need to
  # interact with the subplot's entities.
  players.each { |p| exeunt p }
  # @todo I'm not sure why rejecting nils is necessary here. It's only an
  #   issue in Opal.
  entities.reject(&:nil?).each { |e| destroy e }
  # plot.static.remove(scene_classes + entities)
end

#concluded?Boolean

Returns:

  • (Boolean)


80
81
82
# File 'lib/gamefic/subplot.rb', line 80

def concluded?
  @concluded
end

#configure(**more) ⇒ Object

Subclasses can override this method to handle additional configuration options.



103
104
# File 'lib/gamefic/subplot.rb', line 103

def configure **more
end

#default_conclusionObject



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

def default_conclusion
  plot.default_conclusion
end

#default_sceneObject



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

def default_scene
  plot.default_scene
end

#exeunt(player) ⇒ Object



62
63
64
65
66
67
# File 'lib/gamefic/subplot.rb', line 62

def exeunt player
  player_conclude_procs.each { |block| block.call player }
  player.playbooks.delete playbook
  player.cue (@next_cue || default_scene)
  players.delete player
end

#playbookObject



52
53
54
# File 'lib/gamefic/subplot.rb', line 52

def playbook
  @playbook ||= Gamefic::Plot::Playbook.new
end

#playersObject



36
37
38
# File 'lib/gamefic/subplot.rb', line 36

def players
  @players ||= []
end

#readyObject



84
85
86
87
88
89
90
91
92
93
# File 'lib/gamefic/subplot.rb', line 84

def ready
  # @todo We might not want to conclude subplots without players. There
  #   might be cases where a subplot gets created with the intention of
  #   introducing players in a later turn.
  conclude if players.empty?
  return if concluded?
  playbook.freeze
  call_ready
  call_player_ready
end

#staticObject



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

def static
  plot.static
end

#subplotObject



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

def subplot
  self
end

#updateObject



95
96
97
98
# File 'lib/gamefic/subplot.rb', line 95

def update
  call_player_update
  call_update
end