diff --git a/_2048/__main__.py b/_2048/__main__.py index ff2f885..838f98c 100644 --- a/_2048/__main__.py +++ b/_2048/__main__.py @@ -1,14 +1,4 @@ -"""This module makes the package executable""" +from .main import main -from .main import run_game -import os - - -def main(): - """Execute the game and store state in the current directory.""" - run_game(data_dir=os.getcwd()) - - -# Run the main function if this file is executed directly. if __name__ == '__main__': main() diff --git a/_2048/main.py b/_2048/main.py index 963e9dd..3bcea17 100644 --- a/_2048/main.py +++ b/_2048/main.py @@ -1,6 +1,8 @@ import os +import errno import pygame +from appdirs import user_data_dir from .game import Game2048 from .manager import GameManager @@ -19,8 +21,12 @@ def run_game(game_class=Game2048, title='2048: In Python!', data_dir=None): os.environ['SDL_VIDEODRIVER'] = 'windib' if data_dir is None: - # Use current directory for now. - data_dir = os.getcwd() + data_dir = user_data_dir(appauthor='Quantum', appname='2048', roaming=True) + try: + os.makedirs(data_dir) + except OSError as e: + if e.errno != errno.EEXIST: + raise screen = pygame.display.set_mode((game_class.WIDTH, game_class.HEIGHT)) manager = GameManager(Game2048, screen, diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..8f32817 --- /dev/null +++ b/setup.py @@ -0,0 +1,40 @@ +from setuptools import setup + + +setup( + name='2048', + version='0.1', + packages=['_2048'], + package_data={ + '_2048': ['*.ttf'], + }, + + entry_points={ + 'console_scripts': [ + '2048 = _2048.main:main', + ], + 'gui_scripts': [ + '2048w = _2048.main:main' + ] + + }, + install_requires=['pygame', 'appdirs'], + + author='quantum', + author_email='quantum2048@gmail.com', + url='https://github.com/quantum5/2048', + description="Quantum's version of the 2048 game, with multi-instance support," + 'restored from an old high school project.', + keywords='2048 pygame', + classifiers=[ + 'Development Status :: 3 - Beta', + 'Environment :: Win32 (MS Windows)', + 'Environment :: X11 Applications', + 'Intended Audience :: End Users/Desktop', + 'License :: OSI Approved :: GNU Affero General Public License v3', + 'Operating System :: Microsoft :: Windows', + 'Operating System :: POSIX :: Linux', + 'Programming Language :: Python', + 'Topic :: Games/Entertainment', + ], +)