Module: Gamefic::Plot::Snapshot
- Included in:
- Gamefic::Plot
- Defined in:
- lib/gamefic/plot/snapshot.rb
Instance Method Summary collapse
-
#restore(snapshot) ⇒ Object
Restore the plot to the state of the provided snapshot.
-
#save ⇒ Hash
Take a snapshot of the plot’s current state.
Instance Method Details
#restore(snapshot) ⇒ Object
Restore the plot to the state of the provided snapshot.
31 32 33 34 35 |
# File 'lib/gamefic/plot/snapshot.rb', line 31 def restore snapshot restore_initial_state internal_restore snapshot[:entities] restore_subplots snapshot[:subplots] end |
#save ⇒ Hash
Take a snapshot of the plot’s current state. The snapshot is a hash with two keys: entities and subplots.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# 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, metadata: } end |