Class: Gamefic::Subplot

Inherits:
Object show all
Extended by:
Gamefic::Scriptable::ClassMethods
Includes:
Scriptable, Serialize, World
Defined in:
lib/gamefic/subplot.rb

Overview

< Container

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Gamefic::Scriptable::ClassMethods

blocks, script

Methods included from Serialize

instances, #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, #disambiguate, #get_default_query, #interpret, #meta, #override, #parse, #respond, #set_default_query, #validate, #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



17
18
19
20
21
22
23
24
25
26
27
# File 'lib/gamefic/subplot.rb', line 17

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)



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

def plot
  @plot
end

Instance Method Details

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



53
54
55
56
57
# File 'lib/gamefic/subplot.rb', line 53

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

#concludeObject



66
67
68
69
70
71
72
73
74
75
# File 'lib/gamefic/subplot.rb', line 66

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



77
78
79
# File 'lib/gamefic/subplot.rb', line 77

def concluded?
  @concluded
end

#configure(more) ⇒ Object

Subclasses can override this method to handle additional configuration options.



100
101
# File 'lib/gamefic/subplot.rb', line 100

def configure more
end

#default_conclusionObject



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

def default_conclusion
  plot.default_conclusion
end

#default_sceneObject



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

def default_scene
  plot.default_scene
end

#exeunt(player) ⇒ Object



59
60
61
62
63
64
# File 'lib/gamefic/subplot.rb', line 59

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



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

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

#playersObject



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

def players
  @players ||= []
end

#readyObject



81
82
83
84
85
86
87
88
89
90
# File 'lib/gamefic/subplot.rb', line 81

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



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

def static
  plot.static
end

#subplotObject



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

def subplot
  self
end

#updateObject



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

def update
  call_player_update
  call_update
end