mirror of
https://github.com/kaosat-dev/Blender_bevy_components_workflow.git
synced 2024-11-22 20:00:53 +00:00
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:
parent
ac02e8b364
commit
0ca57ba6de
@ -28,7 +28,7 @@ pub fn export_types(world: &mut World) {
|
|||||||
writer,
|
writer,
|
||||||
&json!({
|
&json!({
|
||||||
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
||||||
"title": "bevy component registry schema",
|
"long_name": "bevy component registry schema",
|
||||||
"$defs": schemas,
|
"$defs": schemas,
|
||||||
}),
|
}),
|
||||||
)
|
)
|
||||||
@ -41,6 +41,7 @@ pub fn export_type(reg: &TypeRegistration) -> (String, Value) {
|
|||||||
let t = reg.type_info();
|
let t = reg.type_info();
|
||||||
let binding = t.type_path_table();
|
let binding = t.type_path_table();
|
||||||
let short_name = binding.short_path();
|
let short_name = binding.short_path();
|
||||||
|
println!("T YOOO {:?}", t);
|
||||||
let mut schema = match t {
|
let mut schema = match t {
|
||||||
TypeInfo::Struct(info) => {
|
TypeInfo::Struct(info) => {
|
||||||
let properties = info
|
let properties = info
|
||||||
@ -57,7 +58,7 @@ pub fn export_type(reg: &TypeRegistration) -> (String, Value) {
|
|||||||
json!({
|
json!({
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"typeInfo": "Struct",
|
"typeInfo": "Struct",
|
||||||
"title": t.type_path(),
|
"long_name": t.type_path(),
|
||||||
"properties": properties,
|
"properties": properties,
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
"required": info
|
"required": info
|
||||||
@ -75,7 +76,7 @@ pub fn export_type(reg: &TypeRegistration) -> (String, Value) {
|
|||||||
json!({
|
json!({
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"typeInfo": "Enum",
|
"typeInfo": "Enum",
|
||||||
"title": t.type_path(),
|
"long_name": t.type_path(),
|
||||||
"oneOf": info
|
"oneOf": info
|
||||||
.iter()
|
.iter()
|
||||||
.map(|variant| match variant {
|
.map(|variant| match variant {
|
||||||
@ -94,12 +95,12 @@ pub fn export_type(reg: &TypeRegistration) -> (String, Value) {
|
|||||||
VariantInfo::Struct(v) => json!({
|
VariantInfo::Struct(v) => json!({
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"typeInfo": "Struct",
|
"typeInfo": "Struct",
|
||||||
"title": v.name(),
|
"long_name": v.name(),
|
||||||
"short_name": v.name().split("::").last().unwrap_or(v.name()),
|
"short_name": v.name().split("::").last().unwrap_or(v.name()),
|
||||||
"properties": v
|
"properties": v
|
||||||
.iter()
|
.iter()
|
||||||
.enumerate()
|
.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<_, _>>(),
|
.collect::<Map<_, _>>(),
|
||||||
"additionalProperties": false,
|
"additionalProperties": false,
|
||||||
"required": v
|
"required": v
|
||||||
@ -111,7 +112,7 @@ pub fn export_type(reg: &TypeRegistration) -> (String, Value) {
|
|||||||
VariantInfo::Tuple(v) => json!({
|
VariantInfo::Tuple(v) => json!({
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"typeInfo": "Tuple",
|
"typeInfo": "Tuple",
|
||||||
"title": v.name(),
|
"long_name": v.name(),
|
||||||
"short_name":v.name(),
|
"short_name":v.name(),
|
||||||
"prefixItems": v
|
"prefixItems": v
|
||||||
.iter()
|
.iter()
|
||||||
@ -121,7 +122,7 @@ pub fn export_type(reg: &TypeRegistration) -> (String, Value) {
|
|||||||
"items": false,
|
"items": false,
|
||||||
}),
|
}),
|
||||||
VariantInfo::Unit(v) => json!({
|
VariantInfo::Unit(v) => json!({
|
||||||
"title": v.name(),
|
"long_name": v.name(),
|
||||||
}),
|
}),
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>();
|
.collect::<Vec<_>>();
|
||||||
@ -129,13 +130,13 @@ pub fn export_type(reg: &TypeRegistration) -> (String, Value) {
|
|||||||
json!({
|
json!({
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"typeInfo": "Enum",
|
"typeInfo": "Enum",
|
||||||
"title": t.type_path(),
|
"long_name": t.type_path(),
|
||||||
"oneOf": variants,
|
"oneOf": variants,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
TypeInfo::TupleStruct(info) => json!({
|
TypeInfo::TupleStruct(info) => json!({
|
||||||
"title": t.type_path(),
|
"long_name": t.type_path(),
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"typeInfo": "TupleStruct",
|
"typeInfo": "TupleStruct",
|
||||||
"prefixItems": info
|
"prefixItems": info
|
||||||
@ -147,26 +148,26 @@ pub fn export_type(reg: &TypeRegistration) -> (String, Value) {
|
|||||||
}),
|
}),
|
||||||
TypeInfo::List(info) => {
|
TypeInfo::List(info) => {
|
||||||
json!({
|
json!({
|
||||||
"title": t.type_path(),
|
"long_name": t.type_path(),
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"typeInfo": "List",
|
"typeInfo": "List",
|
||||||
"items": json!({"type": typ(info.item_type_path_table().path())}),
|
"items": json!({"type": typ(info.item_type_path_table().path())}),
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
TypeInfo::Array(info) => json!({
|
TypeInfo::Array(info) => json!({
|
||||||
"title": t.type_path(),
|
"long_name": t.type_path(),
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"typeInfo": "Array",
|
"typeInfo": "Array",
|
||||||
"items": json!({"type": typ(info.item_type_path_table().path())}),
|
"items": json!({"type": typ(info.item_type_path_table().path())}),
|
||||||
}),
|
}),
|
||||||
TypeInfo::Map(info) => json!({
|
TypeInfo::Map(info) => json!({
|
||||||
"title": t.type_path(),
|
"long_name": t.type_path(),
|
||||||
"type": "object",
|
"type": "object",
|
||||||
"typeInfo": "Map",
|
"typeInfo": "Map",
|
||||||
"additionalProperties": json!({"type": typ(info.value_type_path_table().path())}),
|
"additionalProperties": json!({"type": typ(info.value_type_path_table().path())}),
|
||||||
}),
|
}),
|
||||||
TypeInfo::Tuple(info) => json!({
|
TypeInfo::Tuple(info) => json!({
|
||||||
"title": t.type_path(),
|
"long_name": t.type_path(),
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"typeInfo": "Tuple",
|
"typeInfo": "Tuple",
|
||||||
"prefixItems": info
|
"prefixItems": info
|
||||||
@ -177,7 +178,7 @@ pub fn export_type(reg: &TypeRegistration) -> (String, Value) {
|
|||||||
"items": false,
|
"items": false,
|
||||||
}),
|
}),
|
||||||
TypeInfo::Value(info) => json!({
|
TypeInfo::Value(info) => json!({
|
||||||
"title": t.type_path(),
|
"long_name": t.type_path(),
|
||||||
"type": map_json_type(info.type_path()),
|
"type": map_json_type(info.type_path()),
|
||||||
"typeInfo": "Value",
|
"typeInfo": "Value",
|
||||||
}),
|
}),
|
||||||
|
File diff suppressed because it is too large
Load Diff
@ -48,7 +48,7 @@ UI:
|
|||||||
* Cuboid(Vec3)
|
* Cuboid(Vec3)
|
||||||
* Sphere(radius)
|
* Sphere(radius)
|
||||||
- [x] deal with enums variants that do not have any data: ex {
|
- [x] deal with enums variants that do not have any data: ex {
|
||||||
"title": "Mesh"
|
"long_name": "Mesh"
|
||||||
}
|
}
|
||||||
|
|
||||||
- [x] remove / change use of ComponentDefinitionsList
|
- [x] remove / change use of ComponentDefinitionsList
|
||||||
@ -82,7 +82,7 @@ UI:
|
|||||||
- [x] change custom property => propGroup to convert RON => Json first => obsolete
|
- [x] change custom property => propGroup to convert RON => Json first => obsolete
|
||||||
- [x] cleanup process_lists
|
- [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
|
- [x] display single item enums inline, others in a seperate row
|
||||||
|
|
||||||
@ -217,6 +217,7 @@ Restructuring of storage of components
|
|||||||
|
|
||||||
- [ ] in conversions from propgroups
|
- [ ] in conversions from propgroups
|
||||||
component_name = definition["short_name"]
|
component_name = definition["short_name"]
|
||||||
|
- [ ] fix is_component_valid that is used in gltf_auto_export
|
||||||
|
|
||||||
- Hashmap Support
|
- Hashmap Support
|
||||||
- [ ] fix parsing of keys's type either on Bevy side (prefered, unlikely to be possible) or on the Blender side
|
- [ ] fix parsing of keys's type either on Bevy side (prefered, unlikely to be possible) or on the Blender side
|
||||||
|
@ -28,19 +28,6 @@ from .components.maps import GENERIC_MAP_OT_actions
|
|||||||
from .components.definitions_list import (ComponentDefinitionsList, ClearComponentDefinitionsList)
|
from .components.definitions_list import (ComponentDefinitionsList, ClearComponentDefinitionsList)
|
||||||
from .components.ui import (BEVY_COMPONENTS_PT_ComponentsPanel)
|
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):
|
class BEVY_COMPONENTS_PT_MainPanel(bpy.types.Panel):
|
||||||
bl_idname = "BEVY_COMPONENTS_PT_MainPanel"
|
bl_idname = "BEVY_COMPONENTS_PT_MainPanel"
|
||||||
bl_label = ""
|
bl_label = ""
|
||||||
|
@ -2,12 +2,11 @@ import bpy
|
|||||||
from bpy.props import (StringProperty, BoolProperty, PointerProperty)
|
from bpy.props import (StringProperty, BoolProperty, PointerProperty)
|
||||||
from bpy_types import (PropertyGroup)
|
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_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
|
from ..propGroups.conversions_to_prop_group import property_group_value_from_custom_property_value
|
||||||
|
|
||||||
class ComponentMetadata(bpy.types.PropertyGroup):
|
class ComponentMetadata(bpy.types.PropertyGroup):
|
||||||
name : bpy.props.StringProperty(
|
short_name : bpy.props.StringProperty(
|
||||||
name = "name",
|
name = "name",
|
||||||
default = ""
|
default = ""
|
||||||
) # type: ignore
|
) # type: ignore
|
||||||
@ -17,11 +16,6 @@ class ComponentMetadata(bpy.types.PropertyGroup):
|
|||||||
default = ""
|
default = ""
|
||||||
) # type: ignore
|
) # type: ignore
|
||||||
|
|
||||||
type_name : bpy.props.StringProperty(
|
|
||||||
name = "Type",
|
|
||||||
default = ""
|
|
||||||
) # type: ignore
|
|
||||||
|
|
||||||
values: bpy.props.StringProperty(
|
values: bpy.props.StringProperty(
|
||||||
name = "Value",
|
name = "Value",
|
||||||
default = ""
|
default = ""
|
||||||
@ -64,12 +58,6 @@ class ComponentsMeta(PropertyGroup):
|
|||||||
def unregister(cls):
|
def unregister(cls):
|
||||||
del bpy.types.Object.components_meta
|
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
|
# remove no longer valid metadata from object
|
||||||
def cleanup_invalid_metadata(object):
|
def cleanup_invalid_metadata(object):
|
||||||
bevy_components = get_bevy_components(object)
|
bevy_components = get_bevy_components(object)
|
||||||
@ -78,23 +66,15 @@ def cleanup_invalid_metadata(object):
|
|||||||
components_metadata = object.components_meta.components
|
components_metadata = object.components_meta.components
|
||||||
to_remove = []
|
to_remove = []
|
||||||
for index, component_meta in enumerate(components_metadata):
|
for index, component_meta in enumerate(components_metadata):
|
||||||
short_name = component_meta.name
|
|
||||||
long_name = component_meta.long_name
|
long_name = component_meta.long_name
|
||||||
if long_name not in bevy_components.keys():
|
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)
|
to_remove.append(index)
|
||||||
for index in to_remove:
|
for index in to_remove:
|
||||||
components_metadata.remove(index)
|
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
|
# 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_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
|
|
||||||
|
|
||||||
def find_component_definition_from_long_name(long_name):
|
def find_component_definition_from_long_name(long_name):
|
||||||
registry = bpy.context.window_manager.components_registry
|
registry = bpy.context.window_manager.components_registry
|
||||||
return registry.type_infos.get(long_name, None)
|
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
|
components_metadata = components_metadata.components
|
||||||
|
|
||||||
missing_metadata = False
|
missing_metadata = False
|
||||||
for component_name in dict(object) :
|
for component_name in get_bevy_components(object) :
|
||||||
if component_name == "components_meta":
|
if component_name == "components_meta":
|
||||||
continue
|
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:
|
if component_meta == None:
|
||||||
# current component has no metadata but is there even a compatible type in the registry ?
|
# current component has no metadata but is there even a compatible type in the registry ?
|
||||||
# if not ignore it
|
# 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:
|
if component_definition != None:
|
||||||
missing_metadata = True
|
missing_metadata = True
|
||||||
break
|
break
|
||||||
@ -173,7 +153,7 @@ def add_component_to_object(object, component_definition, value=None):
|
|||||||
cleanup_invalid_metadata(object)
|
cleanup_invalid_metadata(object)
|
||||||
if object is not None:
|
if object is not None:
|
||||||
# print("add_component_to_object", component_definition)
|
# 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
|
registry = bpy.context.window_manager.components_registry
|
||||||
if not registry.has_type_infos():
|
if not registry.has_type_infos():
|
||||||
raise Exception('registry type infos have not been loaded yet or are missing !')
|
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)
|
component_definition = registry.type_infos.get(long_name, None)
|
||||||
if component_definition != None:
|
if component_definition != None:
|
||||||
short_name = component_definition["short_name"]
|
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)
|
property_group_name = registry.get_propertyGroupName_from_longName(long_name)
|
||||||
propertyGroup = None
|
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):
|
def apply_propertyGroup_values_to_object_customProperties_for_component(object, component_name):
|
||||||
registry = bpy.context.window_manager.components_registry
|
registry = bpy.context.window_manager.components_registry
|
||||||
(_, propertyGroup) = upsert_component_in_object(object, component_name, 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:
|
if component_definition != None:
|
||||||
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
|
||||||
|
|
||||||
components_metadata = object.components_meta.components
|
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:
|
if componentMeta:
|
||||||
componentMeta.invalid = False
|
componentMeta.invalid = False
|
||||||
componentMeta.invalid_details = ""
|
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):
|
def apply_customProperty_values_to_object_propertyGroups(object):
|
||||||
print("apply custom properties to ", object.name)
|
print("apply custom properties to ", object.name)
|
||||||
registry = bpy.context.window_manager.components_registry
|
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":
|
if component_name == "components_meta":
|
||||||
continue
|
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:
|
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
|
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
|
# matching component means we already have this type of component
|
||||||
propertyGroup = getattr(source_componentMeta, property_group_name, None)
|
propertyGroup = getattr(source_componentMeta, property_group_name, None)
|
||||||
customProperty_value = object[component_name]
|
customProperty_value = object[component_name]
|
||||||
|
@ -4,7 +4,7 @@ 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_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):
|
class AddComponentOperator(Operator):
|
||||||
"""Add Bevy component to object"""
|
"""Add Bevy component to object"""
|
||||||
@ -236,7 +236,7 @@ class OT_rename_component(Operator):
|
|||||||
|
|
||||||
try:
|
try:
|
||||||
# attempt conversion
|
# attempt conversion
|
||||||
long_name = registry.short_names_to_long_names[new_name]
|
long_name = new_name
|
||||||
component_definition = type_infos[long_name]
|
component_definition = type_infos[long_name]
|
||||||
add_component_to_object(object, component_definition, object[new_name])
|
add_component_to_object(object, component_definition, object[new_name])
|
||||||
except Exception as error:
|
except Exception as error:
|
||||||
|
@ -2,23 +2,19 @@ import json
|
|||||||
import bpy
|
import bpy
|
||||||
|
|
||||||
from ..registry.operators import COMPONENTS_OT_REFRESH_CUSTOM_PROPERTIES_CURRENT
|
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
|
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):
|
def draw_propertyGroup( propertyGroup, layout, nesting =[], rootName=None):
|
||||||
is_enum = getattr(propertyGroup, "with_enum")
|
is_enum = getattr(propertyGroup, "with_enum")
|
||||||
is_list = getattr(propertyGroup, "with_list")
|
is_list = getattr(propertyGroup, "with_list")
|
||||||
is_map = getattr(propertyGroup, "with_map")
|
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
|
# 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
|
# 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
|
field_names = propertyGroup.field_names
|
||||||
#print("")
|
#print("")
|
||||||
#print("drawing", propertyGroup, nesting, "component_name", rootName)
|
#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:
|
if is_enum:
|
||||||
subrow = layout.row()
|
subrow = layout.row()
|
||||||
display_name = field_names[0] if propertyGroup.tupple_or_struct == "struct" else ""
|
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
|
# if an enum variant is not a propertyGroup
|
||||||
break
|
break
|
||||||
elif is_list:
|
elif is_list:
|
||||||
#print("show list", propertyGroup, dict(propertyGroup), propertyGroup.type_name)
|
|
||||||
item_list = getattr(propertyGroup, "list")
|
item_list = getattr(propertyGroup, "list")
|
||||||
item_type = getattr(propertyGroup, "type_name_short")
|
|
||||||
list_index = getattr(propertyGroup, "list_index")
|
list_index = getattr(propertyGroup, "list_index")
|
||||||
box = layout.box()
|
box = layout.box()
|
||||||
split = box.split(factor=0.9)
|
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_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())
|
#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)
|
#print("component_name", component_name)
|
||||||
if component_name == "components_meta":
|
if component_name == "components_meta":
|
||||||
continue
|
continue
|
||||||
|
@ -28,29 +28,29 @@ conversion_tables = {
|
|||||||
#converts the value of a property group(no matter its complexity) into a single custom property value
|
#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)
|
# 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):
|
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_info = definition["typeInfo"] if "typeInfo" in definition else None
|
||||||
type_def = definition["type"] if "type" in definition else None
|
type_def = definition["type"] if "type" in definition else None
|
||||||
type_name = definition["title"]
|
is_value_type = long_name in conversion_tables
|
||||||
is_value_type = type_name in conversion_tables
|
# print("computing custom property: component name:", long_name, "type_info", type_info, "type_def", type_def)
|
||||||
# print("computing custom property: component name:", component_name, "type_info", type_info, "type_def", type_def, "type_name", type_name)
|
|
||||||
|
|
||||||
if is_value_type:
|
if is_value_type:
|
||||||
value = conversion_tables[type_name](value)
|
value = conversion_tables[long_name](value)
|
||||||
elif type_info == "Struct":
|
elif type_info == "Struct":
|
||||||
values = {}
|
values = {}
|
||||||
if len(property_group.field_names) ==0:
|
if len(property_group.field_names) ==0:
|
||||||
value = '()'
|
value = '()'
|
||||||
else:
|
else:
|
||||||
for index, field_name in enumerate(property_group.field_names):
|
for index, field_name in enumerate(property_group.field_names):
|
||||||
item_type_name = definition["properties"][field_name]["type"]["$ref"].replace("#/$defs/", "")
|
item_long_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_definition = registry.type_infos[item_long_name] if item_long_name in registry.type_infos else None
|
||||||
|
|
||||||
value = getattr(property_group, field_name)
|
value = getattr(property_group, field_name)
|
||||||
is_property_group = isinstance(value, PropertyGroup)
|
is_property_group = isinstance(value, PropertyGroup)
|
||||||
child_property_group = value if is_property_group else None
|
child_property_group = value if is_property_group else None
|
||||||
if item_definition != 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:
|
else:
|
||||||
value = '""'
|
value = '""'
|
||||||
values[field_name] = 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":
|
elif type_info == "Tuple":
|
||||||
values = {}
|
values = {}
|
||||||
for index, field_name in enumerate(property_group.field_names):
|
for index, field_name in enumerate(property_group.field_names):
|
||||||
item_type_name = definition["prefixItems"][index]["type"]["$ref"].replace("#/$defs/", "")
|
item_long_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_definition = registry.type_infos[item_long_name] if item_long_name in registry.type_infos else None
|
||||||
|
|
||||||
value = getattr(property_group, field_name)
|
value = getattr(property_group, field_name)
|
||||||
is_property_group = isinstance(value, PropertyGroup)
|
is_property_group = isinstance(value, PropertyGroup)
|
||||||
child_property_group = value if is_property_group else None
|
child_property_group = value if is_property_group else None
|
||||||
if item_definition != 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:
|
else:
|
||||||
value = '""'
|
value = '""'
|
||||||
values[field_name] = value
|
values[field_name] = value
|
||||||
@ -75,23 +75,24 @@ def property_group_value_to_custom_property_value(property_group, definition, re
|
|||||||
values = {}
|
values = {}
|
||||||
for index, field_name in enumerate(property_group.field_names):
|
for index, field_name in enumerate(property_group.field_names):
|
||||||
#print("toto", index, definition["prefixItems"][index]["type"]["$ref"])
|
#print("toto", index, definition["prefixItems"][index]["type"]["$ref"])
|
||||||
item_type_name = definition["prefixItems"][index]["type"]["$ref"].replace("#/$defs/", "")
|
item_long_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_definition = registry.type_infos[item_long_name] if item_long_name in registry.type_infos else None
|
||||||
# print("here", item_type_name, item_definition)
|
|
||||||
|
|
||||||
value = getattr(property_group, field_name)
|
value = getattr(property_group, field_name)
|
||||||
is_property_group = isinstance(value, PropertyGroup)
|
is_property_group = isinstance(value, PropertyGroup)
|
||||||
child_property_group = value if is_property_group else None
|
child_property_group = value if is_property_group else None
|
||||||
if item_definition != 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:
|
else:
|
||||||
value = '""'
|
value = '""'
|
||||||
values[field_name] = value
|
values[field_name] = value
|
||||||
|
|
||||||
value = tuple(e for e in list(values.values()))
|
value = tuple(e for e in list(values.values()))
|
||||||
elif type_info == "Enum":
|
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
|
# 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":
|
if type_def == "object":
|
||||||
selection_index = property_group.field_names.index("variant_"+selected)
|
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)
|
is_property_group = isinstance(value, PropertyGroup)
|
||||||
child_property_group = value if is_property_group else None
|
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)
|
value = selected + str(value,) #"{}{},".format(selected ,value)
|
||||||
elif "properties" in variant_definition:
|
elif "properties" in variant_definition:
|
||||||
value = getattr(property_group, variant_name)
|
value = getattr(property_group, variant_name)
|
||||||
is_property_group = isinstance(value, PropertyGroup)
|
is_property_group = isinstance(value, PropertyGroup)
|
||||||
child_property_group = value if is_property_group else None
|
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,)
|
value = selected + str(value,)
|
||||||
else:
|
else:
|
||||||
value = getattr(property_group, variant_name)
|
value = getattr(property_group, variant_name)
|
||||||
is_property_group = isinstance(value, PropertyGroup)
|
is_property_group = isinstance(value, PropertyGroup)
|
||||||
child_property_group = value if is_property_group else None
|
child_property_group = value if is_property_group else None
|
||||||
if child_property_group:
|
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,)
|
value = selected + str(value,)
|
||||||
else:
|
else:
|
||||||
value = selected # here the value of the enum is just the name of the variant
|
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":
|
elif type_info == "List":
|
||||||
item_list = getattr(property_group, "list")
|
item_list = getattr(property_group, "list")
|
||||||
#item_type = getattr(property_group, "type_name_short")
|
|
||||||
value = []
|
value = []
|
||||||
for item in item_list:
|
for item in item_list:
|
||||||
item_type_name = getattr(item, "type_name")
|
item_long_name = getattr(item, "long_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:
|
if definition != None:
|
||||||
item_value = property_group_value_to_custom_property_value(item, definition, registry, component_name, None)
|
item_value = property_group_value_to_custom_property_value(item, definition, registry, long_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
|
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]
|
item_value = item_value[0]
|
||||||
else:
|
else:
|
||||||
item_value = '""'
|
item_value = '""'
|
||||||
@ -144,21 +144,21 @@ def property_group_value_to_custom_property_value(property_group, definition, re
|
|||||||
value = {}
|
value = {}
|
||||||
for index, key in enumerate(keys_list):
|
for index, key in enumerate(keys_list):
|
||||||
# first get the keys
|
# first get the keys
|
||||||
key_type_name = getattr(key, "type_name")
|
key_long_name = getattr(key, "long_name")
|
||||||
definition = registry.type_infos[key_type_name] if key_type_name in registry.type_infos else None
|
definition = registry.type_infos[key_long_name] if key_long_name in registry.type_infos else None
|
||||||
if definition != None:
|
if definition != None:
|
||||||
key_value = property_group_value_to_custom_property_value(key, definition, registry, component_name, None)
|
key_value = property_group_value_to_custom_property_value(key, definition, registry, long_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
|
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]
|
key_value = key_value[0]
|
||||||
else:
|
else:
|
||||||
key_value = '""'
|
key_value = '""'
|
||||||
# and then the values
|
# and then the values
|
||||||
val = values_list[index]
|
val = values_list[index]
|
||||||
value_type_name = getattr(val, "type_name")
|
value_long_name = getattr(val, "long_name")
|
||||||
definition = registry.type_infos[value_type_name] if value_type_name in registry.type_infos else None
|
definition = registry.type_infos[value_long_name] if value_long_name in registry.type_infos else None
|
||||||
if definition != None:
|
if definition != None:
|
||||||
val_value = property_group_value_to_custom_property_value(val, definition, registry, component_name, None)
|
val_value = property_group_value_to_custom_property_value(val, definition, registry, long_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
|
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]
|
val_value = val_value[0]
|
||||||
else:
|
else:
|
||||||
val_value = '""'
|
val_value = '""'
|
||||||
@ -166,7 +166,7 @@ def property_group_value_to_custom_property_value(property_group, definition, re
|
|||||||
value[key_value] = val_value
|
value[key_value] = val_value
|
||||||
value = str(value).replace('{','@').replace('}','²') # FIXME: eeek !!
|
value = str(value).replace('{','@').replace('}','²') # FIXME: eeek !!
|
||||||
else:
|
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
|
value = '""' if isinstance(value, PropertyGroup) else value
|
||||||
|
|
||||||
#print("generating custom property value", value, type(value))
|
#print("generating custom property value", value, type(value))
|
||||||
|
@ -171,43 +171,34 @@ def is_def_value_type(definition, registry):
|
|||||||
if definition == None:
|
if definition == None:
|
||||||
return True
|
return True
|
||||||
value_types_defaults = registry.value_types_defaults
|
value_types_defaults = registry.value_types_defaults
|
||||||
type_name = definition["title"]
|
long_name = definition["long_name"]
|
||||||
is_value_type = type_name in value_types_defaults
|
is_value_type = long_name in value_types_defaults
|
||||||
return is_value_type
|
return is_value_type
|
||||||
|
|
||||||
#converts the value of a single custom property into a value (values) of a property group
|
#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 = []):
|
def property_group_value_from_custom_property_value(property_group, definition, registry, value, nesting = []):
|
||||||
value_types_defaults = registry.value_types_defaults
|
value_types_defaults = registry.value_types_defaults
|
||||||
|
|
||||||
type_info = definition["typeInfo"] if "typeInfo" in definition else None
|
type_info = definition["typeInfo"] if "typeInfo" in definition else None
|
||||||
type_def = definition["type"] if "type" in definition else None
|
type_def = definition["type"] if "type" in definition else None
|
||||||
properties = definition["properties"] if "properties" in definition else {}
|
properties = definition["properties"] if "properties" in definition else {}
|
||||||
prefixItems = definition["prefixItems"] if "prefixItems" in definition else []
|
prefixItems = definition["prefixItems"] if "prefixItems" in definition else []
|
||||||
has_properties = len(properties.keys()) > 0
|
long_name = definition["long_name"]
|
||||||
has_prefixItems = len(prefixItems) > 0
|
|
||||||
is_enum = type_info == "Enum"
|
|
||||||
is_list = type_info == "List"
|
|
||||||
type_name = definition["title"]
|
|
||||||
|
|
||||||
#is_value_type = type_def in value_types_defaults or 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 = type_name in value_types_defaults
|
is_value_type = long_name in value_types_defaults
|
||||||
nesting = nesting + [definition["short_name"]]
|
nesting = nesting + [definition["short_name"]]
|
||||||
|
|
||||||
"""print(" ")
|
|
||||||
print("raw value", value, "nesting", nesting)
|
|
||||||
print("nesting", len(nesting))
|
|
||||||
print("definition", definition)"""
|
|
||||||
|
|
||||||
if is_value_type:
|
if is_value_type:
|
||||||
value = value.replace("(", "").replace(")", "")# FIXME: temporary, incoherent use of nesting levels between parse_tuplestruct_string & parse_struct_string
|
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
|
return value
|
||||||
elif type_info == "Struct":
|
elif type_info == "Struct":
|
||||||
if len(property_group.field_names) != 0 :
|
if len(property_group.field_names) != 0 :
|
||||||
custom_property_values = parse_struct_string(value, start_nesting=1 if value.startswith("(") else 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):
|
for index, field_name in enumerate(property_group.field_names):
|
||||||
item_type_name = definition["properties"][field_name]["type"]["$ref"].replace("#/$defs/", "")
|
item_long_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_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]
|
custom_prop_value = custom_property_values[field_name]
|
||||||
#print("field name", field_name, "value", custom_prop_value)
|
#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)
|
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):
|
for index, field_name in enumerate(property_group.field_names):
|
||||||
item_type_name = definition["prefixItems"][index]["type"]["$ref"].replace("#/$defs/", "")
|
item_long_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_definition = registry.type_infos[item_long_name] if item_long_name in registry.type_infos else None
|
||||||
|
|
||||||
custom_property_value = custom_property_values[index]
|
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":
|
elif type_info == "TupleStruct":
|
||||||
custom_property_values = parse_tuplestruct_string(value, start_nesting=1 if len(nesting) == 1 else 0)
|
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):
|
for index, field_name in enumerate(property_group.field_names):
|
||||||
item_type_name = definition["prefixItems"][index]["type"]["$ref"].replace("#/$defs/", "")
|
item_long_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_definition = registry.type_infos[item_long_name] if item_long_name in registry.type_infos else None
|
||||||
|
|
||||||
custom_prop_value = custom_property_values[index]
|
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":
|
elif type_info == "List":
|
||||||
item_list = getattr(property_group, "list")
|
item_list = getattr(property_group, "list")
|
||||||
item_type_name = getattr(property_group, "type_name_short")
|
item_long_name = getattr(property_group, "long_name")
|
||||||
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
|
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
|
# clear list first
|
||||||
item_list.clear()
|
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:
|
for raw_value in custom_property_values:
|
||||||
new_entry = item_list.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:
|
if definition != None:
|
||||||
property_group_value_from_custom_property_value(new_entry, definition, registry, value=raw_value, nesting=nesting)
|
property_group_value_from_custom_property_value(new_entry, definition, registry, value=raw_value, nesting=nesting)
|
||||||
else:
|
else:
|
||||||
try:
|
try:
|
||||||
value = value.replace("(", "").replace(")", "")# FIXME: temporary, incoherent use of nesting levels between parse_tuplestruct_string & parse_struct_string
|
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
|
return value
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
@ -8,7 +8,7 @@ from . import process_list
|
|||||||
from . import process_map
|
from . import process_map
|
||||||
|
|
||||||
def process_component(registry, definition, update, extras=None, nesting = [], nesting_long_names = []):
|
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"]
|
short_name = definition["short_name"]
|
||||||
type_info = definition["typeInfo"] if "typeInfo" in definition else None
|
type_info = definition["typeInfo"] if "typeInfo" in definition else None
|
||||||
type_def = definition["type"] if "type" 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_list = type_info == "List"
|
||||||
is_map = type_info == "Map"
|
is_map = type_info == "Map"
|
||||||
|
|
||||||
# print("processing", short_name, component_name, type_def, type_info)
|
|
||||||
|
|
||||||
__annotations__ = {}
|
__annotations__ = {}
|
||||||
tupple_or_struct = None
|
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 {
|
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
|
root_component = nesting_long_names[0] if len(nesting_long_names) > 0 else long_name
|
||||||
# print("DONE:",short_name,"__annotations__", __annotations__)
|
|
||||||
# print("")
|
# print("")
|
||||||
property_group_params = {
|
property_group_params = {
|
||||||
**extras,
|
**extras,
|
||||||
'__annotations__': __annotations__,
|
'__annotations__': __annotations__,
|
||||||
'tupple_or_struct': tupple_or_struct,
|
'tupple_or_struct': tupple_or_struct,
|
||||||
'field_names': field_names,
|
'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
|
'root_component': root_component
|
||||||
}
|
}
|
||||||
#FIXME: YIKES, but have not found another way:
|
#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"
|
-BasicTest => the registration & update callback of this one overwrites the first "basicTest"
|
||||||
have not found a cleaner workaround so far
|
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)
|
(property_group_pointer, property_group_class) = property_group_from_infos(property_group_name, property_group_params)
|
||||||
# add our component propertyGroup to the registry
|
# add our component propertyGroup to the registry
|
||||||
registry.register_component_propertyGroup(property_group_name, property_group_pointer)
|
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)
|
return (property_group_pointer, property_group_class)
|
||||||
|
|
||||||
|
@ -4,7 +4,7 @@ from . import process_component
|
|||||||
def process_enum(registry, definition, update, nesting, nesting_long_names):
|
def process_enum(registry, definition, update, nesting, nesting_long_names):
|
||||||
blender_property_mapping = registry.blender_property_mapping
|
blender_property_mapping = registry.blender_property_mapping
|
||||||
short_name = definition["short_name"]
|
short_name = definition["short_name"]
|
||||||
long_name = definition["title"]
|
long_name = definition["long_name"]
|
||||||
|
|
||||||
type_def = definition["type"] if "type" in definition else None
|
type_def = definition["type"] if "type" in definition else None
|
||||||
values = definition["oneOf"]
|
values = definition["oneOf"]
|
||||||
@ -21,9 +21,9 @@ def process_enum(registry, definition, update, nesting, nesting_long_names):
|
|||||||
labels = []
|
labels = []
|
||||||
additional_annotations = {}
|
additional_annotations = {}
|
||||||
for item in values:
|
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
|
item_short_name = item["short_name"] if "short_name" in item else item_name
|
||||||
variant_name = "variant_"+item_short_name
|
variant_name = "variant_" + item_short_name
|
||||||
labels.append(item_name)
|
labels.append(item_name)
|
||||||
|
|
||||||
if "prefixItems" in item:
|
if "prefixItems" in item:
|
||||||
|
@ -7,15 +7,14 @@ def process_list(registry, definition, update, nesting=[], nesting_long_names=[]
|
|||||||
type_infos = registry.type_infos
|
type_infos = registry.type_infos
|
||||||
|
|
||||||
short_name = definition["short_name"]
|
short_name = definition["short_name"]
|
||||||
long_name = definition["title"]
|
long_name = definition["long_name"]
|
||||||
ref_name = definition["items"]["type"]["$ref"].replace("#/$defs/", "")
|
ref_name = definition["items"]["type"]["$ref"].replace("#/$defs/", "")
|
||||||
|
|
||||||
nesting = nesting+[short_name]
|
nesting = nesting+[short_name]
|
||||||
nesting_long_names = nesting_long_names + [long_name]
|
nesting_long_names = nesting_long_names + [long_name]
|
||||||
|
|
||||||
item_definition = type_infos[ref_name]
|
item_definition = type_infos[ref_name]
|
||||||
item_long_name = item_definition["title"]
|
item_long_name = item_definition["long_name"]
|
||||||
item_short_name = item_definition["short_name"]
|
|
||||||
is_item_value_type = item_long_name in value_types_defaults
|
is_item_value_type = item_long_name in value_types_defaults
|
||||||
|
|
||||||
property_group_class = None
|
property_group_class = None
|
||||||
@ -23,16 +22,16 @@ def process_list(registry, definition, update, nesting=[], nesting_long_names=[]
|
|||||||
if is_item_value_type:
|
if is_item_value_type:
|
||||||
property_group_class = generate_wrapper_propertyGroup(long_name, item_long_name, definition["items"]["type"]["$ref"], registry, update)
|
property_group_class = generate_wrapper_propertyGroup(long_name, item_long_name, definition["items"]["type"]["$ref"], registry, update)
|
||||||
else:
|
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
|
property_group_class = list_content_group_class
|
||||||
|
|
||||||
item_collection = CollectionProperty(type=property_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__ = {
|
__annotations__ = {
|
||||||
"list": item_collection,
|
"list": item_collection,
|
||||||
"list_index": IntProperty(name = "Index for list", default = 0, update=update),
|
"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__
|
return __annotations__
|
@ -7,7 +7,7 @@ def process_map(registry, definition, update, nesting=[], nesting_long_names=[])
|
|||||||
type_infos = registry.type_infos
|
type_infos = registry.type_infos
|
||||||
|
|
||||||
short_name = definition["short_name"]
|
short_name = definition["short_name"]
|
||||||
long_name = definition["title"]
|
long_name = definition["long_name"]
|
||||||
|
|
||||||
nesting = nesting + [short_name]
|
nesting = nesting + [short_name]
|
||||||
nesting_long_names = nesting_long_names + [long_name]
|
nesting_long_names = nesting_long_names + [long_name]
|
||||||
@ -19,15 +19,15 @@ def process_map(registry, definition, update, nesting=[], nesting_long_names=[])
|
|||||||
__annotations__ = {}
|
__annotations__ = {}
|
||||||
if key_ref_name in type_infos:
|
if key_ref_name in type_infos:
|
||||||
key_definition = type_infos[key_ref_name]
|
key_definition = type_infos[key_ref_name]
|
||||||
original_type_name = key_definition["title"]
|
original_long_name = key_definition["long_name"]
|
||||||
is_key_value_type = original_type_name in value_types_defaults
|
is_key_value_type = original_long_name in value_types_defaults
|
||||||
definition_link = f"#/$defs/{key_ref_name}"
|
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 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:
|
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:
|
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_property_group_class = list_content_group_class
|
||||||
|
|
||||||
keys_collection = CollectionProperty(type=keys_property_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:
|
if value_ref_name in type_infos:
|
||||||
value_definition = type_infos[value_ref_name]
|
value_definition = type_infos[value_ref_name]
|
||||||
original_type_name = value_definition["title"]
|
original_long_name = value_definition["long_name"]
|
||||||
is_value_value_type = original_type_name in value_types_defaults
|
is_value_value_type = original_long_name in value_types_defaults
|
||||||
definition_link = definition["additionalProperties"]["type"]["$ref"]#f"#/$defs/{value_ref_name}"
|
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 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:
|
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:
|
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_property_group_class = list_content_group_class
|
||||||
|
|
||||||
values_collection = CollectionProperty(type=values_property_group_class)
|
values_collection = CollectionProperty(type=values_property_group_class)
|
||||||
|
@ -5,7 +5,7 @@ def process_structs(registry, definition, properties, update, nesting, nesting_l
|
|||||||
value_types_defaults = registry.value_types_defaults
|
value_types_defaults = registry.value_types_defaults
|
||||||
blender_property_mapping = registry.blender_property_mapping
|
blender_property_mapping = registry.blender_property_mapping
|
||||||
type_infos = registry.type_infos
|
type_infos = registry.type_infos
|
||||||
long_name = definition["title"]
|
long_name = definition["long_name"]
|
||||||
short_name = definition["short_name"]
|
short_name = definition["short_name"]
|
||||||
|
|
||||||
__annotations__ = {}
|
__annotations__ = {}
|
||||||
@ -13,25 +13,19 @@ def process_structs(registry, definition, properties, update, nesting, nesting_l
|
|||||||
nesting = nesting + [short_name]
|
nesting = nesting + [short_name]
|
||||||
nesting_long_names = nesting_long_names + [long_name]
|
nesting_long_names = nesting_long_names + [long_name]
|
||||||
|
|
||||||
if short_name == "HashmapTestSimple":
|
|
||||||
print("Struct", short_name)
|
|
||||||
for property_name in properties.keys():
|
for property_name in properties.keys():
|
||||||
ref_name = properties[property_name]["type"]["$ref"].replace("#/$defs/", "")
|
ref_name = properties[property_name]["type"]["$ref"].replace("#/$defs/", "")
|
||||||
if short_name == "HashmapTestSimple":
|
|
||||||
print("ref name", ref_name)
|
|
||||||
if ref_name in type_infos:
|
if ref_name in type_infos:
|
||||||
original = type_infos[ref_name]
|
original = type_infos[ref_name]
|
||||||
original_type_name = original["title"]
|
original_long_name = original["long_name"]
|
||||||
is_value_type = original_type_name in value_types_defaults
|
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[property_name] = value
|
default_values[property_name] = value
|
||||||
|
|
||||||
if short_name == "HashmapTestSimple":
|
|
||||||
print("original",original, original_type_name, is_value_type, value)
|
|
||||||
|
|
||||||
if is_value_type:
|
if is_value_type:
|
||||||
if original_type_name in blender_property_mapping:
|
if original_long_name in blender_property_mapping:
|
||||||
blender_property_def = blender_property_mapping[original_type_name]
|
blender_property_def = blender_property_mapping[original_long_name]
|
||||||
blender_property = blender_property_def["type"](
|
blender_property = blender_property_def["type"](
|
||||||
**blender_property_def["presets"],# we inject presets first
|
**blender_property_def["presets"],# we inject presets first
|
||||||
name = property_name,
|
name = property_name,
|
||||||
@ -40,8 +34,8 @@ def process_structs(registry, definition, properties, update, nesting, nesting_l
|
|||||||
)
|
)
|
||||||
__annotations__[property_name] = blender_property
|
__annotations__[property_name] = blender_property
|
||||||
else:
|
else:
|
||||||
original_long_name = original["title"]
|
original_long_name = original["long_name"]
|
||||||
(sub_component_group, _) = process_component.process_component(registry, original, update, {"nested": True, "type_name": original_long_name}, nesting, nesting_long_names)
|
(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
|
__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)
|
# 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:
|
else:
|
||||||
|
@ -5,10 +5,10 @@ def process_tupples(registry, definition, prefixItems, update, nesting=[], nesti
|
|||||||
value_types_defaults = registry.value_types_defaults
|
value_types_defaults = registry.value_types_defaults
|
||||||
blender_property_mapping = registry.blender_property_mapping
|
blender_property_mapping = registry.blender_property_mapping
|
||||||
type_infos = registry.type_infos
|
type_infos = registry.type_infos
|
||||||
long_name = definition["title"]
|
long_name = definition["long_name"]
|
||||||
short_name = definition["short_name"]
|
short_name = definition["short_name"]
|
||||||
|
|
||||||
nesting = nesting+[short_name]
|
nesting = nesting + [short_name]
|
||||||
nesting_long_names = nesting_long_names + [long_name]
|
nesting_long_names = nesting_long_names + [long_name]
|
||||||
__annotations__ = {}
|
__annotations__ = {}
|
||||||
|
|
||||||
@ -21,16 +21,16 @@ def process_tupples(registry, definition, prefixItems, update, nesting=[], nesti
|
|||||||
|
|
||||||
if ref_name in type_infos:
|
if ref_name in type_infos:
|
||||||
original = type_infos[ref_name]
|
original = type_infos[ref_name]
|
||||||
original_type_name = original["title"]
|
original_long_name = original["long_name"]
|
||||||
is_value_type = original_type_name in value_types_defaults
|
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)
|
default_values.append(value)
|
||||||
prefix_infos.append(original)
|
prefix_infos.append(original)
|
||||||
|
|
||||||
if is_value_type:
|
if is_value_type:
|
||||||
if original_type_name in blender_property_mapping:
|
if original_long_name in blender_property_mapping:
|
||||||
blender_property_def = blender_property_mapping[original_type_name]
|
blender_property_def = blender_property_mapping[original_long_name]
|
||||||
blender_property = blender_property_def["type"](
|
blender_property = blender_property_def["type"](
|
||||||
**blender_property_def["presets"],# we inject presets first
|
**blender_property_def["presets"],# we inject presets first
|
||||||
name = property_name,
|
name = property_name,
|
||||||
@ -40,8 +40,8 @@ def process_tupples(registry, definition, prefixItems, update, nesting=[], nesti
|
|||||||
|
|
||||||
__annotations__[property_name] = blender_property
|
__annotations__[property_name] = blender_property
|
||||||
else:
|
else:
|
||||||
original_long_name = original["title"]
|
original_long_name = original["long_name"]
|
||||||
(sub_component_group, _) = process_component.process_component(registry, original, update, {"nested": True, "type_name": original_long_name}, nesting)
|
(sub_component_group, _) = process_component.process_component(registry, original, update, {"nested": True, "long_name": original_long_name}, nesting)
|
||||||
__annotations__[property_name] = sub_component_group
|
__annotations__[property_name] = sub_component_group
|
||||||
else:
|
else:
|
||||||
# component not found in type_infos, generating placeholder
|
# component not found in type_infos, generating placeholder
|
||||||
|
@ -27,7 +27,7 @@ def generate_wrapper_propertyGroup(wrapped_type_long_name_name, item_long_name,
|
|||||||
}
|
}
|
||||||
],
|
],
|
||||||
"short_name": wrapper_name, # FIXME !!!
|
"short_name": wrapper_name, # FIXME !!!
|
||||||
"title": wrapper_name,
|
"long_name": wrapper_name,
|
||||||
"type": "array",
|
"type": "array",
|
||||||
"typeInfo": "TupleStruct"
|
"typeInfo": "TupleStruct"
|
||||||
}
|
}
|
||||||
@ -55,7 +55,7 @@ def generate_wrapper_propertyGroup(wrapped_type_long_name_name, item_long_name,
|
|||||||
'__annotations__': wrapper_annotations,
|
'__annotations__': wrapper_annotations,
|
||||||
'tupple_or_struct': "tupple",
|
'tupple_or_struct': "tupple",
|
||||||
'field_names': ['0'],
|
'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)
|
property_group_class = type(property_group_name, (PropertyGroup,), property_group_params)
|
||||||
bpy.utils.register_class(property_group_class)
|
bpy.utils.register_class(property_group_class)
|
||||||
|
@ -12,7 +12,7 @@ from ..components.metadata import ComponentMetadata, ensure_metadata_for_all_obj
|
|||||||
|
|
||||||
# helper class to store missing bevy types information
|
# helper class to store missing bevy types information
|
||||||
class MissingBevyType(bpy.types.PropertyGroup):
|
class MissingBevyType(bpy.types.PropertyGroup):
|
||||||
type_name: bpy.props.StringProperty(
|
long_name: bpy.props.StringProperty(
|
||||||
name="type",
|
name="type",
|
||||||
) # type: ignore
|
) # type: ignore
|
||||||
|
|
||||||
@ -211,7 +211,6 @@ class ComponentsRegistry(PropertyGroup):
|
|||||||
type_infos = {}
|
type_infos = {}
|
||||||
type_infos_missing = []
|
type_infos_missing = []
|
||||||
component_propertyGroups = {}
|
component_propertyGroups = {}
|
||||||
short_names_to_long_names = {}
|
|
||||||
custom_types_to_add = {}
|
custom_types_to_add = {}
|
||||||
invalid_components = []
|
invalid_components = []
|
||||||
|
|
||||||
@ -243,13 +242,11 @@ class ComponentsRegistry(PropertyGroup):
|
|||||||
print("load schema", self)
|
print("load schema", self)
|
||||||
# cleanup previous data if any
|
# cleanup previous data if any
|
||||||
self.propGroupIdCounter = 0
|
self.propGroupIdCounter = 0
|
||||||
self.short_names_to_propgroup_names.clear()
|
|
||||||
self.long_names_to_propgroup_names.clear()
|
self.long_names_to_propgroup_names.clear()
|
||||||
self.missing_types_list.clear()
|
self.missing_types_list.clear()
|
||||||
self.type_infos.clear()
|
self.type_infos.clear()
|
||||||
self.type_infos_missing.clear()
|
self.type_infos_missing.clear()
|
||||||
self.component_propertyGroups.clear()
|
self.component_propertyGroups.clear()
|
||||||
self.short_names_to_long_names.clear()
|
|
||||||
self.custom_types_to_add.clear()
|
self.custom_types_to_add.clear()
|
||||||
self.invalid_components.clear()
|
self.invalid_components.clear()
|
||||||
|
|
||||||
@ -297,24 +294,20 @@ class ComponentsRegistry(PropertyGroup):
|
|||||||
def register_component_propertyGroup(self, name, propertyGroup):
|
def register_component_propertyGroup(self, name, propertyGroup):
|
||||||
self.component_propertyGroups[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
|
# 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):
|
def add_missing_typeInfo(self, long_name):
|
||||||
if not type_name in self.type_infos_missing:
|
if not long_name in self.type_infos_missing:
|
||||||
self.type_infos_missing.append(type_name)
|
self.type_infos_missing.append(long_name)
|
||||||
setattr(self, "missing_type_infos", str(self.type_infos_missing))
|
setattr(self, "missing_type_infos", str(self.type_infos_missing))
|
||||||
item = self.missing_types_list.add()
|
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):
|
def add_custom_type(self, long_name, type_definition):
|
||||||
self.custom_types_to_add[type_name] = type_definition
|
self.custom_types_to_add[long_name] = type_definition
|
||||||
|
|
||||||
def process_custom_types(self):
|
def process_custom_types(self):
|
||||||
for type_name in self.custom_types_to_add:
|
for long_name in self.custom_types_to_add:
|
||||||
self.type_infos[type_name] = self.custom_types_to_add[type_name]
|
self.type_infos[long_name] = self.custom_types_to_add[long_name]
|
||||||
self.custom_types_to_add.clear()
|
self.custom_types_to_add.clear()
|
||||||
|
|
||||||
# add an invalid component to the list (long name)
|
# add an invalid component to the list (long name)
|
||||||
@ -332,31 +325,20 @@ class ComponentsRegistry(PropertyGroup):
|
|||||||
default=0
|
default=0
|
||||||
) # type: ignore
|
) # type: ignore
|
||||||
|
|
||||||
short_names_to_propgroup_names = {} # TODO; double check if needed, remove otherwise
|
|
||||||
long_names_to_propgroup_names = {}
|
long_names_to_propgroup_names = {}
|
||||||
|
|
||||||
# generate propGroup name from nesting level & shortName: each shortName + nesting is unique
|
# generate propGroup name from nesting level & shortName: each shortName + nesting is unique
|
||||||
def generate_propGroup_name(self, nesting, longName):
|
def generate_propGroup_name(self, nesting, longName):
|
||||||
#print("gen propGroup name for", shortName, nesting)
|
#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
|
self.propGroupIdCounter += 1
|
||||||
|
|
||||||
propGroupIndex = str(self.propGroupIdCounter)
|
propGroupIndex = str(self.propGroupIdCounter)
|
||||||
propGroupName = propGroupIndex + "_ui"
|
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
|
key = str(nesting) + longName if len(nesting) > 0 else longName
|
||||||
self.long_names_to_propgroup_names[key] = propGroupName
|
self.long_names_to_propgroup_names[key] = propGroupName
|
||||||
return 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):
|
def get_propertyGroupName_from_longName(self, longName):
|
||||||
return self.long_names_to_propgroup_names.get(longName, None)
|
return self.long_names_to_propgroup_names.get(longName, None)
|
||||||
|
|
||||||
|
@ -92,7 +92,7 @@ class BEVY_COMPONENTS_PT_AdvancedToolsPanel(bpy.types.Panel):
|
|||||||
|
|
||||||
col = row.column()
|
col = row.column()
|
||||||
operator = col.operator(OT_rename_component.bl_idname, text="", icon="SHADERFX") #rename
|
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.original_name = component_name
|
||||||
operator.target_objects = json.dumps([object.name])
|
operator.target_objects = json.dumps([object.name])
|
||||||
operator.new_name = new_name
|
operator.new_name = new_name
|
||||||
@ -285,7 +285,7 @@ class MISSING_TYPES_UL_List(UIList):
|
|||||||
default=False,
|
default=False,
|
||||||
options=set(),
|
options=set(),
|
||||||
description="Reverse name filtering",
|
description="Reverse name filtering",
|
||||||
)
|
) # type: ignore
|
||||||
|
|
||||||
use_order_name = bpy.props.BoolProperty(name="Name", default=False, options=set(),
|
use_order_name = bpy.props.BoolProperty(name="Name", default=False, options=set(),
|
||||||
description="Sort groups by their name (case-insensitive)")
|
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))
|
print("filter, order", items, self, dict(self))
|
||||||
if self.filter_name:
|
if self.filter_name:
|
||||||
print("ssdfs", 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:
|
if not filtered:
|
||||||
filtered = [self.bitflag_filter_item] * len(items)
|
filtered = [self.bitflag_filter_item] * len(items)
|
||||||
@ -320,9 +320,9 @@ class MISSING_TYPES_UL_List(UIList):
|
|||||||
row = layout.row()
|
row = layout.row()
|
||||||
#row.enabled = False
|
#row.enabled = False
|
||||||
#row.alert = True
|
#row.alert = True
|
||||||
row.prop(item, "type_name", text="")
|
row.prop(item, "long_name", text="")
|
||||||
|
|
||||||
elif self.layout_type in {'GRID'}:
|
elif self.layout_type in {'GRID'}:
|
||||||
layout.alignment = 'CENTER'
|
layout.alignment = 'CENTER'
|
||||||
row = layout.row()
|
row = layout.row()
|
||||||
row.prop(item, "type_name", text="")
|
row.prop(item, "long_name", text="")
|
||||||
|
@ -74,8 +74,8 @@ def is_def_value_type(definition, registry):
|
|||||||
if definition == None:
|
if definition == None:
|
||||||
return True
|
return True
|
||||||
value_types_defaults = registry.value_types_defaults
|
value_types_defaults = registry.value_types_defaults
|
||||||
type_name = definition["title"]
|
long_name = definition["long_name"]
|
||||||
is_value_type = type_name in value_types_defaults
|
is_value_type = long_name in value_types_defaults
|
||||||
return is_value_type
|
return is_value_type
|
||||||
|
|
||||||
# see https://docs.python.org/3/library/random.html
|
# 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
|
has_prefixItems = len(prefixItems) > 0
|
||||||
is_enum = type_info == "Enum"
|
is_enum = type_info == "Enum"
|
||||||
is_list = type_info == "List"
|
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_def in value_types_defaults or long_name in value_types_defaults
|
||||||
is_value_type = type_name in value_types_defaults
|
is_value_type = long_name in value_types_defaults
|
||||||
|
|
||||||
if is_value_type:
|
if is_value_type:
|
||||||
fieldValue = type_mappings[type_name]()
|
fieldValue = type_mappings[long_name]()
|
||||||
return fieldValue
|
return fieldValue
|
||||||
|
|
||||||
elif type_info == "Struct":
|
elif type_info == "Struct":
|
||||||
for index, field_name in enumerate(property_group.field_names):
|
for index, field_name in enumerate(property_group.field_names):
|
||||||
item_type_name = definition["properties"][field_name]["type"]["$ref"].replace("#/$defs/", "")
|
item_long_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_definition = registry.type_infos[item_long_name] if item_long_name in registry.type_infos else None
|
||||||
|
|
||||||
value = getattr(property_group, field_name)
|
value = getattr(property_group, field_name)
|
||||||
is_property_group = isinstance(value, PropertyGroup)
|
is_property_group = isinstance(value, PropertyGroup)
|
||||||
@ -123,8 +123,8 @@ def component_values_shuffler(seed=1, property_group=None, definition=None, regi
|
|||||||
#print("tup")
|
#print("tup")
|
||||||
|
|
||||||
for index, field_name in enumerate(property_group.field_names):
|
for index, field_name in enumerate(property_group.field_names):
|
||||||
item_type_name = definition["prefixItems"][index]["type"]["$ref"].replace("#/$defs/", "")
|
item_long_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_definition = registry.type_infos[item_long_name] if item_long_name in registry.type_infos else None
|
||||||
|
|
||||||
value = getattr(property_group, field_name)
|
value = getattr(property_group, field_name)
|
||||||
is_property_group = isinstance(value, PropertyGroup)
|
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":
|
elif type_info == "TupleStruct":
|
||||||
#print("tupstruct")
|
#print("tupstruct")
|
||||||
for index, field_name in enumerate(property_group.field_names):
|
for index, field_name in enumerate(property_group.field_names):
|
||||||
item_type_name = definition["prefixItems"][index]["type"]["$ref"].replace("#/$defs/", "")
|
item_long_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_definition = registry.type_infos[item_long_name] if item_long_name in registry.type_infos else None
|
||||||
|
|
||||||
value = getattr(property_group, field_name)
|
value = getattr(property_group, field_name)
|
||||||
is_property_group = isinstance(value, PropertyGroup)
|
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)
|
setattr(property_group , field_name, value)
|
||||||
|
|
||||||
elif type_info == "Enum":
|
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)
|
selected = random.choice(available_variants)
|
||||||
|
|
||||||
# set selected variant
|
# 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 = getattr(property_group, "list")
|
||||||
item_list.clear()
|
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)
|
number_of_list_items_to_add = random.randint(1, 2)
|
||||||
|
|
||||||
for i in range(0, number_of_list_items_to_add):
|
for i in range(0, number_of_list_items_to_add):
|
||||||
new_entry = item_list.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:
|
if definition != None:
|
||||||
component_values_shuffler(seed, new_entry, definition, registry, parent=component_name)
|
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
|
pass
|
||||||
else:
|
else:
|
||||||
print("something 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 fieldValue
|
||||||
|
|
||||||
#return value
|
#return value
|
||||||
|
@ -17,8 +17,8 @@ def setup_data(request):
|
|||||||
object = bpy.context.object
|
object = bpy.context.object
|
||||||
remove_component_operator = bpy.ops.object.remove_bevy_component
|
remove_component_operator = bpy.ops.object.remove_bevy_component
|
||||||
|
|
||||||
for type_name in type_infos:
|
for long_name in type_infos:
|
||||||
definition = type_infos[type_name]
|
definition = type_infos[long_name]
|
||||||
component_name = definition["short_name"]
|
component_name = definition["short_name"]
|
||||||
if component_name in object:
|
if component_name in object:
|
||||||
try:
|
try:
|
||||||
|
@ -23,9 +23,9 @@ def test_components_should_generate_correct_custom_properties(setup_data):
|
|||||||
|
|
||||||
custom_property_values = {}
|
custom_property_values = {}
|
||||||
|
|
||||||
for type_name in type_infos:
|
for long_name in type_infos:
|
||||||
definition = type_infos[type_name]
|
definition = type_infos[long_name]
|
||||||
component_type = definition["title"]
|
component_type = definition["long_name"]
|
||||||
short_name = definition["short_name"]
|
short_name = definition["short_name"]
|
||||||
is_component = definition['isComponent'] if "isComponent" in definition else False
|
is_component = definition['isComponent'] if "isComponent" in definition else False
|
||||||
if not is_component:
|
if not is_component:
|
||||||
@ -72,9 +72,9 @@ def test_components_should_generate_correct_custom_properties_with_randomized_va
|
|||||||
|
|
||||||
custom_property_values = {}
|
custom_property_values = {}
|
||||||
|
|
||||||
for type_name in type_infos:
|
for long_name in type_infos:
|
||||||
definition = type_infos[type_name]
|
definition = type_infos[long_name]
|
||||||
component_type = definition["title"]
|
component_type = definition["long_name"]
|
||||||
short_name = definition["short_name"]
|
short_name = definition["short_name"]
|
||||||
is_component = definition['isComponent'] if "isComponent" in definition else False
|
is_component = definition['isComponent'] if "isComponent" in definition else False
|
||||||
if not is_component:
|
if not is_component:
|
||||||
@ -121,9 +121,9 @@ def test_components_should_generate_correct_propertyGroup_values_from_custom_pro
|
|||||||
added_components = []
|
added_components = []
|
||||||
failing_components = []
|
failing_components = []
|
||||||
|
|
||||||
for type_name in type_infos:
|
for long_name in type_infos:
|
||||||
definition = type_infos[type_name]
|
definition = type_infos[long_name]
|
||||||
component_type = definition["title"]
|
component_type = definition["long_name"]
|
||||||
short_name = definition["short_name"]
|
short_name = definition["short_name"]
|
||||||
is_component = definition['isComponent'] if "isComponent" in definition else False
|
is_component = definition['isComponent'] if "isComponent" in definition else False
|
||||||
if not is_component:
|
if not is_component:
|
||||||
@ -178,9 +178,9 @@ def test_remove_components(setup_data):
|
|||||||
addable_components = []
|
addable_components = []
|
||||||
added_components = []
|
added_components = []
|
||||||
|
|
||||||
for type_name in type_infos:
|
for long_name in type_infos:
|
||||||
definition = type_infos[type_name]
|
definition = type_infos[long_name]
|
||||||
component_type = definition["title"]
|
component_type = definition["long_name"]
|
||||||
short_name = definition["short_name"]
|
short_name = definition["short_name"]
|
||||||
is_component = definition['isComponent'] if "isComponent" in definition else False
|
is_component = definition['isComponent'] if "isComponent" in definition else False
|
||||||
if not is_component:
|
if not is_component:
|
||||||
|
Loading…
Reference in New Issue
Block a user