Class: Gamefic::Plot
Defined Under Namespace
Modules: ArticleMount, CommandMount, EntityMount, QueryMount, SceneMount, Snapshot, YouMount
Instance Attribute Summary collapse
-
#asserts ⇒ Object
readonly
Returns the value of attribute asserts.
-
#commands ⇒ Object
readonly
Returns the value of attribute commands.
-
#default_scene ⇒ Object
TODO Metadata could use better protection.
-
#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.
-
#rules ⇒ Object
readonly
Returns the value of attribute rules.
-
#source ⇒ Object
readonly
Returns the value of attribute source.
Instance Method Summary collapse
-
#actions ⇒ Array<Action>
Get an Array of all Actions defined in the Plot.
-
#actions_with_verb(verb) ⇒ Array<Action>
Get an Array of all Actions associated with the specified verb.
-
#assert_action(name) {|The, The, The| ... } ⇒ Object
Add a Block to be executed for the given verb.
- #concluded?(actor) ⇒ Boolean
-
#entities ⇒ Array<Entity>
Get an Array of the Plot’s current Entities.
-
#initialize(source = nil) ⇒ Plot
constructor
A new instance of Plot.
-
#introduce(player) ⇒ Object
Introduce a player to the game.
-
#introduction {|| ... } ⇒ Object
Add a block to be executed when a player is added to the game.
-
#on_player_ready {|| ... } ⇒ Object
Add a block to be executed for each player when the Plot prepares them for the next turn in the game.
-
#on_player_update {|| ... } ⇒ Object
Add a block to be executed for each player after they have completed a turn in the game.
-
#on_ready(&block) ⇒ Object
Add a block to be executed on preparation of every turn.
-
#on_update(&block) ⇒ Object
Add a block to be executed after the Plot is finished updating a turn.
-
#players ⇒ Array<Character>
Get an Array of current players.
- #post_initialize ⇒ Object
-
#ready ⇒ Object
Prepare the Plot for the next turn of gameplay.
- #scenes ⇒ Object
-
#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.
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/gamefic/plot.rb', line 36 def initialize(source = nil) @source = source || Source::Text.new({}) @commands = {} @syntaxes = [] @ready_procs = [] @update_procs = [] @player_ready = [] @player_procs = [] @working_scripts = [] @imported_scripts = [] @entities = [] @players = [] @asserts = {} @default_scene = :active @subplots = [] post_initialize end |
Instance Attribute Details
#asserts ⇒ Object (readonly)
Returns the value of attribute asserts.
21 22 23 |
# File 'lib/gamefic/plot.rb', line 21 def asserts @asserts end |
#commands ⇒ Object (readonly)
Returns the value of attribute commands.
21 22 23 |
# File 'lib/gamefic/plot.rb', line 21 def commands @commands end |
#default_scene ⇒ Object
TODO Metadata could use better protection
23 24 25 |
# File 'lib/gamefic/plot.rb', line 23 def default_scene @default_scene end |
#imported_scripts ⇒ Array<Script> (readonly)
Get an Array of all scripts that have been imported into the Plot.
85 86 87 |
# File 'lib/gamefic/plot.rb', line 85 def imported_scripts @imported_scripts end |
#metadata ⇒ Object
TODO Metadata could use better protection
23 24 25 |
# File 'lib/gamefic/plot.rb', line 23 def @metadata end |
#rules ⇒ Object (readonly)
Returns the value of attribute rules.
21 22 23 |
# File 'lib/gamefic/plot.rb', line 21 def rules @rules end |
#source ⇒ Object (readonly)
Returns the value of attribute source.
21 22 23 |
# File 'lib/gamefic/plot.rb', line 21 def source @source end |
Instance Method Details
#actions ⇒ Array<Action>
Get an Array of all Actions defined in the Plot.
70 71 72 |
# File 'lib/gamefic/plot.rb', line 70 def actions @commands.values.flatten end |
#actions_with_verb(verb) ⇒ Array<Action>
Get an Array of all Actions associated with the specified verb.
78 79 80 |
# File 'lib/gamefic/plot.rb', line 78 def actions_with_verb(verb) @commands[verb].clone || [] end |
#assert_action(name) {|The, The, The| ... } ⇒ Object
Add a Block to be executed for the given verb. If the block returns false, the Action is cancelled.
105 106 107 |
# File 'lib/gamefic/plot.rb', line 105 def assert_action name, &block @asserts[name] = Assert.new(name, &block) end |
#concluded?(actor) ⇒ Boolean
63 64 65 |
# File 'lib/gamefic/plot.rb', line 63 def concluded?(actor) scenes[actor.scene].kind_of?(Scene::Conclusion) end |
#entities ⇒ Array<Entity>
Get an Array of the Plot’s current Entities.
116 117 118 |
# File 'lib/gamefic/plot.rb', line 116 def entities @entities.clone end |
#introduce(player) ⇒ Object
Introduce a player to the game. This method is typically called by the Engine that manages game execution.
171 172 173 174 175 176 |
# File 'lib/gamefic/plot.rb', line 171 def introduce(player) player.extend Subplot::Feature player.cue :active @players.push player @introduction.call(player) unless @introduction.nil? end |
#introduction {|| ... } ⇒ Object
Add a block to be executed when a player is added to the game. Each Plot can only have one introduction. Subsequent calls will overwrite the existing one.
165 166 167 |
# File 'lib/gamefic/plot.rb', line 165 def introduction (&proc) @introduction = proc end |
#on_player_ready {|| ... } ⇒ Object
Add a block to be executed for each player when the Plot prepares them for the next turn in the game.
234 235 236 |
# File 'lib/gamefic/plot.rb', line 234 def on_player_ready &block @player_ready.push block end |
#on_player_update {|| ... } ⇒ Object
Add a block to be executed for each player after they have completed a turn in the game.
242 243 244 |
# File 'lib/gamefic/plot.rb', line 242 def on_player_update &block @player_procs.push block end |
#on_ready(&block) ⇒ Object
Add a block to be executed on preparation of every turn. Each on_ready block is executed once per turn, as opposed to on_player_ready blocks, which are executed once for each player.
144 145 146 |
# File 'lib/gamefic/plot.rb', line 144 def on_ready(&block) @ready_procs.push block end |
#on_update(&block) ⇒ Object
Add a block to be executed after the Plot is finished updating a turn. Each on_update block is executed once per turn, as opposed to on_player_update blocks, which are executed once for each player.
151 152 153 |
# File 'lib/gamefic/plot.rb', line 151 def on_update(&block) @update_procs.push block end |
#players ⇒ Array<Character>
Get an Array of current players.
130 131 132 |
# File 'lib/gamefic/plot.rb', line 130 def players @players.clone end |
#post_initialize ⇒ Object
109 110 111 |
# File 'lib/gamefic/plot.rb', line 109 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.
180 181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/gamefic/plot.rb', line 180 def ready @ready_procs.each { |p| p.call } # Prepare player scenes for the update. @players.each { |player| this_scene = player.next_scene || player.scene player.prepare nil player.cue this_scene unless player.scene == this_scene @player_ready.each { |block| block.call player } } end |
#scenes ⇒ Object
54 55 56 57 58 59 60 61 |
# File 'lib/gamefic/plot.rb', line 54 def scenes if @scenes.nil? @scenes = {} @scenes[:active] = Scene::Active.new @scenes[:concluded] = Scene::Conclusion.new end @scenes 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.
214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 |
# File 'lib/gamefic/plot.rb', line 214 def script path imported_script = source.export(path) if imported_script.nil? raise "Script not found: #{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.
123 124 125 |
# File 'lib/gamefic/plot.rb', line 123 def syntaxes @syntaxes.clone end |
#tell(entities, message, refresh = false) ⇒ Object
202 203 204 205 206 |
# File 'lib/gamefic/plot.rb', line 202 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.
195 196 197 198 199 200 |
# File 'lib/gamefic/plot.rb', line 195 def update @players.each { |p| process_input p } @entities.each { |e| e.update } @players.each { |player| update_player player } @update_procs.each { |p| p.call } end |