feat(bevy_components): continued refactor to use long names instead of short names & co

* changed all various uses of short name to long_name
 * same for type_names
 * also changed bevy_registry_export to output "long_name" instead of "title" for coherence
 * related changes & tweaks
 * still WIP
This commit is contained in:
kaosat.dev 2024-05-05 22:04:25 +02:00
parent ac02e8b364
commit 0ca57ba6de
21 changed files with 1460 additions and 1539 deletions

View File

@ -28,7 +28,7 @@ pub fn export_types(world: &mut World) {
writer,
&json!({
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "bevy component registry schema",
"long_name": "bevy component registry schema",
"$defs": schemas,
}),
)
@ -41,6 +41,7 @@ pub fn export_type(reg: &TypeRegistration) -> (String, Value) {
let t = reg.type_info();
let binding = t.type_path_table();
let short_name = binding.short_path();
println!("T YOOO {:?}", t);
let mut schema = match t {
TypeInfo::Struct(info) => {
let properties = info
@ -57,7 +58,7 @@ pub fn export_type(reg: &TypeRegistration) -> (String, Value) {
json!({
"type": "object",
"typeInfo": "Struct",
"title": t.type_path(),
"long_name": t.type_path(),
"properties": properties,
"additionalProperties": false,
"required": info
@ -75,7 +76,7 @@ pub fn export_type(reg: &TypeRegistration) -> (String, Value) {
json!({
"type": "string",
"typeInfo": "Enum",
"title": t.type_path(),
"long_name": t.type_path(),
"oneOf": info
.iter()
.map(|variant| match variant {
@ -94,12 +95,12 @@ pub fn export_type(reg: &TypeRegistration) -> (String, Value) {
VariantInfo::Struct(v) => json!({
"type": "object",
"typeInfo": "Struct",
"title": v.name(),
"long_name": v.name(),
"short_name": v.name().split("::").last().unwrap_or(v.name()),
"properties": v
.iter()
.enumerate()
.map(|(variant_idx, field)| (field.name().to_owned(), add_min_max(json!({"type": typ(field.type_path()), "title": field.name()}), reg, field_idx, Some(variant_idx))))
.map(|(variant_idx, field)| (field.name().to_owned(), add_min_max(json!({"type": typ(field.type_path()), "long_name": field.name()}), reg, field_idx, Some(variant_idx))))
.collect::<Map<_, _>>(),
"additionalProperties": false,
"required": v
@ -111,7 +112,7 @@ pub fn export_type(reg: &TypeRegistration) -> (String, Value) {
VariantInfo::Tuple(v) => json!({
"type": "array",
"typeInfo": "Tuple",
"title": v.name(),
"long_name": v.name(),
"short_name":v.name(),
"prefixItems": v
.iter()
@ -121,7 +122,7 @@ pub fn export_type(reg: &TypeRegistration) -> (String, Value) {
"items": false,
}),
VariantInfo::Unit(v) => json!({
"title": v.name(),
"long_name": v.name(),
}),
})
.collect::<Vec<_>>();
@ -129,13 +130,13 @@ pub fn export_type(reg: &TypeRegistration) -> (String, Value) {
json!({
"type": "object",
"typeInfo": "Enum",
"title": t.type_path(),
"long_name": t.type_path(),
"oneOf": variants,
})
}
}
TypeInfo::TupleStruct(info) => json!({
"title": t.type_path(),
"long_name": t.type_path(),
"type": "array",
"typeInfo": "TupleStruct",
"prefixItems": info
@ -147,26 +148,26 @@ pub fn export_type(reg: &TypeRegistration) -> (String, Value) {
}),
TypeInfo::List(info) => {
json!({
"title": t.type_path(),
"long_name": t.type_path(),
"type": "array",
"typeInfo": "List",
"items": json!({"type": typ(info.item_type_path_table().path())}),
})
}
TypeInfo::Array(info) => json!({
"title": t.type_path(),
"long_name": t.type_path(),
"type": "array",
"typeInfo": "Array",
"items": json!({"type": typ(info.item_type_path_table().path())}),
}),
TypeInfo::Map(info) => json!({
"title": t.type_path(),
"long_name": t.type_path(),
"type": "object",
"typeInfo": "Map",
"additionalProperties": json!({"type": typ(info.value_type_path_table().path())}),
}),
TypeInfo::Tuple(info) => json!({
"title": t.type_path(),
"long_name": t.type_path(),
"type": "array",
"typeInfo": "Tuple",
"prefixItems": info
@ -177,7 +178,7 @@ pub fn export_type(reg: &TypeRegistration) -> (String, Value) {
"items": false,
}),
TypeInfo::Value(info) => json!({
"title": t.type_path(),
"long_name": t.type_path(),
"type": map_json_type(info.type_path()),
"typeInfo": "Value",
}),

File diff suppressed because it is too large Load Diff

View File

@ -48,7 +48,7 @@ UI:
* Cuboid(Vec3)
* Sphere(radius)
- [x] deal with enums variants that do not have any data: ex {
"title": "Mesh"
"long_name": "Mesh"
}
- [x] remove / change use of ComponentDefinitionsList
@ -82,7 +82,7 @@ UI:
- [x] change custom property => propGroup to convert RON => Json first => obsolete
- [x] cleanup process_lists
- [x] fix issues with enum variants with only a title
- [x] fix issues with enum variants with only a long_name
- [x] display single item enums inline, others in a seperate row
@ -217,6 +217,7 @@ Restructuring of storage of components
- [ ] in conversions from propgroups
component_name = definition["short_name"]
- [ ] fix is_component_valid that is used in gltf_auto_export
- Hashmap Support
- [ ] fix parsing of keys's type either on Bevy side (prefered, unlikely to be possible) or on the Blender side

View File

@ -28,19 +28,6 @@ from .components.maps import GENERIC_MAP_OT_actions
from .components.definitions_list import (ComponentDefinitionsList, ClearComponentDefinitionsList)
from .components.ui import (BEVY_COMPONENTS_PT_ComponentsPanel)
# just a test, remove
def scan_item(item, nesting=0):
try:
for sub in dict(item).keys():
print("--", sub, getattr(item[sub], "type_name", None), item[sub], nesting)
try:
scan_item(item[sub], nesting+1)
except:
pass
except:
pass
class BEVY_COMPONENTS_PT_MainPanel(bpy.types.Panel):
bl_idname = "BEVY_COMPONENTS_PT_MainPanel"
bl_label = ""

View File

@ -2,12 +2,11 @@ import bpy
from bpy.props import (StringProperty, BoolProperty, PointerProperty)
from bpy_types import (PropertyGroup)
from .helpers import ping_depsgraph_update
from ..propGroups.conversions_from_prop_group import property_group_value_to_custom_property_value
from ..propGroups.conversions_to_prop_group import property_group_value_from_custom_property_value
class ComponentMetadata(bpy.types.PropertyGroup):
name : bpy.props.StringProperty(
short_name : bpy.props.StringProperty(
name = "name",
default = ""
) # type: ignore
@ -17,11 +16,6 @@ class ComponentMetadata(bpy.types.PropertyGroup):
default = ""
) # type: ignore
type_name : bpy.props.StringProperty(
name = "Type",
default = ""
) # type: ignore
values: bpy.props.StringProperty(
name = "Value",
default = ""
@ -64,12 +58,6 @@ class ComponentsMeta(PropertyGroup):
def unregister(cls):
del bpy.types.Object.components_meta
# We need a collection property of components PER object
def get_component_metadata_by_short_name(object, short_name):
if not "components_meta" in object:
return None
return next(filter(lambda component: component["name"] == short_name, object.components_meta.components), None)
# remove no longer valid metadata from object
def cleanup_invalid_metadata(object):
bevy_components = get_bevy_components(object)
@ -78,23 +66,15 @@ def cleanup_invalid_metadata(object):
components_metadata = object.components_meta.components
to_remove = []
for index, component_meta in enumerate(components_metadata):
short_name = component_meta.name
long_name = component_meta.long_name
if long_name not in bevy_components.keys():
print("component:", short_name, "present in metadata, but not in object")
print("component:", long_name, "present in metadata, but not in object")
to_remove.append(index)
for index in to_remove:
components_metadata.remove(index)
# returns a component definition ( an entry in registry's type_infos) with matching short name or None if nothing has been found
def find_component_definition_from_short_name(short_name):
registry = bpy.context.window_manager.components_registry
long_name = registry.short_names_to_long_names.get(short_name, None)
if long_name != None:
return registry.type_infos.get(long_name, None)
return None
# returns a component definition ( an entry in registry's type_infos) with matching long name or None if nothing has been found
def find_component_definition_from_long_name(long_name):
registry = bpy.context.window_manager.components_registry
return registry.type_infos.get(long_name, None)
@ -114,14 +94,14 @@ def do_object_custom_properties_have_missing_metadata(object):
components_metadata = components_metadata.components
missing_metadata = False
for component_name in dict(object) :
for component_name in get_bevy_components(object) :
if component_name == "components_meta":
continue
component_meta = next(filter(lambda component: component["name"] == component_name, components_metadata), None)
component_meta = next(filter(lambda component: component["long_name"] == component_name, components_metadata), None)
if component_meta == None:
# current component has no metadata but is there even a compatible type in the registry ?
# if not ignore it
component_definition = find_component_definition_from_short_name(component_name)
component_definition = find_component_definition_from_long_name(component_name)
if component_definition != None:
missing_metadata = True
break
@ -173,7 +153,7 @@ def add_component_to_object(object, component_definition, value=None):
cleanup_invalid_metadata(object)
if object is not None:
# print("add_component_to_object", component_definition)
long_name = component_definition["title"]
long_name = component_definition["long_name"]
registry = bpy.context.window_manager.components_registry
if not registry.has_type_infos():
raise Exception('registry type infos have not been loaded yet or are missing !')
@ -201,7 +181,7 @@ def upsert_component_in_object(object, long_name, registry):
component_definition = registry.type_infos.get(long_name, None)
if component_definition != None:
short_name = component_definition["short_name"]
long_name = component_definition["title"]
long_name = component_definition["long_name"]
property_group_name = registry.get_propertyGroupName_from_longName(long_name)
propertyGroup = None
@ -286,13 +266,13 @@ def apply_propertyGroup_values_to_object_customProperties(object):
def apply_propertyGroup_values_to_object_customProperties_for_component(object, component_name):
registry = bpy.context.window_manager.components_registry
(_, propertyGroup) = upsert_component_in_object(object, component_name, registry)
component_definition = find_component_definition_from_short_name(component_name)
component_definition = find_component_definition_from_long_name(component_name)
if component_definition != None:
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)
componentMeta = next(filter(lambda component: component["long_name"] == component_name, components_metadata), None)
if componentMeta:
componentMeta.invalid = False
componentMeta.invalid_details = ""
@ -301,14 +281,14 @@ def apply_propertyGroup_values_to_object_customProperties_for_component(object,
def apply_customProperty_values_to_object_propertyGroups(object):
print("apply custom properties to ", object.name)
registry = bpy.context.window_manager.components_registry
for component_name in dict(object) :
for component_name in get_bevy_components(object) :
if component_name == "components_meta":
continue
component_definition = find_component_definition_from_short_name(component_name)
component_definition = find_component_definition_from_long_name(component_name)
if component_definition != None:
property_group_name = registry.get_propertyGroupName_from_shortName(component_name)
property_group_name = registry.get_propertyGroupName_from_longName(component_name)
components_metadata = object.components_meta.components
source_componentMeta = next(filter(lambda component: component["name"] == component_name, components_metadata), None)
source_componentMeta = next(filter(lambda component: component["long_name"] == component_name, components_metadata), None)
# matching component means we already have this type of component
propertyGroup = getattr(source_componentMeta, property_group_name, None)
customProperty_value = object[component_name]

View File

@ -4,7 +4,7 @@ import bpy
from bpy_types import Operator
from bpy.props import (StringProperty)
from .metadata import add_component_from_custom_property, 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, get_bevy_component_value_by_long_name, get_bevy_components, is_bevy_component_in_object, remove_component_from_object, toggle_component
from .metadata import add_component_from_custom_property, 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, get_bevy_component_value_by_long_name, get_bevy_components, is_bevy_component_in_object, remove_component_from_object, toggle_component
class AddComponentOperator(Operator):
"""Add Bevy component to object"""
@ -236,7 +236,7 @@ class OT_rename_component(Operator):
try:
# attempt conversion
long_name = registry.short_names_to_long_names[new_name]
long_name = new_name
component_definition = type_infos[long_name]
add_component_to_object(object, component_definition, object[new_name])
except Exception as error:

View File

@ -2,23 +2,19 @@ import json
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, get_bevy_components
from .operators import AddComponentOperator, CopyComponentOperator, Fix_Component_Operator, RemoveComponentOperator, GenerateComponent_From_custom_property_Operator, PasteComponentOperator, Toggle_ComponentVisibility
def draw_propertyGroup( propertyGroup, layout, nesting =[], rootName=None):
is_enum = getattr(propertyGroup, "with_enum")
is_list = getattr(propertyGroup, "with_list")
is_map = getattr(propertyGroup, "with_map")
#nesting = nesting + [current_short_name] # we need this convoluted "nested path strings " workaround so that operators working on a given
# item in our components hierarchy can get the correct propertyGroup by STRINGS because of course, we cannot pass objects to operators...sigh
# if it is an enum, the first field name is always the list of enum variants, the others are the variants
field_names = propertyGroup.field_names
#print("")
#print("drawing", propertyGroup, nesting, "component_name", rootName)
#type_name = getattr(propertyGroup, "type_name", None)#propertyGroup.type_name if "type_name" in propertyGroup else ""
#print("type name", type_name)
#print("name", propertyGroup.name, "name2", getattr(propertyGroup, "name"), "short_name", getattr(propertyGroup, "short_name", None), "nesting", nesting)
if is_enum:
subrow = layout.row()
display_name = field_names[0] if propertyGroup.tupple_or_struct == "struct" else ""
@ -39,9 +35,7 @@ def draw_propertyGroup( propertyGroup, layout, nesting =[], rootName=None):
# if an enum variant is not a propertyGroup
break
elif is_list:
#print("show list", propertyGroup, dict(propertyGroup), propertyGroup.type_name)
item_list = getattr(propertyGroup, "list")
item_type = getattr(propertyGroup, "type_name_short")
list_index = getattr(propertyGroup, "list_index")
box = layout.box()
split = box.split(factor=0.9)
@ -199,10 +193,9 @@ class BEVY_COMPONENTS_PT_ComponentsPanel(bpy.types.Panel):
components_in_object = object.components_meta.components
components_bla = json.loads(object["bevy_components"]) if "bevy_components" in object else '{}'
#print("components_names", dict(components_bla).keys())
for component_name in sorted(dict(components_bla)) : # sorted by component name, practical
for component_name in sorted(get_bevy_components(object)) : # sorted by component name, practical
#print("component_name", component_name)
if component_name == "components_meta":
continue

View File

@ -28,29 +28,29 @@ conversion_tables = {
#converts the value of a property group(no matter its complexity) into a single custom property value
# this is more or less a glorified "to_ron()" method (not quite but close to)
def property_group_value_to_custom_property_value(property_group, definition, registry, parent=None, value=None):
component_name = definition["short_name"] # FIXME: we should operate based on long names
print('definition', definition)
long_name = definition["long_name"]
type_info = definition["typeInfo"] if "typeInfo" in definition else None
type_def = definition["type"] if "type" in definition else None
type_name = definition["title"]
is_value_type = type_name in conversion_tables
# print("computing custom property: component name:", component_name, "type_info", type_info, "type_def", type_def, "type_name", type_name)
is_value_type = long_name in conversion_tables
# print("computing custom property: component name:", long_name, "type_info", type_info, "type_def", type_def)
if is_value_type:
value = conversion_tables[type_name](value)
value = conversion_tables[long_name](value)
elif type_info == "Struct":
values = {}
if len(property_group.field_names) ==0:
value = '()'
else:
for index, field_name in enumerate(property_group.field_names):
item_type_name = definition["properties"][field_name]["type"]["$ref"].replace("#/$defs/", "")
item_definition = registry.type_infos[item_type_name] if item_type_name in registry.type_infos else None
item_long_name = definition["properties"][field_name]["type"]["$ref"].replace("#/$defs/", "")
item_definition = registry.type_infos[item_long_name] if item_long_name in registry.type_infos else None
value = getattr(property_group, field_name)
is_property_group = isinstance(value, PropertyGroup)
child_property_group = value if is_property_group else None
if item_definition != None:
value = property_group_value_to_custom_property_value(child_property_group, item_definition, registry, parent=component_name, value=value)
value = property_group_value_to_custom_property_value(child_property_group, item_definition, registry, parent=long_name, value=value)
else:
value = '""'
values[field_name] = value
@ -58,14 +58,14 @@ def property_group_value_to_custom_property_value(property_group, definition, re
elif type_info == "Tuple":
values = {}
for index, field_name in enumerate(property_group.field_names):
item_type_name = definition["prefixItems"][index]["type"]["$ref"].replace("#/$defs/", "")
item_definition = registry.type_infos[item_type_name] if item_type_name in registry.type_infos else None
item_long_name = definition["prefixItems"][index]["type"]["$ref"].replace("#/$defs/", "")
item_definition = registry.type_infos[item_long_name] if item_long_name in registry.type_infos else None
value = getattr(property_group, field_name)
is_property_group = isinstance(value, PropertyGroup)
child_property_group = value if is_property_group else None
if item_definition != None:
value = property_group_value_to_custom_property_value(child_property_group, item_definition, registry, parent=component_name, value=value)
value = property_group_value_to_custom_property_value(child_property_group, item_definition, registry, parent=long_name, value=value)
else:
value = '""'
values[field_name] = value
@ -75,23 +75,24 @@ def property_group_value_to_custom_property_value(property_group, definition, re
values = {}
for index, field_name in enumerate(property_group.field_names):
#print("toto", index, definition["prefixItems"][index]["type"]["$ref"])
item_type_name = definition["prefixItems"][index]["type"]["$ref"].replace("#/$defs/", "")
item_definition = registry.type_infos[item_type_name] if item_type_name in registry.type_infos else None
# print("here", item_type_name, item_definition)
item_long_name = definition["prefixItems"][index]["type"]["$ref"].replace("#/$defs/", "")
item_definition = registry.type_infos[item_long_name] if item_long_name in registry.type_infos else None
value = getattr(property_group, field_name)
is_property_group = isinstance(value, PropertyGroup)
child_property_group = value if is_property_group else None
if item_definition != None:
value = property_group_value_to_custom_property_value(child_property_group, item_definition, registry, parent=component_name, value=value)
value = property_group_value_to_custom_property_value(child_property_group, item_definition, registry, parent=long_name, value=value)
else:
value = '""'
values[field_name] = value
value = tuple(e for e in list(values.values()))
elif type_info == "Enum":
short_name = definition["short_name"]
print("ENUM", definition, property_group.field_names, long_name)
# TODO: perhaps use a mapping of (long) component name to a short ID , like we do in get_propertyGroupName_from_longName
selected = getattr(property_group, component_name)
selected = getattr(property_group, short_name)
if type_def == "object":
selection_index = property_group.field_names.index("variant_"+selected)
@ -102,21 +103,21 @@ def property_group_value_to_custom_property_value(property_group, definition, re
is_property_group = isinstance(value, PropertyGroup)
child_property_group = value if is_property_group else None
value = property_group_value_to_custom_property_value(child_property_group, variant_definition, registry, parent=component_name, value=value)
value = property_group_value_to_custom_property_value(child_property_group, variant_definition, registry, parent=long_name, value=value)
value = selected + str(value,) #"{}{},".format(selected ,value)
elif "properties" in variant_definition:
value = getattr(property_group, variant_name)
is_property_group = isinstance(value, PropertyGroup)
child_property_group = value if is_property_group else None
value = property_group_value_to_custom_property_value(child_property_group, variant_definition, registry, parent=component_name, value=value)
value = property_group_value_to_custom_property_value(child_property_group, variant_definition, registry, parent=long_name, value=value)
value = selected + str(value,)
else:
value = getattr(property_group, variant_name)
is_property_group = isinstance(value, PropertyGroup)
child_property_group = value if is_property_group else None
if child_property_group:
value = property_group_value_to_custom_property_value(child_property_group, variant_definition, registry, parent=component_name, value=value)
value = property_group_value_to_custom_property_value(child_property_group, variant_definition, registry, parent=long_name, value=value)
value = selected + str(value,)
else:
value = selected # here the value of the enum is just the name of the variant
@ -125,14 +126,13 @@ def property_group_value_to_custom_property_value(property_group, definition, re
elif type_info == "List":
item_list = getattr(property_group, "list")
#item_type = getattr(property_group, "type_name_short")
value = []
for item in item_list:
item_type_name = getattr(item, "type_name")
definition = registry.type_infos[item_type_name] if item_type_name in registry.type_infos else None
item_long_name = getattr(item, "long_name")
definition = registry.type_infos[item_long_name] if item_long_name in registry.type_infos else None
if definition != None:
item_value = property_group_value_to_custom_property_value(item, definition, registry, component_name, None)
if item_type_name.startswith("wrapper_"): #if we have a "fake" tupple for aka for value types, we need to remove one nested level
item_value = property_group_value_to_custom_property_value(item, definition, registry, long_name, None)
if item_long_name.startswith("wrapper_"): #if we have a "fake" tupple for aka for value types, we need to remove one nested level
item_value = item_value[0]
else:
item_value = '""'
@ -144,21 +144,21 @@ def property_group_value_to_custom_property_value(property_group, definition, re
value = {}
for index, key in enumerate(keys_list):
# first get the keys
key_type_name = getattr(key, "type_name")
definition = registry.type_infos[key_type_name] if key_type_name in registry.type_infos else None
key_long_name = getattr(key, "long_name")
definition = registry.type_infos[key_long_name] if key_long_name in registry.type_infos else None
if definition != None:
key_value = property_group_value_to_custom_property_value(key, definition, registry, component_name, None)
if key_type_name.startswith("wrapper_"): #if we have a "fake" tupple for aka for value types, we need to remove one nested level
key_value = property_group_value_to_custom_property_value(key, definition, registry, long_name, None)
if key_long_name.startswith("wrapper_"): #if we have a "fake" tupple for aka for value types, we need to remove one nested level
key_value = key_value[0]
else:
key_value = '""'
# and then the values
val = values_list[index]
value_type_name = getattr(val, "type_name")
definition = registry.type_infos[value_type_name] if value_type_name in registry.type_infos else None
value_long_name = getattr(val, "long_name")
definition = registry.type_infos[value_long_name] if value_long_name in registry.type_infos else None
if definition != None:
val_value = property_group_value_to_custom_property_value(val, definition, registry, component_name, None)
if value_type_name.startswith("wrapper_"): #if we have a "fake" tupple for aka for value types, we need to remove one nested level
val_value = property_group_value_to_custom_property_value(val, definition, registry, long_name, None)
if value_long_name.startswith("wrapper_"): #if we have a "fake" tupple for aka for value types, we need to remove one nested level
val_value = val_value[0]
else:
val_value = '""'
@ -166,7 +166,7 @@ def property_group_value_to_custom_property_value(property_group, definition, re
value[key_value] = val_value
value = str(value).replace('{','@').replace('}','²') # FIXME: eeek !!
else:
value = conversion_tables[type_name](value) if is_value_type else value
value = conversion_tables[long_name](value) if is_value_type else value
value = '""' if isinstance(value, PropertyGroup) else value
#print("generating custom property value", value, type(value))

View File

@ -171,43 +171,34 @@ def is_def_value_type(definition, registry):
if definition == None:
return True
value_types_defaults = registry.value_types_defaults
type_name = definition["title"]
is_value_type = type_name in value_types_defaults
long_name = definition["long_name"]
is_value_type = long_name in value_types_defaults
return is_value_type
#converts the value of a single custom property into a value (values) of a property group
def property_group_value_from_custom_property_value(property_group, definition, registry, value, nesting = []):
value_types_defaults = registry.value_types_defaults
type_info = definition["typeInfo"] if "typeInfo" in definition else None
type_def = definition["type"] if "type" in definition else None
properties = definition["properties"] if "properties" in definition else {}
prefixItems = definition["prefixItems"] if "prefixItems" in definition else []
has_properties = len(properties.keys()) > 0
has_prefixItems = len(prefixItems) > 0
is_enum = type_info == "Enum"
is_list = type_info == "List"
type_name = definition["title"]
long_name = definition["long_name"]
#is_value_type = type_def in value_types_defaults or type_name in value_types_defaults
is_value_type = type_name in value_types_defaults
#is_value_type = type_def in value_types_defaults or long_name in value_types_defaults
is_value_type = long_name in value_types_defaults
nesting = nesting + [definition["short_name"]]
"""print(" ")
print("raw value", value, "nesting", nesting)
print("nesting", len(nesting))
print("definition", definition)"""
if is_value_type:
value = value.replace("(", "").replace(")", "")# FIXME: temporary, incoherent use of nesting levels between parse_tuplestruct_string & parse_struct_string
value = type_mappings[type_name](value) if type_name in type_mappings else value
value = type_mappings[long_name](value) if long_name in type_mappings else value
return value
elif type_info == "Struct":
if len(property_group.field_names) != 0 :
custom_property_values = parse_struct_string(value, start_nesting=1 if value.startswith("(") else 0)
for index, field_name in enumerate(property_group.field_names):
item_type_name = definition["properties"][field_name]["type"]["$ref"].replace("#/$defs/", "")
item_definition = registry.type_infos[item_type_name] if item_type_name in registry.type_infos else None
item_long_name = definition["properties"][field_name]["type"]["$ref"].replace("#/$defs/", "")
item_definition = registry.type_infos[item_long_name] if item_long_name in registry.type_infos else None
custom_prop_value = custom_property_values[field_name]
#print("field name", field_name, "value", custom_prop_value)
@ -232,8 +223,8 @@ def property_group_value_from_custom_property_value(property_group, definition,
custom_property_values = parse_tuplestruct_string(value, start_nesting=1 if len(nesting) == 1 else 1)
for index, field_name in enumerate(property_group.field_names):
item_type_name = definition["prefixItems"][index]["type"]["$ref"].replace("#/$defs/", "")
item_definition = registry.type_infos[item_type_name] if item_type_name in registry.type_infos else None
item_long_name = definition["prefixItems"][index]["type"]["$ref"].replace("#/$defs/", "")
item_definition = registry.type_infos[item_long_name] if item_long_name in registry.type_infos else None
custom_property_value = custom_property_values[index]
@ -248,8 +239,8 @@ def property_group_value_from_custom_property_value(property_group, definition,
elif type_info == "TupleStruct":
custom_property_values = parse_tuplestruct_string(value, start_nesting=1 if len(nesting) == 1 else 0)
for index, field_name in enumerate(property_group.field_names):
item_type_name = definition["prefixItems"][index]["type"]["$ref"].replace("#/$defs/", "")
item_definition = registry.type_infos[item_type_name] if item_type_name in registry.type_infos else None
item_long_name = definition["prefixItems"][index]["type"]["$ref"].replace("#/$defs/", "")
item_definition = registry.type_infos[item_long_name] if item_long_name in registry.type_infos else None
custom_prop_value = custom_property_values[index]
@ -301,23 +292,21 @@ def property_group_value_from_custom_property_value(property_group, definition,
elif type_info == "List":
item_list = getattr(property_group, "list")
item_type_name = getattr(property_group, "type_name_short")
custom_property_values = parse_tuplestruct_string(value, start_nesting=2 if item_type_name.startswith("wrapper_") and value.startswith('(') else 1) # TODO : the additional check here is wrong, there is an issue somewhere in higher level stuff
item_long_name = getattr(property_group, "long_name")
custom_property_values = parse_tuplestruct_string(value, start_nesting=2 if item_long_name.startswith("wrapper_") and value.startswith('(') else 1) # TODO : the additional check here is wrong, there is an issue somewhere in higher level stuff
# clear list first
item_list.clear()
#print("custom_property_values", custom_property_values, "value", value, "item_type_name", item_type_name)
for raw_value in custom_property_values:
new_entry = item_list.add()
item_type_name = getattr(new_entry, "type_name") # we get the REAL type name
definition = registry.type_infos[item_type_name] if item_type_name in registry.type_infos else None
item_long_name = getattr(new_entry, "long_name") # we get the REAL type name
definition = registry.type_infos[item_long_name] if item_long_name in registry.type_infos else None
if definition != None:
property_group_value_from_custom_property_value(new_entry, definition, registry, value=raw_value, nesting=nesting)
else:
try:
value = value.replace("(", "").replace(")", "")# FIXME: temporary, incoherent use of nesting levels between parse_tuplestruct_string & parse_struct_string
value = type_mappings[type_name](value) if type_name in type_mappings else value
value = type_mappings[long_name](value) if long_name in type_mappings else value
return value
except:
pass

View File

@ -8,7 +8,7 @@ from . import process_list
from . import process_map
def process_component(registry, definition, update, extras=None, nesting = [], nesting_long_names = []):
component_name = definition['title']
long_name = definition['long_name']
short_name = definition["short_name"]
type_info = definition["typeInfo"] if "typeInfo" in definition else None
type_def = definition["type"] if "type" in definition else None
@ -21,8 +21,6 @@ def process_component(registry, definition, update, extras=None, nesting = [], n
is_list = type_info == "List"
is_map = type_info == "Map"
# print("processing", short_name, component_name, type_def, type_info)
__annotations__ = {}
tupple_or_struct = None
@ -61,17 +59,16 @@ def process_component(registry, definition, update, extras=None, nesting = [], n
extras = extras if extras is not None else {
"type_name": component_name
"long_name": long_name
}
root_component = nesting_long_names[0] if len(nesting_long_names) > 0 else component_name
# print("DONE:",short_name,"__annotations__", __annotations__)
root_component = nesting_long_names[0] if len(nesting_long_names) > 0 else long_name
# print("")
property_group_params = {
**extras,
'__annotations__': __annotations__,
'tupple_or_struct': tupple_or_struct,
'field_names': field_names,
**dict(with_properties = with_properties, with_items= with_items, with_enum= with_enum, with_list= with_list, with_map = with_map, short_name= short_name),
**dict(with_properties = with_properties, with_items= with_items, with_enum= with_enum, with_list= with_list, with_map = with_map, short_name= short_name, long_name=long_name),
'root_component': root_component
}
#FIXME: YIKES, but have not found another way:
@ -81,12 +78,10 @@ def process_component(registry, definition, update, extras=None, nesting = [], n
-BasicTest => the registration & update callback of this one overwrites the first "basicTest"
have not found a cleaner workaround so far
"""
property_group_name = registry.generate_propGroup_name(nesting, component_name)
property_group_name = registry.generate_propGroup_name(nesting, long_name)
(property_group_pointer, property_group_class) = property_group_from_infos(property_group_name, property_group_params)
# add our component propertyGroup to the registry
registry.register_component_propertyGroup(property_group_name, property_group_pointer)
# for practicality, we add an entry for a reverse lookup (short => long name, since we already have long_name => short_name with the keys of the raw registry)
registry.add_shortName_to_longName(short_name, component_name)
return (property_group_pointer, property_group_class)

View File

@ -4,7 +4,7 @@ from . import process_component
def process_enum(registry, definition, update, nesting, nesting_long_names):
blender_property_mapping = registry.blender_property_mapping
short_name = definition["short_name"]
long_name = definition["title"]
long_name = definition["long_name"]
type_def = definition["type"] if "type" in definition else None
values = definition["oneOf"]
@ -21,7 +21,7 @@ def process_enum(registry, definition, update, nesting, nesting_long_names):
labels = []
additional_annotations = {}
for item in values:
item_name = item["title"]
item_name = item["long_name"]
item_short_name = item["short_name"] if "short_name" in item else item_name
variant_name = "variant_" + item_short_name
labels.append(item_name)

View File

@ -7,15 +7,14 @@ def process_list(registry, definition, update, nesting=[], nesting_long_names=[]
type_infos = registry.type_infos
short_name = definition["short_name"]
long_name = definition["title"]
long_name = definition["long_name"]
ref_name = definition["items"]["type"]["$ref"].replace("#/$defs/", "")
nesting = nesting+[short_name]
nesting_long_names = nesting_long_names + [long_name]
item_definition = type_infos[ref_name]
item_long_name = item_definition["title"]
item_short_name = item_definition["short_name"]
item_long_name = item_definition["long_name"]
is_item_value_type = item_long_name in value_types_defaults
property_group_class = None
@ -23,16 +22,16 @@ def process_list(registry, definition, update, nesting=[], nesting_long_names=[]
if is_item_value_type:
property_group_class = generate_wrapper_propertyGroup(long_name, item_long_name, definition["items"]["type"]["$ref"], registry, update)
else:
(_, list_content_group_class) = process_component.process_component(registry, item_definition, update, {"nested": True, "type_name": item_long_name}, nesting)
(_, list_content_group_class) = process_component.process_component(registry, item_definition, update, {"nested": True, "long_name": item_long_name}, nesting)
property_group_class = list_content_group_class
item_collection = CollectionProperty(type=property_group_class)
item_short_name = item_short_name if not is_item_value_type else "wrapper_" + item_short_name
item_long_name = item_long_name if not is_item_value_type else "wrapper_" + item_long_name
__annotations__ = {
"list": item_collection,
"list_index": IntProperty(name = "Index for list", default = 0, update=update),
"type_name_short": StringProperty(default=item_short_name)
"long_name": StringProperty(default=item_long_name)
}
return __annotations__

View File

@ -7,7 +7,7 @@ def process_map(registry, definition, update, nesting=[], nesting_long_names=[])
type_infos = registry.type_infos
short_name = definition["short_name"]
long_name = definition["title"]
long_name = definition["long_name"]
nesting = nesting + [short_name]
nesting_long_names = nesting_long_names + [long_name]
@ -19,15 +19,15 @@ def process_map(registry, definition, update, nesting=[], nesting_long_names=[])
__annotations__ = {}
if key_ref_name in type_infos:
key_definition = type_infos[key_ref_name]
original_type_name = key_definition["title"]
is_key_value_type = original_type_name in value_types_defaults
original_long_name = key_definition["long_name"]
is_key_value_type = original_long_name in value_types_defaults
definition_link = f"#/$defs/{key_ref_name}"
#if the content of the list is a unit type, we need to generate a fake wrapper, otherwise we cannot use layout.prop(group, "propertyName") as there is no propertyName !
if is_key_value_type:
keys_property_group_class = generate_wrapper_propertyGroup(f"{long_name}_values", original_type_name, definition_link, registry, update)
keys_property_group_class = generate_wrapper_propertyGroup(f"{long_name}_values", original_long_name, definition_link, registry, update)
else:
(_, list_content_group_class) = process_component.process_component(registry, key_definition, update, {"nested": True, "type_name": original_type_name}, nesting, nesting_long_names)
(_, list_content_group_class) = process_component.process_component(registry, key_definition, update, {"nested": True, "long_name": original_long_name}, nesting, nesting_long_names)
keys_property_group_class = list_content_group_class
keys_collection = CollectionProperty(type=keys_property_group_class)
@ -40,15 +40,15 @@ def process_map(registry, definition, update, nesting=[], nesting_long_names=[])
if value_ref_name in type_infos:
value_definition = type_infos[value_ref_name]
original_type_name = value_definition["title"]
is_value_value_type = original_type_name in value_types_defaults
original_long_name = value_definition["long_name"]
is_value_value_type = original_long_name in value_types_defaults
definition_link = definition["additionalProperties"]["type"]["$ref"]#f"#/$defs/{value_ref_name}"
#if the content of the list is a unit type, we need to generate a fake wrapper, otherwise we cannot use layout.prop(group, "propertyName") as there is no propertyName !
if is_value_value_type:
values_property_group_class = generate_wrapper_propertyGroup(f"{long_name}_keys", original_type_name, definition_link, registry, update)
values_property_group_class = generate_wrapper_propertyGroup(f"{long_name}_keys", original_long_name, definition_link, registry, update)
else:
(_, list_content_group_class) = process_component.process_component(registry, value_definition, update, {"nested": True, "type_name": original_type_name}, nesting, nesting_long_names)
(_, list_content_group_class) = process_component.process_component(registry, value_definition, update, {"nested": True, "long_name": original_long_name}, nesting, nesting_long_names)
values_property_group_class = list_content_group_class
values_collection = CollectionProperty(type=values_property_group_class)

View File

@ -5,7 +5,7 @@ def process_structs(registry, definition, properties, update, nesting, nesting_l
value_types_defaults = registry.value_types_defaults
blender_property_mapping = registry.blender_property_mapping
type_infos = registry.type_infos
long_name = definition["title"]
long_name = definition["long_name"]
short_name = definition["short_name"]
__annotations__ = {}
@ -13,25 +13,19 @@ def process_structs(registry, definition, properties, update, nesting, nesting_l
nesting = nesting + [short_name]
nesting_long_names = nesting_long_names + [long_name]
if short_name == "HashmapTestSimple":
print("Struct", short_name)
for property_name in properties.keys():
ref_name = properties[property_name]["type"]["$ref"].replace("#/$defs/", "")
if short_name == "HashmapTestSimple":
print("ref name", ref_name)
if ref_name in type_infos:
original = type_infos[ref_name]
original_type_name = original["title"]
is_value_type = original_type_name in value_types_defaults
value = value_types_defaults[original_type_name] if is_value_type else None
original_long_name = original["long_name"]
is_value_type = original_long_name in value_types_defaults
value = value_types_defaults[original_long_name] if is_value_type else None
default_values[property_name] = value
if short_name == "HashmapTestSimple":
print("original",original, original_type_name, is_value_type, value)
if is_value_type:
if original_type_name in blender_property_mapping:
blender_property_def = blender_property_mapping[original_type_name]
if original_long_name in blender_property_mapping:
blender_property_def = blender_property_mapping[original_long_name]
blender_property = blender_property_def["type"](
**blender_property_def["presets"],# we inject presets first
name = property_name,
@ -40,8 +34,8 @@ def process_structs(registry, definition, properties, update, nesting, nesting_l
)
__annotations__[property_name] = blender_property
else:
original_long_name = original["title"]
(sub_component_group, _) = process_component.process_component(registry, original, update, {"nested": True, "type_name": original_long_name}, nesting, nesting_long_names)
original_long_name = original["long_name"]
(sub_component_group, _) = process_component.process_component(registry, original, update, {"nested": True, "long_name": original_long_name}, nesting, nesting_long_names)
__annotations__[property_name] = sub_component_group
# if there are sub fields, add an attribute "sub_fields" possibly a pointer property ? or add a standard field to the type , that is stored under "attributes" and not __annotations (better)
else:

View File

@ -5,7 +5,7 @@ def process_tupples(registry, definition, prefixItems, update, nesting=[], nesti
value_types_defaults = registry.value_types_defaults
blender_property_mapping = registry.blender_property_mapping
type_infos = registry.type_infos
long_name = definition["title"]
long_name = definition["long_name"]
short_name = definition["short_name"]
nesting = nesting + [short_name]
@ -21,16 +21,16 @@ def process_tupples(registry, definition, prefixItems, update, nesting=[], nesti
if ref_name in type_infos:
original = type_infos[ref_name]
original_type_name = original["title"]
is_value_type = original_type_name in value_types_defaults
original_long_name = original["long_name"]
is_value_type = original_long_name in value_types_defaults
value = value_types_defaults[original_type_name] if is_value_type else None
value = value_types_defaults[original_long_name] if is_value_type else None
default_values.append(value)
prefix_infos.append(original)
if is_value_type:
if original_type_name in blender_property_mapping:
blender_property_def = blender_property_mapping[original_type_name]
if original_long_name in blender_property_mapping:
blender_property_def = blender_property_mapping[original_long_name]
blender_property = blender_property_def["type"](
**blender_property_def["presets"],# we inject presets first
name = property_name,
@ -40,8 +40,8 @@ def process_tupples(registry, definition, prefixItems, update, nesting=[], nesti
__annotations__[property_name] = blender_property
else:
original_long_name = original["title"]
(sub_component_group, _) = process_component.process_component(registry, original, update, {"nested": True, "type_name": original_long_name}, nesting)
original_long_name = original["long_name"]
(sub_component_group, _) = process_component.process_component(registry, original, update, {"nested": True, "long_name": original_long_name}, nesting)
__annotations__[property_name] = sub_component_group
else:
# component not found in type_infos, generating placeholder

View File

@ -27,7 +27,7 @@ def generate_wrapper_propertyGroup(wrapped_type_long_name_name, item_long_name,
}
],
"short_name": wrapper_name, # FIXME !!!
"title": wrapper_name,
"long_name": wrapper_name,
"type": "array",
"typeInfo": "TupleStruct"
}
@ -55,7 +55,7 @@ def generate_wrapper_propertyGroup(wrapped_type_long_name_name, item_long_name,
'__annotations__': wrapper_annotations,
'tupple_or_struct': "tupple",
'field_names': ['0'],
**dict(with_properties = False, with_items= True, with_enum= False, with_list= False, with_map =False, short_name=wrapper_name, type_name=wrapper_name),
**dict(with_properties = False, with_items= True, with_enum= False, with_list= False, with_map =False, short_name=wrapper_name, long_name=wrapper_name),
}
property_group_class = type(property_group_name, (PropertyGroup,), property_group_params)
bpy.utils.register_class(property_group_class)

View File

@ -12,7 +12,7 @@ from ..components.metadata import ComponentMetadata, ensure_metadata_for_all_obj
# helper class to store missing bevy types information
class MissingBevyType(bpy.types.PropertyGroup):
type_name: bpy.props.StringProperty(
long_name: bpy.props.StringProperty(
name="type",
) # type: ignore
@ -211,7 +211,6 @@ class ComponentsRegistry(PropertyGroup):
type_infos = {}
type_infos_missing = []
component_propertyGroups = {}
short_names_to_long_names = {}
custom_types_to_add = {}
invalid_components = []
@ -243,13 +242,11 @@ class ComponentsRegistry(PropertyGroup):
print("load schema", self)
# cleanup previous data if any
self.propGroupIdCounter = 0
self.short_names_to_propgroup_names.clear()
self.long_names_to_propgroup_names.clear()
self.missing_types_list.clear()
self.type_infos.clear()
self.type_infos_missing.clear()
self.component_propertyGroups.clear()
self.short_names_to_long_names.clear()
self.custom_types_to_add.clear()
self.invalid_components.clear()
@ -297,24 +294,20 @@ class ComponentsRegistry(PropertyGroup):
def register_component_propertyGroup(self, name, propertyGroup):
self.component_propertyGroups[name] = propertyGroup
#for practicality, we add an entry for a reverse lookup (short => long name, since we already have long_name => short_name with the keys of the raw registry)
def add_shortName_to_longName(self, short_name, long_name):
self.short_names_to_long_names[short_name] = long_name
# to be able to give the user more feedback on any missin/unregistered types in their schema file
def add_missing_typeInfo(self, type_name):
if not type_name in self.type_infos_missing:
self.type_infos_missing.append(type_name)
def add_missing_typeInfo(self, long_name):
if not long_name in self.type_infos_missing:
self.type_infos_missing.append(long_name)
setattr(self, "missing_type_infos", str(self.type_infos_missing))
item = self.missing_types_list.add()
item.type_name = type_name
item.long_name = long_name
def add_custom_type(self, type_name, type_definition):
self.custom_types_to_add[type_name] = type_definition
def add_custom_type(self, long_name, type_definition):
self.custom_types_to_add[long_name] = type_definition
def process_custom_types(self):
for type_name in self.custom_types_to_add:
self.type_infos[type_name] = self.custom_types_to_add[type_name]
for long_name in self.custom_types_to_add:
self.type_infos[long_name] = self.custom_types_to_add[long_name]
self.custom_types_to_add.clear()
# add an invalid component to the list (long name)
@ -332,31 +325,20 @@ class ComponentsRegistry(PropertyGroup):
default=0
) # type: ignore
short_names_to_propgroup_names = {} # TODO; double check if needed, remove otherwise
long_names_to_propgroup_names = {}
# generate propGroup name from nesting level & shortName: each shortName + nesting is unique
def generate_propGroup_name(self, nesting, longName):
#print("gen propGroup name for", shortName, nesting)
#if shortName in self.short_names_to_propgroup_names and len(nesting) == 0:
# return self.get_propertyGroupName_from_shortName(shortName)
self.propGroupIdCounter += 1
propGroupIndex = str(self.propGroupIdCounter)
propGroupName = propGroupIndex + "_ui"
#
"""key = str(nesting) + shortName if len(nesting) > 0 else shortName
self.short_names_to_propgroup_names[key] = propGroupName"""
# FIXME:
key = str(nesting) + longName if len(nesting) > 0 else longName
self.long_names_to_propgroup_names[key] = propGroupName
return propGroupName
def get_propertyGroupName_from_shortName(self, shortName):
return self.short_names_to_propgroup_names.get(shortName, None)
def get_propertyGroupName_from_longName(self, longName):
return self.long_names_to_propgroup_names.get(longName, None)

View File

@ -92,7 +92,7 @@ class BEVY_COMPONENTS_PT_AdvancedToolsPanel(bpy.types.Panel):
col = row.column()
operator = col.operator(OT_rename_component.bl_idname, text="", icon="SHADERFX") #rename
new_name = registry.type_infos[available_components.list]['short_name'] if available_components.list in registry.type_infos else ""
new_name = registry.type_infos[available_components.list]['long_name'] if available_components.list in registry.type_infos else ""
operator.original_name = component_name
operator.target_objects = json.dumps([object.name])
operator.new_name = new_name
@ -285,7 +285,7 @@ class MISSING_TYPES_UL_List(UIList):
default=False,
options=set(),
description="Reverse name filtering",
)
) # type: ignore
use_order_name = bpy.props.BoolProperty(name="Name", default=False, options=set(),
description="Sort groups by their name (case-insensitive)")
@ -303,7 +303,7 @@ class MISSING_TYPES_UL_List(UIList):
print("filter, order", items, self, dict(self))
if self.filter_name:
print("ssdfs", self.filter_name)
filtered= helper_funcs.filter_items_by_name(self.filter_name, self.bitflag_filter_item, items, "type_name", reverse=self.use_filter_name_reverse)
filtered= helper_funcs.filter_items_by_name(self.filter_name, self.bitflag_filter_item, items, "long_name", reverse=self.use_filter_name_reverse)
if not filtered:
filtered = [self.bitflag_filter_item] * len(items)
@ -320,9 +320,9 @@ class MISSING_TYPES_UL_List(UIList):
row = layout.row()
#row.enabled = False
#row.alert = True
row.prop(item, "type_name", text="")
row.prop(item, "long_name", text="")
elif self.layout_type in {'GRID'}:
layout.alignment = 'CENTER'
row = layout.row()
row.prop(item, "type_name", text="")
row.prop(item, "long_name", text="")

View File

@ -74,8 +74,8 @@ def is_def_value_type(definition, registry):
if definition == None:
return True
value_types_defaults = registry.value_types_defaults
type_name = definition["title"]
is_value_type = type_name in value_types_defaults
long_name = definition["long_name"]
is_value_type = long_name in value_types_defaults
return is_value_type
# see https://docs.python.org/3/library/random.html
@ -93,19 +93,19 @@ def component_values_shuffler(seed=1, property_group=None, definition=None, regi
has_prefixItems = len(prefixItems) > 0
is_enum = type_info == "Enum"
is_list = type_info == "List"
type_name = definition["title"]
long_name = definition["long_name"]
#is_value_type = type_def in value_types_defaults or type_name in value_types_defaults
is_value_type = type_name in value_types_defaults
#is_value_type = type_def in value_types_defaults or long_name in value_types_defaults
is_value_type = long_name in value_types_defaults
if is_value_type:
fieldValue = type_mappings[type_name]()
fieldValue = type_mappings[long_name]()
return fieldValue
elif type_info == "Struct":
for index, field_name in enumerate(property_group.field_names):
item_type_name = definition["properties"][field_name]["type"]["$ref"].replace("#/$defs/", "")
item_definition = registry.type_infos[item_type_name] if item_type_name in registry.type_infos else None
item_long_name = definition["properties"][field_name]["type"]["$ref"].replace("#/$defs/", "")
item_definition = registry.type_infos[item_long_name] if item_long_name in registry.type_infos else None
value = getattr(property_group, field_name)
is_property_group = isinstance(value, PropertyGroup)
@ -123,8 +123,8 @@ def component_values_shuffler(seed=1, property_group=None, definition=None, regi
#print("tup")
for index, field_name in enumerate(property_group.field_names):
item_type_name = definition["prefixItems"][index]["type"]["$ref"].replace("#/$defs/", "")
item_definition = registry.type_infos[item_type_name] if item_type_name in registry.type_infos else None
item_long_name = definition["prefixItems"][index]["type"]["$ref"].replace("#/$defs/", "")
item_definition = registry.type_infos[item_long_name] if item_long_name in registry.type_infos else None
value = getattr(property_group, field_name)
is_property_group = isinstance(value, PropertyGroup)
@ -142,8 +142,8 @@ def component_values_shuffler(seed=1, property_group=None, definition=None, regi
elif type_info == "TupleStruct":
#print("tupstruct")
for index, field_name in enumerate(property_group.field_names):
item_type_name = definition["prefixItems"][index]["type"]["$ref"].replace("#/$defs/", "")
item_definition = registry.type_infos[item_type_name] if item_type_name in registry.type_infos else None
item_long_name = definition["prefixItems"][index]["type"]["$ref"].replace("#/$defs/", "")
item_definition = registry.type_infos[item_long_name] if item_long_name in registry.type_infos else None
value = getattr(property_group, field_name)
is_property_group = isinstance(value, PropertyGroup)
@ -158,7 +158,7 @@ def component_values_shuffler(seed=1, property_group=None, definition=None, regi
setattr(property_group , field_name, value)
elif type_info == "Enum":
available_variants = definition["oneOf"] if type_def != "object" else list(map(lambda x: x["title"], definition["oneOf"]))
available_variants = definition["oneOf"] if type_def != "object" else list(map(lambda x: x["long_name"], definition["oneOf"]))
selected = random.choice(available_variants)
# set selected variant
@ -193,14 +193,14 @@ def component_values_shuffler(seed=1, property_group=None, definition=None, regi
item_list = getattr(property_group, "list")
item_list.clear()
item_type_name = getattr(property_group, "type_name_short")
item_long_name = getattr(property_group, "long_name")
number_of_list_items_to_add = random.randint(1, 2)
for i in range(0, number_of_list_items_to_add):
new_entry = item_list.add()
item_type_name = getattr(new_entry, "type_name") # we get the REAL type name
item_long_name = getattr(new_entry, "long_name") # we get the REAL type name
definition = registry.type_infos[item_type_name] if item_type_name in registry.type_infos else None
definition = registry.type_infos[item_long_name] if item_long_name in registry.type_infos else None
if definition != None:
component_values_shuffler(seed, new_entry, definition, registry, parent=component_name)
@ -208,7 +208,7 @@ def component_values_shuffler(seed=1, property_group=None, definition=None, regi
pass
else:
print("something else")
fieldValue = type_mappings[type_name]() if type_name in type_mappings else 'None'
fieldValue = type_mappings[long_name]() if long_name in type_mappings else 'None'
return fieldValue
#return value

View File

@ -17,8 +17,8 @@ def setup_data(request):
object = bpy.context.object
remove_component_operator = bpy.ops.object.remove_bevy_component
for type_name in type_infos:
definition = type_infos[type_name]
for long_name in type_infos:
definition = type_infos[long_name]
component_name = definition["short_name"]
if component_name in object:
try:

View File

@ -23,9 +23,9 @@ def test_components_should_generate_correct_custom_properties(setup_data):
custom_property_values = {}
for type_name in type_infos:
definition = type_infos[type_name]
component_type = definition["title"]
for long_name in type_infos:
definition = type_infos[long_name]
component_type = definition["long_name"]
short_name = definition["short_name"]
is_component = definition['isComponent'] if "isComponent" in definition else False
if not is_component:
@ -72,9 +72,9 @@ def test_components_should_generate_correct_custom_properties_with_randomized_va
custom_property_values = {}
for type_name in type_infos:
definition = type_infos[type_name]
component_type = definition["title"]
for long_name in type_infos:
definition = type_infos[long_name]
component_type = definition["long_name"]
short_name = definition["short_name"]
is_component = definition['isComponent'] if "isComponent" in definition else False
if not is_component:
@ -121,9 +121,9 @@ def test_components_should_generate_correct_propertyGroup_values_from_custom_pro
added_components = []
failing_components = []
for type_name in type_infos:
definition = type_infos[type_name]
component_type = definition["title"]
for long_name in type_infos:
definition = type_infos[long_name]
component_type = definition["long_name"]
short_name = definition["short_name"]
is_component = definition['isComponent'] if "isComponent" in definition else False
if not is_component:
@ -178,9 +178,9 @@ def test_remove_components(setup_data):
addable_components = []
added_components = []
for type_name in type_infos:
definition = type_infos[type_name]
component_type = definition["title"]
for long_name in type_infos:
definition = type_infos[long_name]
component_type = definition["long_name"]
short_name = definition["short_name"]
is_component = definition['isComponent'] if "isComponent" in definition else False
if not is_component: