Skip to content

Commit

Permalink
feat: add the ability for crops to have more than 1 growing phase (#473)
Browse files Browse the repository at this point in the history
this change converts the `cropTimetable` property into a `cropTimeline` which allows for each crop to have a varying number of growing phases, each represented by a different image. the majority of crops have been updated with new art to take advantage of this new capability. 

this commit also has several updates to fix type warnings, and improve tests that were mocking crops and constants where it was not necessary.

* refactor(types): fix all type errors for utils/index.js

---------

Co-authored-by: Jeremy Kahn <[email protected]>
  • Loading branch information
lstebner and jeremyckahn authored Jan 16, 2024
1 parent a830c8f commit 71f7840
Show file tree
Hide file tree
Showing 171 changed files with 402 additions and 342 deletions.
11 changes: 11 additions & 0 deletions src/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
* @ignore
*/

/**
* @typedef {import('./index').farmhand.purchaseableFieldSize} farmhand.purchaseableFieldSize
*/

import { cowColors, fieldMode, stageFocusType, toolLevel } from './enums'

const { freeze } = Object
Expand Down Expand Up @@ -34,6 +38,9 @@ export const STORAGE_EXPANSION_SCALE_PREMIUM = 50
export const INITIAL_FIELD_WIDTH = 6
export const INITIAL_FIELD_HEIGHT = 10

/**
* @type Map<number, farmhand.purchaseableFieldSize>
*/
export const PURCHASEABLE_FIELD_SIZES = freeze(
new Map([
[1, { columns: 8, rows: 12, price: 1_000 }],
Expand All @@ -42,6 +49,10 @@ export const PURCHASEABLE_FIELD_SIZES = freeze(
])
)

export const LARGEST_PURCHASABLE_FIELD_SIZE = /** @type {farmhand.purchaseableFieldSize} */ (PURCHASEABLE_FIELD_SIZES.get(
PURCHASEABLE_FIELD_SIZES.size
))

export const PURCHASEABLE_COMBINES = freeze(
new Map([[1, { type: 'Basic', price: 500_000 }]])
)
Expand Down
19 changes: 4 additions & 15 deletions src/data/__mocks__/items.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
import { testItem } from '../../test-utils'
import { cropLifeStage, itemType } from '../../enums'

const { SEED, GROWING } = cropLifeStage
import { itemType } from '../../enums'

// Patch the original items data into the mock. This has the potential to break
// with future versions of Webpack (keep an eye on
Expand Down Expand Up @@ -87,10 +85,7 @@ export const sampleCropItem1 = testItem({
name: 'Sample Crop Item 1',
type: itemType.CROP,
value: 2,
cropTimetable: {
[SEED]: 1,
[GROWING]: 2,
},
cropTimeline: [1, 2],
})

export const sampleCropSeedsItem2 = testItem({
Expand All @@ -111,10 +106,7 @@ export const sampleCropItem2 = testItem({
name: 'Sample Crop Item 2',
type: itemType.CROP,
value: 3,
cropTimetable: {
[SEED]: 2,
[GROWING]: 3,
},
cropTimeline: [2, 3],
})

export const sampleCropSeedsItem3 = testItem({
Expand All @@ -134,10 +126,7 @@ export const sampleCropItem3 = testItem({
name: 'Sample Crop Item 3',
type: itemType.CROP,
value: 4,
cropTimetable: {
[SEED]: 5,
[GROWING]: 5,
},
cropTimeline: [5, 5],
})

export const sampleFieldTool1 = testItem({
Expand Down
12 changes: 6 additions & 6 deletions src/data/crop.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,17 @@ const { freeze } = Object
* @returns {farmhand.item}
*/
export const crop = ({
cropTimetable,
cropTimeline,
growsInto,
tier,

isSeed = Boolean(growsInto),
cropLifecycleDuration = getCropLifecycleDuration({ cropTimetable }),
cropLifecycleDuration = getCropLifecycleDuration({ cropTimeline }),

...rest
}) =>
freeze({
cropTimetable,
cropTimeline,
doesPriceFluctuate: true,
tier,
type: itemType.CROP,
Expand All @@ -41,20 +41,20 @@ export const crop = ({
* @returns {farmhand.item}
*/
export const fromSeed = (
{ cropTimetable, cropType, growsInto, tier },
{ cropTimeline, cropType, growsInto, tier },
{ variantIdx = 0, canBeFermented = false } = {}
) => {
const variants = Array.isArray(growsInto) ? growsInto : [growsInto]

return {
cropTimetable,
cropTimeline,
cropType,
doesPriceFluctuate: true,
id: variants[variantIdx],
tier,
type: itemType.CROP,
...(canBeFermented && {
daysToFerment: getCropLifecycleDuration({ cropTimetable }) * tier,
daysToFerment: getCropLifecycleDuration({ cropTimeline }) * tier,
}),
}
}
11 changes: 4 additions & 7 deletions src/data/crops/asparagus.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import { crop, fromSeed } from '../crop'
import { cropLifeStage, cropType } from '../../enums'
/** @typedef {import('../../components/Farmhand/Farmhand').farmhand.item} farmhand.item */

const { SEED, GROWING } = cropLifeStage
import { crop, fromSeed } from '../crop'
import { cropType } from '../../enums'

/**
* @property farmhand.module:items.asparagusSeed
* @type {farmhand.item}
*/
export const asparagusSeed = crop({
cropType: cropType.ASPARAGUS,
cropTimetable: {
[SEED]: 4,
[GROWING]: 5,
},
cropTimeline: [4, 2, 2, 1],
growsInto: 'asparagus',
id: 'asparagus-seed',
name: 'Asparagus Seed',
Expand Down
9 changes: 2 additions & 7 deletions src/data/crops/carrot.js
Original file line number Diff line number Diff line change
@@ -1,20 +1,15 @@
/** @typedef {import("../../index").farmhand.item} item */

import { crop, fromSeed } from '../crop'
import { cropLifeStage, cropType } from '../../enums'

const { SEED, GROWING } = cropLifeStage
import { cropType } from '../../enums'

/**
* @property farmhand.module:items.carrotSeed
* @type {item}
*/
export const carrotSeed = crop({
cropType: cropType.CARROT,
cropTimetable: {
[SEED]: 2,
[GROWING]: 3,
},
cropTimeline: [2, 1, 1, 1],
growsInto: 'carrot',
id: 'carrot-seed',
name: 'Carrot Seed',
Expand Down
11 changes: 4 additions & 7 deletions src/data/crops/corn.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import { crop, fromSeed } from '../crop'
import { cropLifeStage, cropType } from '../../enums'
/** @typedef {import('../../components/Farmhand/Farmhand').farmhand.item} farmhand.item */

const { SEED, GROWING } = cropLifeStage
import { crop, fromSeed } from '../crop'
import { cropType } from '../../enums'

/**
* @property farmhand.module:items.cornSeed
* @type {farmhand.item}
*/
export const cornSeed = crop({
cropType: cropType.CORN,
cropTimetable: {
[SEED]: 3,
[GROWING]: 7,
},
cropTimeline: [3, 1, 1, 1, 2, 2],
growsInto: 'corn',
id: 'corn-seed',
name: 'Corn Kernels',
Expand Down
11 changes: 4 additions & 7 deletions src/data/crops/garlic.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import { crop, fromSeed } from '../crop'
import { cropLifeStage, cropType } from '../../enums'
/** @typedef {import('../../components/Farmhand/Farmhand').farmhand.item} farmhand.item */

const { SEED, GROWING } = cropLifeStage
import { crop, fromSeed } from '../crop'
import { cropType } from '../../enums'

/**
* @property farmhand.module:items.garlicSeed
* @type {farmhand.item}
*/
export const garlicSeed = crop({
cropType: cropType.GARLIC,
cropTimetable: {
[SEED]: 2,
[GROWING]: 3,
},
cropTimeline: [2, 1, 1, 1],
growsInto: 'garlic',
id: 'garlic-seed',
name: 'Garlic Bulb',
Expand Down
9 changes: 2 additions & 7 deletions src/data/crops/grape.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,15 @@
/** @typedef {import("../../index").farmhand.cropVariety} farmhand.cropVariety */

import { crop, fromSeed } from '../crop'
import { cropLifeStage, cropType } from '../../enums'

const { SEED, GROWING } = cropLifeStage
import { cropType } from '../../enums'

/**
* @property farmhand.module:items.grapeSeed
* @type {farmhand.item}
*/
export const grapeSeed = crop({
cropType: cropType.GRAPE,
cropTimetable: {
[SEED]: 3,
[GROWING]: 4,
},
cropTimeline: [3, 4],
growsInto: [
'grape-chardonnay',
'grape-sauvignon-blanc',
Expand Down
11 changes: 4 additions & 7 deletions src/data/crops/jalapeno.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import { crop, fromSeed } from '../crop'
import { cropLifeStage, cropType } from '../../enums'
/** @typedef {import('../../components/Farmhand/Farmhand').farmhand.item} farmhand.item */

const { SEED, GROWING } = cropLifeStage
import { crop, fromSeed } from '../crop'
import { cropType } from '../../enums'

/**
* @property farmhand.module:items.jalapenoSeed
* @type {farmhand.item}
*/
export const jalapenoSeed = crop({
cropType: cropType.JALAPENO,
cropTimetable: {
[SEED]: 2,
[GROWING]: 3,
},
cropTimeline: [2, 1, 1, 1],
growsInto: 'jalapeno',
id: 'jalapeno-seed',
name: 'Jalapeño Seed',
Expand Down
11 changes: 4 additions & 7 deletions src/data/crops/olive.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import { crop, fromSeed } from '../crop'
import { cropLifeStage, cropType } from '../../enums'
/** @typedef {import('../../components/Farmhand/Farmhand').farmhand.item} farmhand.item */

const { SEED, GROWING } = cropLifeStage
import { crop, fromSeed } from '../crop'
import { cropType } from '../../enums'

/**
* @property farmhand.module:items.oliveSeed
* @type {farmhand.item}
*/
export const oliveSeed = crop({
cropType: cropType.OLIVE,
cropTimetable: {
[SEED]: 3,
[GROWING]: 6,
},
cropTimeline: [3, 6],
growsInto: 'olive',
id: 'olive-seed',
name: 'Olive Seed',
Expand Down
11 changes: 4 additions & 7 deletions src/data/crops/onion.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import { crop, fromSeed } from '../crop'
import { cropLifeStage, cropType } from '../../enums'
/** @typedef {import('../../components/Farmhand/Farmhand').farmhand.item} farmhand.item */

const { SEED, GROWING } = cropLifeStage
import { crop, fromSeed } from '../crop'
import { cropType } from '../../enums'

/**
* @property farmhand.module:items.onionSeed
* @type {farmhand.item}
*/
export const onionSeed = crop({
cropType: cropType.ONION,
cropTimetable: {
[SEED]: 3,
[GROWING]: 4,
},
cropTimeline: [3, 1, 2, 1],
growsInto: 'onion',
id: 'onion-seed',
name: 'Onion Seeds',
Expand Down
11 changes: 4 additions & 7 deletions src/data/crops/pea.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import { crop, fromSeed } from '../crop'
import { cropLifeStage, cropType } from '../../enums'
/** @typedef {import("../../index").farmhand.item} farmhand.item */

const { SEED, GROWING } = cropLifeStage
import { crop, fromSeed } from '../crop'
import { cropType } from '../../enums'

/**
* @property farmhand.module:items.peaSeed
* @type {farmhand.item}
*/
export const peaSeed = crop({
cropType: cropType.PEA,
cropTimetable: {
[SEED]: 2,
[GROWING]: 3,
},
cropTimeline: [2, 3],
growsInto: 'pea',
id: 'pea-seed',
name: 'Pea Seed',
Expand Down
11 changes: 4 additions & 7 deletions src/data/crops/potato.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import { crop, fromSeed } from '../crop'
import { cropLifeStage, cropType } from '../../enums'
/** @typedef {import('../../components/Farmhand/Farmhand').farmhand.item} farmhand.item */

const { SEED, GROWING } = cropLifeStage
import { crop, fromSeed } from '../crop'
import { cropType } from '../../enums'

/**
* @property farmhand.module:items.potatoSeed
* @type {farmhand.item}
*/
export const potatoSeed = crop({
cropType: cropType.POTATO,
cropTimetable: {
[SEED]: 2,
[GROWING]: 3,
},
cropTimeline: [2, 1, 1, 1],
growsInto: 'potato',
id: 'potato-seed',
name: 'Potato Seeds',
Expand Down
11 changes: 4 additions & 7 deletions src/data/crops/pumpkin.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import { crop, fromSeed } from '../crop'
import { cropLifeStage, cropType } from '../../enums'
/** @typedef {import('../../components/Farmhand/Farmhand').farmhand.item} farmhand.item */

const { SEED, GROWING } = cropLifeStage
import { crop, fromSeed } from '../crop'
import { cropType } from '../../enums'

/**
* @property farmhand.module:items.pumpkinSeed
* @type {farmhand.item}
*/
export const pumpkinSeed = crop({
cropType: cropType.PUMPKIN,
cropTimetable: {
[SEED]: 3,
[GROWING]: 5,
},
cropTimeline: [3, 1, 1, 1, 1, 1],
growsInto: 'pumpkin',
id: 'pumpkin-seed',
name: 'Pumpkin Seed',
Expand Down
11 changes: 4 additions & 7 deletions src/data/crops/soybean.js
Original file line number Diff line number Diff line change
@@ -1,18 +1,15 @@
import { crop, fromSeed } from '../crop'
import { cropLifeStage, cropType } from '../../enums'
/** @typedef {import('../../components/Farmhand/Farmhand').farmhand.item} farmhand.item */

const { SEED, GROWING } = cropLifeStage
import { crop, fromSeed } from '../crop'
import { cropType } from '../../enums'

/**
* @property farmhand.module:items.soybeanSeed
* @type {farmhand.item}
*/
export const soybeanSeed = crop({
cropType: cropType.SOYBEAN,
cropTimetable: {
[SEED]: 2,
[GROWING]: 2,
},
cropTimeline: [2, 2],
growsInto: 'soybean',
id: 'soybean-seed',
name: 'Soybean Seeds',
Expand Down
Loading

0 comments on commit 71f7840

Please sign in to comment.