Skip to content

Commit

Permalink
GH-29: Fixing pylint issues in top level files.
Browse files Browse the repository at this point in the history
  • Loading branch information
ben-ryder committed Sep 20, 2021
1 parent fc0d738 commit a741511
Show file tree
Hide file tree
Showing 5 changed files with 76 additions and 71 deletions.
70 changes: 36 additions & 34 deletions constants.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,33 @@
import sys
import subprocess
import paths
"""
A file to export constants used throughout the application.
This module exports:
VERSION - The game version of the current code.
DISPLAY_NAME - The window title.
DISPLAY_SIZE - The fixed size of the display.
MAP_SIZE - The x by y size of the game maps, in tiles.
TILE_WIDTH - The width of game tiles in px.
TILE_HEIGHT - The height of game tiles in px.
MAP_WIDTH - The total map width, worked out from the MAP_SIZE and TILE_WIDTH.
MAP_HEIGHT - The total map height, worked out from the MAP_SIZE and TILE_WIDTH.
MAP_PADDING - An arbitrary value for padding around the map.
GAME_RECT - The rect value ([x, y, width, height]) of the map, including padding.
ORIGIN - The exact top point of the isometric map.
COLOURS - A dictionary of colours used throughout the application.
FONTS - A dictionary of font information used in teh application.
# Dev Version Text (Tries for git version, if cant get it, revert to version saved here)
try:
if sys.version_info[0] < 3.5:
version = subprocess.check_output(["git", "describe", "--tags"]).strip()
else:
version = subprocess.run(["git", "describe", "--tags"], stdout=subprocess.PIPE).stdout.decode("utf-8")
assert version != ""
except Exception: # seems to be so dependent on system and versions, easier to do a catch all
version = "v1.1.1" # git not installed, or older lib version, so revert to hardcoded version
UNIT_SPECS - The data for each unit in the game including health, attach, defense etc.
LEVELS - A matrix that manages how city level increases work.
"""

import paths

# Application version. Should always match repository tag.
VERSION = "v1.1.1"

# configuration for pygame.display
DISPLAY_NAME = "Conqueror of Empires"
Expand All @@ -27,11 +43,11 @@
MAP_HEIGHT = TILE_HEIGHT*MAP_SIZE[1]
MAP_PADDING = 20 # space between map and edge of game surface.

width = MAP_WIDTH + MAP_PADDING*2
height = MAP_HEIGHT + TILE_HEIGHT + MAP_PADDING*2
x = -MAP_WIDTH/2
y = -MAP_PADDING
GAME_RECT = [x, y, width, height] # x, y change with scroll anyway
WIDTH = MAP_WIDTH + MAP_PADDING * 2
HEIGHT = MAP_HEIGHT + TILE_HEIGHT + MAP_PADDING * 2
X = -MAP_WIDTH / 2
Y = -MAP_PADDING
GAME_RECT = [X, Y, WIDTH, HEIGHT] # x, y change with scroll anyway

ORIGIN = [GAME_RECT[2]/2 - TILE_HEIGHT + MAP_PADDING, MAP_PADDING] # top map point

Expand Down Expand Up @@ -59,18 +75,6 @@
"small": 12},
"colour": COLOURS["white"]}

# Game Data
TILE_DATA = {
"s": [0, 0, 0],
"w": [0, 0, 0],
"g": [0, 0, 0],
"f": [100, 20, 5],
"m": [10, 100, 20],
"o": [10, 100, 50],
"c": [100, 50, 25], # default of settlement store (level 1)
}


UNIT_SPECS = {
"scout": {
"max_health": 10,
Expand Down Expand Up @@ -124,9 +128,8 @@
},
}

# each item is level, each item in level is sub-level.
# item: len() = number of sub-levels to next level, value is ap cost to reach sub level/ len() = 0 means max level
# city level starts at 1, to reference level must do city_level - 1.
# Levels Matrix
# each list item represents a level, each item within a level list represents a sub-level.
LEVELS = [
[2, 2, 2], # 1 to 2
[2, 2, 2, 2], # 2 to 3
Expand All @@ -135,6 +138,5 @@
[], # 5 is max
]


# Cleanup unneeded to not pollute namespace.
del x, y, width, height, MAP_PADDING
del X, Y, WIDTH, HEIGHT, MAP_PADDING
32 changes: 21 additions & 11 deletions main.py
Original file line number Diff line number Diff line change
@@ -1,20 +1,30 @@
#!/usr/bin/env python3

"""
The main entry point for the application.
"""

import logging
logging.basicConfig(filename='main.log', filemode='w', format='%(name)s - %(levelname)s - %(message)s')
from project import control

try:
# Setting up logging
logging.basicConfig(
filename='main.log',
filemode='w',
format='%(name)s - %(levelname)s - %(message)s'
)

import project.control as control

def main():
controller = control.ApplicationController()
controller.run()
def main():
""" The main function to instantiate and run the application controller. """

controller = control.ApplicationController()
controller.run()

if __name__ == "__main__":
main()

except Exception as e:
logging.exception("caught at main")
raise e # personal choice, still want to see error in IDE
if __name__ == "__main__":
try:
main()
except Exception as error:
logging.exception("caught at main")
raise error # personal choice, still want to see error in IDE
18 changes: 18 additions & 0 deletions paths.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,21 @@
"""
A constants file to export file paths used in the application.
This includes data and asset paths.
This module exports:
dataPath - The base folder that stores game data such as maps, game saves etc.
assetPath - The base folder that stores game assets.
gamePath - The folder that stores saved games.
mapPath - The folder that stores map files.
fontPath - The folder that stores font files used in the application.
imagePath - The base path that stores image assets used in the application.
tilePath - The folder that stores map tile images.
unitPath - The folder that stores unit images.
uiPath - The folder that stores general images related to the application UI.
uiMenuPath - The folder that stores UI images specifically for the menus.
uiGamePath - The folder that stores UI images specifically for use in the game.
"""

import os

dataPath = os.getcwd() + os.sep + "data" + os.sep
Expand Down
25 changes: 0 additions & 25 deletions project/game/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,6 @@ class Tile:
def __init__(self, save_data):
self.type = save_data["type"]
self.position = save_data["position"]
# self.wood, self.stone, self.metal = constants.TILE_DATA[tile_type]

def get_save_data(self):
return {
Expand All @@ -303,30 +302,6 @@ def get_type(self):
def get_position(self):
return self.position

# def take_wood(self, amount=1): # defaults, left for future in case decide change.
# if self.wood > 0:
# self.wood = self.wood - amount
# if self.wood < 0:
# self.wood = 0 # ensures resource is fully used, but cant go negative.
# return True
# return False
#
# def take_stone(self, amount=1):
# if self.stone > 0:
# self.stone = self.stone - amount
# if self.stone < 0:
# self.stone = 0
# return True
# return False
#
# def take_metal(self, amount=1):
# if self.metal > 0:
# self.metal = self.metal - amount
# if self.metal < 0:
# self.metal = 0
# return True
# return False


class City:
def __init__(self, model_link, save_data):
Expand Down
2 changes: 1 addition & 1 deletion project/menus/menu.py
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ def __init__(self, GUI):
self.rect[0] + 5, self.rect[1] + 130)

self.version = pygame_gui.Text(
constants.version,
constants.VERSION,
constants.FONTS["sizes"]["medium"], constants.FONTS["colour"], constants.FONTS["main"],
self.rect[0] + 5, self.rect[1] + self.rect[3] - 20)

Expand Down

0 comments on commit a741511

Please sign in to comment.