costume_base.py 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. # This Python file uses the following encoding: utf-8
  2. # @author runhey
  3. # github https://github.com/runhey
  4. from module.atom.image import RuleImage
  5. from tasks.Component.Costume.config import MainType, CostumeConfig
  6. from tasks.Component.Costume.assets import CostumeAssets
  7. main_costume_model = {
  8. MainType.COSTUME_MAIN_1: {'I_CHECK_MAIN': 'I_CHECK_MAIN_1',
  9. 'I_MAIN_GOTO_EXPLORATION': 'I_MAIN_GOTO_EXPLORATION_1',
  10. 'I_MAIN_GOTO_SUMMON': 'I_MAIN_GOTO_SUMMON_1',
  11. 'I_MAIN_GOTO_TOWN': 'I_MAIN_GOTO_TOWN_1',
  12. 'I_PET_HOUSE': 'I_PET_HOUSE_1', },
  13. MainType.COSTUME_MAIN_2: {'I_CHECK_MAIN': 'I_CHECK_MAIN_2',
  14. 'I_MAIN_GOTO_EXPLORATION': 'I_MAIN_GOTO_EXPLORATION_2',
  15. 'I_MAIN_GOTO_SUMMON': 'I_MAIN_GOTO_SUMMON_2',
  16. 'I_MAIN_GOTO_TOWN': 'I_MAIN_GOTO_TOWN_2',
  17. 'I_PET_HOUSE': 'I_PET_HOUSE_2', },
  18. }
  19. class CostumeBase:
  20. def check_costume(self, config: CostumeConfig):
  21. self.check_costume_main(config.costume_main_type)
  22. def check_costume_main(self, main_type: MainType):
  23. if main_type == MainType.COSTUME_MAIN:
  24. return
  25. costume_assets = CostumeAssets()
  26. for key, value in main_costume_model[main_type].items():
  27. assert_value: RuleImage = getattr(costume_assets, value)
  28. self.replace_img(key, assert_value)
  29. def replace_img(self, asset_before: str, asset_after: RuleImage):
  30. if not hasattr(self, asset_before):
  31. return
  32. # setattr(self, asset_before, asset_after)
  33. asset_before_object: RuleImage = getattr(self, asset_before)
  34. asset_before_object.roi_front = asset_after.roi_front
  35. asset_before_object.roi_back = asset_after.roi_back
  36. asset_before_object.threshold = asset_after.threshold
  37. asset_before_object.file = asset_after.file
  38. if __name__ == '__main__':
  39. c = CostumeBase()
  40. c.check_costume_main(MainType.COSTUME_MAIN_1)