Skip to content

Commit

Permalink
feat: Include class type challenges in character search
Browse files Browse the repository at this point in the history
The code changes modify the search functionality to include challenges that apply to specific class types in the search results for legends of that class. The changes also update the README.md file to provide an example of how the search filter works.
  • Loading branch information
Elec0 committed Jun 28, 2024
1 parent 195faf6 commit 32860ea
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 4 deletions.
5 changes: 3 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ Hotkey N will add a new challenge, pressing Enter while editing will save the ch
When adding a new challenge, the first number entered will be placed in the max value box, if no other number has been entered already.

The search icon opens a filter panel, which will search all entered challenges.
Text after a comma will be filtered as Modes.
> Ex: "Bloodhound, BR" shows all challenges with Bloodhound and the BR mode.
Text after a comma will be filtered as Modes.
Challenges applying to class types will appear in the search results for legends of that class.
> Ex: "Bloodhound, BR" shows all challenges with Bloodhound, the BR mode, and any that include "Recon".
>
Adding an asterisk will also include the challenges with the 'All' mode.
> Ex: "Ash, A*"
Expand Down
16 changes: 15 additions & 1 deletion cypress/e2e/path.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ describe("Verify optimal path calculations are correct", () => {
Object.values(CLASS_TYPES).forEach(element => {
valueEq(element, "1");
});

});

it("Includes class types in character totals", () => {
Expand All @@ -55,6 +55,20 @@ describe("Verify optimal path calculations are correct", () => {
});
});

it("Includes class type challenges in character search", () => {
// Import data with a new challenge, a 1 pointer for the 'Assault' class
importData("path-class-data");
goToPath();

// Check that the Assault challenge shows up in Ash's search
// Click <div class="path-entry" name="Ash">
cy.get("[name='Ash']").click();

// Check that the challenge with Assault in its text shows up
// i.e. <span class="keyword">Assault</span> exists
cy.get("span.keyword").contains("Assault");
});

/**
Challenge values:
Ash: BR: 10
Expand Down
28 changes: 27 additions & 1 deletion src/storage-helper.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import { ChallengeEntry } from "src/challenge/ChallengeEntry";
import { KEY_WEEK_DATA, KEY_CHALLENGES, KEY_CHALLENGES_LZ, KEY_WEEK_DATA_LZ, MODES, WEEKS_NUM } from "src/constants";
import { KEY_WEEK_DATA, KEY_CHALLENGES, KEY_CHALLENGES_LZ, KEY_WEEK_DATA_LZ, MODES, WEEKS_NUM, LEGENDS, LEGEND_CLASSES } from "src/constants";
import { compressToUTF16, decompressFromUTF16 } from "lz-string";

export class StorageHelper {
Expand Down Expand Up @@ -359,6 +359,8 @@ export class StorageHelper {
*
* If there's a comma, after that will be the mode.
*
* Filtering by Legend name will also include challenges for that Legend's class type.
*
* "Ash" => Challenges with Ash
* "Ash, BR" => Ash & BR mode
* ",BR" => All BR challenges
Expand All @@ -377,11 +379,20 @@ export class StorageHelper {
filterMode = spl[1].trim();
}

const legend = this.getLegendFromText(filterLower);

this.challenges.forEach((val, key) => {
if (!showCompleted && val.isCompleted())
return;
// Check if the challenge text includes our filter text
let include: boolean = val.text.toLowerCase().includes(filterLower);

// There must be a legend name in the filter text, and that legend must have a class type
if (legend != "" && Object.hasOwnProperty.call(LEGEND_CLASSES, legend)) {
// Include challenges for the legend's class type
include = include || val.text.includes(LEGEND_CLASSES[legend].toString());
}

// See if we need to check the mode
if (filterMode != "") // If the entered mode text includes the string key value of the challenge mode
// The regex handles the A/All case: need to not match 'A' when ',All' is the filter
Expand All @@ -395,6 +406,21 @@ export class StorageHelper {
return result;
}

/**
* Determine if the provided text contains a legend name.
*
* @returns The legend name if found, else an empty string. The first legend found will be returned.
*/
private static getLegendFromText(text: string): string {
let lower = text.toLowerCase();
for (let i = 0; i < LEGENDS.length; ++i) {
if (lower.includes(LEGENDS[i].toLowerCase())) {
return LEGENDS[i];
}
}
return "";
}

/** Return how many challenges have been completed within the provided week */
public static getWeekCompleted(week: number): number {
if (this.weekData.length <= week) {
Expand Down

0 comments on commit 32860ea

Please sign in to comment.