From 54e258ed28d3615a146ea8380dfd83e42d582367 Mon Sep 17 00:00:00 2001 From: Nguyễn Gia Phong Date: Tue, 10 Aug 2021 11:27:22 +0700 Subject: s/appdirs/loca/ --- brutalmaze/__init__.py | 2 +- brutalmaze/__main__.py | 36 ++++++++++++++++-------------------- pyproject.toml | 2 +- 3 files changed, 18 insertions(+), 22 deletions(-) diff --git a/brutalmaze/__init__.py b/brutalmaze/__init__.py index 1eca2a1..9c88e1b 100644 --- a/brutalmaze/__init__.py +++ b/brutalmaze/__init__.py @@ -1,3 +1,3 @@ """Minimalist thrilling shoot 'em up game""" -from .__main__ import __version__ +__version__ = '1.1.0' diff --git a/brutalmaze/__main__.py b/brutalmaze/__main__.py index a9a0e98..24ae082 100644 --- a/brutalmaze/__main__.py +++ b/brutalmaze/__main__.py @@ -16,13 +16,11 @@ # You should have received a copy of the GNU Affero General Public License # along with Brutal Maze. If not, see . -__version__ = '1.0.0' - import re from argparse import ArgumentParser, FileType, RawTextHelpFormatter from configparser import ConfigParser from contextlib import redirect_stdout -from importlib.resources import open_binary, path, read_text +from importlib.resources import open_binary, open_text, read_text from io import StringIO from math import atan2, pi, radians from os.path import join as pathjoin, pathsep @@ -31,20 +29,19 @@ from sys import stdout from threading import Thread with redirect_stdout(StringIO()): import pygame -from appdirs import AppDirs +from loca import Loca from palace import Context, Device, free, use_context from pygame import KEYDOWN, MOUSEBUTTONUP, QUIT, VIDEORESIZE from pygame.time import Clock, get_ticks +from . import __version__ from .constants import HERO_SPEED, MIDDLE, SFX from .maze import Maze from .misc import deg, join, play, sign class ConfigReader: - """Object reading and processing INI configuration file for - Brutal Maze. - """ + """INI configuration files reader and processor.""" CONTROL_ALIASES = (('New game', 'new'), ('Toggle pause', 'pause'), ('Toggle mute', 'mute'), ('Move left', 'left'), ('Move right', 'right'), @@ -54,12 +51,13 @@ class ConfigReader: WEIRD_MOUSE_ERR = '{}: Mouse is not a suitable control' INVALID_CONTROL_ERR = '{}: {} is not recognized as a valid control key' - def __init__(self, filenames): + def __init__(self, paths): self.config = ConfigParser() # Default configuration - with path('brutalmaze', 'settings.ini') as settings: - self.config.read(settings) - self.config.read(filenames) + with open_text('brutalmaze', 'settings.ini') as settings: + self.config.read_file(settings) + self.config.read(paths) + self.parse() # Fallback to None when attribute is missing def __getattr__(self, name): return None @@ -336,16 +334,14 @@ class Game: def main(): """Start game and main loop.""" - # Read configuration file - dirs = AppDirs(appname='brutalmaze', appauthor=False, multipath=True) - parents = dirs.site_config_dir.split(pathsep) - parents.append(dirs.user_config_dir) - filenames = [pathjoin(parent, 'settings.ini') for parent in parents] - config = ConfigReader(filenames) - config.parse() + # Read configuration files + loca = Loca().config + config_files = tuple(d / 'brutalmaze' / 'settings.ini' + for d in (*loca.shared(), loca.user())) + config = ConfigReader(config_files) # Parse command-line arguments - parser = ArgumentParser(usage='%(prog)s [options]', + parser = ArgumentParser(usage='brutalmaze [options]', formatter_class=RawTextHelpFormatter) parser.add_argument('-v', '--version', action='version', version='Brutal Maze {}'.format(__version__)) @@ -356,7 +352,7 @@ def main(): parser.add_argument( '-c', '--config', metavar='PATH', help='location of the configuration file (fallback: {})'.format( - pathsep.join(filenames))) + pathsep.join(map(str, config_files)))) parser.add_argument( '-s', '--size', type=int, nargs=2, metavar=('X', 'Y'), help='the desired screen size (fallback: {}x{})'.format(*config.size)) diff --git a/pyproject.toml b/pyproject.toml index 77e06aa..864eb7c 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -7,7 +7,7 @@ module = 'brutalmaze' author = 'Nguyễn Gia Phong' author-email = 'mcsinyx@disroot.org' home-page = 'https://sr.ht/~cnx/brutalmaze' -requires = ['appdirs', 'palace', 'pygame>=2'] +requires = ['loca', 'palace', 'pygame>=2'] description-file = 'README.rst' classifiers = [ 'Development Status :: 5 - Production/Stable', -- cgit 1.4.1