feat: initial undo tests

This commit is contained in:
Swann
2020-12-23 17:27:43 +01:00
parent 8a8cc0b322
commit cd1e535a56
5 changed files with 48 additions and 12 deletions

View File

@ -44,7 +44,7 @@ from . import environment
DEPENDENCIES = {
("replication", '0.1.17'),
("replication", '0.1.18'),
}

View File

@ -134,7 +134,7 @@ class BlDatablock(ReplicatedDatablock):
else:
self.diff_method = DIFF_BINARY
def resolve(self):
def resolve(self, construct = True):
datablock_ref = None
datablock_root = getattr(bpy.data, self.bl_id)
datablock_ref = utils.find_from_attr('uuid', self.uuid, datablock_root)
@ -143,14 +143,20 @@ class BlDatablock(ReplicatedDatablock):
try:
datablock_ref = datablock_root[self.data['name']]
except Exception:
if construct:
name = self.data.get('name')
logging.debug(f"Constructing {name}")
datablock_ref = self._construct(data=self.data)
for i in range(bpy.context.preferences.edit.undo_steps+1):
bpy.ops.ed.undo_push(message="Multiuser history flush")
if datablock_ref:
if datablock_ref is not None:
setattr(datablock_ref, 'uuid', self.uuid)
self.instance = datablock_ref
return True
else:
return False
def remove_instance(self):
"""

View File

@ -274,10 +274,11 @@ class BlObject(BlDatablock):
# MODIFIERS
modifiers = getattr(instance,'modifiers', None )
data["modifiers"] = {}
if modifiers:
dumper.include_filter = None
dumper.depth = 1
data["modifiers"] = {}
for index, modifier in enumerate(modifiers):
data["modifiers"][modifier.name] = dumper.dump(modifier)

View File

@ -98,6 +98,10 @@ def initialize_session():
bpy.ops.session.apply_armature_operator('INVOKE_DEFAULT')
# Step 0: Clearing history
for i in range(bpy.context.preferences.edit.undo_steps+1):
bpy.ops.ed.undo_push(message="Multiuser history flush")
@session_callback('on_exit')
def on_connection_end(reason="none"):
@ -926,8 +930,14 @@ def sanitize_deps_graph(dummy):
"""
if session and session.state['STATE'] == STATE_ACTIVE:
session.lock_operations()
for node_key in session.list():
session.get(node_key).resolve()
node = session.get(node_key)
node.resolve(construct=False)
session.unlock_operations()
@persistent
@ -978,6 +988,16 @@ def depsgraph_evaluation(scene):
# # New items !
# logger.error("UPDATE: ADD")
@persistent
def unlock(dummy):
if session and session.state['STATE'] == STATE_ACTIVE:
session.unlock_operations()
@persistent
def lock(dummy):
if session and session.state['STATE'] == STATE_ACTIVE:
session.lock_operations()
def register():
from bpy.utils import register_class
@ -985,6 +1005,11 @@ def register():
for cls in classes:
register_class(cls)
bpy.app.handlers.undo_post.append(unlock)
bpy.app.handlers.undo_pre.append(lock)
bpy.app.handlers.redo_pre.append(unlock)
bpy.app.handlers.redo_post.append(lock)
bpy.app.handlers.undo_post.append(sanitize_deps_graph)
bpy.app.handlers.redo_post.append(sanitize_deps_graph)
@ -1000,6 +1025,10 @@ def unregister():
for cls in reversed(classes):
unregister_class(cls)
bpy.app.handlers.undo_post.remove(unlock)
bpy.app.handlers.undo_pre.remove(lock)
bpy.app.handlers.redo_pre.remove(unlock)
bpy.app.handlers.redo_post.remove(lock)
bpy.app.handlers.undo_post.remove(sanitize_deps_graph)
bpy.app.handlers.redo_post.remove(sanitize_deps_graph)

View File

@ -104,7 +104,7 @@ class ApplyTimer(Timer):
def __init__(self, timeout=1, target_type=None):
self._type = target_type
super().__init__(timeout)
self.id = target_type.__name__
self.id = target_type.__name__ if target_type else "ApplyTimer"
def execute(self):
if session and session.state['STATE'] == STATE_ACTIVE: