Kazeged.py 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. #!/usr/bin/env python
  2. #! coding: utf-8
  3. #! python3
  4. # Kazeged 2022
  5. import sys
  6. import argparse
  7. import os
  8. import random
  9. import engine
  10. #==============================================================================
  11. # Gather arguments
  12. #==============================================================================
  13. def Args():
  14. parser = argparse.ArgumentParser()
  15. parser.add_argument( "-g", "--game-folder", default=None, dest="gameFolder", help="Auto load a game folder" )
  16. parser.add_argument( "-l", "--game-lib-folder", default=None, dest="gameLibFolder", help="Change the game lib folder" )
  17. parser.add_argument( "-f", "--force-selection", default=False, action="store_true", dest="forceSelection", help="Force game selection from lib" )
  18. parser.add_argument( "-s", "--skip-intro", default=False, action="store_true", dest="skipIntro", help="Skips intro" )
  19. return parser.parse_args()
  20. #==============================================================================
  21. # Main program
  22. #==============================================================================
  23. if getattr( sys, 'frozen', False ) :
  24. scriptPath = os.path.dirname( sys.executable )
  25. elif __file__:
  26. scriptPath = os.path.dirname( __file__ )
  27. args = Args()
  28. # Check parameters: Skip engine intro?
  29. if args.skipIntro == False : engine.intro()
  30. # Check parameters: Change game lib folder?
  31. #TODO change default setting for MyDoccuments/home
  32. gameLibFolder = os.path.join( scriptPath, "gamelib" )
  33. if args.gameLibFolder :
  34. if os.path.exists( args.gameLibFolder ) :
  35. gameLibFolder = args.gameLibFolder
  36. # Check parameters: Auto load a game folder?
  37. gameFolder = None
  38. # Load different games depending on the case
  39. if args.gameFolder :
  40. if os.path.exists( args.gameFolder ) :
  41. gameFolder = args.gameFolder
  42. else :
  43. # Load the default game folder
  44. if os.path.exists( os.path.join( scriptPath, "game" ) ) :
  45. gameFolder = os.path.join( scriptPath, "game" )
  46. # Fallback: a small interface to choose the game to load if none given
  47. # or the user asked for the game selector
  48. if (gameFolder == None) or (args.forceSelection) :
  49. gameFolder = engine.game_selection( gameLibFolder )
  50. # Start the game
  51. engine.game_start( gameFolder )
  52. # Stop the engine
  53. engine.game_end()