Skip to content

Commit 52a653c

Browse files
committed
Partially address 3-deep branches being incorrect
1 parent c99a122 commit 52a653c

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

README.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,11 @@ I also went to lengths to try to ensure I did not infringe upon Nintendo's intel
9393
#### Trunks of treevolutions
9494

9595
Evolutions display correctly for both fully linear evolutions *and* 2-long branches of treevolutions.
96-
Treevolutions display a random path that can be randomly changed with a button. 3-long branches are static, meaning that they are always wrong for Pokémon like, for example, Dustox.
96+
Treevolutions and 3-long branches display a random path that can be randomly changed with a button. A warning is also displayed for these.
9797
I might eventually implement a proper tree view. If I were to do this, I would probably do it in a modal, and replace the normal line view with a button to open that modal.
9898

99+
One solution for 3-long branches could be to also work backwards from the current ID, instead of always working forward from the earliest evolution in the chain.
100+
99101
#### Automated unit testing
100102

101103
I did not do the bonus objective that called for unit-testing the application. Time constraints being what they were, I decided to triage this, since I know the company does not generally use automated unit testing in its UI (instead relying on a mixture of manual QA and end-to-end testing). I did, however, ensure that [Jest](https://jestjs.io) was at least present and ready to go (by integrating `vite-template-redux` into the project).

frontend/app/src/widgets/evolutions/evolution-line.tsx

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -54,31 +54,33 @@ const chainToLine = (
5454

5555
// Set the next link.
5656
if(link.evolves_to.length < 1) return; // End of the line.
57-
let nextInLine: ChainLink = link.evolves_to[0]!;
57+
let nextInLine: ChainLink | void;
5858

5959
// If we haven't matched the ID yet, check the current ID.
6060
if(!idFound) {
6161
idFound = isValidNumber(id) && id === urlToId(link.species.url);
6262
}
6363

64-
// If we've matched the ID before or now, then we can choose the next node at random, if there are more than one of them.
65-
if(idFound) {
66-
if(link.evolves_to.length > 1) { //WARN: The below is only a rough approximation of tree evolutions; please use `EvolutionTree` instead of `EvolutionLine` to properly display evolution trees.
67-
const index = Math.floor(Math.random() * link.evolves_to.length); // Choosing a random index to at least get some variety.
68-
nextInLine = link.evolves_to[index]!;
64+
// If even the current ID wasn't a match, try looking deeper
65+
if(!idFound) {
66+
for(let i = 0; i < link.evolves_to.length; i++) {
67+
if(urlToId(link.evolves_to[i]!.species.url) === id) {
68+
idFound = true;
69+
nextInLine = link.evolves_to[i]!;
70+
break;
71+
}
6972
}
70-
} else {
73+
//BUG: If the match is one level deeper, this won't find it, and we'll end-up going with a random index...
74+
//TODO: Make this recursive somehow, to fix the above bug.
75+
}
7176

72-
// If even the current ID wasn't a match, try looking deeper
73-
if(!idFound) {
74-
for(let i = 1; i < link.evolves_to.length; i++) {
75-
if(urlToId(link.evolves_to[i]!.species.url) === id) {
76-
idFound = true;
77-
nextInLine = link.evolves_to[i]!;
78-
break;
79-
}
80-
}
81-
//BUG: If the match is one level deeper, this won't find it, and we'll end-up going with the `0` index...
77+
// If we have no next-in-line at this point, then we can choose the next node at random.
78+
if(!nextInLine) {
79+
if(link.evolves_to.length > 1) { //WARN: This is only a rough approximation of tree evolutions; please use `EvolutionTree` instead of `EvolutionLine` to properly display evolution trees.
80+
const index = Math.floor(Math.random() * link.evolves_to.length); // Choosing a random index to at least get some variety.
81+
nextInLine = link.evolves_to[index]!;
82+
} else {
83+
nextInLine = link.evolves_to[0]!;
8284
}
8385
}
8486

0 commit comments

Comments
 (0)