Skip to content

Commit

Permalink
Prepare for v1.5.2
Browse files Browse the repository at this point in the history
  • Loading branch information
vinnymac committed Sep 20, 2016
2 parents 54b1484 + 1727872 commit 5400aee
Show file tree
Hide file tree
Showing 18 changed files with 248 additions and 139 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

## Downloads for v1.5.0
You may view all the releases [here](https://github.com/vinnymac/PokeNurse/releases)
* [Mac OS X](https://github.com/vinnymac/PokeNurse/releases/download/v1.5.0/PokeNurse-darwin-x64.zip)
* [macOS](https://github.com/vinnymac/PokeNurse/releases/download/v1.5.0/PokeNurse-darwin-x64.zip)
* [Windows 32 bit](https://github.com/vinnymac/PokeNurse/releases/download/v1.5.0/PokeNurse-win32-ia32.zip)
* [Windows 64 bit](https://github.com/vinnymac/PokeNurse/releases/download/v1.5.0/PokeNurse-win32-x64.zip)
* [Linux 32 bit](https://github.com/vinnymac/PokeNurse/releases/download/v1.5.0/PokeNurse-linux-ia32.zip)
Expand Down
7 changes: 5 additions & 2 deletions app/actions/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ import {
createAction
} from 'redux-actions'

const updateStatus = createAction('UPDATE_STATUS')
const resetStatus = createAction('RESET_STATUS')

export default {
updateStatus: createAction('UPDATE_STATUS'),
resetStatus: createAction('RESET_STATUS')
updateStatus,
resetStatus,
}
108 changes: 107 additions & 1 deletion app/actions/trainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,22 @@ import {
} from 'lodash'
import pogobuf from 'pogobuf'
import POGOProtos from 'node-pogo-protos'
import {
ipcRenderer
} from 'electron'
import moment from 'moment'

import client from '../client'

// TODO Must move these helpers to app folder
import utils from '../utils'
import baseStats from '../../baseStats'

import {
updateStatus,
resetStatus,
} from './status'

// Maybe put this info and the helper methods in utils?
const kantoDexCount = 151

Expand Down Expand Up @@ -253,6 +262,7 @@ function transferPokemon(pokemon, delay) {
dispatch(transferPokemonSuccess(pokemon))
} catch (error) {
dispatch(transferPokemonFailed(error))
throw error
}
}
}
Expand All @@ -265,12 +275,106 @@ function evolvePokemon(pokemon, delay) {
dispatch(evolvePokemonSuccess(pokemon))
} catch (error) {
dispatch(evolvePokemonFailed(error))
throw error
}
}
}

function promiseChainFromArray(array, iterator) {
let promise = Promise.resolve()

array.forEach((value, index) => {
promise = promise.then(() => iterator(value, index))
})

return promise
}

function randomDelay([min, max]) {
return Math.round((min + Math.random() * (max - min)) * 1000)
}

function average(arr) {
const sum = arr.reduce((result, currentValue) =>
result + currentValue
, 0)

return sum / arr.length
}

const updateMonster = createAction('UPDATE_MONSTER')

function processSelectedPokemon(selectedPokemon, method, action, time, delayRange, done) {
return async (dispatch) => {
dispatch(updateStatus({
selectedPokemon,
method,
time,
}))

let startTime = moment()
const responseTimesInSeconds = []

promiseChainFromArray(selectedPokemon, (pokemon, index) =>
dispatch(action(pokemon, index * randomDelay(delayRange)))
.then(() => {
let statusUpdates = { current: pokemon }

// Calculate the Estimated Time in Seconds Left
const requestLatencyInSeconds = moment().diff(startTime, 'seconds')
startTime = moment()

if (requestLatencyInSeconds > 0) {
responseTimesInSeconds.push(requestLatencyInSeconds)
const averageRequestLatencyInSeconds = average(responseTimesInSeconds)

const numberOfJobsLeft = selectedPokemon.length - (index + 1)
const estimatedSecondsLeft = numberOfJobsLeft * averageRequestLatencyInSeconds

statusUpdates = Object.assign({}, statusUpdates, { time: estimatedSecondsLeft })
}

dispatch(updateStatus(statusUpdates))

dispatch(updateMonster({
pokemon,
options: { remove: true }
}))
})
).then(() => {
done()
ipcRenderer.send('information-dialog', 'Complete!', `Finished ${method}`)
dispatch(resetStatus())
dispatch(getTrainerPokemon())
}).catch(error => {
done()
ipcRenderer.send('error-message', `Error while running ${method.toLowerCase()}:\n\n${error}`)
dispatch(resetStatus())
dispatch(getTrainerPokemon())
})
}
}

function transferSelectedPokemon(selectedPokemon, done) {
const method = 'Transfer'
const time = selectedPokemon.length * 2.5
const delayRange = [2, 3]
const action = transferPokemon

return processSelectedPokemon(selectedPokemon, method, action, time, delayRange, done)
}

function evolveSelectedPokemon(selectedPokemon, done) {
const method = 'Evolve'
const time = selectedPokemon.length * 27.5
const delayRange = [25, 30]
const action = evolvePokemon

return processSelectedPokemon(selectedPokemon, method, action, time, delayRange, done)
}

export default {
updateMonster: createAction('UPDATE_MONSTER'),
updateMonster,
updateSpecies: createAction('UPDATE_SPECIES'),
updateMonsterSort: createAction('UPDATE_MONSTER_SORT'),
sortSpecies: createAction('SORT_SPECIES'),
Expand All @@ -286,4 +390,6 @@ export default {
renamePokemon,
transferPokemon,
evolvePokemon,
evolveSelectedPokemon,
transferSelectedPokemon,
}
19 changes: 18 additions & 1 deletion app/css/pokenurse.css
Original file line number Diff line number Diff line change
Expand Up @@ -38,24 +38,41 @@
.bm-item-list ul {
float: none;
display: block;
list-style: none;
width: 100%;
}
.bm-menu .bm-item-list li {
float: none;
display: block;
padding: 5px 0px;
border-bottom: 1px solid #b8b7ad;
border-top: 1px solid #b8b7ad;
width: 100%;
}
.bm-menu .bm-item-list li:first-of-type, li:last-of-type {
border-top: none;
}

.bm-menu .bm-item-list li a {
padding: 5px 0px;
cursor: pointer;
color: #9d9d9d;
text-decoration: none;
line-height: 20px;
}

.bm-menu .bm-item-list li a:hover, a:active {
color: white;
}

.bm-menu .bm-item-list i {
padding-top: 5px;
float: right;
}

.bm-menu .bm-item-list .submenu li {
background-color: rgba(35, 35, 35, 0.4);
}

/* Morph shape necessary with bubble or elastic */
.bm-morph-shape {
fill: #373a47;
Expand Down
Binary file added app/imgs/egg.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
1 change: 0 additions & 1 deletion app/reducers/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ const initialState = {
current: null,
time: 0,
method: '',
finished: null
}

export default handleActions({
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const SelectedPokemon = React.createClass({
</tr>
</thead>
<tbody>
{ this.buildRows(pokemon) }
{ this.buildRows(pokemon) }
</tbody>
</table>
</div>
Expand Down
29 changes: 29 additions & 0 deletions app/screens/Menu/components/Eggs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import React, {
PropTypes
} from 'react'

const Eggs = React.createClass({
propTypes: {
eggList: PropTypes.array,
},

render() {
const {
eggList
} = this.props

const eggs = eggList.map((e, i) =>
<li key={i}>
{e.egg_km_walked_start}.0 / {e.egg_km_walked_target}.0 km
</li>
)

return (
<ul className="nav navbar-nav submenu">
{eggs}
</ul>
)
}
})

export default Eggs
17 changes: 14 additions & 3 deletions app/screens/Menu/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,26 +9,37 @@ import {
logout
} from '../../actions'
import renderSettings from '../Settings'
// import Eggs from './components/Eggs'

const Menu = require('react-burger-menu').slide

const MainMenu = React.createClass({
propTypes: {
updateStatus: PropTypes.func.isRequired,
logout: PropTypes.func.isRequired
logout: PropTypes.func.isRequired,
eggs: PropTypes.array,
},

render() {
// const {
// eggs
// } = this.props

return (
<Menu>
<div>
<ul className="nav navbar-nav">
<li><a onClick={this.handleClickSettings}>Settings <i className="glyphicon glyphicon-cog" /></a></li>
{
// <li><a>Trainer Info <i className="glyphicon glyphicon-user" /></a></li>
// <li><a>Applied Items <i className="glyphicon glyphicon-chevron-down" /></a></li>
// <li>
// <a>
// Eggs <i className="glyphicon glyphicon-chevron-down" />
// </a>
// <Eggs eggList={eggs} />
// </li>
// <li><a>Trainer Info <i className="glyphicon glyphicon-user" /></a></li>
// <li><a>Inventory <i className="glyphicon glyphicon-chevron-down" /></a></li>
// <li><a>Eggs <i className="glyphicon glyphicon-chevron-down" /></a></li>
}
<li><a onClick={this.handleSignOut}>Sign Out <i className="glyphicon glyphicon-off" /></a></li>
</ul>
Expand Down
4 changes: 2 additions & 2 deletions app/screens/Table/components/Species.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,10 +45,10 @@ const Species = React.createClass({
<div className="col-md-12">
<table className="table table-condensed table-hover display no-footer">
<thead>
{this.getSpeciesHeader()}
{this.getSpeciesHeader()}
</thead>
<tbody>
{this.getSpeciesBody(monsters.species)}
{this.getSpeciesBody(monsters.species)}
</tbody>
</table>
</div>
Expand Down
2 changes: 1 addition & 1 deletion app/screens/Table/components/SpeciesPokemonCounter.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ const SpeciesPokemonCounter = React.createClass({
return (
<span>
<span>
Species: {this.handleSpeciesRecount(monsters)}
Species: {this.handleSpeciesRecount(monsters)}
</span>
{' | '}
<span>
Expand Down
32 changes: 1 addition & 31 deletions app/screens/Table/components/Status.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,14 @@ import React, {
import {
connect
} from 'react-redux'
import { bindActionCreators } from 'redux'

import Progress from './Progress'

import { updateStatus, resetStatus } from '../../../actions'

const Status = React.createClass({
displayName: 'Status',

propTypes: {
status: PropTypes.object,
resetStatus: PropTypes.func.isRequired,
updateStatus: PropTypes.func.isRequired
},

componentDidUpdate(prevProps) {
// TODO add thunks and move interval to redux action creators
if (!prevProps.status.current && this.props.status.current) {
this.countDownInterval()
}
},

render() {
Expand Down Expand Up @@ -52,26 +40,8 @@ const Status = React.createClass({
</div>
)
},

countDownInterval() {
let { time } = this.props.status

const { finished } = this.props.status

const interval = setInterval(() => {
this.props.updateStatus({ time: time-- })

if (time <= 0) {
clearInterval(interval)
finished()
this.props.resetStatus()
}
}, 1000)
}
})

export default connect(state => ({
status: state.status
}), (dispatch => bindActionCreators({
updateStatus, resetStatus
}, dispatch)))(Status)
}), null)(Status)
Loading

0 comments on commit 5400aee

Please sign in to comment.