From ec689a846c4d9b9b5b4d29b3e0368de05be6762e Mon Sep 17 00:00:00 2001 From: Aspirata <102383379+Aspirata@users.noreply.github.com> Date: Thu, 11 Jul 2024 21:38:42 +0700 Subject: [PATCH] Some Fixes, New Dev Tool (Remove Attribute)) --- Mcblend Source/Assets.py | 3 +- Mcblend Source/Operators.py | 31 ++++++++++++ Mcblend Source/UI.py | 63 +++++++++++++++---------- Mcblend Source/Utils/Absolute_Solver.py | 4 +- Mcblend Source/__init__.py | 14 +++--- 5 files changed, 78 insertions(+), 37 deletions(-) diff --git a/Mcblend Source/Assets.py b/Mcblend Source/Assets.py index e96e6612..6ac51e46 100644 --- a/Mcblend Source/Assets.py +++ b/Mcblend Source/Assets.py @@ -32,7 +32,7 @@ def append_asset(asset_name, asset_category): run_python_script(asset_path) except: - Absolute_Solver(err=traceback.print_exc(), data=asset_name, error_name="Bad Asset Import", description="Can't Import {Data} Asset") + Absolute_Solver(tech_things=traceback.print_exc(), data=asset_name, error_name="Bad Asset Import", description="Can't Import {Data} Asset") def update_assets(): items = bpy.context.scene.assetsproperties.asset_items @@ -48,7 +48,6 @@ def update_assets(): item = items.add() item.name = key - def run_python_script(file_path): def import_all_from_module(module_name, module_path=None): diff --git a/Mcblend Source/Operators.py b/Mcblend Source/Operators.py index c53da406..bdbcf41e 100644 --- a/Mcblend Source/Operators.py +++ b/Mcblend Source/Operators.py @@ -68,6 +68,37 @@ def draw(self, context): row = box.row() row.prop(self, "create_clouds", text='create_clouds', expand=True) +class RemoveAttributeOperator(Operator): + bl_idname = "special.remove_attribute" + bl_label = "Remove Attribute" + bl_options = {'REGISTER', 'UNDO'} + + attribute: bpy.props.StringProperty() + + def execute(self, context): + attr_name = self.attribute + + if attr_name in bpy.context.scene: + del bpy.context.scene[attr_name] + self.report({'INFO'}, f"Attribute '{attr_name}' has been removed.") + else: + try: + parts = attr_name.split(".") + current = bpy.context.scene + + for part in parts[:-1]: + current = getattr(current, part) + + attr = getattr(current, parts[-1]) + attr.clear() + return {'FINISHED'} + except AttributeError as e: + self.report({'WARNING'}, f"Failed to remove attribute '{attr_name}': {str(e)}") + except TypeError as e: + self.report({'WARNING'}, f"Failed to remove attribute '{attr_name}': {str(e)}") + self.report({'WARNING'}, f"Attribute '{attr_name}' does not exist.") + return {'FINISHED'} + class FixWorldOperator(Operator): bl_idname = "world.fix_world" bl_label = "Fix World" diff --git a/Mcblend Source/UI.py b/Mcblend Source/UI.py index 03e0c7de..15df176f 100644 --- a/Mcblend Source/UI.py +++ b/Mcblend Source/UI.py @@ -162,6 +162,11 @@ def draw(self, context): row.enabled = scene.resource_properties.animate_textures row.prop(scene.resource_properties, "only_fix_uv") + if Preferences.dev_tools: + row = box.row() + remove_attr = row.operator("special.remove_attribute", text="Remove Resource Packs List") + remove_attr.attribute = "resource_packs" + row = box.row() row.operator("resource_pack.apply", icon='CHECKMARK') @@ -504,39 +509,40 @@ def draw(self, context): row.prop(scene.ppbr_properties, "revert_normals", slider=True) row.enabled = not context.scene.ppbr_properties.use_normals - row = box.row() - row.prop(scene.ppbr_properties, "pspecular") - row.prop(scene.ppbr_properties, "pspecular_settings", icon=("TRIA_DOWN" if scene.ppbr_properties.pspecular_settings else "TRIA_LEFT"), icon_only=True) - if scene.ppbr_properties.pspecular_settings: - sbox = box.box() - row = sbox.row() - row.label(text="Procedural Specular Settings:", icon="MODIFIER") + if Preferences.dev_tools: + row = box.row() + row.prop(scene.ppbr_properties, "pspecular") + row.prop(scene.ppbr_properties, "pspecular_settings", icon=("TRIA_DOWN" if scene.ppbr_properties.pspecular_settings else "TRIA_LEFT"), icon_only=True) + if scene.ppbr_properties.pspecular_settings: + sbox = box.box() + row = sbox.row() + row.label(text="Procedural Specular Settings:", icon="MODIFIER") - row = sbox.row() - row.prop(scene.ppbr_properties, "ps_interpolation") + row = sbox.row() + row.prop(scene.ppbr_properties, "ps_interpolation") - row = sbox.row() - row.prop(scene.ppbr_properties, "ps_dif") + row = sbox.row() + row.prop(scene.ppbr_properties, "ps_dif") - row = sbox.row() - row.prop(scene.ppbr_properties, "ps_revert") + row = sbox.row() + row.prop(scene.ppbr_properties, "ps_revert") - row = box.row() - row.prop(scene.ppbr_properties, "proughness") - row.prop(scene.ppbr_properties, "proughness_settings", icon=("TRIA_DOWN" if scene.ppbr_properties.proughness_settings else "TRIA_LEFT"), icon_only=True) - if scene.ppbr_properties.proughness_settings: - sbox = box.box() - row = sbox.row() - row.label(text="Procedural Roughness Settings:", icon="MODIFIER") + row = box.row() + row.prop(scene.ppbr_properties, "proughness") + row.prop(scene.ppbr_properties, "proughness_settings", icon=("TRIA_DOWN" if scene.ppbr_properties.proughness_settings else "TRIA_LEFT"), icon_only=True) + if scene.ppbr_properties.proughness_settings: + sbox = box.box() + row = sbox.row() + row.label(text="Procedural Roughness Settings:", icon="MODIFIER") - row = sbox.row() - row.prop(scene.ppbr_properties, "pr_interpolation") + row = sbox.row() + row.prop(scene.ppbr_properties, "pr_interpolation") - row = sbox.row() - row.prop(scene.ppbr_properties, "pr_dif") + row = sbox.row() + row.prop(scene.ppbr_properties, "pr_dif") - row = sbox.row() - row.prop(scene.ppbr_properties, "pr_revert") + row = sbox.row() + row.prop(scene.ppbr_properties, "pr_revert") row = box.row() row.prop(scene.ppbr_properties, "advanced_settings", toggle=True, text="Advanced Settings", icon=("TRIA_DOWN" if scene.ppbr_properties.advanced_settings else "TRIA_RIGHT")) @@ -803,6 +809,11 @@ def importcategoryfix(): row = box.row() row.operator("assets.update_assets") + if Preferences.dev_tools: + row = box.row() + remove_attr = row.operator("special.remove_attribute", text="Remove Assets List") + remove_attr.attribute = "assetsproperties.asset_items" + row = box.row() row.scale_y = Big_Button_Scale row.operator("assets.import_asset", text=importcategoryfix()) diff --git a/Mcblend Source/Utils/Absolute_Solver.py b/Mcblend Source/Utils/Absolute_Solver.py index 6ffedab7..f07be935 100644 --- a/Mcblend Source/Utils/Absolute_Solver.py +++ b/Mcblend Source/Utils/Absolute_Solver.py @@ -1,5 +1,5 @@ from ..Data import * -import bpy, re +import bpy, re, traceback Absolute_Solver_Errors = { @@ -15,7 +15,7 @@ "000": { "Error Name": "Absolute Solver Error", - "Description": "Absolute Solver Can't Display This Error - {Data}, Please Report To Aspirata", + "Description": "Absolute Solver Can't Display This Error - {Data}", }, "001": { diff --git a/Mcblend Source/__init__.py b/Mcblend Source/__init__.py index b062fb78..d4380325 100644 --- a/Mcblend Source/__init__.py +++ b/Mcblend Source/__init__.py @@ -34,13 +34,13 @@ def InitOnStart(): def load_post_handler(dummy): InitOnStart() -classes = [McblendPreferences, AbsoluteSolver, RecreateEnvironment, - WorldProperties, MaterialsProperties, ResourcePackProperties, CreateEnvProperties, PPBRProperties, - WorldAndMaterialsPanel, CreateEnvOperator, FixWorldOperator, OpenConsoleOperator, SetProceduralPBROperator, FixMaterialsOperator, UpgradeMaterialsOperator, SwapTexturesOperator, - ResourcePackToggleOperator, MoveResourcePackUp, MoveResourcePackDown, RemoveResourcePack, UpdateDefaultPack, FixPacks, AddResourcePack, ApplyResourcePack, - OptimizationProperties, OptimizationPanel, OptimizeOperator, - UtilsProperties, UtilsPanel, SetRenderSettingsOperator, EnchantOperator, AssingVertexGroupOperator, - AssetsProperties, AssetPanel, Assets_List_UL_, ImportAssetOperator, ManualAssetsUpdateOperator +classes = [McblendPreferences, AbsoluteSolver, RecreateEnvironment, # Special Paneles + WorldProperties, MaterialsProperties, ResourcePackProperties, CreateEnvProperties, PPBRProperties, OptimizationProperties, UtilsProperties, AssetsProperties, # Properties + WorldAndMaterialsPanel, OptimizationPanel, UtilsPanel, AssetPanel, Assets_List_UL_, # Panels + RemoveAttributeOperator, OpenConsoleOperator, FixWorldOperator, SwapTexturesOperator, ResourcePackToggleOperator, MoveResourcePackUp, MoveResourcePackDown, # Operators + RemoveResourcePack, UpdateDefaultPack, FixPacks, AddResourcePack, ApplyResourcePack, CreateEnvOperator, FixMaterialsOperator, UpgradeMaterialsOperator, + SetProceduralPBROperator, OptimizeOperator, SetRenderSettingsOperator, EnchantOperator, AssingVertexGroupOperator, ImportAssetOperator, + ManualAssetsUpdateOperator, ] def register():