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: Darkroom, 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
- #player_class(cls = nil) ⇒ 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 Articles
Methods included from YouMount
Methods included from Snapshot
#initial_state, #restore, #save
Methods included from Host
#branch, #in_subplot?, #subplots, #subplots_featuring
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, #scene_classes, #yes_or_no
Methods included from Commands
#action, #actions, #disambiguate, #interpret, #meta, #respond, #validate, #verbs, #xlate
Methods included from Entities
#cast, #destroy, #entities, #make, #pick, #players
Methods included from Theater
Constructor Details
#initialize(source = nil) ⇒ Plot
Returns a new instance of Plot.
31 32 33 34 35 36 37 |
# File 'lib/gamefic/plot.rb', line 31 def initialize(source = nil) @source = source || Source::Text.new({}) @working_scripts = [] @imported_scripts = [] @running = false post_initialize end |
Instance Attribute Details
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
22 23 24 |
# File 'lib/gamefic/plot.rb', line 22 def commands @commands end |
#imported_scripts ⇒ Array<Script> (readonly)
Get an Array of all scripts that have been imported into the Plot.
56 57 58 |
# File 'lib/gamefic/plot.rb', line 56 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.
22 23 24 |
# File 'lib/gamefic/plot.rb', line 22 def source @source end |
Instance Method Details
#playbook ⇒ Gamefic::Plot::Playbook
45 46 47 |
# File 'lib/gamefic/plot.rb', line 45 def playbook @playbook ||= Gamefic::Plot::Playbook.new end |
#player_class(cls = nil) ⇒ Object
39 40 41 42 |
# File 'lib/gamefic/plot.rb', line 39 def player_class cls = nil @player_class = cls unless cls.nil? @player_class end |
#post_initialize ⇒ Object
60 61 62 |
# File 'lib/gamefic/plot.rb', line 60 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.
73 74 75 76 77 78 79 80 81 |
# File 'lib/gamefic/plot.rb', line 73 def ready playbook.freeze @running = true # Call the initial state to make sure it's set initial_state call_ready call_player_ready p_subplots.each { |s| s.ready } end |
#running? ⇒ Boolean
49 50 51 |
# File 'lib/gamefic/plot.rb', line 49 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.
111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 |
# File 'lib/gamefic/plot.rb', line 111 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.
67 68 69 |
# File 'lib/gamefic/plot.rb', line 67 def syntaxes playbook.syntaxes end |
#tell(entities, message, refresh = false) ⇒ Object
99 100 101 102 103 |
# File 'lib/gamefic/plot.rb', line 99 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.
85 86 87 88 89 90 91 92 93 94 95 96 97 |
# File 'lib/gamefic/plot.rb', line 85 def update entities.each { |e| e.flush } call_before_player_update p_players.each { |p| p.performed nil 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 |