Minor stylistic clean-up.

This commit is contained in:
Dorian 2016-07-17 00:06:06 -04:00
parent 18bb30c971
commit de07ca8c73
2 changed files with 13 additions and 34 deletions

View File

@ -1,20 +0,0 @@
#:include debug.kv
BoxLayout:
orientation: 'horizontal'
Hex:
pos: self.pos
DebugLabel:
text: '1'
Hex:
pos: self.pos
DebugLabel:
text: '1'
<Hex@Label>:
pos_hint: {'center_x':.5, 'center_y':.5}
canvas.after:
Color:
rgba: 1,1,1,1
Ellipse:
segments: 6
pos: self.pos
size: min(self.width, self.height), min(self.width, self.height)

View File

@ -1,10 +1,10 @@
import collections import collections
from math import ceil from math import ceil
import kivy.utils
from kivy.logger import Logger from kivy.logger import Logger
from kivy.uix.label import Label from kivy.uix.label import Label
from kivy.graphics import Color, Ellipse, Line from kivy.graphics import Color, Line
import kivy.utils
from kivy.vector import Vector from kivy.vector import Vector
MapCoords = collections.namedtuple('MapCoords', ['row', 'col']) MapCoords = collections.namedtuple('MapCoords', ['row', 'col'])
@ -14,43 +14,42 @@ class HexMapCell(Label):
def __init__(self, row=0, col=0, **kwargs): def __init__(self, row=0, col=0, **kwargs):
super(HexMapCell, self).__init__(**kwargs) super(HexMapCell, self).__init__(**kwargs)
self.coords = MapCoords(row, col) self.coords = MapCoords(row, col)
## set the cube coordinates of the hexagon # set the cube coordinates of the hexagon
## as [x, y, z] # as [x, y, z]
self.cube_coords = self.even_r_to_cube(self.coords.row / 3, self.coords.col / 2) self.cube_coords = self.even_r_to_cube(self.coords.row / 3, self.coords.col / 2)
self.selected = False self.selected = False
self.visible_on_map = False self.visible_on_map = False
self.terrain_colour = Color(0, 0, 0, 1) self.terrain_colour = Color(0, 0, 0, 1)
self.terrain = '' self.terrain = ''
def even_r_to_cube(self, row, col): @staticmethod
'''compute cube coordinates from even-r hex coordinates''' def even_r_to_cube(row, col):
"""compute cube coordinates from even-r hex coordinates"""
x = int(col - ceil(float(row)/2)) x = int(col - ceil(float(row)/2))
z = row z = row
y = - x - z y = - x - z
return([x, y, z]) return [x, y, z]
def cube_to_even_r(self, x, y, z): @staticmethod
def cube_to_even_r(x, y, z):
row = int(x + ceil(z / 2)) row = int(x + ceil(z / 2))
col = z col = z
return ([row, col]) return ([row, col])
@property @property
def even_r_coords(self): def even_r_coords(self):
'''return even-r coordinates of the hexagon.''' """return even-r coordinates of the hexagon."""
return(self.cube_to_even_r(*self.cube_coords)) return self.cube_to_even_r(*self.cube_coords)
@even_r_coords.setter @even_r_coords.setter
def even_r_coords(self, value): def even_r_coords(self, value):
self.cube_coords = self.even_r_to_cube(*value) self.cube_coords = self.even_r_to_cube(*value)
def coordinate_text(self):
return '({}, {})'.format(self.coords.row, self.coords.col)
def even_r_coordinate_text(self): def even_r_coordinate_text(self):
return '{}'.format(self.even_r_coords) return '{}'.format(self.even_r_coords)
def cube_coordinate_text(self): def cube_coordinate_text(self):
return '{}\n{}\n{}'.format(*self.cube_coords) return '{!r}'.format(self.cube_coords)
def map_display_text(self): def map_display_text(self):
return "{}\n{} \n {}".format(self.even_r_coordinate_text(), self.cube_coordinate_text(), self.terrain) return "{}\n{} \n {}".format(self.even_r_coordinate_text(), self.cube_coordinate_text(), self.terrain)