@@ -481,13 +481,78 @@ def sprite(path: str, width: int, height: int, image_path: Optional[str], color:
481481 print_success (f"Created sprite: { path } " )
482482
483483
484+ def _build_import_settings_from_flags (
485+ texture_type : Optional [str ],
486+ sprite_mode : Optional [str ],
487+ sprite_ppu : Optional [float ],
488+ max_size : Optional [str ],
489+ compression : Optional [str ],
490+ generate_mipmaps : Optional [bool ],
491+ srgb : Optional [bool ],
492+ readable : Optional [bool ],
493+ ) -> dict [str , Any ]:
494+ """Build importSettings dict from CLI flags. Returns empty dict if no flags set."""
495+ import_settings : dict [str , Any ] = {}
496+ if texture_type :
497+ import_settings ["textureType" ] = _TEXTURE_TYPES [texture_type ]
498+ if sprite_mode :
499+ import_settings ["spriteImportMode" ] = _SPRITE_MODES [sprite_mode ]
500+ if sprite_ppu is not None :
501+ import_settings ["spritePixelsPerUnit" ] = sprite_ppu
502+ if max_size :
503+ import_settings ["maxTextureSize" ] = int (max_size )
504+ if compression :
505+ import_settings ["textureCompression" ] = _COMPRESSIONS [compression ]
506+ if generate_mipmaps is not None :
507+ import_settings ["mipmapEnabled" ] = generate_mipmaps
508+ if srgb is not None :
509+ import_settings ["sRGBTexture" ] = srgb
510+ if readable is not None :
511+ import_settings ["isReadable" ] = readable
512+ return import_settings
513+
514+
515+ def _apply_import_flags_to_params (
516+ params : dict [str , Any ],
517+ texture_type : Optional [str ],
518+ sprite_mode : Optional [str ],
519+ sprite_ppu : Optional [float ],
520+ max_size : Optional [str ],
521+ compression : Optional [str ],
522+ generate_mipmaps : Optional [bool ],
523+ srgb : Optional [bool ],
524+ readable : Optional [bool ],
525+ as_sprite : bool ,
526+ ) -> bool :
527+ """Validate and apply import-setting flags to params dict. Returns True if any import setting present."""
528+ has_other_flags = any (v is not None for v in (
529+ texture_type , sprite_mode , sprite_ppu , max_size , compression , generate_mipmaps , srgb , readable ))
530+
531+ if as_sprite :
532+ if has_other_flags :
533+ print_error ("--as-sprite cannot be combined with other import-setting flags" )
534+ sys .exit (1 )
535+ params ["spriteSettings" ] = {"pivot" : [0.5 , 0.5 ], "pixelsPerUnit" : 100 }
536+ return True
537+
538+ if has_other_flags :
539+ import_settings = _build_import_settings_from_flags (
540+ texture_type , sprite_mode , sprite_ppu , max_size , compression ,
541+ generate_mipmaps , srgb , readable )
542+ if import_settings :
543+ params ["importSettings" ] = import_settings
544+ return True
545+
546+ return False
547+
548+
484549@texture .command ("modify" )
485550@click .argument ("path" )
486551@click .option ("--set-pixels" , default = None , help = "Modification args as JSON" )
487552@click .option ("--texture-type" , type = click .Choice (list (_TEXTURE_TYPES .keys ())), help = "Texture type" )
488553@click .option ("--sprite-mode" , type = click .Choice (list (_SPRITE_MODES .keys ())), help = "Sprite import mode" )
489554@click .option ("--sprite-ppu" , type = float , help = "Sprite pixels per unit" )
490- @click .option ("--max-size" , type = click .Choice (["32" , "64" , "128" , "256" , "512" , "1024" , "2048" , "4096" , "8192" ]), help = "Max texture size" )
555+ @click .option ("--max-size" , type = click .Choice (["32" , "64" , "128" , "256" , "512" , "1024" , "2048" , "4096" , "8192" , "16384" ]), help = "Max texture size" )
491556@click .option ("--compression" , type = click .Choice (list (_COMPRESSIONS .keys ())), help = "Compression quality" )
492557@click .option ("--generate-mipmaps/--no-mipmaps" , default = None , help = "Generate mipmaps" )
493558@click .option ("--srgb/--linear" , default = None , help = "sRGB color texture" )
@@ -509,51 +574,21 @@ def modify(path: str, set_pixels: Optional[str], texture_type: Optional[str], sp
509574 """
510575 config = get_config ()
511576
512- has_import_setting = any ( v is not None for v in ( texture_type , sprite_mode , sprite_ppu , max_size , compression , generate_mipmaps , srgb , readable )) or as_sprite
577+ params : dict [ str , Any ] = { "action" : "modify" , "path" : path }
513578
514- if set_pixels is None and not has_import_setting :
515- print_error ("At least one of --set-pixels or an import-setting flag must be provided" )
516- sys .exit (1 )
517-
518- if as_sprite :
519- if any (v is not None for v in (texture_type , sprite_mode , sprite_ppu , max_size , compression , generate_mipmaps , srgb , readable )):
520- print_error ("--as-sprite cannot be combined with other import-setting flags" )
521- sys .exit (1 )
522-
523- params : dict [str , Any ] = {
524- "action" : "modify" ,
525- "path" : path ,
526- }
579+ has_import = _apply_import_flags_to_params (
580+ params , texture_type , sprite_mode , sprite_ppu , max_size ,
581+ compression , generate_mipmaps , srgb , readable , as_sprite )
527582
528583 if set_pixels is not None :
529584 try :
530585 params ["setPixels" ] = _normalize_set_pixels (set_pixels )
531586 except ValueError as e :
532587 print_error (str (e ))
533588 sys .exit (1 )
534-
535- if as_sprite :
536- params ["spriteSettings" ] = {"pivot" : [0.5 , 0.5 ], "pixelsPerUnit" : 100 }
537- elif has_import_setting :
538- import_settings : dict [str , Any ] = {}
539- if texture_type :
540- import_settings ["textureType" ] = _TEXTURE_TYPES [texture_type ]
541- if sprite_mode :
542- import_settings ["spriteImportMode" ] = _SPRITE_MODES [sprite_mode ]
543- if sprite_ppu is not None :
544- import_settings ["spritePixelsPerUnit" ] = sprite_ppu
545- if max_size :
546- import_settings ["maxTextureSize" ] = int (max_size )
547- if compression :
548- import_settings ["textureCompression" ] = _COMPRESSIONS [compression ]
549- if generate_mipmaps is not None :
550- import_settings ["mipmapEnabled" ] = generate_mipmaps
551- if srgb is not None :
552- import_settings ["sRGBTexture" ] = srgb
553- if readable is not None :
554- import_settings ["isReadable" ] = readable
555- if import_settings :
556- params ["importSettings" ] = import_settings
589+ elif not has_import :
590+ print_error ("At least one of --set-pixels or an import-setting flag must be provided" )
591+ sys .exit (1 )
557592
558593 result = run_command ("manage_texture" , params , config )
559594 click .echo (format_output (result , config .format ))
@@ -594,7 +629,7 @@ def delete(path: str, force: bool):
594629@click .option ("--texture-type" , type = click .Choice (list (_TEXTURE_TYPES .keys ())), help = "Texture type" )
595630@click .option ("--sprite-mode" , type = click .Choice (list (_SPRITE_MODES .keys ())), help = "Sprite import mode" )
596631@click .option ("--sprite-ppu" , type = float , help = "Sprite pixels per unit" )
597- @click .option ("--max-size" , type = click .Choice (["32" , "64" , "128" , "256" , "512" , "1024" , "2048" , "4096" , "8192" ]), help = "Max texture size" )
632+ @click .option ("--max-size" , type = click .Choice (["32" , "64" , "128" , "256" , "512" , "1024" , "2048" , "4096" , "8192" , "16384" ]), help = "Max texture size" )
598633@click .option ("--compression" , type = click .Choice (list (_COMPRESSIONS .keys ())), help = "Compression quality" )
599634@click .option ("--generate-mipmaps/--no-mipmaps" , default = None , help = "Generate mipmaps" )
600635@click .option ("--srgb/--linear" , default = None , help = "sRGB color texture" )
@@ -616,40 +651,15 @@ def set_import_settings(path: str, texture_type: Optional[str], sprite_mode: Opt
616651 """
617652 config = get_config ()
618653
619- params : dict [str , Any ] = {
620- "action" : "set_import_settings" ,
621- "path" : path ,
622- }
654+ params : dict [str , Any ] = {"action" : "set_import_settings" , "path" : path }
623655
624- if as_sprite :
625- if any (v is not None for v in (texture_type , sprite_mode , sprite_ppu , max_size , compression , generate_mipmaps , srgb , readable )):
626- print_error ("--as-sprite cannot be combined with other import-setting flags" )
627- sys .exit (1 )
628- params ["spriteSettings" ] = {"pivot" : [0.5 , 0.5 ], "pixelsPerUnit" : 100 }
629- else :
630- import_settings = {}
631- if texture_type :
632- import_settings ["textureType" ] = _TEXTURE_TYPES [texture_type ]
633- if sprite_mode :
634- import_settings ["spriteImportMode" ] = _SPRITE_MODES [sprite_mode ]
635- if sprite_ppu is not None :
636- import_settings ["spritePixelsPerUnit" ] = sprite_ppu
637- if max_size :
638- import_settings ["maxTextureSize" ] = int (max_size )
639- if compression :
640- import_settings ["textureCompression" ] = _COMPRESSIONS [compression ]
641- if generate_mipmaps is not None :
642- import_settings ["mipmapEnabled" ] = generate_mipmaps
643- if srgb is not None :
644- import_settings ["sRGBTexture" ] = srgb
645- if readable is not None :
646- import_settings ["isReadable" ] = readable
647-
648- if not import_settings :
649- print_error ("At least one import setting must be specified" )
650- sys .exit (1 )
656+ has_import = _apply_import_flags_to_params (
657+ params , texture_type , sprite_mode , sprite_ppu , max_size ,
658+ compression , generate_mipmaps , srgb , readable , as_sprite )
651659
652- params ["importSettings" ] = import_settings
660+ if not has_import :
661+ print_error ("At least one import setting must be specified" )
662+ sys .exit (1 )
653663
654664 result = run_command ("manage_texture" , params , config )
655665 click .echo (format_output (result , config .format ))
0 commit comments