-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: attach/detach, loop animation, stop animation/sound (#770)
* feat: attach/detach, loop animation, stop animation/sound * feat: upgrade @dcl/asset-packs
- Loading branch information
Showing
11 changed files
with
395 additions
and
292 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
11 changes: 11 additions & 0 deletions
11
...rc/components/EntityInspector/ActionInspector/PlayAnimationAction/PlayAnimationAction.css
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
.PlayAnimationActionContainer { | ||
width: 100%; | ||
} | ||
|
||
.PlayAnimationActionContainer .SelectField { | ||
width: 100%; | ||
} | ||
|
||
.PlayAnimationActionContainer .SelectField { | ||
width: 100%; | ||
} |
78 changes: 78 additions & 0 deletions
78
...rc/components/EntityInspector/ActionInspector/PlayAnimationAction/PlayAnimationAction.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
import React, { useCallback, useEffect, useState } from 'react' | ||
import { ActionPayload, ActionType } from '@dcl/asset-packs' | ||
import { recursiveCheck } from 'jest-matcher-deep-close-to/lib/recursiveCheck' | ||
import { SelectField } from '../../SelectField' | ||
import { Dropdown } from '../../../Dropdown' | ||
import { isValid } from './utils' | ||
import type { Props } from './types' | ||
|
||
import './PlayAnimationAction.css' | ||
|
||
enum PLAY_MODE { | ||
PLAY_ONCE = 'play-once', | ||
LOOP = 'loop' | ||
} | ||
|
||
const playModeOptions = [ | ||
{ | ||
label: 'Play Once', | ||
value: PLAY_MODE.PLAY_ONCE | ||
}, | ||
{ | ||
label: 'Loop', | ||
value: PLAY_MODE.LOOP | ||
} | ||
] | ||
|
||
const PlaySoundAction: React.FC<Props> = ({ value, animations, onUpdate }: Props) => { | ||
const [payload, setPayload] = useState<Partial<ActionPayload<ActionType.PLAY_ANIMATION>>>({ | ||
...value | ||
}) | ||
|
||
useEffect(() => { | ||
if (!recursiveCheck(payload, value, 2) || !isValid(payload)) return | ||
onUpdate(payload) | ||
}, [payload, onUpdate]) | ||
|
||
const handleChangeAnimation = useCallback( | ||
({ target: { value } }: React.ChangeEvent<HTMLSelectElement>) => { | ||
setPayload({ ...payload, animation: value }) | ||
}, | ||
[payload, setPayload] | ||
) | ||
|
||
const handleChangePlayMode = useCallback( | ||
({ target: { value } }: React.ChangeEvent<HTMLSelectElement>) => { | ||
setPayload({ ...payload, loop: value === PLAY_MODE.LOOP }) | ||
}, | ||
[payload, setPayload] | ||
) | ||
|
||
return ( | ||
<div className="PlayAnimationActionContainer"> | ||
<div className="row"> | ||
<div className="field"> | ||
<label>Select Animation</label> | ||
<Dropdown | ||
options={[ | ||
{ value: '', text: 'Select an Animation' }, | ||
...animations.map((animation) => ({ text: animation.name, value: animation.name })) | ||
]} | ||
value={payload.animation} | ||
onChange={handleChangeAnimation} | ||
/> | ||
</div> | ||
<div className="field"> | ||
<label>Play Mode</label> | ||
<SelectField | ||
value={payload.loop ? PLAY_MODE.LOOP : PLAY_MODE.PLAY_ONCE} | ||
options={playModeOptions} | ||
onChange={handleChangePlayMode} | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
) | ||
} | ||
|
||
export default React.memo(PlaySoundAction) |
2 changes: 2 additions & 0 deletions
2
...dcl/inspector/src/components/EntityInspector/ActionInspector/PlayAnimationAction/index.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
import PlayAnimationAction from './PlayAnimationAction' | ||
export { PlayAnimationAction } |
8 changes: 8 additions & 0 deletions
8
...dcl/inspector/src/components/EntityInspector/ActionInspector/PlayAnimationAction/types.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
import { AnimationGroup } from '@babylonjs/core' | ||
import { ActionPayload, ActionType } from '@dcl/asset-packs' | ||
|
||
export interface Props { | ||
value: Partial<ActionPayload<ActionType.PLAY_ANIMATION>> | ||
animations: AnimationGroup[] | ||
onUpdate: (value: ActionPayload<ActionType.PLAY_ANIMATION>) => void | ||
} |
7 changes: 7 additions & 0 deletions
7
...dcl/inspector/src/components/EntityInspector/ActionInspector/PlayAnimationAction/utils.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
import { ActionPayload, ActionType } from '@dcl/asset-packs' | ||
|
||
export function isValid( | ||
payload: Partial<ActionPayload<ActionType.PLAY_ANIMATION>> | ||
): payload is ActionPayload<ActionType.PLAY_ANIMATION> { | ||
return !!payload.animation | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters