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

📦 v0.1.1 #42

Merged
merged 15 commits into from
Aug 22, 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
12 changes: 12 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Changelog

## 📦 v0.1.0 (August 21, 2019)

### Added

* 💰 - Basic economy functionality and gameplay.

### Changed

### Fixed

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "hermes-game",
"version": "0.0.0",
"version": "0.1.0",
"description": "A game about space and junk.",
"repository": {
"type": "git",
Expand Down
60 changes: 22 additions & 38 deletions src/App.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,65 +2,49 @@ import React, { useEffect } from 'react'
import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { generatePlanets } from './util'
import { setShipLocationValue, setShipLocationName } from './redux/actions/ship'
import { setPlanets } from './redux/actions/world'
import ItemTimer from './components/ItemTimer'
import View from './views/View'
import { Box } from 'grommet'
import CashDisplay from './components/CashDisplay'
import ItemTimer from './components/ItemTimer'
import Title from './components/Title'
import ViewSelector from './components/ViewSelector'
import { setShipLocationValue, setShipLocationName } from './redux/actions/ship'

const App = ({
handleInitializeShipLocation,
handleSetPlanets,
planets,
userCash
}) => {
const App = ({ handleInitializeApplication, planets }) => {
useEffect(() => {
if (planets.length === 0) {
const planets = generatePlanets()

handleSetPlanets(planets)

const homePlanet = planets.find(planet => planet.isHomePlanet === true)

const value = homePlanet.location
const name = homePlanet.name

handleInitializeShipLocation(value, name)
}

if (planets.length === 0) handleInitializeApplication()
// eslint-disable-next-line
}, [])

return (
<div>
<h1>hermes</h1>
<Box fill>
<Title />
<ItemTimer />
<h2>Cash:</h2>
<span>{userCash}</span>
<br />
<br />
<CashDisplay />
<ViewSelector />
<div>
<View />
</div>
</div>
<View />
</Box>
)
}

App.propTypes = {
handleInitializeShipLocation: PropTypes.func.isRequired,
handleSetPlanets: PropTypes.func.isRequired,
handleInitializeApplication: PropTypes.func.isRequired,
planets: PropTypes.array.isRequired
}

const mapStateToProps = ({ user, world }) => ({
planets: world.planets,
userCash: user.cash
const mapStateToProps = ({ world }) => ({
planets: world.planets
})

const mapDispatchToProps = dispatch => ({
handleSetPlanets: planets => dispatch(setPlanets(planets)),
handleInitializeShipLocation: (value, name) => {
handleInitializeApplication: () => {
const planets = generatePlanets()
const homePlanet = planets.find(planet => planet.isHomePlanet === true)
const value = homePlanet.location
const name = homePlanet.name

dispatch(setPlanets(planets))
dispatch(setShipLocationValue(value))
dispatch(setShipLocationName(name))
}
Expand Down
23 changes: 23 additions & 0 deletions src/components/CashDisplay.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react'
import PropTypes from 'prop-types'
import { Heading, Text, Box } from 'grommet'
import { connect } from 'react-redux'

const CashDisplay = ({ cash }) => {
return (
<Box margin={{ bottom: 'small' }}>
<Heading level="2" margin={{ bottom: 'xsmall' }}>
Cash:
</Heading>
<Text>{cash}</Text>
</Box>
)
}

CashDisplay.propTypes = {
cash: PropTypes.number.isRequired
}

const mapStateToProps = ({ user }) => ({ cash: user.cash })

export default connect(mapStateToProps)(CashDisplay)
8 changes: 8 additions & 0 deletions src/components/Title.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import React from 'react'
import { Heading } from 'grommet'

const Title = () => {
return <Heading level="1">Hermes</Heading>
}

export default Title
23 changes: 13 additions & 10 deletions src/components/ViewSelector.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,24 @@ import PropTypes from 'prop-types'
import { connect } from 'react-redux'
import { views } from '../constants'
import { setView } from '../redux/actions/ui'
import { Box } from 'grommet'

const ViewSelector = ({ handleSetView, view }) => {
const handleChange = e => handleSetView(e.target.value)

return (
<select onChange={handleChange}>
<option>{view}</option>
{Object.keys(views).map((viewName, i) => {
if (viewName !== view) {
return <option key={i}>{viewName}</option>
} else {
return null
}
})}
</select>
<Box width="small">
<select onChange={handleChange}>
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like there's a label missing for this input. That makes it hard for people using screen readers or voice control to use the input.

<option>{view}</option>
{Object.keys(views).map((viewName, i) => {
if (viewName !== view) {
return <option key={i}>{viewName}</option>
} else {
return null
}
})}
</select>
</Box>
)
}

Expand Down
24 changes: 12 additions & 12 deletions src/redux/actions/ship.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,32 @@
// * ACTION TYPES
const STORE_CARGO = 'STORE_CARGO'
const REMOVE_CARGO = 'REMOVE_CARGO'
const SET_SHIP_LOCATION_VALUE = 'SET_SHIP_LOCATION_VALUE'
const SET_SHIP_LOCATION_NAME = 'SET_SHIP_LOCATION_NAME'
const SET_SHIP_LOCATION_VALUE = 'SET_SHIP_LOCATION_VALUE'
const STORE_CARGO = 'STORE_CARGO'

// * ACTION GENERATORS
export const storeCargo = item => ({
type: STORE_CARGO,
payload: {
item
}
})

export const removeCargo = item => ({
type: REMOVE_CARGO,
payload: {
item
}
})

export const setShipLocationName = name => ({
type: SET_SHIP_LOCATION_NAME,
payload: { name }
})

export const setShipLocationValue = value => ({
type: SET_SHIP_LOCATION_VALUE,
payload: { value }
})

export const setShipLocationName = name => ({
type: SET_SHIP_LOCATION_NAME,
payload: { name }
export const storeCargo = item => ({
type: STORE_CARGO,
payload: {
item
}
})

// * PROMISES
Expand Down
26 changes: 13 additions & 13 deletions src/redux/actions/world.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,14 @@
// * ACTION TYPES
const SET_TIMER_RUNNING = 'SET_TIMER_RUNNING'
const REMOVE_ITEM = 'REMOVE_ITEM'
const SET_PLANETS = 'SET_PLANETS'
const CLEAR_ITEMS = 'CLEAR_ITEMS'
const REFRESH_ITEMS = 'REFRESH_ITEMS'
const REMOVE_ITEM = 'REMOVE_ITEM'
const SET_PLANETS = 'SET_PLANETS'
const SET_TIMER_RUNNING = 'SET_TIMER_RUNNING'

// * ACTION GENERATORS
export const setPlanets = planets => ({
type: SET_PLANETS,
payload: { planets }
})
export const clearItems = () => ({ type: CLEAR_ITEMS })

export const setTimerRunning = isTimerRunning => ({
type: SET_TIMER_RUNNING,
payload: { isTimerRunning }
})
export const refreshItems = () => ({ type: REFRESH_ITEMS })

export const removeItem = item => ({
type: REMOVE_ITEM,
Expand All @@ -23,9 +17,15 @@ export const removeItem = item => ({
}
})

export const clearItems = () => ({ type: CLEAR_ITEMS })
export const setPlanets = planets => ({
type: SET_PLANETS,
payload: { planets }
})

export const refreshItems = () => ({ type: REFRESH_ITEMS })
export const setTimerRunning = isTimerRunning => ({
type: SET_TIMER_RUNNING,
payload: { isTimerRunning }
})

// * PROMISES

Expand Down
18 changes: 7 additions & 11 deletions src/redux/reducers/ship.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,27 +8,23 @@ const shipDefaultState = {

export default (state = shipDefaultState, action) => {
switch (action.type) {
case 'SET_SHIP_LOCATION_VALUE':
case 'REMOVE_CARGO':
return {
...state,
location: { ...state.location, value: action.payload.value }
cargo: state.cargo.filter(item => item.id !== action.payload.item.id)
}
case 'SET_SHIP_LOCATION_NAME':
return {
...state,
location: { ...state.location, name: action.payload.name }
}
case 'SET_SHIP_LOCATION_VALUE':
return {
...state,
location: { ...state.location, value: action.payload.value }
}
case 'STORE_CARGO':
return { ...state, cargo: [...state.cargo, action.payload.item] }
case 'REMOVE_CARGO':
const itemIndex = state.cargo.findIndex(
item => item.id === action.payload.item.id
)

const newCargo = Array.from(state.cargo)
newCargo.splice(itemIndex, 1)

return { ...state, cargo: newCargo }
default:
return state
}
Expand Down
3 changes: 1 addition & 2 deletions src/redux/reducers/ui.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,7 @@ const uiDefaultState = {
export default (state = uiDefaultState, action) => {
switch (action.type) {
case 'SET_VIEW':
const { view } = action.payload
return { ...state, view }
return { ...state, view: action.payload.view }
default:
return state
}
Expand Down
54 changes: 20 additions & 34 deletions src/redux/reducers/world.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,55 +8,41 @@ const worldDefaultState = {
export default (state = worldDefaultState, action) => {
switch (action.type) {
case 'CLEAR_ITEMS':
const newPlanets = [...state.planets]

newPlanets.forEach(planet => {
planet.items = []
})

return { ...state, planets: newPlanets }
return {
...state,
planets: state.planets.map(planet => ({ ...planet, items: [] }))
}
case 'REFRESH_ITEMS':
const additionalPlanets = [...state.planets]

additionalPlanets.forEach(planet => {
planet.items = generateItems()
})

return { ...state, planets: additionalPlanets }
case 'SET_PLANETS':
const { planets } = action.payload

return { ...state, planets }
case 'SET_TIMER_RUNNING':
const { isTimerRunning } = action.payload

return { ...state, isTimerRunning }
return {
...state,
planets: state.planets.map(planet => ({
...planet,
items: generateItems(state.planets)
}))
}
case 'REMOVE_ITEM':
const { item } = action.payload

const updatedPlanets = []

state.planets.forEach(planet => {
const updatedPlanets = state.planets.map(planet => {
const { isHomePlanet, items, location, name } = planet
const planetContainsItem = items.includes(item)
if (planetContainsItem) {
const itemIndex = items.findIndex(currentItem => item === currentItem)
const newItems = Array.from(items)
newItems.splice(itemIndex, 1)

const newPlanetObj = {
if (planet.items.includes(item)) {
return {
isHomePlanet,
items: newItems,
items: items.filter(currentItem => item !== currentItem),
location,
name
}
updatedPlanets.push(newPlanetObj)
} else {
updatedPlanets.push(planet)
return planet
}
})

return { ...state, planets: updatedPlanets }
case 'SET_PLANETS':
return { ...state, planets: action.payload.planets }
case 'SET_TIMER_RUNNING':
return { ...state, isTimerRunning: action.payload.isTimerRunning }
default:
return state
}
Expand Down
Loading