Skip to content

Commit

Permalink
Hard coded tween working for anim input link
Browse files Browse the repository at this point in the history
  • Loading branch information
funwithtriangles committed Dec 9, 2018
1 parent 5d50db9 commit ed8c577
Show file tree
Hide file tree
Showing 10 changed files with 64 additions and 22 deletions.
1 change: 1 addition & 0 deletions package.json
Expand Up @@ -33,6 +33,7 @@
]
},
"dependencies": {
"@tweenjs/tween.js": "^17.2.0",
"babel-loader": "^6.3.2",
"babel-plugin-transform-object-rest-spread": "^6.22.0",
"babel-polyfill": "^6.23.0",
Expand Down
10 changes: 5 additions & 5 deletions src/components/InputLink/index.js
Expand Up @@ -51,7 +51,7 @@ class InputLink extends React.Component {

render () {
const { modifierIds, lfoOptionIds, size, midiOptionIds, title, toggleActionId,
onAnimTriggerClick, animTriggerActionId,
onAnimStartClick, animStartActionId,
sequencerGridId, onDeleteClick, onActivateToggle, isActive, isActivateVisible } = this.props
return (
<div>
Expand All @@ -74,8 +74,8 @@ class InputLink extends React.Component {
{sequencerGridId &&
<SequencerGrid nodeId={sequencerGridId} />
}
{animTriggerActionId &&
<Button onClick={onAnimTriggerClick}>Trigger Anim</Button>
{animStartActionId &&
<Button onClick={onAnimStartClick}>Start Anim</Button>
}
</Wrapper>
<Row justify='space-between'>
Expand Down Expand Up @@ -112,8 +112,8 @@ InputLink.propTypes = {
sequencerGridId: PropTypes.string,
toggleActionId: PropTypes.string.isRequired,
isActivateVisible: PropTypes.bool,
animTriggerActionId: PropTypes.string,
onAnimTriggerClick: PropTypes.func.isRequired,
animStartActionId: PropTypes.string,
onAnimStartClick: PropTypes.func.isRequired,
}

export default InputLink
9 changes: 5 additions & 4 deletions src/containers/InputLink/index.js
Expand Up @@ -7,7 +7,8 @@ import getInputLink from '../../selectors/getInputLink'
import getIsInputLinkActive from '../../selectors/getIsInputLinkActive'
import getCanInputLinkDisable from '../../selectors/getCanInputLinkDisable'
import { uInputLinkDelete, uInputLinkCreate } from '../../store/inputLinks/actions'
import { nodeTabOpen, nodeActiveInputLinkToggle, nodeTriggerAnim } from '../../store/nodes/actions'
import { nodeTabOpen, nodeActiveInputLinkToggle } from '../../store/nodes/actions'
import { uAnimStart } from '../../store/anims/actions'

const mapStateToProps = (state, ownProps) => {
const link = getInputLink(state, ownProps.id)
Expand All @@ -20,7 +21,7 @@ const mapStateToProps = (state, ownProps) => {
isActivateVisible: getCanInputLinkDisable(state, ownProps.id),
toggleActionId: link.linkableActions.toggleActivate,
sequencerGridId: link.sequencerGridId,
animTriggerActionId: link.linkableActions.animTrigger,
animStartActionId: link.linkableActions.animStart,
}
}

Expand All @@ -35,8 +36,8 @@ const mapDispatchToProps = (dispatch, ownProps) => ({
onActivateAssignClick: () => {
dispatch(uInputLinkCreate(ownProps.id, 'midi', 'inputLinkToggle'))
},
onAnimTriggerClick: () => {
dispatch(nodeTriggerAnim(ownProps.nodeId, ownProps.id))
onAnimStartClick: () => {
dispatch(uAnimStart(ownProps.id))
},
})

Expand Down
5 changes: 5 additions & 0 deletions src/engine/index.js
Expand Up @@ -13,6 +13,7 @@ import now from 'performance-now'
import * as renderer from './renderer'
import Scene from './Scene'
import { nodeValuesBatchUpdate } from '../store/nodes/actions'
import TWEEN from '@tweenjs/tween.js'

export let scenes = {}

Expand Down Expand Up @@ -154,6 +155,10 @@ export const run = (injectedStore, stats) => {
spf = 1000 / state.settings.throttledFPS

newTime = now()

// Tween JS used for animated param values (anims)
TWEEN.update(newTime)

delta = newTime - oldTimeModified
// Elapsed frames are from the perspective of a 60FPS target
// regardless of throttling (so that throttled animations dont slow down)
Expand Down
8 changes: 8 additions & 0 deletions src/store/anims/actions.js
@@ -0,0 +1,8 @@
export function uAnimStart (linkId) {
return {
type: 'U_ANIM_START',
payload: {
linkId,
},
}
}
29 changes: 29 additions & 0 deletions src/store/anims/listener.js
@@ -0,0 +1,29 @@
import getInputLink from '../../selectors/getInputLink'
import getNode from '../../selectors/getNode'
import { nodeValueUpdate } from '../nodes/actions'
import TWEEN from '@tweenjs/tween.js'

const handleAnimStart = (action, store) => {
const state = store.getState()
const inputLink = getInputLink(state, action.payload.linkId)
const node = getNode(state, inputLink.nodeId)
const props = {
nodeValue: node.value,
}

new TWEEN.Tween(props)
.to({ nodeValue: 0.9 }, 1000)
.easing(TWEEN.Easing.Quadratic.Out)
.onUpdate(() => {
store.dispatch(nodeValueUpdate(inputLink.nodeId, props.nodeValue))
})
.start()
}

export default (action, store) => {
switch (action.type) {
case 'U_ANIM_START':
handleAnimStart(action, store)
break
}
}
9 changes: 5 additions & 4 deletions src/store/inputLinks/sagas.js
Expand Up @@ -3,8 +3,9 @@ import { getDefaultModifierIds } from './selectors'
import getInputLink from '../../selectors/getInputLink'
import getNode from '../../selectors/getNode'
import { rInputLinkCreate, rInputLinkDelete } from './actions'
import { uAnimStart } from '../anims/actions'
import { rNodeCreate, uNodeCreate, uNodeDelete, uNodeInputLinkAdd,
nodeInputLinkRemove, nodeActiveInputLinkToggle, nodeTriggerAnim } from '../nodes/actions'
nodeInputLinkRemove, nodeActiveInputLinkToggle } from '../nodes/actions'
import { inputAssignedLinkCreate, inputAssignedLinkDelete } from '../inputs/actions'
import { linkableActionCreate, linkableActionInputLinkAdd,
linkableActionInputLinkRemove, linkableActionDelete } from '../linkableActions/actions'
Expand Down Expand Up @@ -107,9 +108,9 @@ export function* inputLinkCreate (action) {
}

if (p.inputType === 'anim') {
const animTriggerActionId = yield call(uid)
yield put(linkableActionCreate(animTriggerActionId, nodeTriggerAnim(p.nodeId, linkId)))
linkableActions.animTrigger = animTriggerActionId
const animStartActionId = yield call(uid)
yield put(linkableActionCreate(animStartActionId, uAnimStart(linkId)))
linkableActions.animStart = animStartActionId
}

if (linkType === 'node') {
Expand Down
9 changes: 0 additions & 9 deletions src/store/nodes/actions.js
Expand Up @@ -158,15 +158,6 @@ export function nodeActiveInputLinkToggle (nodeId, linkId) {
}
}

export function nodeTriggerAnim (nodeId, linkId) {
return {
type: 'NODE_TRIGGER_ANIM',
payload: {
nodeId, linkId,
},
}
}

export function nodeShotFired (nodeId, sketchId, method) {
return {
type: 'NODE_SHOT_FIRED',
Expand Down
2 changes: 2 additions & 0 deletions src/store/rootListener.js
@@ -1,6 +1,7 @@
import scenesListener from './scenes/listener'
import sketchesListener from './sketches/listener'
import linkableActionsListener from './linkableActions/listener'
import animListener from './anims/listener'
import engineListener from '../engine/listener'

export default {
Expand All @@ -11,5 +12,6 @@ export default {
sketchesListener(action, store)
linkableActionsListener(action, store)
engineListener(action, store)
animListener(action, store)
},
}
4 changes: 4 additions & 0 deletions yarn.lock
Expand Up @@ -26,6 +26,10 @@
version "0.0.6"
resolved "https://registry.yarnpkg.com/7zip/-/7zip-0.0.6.tgz#9cafb171af82329490353b4816f03347aa150a30"

"@tweenjs/tween.js@^17.2.0":
version "17.2.0"
resolved "https://registry.yarnpkg.com/@tweenjs/tween.js/-/tween.js-17.2.0.tgz#21f89b709bafc4b303adae7a83b4f35a0d9e4796"

"@types/node@*":
version "4.0.35"
resolved "https://registry.yarnpkg.com/@types/node/-/node-4.0.35.tgz#2b96b8e67bea7451e6e1ba8b65eaeb8f223261ed"
Expand Down

0 comments on commit ed8c577

Please sign in to comment.