Ver código fonte

feat(Costume): Attach GIF multi-frame behavior in-place so page routing works #1824
- add RuleGif.attach_to to swap GIF match methods onto a RuleImage instance
- switch COSTUME_MAIN_17 replacement from set_asset to in-place attach_to
- retune pet_house 17_a/17_b frame ROI and images

neptine 1 mês atrás
pai
commit
bb808e1bd6

+ 26 - 0
module/atom/gif.py

@@ -1,6 +1,8 @@
 # This Python file uses the following encoding: utf-8
 # @author runhey
 # github https://github.com/runhey
+import types
+
 import numpy as np
 
 from module.atom.image import RuleImage
@@ -10,6 +12,30 @@ from module.atom.image import RuleImage
 class RuleGif:
     # 大部分实现同RuleImage 的接口
 
+    @staticmethod
+    def attach_to(image_obj: RuleImage, targets: list[RuleImage]) -> None:
+        """
+        把GIF的多帧匹配行为原地挂载到一个RuleImage实例上
+
+        与replace_img的原地换属性同思路: 不换对象、不换引用,
+        持有该对象引用的Page/寻路会立即生效
+        :param image_obj: 被挂载的RuleImage实例
+        :param targets: 多帧RuleImage, 顺序即匹配优先级
+        """
+        # GIF状态
+        image_obj.targets = targets
+        image_obj.roi_front = [0, 0, 0, 0]
+        image_obj.roi_back = targets[0].roi_back
+        image_obj.appear_target = targets[0]
+        image_obj.name = targets[0].name
+        image_obj._match_init = False
+        # 方法级替换: 把RuleGif的所有公开方法绑定到该实例上
+        for name, attr in RuleGif.__dict__.items():
+            if name.startswith('_'):
+                continue
+            if isinstance(attr, types.FunctionType):
+                setattr(image_obj, name, types.MethodType(attr, image_obj))
+
     @property
     def name(self) -> str:
         return self.targets[0].name

+ 3 - 3
tasks/Component/Costume/assets.py

@@ -140,11 +140,11 @@ class CostumeAssets:
 	# 町中 c 
 	I_MAIN_GOTO_TOWN_17_C = RuleImage(roi_front=(1008,343,29,43), roi_back=(960,300,100,120), threshold=0.8, method="Template matching", file="./tasks/Component/Costume/main17/main17_main_goto_town_17_c.png")
 	# 宠物屋 a 
-	I_PET_HOUSE_17_A = RuleImage(roi_front=(1226,423,34,37), roi_back=(1191,340,89,152), threshold=0.8, method="Template matching", file="./tasks/Component/Costume/main17/main17_pet_house_17_a.png")
+	I_PET_HOUSE_17_A = RuleImage(roi_front=(1249,404,23,56), roi_back=(1231,340,49,154), threshold=0.8, method="Template matching", file="./tasks/Component/Costume/main17/main17_pet_house_17_a.png")
 	# 宠物屋 b 
-	I_PET_HOUSE_17_B = RuleImage(roi_front=(1221,422,33,39), roi_back=(1191,366,89,116), threshold=0.8, method="Template matching", file="./tasks/Component/Costume/main17/main17_pet_house_17_b.png")
+	I_PET_HOUSE_17_B = RuleImage(roi_front=(1251,417,19,45), roi_back=(1231,366,49,124), threshold=0.8, method="Template matching", file="./tasks/Component/Costume/main17/main17_pet_house_17_b.png")
 	# 宠物屋 c 
-	I_PET_HOUSE_17_C = RuleImage(roi_front=(1226,417,42,45), roi_back=(1210,340,70,140), threshold=0.8, method="Template matching", file="./tasks/Component/Costume/main17/main17_pet_house_17_c.png")
+	I_PET_HOUSE_17_C = RuleImage(roi_front=(1248,406,19,59), roi_back=(1228,340,52,176), threshold=0.8, method="Template matching", file="./tasks/Component/Costume/main17/main17_pet_house_17_c.png")
 
 
 	# Image Rule Assets

+ 10 - 5
tasks/Component/Costume/costume_base.py

@@ -32,6 +32,14 @@ main_costume_model[getattr(MainType, "COSTUME_MAIN_17")] = {
     'I_MAIN_GOTO_TOWN': ['I_MAIN_GOTO_TOWN_17_A', 'I_MAIN_GOTO_TOWN_17_B', 'I_MAIN_GOTO_TOWN_17_C'],
     'I_PET_HOUSE': ['I_PET_HOUSE_17_A', 'I_PET_HOUSE_17_B', 'I_PET_HOUSE_17_C'],
 }
+main_costume_model[getattr(MainType, "COSTUME_MAIN_13")] = {
+    'I_CHECK_MAIN': ['I_CHECK_MAIN_13',],
+    'I_MAIN_GOTO_EXPLORATION': ['I_MAIN_GOTO_EXPLORATION_13', ],
+    'I_MAIN_GOTO_SUMMON': ['I_MAIN_GOTO_SUMMON_13',],
+    'I_MAIN_GOTO_TOWN': ['I_MAIN_GOTO_TOWN_13',],
+    'I_PET_HOUSE': ['I_PET_HOUSE_13',],
+}
+
 
 
 # 鲤鱼旗皮肤
@@ -104,9 +112,6 @@ class CostumeBase:
         asset_before_object.threshold = asset_after.threshold
         asset_before_object.file = asset_after.file
 
-    def set_asset(self, asset_before: str, rule: RuleImage | RuleGif) -> None:
-        setattr(self, asset_before, rule)
-
     def check_costume_main(self, main_type: MainType):
         if main_type == MainType.COSTUME_MAIN:
             return
@@ -115,7 +120,7 @@ class CostumeBase:
         for key, value in main_costume_model[main_type].items():
             if isinstance(value, list):
                 rules: list[RuleImage] = [getattr(costume_assets, item) for item in value]
-                self.set_asset(key, RuleGif(rules))
+                RuleGif.attach_to(getattr(self, key), rules)
             else:
                 assert_value: RuleImage = getattr(costume_assets, value)
                 self.replace_img(key, assert_value)
@@ -167,4 +172,4 @@ class CostumeBase:
 
 if __name__ == '__main__':
     c = CostumeBase()
-    c.check_costume_main(MainType.COSTUME_MAIN_2)
+    c.check_costume_main(MainType.COSTUME_MAIN_13)

+ 1 - 1
tasks/Component/Costume/costume_test.py

@@ -20,7 +20,7 @@ class ScriptTask(GeneralBattle, GameUi, SwitchSoul, PetsAssets, ):
         self.ui_click(self.I_TOWN_GOTO_MAIN, self.I_CHECK_MAIN)
         # 探索测试
         self.ui_click(self.I_MAIN_GOTO_EXPLORATION, self.I_CHECK_EXPLORATION)
-        self.ui_click(self.I_UI_BACK_BLUE, self.I_CHECK_MAIN)
+        self.ui_click(self.I_UI_BACK_YELLOW, self.I_CHECK_MAIN)
         # 召唤测试
         self.ui_click(self.I_MAIN_GOTO_SUMMON, self.I_CHECK_SUMMON)
         self.ui_click(self.I_SUMMON_GOTO_MAIN, self.I_CHECK_MAIN)

+ 6 - 6
tasks/Component/Costume/main17/image.json

@@ -110,8 +110,8 @@
   {
     "itemName": "pet_house_17_a",
     "imageName": "main17_pet_house_17_a.png",
-    "roiFront": "1226,423,34,37",
-    "roiBack": "1191,340,89,152",
+    "roiFront": "1249,404,23,56",
+    "roiBack": "1231,340,49,154",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "宠物屋 a"
@@ -119,8 +119,8 @@
   {
     "itemName": "pet_house_17_b",
     "imageName": "main17_pet_house_17_b.png",
-    "roiFront": "1221,422,33,39",
-    "roiBack": "1191,366,89,116",
+    "roiFront": "1251,417,19,45",
+    "roiBack": "1231,366,49,124",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "宠物屋 b"
@@ -128,8 +128,8 @@
   {
     "itemName": "pet_house_17_c",
     "imageName": "main17_pet_house_17_c.png",
-    "roiFront": "1226,417,42,45",
-    "roiBack": "1210,340,70,140",
+    "roiFront": "1248,406,19,59",
+    "roiBack": "1228,340,52,176",
     "method": "Template matching",
     "threshold": 0.8,
     "description": "宠物屋 c"

BIN
tasks/Component/Costume/main17/main17_pet_house_17_a.png


BIN
tasks/Component/Costume/main17/main17_pet_house_17_b.png


BIN
tasks/Component/Costume/main17/main17_pet_house_17_c.png