Class: Gamefic::Plot

Inherits:
Object
  • Object
show all
Includes:
Stage
Defined in:
lib/gamefic/plot.rb,
lib/gamefic/plot/entities.rb,
lib/gamefic/plot/playbook.rb

Defined Under Namespace

Modules: ArticleMount, Callbacks, CommandMount, Entities, Host, Players, QueryMount, SceneMount, Snapshot, YouMount Classes: Playbook

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Stage

#stage

Constructor Details

#initialize(source = nil) ⇒ Plot

Returns a new instance of Plot.

Parameters:



32
33
34
35
36
37
38
39
# File 'lib/gamefic/plot.rb', line 32

def initialize(source = nil)
  @source = source || Source::Text.new({})
  @working_scripts = []
  @imported_scripts = []
  @running = false
  @playbook = Playbook.new
  post_initialize
end

Instance Attribute Details

#commandsObject (readonly)

Returns the value of attribute commands.



23
24
25
# File 'lib/gamefic/plot.rb', line 23

def commands
  @commands
end

#imported_scriptsArray<Script> (readonly)

Get an Array of all scripts that have been imported into the Plot.

Returns:



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

def imported_scripts
  @imported_scripts
end

#metadataObject

TODO: Metadata could use better protection



25
26
27
# File 'lib/gamefic/plot.rb', line 25

def 
  
end

#sourceObject (readonly)

Returns the value of attribute source.



23
24
25
# File 'lib/gamefic/plot.rb', line 23

def source
  @source
end

Instance Method Details

#playbookObject



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

def playbook
  @playbook ||= Playbook.new
end

#post_initializeObject



56
57
58
# File 'lib/gamefic/plot.rb', line 56

def post_initialize
  # TODO: Should this method be required by extended classes?

end

#readyObject

Prepare the Plot for the next turn of gameplay. This method is typically called by the Engine that manages game execution.



69
70
71
72
73
74
75
# File 'lib/gamefic/plot.rb', line 69

def ready
  playbook.freeze
  @running = true
  call_ready
  call_player_ready
  p_subplots.each { |s| s.ready }
end

#running?Boolean

Returns:

  • (Boolean)


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

def running?
  @running
end

#script(path) ⇒ Boolean

Load a script into the current Plot. This method is similar to Kernel#require, except that the script is evaluated within the Plot’s context via #stage.

Parameters:

  • path (String)

    The path to the script being evaluated

Returns:

  • (Boolean)

    true if the script was loaded by this call or false if it was already loaded.



100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/gamefic/plot.rb', line 100

def script path
  imported_script = source.export(path)
  if imported_script.nil?
    raise LoadError.new("cannot load script -- #{path}")
  end
  if !@working_scripts.include?(imported_script) and !imported_scripts.include?(imported_script)
    @working_scripts.push imported_script
    stage imported_script.read, imported_script.absolute_path
    @working_scripts.pop
    imported_scripts.push imported_script
    true
  else
    false
  end
end

#syntaxesArray<Syntax>

Get an Array of the Plot’s current Syntaxes.

Returns:



63
64
65
# File 'lib/gamefic/plot.rb', line 63

def syntaxes
  playbook.syntaxes
end

#tell(entities, message, refresh = false) ⇒ Object



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

def tell entities, message, refresh = false
  entities.each { |entity|
    entity.tell message, refresh
  }
end

#updateObject

Update the Plot’s current turn of gameplay. This method is typically called by the Engine that manages game execution.



79
80
81
82
83
84
85
86
# File 'lib/gamefic/plot.rb', line 79

def update
  p_players.each { |p| process_input p }
  p_entities.each { |e| e.update }
  call_player_update
  call_update
  p_subplots.each { |s| s.update unless s.concluded? }
  p_subplots.delete_if { |s| s.concluded? }
end