Module: GameMachine::Helpers::StateMachine

Defined in:
server/lib/game_machine/helpers/state_machine.rb

Instance Method Summary collapse

Instance Method Details

#destroy_state(id) ⇒ Object


18
19
20
# File 'server/lib/game_machine/helpers/state_machine.rb', line 18

def destroy_state(id)
  @actor_states.delete(id)
end

#initialize_statesObject


22
23
24
25
26
# File 'server/lib/game_machine/helpers/state_machine.rb', line 22

def initialize_states
  @actor_states = {}
  initialize_state_machines
  @initial_state = self.state.dup
end

#load_state(id, &block) ⇒ Object


5
6
7
8
9
10
11
12
# File 'server/lib/game_machine/helpers/state_machine.rb', line 5

def load_state(id, &block)
  @actor_states[id] ||= @initial_state
  self.state = @actor_states[id]
  if block_given?
    yield
    save_state(id)
  end
end

#save_state(id) ⇒ Object


14
15
16
# File 'server/lib/game_machine/helpers/state_machine.rb', line 14

def save_state(id)
  @actor_states[id] = self.state
end