Class: Gamefic::Plot
- Includes:
- Host, Snapshot, Scriptable, Serialize, World
- Defined in:
- lib/gamefic/plot.rb,
lib/gamefic/plot/darkroom.rb
Overview
Create and restore plot snapshots.
Defined Under Namespace
Modules: Host, Snapshot Classes: Darkroom
Instance Attribute Summary collapse
- #metadata ⇒ Hash readonly
-
#static ⇒ Object
readonly
Returns the value of attribute static.
Instance Method Summary collapse
-
#initialize(metadata: {}) ⇒ Plot
constructor
A new instance of Plot.
-
#ready ⇒ Object
Prepare the Plot for the next turn of gameplay.
-
#syntaxes ⇒ Array<Syntax>
Get an Array of the Plot’s current Syntaxes.
-
#tell(entities, message) ⇒ Object
Send a message to a group of entities.
-
#update ⇒ Object
Update the Plot’s current turn of gameplay.
Methods included from Serialize
instances, #serialized_class, string_to_constant, #to_serial
Methods included from Host
#branch, #in_subplot?, #subplots, #subplots_featuring
Methods included from Snapshot
Methods included from Scriptable
Methods included from World::Players
#make_player_character, #player_class, #players, #set_player_class
Methods included from World::Commands
#actions, #disambiguate, #get_default_query, #interpret, #meta, #override, #parse, #playbook, #respond, #set_default_query, #validate, #verbs
Methods included from World::Entities
#cast, #destroy, #entities, #make, #pick, #players
Methods included from World::Scenes
#conclusion, #custom, #default_conclusion, #default_scene, #introduce, #introduction, #multiple_choice, #multiple_scene, #pause, #question, #scene_classes, #yes_or_no
Methods included from World::Callbacks
#before_player_update, #before_player_update_procs, #on_player_conclude, #on_player_ready, #on_player_update, #on_ready, #on_update, #player_conclude_procs, #player_ready_procs, #player_update_procs, #ready_procs, #update_procs
Constructor Details
#initialize(metadata: {}) ⇒ Plot
Returns a new instance of Plot.
31 32 33 34 35 |
# File 'lib/gamefic/plot.rb', line 31 def initialize metadata: {} = run_scripts @static = [self] + scene_classes + entities end |
Instance Attribute Details
#static ⇒ Object (readonly)
Returns the value of attribute static.
19 20 21 |
# File 'lib/gamefic/plot.rb', line 19 def static @static end |
Instance Method Details
#ready ⇒ Object
Prepare the Plot for the next turn of gameplay. This method is typically called by the Engine that manages game execution.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/gamefic/plot.rb', line 48 def ready playbook.freeze call_ready call_player_ready subplots.each { |s| s.ready } players.each do |p| p.state.replace( p.scene.state .merge({ messages: p., last_prompt: p.last_prompt, last_input: p.last_input, queue: p.queue }) .merge(p.state) ) p.output.replace(p.state) p.state.clear end end |
#syntaxes ⇒ Array<Syntax>
Get an Array of the Plot’s current Syntaxes.
40 41 42 |
# File 'lib/gamefic/plot.rb', line 40 def syntaxes playbook.syntaxes end |
#tell(entities, message) ⇒ Object
Send a message to a group of entities.
98 99 100 101 102 |
# File 'lib/gamefic/plot.rb', line 98 def tell entities, entities.each { |entity| entity.tell } end |
#update ⇒ Object
Update the Plot’s current turn of gameplay. This method is typically called by the Engine that manages game execution.
73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/gamefic/plot.rb', line 73 def update entities.each { |e| e.flush } call_before_player_update players.each do |p| p.performed nil next unless p.scene p.last_input = p.queue.last p.last_prompt = p.scene.prompt p.scene.update if p.scene.is_a?(Scene::Conclusion) player_conclude_procs.each do |proc| proc.call p end end end call_player_update call_update subplots.delete_if(&:concluded?) subplots.each(&:update) end |