Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Code refactoring

  • Loading branch information...
commit 84c54773ce41e00e4f881c183de4a482942e732a 1 parent 8f7e77a
Jean-André Santoni authored
Showing with 42 additions and 45 deletions.
  1. +41 −18 client/KeyboardTileTraverser.py
  2. +1 −27 client/main.py
59 client/KeyboardTileTraverser.py
View
@@ -1,5 +1,7 @@
-from direct.showbase.DirectObject import DirectObject
from Config import *
+from direct.showbase.DirectObject import DirectObject
+import math
+from operator import itemgetter
import GUI
class KeyboardTileTraverser(DirectObject):
@@ -32,40 +34,40 @@ def onArrowClicked(self, direction):
if direction == 'up':
if h >= 0 and h < 90:
- self.client.findTileAndUpdateCursorPos((x+1, y ))
+ self.findTileAndUpdateCursorPos((x+1, y ))
if h >= -90 and h < 0:
- self.client.findTileAndUpdateCursorPos((x , y-1))
+ self.findTileAndUpdateCursorPos((x , y-1))
if h >= -180 and h < -90:
- self.client.findTileAndUpdateCursorPos((x-1, y ))
+ self.findTileAndUpdateCursorPos((x-1, y ))
if h >= 90 and h < 180:
- self.client.findTileAndUpdateCursorPos((x , y+1))
+ self.findTileAndUpdateCursorPos((x , y+1))
elif direction == 'down':
if h >= 0 and h < 90:
- self.client.findTileAndUpdateCursorPos((x-1, y ))
+ self.findTileAndUpdateCursorPos((x-1, y ))
if h >= -90 and h < 0:
- self.client.findTileAndUpdateCursorPos((x , y+1))
+ self.findTileAndUpdateCursorPos((x , y+1))
if h >= -180 and h < -90:
- self.client.findTileAndUpdateCursorPos((x+1, y ))
+ self.findTileAndUpdateCursorPos((x+1, y ))
if h >= 90 and h < 180:
- self.client.findTileAndUpdateCursorPos((x , y-1))
+ self.findTileAndUpdateCursorPos((x , y-1))
elif direction == 'left':
if h >= 0 and h < 90:
- self.client.findTileAndUpdateCursorPos((x , y+1))
+ self.findTileAndUpdateCursorPos((x , y+1))
if h >= -90 and h < 0:
- self.client.findTileAndUpdateCursorPos((x+1, y ))
+ self.findTileAndUpdateCursorPos((x+1, y ))
if h >= -180 and h < -90:
- self.client.findTileAndUpdateCursorPos((x , y-1))
+ self.findTileAndUpdateCursorPos((x , y-1))
if h >= 90 and h < 180:
- self.client.findTileAndUpdateCursorPos((x-1, y ))
+ self.findTileAndUpdateCursorPos((x-1, y ))
elif direction == 'right':
if h >= 0 and h < 90:
- self.client.findTileAndUpdateCursorPos((x , y-1))
+ self.findTileAndUpdateCursorPos((x , y-1))
if h >= -90 and h < 0:
- self.client.findTileAndUpdateCursorPos((x-1, y ))
+ self.findTileAndUpdateCursorPos((x-1, y ))
if h >= -180 and h < -90:
- self.client.findTileAndUpdateCursorPos((x , y+1))
+ self.findTileAndUpdateCursorPos((x , y+1))
if h >= 90 and h < 180:
- self.client.findTileAndUpdateCursorPos((x+1, y ))
+ self.findTileAndUpdateCursorPos((x+1, y ))
# You clicked on a tile, this can mean different things, so this is a dispatcher
def onCircleClicked(self):
@@ -144,4 +146,25 @@ def onCrossClicked(self):
self.client.matrix.clearZone()
self.client.cancel_snd.play()
self.client.subphase = None
- self.client.send.UPDATE_PARTY()
+ self.client.send.UPDATE_PARTY()
+
+ # Returns the closest tile for the given x and y
+ def findTileAndUpdateCursorPos(self, pos):
+ fux, fuy = pos
+
+ # list the possibles tiles, on official maps, this list should not excess 2 items
+ possibles = []
+ for x,xs in enumerate(self.client.party['map']['tiles']):
+ for y,ys in enumerate(xs):
+ for z,zs in enumerate(ys):
+ if not self.client.party['map']['tiles'][x][y][z] is None:
+ if fux == x and fuy == y:
+ d = math.fabs(z-self.client.cursor.z) # for each possible, compute the Z delta with the current tile
+ possibles.append((x, y, z, d))
+
+ if len(possibles):
+ # sort the possibles on Z delta, and get the closer tile
+ selected = sorted(possibles, key=itemgetter(3))[0][0:3]
+
+ self.client.hover_snd.play()
+ self.client.updateCursorPos(selected)
28 client/main.py
View
@@ -4,11 +4,7 @@
from direct.gui.DirectGui import *
from direct.task.Task import Task
from direct.distributed.PyDatagramIterator import *
-from direct.distributed.PyDatagram import *
from direct.interval.IntervalGlobal import *
-import math
-from operator import itemgetter
-import json
import GUI
from CameraHandler import *
from DirectionChooser import *
@@ -210,8 +206,6 @@ def updateSpriteAnimation(self, charid, animation=False):
h = self.camhandler.container.getH()
self.matrix.sprites[charid].updateDisplayDir( h, True )
-### Events
-
def updateCursorPos(self, pos):
self.camhandler.move(self.battleGraphics.logic2terrain(pos))
@@ -237,27 +231,7 @@ def updateCursorPos(self, pos):
except:
self.coords = GUI.Coords(tile)
- # Returns the closest tile for the given x and y
- # Keyboard related callback, move this to the KeyboardTileTraverser
- def findTileAndUpdateCursorPos(self, pos):
- fux, fuy = pos
-
- # list the possibles tiles, on official maps, this list should not excess 2 items
- possibles = []
- for x,xs in enumerate(self.party['map']['tiles']):
- for y,ys in enumerate(xs):
- for z,zs in enumerate(ys):
- if not self.party['map']['tiles'][x][y][z] is None:
- if fux == x and fuy == y:
- d = math.fabs(z-self.cursor.z) # for each possible, compute the Z delta with the current tile
- possibles.append((x, y, z, d))
-
- if len(possibles):
- # sort the possibles on Z delta, and get the closer tile
- selected = sorted(possibles, key=itemgetter(3))[0][0:3]
-
- self.hover_snd.play()
- self.updateCursorPos(selected)
+### Events
# Battle func
def setupWalkableTileChooser(self, charid, walkables):
Please sign in to comment.
Something went wrong with that request. Please try again.