|
1 | 1 | import React, { useState, useEffect } from 'react' |
| 2 | +import type { cropsShippedType } from 'types/savefile'; |
2 | 3 |
|
3 | | -interface CropShipped { |
4 | | - shipped?: { |
5 | | - times: string; |
6 | | - }; |
7 | | - name: string; |
8 | | - image: string; |
| 4 | +interface CropsShippedWrapperType { |
| 5 | + cropsShipped: cropsShippedType; |
9 | 6 | } |
10 | 7 |
|
11 | | -interface CropsShippedData { |
12 | | - poly_crops: CropShipped[]; |
13 | | - mono_extras: CropShipped[]; |
14 | | -} |
15 | | - |
16 | | -interface CropsProps { |
17 | | - cropsShipped: CropsShippedData; |
18 | | -} |
19 | | - |
20 | | -const Crops: React.FC<CropsProps> = ({ cropsShipped }) => { |
21 | | - const [maxShipped, setMaxShipped] = useState<{name: string, times: number}>({name: '', times: 0}); |
| 8 | +const Crops= (cropsShipped : CropsShippedWrapperType) => { |
| 9 | + let _monocultureText = cropsShipped.cropsShipped.hasMonoculture ? "You already have the 'Monoculture' Achievement" : `You've shipped ${ cropsShipped.cropsShipped.maxMono?.name } the most and you require ${300 - cropsShipped.cropsShipped.maxMono?.shipped} more of it to get the 'Monoculture' Achievement`; |
| 10 | + let _polycultureText = cropsShipped.cropsShipped.hasPolyculture ? "You already have the 'Polyculture' Achievement" : `You need to ship 15 crops for each polyculture crop to get the 'Polyculture' achievement`; |
22 | 11 |
|
23 | | - const timesShipped = (arr: CropsShippedData) => { |
24 | | - let Max: number[] = [] |
25 | | - let name: string[] = [] |
26 | | - arr.poly_crops.forEach( crop => { |
27 | | - Max = (crop.shipped !== undefined) ? [...Max, parseInt(crop.shipped.times)] : [...Max] |
28 | | - name = (crop.shipped !== undefined) ? [...name, crop.name] : [...name] |
29 | | - }) |
30 | | - arr.mono_extras.forEach( crop => { |
31 | | - Max = (crop.shipped !== undefined) ? [...Max, parseInt(crop.shipped.times)] : [...Max] |
32 | | - name = (crop.shipped !== undefined) ? [...name, crop.name] : [...name] |
33 | | - }) |
34 | | - |
35 | | - if (Max.length === 0 || name.length === 0) { |
36 | | - setMaxShipped({name: 'None', times: 0}); |
37 | | - return; |
38 | | - } |
39 | | - |
40 | | - const indexOfMaxValue = Max.reduce((iMax: number, x: number, i: number, arr: number[]) => { |
41 | | - return x > (arr[iMax] ?? 0) ? i : iMax; |
42 | | - }, 0); |
43 | | - setMaxShipped({ |
44 | | - name: name[indexOfMaxValue] || 'Unknown', |
45 | | - times: Max[indexOfMaxValue] || 0 |
46 | | - }); |
47 | | - }; |
48 | | - |
49 | | - useEffect(() => { |
50 | | - timesShipped(cropsShipped); |
51 | | - }, [cropsShipped]); |
52 | | - |
53 | 12 | return ( |
54 | 13 | <div className="progress-container"> |
55 | | - <span className="a-title"><h1>{(maxShipped.times < 300) ? `You've shipped ${ maxShipped.name } the most and you require ${300 - maxShipped.times} more of it to get the 'Monoculture' Achievement` : <span className="completed">`You already have the 'Monoculture' Achievement`</span> }</h1></span> |
56 | | - <br /><br /> |
57 | | - <span className="a-title"><h1>Ship 15 of the following crops to get the 'Polyculture' achievement</h1></span> |
58 | | - {cropsShipped.poly_crops.map((crop, i) =><a href={`https://stardewvalleywiki.com/${crop.image}`} target="blank" key={i}> <img key={i} src={`https://stardew-tracker.s3.amazonaws.com/Crops/${crop.image}.png`} alt={crop.name} className={ (crop.shipped !== undefined) ? ((parseInt(crop.shipped.times) >= 15) ? "done" : "known" ): "" } title={(crop.shipped !== undefined) ? (parseInt(crop.shipped.times) >= 15) ? `You have shipped ${crop.name} ${crop.shipped.times} times` : `You have to ship ${ 15 - parseInt(crop.shipped.times)} more ${crop.name} ` : `You haven't shipped ${crop.name}`} ></img></a>)} |
59 | | - |
60 | | - <span className="a-title"><h1>This crops are not counted for the 'Polyculture' achievement</h1></span> |
61 | | - {cropsShipped.mono_extras.map((crop, i) =><a href={`https://stardewvalleywiki.com/${crop.image}`} target="blank" key={i}> <img key={i} src={`https://stardew-tracker.s3.amazonaws.com/Crops/${crop.image}.png`} alt={crop.name} className={ (crop.shipped !== undefined) ? ((parseInt(crop.shipped.times) > 0) ? "done" : "known" ): "" } title={(crop.shipped !== undefined) ? `You have shipped ${crop.name} ${crop.shipped.times} times` : `You haven't shipped ${crop.name}`} ></img></a>)} |
| 14 | + {/* <span className="a-title"><h1>{_monocultureAchieved ? `You've shipped ${ maxShipped.name } the most and you require ${300 - maxShipped.times} more of it to get the 'Monoculture' Achievement` : <span className="completed">`You already have the 'Monoculture' Achievement`</span> }</h1></span> */} |
| 15 | + <br /> |
| 16 | + <h2>Farming Achievements</h2> |
| 17 | + <ul className="a-List"> |
| 18 | + <li>Monoculture: <span className={cropsShipped.cropsShipped.hasMonoculture ? "completed" : "pending"}>{_monocultureText}</span> </li> |
| 19 | + <li>Polyculture: <span className={cropsShipped.cropsShipped.hasPolyculture ? "completed" : "pending"}>{_polycultureText}</span></li> |
| 20 | + </ul> |
| 21 | + <span className="a-title"><p>Ship 15 of the following crops to get the 'Polyculture' achievement</p></span> |
| 22 | + {cropsShipped.cropsShipped.poly_crops.map((crop, i) =><a href={`https://stardewvalleywiki.com/${crop.image}`} target="blank" key={i}> <img key={i} src={`https://stardew-tracker.s3.amazonaws.com/Crops/${crop.image}.png`} alt={crop.name} className={ (crop.shipped !== undefined) ? ((crop.shipped >= 15) ? "done" : "known" ): "" } title={(crop.shipped !== undefined) ? (crop.shipped >= 15) ? `You have shipped ${crop.name} ${crop.shipped} times` : `You have to ship ${ 15 - crop.shipped} more ${crop.name} ` : `You haven't shipped ${crop.name}`} ></img></a>)} |
| 23 | + |
| 24 | + <span className="a-title"><p>These crops are not counted for the 'Polyculture' achievement</p></span> |
| 25 | + {cropsShipped.cropsShipped.mono_extras.map((crop, i) =><a href={`https://stardewvalleywiki.com/${crop.image}`} target="blank" key={i}> <img key={i} src={`https://stardew-tracker.s3.amazonaws.com/Crops/${crop.image}.png`} alt={crop.name} className={ (crop.shipped !== undefined) ? ((crop.shipped > 0) ? "done" : "known" ): "" } title={(crop.shipped !== undefined) ? `You have shipped ${crop.name} ${crop.shipped} times` : `You haven't shipped ${crop.name}`} ></img></a>)} |
62 | 26 | </div> |
63 | 27 | ); |
64 | 28 | }; |
|
0 commit comments