refactor: add diff back
This commit is contained in:
parent
50d6c6b3c8
commit
8ebba80b97
@ -261,12 +261,10 @@ class BlCurve(ReplicatedDatablock):
|
|||||||
return deps
|
return deps
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def diff(self):
|
def needs_update(datablock: object, data: dict) -> bool:
|
||||||
if 'EDIT' in bpy.context.mode \
|
return 'EDIT' not in bpy.context.mode \
|
||||||
and not get_preferences().sync_flags.sync_during_editmode:
|
or get_preferences().sync_flags.sync_during_editmode
|
||||||
return None
|
|
||||||
else:
|
|
||||||
return super().diff()
|
|
||||||
|
|
||||||
_type = [bpy.types.Curve, bpy.types.TextCurve]
|
_type = [bpy.types.Curve, bpy.types.TextCurve]
|
||||||
_class = BlCurve
|
_class = BlCurve
|
||||||
|
@ -43,25 +43,3 @@ def resolve_datablock_from_uuid(uuid, bpy_collection):
|
|||||||
if getattr(item, 'uuid', None) == uuid:
|
if getattr(item, 'uuid', None) == uuid:
|
||||||
return item
|
return item
|
||||||
return None
|
return None
|
||||||
|
|
||||||
def resolve_from_root(data: dict, root: str, construct = True):
|
|
||||||
datablock_root = getattr(bpy.data, self.bl_id)
|
|
||||||
datablock_ref = utils.find_from_attr('uuid', self.uuid, datablock_root)
|
|
||||||
|
|
||||||
if not datablock_ref:
|
|
||||||
try:
|
|
||||||
datablock_ref = datablock_root[self.data['name']]
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
if construct and not datablock_ref:
|
|
||||||
name = self.data.get('name')
|
|
||||||
logging.debug(f"Constructing {name}")
|
|
||||||
datablock_ref = self.construct(data=self.data)
|
|
||||||
|
|
||||||
if datablock_ref is not None:
|
|
||||||
setattr(datablock_ref, 'uuid', self.uuid)
|
|
||||||
self.instance = datablock_ref
|
|
||||||
return True
|
|
||||||
else:
|
|
||||||
return False
|
|
||||||
|
@ -114,27 +114,28 @@ class BlFile(ReplicatedDatablock):
|
|||||||
else:
|
else:
|
||||||
file.close()
|
file.close()
|
||||||
|
|
||||||
def diff(self):
|
@staticmethod
|
||||||
|
def resolve_deps(datablock: object) -> [object]:
|
||||||
|
return []
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def needs_update(datablock: object, data:dict)-> bool:
|
||||||
if get_preferences().clear_memory_filecache:
|
if get_preferences().clear_memory_filecache:
|
||||||
return False
|
return False
|
||||||
else:
|
else:
|
||||||
if not datablock:
|
if not datablock:
|
||||||
return None
|
return None
|
||||||
|
|
||||||
if not self.data:
|
if not data:
|
||||||
return super().diff()
|
return True
|
||||||
|
|
||||||
memory_size = sys.getsizeof(self.data['file'])-33
|
memory_size = sys.getsizeof(data['file'])-33
|
||||||
disk_size = datablock.stat().st_size
|
disk_size = datablock.stat().st_size
|
||||||
|
|
||||||
if memory_size != disk_size:
|
if memory_size != disk_size:
|
||||||
return super().diff()
|
return True
|
||||||
else:
|
else:
|
||||||
return None
|
return False
|
||||||
|
|
||||||
@staticmethod
|
|
||||||
def resolve_deps(datablock: object) -> [object]:
|
|
||||||
return []
|
|
||||||
|
|
||||||
_type = [WindowsPath, PosixPath]
|
_type = [WindowsPath, PosixPath]
|
||||||
_class = BlFile
|
_class = BlFile
|
@ -62,9 +62,6 @@ class BlFont(ReplicatedDatablock):
|
|||||||
'name': datablock.name
|
'name': datablock.name
|
||||||
}
|
}
|
||||||
|
|
||||||
def diff(self):
|
|
||||||
return False
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def resolve(data: dict) -> object:
|
def resolve(data: dict) -> object:
|
||||||
uuid = data.get('uuid')
|
uuid = data.get('uuid')
|
||||||
@ -85,5 +82,9 @@ class BlFont(ReplicatedDatablock):
|
|||||||
|
|
||||||
return deps
|
return deps
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def needs_update(datablock: object, data:dict)-> bool:
|
||||||
|
return False
|
||||||
|
|
||||||
_type = bpy.types.VectorFont
|
_type = bpy.types.VectorFont
|
||||||
_class = BlFont
|
_class = BlFont
|
@ -27,9 +27,8 @@ from .dump_anything import (Dumper,
|
|||||||
from replication.protocol import ReplicatedDatablock
|
from replication.protocol import ReplicatedDatablock
|
||||||
from .bl_datablock import resolve_datablock_from_uuid
|
from .bl_datablock import resolve_datablock_from_uuid
|
||||||
from .bl_action import dump_animation_data, load_animation_data, resolve_animation_dependencies
|
from .bl_action import dump_animation_data, load_animation_data, resolve_animation_dependencies
|
||||||
|
from ..utils import get_preferences
|
||||||
|
|
||||||
# GPencil data api is structured as it follow:
|
|
||||||
# GP-Object --> GP-Layers --> GP-Frames --> GP-Strokes --> GP-Stroke-Points
|
|
||||||
|
|
||||||
STROKE_POINT = [
|
STROKE_POINT = [
|
||||||
'co',
|
'co',
|
||||||
@ -231,6 +230,18 @@ def load_layer(layer_data, layer):
|
|||||||
|
|
||||||
load_frame(frame_data, target_frame)
|
load_frame(frame_data, target_frame)
|
||||||
|
|
||||||
|
|
||||||
|
def layer_changed(datablock: object, data: dict) -> bool:
|
||||||
|
if datablock.layers.active and \
|
||||||
|
datablock.layers.active.info != data["active_layers"]:
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
def frame_changed(data: dict) -> bool:
|
||||||
|
return bpy.context.scene.frame_current != data["eval_frame"]
|
||||||
|
|
||||||
class BlGpencil(ReplicatedDatablock):
|
class BlGpencil(ReplicatedDatablock):
|
||||||
bl_id = "grease_pencils"
|
bl_id = "grease_pencils"
|
||||||
bl_class = bpy.types.GreasePencil
|
bl_class = bpy.types.GreasePencil
|
||||||
@ -312,25 +323,12 @@ class BlGpencil(ReplicatedDatablock):
|
|||||||
|
|
||||||
return deps
|
return deps
|
||||||
|
|
||||||
def layer_changed(self):
|
@staticmethod
|
||||||
if datablock.layers.active and \
|
def needs_update(datablock: object, data: dict) -> bool:
|
||||||
datablock.layers.active.info != self.data["active_layers"]:
|
return bpy.context.mode == 'OBJECT' \
|
||||||
return True
|
or layer_changed(datablock, data) \
|
||||||
else:
|
or frame_changed(data) \
|
||||||
return False
|
or get_preferences().sync_flags.sync_during_editmode
|
||||||
|
|
||||||
def frame_changed(self):
|
|
||||||
return bpy.context.scene.frame_current != self.data["eval_frame"]
|
|
||||||
|
|
||||||
def diff(self):
|
|
||||||
if not self.data \
|
|
||||||
or self.layer_changed() \
|
|
||||||
or self.frame_changed() \
|
|
||||||
or bpy.context.mode == 'OBJECT' \
|
|
||||||
or get_preferences().sync_flags.sync_during_editmode:
|
|
||||||
return super().diff()
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
_type = bpy.types.GreasePencil
|
_type = bpy.types.GreasePencil
|
||||||
_class = BlGpencil
|
_class = BlGpencil
|
||||||
|
@ -100,16 +100,6 @@ class BlImage(ReplicatedDatablock):
|
|||||||
data.update(dumper.dump(datablock))
|
data.update(dumper.dump(datablock))
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
|
||||||
def diff(self):
|
|
||||||
if self.instance.is_dirty:
|
|
||||||
self.instance.save()
|
|
||||||
|
|
||||||
if not self.data or (self.instance and (self.instance.name != self.data['name'])):
|
|
||||||
return super().diff()
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def resolve(data: dict) -> object:
|
def resolve(data: dict) -> object:
|
||||||
uuid = data.get('uuid')
|
uuid = data.get('uuid')
|
||||||
@ -142,6 +132,15 @@ class BlImage(ReplicatedDatablock):
|
|||||||
|
|
||||||
return deps
|
return deps
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def needs_update(datablock: object, data:dict)-> bool:
|
||||||
|
if datablock.is_dirty:
|
||||||
|
datablock.save()
|
||||||
|
|
||||||
|
if not data or (datablock and (datablock.name != data.get('name'))):
|
||||||
|
return True
|
||||||
|
else:
|
||||||
|
return False
|
||||||
|
|
||||||
_type = bpy.types.Image
|
_type = bpy.types.Image
|
||||||
_class = BlImage
|
_class = BlImage
|
||||||
|
@ -196,13 +196,10 @@ class BlMesh(ReplicatedDatablock):
|
|||||||
|
|
||||||
return datablock
|
return datablock
|
||||||
|
|
||||||
def diff(self):
|
@staticmethod
|
||||||
if 'EDIT' in bpy.context.mode \
|
def needs_update(datablock: object, data: dict) -> bool:
|
||||||
and not get_preferences().sync_flags.sync_during_editmode:
|
return 'EDIT' not in bpy.context.mode \
|
||||||
return False
|
or get_preferences().sync_flags.sync_during_editmode
|
||||||
else:
|
|
||||||
return super().diff()
|
|
||||||
|
|
||||||
|
|
||||||
_type = bpy.types.Mesh
|
_type = bpy.types.Mesh
|
||||||
_class = BlMesh
|
_class = BlMesh
|
||||||
|
@ -562,16 +562,17 @@ class BlScene(ReplicatedDatablock):
|
|||||||
|
|
||||||
return datablock
|
return datablock
|
||||||
|
|
||||||
def diff(self):
|
@staticmethod
|
||||||
|
def compute_delta(last_data:dict, current_data: dict)-> Delta:
|
||||||
exclude_path = []
|
exclude_path = []
|
||||||
|
|
||||||
if not self.preferences.sync_flags.sync_render_settings:
|
if not get_preferences().sync_flags.sync_render_settings:
|
||||||
exclude_path.append("root['eevee']")
|
exclude_path.append("root['eevee']")
|
||||||
exclude_path.append("root['cycles']")
|
exclude_path.append("root['cycles']")
|
||||||
exclude_path.append("root['view_settings']")
|
exclude_path.append("root['view_settings']")
|
||||||
exclude_path.append("root['render']")
|
exclude_path.append("root['render']")
|
||||||
|
|
||||||
if not self.preferences.sync_flags.sync_active_camera:
|
if not get_preferences().sync_flags.sync_active_camera:
|
||||||
exclude_path.append("root['camera']")
|
exclude_path.append("root['camera']")
|
||||||
|
|
||||||
diff_params = {
|
diff_params = {
|
||||||
@ -582,7 +583,9 @@ class BlScene(ReplicatedDatablock):
|
|||||||
delta_params = {
|
delta_params = {
|
||||||
'mutate':True
|
'mutate':True
|
||||||
}
|
}
|
||||||
return super().diff(diff_params=diff_params)
|
|
||||||
|
return Delta(DeepDiff(last_data, current_data, cache_size=5000,**diff_params), **delta_params)
|
||||||
|
|
||||||
|
|
||||||
_type = bpy.types.Scene
|
_type = bpy.types.Scene
|
||||||
_class = BlScene
|
_class = BlScene
|
||||||
|
@ -46,9 +46,6 @@ class BlSound(ReplicatedDatablock):
|
|||||||
loader = Loader()
|
loader = Loader()
|
||||||
loader.load(datablock, data)
|
loader.load(datablock, data)
|
||||||
|
|
||||||
def diff(self):
|
|
||||||
return False
|
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def dump(datablock: object) -> dict:
|
def dump(datablock: object) -> dict:
|
||||||
filename = Path(datablock.filepath).name
|
filename = Path(datablock.filepath).name
|
||||||
@ -81,5 +78,9 @@ class BlSound(ReplicatedDatablock):
|
|||||||
|
|
||||||
return datablock
|
return datablock
|
||||||
|
|
||||||
|
@staticmethod
|
||||||
|
def needs_update(datablock: object, data:dict)-> bool:
|
||||||
|
return False
|
||||||
|
|
||||||
_type = bpy.types.Sound
|
_type = bpy.types.Sound
|
||||||
_class = BlSound
|
_class = BlSound
|
@ -1 +1 @@
|
|||||||
Subproject commit 1a75bbba0bbc075da4efd68e2076dc167abe3b38
|
Subproject commit 919acd77ca625cafc9998698a39182825bcc5e02
|
Loading…
Reference in New Issue
Block a user