From 2e83fa9270ba65899cb8d38ddffb9eead64784e0 Mon Sep 17 00:00:00 2001 From: Jeremy Kahn Date: Thu, 18 Apr 2024 21:31:40 -0500 Subject: [PATCH] docs(types): define remaining FarmhandContext props --- src/components/Farmhand/Farmhand.context.js | 16 +++++++++++- src/components/Farmhand/Farmhand.js | 25 ++++++++++++------- .../helpers/getInventoryQuantities.js | 2 +- src/data/shop-inventory.js | 5 ++++ src/utils/index.js | 7 ++++-- 5 files changed, 42 insertions(+), 13 deletions(-) diff --git a/src/components/Farmhand/Farmhand.context.js b/src/components/Farmhand/Farmhand.context.js index 28fa2fbc0..f177b1d2f 100644 --- a/src/components/Farmhand/Farmhand.context.js +++ b/src/components/Farmhand/Farmhand.context.js @@ -1,11 +1,25 @@ /** + * @typedef {import('../../').farmhand.item} farmhand.item + * @typedef {import('../../').farmhand.levelEntitlements} farmhand.levelEntitlements * @typedef {import('./Farmhand').farmhand.state} farmhand.state */ import { createContext } from 'react' /** * @type {import('react').Context<{ - * gameState: farmhand.state + * gameState: farmhand.state & { + * blockInput: boolean, + * features: Record, + * fieldToolInventory: farmhand.item[], + * isChatAvailable: boolean, + * levelEntitlements: farmhand.levelEntitlements, + * plantableCropInventory: farmhand.item[], + * playerInventory: farmhand.item[], + * playerInventoryQuantities: Record, + * shopInventory: farmhand.item[], + * viewList: string[], + * viewTitle: string, + * } * handlers: {} * }>} */ diff --git a/src/components/Farmhand/Farmhand.js b/src/components/Farmhand/Farmhand.js index c0126f88d..f28d505b4 100644 --- a/src/components/Farmhand/Farmhand.js +++ b/src/components/Farmhand/Farmhand.js @@ -135,11 +135,14 @@ const { CLEANUP, HARVEST, MINE, OBSERVE, WATER, PLANT } = fieldMode const emptyObject = Object.freeze({}) /*! - * @param {Array.<{ id: farmhand.item, quantity: number }>} inventory - * @param {Object.} valueAdjustments - * @returns {Array.} + * @param {{ id: farmhand.item['id'], quantity: number }} inventory + * @param {Record} valueAdjustments + * @returns {farmhand.item[]} */ -export const computePlayerInventory = memoize((inventory, valueAdjustments) => +export const computePlayerInventory = memoize(( + /** @type {{ id: farmhand.item['id'], quantity: number }[]} */ inventory, + /** @type {Record} */ valueAdjustments +) => inventory.map(({ quantity, id }) => ({ quantity, ...itemsMap[id], @@ -148,10 +151,12 @@ export const computePlayerInventory = memoize((inventory, valueAdjustments) => ) /*! - * @param {Array.<{ id: farmhand.item }>} inventory - * @returns {Array.<{ id: farmhand.item }>} + * @param {farmhand.item[]} inventory + * @returns {{ id: farmhand.item }[]} */ -export const getFieldToolInventory = memoize(inventory => +export const getFieldToolInventory = memoize(( + /** @type {Array.} */ inventory +) => inventory .filter(({ id }) => { const { enablesFieldMode } = itemsMap[id] @@ -162,10 +167,12 @@ export const getFieldToolInventory = memoize(inventory => ) /*! - * @param {Array.<{ id: farmhand.item }>} inventory + * @param {farmhand.item[]} inventory * @returns {Array.<{ id: farmhand.item }>} */ -export const getPlantableCropInventory = memoize(inventory => +export const getPlantableCropInventory = memoize(( + /** @type {farmhand.item[]} */ inventory +) => inventory .filter(({ id }) => itemsMap[id].isPlantableCrop) .map(({ id }) => itemsMap[id]) diff --git a/src/components/Farmhand/helpers/getInventoryQuantities.js b/src/components/Farmhand/helpers/getInventoryQuantities.js index a197589ea..15fb76c1f 100644 --- a/src/components/Farmhand/helpers/getInventoryQuantities.js +++ b/src/components/Farmhand/helpers/getInventoryQuantities.js @@ -4,7 +4,7 @@ const itemIds = Object.keys(itemsMap) /** * @param {Array.<{ id: farmhand.item, quantity: number }>} inventory - * @returns {Object.} + * @returns {Record} */ export const getInventoryQuantities = inventory => { const quantities = {} diff --git a/src/data/shop-inventory.js b/src/data/shop-inventory.js index 4541c6390..7803907b7 100644 --- a/src/data/shop-inventory.js +++ b/src/data/shop-inventory.js @@ -1,3 +1,7 @@ +/** + * @typedef {import('../index').farmhand.item} farmhand.item + */ + import { // Plantable crops asparagusSeed, @@ -27,6 +31,7 @@ import { import { fertilizer } from './recipes' +/** @type {farmhand.item[]} */ const inventory = [ // Plantable crops asparagusSeed, diff --git a/src/utils/index.js b/src/utils/index.js index 03ea00d27..1a9408f2f 100644 --- a/src/utils/index.js +++ b/src/utils/index.js @@ -8,6 +8,7 @@ /** @typedef {import("../index").farmhand.cowBreedingPen} farmhand.cowBreedingPen */ /** @typedef {import("../enums").cropLifeStage} farmhand.cropLifeStage */ /** @typedef {import("../components/Farmhand/Farmhand").farmhand.state} farmhand.state */ +/** @typedef {import("../index").farmhand.levelEntitlements} farmhand.levelEntitlements */ /** * @module farmhand.utils @@ -824,10 +825,12 @@ export const experienceNeededForLevel = targetLevel => ((targetLevel - 1) * 10) ** 2 /** - * @param {Object} levelEntitlements + * @param {farmhand.levelEntitlements} levelEntitlements * @returns {Array.<{ item: farmhand.item }>} */ -export const getAvailableShopInventory = memoize(levelEntitlements => +export const getAvailableShopInventory = memoize(( + /** @type {farmhand.levelEntitlements} */ levelEntitlements +) => shopInventory.filter( ({ id }) => !(