Module: Gamefic::Plot::Snapshot

Defined in:
lib/gamefic/plot/snapshot.rb

Instance Method Summary collapse

Instance Method Details

#restore(snapshot) ⇒ Object

Restore the plot to the state of the provided snapshot.

Parameters:

  • (Hash)


30
31
32
33
34
# File 'lib/gamefic/plot/snapshot.rb', line 30

def restore snapshot
  restore_initial_state
  internal_restore snapshot[:entities]
  restore_subplots snapshot[:subplots]
end

#saveHash

Take a snapshot of the plot’s current state. The snapshot is a hash with two keys: entities and subplots.

Returns:

  • (Hash)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/gamefic/plot/snapshot.rb', line 10

def save
  store = get_entity_hash
  if @initial_state.nil?
    @initial_state = store
    store = []
    @initial_state.length.times do
      store.push {}
    end
  else
    store = reduce(store)
  end
  return {
    entities: store,
    subplots: save_subplots
  }
end