troops.py 1.4KB

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