-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add feature flag - add new view and insert into navigation - add purchaseForest reducer and ui event - add some strings for forest notifications - add some constants for forest sizes - add purchasable upgrade to shop
- Loading branch information
Showing
17 changed files
with
227 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
import React from 'react' | ||
|
||
import FarmhandContext from '../Farmhand/Farmhand.context' | ||
|
||
export const Forest = () => { | ||
return <div>'welcome to da forest'</div> | ||
} | ||
|
||
export default function Consumer(props) { | ||
return ( | ||
<FarmhandContext.Consumer> | ||
{({ gameState, handlers }) => ( | ||
<Forest {...{ ...gameState, ...handlers, ...props }} /> | ||
)} | ||
</FarmhandContext.Consumer> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
export { default } from './Forest' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import { moneyTotal, nullArray } from '../../utils' | ||
import { EXPERIENCE_VALUES, PURCHASABLE_FOREST_SIZES } from '../../constants' | ||
import { FOREST_EXPANDED } from '../../templates' | ||
import { FOREST_AVAILABLE_NOTIFICATION } from '../../strings' | ||
|
||
import { addExperience } from './addExperience' | ||
import { showNotification } from './showNotification' | ||
|
||
/** | ||
* @param {farmhand.state} state | ||
* @param {number} forestId | ||
* @returns {farmhand.state} | ||
*/ | ||
export const purchaseForest = (state, forestId) => { | ||
const { forest, money, purchasedForest } = state | ||
if (purchasedForest >= forestId) { | ||
return state | ||
} | ||
|
||
state = addExperience(state, EXPERIENCE_VALUES.FOREST_EXPANDED) | ||
|
||
const { columns, price, rows } = PURCHASABLE_FOREST_SIZES.get(forestId) | ||
|
||
/* | ||
* FIXME: using FOREST_AVAILABLE_NOTIFICATION here is temporary, this code path will | ||
* ultimately just be for expansion and availability will happen elsewhere, such as | ||
* through leveling up to a certain level | ||
*/ | ||
const notificationText = | ||
forestId === 1 | ||
? FOREST_AVAILABLE_NOTIFICATION | ||
: FOREST_EXPANDED`${rows * columns}` | ||
state = showNotification(state, notificationText, 'success') | ||
|
||
return { | ||
...state, | ||
purchasedForest: forestId, | ||
forest: nullArray(rows).map((_, row) => | ||
nullArray(columns).map( | ||
(_, column) => (forest[row] && forest[row][column]) || null | ||
) | ||
), | ||
money: moneyTotal(money, -price), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { testCrop } from '../../test-utils' | ||
import { EXPERIENCE_VALUES, PURCHASABLE_FOREST_SIZES } from '../../constants' | ||
import { FOREST_AVAILABLE_NOTIFICATION } from '../../strings' | ||
|
||
import { purchaseForest } from './purchaseForest' | ||
|
||
describe('purchaseForest', () => { | ||
test('updates purchasedForest', () => { | ||
const { purchasedForest } = purchaseForest({ purchasedForest: 0 }, 0) | ||
expect(purchasedForest).toEqual(0) | ||
}) | ||
|
||
test('prevents repurchasing options', () => { | ||
const { purchasedForest } = purchaseForest({ purchasedForest: 2 }, 1) | ||
expect(purchasedForest).toEqual(2) | ||
}) | ||
|
||
test('deducts money', () => { | ||
const { money } = purchaseForest( | ||
{ todaysNotifications: [], money: 101_000, forest: [[]] }, | ||
1 | ||
) | ||
expect(money).toEqual(1_000) | ||
}) | ||
|
||
test('adds experience', () => { | ||
const { experience } = purchaseForest( | ||
{ experience: 0, todaysNotifications: [], forest: [[]] }, | ||
1 | ||
) | ||
|
||
expect(experience).toEqual(EXPERIENCE_VALUES.FOREST_EXPANDED) | ||
}) | ||
|
||
test('shows notification', () => { | ||
const { todaysNotifications } = purchaseForest( | ||
{ todaysNotifications: [], forest: [[]] }, | ||
1 | ||
) | ||
|
||
expect(todaysNotifications[0].message).toEqual( | ||
FOREST_AVAILABLE_NOTIFICATION | ||
) | ||
}) | ||
|
||
describe('forest expansion', () => { | ||
test('forest expands without destroying existing data', () => { | ||
const expectedForest = [] | ||
const forestSize = PURCHASABLE_FOREST_SIZES.get(1) | ||
|
||
for (let y = 0; y < forestSize.rows; y++) { | ||
const row = [] | ||
for (let x = 0; x < forestSize.columns; x++) { | ||
row.push(null) | ||
} | ||
expectedForest.push(row) | ||
} | ||
|
||
const { forest } = purchaseForest( | ||
{ | ||
todaysNotifications: [], | ||
forest: [ | ||
[testCrop(), null], | ||
[null, testCrop()], | ||
], | ||
}, | ||
1 | ||
) | ||
|
||
expectedForest[0][0] = testCrop() | ||
expectedForest[1][1] = testCrop() | ||
|
||
expect(forest).toEqual(expectedForest) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.