troops.py 1.4KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. # coding: utf-8
  2. from synergine2.config import Config
  3. from synergine2.log import get_logger
  4. from opencombat.strategy.team.stash import TeamStash
  5. from opencombat.strategy.unit.stash import UnitStash
  6. from opencombat.util import get_class_from_string_path
  7. class TroopClassBuilder(object):
  8. def __init__(
  9. self,
  10. config: Config,
  11. ) -> None:
  12. self._logger = get_logger('TroopManagerBuilder', config)
  13. self._config = config
  14. def get_unit_stash(
  15. self,
  16. units_file_path: str,
  17. ) -> UnitStash:
  18. class_address = self._config.resolve(
  19. 'global.unit_stash',
  20. 'opencombat.strategy.unit.stash.UnitStash',
  21. )
  22. class_ = get_class_from_string_path(
  23. self._config,
  24. class_address,
  25. )
  26. return class_(
  27. self._config,
  28. units_file_path,
  29. )
  30. def get_team_stash(
  31. self,
  32. units_file_path: str,
  33. teams_file_path: str,
  34. ) -> TeamStash:
  35. class_address = self._config.resolve(
  36. 'global.team_stash',
  37. 'opencombat.strategy.team.stash.TeamStash',
  38. )
  39. class_ = get_class_from_string_path(
  40. self._config,
  41. class_address,
  42. )
  43. unit_stash = self.get_unit_stash(units_file_path)
  44. return class_(
  45. self._config,
  46. teams_file_path,
  47. unit_stash=unit_stash,
  48. )