fix issues.
- fix issue according to python linter - do not write vt group if no changes. reduce the cost of virtools group class.
This commit is contained in:
parent
1a2dd08092
commit
1432c2990a
@ -236,7 +236,7 @@ def _import_virtools_meshes(
|
||||
|
||||
# return
|
||||
yield face
|
||||
def mtl_iterator() -> typing.Iterator[bpy.types.Material]:
|
||||
def mtl_iterator() -> typing.Iterator[bpy.types.Material | None]:
|
||||
for vtmtl in vtmesh.get_material_slots():
|
||||
if vtmtl:
|
||||
yield material_cret_map.get(vtmtl, None)
|
||||
|
@ -36,7 +36,7 @@ class BallanceElementType(enum.IntEnum):
|
||||
|
||||
_g_ElementCount: int = len(BallanceElementType)
|
||||
_g_ElementNameIdMap: dict[str, int] = dict((entry.name, entry.value) for entry in BallanceElementType)
|
||||
_g_ElementIdNameMap: dict[str, int] = dict((entry.value, entry.name) for entry in BallanceElementType)
|
||||
_g_ElementIdNameMap: dict[int, str] = dict((entry.value, entry.name) for entry in BallanceElementType)
|
||||
|
||||
def get_ballance_element_id(name: str) -> int | None:
|
||||
"""
|
||||
@ -47,7 +47,7 @@ def get_ballance_element_id(name: str) -> int | None:
|
||||
"""
|
||||
return _g_ElementNameIdMap.get(name, None)
|
||||
|
||||
def get_ballance_element_name(id: int) -> int | None:
|
||||
def get_ballance_element_name(id: int) -> str | None:
|
||||
"""
|
||||
Get Ballance element name by its ID
|
||||
|
||||
@ -250,10 +250,10 @@ class BallanceElementsHelper():
|
||||
return mesh
|
||||
|
||||
# if no existing one, create new one
|
||||
new_mesh_name: str | None = get_ballance_element_id(element_id)
|
||||
new_mesh_name: str | None = get_ballance_element_name(element_id)
|
||||
if new_mesh_name is None:
|
||||
raise UTIL_functions.BBPException('invalid element id')
|
||||
new_mesh: bpy.types.Mesh = bpy.data.meshes.new(get_ballance_element_name(element_id))
|
||||
new_mesh: bpy.types.Mesh = bpy.data.meshes.new(new_mesh_name)
|
||||
|
||||
_load_element(new_mesh, element_id)
|
||||
self.__mElementMap[element_id] = new_mesh
|
||||
|
@ -28,12 +28,14 @@ class VirtoolsGroupsHelper():
|
||||
"""
|
||||
__mSingletonMutex: typing.ClassVar[bool] = False
|
||||
__mIsValid: bool
|
||||
__mNoChange: bool ##< A bool indicate whether any change happended during lifetime. If no change, skip the writing when exiting.
|
||||
__mAssocObj: bpy.types.Object
|
||||
__mGroupsSet: set[str]
|
||||
|
||||
def __init__(self, assoc: bpy.types.Object):
|
||||
self.__mGroupsSet = set()
|
||||
self.__mAssocObj = assoc
|
||||
self.__mNoChange = True
|
||||
|
||||
# check singleton
|
||||
if VirtoolsGroupsHelper.__mSingletonMutex:
|
||||
@ -56,8 +58,10 @@ class VirtoolsGroupsHelper():
|
||||
|
||||
def dispose(self) -> None:
|
||||
if self.is_valid():
|
||||
# if have changes,
|
||||
# write to ballance elements property and reset validation
|
||||
self.__write_to_virtools_groups()
|
||||
if not self.__mNoChange:
|
||||
self.__write_to_virtools_groups()
|
||||
self.__mIsValid = False
|
||||
VirtoolsGroupsHelper.__mSingletonMutex = False
|
||||
|
||||
@ -67,18 +71,22 @@ class VirtoolsGroupsHelper():
|
||||
|
||||
def add_group(self, gname: str) -> None:
|
||||
self.__check_valid()
|
||||
self.__mNoChange = False
|
||||
self.__mGroupsSet.add(gname)
|
||||
|
||||
def add_groups(self, gnames: typing.Iterable[str]) -> None:
|
||||
self.__check_valid()
|
||||
self.__mNoChange = False
|
||||
self.__mGroupsSet.update(gnames)
|
||||
|
||||
def remove_group(self, gname: str) -> None:
|
||||
self.__check_valid()
|
||||
self.__mNoChange = False
|
||||
self.__mGroupsSet.discard(gname)
|
||||
|
||||
def remove_groups(self, gnames: typing.Iterable[str]) -> None:
|
||||
self.__check_valid()
|
||||
self.__mNoChange = False
|
||||
for gname in gnames:
|
||||
self.__mGroupsSet.discard(gname)
|
||||
|
||||
@ -103,6 +111,7 @@ class VirtoolsGroupsHelper():
|
||||
|
||||
def clear_all_groups(self):
|
||||
self.__check_valid()
|
||||
self.__mNoChange = False
|
||||
self.__mGroupsSet.clear()
|
||||
|
||||
def __write_to_virtools_groups(self) -> None:
|
||||
|
Loading…
Reference in New Issue
Block a user