Class: Gamefic::Plot
- Inherits:
-
Object
- Object
- Gamefic::Plot
- Includes:
- Gamefic, Articles, Callbacks, Commands, Entities, Host, Players, Scenes, Snapshot, Theater, YouMount, Tester
- Defined in:
- lib/gamefic/plot.rb,
lib/gamefic/plot/entities.rb,
lib/gamefic/plot/playbook.rb
Defined Under Namespace
Modules: Articles, Callbacks, Commands, Entities, Host, Players, Scenes, Snapshot, Theater, YouMount Classes: Playbook
Constant Summary
Constants included from Gamefic
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 ⇒ Gamefic::Plot::Playbook
- #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 Articles
Methods included from YouMount
Methods included from Snapshot
Methods included from Host
#branch, #in_subplot?, #subplot_for, #subplots
Methods included from Callbacks
#before_player_update, #on_player_ready, #on_player_update, #on_ready, #on_update
Methods included from Tester
#on_test, #run_test, #test_procs
Methods included from Players
Methods included from Scenes
#conclusion, #custom, #default_conclusion, #default_scene, #introduce, #introduction, #multiple_choice, #multiple_scene, #pause, #question, #yes_or_no
Methods included from Commands
#action, #actions, #disambiguate, #interpret, #meta, #respond, #validate, #verbs, #xlate
Methods included from Entities
#destroy, #entities, #make, #pick, #players
Methods included from Theater
Constructor Details
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.
51 52 53 |
# File 'lib/gamefic/plot.rb', line 51 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 @metadata 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 ⇒ Gamefic::Plot::Playbook
40 41 42 |
# File 'lib/gamefic/plot.rb', line 40 def playbook @playbook ||= Gamefic::Plot::Playbook.new end |
#post_initialize ⇒ Object
55 56 57 |
# File 'lib/gamefic/plot.rb', line 55 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.
68 69 70 71 72 73 74 |
# File 'lib/gamefic/plot.rb', line 68 def ready playbook.freeze @running = true call_ready call_player_ready p_subplots.each { |s| s.ready } end |
#running? ⇒ Boolean
44 45 46 |
# File 'lib/gamefic/plot.rb', line 44 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.
101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 |
# File 'lib/gamefic/plot.rb', line 101 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 # @hack Arguments need to be in different order if source returns proc if imported_script.read.kind_of?(Proc) stage &imported_script.read else stage imported_script.read, imported_script.absolute_path end @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.
62 63 64 |
# File 'lib/gamefic/plot.rb', line 62 def syntaxes playbook.syntaxes end |
#tell(entities, message, refresh = false) ⇒ Object
89 90 91 92 93 |
# File 'lib/gamefic/plot.rb', line 89 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.
78 79 80 81 82 83 84 85 86 87 |
# File 'lib/gamefic/plot.rb', line 78 def update entities.each { |e| e.flush } call_before_player_update p_players.each { |p| p.scene.update } 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 |