Class: Gamefic::Plot::Darkroom
Instance Attribute Summary collapse
- #plot ⇒ Gamefic::Plot readonly
Instance Method Summary collapse
-
#initialize(plot) ⇒ Darkroom
constructor
A new instance of Darkroom.
-
#restore(snapshot) ⇒ Object
Restore a snapshot.
-
#save(reduce: false) ⇒ Hash
Create a snapshot of the plot.
Constructor Details
#initialize(plot) ⇒ Darkroom
Returns a new instance of Darkroom.
9 10 11 |
# File 'lib/gamefic/plot/darkroom.rb', line 9 def initialize plot @plot = plot end |
Instance Attribute Details
#plot ⇒ Gamefic::Plot (readonly)
7 8 9 |
# File 'lib/gamefic/plot/darkroom.rb', line 7 def plot @plot end |
Instance Method Details
#restore(snapshot) ⇒ Object
Restore a snapshot.
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/gamefic/plot/darkroom.rb', line 30 def restore snapshot Gamefic::Index.elements.map(&:destroy) Gamefic::Index.unserialize snapshot['elements'] plot.entities.clear snapshot['entities'].each do |ser| plot.entities.push Index.from_serial(ser) end snapshot['theater_instance_variables'].each_pair do |k, s| v = Gamefic::Index.from_serial(s) next if v == "#<UNKNOWN>" plot.theater.instance_variable_set(k, v) end snapshot['subplots'].each { |s| unserialize_subplot(s) } end |
#save(reduce: false) ⇒ Hash
Create a snapshot of the plot.
16 17 18 19 20 21 22 23 24 25 |
# File 'lib/gamefic/plot/darkroom.rb', line 16 def save reduce: false result = { 'elements' => Gamefic::Index.serials, 'entities' => plot.entities.map(&:to_serial), 'players' => plot.players.map(&:to_serial), 'theater_instance_variables' => plot.theater.serialize_instance_variables, 'subplots' => plot.subplots.reject(&:concluded?).map { |s| serialize_subplot(s) }, 'metadata' => plot. } end |