diff options
Diffstat (limited to 'usmpgames/application.py')
-rwxr-xr-x | usmpgames/application.py | 18 |
1 files changed, 13 insertions, 5 deletions
diff --git a/usmpgames/application.py b/usmpgames/application.py index d492b5c..7871ee8 100755 --- a/usmpgames/application.py +++ b/usmpgames/application.py @@ -28,7 +28,9 @@ class Application(): def __init__(self): self._state_stack = [] + self._cookie_stack = [] self._current_state = None + self._current_cookie = None self._running = True self._fps = 25 if Application._instance is None: @@ -40,12 +42,13 @@ class Application(): def screen(self): return self._screen - def push_state(self, new_state): + def push_state(self, new_state, new_cookie = None): # exit from current state if self._current_state is not None: self._current_state.exiting_state( True ) if new_state is not None: self._state_stack.append(self._current_state) + self._cookie_stack.append(self._current_state.cookie()) # process new state fromStack = False @@ -55,18 +58,20 @@ class Application(): return else : self._current_state = self.pop_state() + self._current_cookie = self._current_state.cookie() fromStack = True else: self._current_state = new_state + self._current_cookie = new_cookie # entering new state if self._current_state is None: self.set_running(False) else: self._current_state.set_screen(self.screen()) - self._current_state.entering_state(fromStack) + self._current_state.entering_state(fromStack, self._current_cookie) - def change_state(self, new_state): + def change_state(self, new_state, new_cookie): # exit from current state if self._current_state is not None: self._current_state.exiting_state(False) @@ -81,11 +86,12 @@ class Application(): return else: self._current_state = new_state + self._current_cookie = new_cookie # entering new state if self._current_state is not None: self._current_state.set_screen(self.screen()) - self._current_state.entering_state( False ) + self._current_state.entering_state( False, self._current_cookie ) else: self.set_running(False) @@ -96,11 +102,13 @@ class Application(): self._current_state.exiting_state( False ) if len(self._state_stack) >= 1: self._current_state = self._state_stack.pop() + self._current_cookie = self._current_state.cookie() else: self._current_state = None + self._current_cookie = None if self._current_state is not None: self._current_state.set_screen(self.screen()) - self._current_state.entering_state( True ) + self._current_state.entering_state( True, self._current_cookie ) def current_state(self): return self._current_state |