select_troops.py 1.8KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. # coding: utf-8
  2. import argparse
  3. import sys
  4. import typing
  5. from tkinter import Tk
  6. from synergine2.config import Config
  7. from opencombat.strategy.manager import TroopManager
  8. from opencombat.strategy.selection.gui import SelectTroopsGui
  9. def main(
  10. units_file_path: str,
  11. teams_file_path: str,
  12. countries: typing.List[str],
  13. troops_dir_path: str = '.',
  14. ) -> None:
  15. config = Config()
  16. config.load_yaml('config.yaml')
  17. troop_manager = TroopManager(
  18. config,
  19. units_file_path=units_file_path,
  20. teams_file_path=teams_file_path,
  21. )
  22. master = Tk()
  23. gui = SelectTroopsGui(
  24. config,
  25. master=master,
  26. team_stash=troop_manager.team_stash,
  27. troop_manager=troop_manager,
  28. countries=countries,
  29. troops_dir_path=troops_dir_path,
  30. )
  31. master.mainloop()
  32. if __name__ == '__main__':
  33. parser = argparse.ArgumentParser(
  34. description='Display troops selection gui',
  35. )
  36. parser.add_argument(
  37. '--units',
  38. dest='units_file_path',
  39. default='opencombat/strategy/units.xml',
  40. )
  41. parser.add_argument(
  42. '--teams',
  43. dest='teams_file_path',
  44. default='opencombat/strategy/teams.xml',
  45. )
  46. parser.add_argument(
  47. '--country',
  48. action='append',
  49. dest='countries',
  50. )
  51. parser.add_argument(
  52. '--troops-dir-path',
  53. dest='troops_dir_path',
  54. default='.',
  55. )
  56. args = parser.parse_args()
  57. if not args.countries:
  58. print(
  59. 'You must choose one or more countries with parameters '
  60. '--country, eg. `--country USSR --country DE`',
  61. file=sys.stderr,
  62. )
  63. exit(1)
  64. main(
  65. units_file_path=args.units_file_path,
  66. teams_file_path=args.teams_file_path,
  67. countries=args.countries,
  68. troops_dir_path=args.troops_dir_path,
  69. )