diff --git a/scripts-blender/addons/blender_kitsu/__init__.py b/scripts-blender/addons/blender_kitsu/__init__.py index 50c14db9..45c92b5f 100644 --- a/scripts-blender/addons/blender_kitsu/__init__.py +++ b/scripts-blender/addons/blender_kitsu/__init__.py @@ -28,6 +28,7 @@ from blender_kitsu import ( bkglobals, types, cache, + checker, models, playblast, propsdata, @@ -78,6 +79,7 @@ if _need_reload: ui = importlib.reload(ui) sqe.reload() util = importlib.reload(util) + checker = importlib.reload(checker) generic.reload() auth.reload() context.reload() @@ -89,6 +91,7 @@ def register(): lookdev.register() prefs.register() cache.register() + checker.register() props.register() sqe.register() generic.register() @@ -111,6 +114,7 @@ def unregister(): generic.unregister() sqe.unregister() props.unregister() + checker.unregister() cache.unregister() prefs.unregister() lookdev.unregister() diff --git a/scripts-blender/addons/blender_kitsu/checker/__init__.py b/scripts-blender/addons/blender_kitsu/checker/__init__.py new file mode 100644 index 00000000..66621b13 --- /dev/null +++ b/scripts-blender/addons/blender_kitsu/checker/__init__.py @@ -0,0 +1,19 @@ +import importlib +from blender_kitsu.checker import ops + + +# ---------REGISTER ----------. + + +def reload(): + global ops + + ops = importlib.reload(ops) + + +def register(): + ops.register() + + +def unregister(): + ops.unregister() diff --git a/scripts-blender/addons/blender_kitsu/checker/ops.py b/scripts-blender/addons/blender_kitsu/checker/ops.py new file mode 100644 index 00000000..fa794a7b --- /dev/null +++ b/scripts-blender/addons/blender_kitsu/checker/ops.py @@ -0,0 +1,93 @@ +import bpy +import json +from bpy.ops import op_as_string +from pathlib import Path + + +class KITSU_PT_convention_checker_temp_ui(bpy.types.Panel): + # TODO: Remove this UI, for Testing only + + bl_category = "Checker Test" + bl_label = "Convention Chekcer Test UI" + bl_space_type = "VIEW_3D" + bl_region_type = "UI" + + def draw(self, context: bpy.types.Context) -> None: + layout = self.layout + layout.operator('kitsu.convention_checker') + + +class KITSU_OT_test_op(bpy.types.Operator): + bl_idname = "kitsu.test_op" + bl_label = 'test' + + text: bpy.props.StringProperty(name='test', default='test') + + def execute(self, context): + if self.text != "test": + self.report({'ERROR'}, "Failure") + return {'CANCELLED'} + self.report({'INFO'}, "Success") + return {'FINISHED'} + + +def get_config(): + addon_prefs = bpy.context.preferences.addons["blender_kitsu"].preferences + config_file = addon_prefs.convention_config + return Path(config_file).joinpath('convention_checker.json') + + +class KITSU_OT_convention_checker(bpy.types.Operator): + bl_idname = "kitsu.convention_checker" + bl_label = 'Convention Checker' + + @classmethod + def poll(cls, context: bpy.types.Context) -> bool: + config_file = get_config() + if not config_file.exists(): + cls.poll_message_set( + "Convention Checker config file not found. Check add-on preferences" + ) + return config_file.exists() + + def execute(self, context): + # TODO check operator exists before execution + # INFO python3 -m json.tool file.json to 'pretty print' json + config_file = get_config() + with open(config_file, "r") as f: + data = json.load(f) + print(data) + + check_ops = [] + + for item in data: + if item == 'anim': # TODO use current task type + for op in data[item]: + check_ops.append(op) + + for op in check_ops: + try: + exec(op) + except RuntimeError as ex: + args = ex.args[0].split(':') + self.report({args[0].upper()}, f"{op}:{args[1]}") + else: + self.report({'INFO'}, f"{op}: SUCCESS") + return {'FINISHED'} + + +classes = [ + KITSU_OT_test_op, + KITSU_OT_convention_checker, + KITSU_PT_convention_checker_temp_ui, +] + + +def register(): + for cls in classes: + bpy.utils.register_class(cls) + + +def unregister(): + for cls in reversed(classes): + bpy.utils.unregister_class(cls) diff --git a/scripts-blender/addons/blender_kitsu/checker/test.json b/scripts-blender/addons/blender_kitsu/checker/test.json new file mode 100644 index 00000000..90aaf27e --- /dev/null +++ b/scripts-blender/addons/blender_kitsu/checker/test.json @@ -0,0 +1,5 @@ +{ + "anim": [ + "bpy.ops.kitsu.test_op()" + ] +} \ No newline at end of file diff --git a/scripts-blender/addons/blender_kitsu/prefs.py b/scripts-blender/addons/blender_kitsu/prefs.py index e2d2545e..53a9186f 100644 --- a/scripts-blender/addons/blender_kitsu/prefs.py +++ b/scripts-blender/addons/blender_kitsu/prefs.py @@ -331,6 +331,13 @@ class KITSU_addon_preferences(bpy.types.AddonPreferences): default="", ) + convention_config: bpy.props.StringProperty( # type: ignore + name="Convention Checker Config Directory", + options={"HIDDEN", "SKIP_SAVE"}, + description="Path to convention checker configuration file.", + subtype="DIR_PATH", + ) + session: Session = Session() tasks: bpy.props.CollectionProperty(type=KITSU_task) @@ -425,6 +432,13 @@ class KITSU_addon_preferences(bpy.types.AddonPreferences): box.row().prop(self, "shot_builder_action_prefix") box.row().prop(self, "user_exec_code") + # Convention Checker + box = layout.box() + box.label( + text="Convention Checker", + ) + box.row().prop(self, "convention_config") + # Misc settings. box = layout.box() box.label(text="Miscellaneous", icon="MODIFIER")