Skip to content

Commit

Permalink
Load plugin from CDN
Browse files Browse the repository at this point in the history
  • Loading branch information
oskarrough committed Dec 17, 2020
1 parent 092109c commit bcb5563
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 28 deletions.
45 changes: 25 additions & 20 deletions public/ui/animations.js
Original file line number Diff line number Diff line change
@@ -1,13 +1,17 @@
import gsap from './../web_modules/gsap.js'
import {Draggable} from './../web_modules/gsap/Draggable.js'
import {Flip} from './../web_modules/gsap/Flip.js'
// import {Flip} from './../web_modules/gsap/Flip.js'
import Flip from 'https://slaytheweb-assets.netlify.app/gsap/Flip.js'

// This file contains some resuable animations/effects.
// https://greensock.com/cheatsheet/

// Don't forget to register plugins.
gsap.registerPlugin(Draggable)
gsap.registerPlugin(Flip)

if (typeof Flip !== 'undefined') {
gsap.registerPlugin(Flip)
}

// Fly in the cards from the left (draw pile) to your hand.
gsap.registerEffect({
Expand Down Expand Up @@ -69,24 +73,25 @@ gsap.registerEffect({
name: 'playCard',
effect: (targets, config) => {
const tl = gsap.timeline()
return tl.to(targets, {
duration: 0.6,
y: '-=100',
// x: 0,
rotation: 50,
scale: 0.8,
ease: 'power3.out',
onComplete: config.onComplete,
})
.to(targets, {
delay: -0.3,
duration: 0.8,
scale: 0.5,
rotation: 90,
x: window.innerWidth,
y: window.innerHeight,
ease: 'power3.inOut',
})
return tl
.to(targets, {
duration: 0.6,
y: '-=100',
// x: 0,
rotation: 50,
scale: 0.8,
ease: 'power3.out',
onComplete: config.onComplete,
})
.to(targets, {
delay: -0.3,
duration: 0.8,
scale: 0.5,
rotation: 90,
x: window.innerWidth,
y: window.innerHeight,
ease: 'power3.inOut',
})
},
})

Expand Down
26 changes: 18 additions & 8 deletions public/ui/app.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Third party dependencies
import {html, Component} from '../../web_modules/htm/preact/standalone.module.js'
import gsap from './animations.js'
import {Flip} from './../web_modules/gsap/Flip.js'
import Flip from 'https://slaytheweb-assets.netlify.app/gsap/Flip.js'

// Game logic
import createNewGame from '../game/index.js'
Expand Down Expand Up @@ -70,25 +70,35 @@ stw.dealCards()
// Play the card.
const card = this.state.hand.find((c) => c.id === cardId)
this.game.enqueue({type: 'playCard', card, target})

const supportsFlip = typeof Flip !== 'undefined'
let flip

// For the hand animation later.
const flip = Flip.getState('.Hand .Card')
if (supportsFlip) flip = Flip.getState('.Hand .Card')

// Create a clone on top of the card to animate.
const clone = cardElement.cloneNode(true)
document.body.appendChild(clone)
Flip.fit(clone, cardElement, {absolute: true})
if (supportsFlip) Flip.fit(clone, cardElement, {absolute: true})

// Update state and re-enable dragdrop
this.update(() => {
enableDragDrop(this.base, this.playCard)

// Animate cloned card away
gsap.effects.playCard(clone).then(() => {
clone.parentNode.removeChild(clone)
})

// Reposition hand
Flip.from(flip, {
duration: 0.3,
ease: 'power3.inOut',
absolute: true
})
if (supportsFlip) {
Flip.from(flip, {
duration: 0.3,
ease: 'power3.inOut',
absolute: true,
})
}
})
}
endTurn() {
Expand Down

0 comments on commit bcb5563

Please sign in to comment.