refactor: add diff back

This commit is contained in:
Swann 2021-05-19 17:44:42 +02:00
parent 50d6c6b3c8
commit 8ebba80b97
No known key found for this signature in database
GPG Key ID: E1D3641A7C43AACB
10 changed files with 66 additions and 90 deletions

View File

@ -261,12 +261,10 @@ class BlCurve(ReplicatedDatablock):
return deps
@staticmethod
def diff(self):
if 'EDIT' in bpy.context.mode \
and not get_preferences().sync_flags.sync_during_editmode:
return None
else:
return super().diff()
def needs_update(datablock: object, data: dict) -> bool:
return 'EDIT' not in bpy.context.mode \
or get_preferences().sync_flags.sync_during_editmode
_type = [bpy.types.Curve, bpy.types.TextCurve]
_class = BlCurve
_class = BlCurve

View File

@ -43,25 +43,3 @@ def resolve_datablock_from_uuid(uuid, bpy_collection):
if getattr(item, 'uuid', None) == uuid:
return item
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

View File

@ -114,27 +114,28 @@ class BlFile(ReplicatedDatablock):
else:
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:
return False
else:
if not datablock:
return None
if not self.data:
return super().diff()
if not data:
return True
memory_size = sys.getsizeof(self.data['file'])-33
memory_size = sys.getsizeof(data['file'])-33
disk_size = datablock.stat().st_size
if memory_size != disk_size:
return super().diff()
return True
else:
return None
@staticmethod
def resolve_deps(datablock: object) -> [object]:
return []
return False
_type = [WindowsPath, PosixPath]
_class = BlFile

View File

@ -62,9 +62,6 @@ class BlFont(ReplicatedDatablock):
'name': datablock.name
}
def diff(self):
return False
@staticmethod
def resolve(data: dict) -> object:
uuid = data.get('uuid')
@ -85,5 +82,9 @@ class BlFont(ReplicatedDatablock):
return deps
@staticmethod
def needs_update(datablock: object, data:dict)-> bool:
return False
_type = bpy.types.VectorFont
_class = BlFont

View File

@ -27,9 +27,8 @@ from .dump_anything import (Dumper,
from replication.protocol import ReplicatedDatablock
from .bl_datablock import resolve_datablock_from_uuid
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 = [
'co',
@ -231,6 +230,18 @@ def load_layer(layer_data, layer):
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):
bl_id = "grease_pencils"
bl_class = bpy.types.GreasePencil
@ -312,25 +323,12 @@ class BlGpencil(ReplicatedDatablock):
return deps
def layer_changed(self):
if datablock.layers.active and \
datablock.layers.active.info != self.data["active_layers"]:
return True
else:
return False
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
@staticmethod
def needs_update(datablock: object, data: dict) -> bool:
return bpy.context.mode == 'OBJECT' \
or layer_changed(datablock, data) \
or frame_changed(data) \
or get_preferences().sync_flags.sync_during_editmode
_type = bpy.types.GreasePencil
_class = BlGpencil
_class = BlGpencil

View File

@ -100,16 +100,6 @@ class BlImage(ReplicatedDatablock):
data.update(dumper.dump(datablock))
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
def resolve(data: dict) -> object:
uuid = data.get('uuid')
@ -142,6 +132,15 @@ class BlImage(ReplicatedDatablock):
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
_class = BlImage

View File

@ -196,13 +196,10 @@ class BlMesh(ReplicatedDatablock):
return datablock
def diff(self):
if 'EDIT' in bpy.context.mode \
and not get_preferences().sync_flags.sync_during_editmode:
return False
else:
return super().diff()
@staticmethod
def needs_update(datablock: object, data: dict) -> bool:
return 'EDIT' not in bpy.context.mode \
or get_preferences().sync_flags.sync_during_editmode
_type = bpy.types.Mesh
_class = BlMesh

View File

@ -562,16 +562,17 @@ class BlScene(ReplicatedDatablock):
return datablock
def diff(self):
@staticmethod
def compute_delta(last_data:dict, current_data: dict)-> Delta:
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['cycles']")
exclude_path.append("root['view_settings']")
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']")
diff_params = {
@ -582,7 +583,9 @@ class BlScene(ReplicatedDatablock):
delta_params = {
'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
_class = BlScene
_class = BlScene

View File

@ -46,9 +46,6 @@ class BlSound(ReplicatedDatablock):
loader = Loader()
loader.load(datablock, data)
def diff(self):
return False
@staticmethod
def dump(datablock: object) -> dict:
filename = Path(datablock.filepath).name
@ -81,5 +78,9 @@ class BlSound(ReplicatedDatablock):
return datablock
@staticmethod
def needs_update(datablock: object, data:dict)-> bool:
return False
_type = bpy.types.Sound
_class = BlSound

@ -1 +1 @@
Subproject commit 1a75bbba0bbc075da4efd68e2076dc167abe3b38
Subproject commit 919acd77ca625cafc9998698a39182825bcc5e02