Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🚀 Ship Arrival #168

Merged
merged 1 commit into from
Sep 28, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion cypress/integration/Map-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,10 @@ describe('Map', () => {
})

it('Should travel to a planet.', () => {
const stub = cy.stub()

cy.on('window:alert', stub)

const destinationPlanet = mockState.world.planets.find(
planet => planet.name !== mockState.ship.location.name
)
Expand All @@ -66,6 +70,10 @@ describe('Map', () => {
cy.wait(1000)
cy.get('body').contains(`Warping to ${destinationPlanet.name}...`)
cy.wait(11000)
cy.get('body').contains('Warp complete!')
cy.get('body')
.contains('Warp complete!')
.then(() => {
expect(stub.getCall(0)).to.be.calledWith(destinationPlanet.name)
})
})
})
2 changes: 1 addition & 1 deletion src/components/TravelPrompt.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ const mapStateToProps = () => ({})

const mapDispatchToProps = dispatch => ({
handleTravel: (destination, setOpen) => {
hidePlanets(destination)
hidePlanets(destination, dispatch)
// dispatch(instantTravel(destination))
setOpen(false)
}
Expand Down
10 changes: 7 additions & 3 deletions src/util/map.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import * as d3 from 'd3'
import { setShipLocation } from '../redux/actions/ship'

const radius = 23
const fill = '#1976d2'
Expand Down Expand Up @@ -210,21 +211,21 @@ export const getHeight = selector =>

export const getWidth = selector => d3.select(selector).property('clientWidth')

export const hidePlanets = destination => {
export const hidePlanets = (destination, dispatch) => {
d3.selectAll('g').style('pointer-events', 'none')
let value = 1.0
const interval = setInterval(() => {
if (value <= 0) {
clearInterval(interval)
d3.selectAll('g').remove()
showWarpingTo(destination)
showWarpingTo(destination, dispatch)
}
d3.selectAll('g').style('opacity', value - 0.05)
value -= 0.05
}, 100)
}

const showWarpingTo = destination => {
const showWarpingTo = (destination, dispatch) => {
const svg = d3.select('#map-root > svg')
const height = getHeight('#map-root > svg')
const width = getWidth('#map-root > svg')
Expand All @@ -242,5 +243,8 @@ const showWarpingTo = destination => {
.text('Warp complete!')
.attr('x', () => width / 2 - getLabelWidth(svg, `#warping-to`) / 2)
.attr('y', height / 2)

dispatch(setShipLocation(destination))
alert(destination.name)
}, 10000)
}