Skip to content

Commit

Permalink
add preference, improve syncing procedure, fix mutation error not shown
Browse files Browse the repository at this point in the history
  • Loading branch information
tom1484 committed Mar 16, 2024
1 parent 12bf7bf commit f018edc
Show file tree
Hide file tree
Showing 20 changed files with 273 additions and 163 deletions.
6 changes: 3 additions & 3 deletions editor-blender/__init__.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
bl_info = {
"name": "LightDance Editor",
"author": "NTUEE LightDance",
"version": (1, 0),
"version": (1, 1),
"blender": (4, 0, 0),
"location": "View3D > Toolshelf",
"description": "Addon for LightDance Editor",
Expand All @@ -28,16 +28,16 @@ def register():

from . import operators, panels, properties, storage

storage.register()
properties.register()
operators.register()
panels.register()
storage.register()


def unregister():
from . import operators, panels, properties, storage

storage.unregister()
operators.unregister()
panels.unregister()
operators.unregister()
properties.unregister()
33 changes: 15 additions & 18 deletions editor-blender/api/control_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,10 +94,9 @@ async def add_frame(
except asyncio.CancelledError:
pass

except Exception as e:
print(e)

return None
except Exception as err:
print(err)
raise err

# TODO: Support only change fade
async def save_frame(
Expand Down Expand Up @@ -140,8 +139,9 @@ async def save_frame(
except asyncio.CancelledError:
pass

except Exception as e:
print(e)
except Exception as err:
print(err)
raise err

async def delete_frame(self, id: MapID) -> Optional[str]:
try:
Expand All @@ -155,10 +155,9 @@ async def delete_frame(self, id: MapID) -> Optional[str]:
except asyncio.CancelledError:
pass

except Exception as e:
print(e)

return None
except Exception as err:
print(err)
raise err

async def request_edit(self, id: MapID) -> Optional[bool]:
try:
Expand All @@ -172,10 +171,9 @@ async def request_edit(self, id: MapID) -> Optional[bool]:
except asyncio.CancelledError:
pass

except Exception as e:
print(e)

return None
except Exception as err:
print(err)
raise err

async def cancel_edit(self, id: MapID) -> Optional[bool]:
try:
Expand All @@ -187,10 +185,9 @@ async def cancel_edit(self, id: MapID) -> Optional[bool]:
except asyncio.CancelledError:
pass

except Exception as e:
print(e)

return None
except Exception as err:
print(err)
raise err


control_agent = ControlAgent()
54 changes: 24 additions & 30 deletions editor-blender/api/pos_agent.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,10 +46,9 @@ async def get_pos_record(self) -> Optional[PosRecord]:
except asyncio.CancelledError:
pass

except Exception as e:
print(e)

return None
except Exception as err:
print(err)
raise err

async def get_pos_map_payload(self) -> Optional[QueryPosMapPayload]:
try:
Expand All @@ -61,10 +60,9 @@ async def get_pos_map_payload(self) -> Optional[QueryPosMapPayload]:
except asyncio.CancelledError:
pass

except Exception as e:
print(e)

return None
except Exception as err:
print(err)
raise err

async def get_pos_map(self) -> Optional[PosMap]:
try:
Expand All @@ -76,10 +74,9 @@ async def get_pos_map(self) -> Optional[PosMap]:
except asyncio.CancelledError:
pass

except Exception as e:
print(e)

return None
except Exception as err:
print(err)
raise err

async def add_frame(
self, start: int, positionData: List[List[float]]
Expand All @@ -95,10 +92,9 @@ async def add_frame(
except asyncio.CancelledError:
pass

except Exception as e:
print(e)

return None
except Exception as err:
print(err)
raise err

async def save_frame(
self, id: MapID, positionData: List[List[float]], start: Optional[int] = None
Expand Down Expand Up @@ -136,8 +132,9 @@ async def save_frame(
except asyncio.CancelledError:
pass

except Exception as e:
print(e)
except Exception as err:
print(err)
raise err

async def delete_frame(self, id: MapID) -> Optional[MapID]:
try:
Expand All @@ -151,10 +148,9 @@ async def delete_frame(self, id: MapID) -> Optional[MapID]:
except asyncio.CancelledError:
pass

except Exception as e:
print(e)

return None
except Exception as err:
print(err)
raise err

async def request_edit(self, id: MapID) -> Optional[bool]:
try:
Expand All @@ -166,10 +162,9 @@ async def request_edit(self, id: MapID) -> Optional[bool]:
except asyncio.CancelledError:
pass

except Exception as e:
print(e)

return None
except Exception as err:
print(err)
raise err

async def cancel_edit(self, id: MapID) -> Optional[bool]:
try:
Expand All @@ -181,10 +176,9 @@ async def cancel_edit(self, id: MapID) -> Optional[bool]:
except asyncio.CancelledError:
pass

except Exception as e:
print(e)

return None
except Exception as err:
print(err)
raise err


pos_agent = PosAgent()
8 changes: 0 additions & 8 deletions editor-blender/core/actions/property/timeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,3 @@ def set_time(self: bpy.types.WindowManager, value: str):

self["ld_time"] = value
bpy.context.scene.frame_current = frame


def get_follow_frame(self: bpy.types.WindowManager) -> bool:
return bpy.context.screen.use_follow


def set_follow_frame(self: bpy.types.WindowManager, value: bool):
bpy.context.screen.use_follow = value
44 changes: 26 additions & 18 deletions editor-blender/core/actions/state/control_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,15 @@ async def add_control_frame():
start = bpy.context.scene.frame_current
controlData = control_status_state_to_mut(state.current_status)

set_requesting(True)
try:
set_requesting(True)
await control_agent.add_frame(start, False, controlData)
set_requesting(False)
notify("INFO", f"Added control frame")
except:
notify("WARNING", "Cannot add control frame")

set_requesting(False)


async def save_control_frame(start: Optional[int] = None):
id = state.editing_data.frame_id
Expand Down Expand Up @@ -126,14 +127,13 @@ async def save_control_frame(start: Optional[int] = None):

controlData.append(partControlData)

set_requesting(True)
try:
set_requesting(True)
await control_agent.save_frame(id, controlData, fade=fade, start=start)
notify("INFO", f"Saved control frame")

# Cancel editing
ok = await control_agent.cancel_edit(id)
set_requesting(False)

if ok is not None and ok:
# Reset editing state
Expand All @@ -151,19 +151,22 @@ async def save_control_frame(start: Optional[int] = None):
except:
notify("WARNING", "Cannot save control frame")

set_requesting(False)


async def delete_control_frame():
index = state.current_control_index
id = state.control_record[index]

set_requesting(True)
try:
set_requesting(True)
await control_agent.delete_frame(id)
set_requesting(False)
notify("INFO", f"Deleted control frame: {id}")
except:
notify("WARNING", "Cannot delete control frame")

set_requesting(False)


async def request_edit_control() -> bool:
if state.color_map_pending.add_or_delete:
Expand Down Expand Up @@ -208,23 +211,28 @@ async def cancel_edit_control():
id = state.control_record[index]

set_requesting(True)
ok = await control_agent.cancel_edit(id)
set_requesting(False)
try:
ok = await control_agent.cancel_edit(id)

if ok is not None and ok:
# Revert modification
update_current_status_by_index()
if ok is not None and ok:
# Revert modification
update_current_status_by_index()

# Reset editing state
state.current_editing_frame = -1
state.current_editing_detached = False
state.current_editing_frame_synced = False
state.edit_state = EditMode.IDLE
# Reset editing state
state.current_editing_frame = -1
state.current_editing_detached = False
state.current_editing_frame_synced = False
state.edit_state = EditMode.IDLE

redraw_area({"VIEW_3D", "DOPESHEET_EDITOR"})
else:
redraw_area({"VIEW_3D", "DOPESHEET_EDITOR"})
else:
notify("WARNING", "Cannot cancel edit")

except:
notify("WARNING", "Cannot cancel edit")

set_requesting(False)


def toggle_dancer_mode():
bpy.context.view_layer.objects.active = None # type: ignore
Expand Down
9 changes: 6 additions & 3 deletions editor-blender/core/actions/state/control_map.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def add_control(id: MapID, frame: ControlMapElement):
control_map_updates = state.control_map_updates
control_map_updates.added.append((id, frame))

if state.edit_state == EditMode.EDITING:
if state.edit_state == EditMode.EDITING or not state.preferences.auto_sync:
state.control_map_pending = True
redraw_area({"VIEW_3D", "DOPESHEET_EDITOR"})
else:
Expand Down Expand Up @@ -55,7 +55,7 @@ def delete_control(id: MapID):

control_map_updates.deleted.append(id)

if state.edit_state == EditMode.EDITING:
if state.edit_state == EditMode.EDITING or not state.preferences.auto_sync:
state.control_map_pending = True
redraw_area({"VIEW_3D", "DOPESHEET_EDITOR"})
else:
Expand All @@ -80,7 +80,7 @@ def update_control(id: MapID, frame: ControlMapElement):

control_map_updates.updated.append((id, frame))

if state.edit_state == EditMode.EDITING:
if state.edit_state == EditMode.EDITING or not state.preferences.auto_sync:
state.control_map_pending = True
redraw_area({"VIEW_3D", "DOPESHEET_EDITOR"})
else:
Expand All @@ -89,6 +89,9 @@ def update_control(id: MapID, frame: ControlMapElement):


def apply_control_map_updates():
if not state.ready:
return

control_map_updates = state.control_map_updates

for status in control_map_updates.added:
Expand Down
Loading

0 comments on commit f018edc

Please sign in to comment.