Class: Gamefic::Plot::Darkroom

Inherits:
Object
  • Object
show all
Defined in:
lib/gamefic/plot/darkroom.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#plotGamefic::Plot (readonly)

Returns:



7
8
9
# File 'lib/gamefic/plot/darkroom.rb', line 7

def plot
  @plot
end

Instance Method Details

#restore(snapshot) ⇒ Object

Restore a snapshot.

Parameters:



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.

Returns:



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