修改检测逻辑
							parent
							
								
									3bf543f95a
								
							
						
					
					
						commit
						bc0b2f100d
					
				
							
								
								
									
										
											BIN
										
									
								
								CheckPsd/新关卡.psd
								
								
								
								
							
							
						
						
									
										
											BIN
										
									
								
								CheckPsd/新关卡.psd
								
								
								
								
							
										
											Binary file not shown.
										
									
								
							
							
								
								
									
										128
									
								
								check_zip_psd.py
								
								
								
								
							
							
						
						
									
										128
									
								
								check_zip_psd.py
								
								
								
								
							|  | @ -40,16 +40,27 @@ def check_psd(psd_path): | |||
|     psd_width = psd.width | ||||
|     psd_height = psd.height | ||||
| 
 | ||||
|     if (psd_width != config.psd_standard_width and psd_width != config.psd_standard_width2) or (psd_height != config.psd_standard_height and psd_height != config.psd_standard_height2): | ||||
|         error_log.append(f'{psd_name}:{config.error_log.psd_size_error.value}') | ||||
|     # print(f'{psd.size}') | ||||
| 
 | ||||
|     # if (psd_width != config.psd_standard_width and psd_width != config.psd_standard_width2) or (psd_height != config.psd_standard_height and psd_height != config.psd_standard_height2): | ||||
|     #     error_log.append(f'{psd_name}:{config.error_log.psd_size_error.value}') | ||||
| 
 | ||||
| 
 | ||||
|     titem_name = 'titem' | ||||
|     tfull_name = 'tfull' | ||||
|     tmask_name = 'tmask' | ||||
|     tlight_name = 'tlight' | ||||
|     tshadow_name = 'tshadow' | ||||
|     group_name = 'group_' | ||||
| 
 | ||||
|     all_items = [] | ||||
|     all_full = {} | ||||
|     all_mask = [] | ||||
|     all_tlight = [] | ||||
|     all_tshadow = [] | ||||
|     all_color_it_full = [] | ||||
|     all_color_it_item = [] | ||||
|     all_group = [] | ||||
|     # all_color_it_full = [] | ||||
|     # all_color_it_item = [] | ||||
|     is_exist_base = False | ||||
|     is_exist_titem_group = False | ||||
|     all_occlusion_degree = [] | ||||
|  | @ -59,45 +70,61 @@ def check_psd(psd_path): | |||
|             error_log.append(f'{psd_name}:{layer.name}:{config.error_log.name_contains_spaces.value}') | ||||
|         if layer.name == 'nouse' and layer.is_group(): | ||||
|             continue | ||||
|         if layer.name == 'titem' and layer.is_group(): | ||||
|         if layer.name == titem_name and layer.is_group(): | ||||
|             is_exist_titem_group = True | ||||
|             for item_layer in layer: | ||||
|                 if ' ' in item_layer.name: | ||||
|                     error_log.append(f'{psd_name}:{item_layer.name}:{config.error_log.name_contains_spaces.value}') | ||||
|                 # item_names = item_layer.name.split('_') | ||||
|                 if 'titem' in item_layer.name: | ||||
|                     if item_layer.name in all_items or item_layer.name in all_color_it_item: | ||||
|                 if titem_name in item_layer.name: | ||||
|                     if item_layer.name in all_items: ##or item_layer.name in all_color_it_item: | ||||
|                         error_log.append(f'{psd_name}:{item_layer.name}:{config.error_log.exit_repeat_layer.value}') | ||||
|                     else: | ||||
|                         if 'titemcolor' in item_layer.name: | ||||
|                             all_color_it_item.append(item_layer.name) | ||||
|                         else: | ||||
|                         # if 'titemcolor' in item_layer.name: | ||||
|                         #     all_color_it_item.append(item_layer.name) | ||||
|                         # else: | ||||
|                         all_items.append(item_layer.name) | ||||
|                 else: | ||||
|                     error_log.append(f'{psd_name}:{item_layer.name}:{config.error_log.psd_item_name_error.value}') | ||||
|         elif not layer.is_group() and 'tfull' in layer.name: | ||||
|             if layer.name in all_full.keys() or layer.name in all_color_it_full: | ||||
|                 error_log.append(f'{psd_name}:{layer.name}:{config.error_log.exit_repeat_layer.value}') | ||||
| 
 | ||||
|         elif group_name in layer.name: | ||||
|             if not layer.is_group(): | ||||
|                 error_log.append(f'{psd_name}:{layer.name}:{config.error_log.group_name_error.value}') | ||||
|             elif layer.name in all_group: | ||||
|                 error_log.append(f'{psd_name}:{layer.name}:{config.error_log.exit_repeat_group.value}') | ||||
|             else: | ||||
|                 if 'tfullcolor' in layer.name: | ||||
|                     all_color_it_full.append(layer.name) | ||||
|                 all_group.append(layer.name) | ||||
|                 is_exit_full = False | ||||
|                 for child_layer in layer: | ||||
|                     if child_layer.is_group(): | ||||
|                         error_log.append(f'{psd_name}:{child_layer.name}:{config.error_log.child_layer_is_group.value}') | ||||
|                     else: | ||||
|                     all_full[layer.name] = (layer.left, layer.top, layer.width, layer.height) | ||||
|         elif not layer.is_group() and 'tmask' in layer.name: | ||||
|             if layer.name in all_mask: | ||||
|                 error_log.append(f'{psd_name}:{layer.name}:{config.error_log.exit_repeat_layer.value}') | ||||
|                         if tfull_name in child_layer.name: | ||||
|                             if child_layer.name in all_full.keys(): | ||||
|                                 error_log.append(f'{psd_name}:{child_layer.name}:{config.error_log.exit_repeat_layer.value}') | ||||
|                             else: | ||||
|                 all_mask.append(layer.name) | ||||
|         elif not layer.is_group() and 'tlight' in layer.name: | ||||
|             if layer.name in all_tlight: | ||||
|                 error_log.append(f'{psd_name}:{layer.name}:{config.error_log.exit_repeat_layer.value}') | ||||
|                                 all_full[child_layer.name] = (child_layer.left, child_layer.top, child_layer.width, child_layer.height) | ||||
|                                 is_exit_full = True | ||||
|                         elif tmask_name in child_layer.name: | ||||
|                             if child_layer.name in all_mask: | ||||
|                                 error_log.append(f'{psd_name}:{child_layer.name}:{config.error_log.exit_repeat_layer.value}') | ||||
|                             else: | ||||
|                 all_tlight.append(layer.name) | ||||
|         elif not layer.is_group() and 'tshadow' in layer.name: | ||||
|             if layer.name in all_tshadow: | ||||
|                 error_log.append(f'{psd_name}:{layer.name}:{config.error_log.exit_repeat_layer.value}') | ||||
|                                 all_mask.append(child_layer.name) | ||||
|                         elif tshadow_name in child_layer.name: | ||||
|                             if child_layer.name in all_tshadow: | ||||
|                                 error_log.append(f'{psd_name}:{child_layer.name}:{config.error_log.exit_repeat_layer.value}') | ||||
|                             else: | ||||
|                 all_tshadow.append(layer.name) | ||||
|                                 all_tshadow.append(child_layer.name) | ||||
|                         elif tlight_name in child_layer.name: | ||||
|                             if child_layer.name in all_tlight: | ||||
|                                 error_log.append(f'{psd_name}:{child_layer.name}:{config.error_log.exit_repeat_layer.value}') | ||||
|                             else: | ||||
|                                 all_tlight.append(child_layer.name) | ||||
|                         else: | ||||
|                             error_log.append( | ||||
|                                 f'{psd_name}:{child_layer.name}:{config.error_log.child_layer_unknown.value}') | ||||
|                 if not is_exit_full: | ||||
|                     error_log.append(f'{psd_name}:{layer.name}:{config.error_log.group_tfull_not_exit.value}') | ||||
|         elif layer.name == 'base': | ||||
|             if is_exist_base: | ||||
|                 error_log.append(f'{psd_name}:{config.error_log.exit_more_base.value}') | ||||
|  | @ -112,35 +139,54 @@ def check_psd(psd_path): | |||
|         error_log.append(f'{psd_name}:{config.error_log.item_group_not_exit.value}') | ||||
| 
 | ||||
|     all_item_count = len(all_items) | ||||
|     if len(all_full) != all_item_count or ( | ||||
|             len(all_color_it_item) != 0 and len(all_color_it_item) != all_item_count) or ( | ||||
|             len(all_color_it_full) != 0 and len(all_color_it_full) != all_item_count): | ||||
|     if len(all_full) != all_item_count: | ||||
|             #or ( len(all_color_it_item) != 0 and len(all_color_it_item) != all_item_count) or ( | ||||
|             #len(all_color_it_full) != 0 and len(all_color_it_full) != all_item_count): | ||||
|         error_log.append(f'{psd_name}:{config.error_log.item_or_full_num_error.value}') | ||||
| 
 | ||||
|     for item in all_items: | ||||
|         full_name = item.replace('item', 'full') | ||||
|         if full_name not in all_full.keys(): | ||||
|             error_log.append(f'{psd_name}:{item}:{config.error_log.psd_not_full.value}') | ||||
|     if len(all_color_it_item) > 0 and len(all_color_it_full) > 0: | ||||
|         for item in all_items: | ||||
|             fullcolor_name = item.replace('item', 'fullcolor') | ||||
|             itemcolor_name = item.replace('item', 'itemcolor') | ||||
|             if fullcolor_name not in all_color_it_full: | ||||
|                 error_log.append(f'{psd_name}:{item}:{config.error_log.psd_not_fullcolor.value}') | ||||
|             if itemcolor_name not in all_color_it_item: | ||||
|                 error_log.append(f'{psd_name}:{item}:{config.error_log.psd_not_itemcolor.value}') | ||||
|     # if len(all_color_it_item) > 0 and len(all_color_it_full) > 0: | ||||
|     #     for item in all_items: | ||||
|     #         fullcolor_name = item.replace('item', 'fullcolor') | ||||
|     #         itemcolor_name = item.replace('item', 'itemcolor') | ||||
|     #         if fullcolor_name not in all_color_it_full: | ||||
|     #             error_log.append(f'{psd_name}:{item}:{config.error_log.psd_not_fullcolor.value}') | ||||
|     #         if itemcolor_name not in all_color_it_item: | ||||
|     #             error_log.append(f'{psd_name}:{item}:{config.error_log.psd_not_itemcolor.value}') | ||||
| 
 | ||||
|     # if not os.path.exists('./test'): | ||||
|     #     os.mkdir('./test') | ||||
| 
 | ||||
|     def find_layer_by_name(layers, target_name): | ||||
|         """递归搜索图层中指定名称的图层""" | ||||
|         for layer in layers: | ||||
|             if layer.name == target_name: | ||||
|                 return layer | ||||
|             if layer.is_group():  # 检查是否为组 | ||||
|                 found = find_layer_by_name(layer, target_name) | ||||
|                 if found: | ||||
|                     return found | ||||
|         return None | ||||
| 
 | ||||
|     # 计算mask和full的遮罩百分比 | ||||
|     for cur_mask in all_mask: | ||||
|         img_mask = psd.composite(layer_filter=lambda mask_layer: mask_layer.name == cur_mask) | ||||
|         # img_mask = psd.composite(layer_filter=lambda mask_layer: mask_layer.name == cur_mask) | ||||
|         layer_mask = find_layer_by_name(psd,cur_mask) | ||||
|         full_name = cur_mask.replace('mask', 'full') | ||||
|         cur_full_rect = None | ||||
|         if full_name in all_full.keys(): | ||||
|             cur_full_rect = all_full[full_name] | ||||
|             img_full = psd.composite(layer_filter=lambda full_layer: full_layer.name == full_name) | ||||
|             # img_full = psd.composite(layer_filter=lambda full_layer: full_layer.name == full_name) | ||||
|             layer_full = find_layer_by_name(psd, full_name) | ||||
|             if layer_mask is None or layer_full is None: | ||||
|                 error_log.append(f'{psd_name}:{cur_mask}:{config.error_log.not_find_mask_full.value}') | ||||
|                 break | ||||
|             img_mask = psd.composite(layer_mask) | ||||
|             img_full = psd.composite(layer_full) | ||||
| 
 | ||||
|             # img_mask.save(f'./test/{cur_mask}.png') | ||||
|             # img_full.save(f'./test/{full_name}.png') | ||||
|             per = get_item_mask_contact_ratio(img_full, img_mask, cur_full_rect) | ||||
|  |  | |||
|  | @ -20,5 +20,12 @@ class error_log(enum.Enum): | |||
|     item_or_full_num_error = 'item,full或itemcolor,fullcolor的个数不全部相同' | ||||
|     name_contains_spaces = '该图层名字中包含空格' | ||||
|     psd_mask_not_full = '没有mask对应的full' | ||||
|     not_find_mask_full = '没有找到mask或者full' | ||||
|     layer_not_need = '图层第一级有不属于我们需要的图层' | ||||
|     psd_cmyk = 'psd是CMYK的色彩空间' | ||||
| 
 | ||||
|     exit_repeat_group = '存在重复的分组' | ||||
|     group_name_error = '分组的名字错误' | ||||
|     child_layer_is_group = '子层级是个分组' | ||||
|     child_layer_unknown = '子层级名字未知' | ||||
|     group_tfull_not_exit = '分组下没有full图层' | ||||
		Loading…
	
		Reference in New Issue