Class: Gamefic::Plot
- Inherits:
-
Object
- Object
- Gamefic::Plot
- 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
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
-
#imported_scripts ⇒ Array<Script>
readonly
Get an Array of all scripts that have been imported into the Plot.
-
#metadata ⇒ Object
TODO: Metadata could use better protection.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
-
#initialize(source = nil) ⇒ Plot
constructor
A new instance of Plot.
- #playbook ⇒ Object
- #post_initialize ⇒ Object
-
#ready ⇒ Object
Prepare the Plot for the next turn of gameplay.
- #running? ⇒ Boolean
-
#script(path) ⇒ Boolean
Load a script into the current Plot.
-
#syntaxes ⇒ Array<Syntax>
Get an Array of the Plot’s current Syntaxes.
- #tell(entities, message, refresh = false) ⇒ Object
-
#update ⇒ Object
Update the Plot’s current turn of gameplay.
Methods included from Stage
Constructor Details
#initialize(source = nil) ⇒ Plot
Returns a new instance of Plot.
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
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
23 24 25 |
# File 'lib/gamefic/plot.rb', line 23 def commands @commands end |
#imported_scripts ⇒ Array<Script> (readonly)
Get an Array of all scripts that have been imported into the Plot.
52 53 54 |
# File 'lib/gamefic/plot.rb', line 52 def imported_scripts @imported_scripts end |
#metadata ⇒ Object
TODO: Metadata could use better protection
25 26 27 |
# File 'lib/gamefic/plot.rb', line 25 def end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
23 24 25 |
# File 'lib/gamefic/plot.rb', line 23 def source @source end |
Instance Method Details
#playbook ⇒ Object
41 42 43 |
# File 'lib/gamefic/plot.rb', line 41 def playbook @playbook ||= Playbook.new end |
#post_initialize ⇒ Object
56 57 58 |
# File 'lib/gamefic/plot.rb', line 56 def post_initialize # TODO: Should this method be required by extended classes? end |
#ready ⇒ Object
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
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.
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 |
#syntaxes ⇒ Array<Syntax>
Get an Array of the Plot’s current Syntaxes.
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, , refresh = false entities.each { |entity| entity.tell , refresh } end |
#update ⇒ Object
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 |