Skip to content
This repository has been archived by the owner on Jan 4, 2019. It is now read-only.

Commit

Permalink
Improvements to code health
Browse files Browse the repository at this point in the history
  • Loading branch information
cpl committed Aug 9, 2017
1 parent e116e61 commit 0076a31
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 17 deletions.
2 changes: 2 additions & 0 deletions landscape.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@ pylint:
- C0103
- R0903
- R0913
- R0901
- MC0001
- D203
pep8:
full: true
doc-warnings: true
Expand Down
6 changes: 3 additions & 3 deletions stargateRL/launcher/elements.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ def __init__(self, master, label):
self.options = {}

header_font = tkFont.Font(family='Serif', size=18, weight=tkFont.BOLD)
self._label = tk.Label(master=self, text='# '+label, anchor=tk.NW,
self._label = tk.Label(master=self, text='# '+ label, anchor=tk.NW,
padx=25, font=header_font,
bg=HEADER_COLORS[0], fg=HEADER_COLORS[1])
self._label.pack(fill=tk.X)
Expand All @@ -51,7 +51,7 @@ def __init__(self, master, label):
tk.Frame.__init__(self, master, bg=SUBFRAME_COLORS[0])
self.pack(side=tk.TOP, fill=tk.X)

self._label = tk.Label(master=self, text=label+':', anchor=tk.W,
self._label = tk.Label(master=self, text=label + ':', anchor=tk.W,
padx=30, width=10, bg=SUBFRAME_COLORS[0])
self._label.pack(fill=tk.X, side=tk.LEFT)

Expand Down Expand Up @@ -130,7 +130,7 @@ def __init__(self, master, label, value, values):

self._is_int = isinstance(value, int)

self._entry = tk.OptionMenu(self, self._value, *values)
self._entry = tk.OptionMenu(self, self._value, * values)
self._entry.config(bg=SUBFRAME_COLORS[0], relief=tk.FLAT,
highlightbackground=SUBFRAME_COLORS[0],
fg=VALUE_COLORS[1])
Expand Down
10 changes: 7 additions & 3 deletions stargateRL/launcher/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,15 +64,16 @@ def close():
popup.mainloop()
try:
popup.destroy()
# TODO: Restrain which type of exception is thrown here >.>
except Exception:
sys.exit()


# Check for special flag to launch the game without the config menu
if len(sys.argv) > 1:
if sys.argv[1] == '--launch':
import stargateRL.main
stargateRL.main.main()
import stargateRL.main as game
game.main()
sys.exit()


Expand All @@ -91,7 +92,9 @@ def close():
FONT_PATH = DirectoryPaths.FONTS.value

TILESETS = [tile for tile in os.listdir(TILE_PATH) if tile.endswith('.png')]
FONTS = [font.replace('_', ' ')[:-4] for font in os.listdir(FONT_PATH) if font.endswith('.ttf')]
FONTS = [
font.replace('_', ' ')[:-4]
for font in os.listdir(FONT_PATH) if font.endswith('.ttf')]
SIZES = [16, 20, 32, 64]

# Fill the sections with options
Expand Down Expand Up @@ -144,5 +147,6 @@ def close():
root.mainloop()
try:
root.destroy()
# TODO: Restrain which type of exception is thrown here >.>
except Exception:
sys.exit()
12 changes: 8 additions & 4 deletions stargateRL/objects/ftext.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,15 @@ def __init__(self, text, color, position, dimensions, align='left',
self._batch = batch
self._group = group

# TODO: Simplify number of local variables and this entire mammoth!
self._label = Label(text=text,
font_name=DEFAULT_FONT,
font_size=TILE_SIZE+fsdt, bold=False, italic=False,
font_size=TILE_SIZE + fsdt,
bold=False, italic=False,
color=color.value.rgba,
x=x*TILE_SIZE, y=y*TILE_SIZE,
width=x_tiles*TILE_SIZE, height=y_tiles*TILE_SIZE,
x=x * TILE_SIZE, y=y * TILE_SIZE,
width=x_tiles * TILE_SIZE,
height=y_tiles * TILE_SIZE,
anchor_x=anchor_x, anchor_y=anchor_y,
align=align, multiline=False, dpi=None,
batch=batch, group=group)
Expand Down Expand Up @@ -65,7 +68,8 @@ def __init__(self, strings, position, dimensions, colors,
for index, string in enumerate(strings):
self._labels.append(
Text(string, default,
position=(x_tiles/2+x, y_tiles/2+y_tiles/4+y-index),
position=(x_tiles / 2 + x,
y_tiles / 2 + y_tiles / 4 + y - index),
dimensions=(x_tiles, TILE_SIZE),
align=align, anchor=anchor,
fsdt=0, batch=batch, group=group))
Expand Down
8 changes: 4 additions & 4 deletions stargateRL/objects/stext.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ def __init__(self, string, position, dimensions=(None, None),
self._string = string

x, y = position
x_tiles, y_tiles = dimensions
x_tiles, _ = dimensions

# Create sprites from string
self._sprites = []
Expand All @@ -45,12 +45,12 @@ def __init__(self, string, position, dimensions=(None, None),
self._sprites.append(
Sprite(
GX_TILESETS['MAIN'].get_colored(letter_ord, tile_color),
(x+x_mod)*TILE_SIZE, (y+y_mod)*TILE_SIZE,
(x + x_mod) * TILE_SIZE, (y + y_mod) * TILE_SIZE,
batch=self._batch, group=self._group_order))

def set_color(self, tile_color=TileColor(), start=0, end=None):
"""Change the color of the text or part of the text."""
for index, sprite in enumerate(self._sprites[start:end]):
sprite.image =\
GX_TILESETS['MAIN'].get_colored(ord(self._string[index+start]),
tile_color)
GX_TILESETS['MAIN'].get_colored(
ord(self._string[index + start]), tile_color)
7 changes: 4 additions & 3 deletions stargateRL/world/exports.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,16 @@ def monochrome(map_data, file_name='map_monochrome', tone=DefaultColors.WHITE):
color = tone.value.rgb()
for row in map_data:
for val in row:
image_data.append((int(color[0]*val),
int(color[1]*val),
int(color[2]*val)))
image_data.append((int(color[0] * val),
int(color[1] * val),
int(color[2] * val)))

img = Image.new('RGB', (len(map_data), len(map_data[0])))
img.putdata(image_data)
img.save(path.join(file_path, file_name))


# TODO: Look into this ...
def exactmatch(map_data, file_name='map_exactmatch', values=[]):
"""Store a BMP image of the map, using the given value-color pairs."""
image_data = []
Expand Down

0 comments on commit 0076a31

Please sign in to comment.