Compare commits

..

No commits in common. "051e7d3a2a3515ff45d7e5f68d25360c5ffcdad3" and "50a7e138ec9c3ac1e1260928511ef0cfa9a916ad" have entirely different histories.

6 changed files with 21 additions and 246 deletions

View File

@ -16,7 +16,7 @@ from bpy.props import (StringProperty)
from .helpers import load_settings from .helpers import load_settings
from .blueprints import CreateBlueprintOperator from .blueprints import CreateBlueprintOperator
from .components.operators import CopyComponentOperator, Fix_Component_Operator, OT_rename_component, RemoveComponentFromAllObjectsOperator, RemoveComponentOperator, GenerateComponent_From_custom_property_Operator, PasteComponentOperator, AddComponentOperator, RenameHelper, Toggle_ComponentVisibility from .components.operators import CopyComponentOperator, OT_rename_component, RemoveComponentFromAllObjectsOperator, RemoveComponentOperator, GenerateComponent_From_custom_property_Operator, PasteComponentOperator, AddComponentOperator, RenameHelper, Toggle_ComponentVisibility
from .registry.registry import ComponentsRegistry,MissingBevyType from .registry.registry import ComponentsRegistry,MissingBevyType
from .registry.operators import (COMPONENTS_OT_REFRESH_CUSTOM_PROPERTIES_ALL, COMPONENTS_OT_REFRESH_CUSTOM_PROPERTIES_CURRENT, COMPONENTS_OT_REFRESH_PROPGROUPS_FROM_CUSTOM_PROPERTIES_ALL, COMPONENTS_OT_REFRESH_PROPGROUPS_FROM_CUSTOM_PROPERTIES_CURRENT, OT_select_component_name_to_replace, OT_select_object, ReloadRegistryOperator, OT_OpenFilebrowser) from .registry.operators import (COMPONENTS_OT_REFRESH_CUSTOM_PROPERTIES_ALL, COMPONENTS_OT_REFRESH_CUSTOM_PROPERTIES_CURRENT, COMPONENTS_OT_REFRESH_PROPGROUPS_FROM_CUSTOM_PROPERTIES_ALL, COMPONENTS_OT_REFRESH_PROPGROUPS_FROM_CUSTOM_PROPERTIES_CURRENT, OT_select_component_name_to_replace, OT_select_object, ReloadRegistryOperator, OT_OpenFilebrowser)
@ -88,7 +88,6 @@ classes = [
PasteComponentOperator, PasteComponentOperator,
RemoveComponentOperator, RemoveComponentOperator,
RemoveComponentFromAllObjectsOperator, RemoveComponentFromAllObjectsOperator,
Fix_Component_Operator,
OT_rename_component, OT_rename_component,
RenameHelper, RenameHelper,
GenerateComponent_From_custom_property_Operator, GenerateComponent_From_custom_property_Operator,
@ -115,8 +114,8 @@ classes = [
BEVY_COMPONENTS_PT_MainPanel, BEVY_COMPONENTS_PT_MainPanel,
BEVY_COMPONENTS_PT_ComponentsPanel, BEVY_COMPONENTS_PT_ComponentsPanel,
BEVY_COMPONENTS_PT_AdvancedToolsPanel,
BEVY_COMPONENTS_PT_Configuration, BEVY_COMPONENTS_PT_Configuration,
BEVY_COMPONENTS_PT_AdvancedToolsPanel,
MISSING_TYPES_UL_List, MISSING_TYPES_UL_List,
BEVY_COMPONENTS_PT_MissingTypesPanel, BEVY_COMPONENTS_PT_MissingTypesPanel,

View File

@ -237,23 +237,6 @@ def apply_propertyGroup_values_to_object_customProperties(object):
value = property_group_value_to_custom_property_value(propertyGroup, component_definition, registry, None) value = property_group_value_to_custom_property_value(propertyGroup, component_definition, registry, None)
object[component_name] = value object[component_name] = value
# apply component value(s) to custom property of a single component
def apply_propertyGroup_values_to_object_customProperties_for_component(object, component_name):
registry = bpy.context.window_manager.components_registry
print("yallah", component_name)
(_, propertyGroup) = upsert_component_in_object(object, component_name, registry)
component_definition = find_component_definition_from_short_name(component_name)
if component_definition != None:
print("merde")
value = property_group_value_to_custom_property_value(propertyGroup, component_definition, registry, None)
object[component_name] = value
components_metadata = object.components_meta.components
componentMeta = next(filter(lambda component: component["name"] == component_name, components_metadata), None)
if componentMeta:
print("here")
componentMeta.invalid = False
componentMeta.invalid_details = ""
def apply_customProperty_values_to_object_propertyGroups(object): def apply_customProperty_values_to_object_propertyGroups(object):
@ -275,8 +258,6 @@ def apply_customProperty_values_to_object_propertyGroups(object):
object["__disable__update"] = True # disable update callback while we set the values of the propertyGroup "tree" (as a propertyGroup can contain other propertyGroups) object["__disable__update"] = True # disable update callback while we set the values of the propertyGroup "tree" (as a propertyGroup can contain other propertyGroups)
property_group_value_from_custom_property_value(propertyGroup, component_definition, registry, customProperty_value) property_group_value_from_custom_property_value(propertyGroup, component_definition, registry, customProperty_value)
del object["__disable__update"] del object["__disable__update"]
source_componentMeta.invalid = False
source_componentMeta.invalid_details = ""
# removes the given component from the object: removes both the custom property and the matching metadata from the object # removes the given component from the object: removes both the custom property and the matching metadata from the object
def remove_component_from_object(object, component_name): def remove_component_from_object(object, component_name):

View File

@ -3,7 +3,7 @@ import json
import bpy import bpy
from bpy_types import Operator from bpy_types import Operator
from bpy.props import (StringProperty) from bpy.props import (StringProperty)
from .metadata import add_component_to_object, add_metadata_to_components_without_metadata, apply_customProperty_values_to_object_propertyGroups, apply_propertyGroup_values_to_object_customProperties_for_component, copy_propertyGroup_values_to_another_object, find_component_definition_from_short_name, remove_component_from_object from .metadata import add_component_to_object, add_metadata_to_components_without_metadata, apply_customProperty_values_to_object_propertyGroups, copy_propertyGroup_values_to_another_object, find_component_definition_from_short_name, remove_component_from_object
class AddComponentOperator(Operator): class AddComponentOperator(Operator):
"""Add component to blueprint""" """Add component to blueprint"""
@ -173,7 +173,7 @@ class RenameHelper(bpy.types.PropertyGroup):
class OT_rename_component(Operator): class OT_rename_component(Operator):
"""Rename component""" """Rename component"""
bl_idname = "object.rename_bevy_component" bl_idname = "object.rename_component"
bl_label = "rename component" bl_label = "rename component"
bl_options = {"UNDO"} bl_options = {"UNDO"}
@ -210,7 +210,12 @@ class OT_rename_component(Operator):
for index, object_name in enumerate(target_objects): for index, object_name in enumerate(target_objects):
object = bpy.data.objects[object_name] object = bpy.data.objects[object_name]
if object and original_name in object: if object and original_name in object:
# get metadata
components_metadata = getattr(object, "components_meta", None)
component_meta = None
if components_metadata:
components_metadata = components_metadata.components
component_meta = next(filter(lambda component: component["name"] == new_name, components_metadata), None)
# copy data to new component, remove the old one # copy data to new component, remove the old one
try: try:
object[new_name] = object[original_name] object[new_name] = object[original_name]
@ -218,14 +223,9 @@ class OT_rename_component(Operator):
except Exception as error: except Exception as error:
if '__disable__update' in object: if '__disable__update' in object:
del object["__disable__update"] # make sure custom properties are updateable afterwards, even in the case of failure del object["__disable__update"] # make sure custom properties are updateable afterwards, even in the case of failure
# get metadata if component_meta:
components_metadata = getattr(object, "components_meta", None) component_meta.invalid = True
if components_metadata: component_meta.invalid_details = "unknow issue when renaming/transforming component, please remove it & add it back again"
components_metadata = components_metadata.components
component_meta = next(filter(lambda component: component["name"] == new_name, components_metadata), None)
if component_meta:
component_meta.invalid = True
component_meta.invalid_details = "unknow issue when renaming/transforming component, please remove it & add it back again"
errors.append( "failed to copy old component value to new component: object: '" + object.name + "', error: " + str(error)) errors.append( "failed to copy old component value to new component: object: '" + object.name + "', error: " + str(error))
@ -237,23 +237,16 @@ class OT_rename_component(Operator):
except Exception as error: except Exception as error:
if '__disable__update' in object: if '__disable__update' in object:
del object["__disable__update"] # make sure custom properties are updateable afterwards, even in the case of failure del object["__disable__update"] # make sure custom properties are updateable afterwards, even in the case of failure
components_metadata = getattr(object, "components_meta", None) if component_meta:
if components_metadata: component_meta.invalid = True
components_metadata = components_metadata.components component_meta.invalid_details = "wrong custom property value, overwrite them by changing the values in the ui or change them & regenerate ('Update UI from ...button')"
component_meta = next(filter(lambda component: component["name"] == new_name, components_metadata), None)
if component_meta:
component_meta.invalid = True
component_meta.invalid_details = "wrong custom property value, overwrite them by changing the values in the ui or change them & regenerate"
errors.append( "wrong custom property values to generate target component: object: '" + object.name + "', error: " + str(error)) errors.append( "wrong custom property values to generate target component: object: '" + object.name + "', error: " + str(error))
progress = index / total progress = index / total
context.window_manager.components_rename_progress = progress context.window_manager.components_rename_progress = progress
# now force refresh the ui
try: bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
# now force refresh the ui
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
except: pass # this is to allow this to run in cli/headless mode
if len(errors) > 0: if len(errors) > 0:
self.report({'ERROR'}, "Failed to rename component: Errors:" + str(errors)) self.report({'ERROR'}, "Failed to rename component: Errors:" + str(errors))
@ -296,31 +289,6 @@ class GenerateComponent_From_custom_property_Operator(Operator):
return {'FINISHED'} return {'FINISHED'}
class Fix_Component_Operator(Operator):
"""attempt to fix component"""
bl_idname = "object.fix_bevy_component"
bl_label = "Fix component (attempts to)"
bl_options = {"UNDO"}
component_name: StringProperty(
name="component name",
description="component to fix",
) # type: ignore
def execute(self, context):
object = context.object
error = False
try:
apply_propertyGroup_values_to_object_customProperties_for_component(object, self.component_name)
except Exception as error:
if "__disable__update" in object:
del object["__disable__update"] # make sure custom properties are updateable afterwards, even in the case of failure
error = True
self.report({'ERROR'}, "Failed to fix component: Error:" + str(error))
if not error:
self.report({'INFO'}, "Sucessfully fixed component (please double check component & its custom property value)")
return {'FINISHED'}
class Toggle_ComponentVisibility(Operator): class Toggle_ComponentVisibility(Operator):
"""toggles components visibility""" """toggles components visibility"""
bl_idname = "object.toggle_bevy_component_visibility" bl_idname = "object.toggle_bevy_component_visibility"

View File

@ -1,9 +1,7 @@
import json import json
import bpy import bpy
from ..registry.operators import COMPONENTS_OT_REFRESH_CUSTOM_PROPERTIES_CURRENT
from .metadata import do_object_custom_properties_have_missing_metadata from .metadata import do_object_custom_properties_have_missing_metadata
from .operators import AddComponentOperator, CopyComponentOperator, Fix_Component_Operator, RemoveComponentOperator, GenerateComponent_From_custom_property_Operator, PasteComponentOperator, Toggle_ComponentVisibility from .operators import AddComponentOperator, CopyComponentOperator, RemoveComponentOperator, GenerateComponent_From_custom_property_Operator, PasteComponentOperator, Toggle_ComponentVisibility
def draw_propertyGroup( propertyGroup, layout, nesting =[], rootName=None): def draw_propertyGroup( propertyGroup, layout, nesting =[], rootName=None):
is_enum = getattr(propertyGroup, "with_enum") is_enum = getattr(propertyGroup, "with_enum")
@ -195,16 +193,6 @@ class BEVY_COMPONENTS_PT_ComponentsPanel(bpy.types.Panel):
row.label(text=error_message) row.label(text=error_message)
# "footer" with additional controls # "footer" with additional controls
if component_invalid:
if root_propertyGroup_name:
propertyGroup = getattr(component_meta, root_propertyGroup_name, None)
if propertyGroup:
unit_struct = len(propertyGroup.field_names) == 0
if unit_struct:
op = row.operator(Fix_Component_Operator.bl_idname, text="", icon="SHADERFX")
op.component_name = component_name
row.separator()
op = row.operator(RemoveComponentOperator.bl_idname, text="", icon="X") op = row.operator(RemoveComponentOperator.bl_idname, text="", icon="X")
op.component_name = component_name op.component_name = component_name
row.separator() row.separator()

View File

@ -113,10 +113,8 @@ class COMPONENTS_OT_REFRESH_PROPGROUPS_FROM_CUSTOM_PROPERTIES_CURRENT(Operator):
apply_customProperty_values_to_object_propertyGroups(object) apply_customProperty_values_to_object_propertyGroups(object)
progress = 0.5 progress = 0.5
context.window_manager.components_from_custom_properties_progress = progress context.window_manager.components_from_custom_properties_progress = progress
try: # now force refresh the ui
# now force refresh the ui bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
bpy.ops.wm.redraw_timer(type='DRAW_WIN_SWAP', iterations=1)
except:pass # ony run in ui
except Exception as error: except Exception as error:
del object["__disable__update"] # make sure custom properties are updateable afterwards, even in the case of failure del object["__disable__update"] # make sure custom properties are updateable afterwards, even in the case of failure

View File

@ -1,159 +0,0 @@
import json
import re
import bpy
import pprint
import pytest
from .setup_data import setup_data
# small helpers
def get_component_metadata(object, component_name):
target_components_metadata = object.components_meta.components
component_meta = next(filter(lambda component: component["name"] == component_name, target_components_metadata), None)
return component_meta
def get_component_propGroup(registry, component_name, component_meta):
# component_type = registry.short_names_to_long_names[component_name]
# add_component_operator = bpy.ops.object.add_bevy_component
property_group_name = registry.get_propertyGroupName_from_shortName(component_name)
propertyGroup = getattr(component_meta, property_group_name, None)
return propertyGroup
def test_rename_component_single_unit_struct(setup_data):
registry = bpy.context.window_manager.components_registry
registry.schemaPath = setup_data["schema_path"]
bpy.ops.object.reload_registry()
rename_component_operator = bpy.ops.object.rename_bevy_component
object = bpy.context.object
source_component_name = "SomeOldUnitStruct"
target_component_name = "UnitTest"
object[source_component_name] = '()'
rename_component_operator(original_name=source_component_name, new_name=target_component_name, target_objects=json.dumps([object.name]))
is_old_component_in_object = source_component_name in object
is_new_component_in_object = target_component_name in object
assert is_old_component_in_object == False
assert is_new_component_in_object == True
assert object[target_component_name] == '()'
assert get_component_propGroup(registry, target_component_name, get_component_metadata(object, target_component_name)) != None
def test_rename_component_single_complex_struct(setup_data):
registry = bpy.context.window_manager.components_registry
registry.schemaPath = setup_data["schema_path"]
bpy.ops.object.reload_registry()
rename_component_operator = bpy.ops.object.rename_bevy_component
object = bpy.context.object
source_component_name = "ProxyCollider"
target_component_name = "Collider"
object[source_component_name] = 'Capsule(Vec3(x:1.0, y:2.0, z:0.0), Vec3(x:0.0, y:0.0, z:0.0), 3.0)'
rename_component_operator(original_name=source_component_name, new_name=target_component_name, target_objects=json.dumps([object.name]))
is_old_component_in_object = source_component_name in object
is_new_component_in_object = target_component_name in object
assert is_old_component_in_object == False
assert is_new_component_in_object == True
assert object[target_component_name] == 'Capsule(Vec3(x:1.0, y:2.0, z:0.0), Vec3(x:0.0, y:0.0, z:0.0), 3.0)'
assert get_component_propGroup(registry, target_component_name, get_component_metadata(object, target_component_name)) != None
def test_rename_component_bulk(setup_data):
registry = bpy.context.window_manager.components_registry
registry.schemaPath = setup_data["schema_path"]
bpy.ops.object.reload_registry()
rename_component_operator = bpy.ops.object.rename_bevy_component
source_component_name = "SomeOldUnitStruct"
target_component_name = "UnitTest"
objects_names = []
for object in bpy.data.objects:
object[source_component_name] = '()'
objects_names.append(object.name)
# bulk rename
rename_component_operator(original_name=source_component_name, new_name=target_component_name, target_objects=json.dumps(objects_names))
for object in bpy.data.objects:
is_old_component_in_object = source_component_name in object
is_new_component_in_object = target_component_name in object
assert is_old_component_in_object == False
assert is_new_component_in_object == True
assert object[target_component_name] == '()'
assert get_component_propGroup(registry, target_component_name, get_component_metadata(object, target_component_name)) != None
def test_rename_component_single_error_handling(setup_data):
registry = bpy.context.window_manager.components_registry
registry.schemaPath = setup_data["schema_path"]
bpy.ops.object.reload_registry()
rename_component_operator = bpy.ops.object.rename_bevy_component
object = bpy.context.object
source_component_name = "SomeOldUnitStruct"
target_component_name = "UnitTest"
object[source_component_name] = 'Capsule(Vec3(x:1.0, y:2.0, z:0.0), Vec3(x:0.0, y:0.0, z:0.0), 3.0)'
expected_error = f'Error: Failed to rename component: Errors:["wrong custom property values to generate target component: object: \'{object.name}\', error: input string too big for a unit struct"]\n'
expected_error = re.escape(expected_error)
with pytest.raises(Exception, match=expected_error):
rename_component_operator(original_name=source_component_name, new_name=target_component_name, target_objects=json.dumps([object.name]))
target_component_metadata = get_component_metadata(object, target_component_name)
is_old_component_in_object = source_component_name in object
is_new_component_in_object = target_component_name in object
assert is_old_component_in_object == False
assert is_new_component_in_object == True
assert object[target_component_name] == 'Capsule(Vec3(x:1.0, y:2.0, z:0.0), Vec3(x:0.0, y:0.0, z:0.0), 3.0)'
assert get_component_propGroup(registry, target_component_name, target_component_metadata) != None
assert target_component_metadata.invalid == True
assert target_component_metadata.invalid_details == 'wrong custom property value, overwrite them by changing the values in the ui or change them & regenerate'
def test_rename_component_single_error_handling_clean_errors(setup_data):
registry = bpy.context.window_manager.components_registry
registry.schemaPath = setup_data["schema_path"]
bpy.ops.object.reload_registry()
rename_component_operator = bpy.ops.object.rename_bevy_component
object = bpy.context.object
source_component_name = "SomeOldUnitStruct"
target_component_name = "UnitTest"
object[source_component_name] = 'Capsule(Vec3(x:1.0, y:2.0, z:0.0), Vec3(x:0.0, y:0.0, z:0.0), 3.0)'
expected_error = f'Error: Failed to rename component: Errors:["wrong custom property values to generate target component: object: \'{object.name}\', error: input string too big for a unit struct"]\n'
expected_error = re.escape(expected_error)
with pytest.raises(Exception, match=expected_error):
rename_component_operator(original_name=source_component_name, new_name=target_component_name, target_objects=json.dumps([object.name]))
target_component_metadata = get_component_metadata(object, target_component_name)
is_old_component_in_object = source_component_name in object
is_new_component_in_object = target_component_name in object
assert is_old_component_in_object == False
assert is_new_component_in_object == True
assert object[target_component_name] == 'Capsule(Vec3(x:1.0, y:2.0, z:0.0), Vec3(x:0.0, y:0.0, z:0.0), 3.0)'
assert get_component_propGroup(registry, target_component_name, target_component_metadata) != None
assert target_component_metadata.invalid == True
assert target_component_metadata.invalid_details == 'wrong custom property value, overwrite them by changing the values in the ui or change them & regenerate'
# if we fix the custom property value & regen the ui, it should be all good
regen_component_operator = bpy.ops.object.refresh_ui_from_custom_properties_current
object[target_component_name] = ''
regen_component_operator()
assert target_component_metadata.invalid == False