From dee2361c95f8cb36596899dd8bfa9e2f2b9f7692 Mon Sep 17 00:00:00 2001 From: Andrew Prifer Date: Fri, 21 Oct 2022 18:12:22 +0200 Subject: [PATCH] Replace warnings with notifications Also rewrote all warnings to be more helpful and readable. --- theatre/core/src/sequences/Sequence.ts | 20 ++++++++++++++++--- .../AudioPlaybackController.ts | 19 ++++++++++++++++-- theatre/core/src/sheets/TheatreSheet.ts | 7 +++++++ 3 files changed, 41 insertions(+), 5 deletions(-) diff --git a/theatre/core/src/sequences/Sequence.ts b/theatre/core/src/sequences/Sequence.ts index 1a56a35..82e43f8 100644 --- a/theatre/core/src/sequences/Sequence.ts +++ b/theatre/core/src/sequences/Sequence.ts @@ -16,6 +16,7 @@ import DefaultPlaybackController from './playbackControllers/DefaultPlaybackCont import TheatreSequence from './TheatreSequence' import type {ILogger} from '@theatre/shared/logger' import type {ISequence} from '..' +import {notify} from '@theatre/shared/notify' export type IPlaybackRange = [from: number, to: number] @@ -231,10 +232,23 @@ export default class Sequence { } if (range[1] > sequenceDuration) { - console.warn( - `Argument conf.range[1] in sequence.play(conf) cannot be longer than the duration of the sequence, which is ${sequenceDuration}s. ${JSON.stringify( + notify.warning( + "Couldn't play sequence in given range", + `Your animation will still play until the end of the sequence, however the argument \`conf.range[1]\` given in \`sequence.play(conf)\` (${JSON.stringify( range[1], - )} given.`, + )}s) is longer than the duration of the sequence (${sequenceDuration}s). + +To fix this, either set \`conf.range[1]\` to be less the duration of the sequence, or adjust the sequence duration in the UI.`, + [ + { + url: 'https://www.theatrejs.com/docs/latest/manual/sequences', + title: 'Sequences', + }, + { + url: 'https://www.theatrejs.com/docs/latest/manual/sequences', + title: 'Playback API', + }, + ], ) range[1] = sequenceDuration } diff --git a/theatre/core/src/sequences/playbackControllers/AudioPlaybackController.ts b/theatre/core/src/sequences/playbackControllers/AudioPlaybackController.ts index fc932ee..771abfc 100644 --- a/theatre/core/src/sequences/playbackControllers/AudioPlaybackController.ts +++ b/theatre/core/src/sequences/playbackControllers/AudioPlaybackController.ts @@ -11,6 +11,7 @@ import type { IPlaybackController, IPlaybackState, } from './DefaultPlaybackController' +import {notify} from '@theatre/shared/notify' export default class AudioPlaybackController implements IPlaybackController { _mainGain: GainNode @@ -186,8 +187,22 @@ export default class AudioPlaybackController implements IPlaybackController { currentSource.playbackRate.value = rate if (iterationCount > 1000) { - console.warn( - `Audio-controlled sequences cannot have an iterationCount larger than 1000. It has been clamped to 1000.`, + notify.warning( + "Can't play sequences with audio more than 1000 times", + `The sequence will still play, but only 1000 times. The \`iterationCount: ${iterationCount}\` provided to \`sequence.play()\` +is too high for a sequence with audio. + +To fix this, either set \`iterationCount\` to a lower value, or remove the audio from the sequence.`, + [ + { + url: 'https://www.theatrejs.com/docs/latest/manual/audio', + title: 'Using Audio', + }, + { + url: 'https://www.theatrejs.com/docs/latest/api/core#sequence.attachaudio', + title: 'Audio API', + }, + ], ) iterationCount = 1000 } diff --git a/theatre/core/src/sheets/TheatreSheet.ts b/theatre/core/src/sheets/TheatreSheet.ts index 10fbb6a..356f991 100644 --- a/theatre/core/src/sheets/TheatreSheet.ts +++ b/theatre/core/src/sheets/TheatreSheet.ts @@ -18,6 +18,7 @@ import type { } from '@theatre/core/propTypes/internals' import type SheetObject from '@theatre/core/sheetObjects/SheetObject' import type {ObjectAddressKey} from '@theatre/shared/utils/ids' +import {notify} from '@theatre/shared/notify' export type SheetObjectPropTypeConfig = PropTypeConfig_Compound @@ -181,6 +182,12 @@ export default class TheatreSheet implements ISheet { const obj = internal.getObject(sanitizedPath) if (!obj) { + notify.warning( + `Couldn\'t delete object "${sanitizedPath}"`, + `There is no object with key "${sanitizedPath}". + +To fix this, make sure you are calling \`sheet.deleteObject("${sanitizedPath}")\` with the correct key.`, + ) console.warn(`Object key "${sanitizedPath}" does not exist.`) return }