Blender Kitsu: Refactor Shot Builder #183

Merged
Nick Alberelli merged 55 commits from TinyNick/blender-studio-pipeline:feature/shot-builder-2 into main 2023-12-21 23:58:21 +01:00
Showing only changes of commit bc30d2ee26 - Show all commits

View File

@ -1,4 +1,133 @@
import bpy
from typing import List, Any, Tuple, Set, cast
from blender_kitsu import prefs, cache
active_project = None
def get_shots_for_seq(
self: Any, context: bpy.types.Context
) -> List[Tuple[str, str, str]]:
if not self.seq_id:
return []
seq = active_project.get_sequence(self.seq_id)
return cache.get_shots_enum_for_seq(self, context, seq)
def get_tasks_for_shot(
self: Any, context: bpy.types.Context
) -> List[Tuple[str, str, str]]:
global active_project
if not self.seq_id:
return []
shot = active_project.get_shot(self.shot_id)
return cache.get_shot_task_types_enum_for_shot(self, context, shot)
class KITSU_OT_build_new_shot(bpy.types.Operator):
bl_idname = "kitsu.build_new_shot"
bl_label = "Build New Shot"
bl_description = "" # TODO Description
bl_options = {"REGISTER"}
_timer = None
_built_shot = False
_add_vse_area = False
_file_path = ''
production_name: bpy.props.StringProperty( # type: ignore
name="Production",
description="Name of the production to create a shot file for",
options=set(),
)
seq_id: bpy.props.EnumProperty(
name="Sequence ID",
description="Sequence ID of the shot to build",
items=cache.get_sequences_enum_list,
)
shot_id: bpy.props.EnumProperty(
name="Shot ID",
description="Shot ID of the shot to build",
items=get_shots_for_seq,
)
task_type: bpy.props.EnumProperty(
name="Task",
description="Task to create the shot file for",
items=get_tasks_for_shot,
)
auto_save: bpy.props.BoolProperty(
name="Save after building.",
description="Automatically save build file after 'Shot Builder' is complete.",
default=True,
)
def draw(self, context: bpy.types.Context) -> None:
layout = self.layout
row = layout.row()
row.enabled = False
row.prop(self, "production_name")
layout.prop(self, "seq_id")
layout.prop(self, "shot_id")
layout.prop(self, "task_type")
layout.prop(self, "auto_save")
def invoke(self, context: bpy.types.Context, event: bpy.types.Event) -> Set[str]:
global active_project
addon_prefs = prefs.addon_prefs_get(bpy.context)
project = cache.project_active_get()
active_project = project
if addon_prefs.session.is_auth() is False:
self.report(
{'ERROR'},
"Must be logged into Kitsu to continue. \nCheck login status in 'Blender Kitsu' addon preferences.",
)
return {'CANCELLED'}
if project.id == "":
self.report(
{'ERROR'},
"Operator is not able to determine the Kitsu production's name. \nCheck project is selected in 'Blender Kitsu' addon preferences.",
)
return {'CANCELLED'}
if not addon_prefs.is_project_root_valid:
self.report(
{'ERROR'},
"Operator is not able to determine the project root directory. \nCheck project root directiory is configured in 'Blender Kitsu' addon preferences.",
)
return {'CANCELLED'}
self.production_name = project.name
return cast(
Set[str], context.window_manager.invoke_props_dialog(self, width=400)
)
def _get_task_type_for_shot(self, context, shot):
for task_type in shot.get_all_task_types():
if task_type.id == self.task_type:
return task_type
def execute(self, context: bpy.types.Context):
global active_project
sequence = active_project.get_sequence(self.seq_id)
shot = active_project.get_shot(self.shot_id)
task_type = self._get_task_type_for_shot(context, shot)
print("Create shot with the following details") # TODO Remove
print(f"Seq Name: '{sequence.name}' Seq ID: '{self.seq_id}'")
print(f"Shot Name: '{shot.name}' Shot ID: '{self.shot_id}'")
print(f"Task Type Name: '{task_type.name}' Task Type ID: `{self.task_type}`")
self.report({"INFO"}, f"Execution Complete") # TODO remove
return {"FINISHED"}
classes = (KITSU_OT_build_new_shot,)
def register():