costume_base.py 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  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 module.logger import logger
  6. from tasks.Component.Costume.config import (MainType, CostumeConfig, RealmType,
  7. ThemeType, ShikigamiType, SignType, BattleType)
  8. from tasks.Component.Costume.assets import CostumeAssets
  9. from tasks.Component.CostumeRealm.assets import CostumeRealmAssets
  10. from tasks.Component.CostumeBattle.assets import CostumeBattleAssets
  11. # 庭院皮肤
  12. # 主界面皮肤(使用字典推导式动态生成)
  13. main_costume_model = {
  14. getattr(MainType, f"COSTUME_MAIN_{i}"): {
  15. 'I_CHECK_MAIN': f'I_CHECK_MAIN_{i}',
  16. 'I_MAIN_GOTO_EXPLORATION': f'I_MAIN_GOTO_EXPLORATION_{i}',
  17. 'I_MAIN_GOTO_SUMMON': f'I_MAIN_GOTO_SUMMON_{i}',
  18. 'I_MAIN_GOTO_TOWN': f'I_MAIN_GOTO_TOWN_{i}',
  19. 'I_PET_HOUSE': f'I_PET_HOUSE_{i}'
  20. } for i in range(1, 12)
  21. }
  22. # 结界皮肤
  23. realm_costume_model = {
  24. RealmType.COSTUME_REALM_1: {'I_SHI_CARD': 'I_SHI_CARD_1',
  25. 'I_SHI_DEFENSE': 'I_SHI_DEFENSE_1',},
  26. RealmType.COSTUME_REALM_2: {'I_SHI_CARD': 'I_SHI_CARD_2',
  27. 'I_SHI_DEFENSE': 'I_SHI_DEFENSE_2',
  28. 'I_SHI_GROWN': 'I_SHI_GROWN_2',
  29. 'I_BOX_AP': 'I_BOX_AP_2',
  30. 'I_BOX_EXP': 'I_BOX_EXP_2'},
  31. }
  32. # 战斗主题(使用循环处理常规情况 + 特例处理)
  33. battle_theme_model = {}
  34. for i in range(1, 11):
  35. entry = {
  36. 'I_LOCAL': f'I_LOCAL_{i}',
  37. 'I_EXIT': f'I_EXIT_{i}',
  38. 'I_FRIENDS': f'I_FRIENDS_{i}',
  39. }
  40. if i == 8: # 特殊处理第8项
  41. entry.update({
  42. 'I_WIN': 'I_WIN_8',
  43. 'I_DE_WIN': 'I_DE_WIN_8',
  44. 'I_FALSE': 'I_FALSE_8'
  45. })
  46. battle_theme_model[getattr(BattleType, f"COSTUME_BATTLE_{i}")] = entry
  47. class CostumeBase:
  48. def check_costume(self, config: CostumeConfig=None):
  49. if config is None:
  50. config: CostumeConfig = self.config.model.global_game.costume_config
  51. self.check_costume_main(config.costume_main_type)
  52. self.check_costume_realm(config.costume_realm_type)
  53. self.check_costume_battle(config.costume_battle_type)
  54. def replace_img(self,
  55. asset_before: str,
  56. asset_after: RuleImage,
  57. rp_roi_back: bool = True):
  58. if not hasattr(self, asset_before):
  59. return
  60. # setattr(self, asset_before, asset_after)
  61. asset_before_object: RuleImage = getattr(self, asset_before)
  62. asset_before_object.roi_front = asset_after.roi_front
  63. if rp_roi_back:
  64. asset_before_object.roi_back = asset_after.roi_back
  65. asset_before_object.threshold = asset_after.threshold
  66. asset_before_object.file = asset_after.file
  67. def check_costume_main(self, main_type: MainType):
  68. if main_type == MainType.COSTUME_MAIN:
  69. return
  70. logger.info(f'Switch main costume to {main_type}')
  71. costume_assets = CostumeAssets()
  72. for key, value in main_costume_model[main_type].items():
  73. assert_value: RuleImage = getattr(costume_assets, value)
  74. self.replace_img(key, assert_value)
  75. def check_costume_realm(self, realm_type: RealmType):
  76. if realm_type == RealmType.COSTUME_REALM_DEFAULT:
  77. return
  78. logger.info(f'Switch realm theme {realm_type}')
  79. costume_realm_assets = CostumeRealmAssets()
  80. for key, value in realm_costume_model[realm_type].items():
  81. assert_value: RuleImage = getattr(costume_realm_assets, value)
  82. self.replace_img(key, assert_value)
  83. def check_costume_battle(self, battle_type: BattleType):
  84. if battle_type == BattleType.COSTUME_BATTLE_DEFAULT:
  85. return
  86. logger.info(f'Switch battle theme {battle_type}')
  87. costume_battle_assets = CostumeBattleAssets()
  88. for key, value in battle_theme_model[battle_type].items():
  89. assert_value: RuleImage = getattr(costume_battle_assets, value)
  90. # 绿标的坐标点范围不变
  91. if key == 'I_LOCAL':
  92. self.replace_img(key, assert_value, rp_roi_back=False)
  93. else:
  94. self.replace_img(key, assert_value)
  95. if __name__ == '__main__':
  96. c = CostumeBase()
  97. c.check_costume_main(MainType.COSTUME_MAIN_2)