@jeremyckahn/farmhand
Version:
A farming game
19 lines (15 loc) • 454 B
text/typescript
// TODO: Add tests for this reducer.
export const modifyFieldPlotAt = (
state: farmhand.state,
x: number,
y: number,
modifierFn: (arg0: farmhand.plotContent | null) => farmhand.plotContent | null
): farmhand.state => {
const { field } = state
const row = [...field[y]]
const plotContent = modifierFn(row[x])
row[x] = plotContent
const modifiedField = [...field]
modifiedField[y] = row
return { ...state, field: modifiedField }
}