From a74151196b36ec82c12f24bd78d640f9f9fd0272 Mon Sep 17 00:00:00 2001 From: Ben Ryder Date: Mon, 20 Sep 2021 20:40:13 +0100 Subject: [PATCH] GH-29: Fixing pylint issues in top level files. --- constants.py | 70 ++++++++++++++++++++++--------------------- main.py | 32 +++++++++++++------- paths.py | 18 +++++++++++ project/game/model.py | 25 ---------------- project/menus/menu.py | 2 +- 5 files changed, 76 insertions(+), 71 deletions(-) diff --git a/constants.py b/constants.py index 705a00f..868b1eb 100644 --- a/constants.py +++ b/constants.py @@ -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" @@ -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 @@ -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, @@ -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 @@ -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 diff --git a/main.py b/main.py index 0453ffe..7af1c76 100755 --- a/main.py +++ b/main.py @@ -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 diff --git a/paths.py b/paths.py index a22a4c8..4b4ffc1 100644 --- a/paths.py +++ b/paths.py @@ -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 diff --git a/project/game/model.py b/project/game/model.py index dc6457d..f93d949 100644 --- a/project/game/model.py +++ b/project/game/model.py @@ -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 { @@ -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): diff --git a/project/menus/menu.py b/project/menus/menu.py index c520b63..07b8a5d 100644 --- a/project/menus/menu.py +++ b/project/menus/menu.py @@ -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)