recital / packages / ext-common-commands / src / tools / scene-tools.ts
scene-tools.ts
Raw
/**
 * Copyright (c) 2022 Amorphous
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

import { FlatObject, SceneObject } from '@a-morphous/recital/dist/types/types'

export const findScene = (
	stageObjects: FlatObject[],
	primary?: string,
	title?: string
): SceneObject | undefined => {
	if (!primary && !title) {
		return undefined
	}

	if (primary && title) {
		return stageObjects.find((val) => {
			return val.type === 'scene' && val.primary === primary && val.title === title
		}) as SceneObject
	}

	if (primary) {
		return stageObjects.find((val) => {
			return val.type === 'scene' && val.primary === primary
		}) as SceneObject
	}

	if (title) {
		return stageObjects.find((val) => {
			return val.type === 'scene' && val.title === title
		}) as SceneObject
	}
}