import bpy from bpy.props import EnumProperty, PointerProperty, StringProperty from .. import config from ..core import contexts, runner from ..core.check import ADDON_ID class WTD_SanitySettings(bpy.types.PropertyGroup): """Per-file settings, saved in the .blend.""" context: EnumProperty( name="Context", description="Production context the file is checked against", items=contexts.enum_items(), update=lambda self, context: runner.clear(), ) asset_name: StringProperty( name="Asset Name", description="Asset / character name. Leave empty to read it from the file name", ) disabled_checks: StringProperty( name="Disabled Checks", description="Ids of the checks disabled in this file, separated by ';'", ) def get_prefs(): addon = bpy.context.preferences.addons.get(ADDON_ID) return addon.preferences if addon else None def _apply_config_override(self, context): load_config_override(self.config_path) def load_config_override(path=""): try: applied = config.apply_overrides(bpy.path.abspath(path) if path else "") except (OSError, ValueError) as exc: print(f"[WTD Sanity] Could not load config override: {exc}") else: if applied: print(f"[WTD Sanity] Config override: {', '.join(applied)}") class WTD_SanityPreferences(bpy.types.AddonPreferences): bl_idname = ADDON_ID char_reference_path: StringProperty( name="Character Reference", description="Reference JSON exported from the master character (falls back to $WTD_CHAR_REFERENCE)", subtype="FILE_PATH", ) config_path: StringProperty( name="Config Override", description="JSON file overriding values of config.py (falls back to $WTD_SANITY_CONFIG)", subtype="FILE_PATH", update=_apply_config_override, ) def draw(self, context): layout = self.layout layout.prop(self, "char_reference_path") layout.prop(self, "config_path") classes = (WTD_SanitySettings, WTD_SanityPreferences) def register(): for cls in classes: bpy.utils.register_class(cls) bpy.types.Scene.wtd_sanity = PointerProperty(type=WTD_SanitySettings) def unregister(): del bpy.types.Scene.wtd_sanity for cls in reversed(classes): bpy.utils.unregister_class(cls)