Skip to content

Commit

Permalink
Replace warnings with notifications
Browse files Browse the repository at this point in the history
Also rewrote all warnings to be more helpful and readable.
  • Loading branch information
AndrewPrifer committed Oct 21, 2022
1 parent 62bc12a commit dee2361
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 5 deletions.
20 changes: 17 additions & 3 deletions theatre/core/src/sequences/Sequence.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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]

Expand Down Expand Up @@ -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
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import type {
IPlaybackController,
IPlaybackState,
} from './DefaultPlaybackController'
import {notify} from '@theatre/shared/notify'

export default class AudioPlaybackController implements IPlaybackController {
_mainGain: GainNode
Expand Down Expand Up @@ -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
}
Expand Down
7 changes: 7 additions & 0 deletions theatre/core/src/sheets/TheatreSheet.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -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
}
Expand Down

0 comments on commit dee2361

Please sign in to comment.