extends Node class_name GameState # https://github.com/GDQuest/godot-demos/blob/master/2018/04-24-finite-state-machine/player_v2/state_machine.gd # http://www.gameprogrammingpatterns.com/state.html enum State { MAIN, WINNING, GAME_OVER } var transitions = { State.MAIN : [ State.WINNING ], State.WINNING : [ State.GAME_OVER ], State.GAME_OVER : [ State.MAIN ] } signal state_changed(previous, current) export(State) var current_state = State.MAIN func current_state_name() -> String: return State.keys()[current_state] func transition_to(state): assert(state in transitions[current_state]) var previous_state = current_state current_state = state emit_signal("state_changed", previous_state, current_state)