Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

Commit

Permalink
Update Cinematic Camera. Previous/Index Function. (#434)
Browse files Browse the repository at this point in the history
* Update Cinematic Camera. Previous/Index Function.

* Fix random import
  • Loading branch information
Booster1212 committed Aug 10, 2023
1 parent 92069ee commit 6c506bf
Showing 1 changed file with 80 additions and 0 deletions.
80 changes: 80 additions & 0 deletions src/core/client/camera/cinematic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,82 @@ export async function next(removeFromArray = true): Promise<boolean> {
return true;
}

/**
* Goes to the index specified camera.
*
* If `false` is passed in the function it will not remove a camera
* from the camera array. Allows for repeating camera movement over and over.
*
* @param {boolean} [removeFromArray=true]
* @return {Promise<boolean>}
*
*/
export async function switchNode(index: number, removeFromArray = true) {
if (Overrides.switchNode) {
return Overrides.switchNode;
}

if (nodes.length <= 0) {
return false;
}

await InternalFunctions.isCameraUpdating();

if (removeFromArray) {
const prevCam = nodes.pop();
await InternalFunctions.next(prevCam);
} else {
currentCamIndex -= 1;

if (currentCamIndex < 0) {
currentCamIndex = nodes.length - 1;
}

const prevCam = nodes[index];
await InternalFunctions.next(prevCam);
}

return true;
}

/**
* Goes to the previous camera.
*
* If `false` is passed in the function it will not remove a camera
* from the camera array. Allows for repeating camera movement over and over.
*
* @param {boolean} [removeFromArray=true]
* @return {Promise<boolean>}
*
*/
export async function previous(removeFromArray = true): Promise<boolean> {
if (Overrides.previous) {
return Overrides.previous(removeFromArray);
}

if (nodes.length <= 0) {
return false;
}

await InternalFunctions.isCameraUpdating();

if (removeFromArray) {
const prevCam = nodes.pop();
await InternalFunctions.next(prevCam);
} else {
currentCamIndex -= 1;

if (currentCamIndex < 0) {
currentCamIndex = nodes.length - 1;
}

const prevCam = nodes[currentCamIndex];
await InternalFunctions.next(prevCam);
}

return true;
}

/**
* Play all camera nodes, but do not clear the camera nodes array.
*
Expand All @@ -404,6 +480,8 @@ interface CinematicCamFuncs {
destroy: typeof destroy;
overrideNodes: typeof overrideNodes;
next: typeof next;
previous: typeof previous;
switchNode: typeof switchNode;
play: typeof play;
}

Expand All @@ -413,6 +491,8 @@ export function override(functionName: 'addNode', callback: typeof addNode);
export function override(functionName: 'destroy', callback: typeof destroy);
export function override(functionName: 'overrideNodes', callback: typeof overrideNodes);
export function override(functionName: 'next', callback: typeof next);
export function override(functionName: 'switchNode', callback: typeof switchNode);
export function override(functionName: 'previous', callback: typeof previous);
export function override(functionName: 'play', callback: typeof play);
export function override(functionName: keyof CinematicCamFuncs, callback: any): void {
Overrides[functionName] = callback;
Expand Down

0 comments on commit 6c506bf

Please sign in to comment.