Skip to content

Commit

Permalink
Merge minor commit
Browse files Browse the repository at this point in the history
  • Loading branch information
github-actions[bot] committed Sep 8, 2023
2 parents 11eda7f + 51ab78f commit 91a9c63
Show file tree
Hide file tree
Showing 35 changed files with 438 additions and 1,466 deletions.
1,258 changes: 14 additions & 1,244 deletions package-lock.json

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@jeremyckahn/farmhand",
"version": "1.17.6",
"version": "1.18.0",
"publishConfig": {
"access": "public"
},
Expand Down
24 changes: 14 additions & 10 deletions src/components/Farmhand/Farmhand.js
Original file line number Diff line number Diff line change
Expand Up @@ -56,17 +56,16 @@ import NotificationSystem, {
} from '../NotificationSystem'
import DebugMenu from '../DebugMenu'
import theme from '../../mui-theme'
import { levelAchieved } from '../../utils/levelAchieved'
import {
computeMarketPositions,
createNewField,
doesMenuObstructStage,
farmProductsSold,
generateCow,
getAvailableShopInventory,
getItemCurrentValue,
getPeerMetadata,
inventorySpaceRemaining,
levelAchieved,
moneyTotal,
nullArray,
reduceByPersistedKeys,
Expand Down Expand Up @@ -208,14 +207,15 @@ const applyPriceEvents = (valueAdjustments, priceCrashes, priceSurges) => {
* totals of crops harvested. Keys are crop type IDs, values are the number of
* that crop harvested.
* @property {number} dayCount
* @property {number} experience
* @property {string} farmName
* @property {boolean} hasBooted
* @property {(?farmhand.plotContent)[][]} field
* @property {farmhand.fieldMode} fieldMode
* @property {Function?} getCowAccept https://github.com/dmotz/trystero#receiver
* @property {Function?} getCowReject https://github.com/dmotz/trystero#receiver
* @property {Function?} getCowTradeRequest https://github.com/dmotz/trystero#receiver
* @property {Function?} getPeerMetadata https://github.com/dmotz/trystero#receiver
* @property {boolean} hasBooted
* @property {number?} heartbeatTimeoutId
* @property {Array.<number>} historicalDailyLosses
* @property {Array.<number>} historicalDailyRevenue
Expand Down Expand Up @@ -380,9 +380,7 @@ export default class Farmhand extends FarmhandReducers {
}

get levelEntitlements() {
return getLevelEntitlements(
levelAchieved(farmProductsSold(this.state.itemsSold))
)
return getLevelEntitlements(levelAchieved(this.state.experience))
}

get shopInventory() {
Expand Down Expand Up @@ -425,6 +423,7 @@ export default class Farmhand extends FarmhandReducers {
cowTradeTimeoutId: -1,
cropsHarvested: {},
dayCount: 0,
experience: 0,
farmName: 'Unnamed',
field: createNewField(),
fieldMode: OBSERVE,
Expand Down Expand Up @@ -502,6 +501,14 @@ export default class Farmhand extends FarmhandReducers {
}
}

async initializeNewGame() {
await this.incrementDay(true)
this.setState(() => ({
historicalValueAdjustments: [],
}))
this.showNotification(LOAN_INCREASED`${STANDARD_LOAN_AMOUNT}`, 'info')
}

initInputHandlers() {
const debouncedInputRate = 50

Expand Down Expand Up @@ -601,10 +608,7 @@ export default class Farmhand extends FarmhandReducers {
})
})
} else {
// Initialize new game
await this.incrementDay(true)
this.setState(() => ({ historicalValueAdjustments: [] }))
this.showNotification(LOAN_INCREASED`${STANDARD_LOAN_AMOUNT}`, 'info')
await this.initializeNewGame()
}

this.syncToRoom().catch(errorCode => this.handleRoomSyncError(errorCode))
Expand Down
22 changes: 9 additions & 13 deletions src/components/Field/Field.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,8 @@ import Plot from '../Plot'
import QuickSelect from '../QuickSelect'
import { fieldMode } from '../../enums'
import tools from '../../data/tools'
import {
doesInventorySpaceRemain,
farmProductsSold,
levelAchieved,
nullArray,
} from '../../utils'
import { levelAchieved } from '../../utils/levelAchieved'
import { doesInventorySpaceRemain, nullArray } from '../../utils'
import { getLevelEntitlements } from '../../utils/getLevelEntitlements'

import './Field.sass'
Expand Down Expand Up @@ -56,10 +52,10 @@ if (tools.shovel) {
}

export const isInHoverRange = ({
experience,
fieldMode,
hoveredPlotRangeSize,
hoveredPlot: { x: hoveredPlotX, y: hoveredPlotY },
itemsSold,
x,
y,
}) => {
Expand All @@ -74,7 +70,7 @@ export const isInHoverRange = ({
switch (fieldMode) {
case SET_SPRINKLER:
hoveredPlotRangeSizeToRender = getLevelEntitlements(
levelAchieved(farmProductsSold(itemsSold))
levelAchieved(experience)
).sprinklerRange

break
Expand Down Expand Up @@ -131,10 +127,10 @@ export const MemoPlot = memo(
)

MemoPlot.propTypes = {
experience: number.isRequired,
fieldMode: string.isRequired,
hoveredPlot: object.isRequired,
hoveredPlotRangeSize: number.isRequired,
itemsSold: object.isRequired,
plotContent: object,
setHoveredPlot: func.isRequired,
x: number.isRequired,
Expand Down Expand Up @@ -214,13 +210,13 @@ FieldContentWrapper.propTypes = {

export const FieldContent = ({
columns,
experience,
field,
fieldMode,
handleCombineEnabledChange,
hoveredPlot,
hoveredPlotRangeSize,
isCombineEnabled,
itemsSold,
purchasedCombine,
rows,
setHoveredPlot,
Expand All @@ -239,10 +235,10 @@ export const FieldContent = ({
<MemoPlot
key={x}
{...{
experience,
fieldMode,
hoveredPlot,
hoveredPlotRangeSize,
itemsSold,
plotContent,
setHoveredPlot,
x,
Expand Down Expand Up @@ -276,13 +272,13 @@ export const FieldContent = ({

FieldContent.propTypes = {
columns: number.isRequired,
experience: number.isRequired,
field: array.isRequired,
fieldMode: string.isRequired,
handleCombineEnabledChange: func.isRequired,
hoveredPlot: object.isRequired,
hoveredPlotRangeSize: number.isRequired,
isCombineEnabled: bool.isRequired,
itemsSold: object.isRequired,
purchasedCombine: number.isRequired,
rows: number.isRequired,
setHoveredPlot: func.isRequired,
Expand Down Expand Up @@ -425,6 +421,7 @@ export const Field = props => {

Field.propTypes = {
columns: number.isRequired,
experience: number.isRequired,
field: array.isRequired,
fieldMode: string.isRequired,
handleCombineEnabledChange: func.isRequired,
Expand All @@ -433,7 +430,6 @@ Field.propTypes = {
inventory: array.isRequired,
inventoryLimit: number.isRequired,
isCombineEnabled: bool.isRequired,
itemsSold: object.isRequired,
purchasedCombine: number.isRequired,
purchasedField: number.isRequired,
rows: number.isRequired,
Expand Down
20 changes: 10 additions & 10 deletions src/components/Field/Field.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@ beforeEach(() => {
<Field
{...{
columns: 0,
experience: 0,
hoveredPlotRangeSize: 0,
handleCombineEnabledChange: noop,
handleFieldActionRangeChange: noop,
itemsSold: {},
rows: 0,
field: [
[null, null],
Expand All @@ -49,6 +49,7 @@ describe('field rendering', () => {
<FieldContent
{...{
columns: 0,
experience: 1,
handleCombineEnabledChange: noop,
field: [
[null, null],
Expand All @@ -59,7 +60,6 @@ describe('field rendering', () => {
hoveredPlotRangeSize: 0,
fieldMode: fieldMode.OBSERVE,
isCombineEnabled: false,
itemsSold: {},
purchasedCombine: 0,
rows: 0,
setHoveredPlot: noop,
Expand Down Expand Up @@ -162,9 +162,9 @@ describe('isInHoverRange', () => {
test('indicates when plot is not in hover range', () => {
expect(
isInHoverRange({
experience: 0,
hoveredPlotRangeSize: 2,
hoveredPlot: { x: 1, y: 1 },
itemsSold: {},
x: 4,
y: 4,
})
Expand All @@ -174,9 +174,9 @@ describe('isInHoverRange', () => {
test('indicates when plot is in hover range', () => {
expect(
isInHoverRange({
experience: 0,
hoveredPlotRangeSize: 2,
hoveredPlot: { x: 1, y: 1 },
itemsSold: {},
x: 0,
y: 0,
})
Expand All @@ -187,10 +187,10 @@ describe('isInHoverRange', () => {
test('indicates when plot is not in hover range', () => {
expect(
isInHoverRange({
experience: 0,
hoveredPlotRangeSize: 2,
hoveredPlot: { x: 1, y: 1 },
fieldMode: fieldMode.OBSERVE,
itemsSold: {},
x: 4,
y: 4,
})
Expand All @@ -200,10 +200,10 @@ describe('isInHoverRange', () => {
test('indicates when plot is in hover range', () => {
expect(
isInHoverRange({
experience: 0,
hoveredPlotRangeSize: 2,
hoveredPlot: { x: 1, y: 1 },
fieldMode: fieldMode.OBSERVE,
itemsSold: {},
x: 0,
y: 0,
})
Expand All @@ -215,10 +215,10 @@ describe('isInHoverRange', () => {
test('indicates when plot is not in hover range', () => {
expect(
isInHoverRange({
experience: 0,
hoveredPlotRangeSize: 2,
hoveredPlot: { x: 1, y: 1 },
fieldMode: fieldMode.SET_SPRINKLER,
itemsSold: {},
x: 4,
y: 4,
})
Expand All @@ -228,10 +228,10 @@ describe('isInHoverRange', () => {
test('indicates when plot is in hover range', () => {
expect(
isInHoverRange({
experience: 0,
hoveredPlotRangeSize: 2,
hoveredPlot: { x: 1, y: 1 },
fieldMode: fieldMode.SET_SPRINKLER,
itemsSold: {},
x: 0,
y: 0,
})
Expand All @@ -243,21 +243,21 @@ describe('isInHoverRange', () => {
test('indicates that all plots are in hover range', () => {
expect(
isInHoverRange({
experience: 0,
hoveredPlotRangeSize: 2,
hoveredPlot: { x: 1, y: 1 },
fieldMode: fieldMode.SET_SCARECROW,
itemsSold: {},
x: 2,
y: 2,
})
).toBe(true)

expect(
isInHoverRange({
experience: 0,
hoveredPlotRangeSize: 2,
hoveredPlot: { x: 1, y: 1 },
fieldMode: fieldMode.SET_SCARECROW,
itemsSold: {},
x: 100,
y: 100,
})
Expand Down
74 changes: 74 additions & 0 deletions src/components/Navigation/DayAndProgressContainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
import React from 'react'
import { number, object } from 'prop-types'

import Box from '@material-ui/core/Box'
import CircularProgress from '@material-ui/core/CircularProgress'
import Tooltip from '@material-ui/core/Tooltip'

import FarmhandContext from '../Farmhand/Farmhand.context'

import { levelAchieved } from '../../utils/levelAchieved'
import {
experienceNeededForLevel,
integerString,
scaleNumber,
} from '../../utils'

export function DayAndProgressContainer({ dayCount, experience, itemsSold }) {
const currentLevel = levelAchieved(experience)

const levelPercent = scaleNumber(
experience,
experienceNeededForLevel(currentLevel),
experienceNeededForLevel(currentLevel + 1),
0,
100
)

const tooltipText = `${integerString(
experienceNeededForLevel(currentLevel + 1) - experience
)} more experience points needed to reach level ${integerString(
currentLevel + 1
)}`

return (
<h2 className="day-and-progress-container">
<span>Day {integerString(dayCount)}, level:</span>
<Tooltip
{...{
arrow: true,
placement: 'top',
title: tooltipText,
}}
>
<Box>
<CircularProgress
{...{
value: levelPercent,
variant: 'determinate',
}}
/>
<span {...{ className: 'current-level' }}>
{integerString(currentLevel)}
</span>
</Box>
</Tooltip>
</h2>
)
}

DayAndProgressContainer.propTypes = {
dayCount: number.isRequired,
experience: number.isRequired,
itemsSold: object.isRequired,
}

export default function Consumer(props) {
return (
<FarmhandContext.Consumer>
{({ gameState, handlers }) => (
<DayAndProgressContainer {...{ ...gameState, ...handlers, ...props }} />
)}
</FarmhandContext.Consumer>
)
}
Loading

1 comment on commit 91a9c63

@vercel
Copy link

@vercel vercel bot commented on 91a9c63 Sep 8, 2023

Choose a reason for hiding this comment

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

Please sign in to comment.