troops.py 1.2KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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. teams_file_path: str,
  32. ) -> UnitStash:
  33. class_address = self._config.resolve(
  34. 'global.team_stash',
  35. 'opencombat.strategy.team.stash.TeamStash',
  36. )
  37. class_ = get_class_from_string_path(
  38. self._config,
  39. class_address,
  40. )
  41. return class_(
  42. self._config,
  43. teams_file_path,
  44. )