import pygame.locals as pgl
-class NajaEvent(object):
+def finish_event(handled=True, events=(), skip_invalidate=False):
+ for event in events:
+ event.post()
+ if not skip_invalidate:
+ InvalidateTheWorld.post()
+ return handled
+
+class NajaEvent(object):
TYPE = "UNKNOWN"
@classmethod
import pygame.locals as pgl
from naja.constants import INFO_SIZE, EIGHT_BIT_SCALE, MOVE, ACT, KEYS
-from naja.events import InvalidateTheWorld, PlayerMoved
+from naja.events import PlayerMoved, finish_event
from naja.resources import resources
from naja.resources.mutators import EIGHT_BIT
action = self.card.actions[self.chosen]
if not action.check_available(self.state.gameboard.player):
print "BEEP!"
- return True
- action.perform_action(self.state.gameboard, self.card)
- self.state.gameboard.change_mode()
- InvalidateTheWorld.post()
- return True
+ else:
+ action.perform_action(self.state.gameboard, self.card)
+ self.state.gameboard.change_mode()
+ return finish_event()
if ev.key in KEYS.UP:
if self.chosen > 0:
self.chosen -= 1
- InvalidateTheWorld.post()
- return True
+ return finish_event()
if ev.key in KEYS.DOWN:
if self.chosen + 1 < len(self.card.actions):
self.chosen += 1
- InvalidateTheWorld.post()
- return True
+ return finish_event()
return super(InfoAreaWidget, self).handle_event(ev)
import pygame.locals as pgl
from naja.constants import PLAYER_SIZE, BIT_SIZE, TILE_SIZE, BITS, ACT, KEYS
-from naja.events import InvalidateTheWorld, PlayerMoved
+from naja.events import PlayerMoved, finish_event
from naja.resources import resources
from naja.resources.mutators import EIGHT_BIT
from naja.widgets.base import Widget
if ev.key in KEYS.UP:
if self.state.player.move(BITS.NORTH):
self.state.gameboard.change_mode()
- PlayerMoved.post()
- InvalidateTheWorld.post()
- return True
+ return finish_event(events=[PlayerMoved])
if ev.key in KEYS.DOWN:
if self.state.player.move(BITS.SOUTH):
self.state.gameboard.change_mode()
- PlayerMoved.post()
- InvalidateTheWorld.post()
- return True
+ return finish_event(events=[PlayerMoved])
if ev.key in KEYS.LEFT:
if self.state.player.move(BITS.WEST):
self.state.gameboard.change_mode()
- PlayerMoved.post()
- InvalidateTheWorld.post()
- return True
+ return finish_event(events=[PlayerMoved])
if ev.key in KEYS.RIGHT:
if self.state.player.move(BITS.EAST):
self.state.gameboard.change_mode()
- PlayerMoved.post()
- InvalidateTheWorld.post()
- return True
+ return finish_event(events=[PlayerMoved])
if ev.key in (pgl.K_SPACE,):
self.state.gameboard.change_mode()
- InvalidateTheWorld.post()
- return True
+ return finish_event()
return super(RobotWidget, self).handle_event(ev)