Replace warnings with notifications

Also rewrote all warnings to be more helpful and readable.
This commit is contained in:
Andrew Prifer 2022-10-21 18:12:22 +02:00 committed by Andrew Prifer
parent 62bc12ab51
commit dee2361c95
3 changed files with 41 additions and 5 deletions

View file

@ -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
}

View file

@ -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
}

View file

@ -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<UnknownValidCompoundProps>
@ -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
}