Files
artcraft/app/pages/PageEnigma/hooks/useQueueHandler.ts
T
wilandwil b3b30fdf49 Vertical Video and more aspect ratio options (#441)
_**WAITING FOR THE SERVER UPDATE FOR END-TO-END TESTING**_

- created ui and queue communication for switching camera aspect ratio
done
- editor's render camera read queue to switch camera aspect ratio
- letterbox now available in camera view mode for a better preview of
the aspect ratios
- updated ui to match figma design after design update
- vertical camera styling updates (by bflat)
- finalized our render resolutions at different aspect ratio

---------

Co-authored-by: wil <wil@storyteller.ai>
2024-05-30 17:14:04 -04:00

116 lines
3.7 KiB
TypeScript

import { fromEngineActions } from "~/pages/PageEnigma/Queue/fromEngineActions";
import { useSignals } from "@preact/signals-react/runtime";
import { useCallback, useEffect } from "react";
import {
addNewCharacter,
addObjectToTimeline,
clearExistingData,
currentTime,
deleteObjectOrCharacter,
loadAudioData,
loadCameraData,
loadCharacterData,
loadObjectData,
selectedObject,
addKeyframe,
} from "~/pages/PageEnigma/signals";
import Queue, { QueueSubscribeType } from "~/pages/PageEnigma/Queue/Queue";
import { QueueNames } from "~/pages/PageEnigma/Queue/QueueNames";
import { ToastDataType } from "~/components";
import {
MediaItem,
QueueKeyframe,
UpdateTime,
} from "~/pages/PageEnigma/models";
import { CameraAspectRatio, ClipGroup } from "~/pages/PageEnigma/enums";
import { addToast } from "~/signals";
import { ToastTypes } from "~/enums";
import { toTimelineActions } from "~/pages/PageEnigma/Queue/toTimelineActions";
import { ClipUI } from "~/pages/PageEnigma/datastructures/clips/clip_ui";
import { cameraAspectRatio } from "../signals/engine";
const LOADING_FUNCTIONS: Record<ClipGroup, (item: ClipUI) => void> = {
[ClipGroup.CHARACTER]: loadCharacterData,
[ClipGroup.OBJECT]: loadObjectData,
[ClipGroup.CAMERA]: loadCameraData,
[ClipGroup.GLOBAL_AUDIO]: loadAudioData,
};
export function useQueueHandler() {
useSignals();
const handleFromEngineActions = useCallback(
({ action, data }: QueueSubscribeType) => {
console.log("FROM ENGINE", action, data);
switch (action) {
case fromEngineActions.ADD_OBJECT: {
// this could be an object or character
addObjectToTimeline(data as MediaItem);
break;
}
case fromEngineActions.DELETE_OBJECT:
// this could be an object or character
deleteObjectOrCharacter(data as MediaItem);
break;
case fromEngineActions.DESELECT_OBJECT:
selectedObject.value = null;
break;
case fromEngineActions.RESET_TIMELINE:
clearExistingData();
break;
case fromEngineActions.SELECT_OBJECT:
selectedObject.value = {
type: (data as MediaItem).type,
id: (data as MediaItem).object_uuid ?? "",
};
break;
case fromEngineActions.UPDATE_CHARACTER_ID:
addNewCharacter(data as MediaItem);
break;
case fromEngineActions.UPDATE_TIME:
currentTime.value = (data as UpdateTime).currentTime;
break;
case fromEngineActions.UPDATE_TIME_LINE:
clearExistingData();
(data as ClipUI[]).forEach((item) => {
LOADING_FUNCTIONS[item.group](item);
});
break;
case fromEngineActions.POP_A_TOAST: {
const message = (data as ToastDataType).message;
addToast(ToastTypes.ERROR, message);
break;
}
case fromEngineActions.CAMERA_ASPECT_RATIO_CHANGED: {
cameraAspectRatio.value = data as CameraAspectRatio;
break;
}
default:
throw new Error(`Unknown action ${action}`);
}
},
[],
);
const handleToTimelineActions = useCallback(
({ action, data }: QueueSubscribeType) => {
console.log("TO TIMELINE", action, data);
switch (action) {
case toTimelineActions.ADD_KEYFRAME:
addKeyframe(data as QueueKeyframe, currentTime.value);
break;
default:
throw new Error(`Unknown action ${action}`);
}
},
[],
);
useEffect(() => {
Queue.subscribe(QueueNames.FROM_ENGINE, handleFromEngineActions);
Queue.subscribe(QueueNames.TO_TIMELINE, handleToTimelineActions);
}, [handleFromEngineActions, handleToTimelineActions]);
}