projects
/
naja.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
a6261f5
)
Move keys to constants
author
Stefano Rivera
<stefano@rivera.za.net>
Tue, 13 May 2014 18:29:33 +0000
(20:29 +0200)
committer
Stefano Rivera
<stefano@rivera.za.net>
Tue, 13 May 2014 18:29:33 +0000
(20:29 +0200)
naja/constants.py
patch
|
blob
|
history
naja/scenes/credits.py
patch
|
blob
|
history
naja/scenes/game.py
patch
|
blob
|
history
naja/scenes/menu.py
patch
|
blob
|
history
naja/widgets/info_area.py
patch
|
blob
|
history
naja/widgets/robot.py
patch
|
blob
|
history
naja/widgets/selector.py
patch
|
blob
|
history
diff --git
a/naja/constants.py
b/naja/constants.py
index b6fce4e9a7b897b302b932426231f57ca9f4596f..3f45496558320aac8e3084829879cd5800404b52 100644
(file)
--- a/
naja/constants.py
+++ b/
naja/constants.py
@@
-1,3
+1,5
@@
+import pygame.locals as pgl
+
from naja.attrdict import AttrDict
from naja.attrdict import AttrDict
@@
-56,3
+58,13
@@
PLAYER_SIZE = (64, 96)
# Player States
MOVE = 1
ACT = 2
# Player States
MOVE = 1
ACT = 2
+
+KEYS = AttrDict({
+ 'UP': (pgl.K_UP, pgl.K_w, pgl.K_COMMA),
+ 'DOWN': (pgl.K_DOWN, pgl.K_s, pgl.K_o),
+ 'LEFT': (pgl.K_LEFT, pgl.K_a),
+ 'RIGHT': (pgl.K_RIGHT, pgl.K_d, pgl.K_e),
+
+ 'SELECT': (pgl.K_RETURN, pgl.K_KP_ENTER),
+ 'QUIT': (pgl.K_ESCAPE, pgl.K_q),
+})
diff --git
a/naja/scenes/credits.py
b/naja/scenes/credits.py
index 86360245b46979a0267efcd21d68f57197658aa4..67cb4e5a7045facdc7f20acf16d18f96a17c1b6e 100644
(file)
--- a/
naja/scenes/credits.py
+++ b/
naja/scenes/credits.py
@@
-4,6
+4,7
@@
Credits scene.
import pygame.locals as pgl
import pygame.locals as pgl
+from naja.constants import KEYS
from naja.scenes.scene import Scene
from naja.widgets.text import TextWidget, TextBoxWidget
from naja.events import SceneChangeEvent
from naja.scenes.scene import Scene
from naja.widgets.text import TextWidget, TextBoxWidget
from naja.events import SceneChangeEvent
@@
-31,7
+32,7
@@
class CreditsScene(Scene):
box_width=100))
def handle_scene_event(self, ev):
box_width=100))
def handle_scene_event(self, ev):
- if ev.type == pgl.KEYUP and ev.key in
(pgl.K_q, pgl.K_ESCAPE)
:
+ if ev.type == pgl.KEYUP and ev.key in
KEYS.QUIT
:
from naja.scenes.menu import MenuScene
SceneChangeEvent.post(MenuScene)
return
from naja.scenes.menu import MenuScene
SceneChangeEvent.post(MenuScene)
return
diff --git
a/naja/scenes/game.py
b/naja/scenes/game.py
index cca363f797d18b2a4f2774b9f90d530eba0b3260..5b24347a4670c2ba572fb1cc66377d8689c38ed9 100644
(file)
--- a/
naja/scenes/game.py
+++ b/
naja/scenes/game.py
@@
-4,6
+4,7
@@
Gameboard scene.
import pygame.locals as pgl
import pygame.locals as pgl
+from naja.constants import KEYS
from naja.events import SceneChangeEvent
from naja.scenes.scene import Scene
from naja.widgets.board import BoardWidget
from naja.events import SceneChangeEvent
from naja.scenes.scene import Scene
from naja.widgets.board import BoardWidget
@@
-28,6
+29,6
@@
class GameScene(Scene):
def handle_scene_event(self, ev):
from naja.scenes.menu import MenuScene
def handle_scene_event(self, ev):
from naja.scenes.menu import MenuScene
- if ev.type == pgl.KEYUP and ev.key in
(pgl.K_q, pgl.K_ESCAPE)
:
+ if ev.type == pgl.KEYUP and ev.key in
KEYS.QUIT
:
SceneChangeEvent.post(MenuScene)
return
SceneChangeEvent.post(MenuScene)
return
diff --git
a/naja/scenes/menu.py
b/naja/scenes/menu.py
index 6b4152df59401eabd0d34cd31e255a81d4643dfc..91f858b0d6304ef62e55e6142c40e9737b66d5f0 100644
(file)
--- a/
naja/scenes/menu.py
+++ b/
naja/scenes/menu.py
@@
-4,6
+4,7
@@
Main menu scene.
import pygame.locals as pgl
import pygame.locals as pgl
+from naja.constants import KEYS
from naja.scenes.scene import Scene
from naja.widgets.text import TextWidget
from naja.widgets.selector import SelectorWidget
from naja.scenes.scene import Scene
from naja.widgets.text import TextWidget
from naja.widgets.selector import SelectorWidget
@@
-32,6
+33,6
@@
class MenuScene(Scene):
def handle_scene_event(self, ev):
if ev.type == pgl.KEYDOWN:
def handle_scene_event(self, ev):
if ev.type == pgl.KEYDOWN:
- if ev.key in
(pgl.K_q, pgl.K_ESCAPE)
:
+ if ev.key in
KEYS.QUIT
:
QuitGameEvent.post()
return
QuitGameEvent.post()
return
diff --git
a/naja/widgets/info_area.py
b/naja/widgets/info_area.py
index 40bc75b662a758920a1ccc7855b12cd8571b0aae..4c79f07d330641123285efb5d7e928e32f7fee7b 100644
(file)
--- a/
naja/widgets/info_area.py
+++ b/
naja/widgets/info_area.py
@@
-4,7
+4,7
@@
Widget for the game board information area.
import pygame
import pygame.locals as pgl
import pygame
import pygame.locals as pgl
-from naja.constants import INFO_SIZE, EIGHT_BIT_SCALE, MOVE, ACT
+from naja.constants import INFO_SIZE, EIGHT_BIT_SCALE, MOVE, ACT
, KEYS
from naja.events import InvalidateTheWorld
from naja.resources import resources
from naja.resources.mutators import EIGHT_BIT
from naja.events import InvalidateTheWorld
from naja.resources import resources
from naja.resources.mutators import EIGHT_BIT
@@
-82,7
+82,7
@@
class InfoAreaWidget(Widget):
if self.state.gameboard.player_mode == MOVE:
return super(InfoAreaWidget, self).handle_event(ev)
if ev.type == pgl.KEYDOWN:
if self.state.gameboard.player_mode == MOVE:
return super(InfoAreaWidget, self).handle_event(ev)
if ev.type == pgl.KEYDOWN:
- if ev.key in
(pgl.K_RETURN, pgl.K_KP_ENTER)
:
+ if ev.key in
KEYS.SELECT
:
action = self.card.actions[self.chosen]
if not action.check_available(self.state.gameboard.player):
print "BEEP!"
action = self.card.actions[self.chosen]
if not action.check_available(self.state.gameboard.player):
print "BEEP!"
@@
-91,12
+91,12
@@
class InfoAreaWidget(Widget):
self.state.gameboard.change_mode()
InvalidateTheWorld.post()
return True
self.state.gameboard.change_mode()
InvalidateTheWorld.post()
return True
- if ev.key in
(pgl.K_UP, pgl.K_w, pgl.K_COMMA)
:
+ if ev.key in
KEYS.UP
:
if self.chosen > 0:
self.chosen -= 1
InvalidateTheWorld.post()
return True
if self.chosen > 0:
self.chosen -= 1
InvalidateTheWorld.post()
return True
- if ev.key in
(pgl.K_DOWN, pgl.K_s, pgl.K_o)
:
+ if ev.key in
KEYS.DOWN
:
if self.chosen + 1 < len(self.card.actions):
self.chosen += 1
InvalidateTheWorld.post()
if self.chosen + 1 < len(self.card.actions):
self.chosen += 1
InvalidateTheWorld.post()
diff --git
a/naja/widgets/robot.py
b/naja/widgets/robot.py
index 2653f815aef860b7bc7f06e40aa82d4ab76f457b..cbeba2e73443d4e8e75fe220033c32e00e59ba09 100644
(file)
--- a/
naja/widgets/robot.py
+++ b/
naja/widgets/robot.py
@@
-2,7
+2,7
@@
import pygame.locals as pgl
import pygame.locals as pgl
-from naja.constants import PLAYER_SIZE, BIT_SIZE, TILE_SIZE, BITS, ACT
+from naja.constants import PLAYER_SIZE, BIT_SIZE, TILE_SIZE, BITS, ACT
, KEYS
from naja.events import InvalidateTheWorld
from naja.resources import resources
from naja.resources.mutators import EIGHT_BIT
from naja.events import InvalidateTheWorld
from naja.resources import resources
from naja.resources.mutators import EIGHT_BIT
@@
-42,22
+42,22
@@
class RobotWidget(Widget):
if self.state.gameboard.player_mode == ACT:
return super(RobotWidget, self).handle_event(ev)
if ev.type == pgl.KEYDOWN:
if self.state.gameboard.player_mode == ACT:
return super(RobotWidget, self).handle_event(ev)
if ev.type == pgl.KEYDOWN:
- if ev.key in
(pgl.K_UP, pgl.K_w, pgl.K_COMMA)
:
+ if ev.key in
KEYS.UP
:
if self.state.player.move(BITS.NORTH):
self.state.gameboard.change_mode()
InvalidateTheWorld.post()
return True
if self.state.player.move(BITS.NORTH):
self.state.gameboard.change_mode()
InvalidateTheWorld.post()
return True
- if ev.key in
(pgl.K_DOWN, pgl.K_s, pgl.K_o)
:
+ if ev.key in
KEYS.DOWN
:
if self.state.player.move(BITS.SOUTH):
self.state.gameboard.change_mode()
InvalidateTheWorld.post()
return True
if self.state.player.move(BITS.SOUTH):
self.state.gameboard.change_mode()
InvalidateTheWorld.post()
return True
- if ev.key in
(pgl.K_LEFT, pgl.K_a)
:
+ if ev.key in
KEYS.LEFT
:
if self.state.player.move(BITS.WEST):
self.state.gameboard.change_mode()
InvalidateTheWorld.post()
return True
if self.state.player.move(BITS.WEST):
self.state.gameboard.change_mode()
InvalidateTheWorld.post()
return True
- if ev.key in
(pgl.K_RIGHT, pgl.K_d, pgl.K_e)
:
+ if ev.key in
KEYS.RIGHT
:
if self.state.player.move(BITS.EAST):
self.state.gameboard.change_mode()
InvalidateTheWorld.post()
if self.state.player.move(BITS.EAST):
self.state.gameboard.change_mode()
InvalidateTheWorld.post()
diff --git
a/naja/widgets/selector.py
b/naja/widgets/selector.py
index 49cf8d8715048a8371d943c605b112944a6d4371..c5ba07f37a4eb490010155d5b334f0e82c26ed14 100644
(file)
--- a/
naja/widgets/selector.py
+++ b/
naja/widgets/selector.py
@@
-1,5
+1,6
@@
import pygame.locals as pgl
import pygame.locals as pgl
+from naja.constants import KEYS
from naja.widgets.base import Container
from naja.resources import resources
from naja.resources.mutators import EIGHT_BIT, R270
from naja.widgets.base import Container
from naja.resources import resources
from naja.resources.mutators import EIGHT_BIT, R270
@@
-22,15
+23,14
@@
class SelectorWidget(Container):
def handle_event(self, ev):
if ev.type == pgl.KEYDOWN:
def handle_event(self, ev):
if ev.type == pgl.KEYDOWN:
- if ev.key in (pgl.K_DOWN, pgl.K_s, pgl.K_o,
- pgl.K_UP, pgl.K_w, pgl.K_COMMA):
- if ev.key in (pgl.K_DOWN, pgl.K_s, pgl.K_o):
+ if ev.key in KEYS.UP + KEYS.DOWN:
+ if ev.key in KEYS.DOWN:
self.position += 1
else:
self.position -= 1
self.position %= len(self.widgets)
return True
self.position += 1
else:
self.position -= 1
self.position %= len(self.widgets)
return True
- elif ev.key in
(pgl.K_RETURN, pgl.K_KP_ENTER)
:
+ elif ev.key in
KEYS.SELECT
:
return self.widgets[self.position].callback('click')
return super(SelectorWidget, self).handle_event(ev)
return self.widgets[self.position].callback('click')
return super(SelectorWidget, self).handle_event(ev)