Merge pull request #114 from storytold/feature/load-ui

Feature/load UI
This commit is contained in:
ArEnSc authored and GitHub committed 2024-04-08 14:31:59 -04:00
commit c8fb372470
15 files changed
+435 -365

No files matched your search

@@ -2,23 +2,19 @@ import { fromEngineActions } from "~/pages/PageEnigma/Queue/fromEngineActions";
import { useSignals } from "@preact/signals-react/runtime";
import { useCallback, useContext, useEffect } from "react";
import {
audioGroup,
cameraGroup,
characterGroups,
addNewCharacter,
currentTime,
objectGroup,
loadAudioData,
loadCameraData,
loadCharacterData,
loadObjectData,
} from "~/pages/PageEnigma/store";
import Queue from "~/pages/PageEnigma/Queue/Queue";
import { QueueNames } from "~/pages/PageEnigma/Queue/QueueNames";
import { toEngineActions } from "~/pages/PageEnigma/Queue/toEngineActions";
import {
CharacterGroup,
Clip,
ClipGroup,
ClipType,
Keyframe,
MediaItem,
ObjectTrack,
QueueClip,
QueueKeyframe,
UpdateTime,
@@ -32,69 +28,16 @@ interface Arguments {
data: QueueClip | UpdateTime | QueueKeyframe | ClipUI[] | MediaItem;
}
function addCharacter(item: ClipUI) {
const existingCharacter = characterGroups.value.find(
(character) => character.id === item.object_uuid,
);
if (existingCharacter) {
return existingCharacter;
}
const newCharacter = {
id: item.object_uuid,
name: item.object_name,
muted: false,
animationClips: [],
positionKeyframes: [],
lipSyncClips: [],
} as CharacterGroup;
characterGroups.value = [
...characterGroups.value.filter(
(character) => character.id !== item.object_uuid,
),
newCharacter,
].sort((charA, charB) => (charA.id < charB.id ? -1 : 1));
return characterGroups.value.find(
(character) => character.id === item.object_uuid,
) as CharacterGroup;
}
function addObject(item: ClipUI) {
const existingObject = objectGroup.value.objects.find(
(obj) => obj.object_uuid === item.object_uuid,
);
if (existingObject) {
return existingObject;
}
const newObject = {
object_uuid: item.object_uuid,
name: item.object_name,
keyframes: [] as Keyframe[],
} as ObjectTrack;
objectGroup.value = {
id: "OB1",
objects: [
...objectGroup.value.objects.filter(
(obj) => obj.object_uuid !== item.object_uuid,
),
newObject,
].sort((objA, objB) => (objA.object_uuid < objB.object_uuid ? -1 : 1)),
};
return objectGroup.value.objects.find(
(obj) => obj.object_uuid === item.object_uuid,
) as ObjectTrack;
}
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 { addKeyframe } = useContext(TrackContext);
const { addKeyframe, clearExistingData } = useContext(TrackContext);
const handleFromEngineActions = useCallback(({ action, data }: Arguments) => {
console.log("FROM ENGINE", action, data);
@@ -103,120 +46,13 @@ export function useQueueHandler() {
currentTime.value = (data as UpdateTime).currentTime;
break;
case fromEngineActions.UPDATE_TIME_LINE:
console.log(data);
clearExistingData();
(data as ClipUI[]).forEach((item) => {
if (item.group === ClipGroup.CHARACTER) {
const existingCharacter = addCharacter(item);
if (item.type === ClipType.ANIMATION) {
const newItem = {
version: item.version,
clip_uuid: item.clip_uuid,
type: item.type,
group: item.group,
object_uuid: item.object_uuid,
media_id: item.media_id,
name: item.name,
offset: item.offset,
length: item.length,
} as Clip;
existingCharacter.animationClips.push(newItem);
existingCharacter.animationClips.sort(
(clipA, clipB) => clipA.offset - clipB.offset,
);
}
if (item.type === ClipType.TRANSFORM) {
const newKeyframe = {
version: item.version,
keyframe_uuid: item.clip_uuid,
group: item.group,
object_uuid: item.object_uuid,
offset: item.keyframe_offset,
} as Keyframe;
existingCharacter.positionKeyframes.push(newKeyframe);
existingCharacter.positionKeyframes.sort(
(keyframeA, keyframeB) => keyframeA.offset - keyframeB.offset,
);
}
if (item.type === ClipType.AUDIO) {
const newItem = {
version: item.version,
clip_uuid: item.clip_uuid,
type: item.type,
group: item.group,
object_uuid: item.object_uuid,
media_id: item.media_id,
name: item.name,
offset: item.offset,
length: item.length,
} as Clip;
existingCharacter.lipSyncClips.push(newItem);
existingCharacter.lipSyncClips.sort(
(clipA, clipB) => clipA.offset - clipB.offset,
);
}
}
if (item.group === ClipGroup.OBJECT) {
const existingObject = addObject(item);
const newKeyframe = {
version: item.version,
keyframe_uuid: item.clip_uuid,
group: item.group,
object_uuid: item.object_uuid,
offset: item.keyframe_offset,
} as Keyframe;
existingObject.keyframes.push(newKeyframe);
existingObject.keyframes.sort(
(keyframeA, keyframeB) => keyframeA.offset - keyframeB.offset,
);
}
if (item.group === ClipGroup.CAMERA) {
const existingCamera = cameraGroup.value;
const newKeyframe = {
version: item.version,
keyframe_uuid: item.clip_uuid,
group: item.group,
object_uuid: item.object_uuid,
offset: item.keyframe_offset,
} as Keyframe;
existingCamera.keyframes.push(newKeyframe);
existingCamera.keyframes.sort(
(keyframeA, keyframeB) => keyframeA.offset - keyframeB.offset,
);
// cameraGroup.value = { ...cameraGroup.value };
}
if (item.group === ClipGroup.GLOBAL_AUDIO) {
const existingAudio = audioGroup.value;
const newItem = {
version: item.version,
clip_uuid: item.clip_uuid,
type: item.type,
group: item.group,
object_uuid: item.object_uuid,
media_id: item.media_id,
name: item.name,
offset: item.offset,
length: item.length,
} as Clip;
existingAudio.clips.push(newItem);
existingAudio.clips.sort(
(clipA, clipB) => clipA.offset - clipB.offset,
);
}
LOADING_FUNCTIONS[item.group](item);
});
break;
case fromEngineActions.UPDATE_CHARACTER_ID: {
const newCharacter = {
id: (data as MediaItem).object_uuid,
name: (data as MediaItem).name,
muted: false,
animationClips: [],
positionKeyframes: [],
lipSyncClips: [],
} as CharacterGroup;
characterGroups.value = [...characterGroups.value, newCharacter].sort(
(charA, charB) => (charA.id < charB.id ? -1 : 1),
);
addNewCharacter(data as MediaItem);
break;
}
default:
@@ -224,16 +60,19 @@ export function useQueueHandler() {
}
}, []);
const handleToTimelineActions = useCallback(({ action, data }: Arguments) => {
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}`);
}
}, []);
const handleToTimelineActions = useCallback(
({ action, data }: Arguments) => {
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}`);
}
},
[addKeyframe],
);
useEffect(() => {
Queue.subscribe(QueueNames.FROM_ENGINE, handleFromEngineActions);
@@ -6,6 +6,9 @@ export const TrackContext = createContext<{
addKeyframe: (keyframe: QueueKeyframe, offset: number) => void;
deleteKeyframe: (keyframe: Keyframe) => void;
// misc
clearExistingData: () => void;
// drag and drop
startDrag: (item: MediaItem) => void;
endDrag: () => void;
@@ -13,6 +16,8 @@ export const TrackContext = createContext<{
addKeyframe: () => {},
deleteKeyframe: () => {},
clearExistingData: () => {},
startDrag: () => {},
endDrag: () => {},
});
@@ -12,6 +12,10 @@ import {
dropId,
dropOffset,
addObject,
characterGroups,
cameraGroup,
audioGroup,
objectGroup,
} from "~/pages/PageEnigma/store";
import useUpdateKeyframe from "~/pages/PageEnigma/contexts/TrackContext/utils/useUpdateKeyframe";
@@ -26,12 +30,9 @@ export const TrackProvider = ({ children }: Props) => {
// cross group functions
const dropClip = useCallback(() => {
console.log(`${JSON.stringify(dragItem)}`);
if (dragItem.value != null && dragItem != null) {
// should be able to drag into the timeline ... TODO FIX?
if (dragItem.value.type === AssetType.CHARACTER) {
if (dragItem.value) {
const mediaItem = dragItem.value;
if (mediaItem.type === AssetType.CHARACTER) {
addCharacter(dragItem.value);
}
// if (dragItem.value.type === AssetType.CAMERA) {
@@ -48,7 +49,7 @@ export const TrackProvider = ({ children }: Props) => {
if (canDrop.value && dragItem.value) {
if (dragItem.value.type === AssetType.ANIMATION) {
addCharacterAnimation({
dragItem: dragItem.value!,
dragItem: dragItem.value,
characterId: dropId.value,
offset: dropOffset.value,
});
@@ -56,12 +57,12 @@ export const TrackProvider = ({ children }: Props) => {
if (dragItem.value.type === AssetType.AUDIO) {
console.log("add audio", dropId.value);
addCharacterAudio({
dragItem: dragItem.value!,
dragItem: dragItem.value,
characterId: dropId.value,
offset: dropOffset.value,
});
addGlobalAudio({
dragItem: dragItem.value!,
dragItem: dragItem.value,
audioId: dropId.value,
offset: dropOffset.value,
});
@@ -70,14 +71,34 @@ export const TrackProvider = ({ children }: Props) => {
endDrag();
}, [endDrag]);
const clearExistingData = useCallback(() => {
characterGroups.value = [];
cameraGroup.value = {
id: "CG1",
keyframes: [],
};
audioGroup.value = {
id: "AG-1",
clips: [],
muted: false,
};
objectGroup.value = {
id: "OG1",
objects: [],
};
}, []);
const values = useMemo(() => {
return {
...keyframes,
clearExistingData,
...dragDrop,
endDrag: dropClip,
};
}, [keyframes, dragDrop, dropClip]);
}, [keyframes, dragDrop, dropClip, clearExistingData]);
return (
<TrackContext.Provider value={values}>{children}</TrackContext.Provider>
);
@@ -28,6 +28,7 @@ const DELETE_KEYFRAME: Record<ClipGroup, (keyframe: Keyframe) => void> = {
export default function useUpdateKeyframe() {
const addKeyframe = useCallback((keyframe: QueueKeyframe, offset: number) => {
console.log("k", keyframe);
ADD_KEYFRAME[keyframe.group](keyframe, offset);
}, []);
+18
View File
@@ -10,6 +10,7 @@ import { QueueNames } from "~/pages/PageEnigma/Queue/QueueNames";
import { toEngineActions } from "~/pages/PageEnigma/Queue/toEngineActions";
import * as uuid from "uuid";
import { signal } from "@preact/signals-core";
import { ClipUI } from "~/pages/PageEnigma/datastructures/clips/clip_ui";
export const audioGroup = signal<AudioGroup>({
id: "AG-1",
@@ -140,3 +141,20 @@ export function deleteAudioClip(clip: Clip) {
],
};
}
export function loadAudioData(item: ClipUI) {
const existingAudio = audioGroup.value;
const newItem = {
version: item.version,
clip_uuid: item.clip_uuid,
type: item.type,
group: item.group,
object_uuid: item.object_uuid,
media_id: item.media_id,
name: item.name,
offset: item.offset,
length: item.length,
} as Clip;
existingAudio.clips.push(newItem);
existingAudio.clips.sort((clipA, clipB) => clipA.offset - clipB.offset);
}
+16
View File
@@ -8,6 +8,7 @@ import { QueueNames } from "~/pages/PageEnigma/Queue/QueueNames";
import { toEngineActions } from "~/pages/PageEnigma/Queue/toEngineActions";
import * as uuid from "uuid";
import { signal } from "@preact/signals-core";
import { ClipUI } from "~/pages/PageEnigma/datastructures/clips/clip_ui";
// import { toast } from "react-hot-toast";
export const cameraGroup = signal<CameraGroup>({ id: "CG1", keyframes: [] });
@@ -112,3 +113,18 @@ export function deleteCameraKeyframe(deleteKeyframe: Keyframe) {
],
};
}
export function loadCameraData(item: ClipUI) {
const existingCamera = cameraGroup.value;
const newKeyframe = {
version: item.version,
keyframe_uuid: item.clip_uuid,
group: item.group,
object_uuid: item.object_uuid,
offset: item.keyframe_offset,
} as Keyframe;
existingCamera.keyframes.push(newKeyframe);
existingCamera.keyframes.sort(
(keyframeA, keyframeB) => keyframeA.offset - keyframeB.offset,
);
}
@@ -0,0 +1,28 @@
import { CharacterGroup, MediaItem } from "~/pages/PageEnigma/models";
import Queue from "~/pages/PageEnigma/Queue/Queue";
import { QueueNames } from "~/pages/PageEnigma/Queue/QueueNames";
import { toEngineActions } from "~/pages/PageEnigma/Queue/toEngineActions";
import { characterGroups } from "~/pages/PageEnigma/store";
export function addCharacter(character: MediaItem) {
Queue.publish({
queueName: QueueNames.TO_ENGINE,
action: toEngineActions.ADD_CHARACTER,
data: character,
});
}
export function addNewCharacter(data: MediaItem) {
const newCharacter = {
id: data.object_uuid,
name: data.name,
muted: false,
animationClips: [],
positionKeyframes: [],
lipSyncClips: [],
} as CharacterGroup;
characterGroups.value = [...characterGroups.value, newCharacter].sort(
(charA, charB) => (charA.id < charB.id ? -1 : 1),
);
}
@@ -15,95 +15,6 @@ import * as uuid from "uuid";
export const characterGroups = signal<CharacterGroup[]>([]);
export function updateCharacters({
type,
id,
offset,
length,
}: {
type: ClipType;
id: string;
length?: number;
offset: number;
}) {
const oldCharacterGroups = characterGroups.value;
if (type === ClipType.ANIMATION) {
characterGroups.value = oldCharacterGroups.map((character) => {
const newAnimationClips = [...character.animationClips];
const clipIndex = newAnimationClips.findIndex(
(row) => row.clip_uuid === id,
);
if (clipIndex === -1) {
return { ...character };
}
const clip = newAnimationClips[clipIndex];
clip.offset = offset;
clip.length = length!;
Queue.publish({
queueName: QueueNames.TO_ENGINE,
action: toEngineActions.UPDATE_CLIP,
data: clip,
});
return {
...character,
animationClips: newAnimationClips,
};
});
}
if (type === ClipType.TRANSFORM) {
characterGroups.value = oldCharacterGroups.map((character) => {
const newPositionKeyframes = [...character.positionKeyframes];
const keyframeIndex = newPositionKeyframes.findIndex(
(row) => row.keyframe_uuid === id,
);
if (keyframeIndex === -1) {
return { ...character };
}
const keyframe = newPositionKeyframes[keyframeIndex];
keyframe.offset = offset;
Queue.publish({
queueName: QueueNames.TO_ENGINE,
action: toEngineActions.UPDATE_CLIP,
data: keyframe,
});
return {
...character,
positionKeyframes: newPositionKeyframes,
};
});
}
if (type === ClipType.AUDIO) {
characterGroups.value = oldCharacterGroups.map((character) => {
const newLipSyncClips = [...character.lipSyncClips];
const clipIndex = newLipSyncClips.findIndex(
(row) => row.clip_uuid === id,
);
if (clipIndex === -1) {
return { ...character };
}
const clip = newLipSyncClips[clipIndex];
clip.offset = offset;
clip.length = length!;
Queue.publish({
queueName: QueueNames.TO_ENGINE,
action: toEngineActions.UPDATE_CLIP,
data: clip,
});
return {
...character,
lipSyncClips: newLipSyncClips,
};
});
}
}
export function addCharacterAnimation({
dragItem,
characterId,
@@ -326,25 +237,3 @@ export function deleteCharacterKeyframe(keyframe: Keyframe) {
}),
}));
}
// probably not to much to send imo
export function addCharacter(character: MediaItem) {
//{"version":1,"media_id":"m_r7w1tmkx2jg8nznr3hyzj4k6zhfh7d ",
// "type":"character","name":"Female Doll",
// "thumbnail":"resources/characters/img03.png"}
Queue.publish({
queueName: QueueNames.TO_ENGINE,
action: toEngineActions.ADD_CHARACTER,
data: character,
});
}
export function addObject(object: MediaItem) {
//{"version":1,"media_id":"m_r7w1tmkx2jg8nznr3hyzj4k6zhfh7d ",
// "type":"character","name":"Female Doll",
// "thumbnail":"resources/characters/img03.png"}
Queue.publish({
queueName: QueueNames.TO_ENGINE,
action: toEngineActions.ADD_OBJECT,
data: object,
});
}
@@ -0,0 +1,4 @@
export * from "./addCharacter";
export * from "./characterGroups";
export * from "./loadCharacterData";
export * from "./updateCharacters";
@@ -0,0 +1,89 @@
import { ClipUI } from "~/pages/PageEnigma/datastructures/clips/clip_ui";
import {
CharacterGroup,
Clip,
ClipType,
Keyframe,
} from "~/pages/PageEnigma/models";
import { characterGroups } from "~/pages/PageEnigma/store";
function getAddCharacter(item: ClipUI) {
const existingCharacter = characterGroups.value.find(
(character) => character.id === item.object_uuid,
);
if (existingCharacter) {
return existingCharacter;
}
const newCharacter = {
id: item.object_uuid,
name: item.object_name,
muted: false,
animationClips: [],
positionKeyframes: [],
lipSyncClips: [],
} as CharacterGroup;
characterGroups.value = [
...characterGroups.value.filter(
(character) => character.id !== item.object_uuid,
),
newCharacter,
].sort((charA, charB) => (charA.id < charB.id ? -1 : 1));
return characterGroups.value.find(
(character) => character.id === item.object_uuid,
) as CharacterGroup;
}
export function loadCharacterData(item: ClipUI) {
const existingCharacter = getAddCharacter(item);
if (item.type === ClipType.ANIMATION) {
const newItem = {
version: item.version,
clip_uuid: item.clip_uuid,
type: item.type,
group: item.group,
object_uuid: item.object_uuid,
media_id: item.media_id,
name: item.name,
offset: item.offset,
length: item.length,
} as Clip;
existingCharacter.animationClips.push(newItem);
existingCharacter.animationClips.sort(
(clipA, clipB) => clipA.offset - clipB.offset,
);
}
if (item.type === ClipType.TRANSFORM) {
const newKeyframe = {
version: item.version,
keyframe_uuid: item.clip_uuid,
group: item.group,
object_uuid: item.object_uuid,
offset: item.keyframe_offset,
} as Keyframe;
existingCharacter.positionKeyframes.push(newKeyframe);
existingCharacter.positionKeyframes.sort(
(keyframeA, keyframeB) => keyframeA.offset - keyframeB.offset,
);
}
if (item.type === ClipType.AUDIO) {
const newItem = {
version: item.version,
clip_uuid: item.clip_uuid,
type: item.type,
group: item.group,
object_uuid: item.object_uuid,
media_id: item.media_id,
name: item.name,
offset: item.offset,
length: item.length,
} as Clip;
existingCharacter.lipSyncClips.push(newItem);
existingCharacter.lipSyncClips.sort(
(clipA, clipB) => clipA.offset - clipB.offset,
);
}
}
@@ -0,0 +1,94 @@
import { ClipType } from "~/pages/PageEnigma/models";
import Queue from "~/pages/PageEnigma/Queue/Queue";
import { QueueNames } from "~/pages/PageEnigma/Queue/QueueNames";
import { toEngineActions } from "~/pages/PageEnigma/Queue/toEngineActions";
import { characterGroups } from "~/pages/PageEnigma/store";
export function updateCharacters({
type,
id,
offset,
length,
}: {
type: ClipType;
id: string;
length?: number;
offset: number;
}) {
const oldCharacterGroups = characterGroups.value;
if (type === ClipType.ANIMATION) {
characterGroups.value = oldCharacterGroups.map((character) => {
const newAnimationClips = [...character.animationClips];
const clipIndex = newAnimationClips.findIndex(
(row) => row.clip_uuid === id,
);
if (clipIndex === -1) {
return { ...character };
}
const clip = newAnimationClips[clipIndex];
clip.offset = offset;
clip.length = length!;
Queue.publish({
queueName: QueueNames.TO_ENGINE,
action: toEngineActions.UPDATE_CLIP,
data: clip,
});
return {
...character,
animationClips: newAnimationClips,
};
});
}
if (type === ClipType.TRANSFORM) {
characterGroups.value = oldCharacterGroups.map((character) => {
const newPositionKeyframes = [...character.positionKeyframes];
const keyframeIndex = newPositionKeyframes.findIndex(
(row) => row.keyframe_uuid === id,
);
if (keyframeIndex === -1) {
return { ...character };
}
const keyframe = newPositionKeyframes[keyframeIndex];
keyframe.offset = offset;
Queue.publish({
queueName: QueueNames.TO_ENGINE,
action: toEngineActions.UPDATE_CLIP,
data: keyframe,
});
return {
...character,
positionKeyframes: newPositionKeyframes,
};
});
}
if (type === ClipType.AUDIO) {
characterGroups.value = oldCharacterGroups.map((character) => {
const newLipSyncClips = [...character.lipSyncClips];
const clipIndex = newLipSyncClips.findIndex(
(row) => row.clip_uuid === id,
);
if (clipIndex === -1) {
return { ...character };
}
const clip = newLipSyncClips[clipIndex];
clip.offset = offset;
clip.length = length!;
Queue.publish({
queueName: QueueNames.TO_ENGINE,
action: toEngineActions.UPDATE_CLIP,
data: clip,
});
return {
...character,
lipSyncClips: newLipSyncClips,
};
});
}
}
@@ -0,0 +1,3 @@
export * from "./loadObjectData";
export * from "./objectGroup";
export * from "./updateObjectGroup";
@@ -0,0 +1,48 @@
import { ClipUI } from "~/pages/PageEnigma/datastructures/clips/clip_ui";
import { Keyframe, ObjectTrack } from "~/pages/PageEnigma/models";
import { objectGroup } from "~/pages/PageEnigma/store";
function getAddObject(item: ClipUI) {
const existingObject = objectGroup.value.objects.find(
(obj) => obj.object_uuid === item.object_uuid,
);
if (existingObject) {
return existingObject;
}
const newObject = {
object_uuid: item.object_uuid,
name: item.object_name,
keyframes: [] as Keyframe[],
} as ObjectTrack;
objectGroup.value = {
id: "OB1",
objects: [
...objectGroup.value.objects.filter(
(obj) => obj.object_uuid !== item.object_uuid,
),
newObject,
].sort((objA, objB) => (objA.object_uuid < objB.object_uuid ? -1 : 1)),
};
return objectGroup.value.objects.find(
(obj) => obj.object_uuid === item.object_uuid,
) as ObjectTrack;
}
export function loadObjectData(item: ClipUI) {
const existingObject = getAddObject(item);
const newKeyframe = {
version: item.version,
keyframe_uuid: item.clip_uuid,
group: item.group,
object_uuid: item.object_uuid,
offset: item.keyframe_offset,
} as Keyframe;
existingObject.keyframes.push(newKeyframe);
existingObject.keyframes.sort(
(keyframeA, keyframeB) => keyframeA.offset - keyframeB.offset,
);
}
@@ -1,13 +1,16 @@
import { signal } from "@preact/signals-core";
import {
Keyframe,
MediaItem,
ObjectGroup,
ObjectTrack,
QueueKeyframe,
} from "~/pages/PageEnigma/models";
import * as uuid from "uuid";
import Queue from "~/pages/PageEnigma/Queue/Queue";
import { QueueNames } from "~/pages/PageEnigma/Queue/QueueNames";
import { toEngineActions } from "~/pages/PageEnigma/Queue/toEngineActions";
import { ClipUI } from "~/pages/PageEnigma/datastructures/clips/clip_ui";
// import { toast } from "react-hot-toast";
export const objectGroup = signal<ObjectGroup>({
@@ -15,61 +18,6 @@ export const objectGroup = signal<ObjectGroup>({
objects: [],
});
export function updateObject({
id,
offset,
}: {
id: string;
offset: number;
}): void {
const oldObjectGroup = objectGroup.value;
const obj = oldObjectGroup.objects.find((objectTrack) =>
objectTrack.keyframes.some((row) => row.keyframe_uuid === id),
);
if (!obj) {
return;
}
const existingKeyframe = obj.keyframes.some((row) => {
return row.offset === offset && row.keyframe_uuid !== id;
});
if (existingKeyframe) {
//toast.error("There can only be one keyframe at this offset.");
return;
}
objectGroup.value = {
id: oldObjectGroup.id,
objects: oldObjectGroup.objects.map((object) => ({
object_uuid: object.object_uuid,
name: object.name,
keyframes: object.keyframes.map((keyframe) => {
if (keyframe.keyframe_uuid !== id) {
return {
...keyframe,
};
}
Queue.publish({
queueName: QueueNames.TO_ENGINE,
action: toEngineActions.UPDATE_KEYFRAME,
data: {
...keyframe,
offset,
},
});
return {
...keyframe,
offset,
};
}),
})),
};
}
export function addObjectKeyframe(keyframe: QueueKeyframe, offset: number) {
const oldObjectGroup = objectGroup.value;
const obj = oldObjectGroup.objects.find(
@@ -166,3 +114,11 @@ export function deleteObjectKeyframe(keyframe: Keyframe) {
],
};
}
export function addObject(object: MediaItem) {
Queue.publish({
queueName: QueueNames.TO_ENGINE,
action: toEngineActions.ADD_OBJECT,
data: object,
});
}
@@ -0,0 +1,59 @@
import Queue from "~/pages/PageEnigma/Queue/Queue";
import { QueueNames } from "~/pages/PageEnigma/Queue/QueueNames";
import { toEngineActions } from "~/pages/PageEnigma/Queue/toEngineActions";
import { objectGroup } from "~/pages/PageEnigma/store";
export function updateObject({
id,
offset,
}: {
id: string;
offset: number;
}): void {
const oldObjectGroup = objectGroup.value;
const obj = oldObjectGroup.objects.find((objectTrack) =>
objectTrack.keyframes.some((row) => row.keyframe_uuid === id),
);
if (!obj) {
return;
}
const existingKeyframe = obj.keyframes.some((row) => {
return row.offset === offset && row.keyframe_uuid !== id;
});
if (existingKeyframe) {
//toast.error("There can only be one keyframe at this offset.");
return;
}
objectGroup.value = {
id: oldObjectGroup.id,
objects: oldObjectGroup.objects.map((object) => ({
object_uuid: object.object_uuid,
name: object.name,
keyframes: object.keyframes.map((keyframe) => {
if (keyframe.keyframe_uuid !== id) {
return {
...keyframe,
};
}
Queue.publish({
queueName: QueueNames.TO_ENGINE,
action: toEngineActions.UPDATE_KEYFRAME,
data: {
...keyframe,
offset,
},
});
return {
...keyframe,
offset,
};
}),
})),
};
}