W3 Trapping: add owned/collected critters summary#309
Conversation
|
@TolakaD is attempting to deploy a commit to the Idleon Efficiency Team on Vercel. A member of the Team first needs to authorize it. |
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
Sludging
left a comment
There was a problem hiding this comment.
Left some comments, mostly not blocking but I'd like to maintain some conventions so keen to see if you are happy to address them yourselves or want me to look at it post merge as a follow-up PR.
| const critters = initCritterRepo(); | ||
| const critterCounts = { | ||
| regular: critters.map(c => ({ | ||
| id: c.id, | ||
| count: storage?.amountInStorage(c.id) ?? 0, | ||
| location: c.data.location, | ||
| })), | ||
| shiny: critters.map(c => ({ | ||
| id: c.data.shiny, | ||
| count: storage?.amountInStorage(c.data.shiny) ?? 0, | ||
| location: c.data.location, | ||
| })), | ||
| }; | ||
|
|
||
| const totalRewards = new Map<string, number>(); | ||
| playerTraps | ||
| .flat() | ||
| .filter((trap) => trap?.placed) | ||
| .forEach((trap) => { | ||
| const current = totalRewards.get(trap.critterName) ?? 0; | ||
| totalRewards.set(trap.critterName, current + (trap.critters ?? 0)); | ||
| }); | ||
|
|
||
| const trapRewards = Array.from(totalRewards.entries()) | ||
| .map(([name, count]) => ({ name, count })) | ||
| .sort((a, b) => a.name.localeCompare(b.name)); |
There was a problem hiding this comment.
The codebase follows a convention where page components (app/*/content.tsx) pull pre-calculated data from the domain — they aim (unless really inconvinent or depending on user behavior) to not do aggregations or init*Repo() directly.
So as an example for this code portion:
- Repo data should be initialized in the domain layer and surfaced through the store, not re-called every render
- Critter count aggregation and trap reward totals - this kind of logic belongs in the domain layer so the component just pulls the result from
theData.
There was a problem hiding this comment.
Thanks for explanation. Fixed by moving repo's initialization and calculation logic to the traps.tsx file.
| @@ -0,0 +1,37 @@ | |||
| import { Box, Text } from 'grommet'; | |||
There was a problem hiding this comment.
ResourceCountTile is very similar to the existing ResourceDisplay component at
components/account/shared/ResourceDisplay.tsx.
What do you think about rather than introducing a new component, promoting ResourceDisplay from
components/account/shared/ to components/base/ (it's generic enough to live there) and reusing
it for the critter/reward tiles.
If it needs small additions like the border/background styling, those can be added as props or handled by the caller wrapping it in a Box.
There was a problem hiding this comment.
Good point, didn't know what I can reuse for this data. Fixed by removing new component and switching to ResourceDisplay component. Didn't promote it to components/base though, not to expand the scope of this PR.
I would rather open a separate PR for that.
| {duration: 2419e3, qty: 550, shiny: 1150} | ||
| ], | ||
| ]; | ||
| const trapBoxBySetIndex = Object.fromEntries( |
There was a problem hiding this comment.
Is there a reason you went with module level constants for trapIdByName and trapBoxBySetIndex?
The more common pattern is to set the values as class properties (similar to how Sneaking, Farming, etc. do it).
There was a problem hiding this comment.
Having them as class properties will lead to recalculating the same static data over and over again, this is why I've left them at the module level. Note that previously they were at module level as well which made sense for me :)
There was a problem hiding this comment.
We only initialize our domain classes once (at least .. in theory lol) but that's a good point overall. Happy to keep it like that.
| .map(trapBox => [trapBox.index, trapBox.data.times]) | ||
| ) as Record<number, TrapBoxTimeModel[]>; | ||
|
|
||
| export class Trap { |
There was a problem hiding this comment.
To do some of the work I suggested you might need to create a "wrapper" Traps class that inside it holds the traps information (the current data returned) + the new fields.
It's more work (and most of it busy work) compare to what you have done but I think it would be a nice challenge + helps align a misaligned old code to newer conventions.
What do you think? you ok with picking that up?
There was a problem hiding this comment.
Fixed. I didn't create a new class but refactored the existing Traps class in traps.tsx.
I hope the change addresses what you've meant, please let me know otherwise.
There was a problem hiding this comment.
Oh I forgot there was already a Traps domain class 😆
Yeah the changes look good, good work!
| <Box | ||
| border={{ side: 'top', color: 'grey-1', size: '1px' }} | ||
| margin={{ top: 'small' }} | ||
| pad={{ top: 'small' }} | ||
| align="end" | ||
| > | ||
| <Text margin={{ bottom: "small" }}>Trap Rewards</Text> | ||
| <TrapRewardsSummary entries={trapRewards} /> | ||
| </Box> |
There was a problem hiding this comment.
I feel this is hidden at the bottom, what do you think making it top right (i.e. right above the table and below the owned critters section)?
I think it will be more visible and more aligned with other newer pages (like grimoire/tesseract etc)
There was a problem hiding this comment.
Tried and it looks not good in that place. Grimoire/tesseract have pages have cards and this style fits nicely there, but we have a table here :) I've put it between owned critters and traps table, please let me know what you think.
There was a problem hiding this comment.
Thanks for trying, and yeah left side between the two looks fine to me as well!
Sludging
left a comment
There was a problem hiding this comment.
Thanks for working through my requested changes and for delivering on this feature, I'll merge it in now as I'm happy with how it shaped up!
traps.tsxfile to useTrapBoxRepofor trap times and bonuses instead of hard-coded values;traps.tsxfile to useItemDetailRepofor number of traps per trap set type instead of hard-coded values;ResourceCountTilein base components for critters summary tiles. Potentially can be reused for cooking spices.