costume_base.py 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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, CarpBannerType)
  8. from tasks.Component.Costume.assets import CostumeAssets
  9. from tasks.Component.CostumeBattle.assets import CostumeBattleAssets
  10. from tasks.Component.CostumeShikigami.assets import CostumeShikigamiAssets
  11. from tasks.Component.CostumeCarpBanner.assets import CostumeCarpBannerAssets
  12. # 庭院皮肤
  13. # 主界面皮肤(使用字典推导式动态生成)
  14. main_costume_model = {
  15. getattr(MainType, f"COSTUME_MAIN_{i}"): {
  16. 'I_CHECK_MAIN': f'I_CHECK_MAIN_{i}',
  17. 'I_MAIN_GOTO_EXPLORATION': f'I_MAIN_GOTO_EXPLORATION_{i}',
  18. 'I_MAIN_GOTO_SUMMON': f'I_MAIN_GOTO_SUMMON_{i}',
  19. 'I_MAIN_GOTO_TOWN': f'I_MAIN_GOTO_TOWN_{i}',
  20. 'I_PET_HOUSE': f'I_PET_HOUSE_{i}'
  21. } for i in range(1, 16)
  22. }
  23. # 鲤鱼旗皮肤
  24. carpbanner_costume_model = {
  25. getattr(CarpBannerType, f"COSTUME_CARPBANNER_{i}"): {
  26. 'I_SHI_CARD': f'I_SHI_CARD_{i}',
  27. 'I_SHI_DEFENSE': f'I_SHI_DEFENSE_{i}',
  28. 'I_SHI_GROWN': f'I_SHI_GROWN_{i}',
  29. } for i in range(1, 4)
  30. }
  31. # 战斗主题
  32. battle_theme_model = {
  33. getattr(BattleType, f"COSTUME_BATTLE_{i}"): {
  34. 'I_LOCAL': f'I_LOCAL_{i}',
  35. 'I_EXIT': f'I_EXIT_{i}',
  36. 'I_FRIENDS': f'I_FRIENDS_{i}',
  37. 'I_BATTLE_INFO': f'I_BATTLE_INFO_{i}',
  38. # 以下资源并非所有主题都需要修改,未采集的资源将被跳过
  39. 'I_WIN': f'I_WIN_{i}', # 已知:8,12,13,14
  40. 'I_DE_WIN': f'I_DE_WIN_{i}', # 已知:8,12,13,14
  41. 'I_FALSE': f'I_FALSE_{i}' # 已知:8,12,13,14
  42. } for i in range(1, 15)
  43. }
  44. # 幕间主题
  45. shikigami_costume_model = {
  46. getattr(ShikigamiType, f"COSTUME_SHIKIGAMI_{i}"): {
  47. # GameUi 进出式神录
  48. 'I_CHECK_RECORDS': f'I_CHECK_RECORDS_{i}',
  49. 'I_RECORD_SOUL_BACK': f'I_RECORD_SOUL_BACK_{i}',
  50. # SwitchSoul 相关
  51. 'I_SOUL_PRESET': f'I_SOUL_PRESET_{i}',
  52. 'I_SOU_CHECK_IN': f'I_SOU_CHECK_IN_{i}',
  53. 'I_SOU_TEAM_PRESENT': f'I_SOU_TEAM_PRESENT_{i}',
  54. 'I_SOU_CLICK_PRESENT': f'I_SOU_CLICK_PRESENT_{i}',
  55. 'I_SOU_SWITCH_SURE': f'I_SOU_SWITCH_SURE_{i}',
  56. # SwitchSoul 分组相关 (1-7组)
  57. **{f'I_SOU_CHECK_GROUP_{g}': f'I_SOU_CHECK_GROUP_{g}_{i}' for g in range(1, 8)},
  58. # SwitchSoul 队伍相关 (1-4队)
  59. **{f'I_SOU_SWITCH_{t}': f'I_SOU_SWITCH_{t}_{i}' for t in range(1, 5)},
  60. # SoulsTidy 相关
  61. 'I_ST_SOULS': f'I_ST_SOULS_{i}',
  62. 'I_ST_REPLACE': f'I_ST_REPLACE_{i}',
  63. }
  64. for i in range(1, 11) # 目前支持 COSTUME_SHIKIGAMI_1 到 COSTUME_SHIKIGAMI_10
  65. }
  66. class CostumeBase:
  67. def check_costume(self, config: CostumeConfig=None):
  68. if config is None:
  69. config: CostumeConfig = self.config.model.global_game.costume_config
  70. self.check_costume_main(config.costume_main_type)
  71. self.check_costume_carpbanner(config.costume_carpbanner_type)
  72. self.check_costume_battle(config.costume_battle_type)
  73. self.check_costume_shikigami(config.costume_shikigami_type)
  74. def replace_img(self,
  75. asset_before: str,
  76. asset_after: RuleImage,
  77. rp_roi_back: bool = True):
  78. if not hasattr(self, asset_before):
  79. return
  80. # setattr(self, asset_before, asset_after)
  81. asset_before_object: RuleImage = getattr(self, asset_before)
  82. asset_before_object.roi_front = asset_after.roi_front
  83. if rp_roi_back:
  84. asset_before_object.roi_back = asset_after.roi_back
  85. asset_before_object.threshold = asset_after.threshold
  86. asset_before_object.file = asset_after.file
  87. def check_costume_main(self, main_type: MainType):
  88. if main_type == MainType.COSTUME_MAIN:
  89. return
  90. logger.info(f'Switch main costume to {main_type}')
  91. costume_assets = CostumeAssets()
  92. for key, value in main_costume_model[main_type].items():
  93. assert_value: RuleImage = getattr(costume_assets, value)
  94. self.replace_img(key, assert_value)
  95. def check_costume_carpbanner(self, carpbanner_type: CarpBannerType):
  96. if carpbanner_type == CarpBannerType.COSTUME_CARPBANNER_DEFAULT:
  97. return
  98. logger.info(f'Switch carp banner theme {carpbanner_type} (override realm assets)')
  99. carpbanner_assets = CostumeCarpBannerAssets()
  100. model = carpbanner_costume_model.get(carpbanner_type, {})
  101. for key, value in model.items():
  102. if not hasattr(carpbanner_assets, value):
  103. logger.warning(f'Carp banner asset {value} not found, skip')
  104. continue
  105. assert_value: RuleImage = getattr(carpbanner_assets, value)
  106. # 执行替换(覆盖结界皮肤的同名key)
  107. self.replace_img(key, assert_value)
  108. def check_costume_battle(self, battle_type: BattleType):
  109. if battle_type == BattleType.COSTUME_BATTLE_DEFAULT:
  110. return
  111. logger.info(f'Switch battle theme {battle_type}')
  112. costume_battle_assets = CostumeBattleAssets()
  113. for key, value in battle_theme_model[battle_type].items():
  114. if not hasattr(costume_battle_assets, value):
  115. # 尚未采集完成的资产,跳过
  116. continue
  117. assert_value: RuleImage = getattr(costume_battle_assets, value)
  118. # 绿标的坐标点范围不变
  119. if key == 'I_LOCAL':
  120. self.replace_img(key, assert_value, rp_roi_back=False)
  121. else:
  122. self.replace_img(key, assert_value)
  123. def check_costume_shikigami(self, shikigami_type: ShikigamiType):
  124. if shikigami_type == ShikigamiType.COSTUME_SHIKIGAMI_DEFAULT:
  125. return
  126. logger.info(f'Switch shikigami theme {shikigami_type}')
  127. shikigami_assets = CostumeShikigamiAssets()
  128. model = shikigami_costume_model.get(shikigami_type, {})
  129. for key, value in model.items():
  130. if not hasattr(shikigami_assets, value):
  131. # 尚未采集完成的资产,跳过
  132. continue
  133. assert_value: RuleImage = getattr(shikigami_assets, value)
  134. # 一般不需要固定 back ROI,如确有需要可在此为特例设置 rp_roi_back=False
  135. self.replace_img(key, assert_value)
  136. if __name__ == '__main__':
  137. c = CostumeBase()
  138. c.check_costume_main(MainType.COSTUME_MAIN_2)