Theatric: make the studio select the default object on first load
This commit is contained in:
parent
1f8da4f4ba
commit
6bbf43a922
1 changed files with 17 additions and 1 deletions
|
@ -217,12 +217,14 @@ export function useControls<Config extends ControlsAndButtons>(
|
||||||
allPanelActions.push(actions)
|
allPanelActions.push(actions)
|
||||||
// cleanup runs after render, so we have to reconfigure with the new props here too, doing it during render just makes sure that
|
// cleanup runs after render, so we have to reconfigure with the new props here too, doing it during render just makes sure that
|
||||||
// the very first values returned are not undefined
|
// the very first values returned are not undefined
|
||||||
sheet.object(panel, Object.assign({}, ...allPanelProps), {
|
let obj = sheet.object(panel, Object.assign({}, ...allPanelProps), {
|
||||||
reconfigure: true,
|
reconfigure: true,
|
||||||
__actions__THIS_API_IS_UNSTABLE_AND_WILL_CHANGE_IN_THE_NEXT_VERSION:
|
__actions__THIS_API_IS_UNSTABLE_AND_WILL_CHANGE_IN_THE_NEXT_VERSION:
|
||||||
Object.assign({}, ...allPanelActions),
|
Object.assign({}, ...allPanelActions),
|
||||||
})
|
})
|
||||||
|
|
||||||
|
selectObjectIfNecessary(obj)
|
||||||
|
|
||||||
return () => {
|
return () => {
|
||||||
allPanelProps.splice(allPanelProps.indexOf(props), 1)
|
allPanelProps.splice(allPanelProps.indexOf(props), 1)
|
||||||
allActions[panel].splice(allPanelActions.indexOf(actions), 1)
|
allActions[panel].splice(allPanelActions.indexOf(actions), 1)
|
||||||
|
@ -328,3 +330,17 @@ function callGetProject() {
|
||||||
_project = getProject('Theatric', _projectConfig ?? undefined)
|
_project = getProject('Theatric', _projectConfig ?? undefined)
|
||||||
return _project
|
return _project
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let objAlreadySelected = false
|
||||||
|
// When the user first opens the page, no object will be selected, which for users
|
||||||
|
// unfamiliar with theatre can be confusing. Let's help the user by selecting the first object
|
||||||
|
// that is created using `useControls()`.
|
||||||
|
function selectObjectIfNecessary(obj: ISheetObject) {
|
||||||
|
if (objAlreadySelected) return
|
||||||
|
objAlreadySelected = true
|
||||||
|
if (process.env.NODE_ENV === 'development') {
|
||||||
|
if (studio.selection.length === 0) {
|
||||||
|
studio.setSelection([obj])
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue