coh-content-db 2.0.0-rc.6 → 2.0.0-rc.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (72) hide show
  1. package/.github/workflows/build.yml +1 -1
  2. package/.github/workflows/pull-request.yml +1 -1
  3. package/.github/workflows/release.yml +1 -1
  4. package/README.md +3 -3
  5. package/dist/coh-content-db.d.ts +444 -194
  6. package/dist/coh-content-db.js +720 -413
  7. package/dist/coh-content-db.js.map +1 -1
  8. package/dist/coh-content-db.mjs +708 -412
  9. package/dist/coh-content-db.mjs.map +1 -1
  10. package/eslint.config.mjs +1 -0
  11. package/package.json +1 -1
  12. package/src/main/api/alignment.ts +18 -2
  13. package/src/main/api/badge-data.ts +12 -42
  14. package/src/main/api/badge-requirement-data.ts +17 -35
  15. package/src/main/api/badge-requirement-type.ts +28 -7
  16. package/src/main/api/badge-type.ts +15 -15
  17. package/src/main/api/contact-data.ts +7 -5
  18. package/src/main/api/content-bundle.ts +6 -0
  19. package/src/main/api/enhancement-category.ts +26 -26
  20. package/src/main/api/location-data.ts +28 -0
  21. package/src/main/api/mission-data.ts +83 -0
  22. package/src/main/api/mission-type.ts +2 -0
  23. package/src/main/api/morality.ts +31 -0
  24. package/src/main/api/sex.ts +8 -1
  25. package/src/main/api/zone-data.ts +1 -1
  26. package/src/main/changelog.ts +5 -4
  27. package/src/main/db/abstract-index.ts +41 -0
  28. package/src/main/db/alignment-list.ts +54 -0
  29. package/src/main/db/alternates.ts +15 -32
  30. package/src/main/db/badge-index.ts +14 -50
  31. package/src/main/db/badge-requirement.ts +22 -43
  32. package/src/main/db/badge-search-options.ts +4 -4
  33. package/src/main/db/badge.ts +53 -54
  34. package/src/main/db/bundle-metadata.ts +8 -2
  35. package/src/main/db/coh-content-database.ts +80 -67
  36. package/src/main/db/contact.ts +17 -14
  37. package/src/main/db/location.ts +30 -0
  38. package/src/main/db/mission.ts +107 -0
  39. package/src/main/db/morality-list.ts +99 -0
  40. package/src/main/db/zone.ts +1 -1
  41. package/src/main/index.ts +8 -3
  42. package/src/main/util.ts +43 -3
  43. package/src/test/api/alignment.test.ts +38 -4
  44. package/src/test/api/badge-data.fixture.ts +1 -17
  45. package/src/test/api/badge-data.test.ts +3 -3
  46. package/src/test/api/badge-requirement-data.fixture.ts +1 -11
  47. package/src/test/api/badge-requirement-type.test.ts +3 -3
  48. package/src/test/api/badge-type.test.ts +5 -5
  49. package/src/test/api/contact-data.fixture.ts +0 -6
  50. package/src/test/api/content-bundle.fixture.ts +1 -17
  51. package/src/test/api/enhancement-category.test.ts +5 -5
  52. package/src/test/api/mission-data.fixture.ts +12 -0
  53. package/src/test/api/sex.test.ts +33 -1
  54. package/src/test/api/zone-data.fixture.ts +1 -1
  55. package/src/test/db/abstract-index.test.ts +86 -0
  56. package/src/test/db/alignment-list.test.ts +200 -0
  57. package/src/test/db/alternates.test.ts +60 -56
  58. package/src/test/db/badge-index.test.ts +220 -183
  59. package/src/test/db/badge-requirement.test.ts +35 -70
  60. package/src/test/db/badge.test.ts +185 -64
  61. package/src/test/db/bundle-metadata.test.ts +17 -0
  62. package/src/test/db/coh-content-database.test.ts +193 -119
  63. package/src/test/db/contact.test.ts +25 -24
  64. package/src/test/db/location.test.ts +51 -0
  65. package/src/test/db/mission.test.ts +171 -0
  66. package/src/test/db/morality-list.test.ts +457 -0
  67. package/src/test/db/zone.test.ts +4 -4
  68. package/src/test/util.test.ts +54 -1
  69. package/src/main/api/plaque-type.ts +0 -6
  70. package/src/main/db/alignments.ts +0 -17
  71. package/src/test/api/alignments.test.ts +0 -40
  72. package/src/test/api/plaque-type.test.ts +0 -31
@@ -1,11 +1,13 @@
1
1
  import { Link } from './link'
2
2
  import { MarkdownString } from './markdown-string'
3
+ import { LocationData } from './location-data'
4
+ import { MoralityExtended } from './morality'
3
5
 
4
6
  export interface ContactData {
5
7
  /**
6
8
  * Unique key used to reference this contact.
7
9
  *
8
- * Keys can only contain lowercase letters, numbers and hyphens (`-`).
10
+ * Keys must be unique and can only contain lowercase letters, numbers and hyphens (`-`).
9
11
  */
10
12
  readonly key: string
11
13
 
@@ -20,14 +22,14 @@ export interface ContactData {
20
22
  readonly title?: string
21
23
 
22
24
  /**
23
- * The zone this character is located in.
25
+ * The character moralities that this contact will interact with.
24
26
  */
25
- readonly zoneKey?: string
27
+ readonly morality?: MoralityExtended | MoralityExtended[]
26
28
 
27
29
  /**
28
- * The `/loc` coordinates of the contact.
30
+ * The location of this contact.
29
31
  */
30
- readonly loc?: [number, number, number]
32
+ readonly location?: LocationData
31
33
 
32
34
  /**
33
35
  * The level range this contact will offer missions for.
@@ -5,6 +5,7 @@ import { Change } from './change'
5
5
  import { Link } from './link'
6
6
  import { MarkdownString } from './markdown-string'
7
7
  import { ContactData } from './contact-data'
8
+ import { MissionData } from './mission-data'
8
9
 
9
10
  /**
10
11
  * A content bundle holds the data that makes up one forked instance of the game since the original sunset, such as Homecoming (https://forums.homecomingservers.com/).
@@ -51,6 +52,11 @@ export interface ContentBundle {
51
52
  */
52
53
  readonly contacts?: ContactData[]
53
54
 
55
+ /**
56
+ * List of missions available in this fork.
57
+ */
58
+ readonly missions?: MissionData[]
59
+
54
60
  /**
55
61
  * List of badges available on this fork.
56
62
  */
@@ -1,30 +1,30 @@
1
1
  export const ENHANCEMENT_CATEGORY = [
2
- 'DEFENSE_DEBUFF',
3
- 'TO_HIT_DEBUFF',
4
- 'TAUNT',
5
- 'CONFUSE',
6
- 'HEALING',
7
- 'DEFENSE_BUFF',
8
- 'RESIST_DAMAGE',
9
- 'INTANGIBILITY',
10
- 'SLEEP',
11
- 'SLOW',
12
- 'HOLD',
13
- 'STUN',
14
- 'IMMOBILIZE',
15
- 'FEAR',
16
- 'ENDURANCE_MODIFICATION',
17
- 'ENDURANCE_REDUCTION',
18
- 'RECHARGE_REDUCTION',
19
- 'INTERRUPT_DURATION',
20
- 'ACCURACY',
21
- 'TO_HIT_BUFF',
22
- 'DAMAGE',
23
- 'KNOCKBACK',
24
- 'RUN_SPEED',
25
- 'JUMP',
26
- 'FLY_SPEED',
27
- 'RANGE',
2
+ 'defense-debuff',
3
+ 'to-hit-debuff',
4
+ 'taunt',
5
+ 'confuse',
6
+ 'healing',
7
+ 'defense-buff',
8
+ 'resist-damage',
9
+ 'intangibility',
10
+ 'sleep',
11
+ 'slow',
12
+ 'hold',
13
+ 'stun',
14
+ 'immobilize',
15
+ 'fear',
16
+ 'endurance-modification',
17
+ 'endurance-reduction',
18
+ 'recharge-reduction',
19
+ 'interrupt-duration',
20
+ 'accuracy',
21
+ 'to-hit-buff',
22
+ 'damage',
23
+ 'knockback',
24
+ 'run-speed',
25
+ 'jump',
26
+ 'fly-speed',
27
+ 'range',
28
28
  ] as const
29
29
 
30
30
  export type EnhancementCategory = typeof ENHANCEMENT_CATEGORY[number]
@@ -0,0 +1,28 @@
1
+ export interface LocationData {
2
+ /**
3
+ * Key of the {@link Zone} that the location references.
4
+ */
5
+ readonly zoneKey?: string
6
+
7
+ /**
8
+ * In-game `/loc` coordinates of the location.
9
+ */
10
+ readonly coords?: Coords
11
+
12
+ /**
13
+ * The type of icon to use if the location appears on a map. (Typically the Vidiot map icon).
14
+ */
15
+ readonly icon?: LocationIcon
16
+
17
+ /**
18
+ * The text that should appear in the location icon. (Typically a number or symbol from the Vidiot map).
19
+ */
20
+ readonly iconText?: string
21
+ }
22
+
23
+ /**
24
+ * Coordinates as they appear using the in-game `/loc` command.
25
+ */
26
+ export type Coords = [number, number, number]
27
+
28
+ export type LocationIcon = 'badge' | 'plaque' | 'pedestal' | 'object'
@@ -0,0 +1,83 @@
1
+ import { Link } from './link'
2
+ import { MarkdownString } from './markdown-string'
3
+ import { MissionType } from './mission-type'
4
+ import { MoralityExtended } from './morality'
5
+
6
+ export interface MissionData {
7
+ /**
8
+ * Unique key used to reference this mission.
9
+ *
10
+ * Keys must be unique and can only contain lowercase letters, numbers and hyphens (`-`).
11
+ */
12
+ readonly key: string
13
+
14
+ /**
15
+ * The name of the mission as it appears from the contact.
16
+ *
17
+ * The name may be different when viewed in Ouroboros as a Flashback.
18
+ */
19
+ readonly name: string
20
+
21
+ /**
22
+ * The type of mission... Story arc, task force, trial, etc.
23
+ */
24
+ readonly type: MissionType
25
+
26
+ /**
27
+ * The character moralities that may accept the mission.
28
+ */
29
+ readonly morality?: MoralityExtended | MoralityExtended[]
30
+
31
+ /**
32
+ * The keys of any contacts that provide this mission.
33
+ */
34
+ readonly contactKeys?: string | string[]
35
+
36
+ /**
37
+ * The level range this mission is available for.
38
+ */
39
+ readonly levelRange?: [number, number?]
40
+
41
+ /**
42
+ * Freeform notes or tips about the mission.
43
+ */
44
+ readonly notes?: MarkdownString
45
+
46
+ /**
47
+ * List of external links. Wiki, forums, etc.
48
+ */
49
+ readonly links?: Link[]
50
+
51
+ /**
52
+ * If the mission is available in Ouroboros as a Flashback.
53
+ */
54
+ readonly flashback?: MissionFlashbackData
55
+ }
56
+
57
+ export interface MissionFlashbackData {
58
+
59
+ /**
60
+ * The id of the mission as seen in the Flashback menu, i.e. '14.01'.
61
+ */
62
+ readonly id: string
63
+
64
+ /**
65
+ * The level range this mission appears under as a Flashback. Leave undefined if the same as the base mission.
66
+ */
67
+ readonly levelRange?: [number, number?]
68
+
69
+ /**
70
+ * The name as it appears in the Flashback list. Leave undefined if the same as the base mission.
71
+ */
72
+ readonly name?: string
73
+
74
+ /**
75
+ * The character moralities that the mission will appear for in the Flashback list. Leave undefined if the same as the base mission.
76
+ */
77
+ readonly morality?: MoralityExtended | MoralityExtended[]
78
+
79
+ /**
80
+ * Freeform notes or tips about the Flashback version of the mission.
81
+ */
82
+ readonly notes?: MarkdownString
83
+ }
@@ -0,0 +1,2 @@
1
+ export const MISSION_TYPE = ['story-arc', 'mission', 'task-force', 'strike-force', 'trial', 'personal-story'] as const
2
+ export type MissionType = typeof MISSION_TYPE[number]
@@ -0,0 +1,31 @@
1
+ export const MORALITY = ['hero', 'vigilante', 'villain', 'rogue', 'resistance', 'loyalist'] as const
2
+ export type Morality = typeof MORALITY[number]
3
+ export type MoralityExtended = Morality
4
+ /**
5
+ * Any of the Primal Earth moralities - Hero, Vigilante, Villain, Rogue.
6
+ */
7
+ | 'primal'
8
+ /**
9
+ * Either of the Praetorian Earth moralities - Resistance or Loyalist.
10
+ */
11
+ | 'praetorian'
12
+ /**
13
+ * The moralities that roll up to the Hero {@link Alignment} - Hero and Vigilante.
14
+ */
15
+ | 'heroic'
16
+ /**
17
+ * The moralities that roll up to the Villain {@link Alignment} - Villain and Rogue.
18
+ */
19
+ | 'villainous'
20
+ /**
21
+ * Moralities with access to Paragon City - Hero, Vigilante and Rogue.
22
+ */
23
+ | 'paragon-city-access'
24
+ /**
25
+ * Moralities with access to the Rogue Isles - Villain, Rogue and Vigilante.
26
+ */
27
+ | 'rogue-isles-access'
28
+ /**
29
+ * All the moralities.
30
+ */
31
+ | 'all'
@@ -1,3 +1,10 @@
1
1
  export const SEX = ['M', 'F'] as const
2
-
3
2
  export type Sex = typeof SEX[number]
3
+
4
+ const SEX_ORDER = Object.fromEntries(SEX.map((x, index) => [x, index]))
5
+
6
+ export function compareSex(a?: Sex, b?: Sex): number {
7
+ const orderA = a ? SEX_ORDER[a] : -1
8
+ const orderB = b ? SEX_ORDER[b] : -1
9
+ return orderA - orderB
10
+ }
@@ -4,7 +4,7 @@ export interface ZoneData {
4
4
  /**
5
5
  * Unique key used to reference this zone.
6
6
  *
7
- * Keys can only contain lowercase letters, numbers and hyphens (`-`).
7
+ * Keys must be unique and can only contain lowercase letters, numbers and hyphens (`-`).
8
8
  */
9
9
  readonly key: string
10
10
 
@@ -7,15 +7,16 @@ export const CHANGELOG: Change[] = [
7
7
  description: ''
8
8
  + '* Replaced redundant interfaces with their concrete equivalents.\n'
9
9
  + `* Server groups are now referred to as 'forks'.\n`
10
- + '* Replaced enums with union types.\n'
11
- + '* `IServerGroupData` is now `ContentBundle` and each database instance is now designed to accept only a single server group.\n'
10
+ + '* Replaced enums with union types and changed values to `kebab-case`.\n'
11
+ + '* `IServerGroupData` is now `ContentBundle` and each database instance is now designed to accept only a single bundle.\n'
12
12
  + '* `GameMap` is now `Zone`.\n'
13
13
  + '* Removed the `serverGroup` property from entities to simplify the object tree given that only a single context can exist per db now.\n'
14
14
  + '* Added a simple indexing and search function for badge names, text and acquisition info.\n'
15
15
  + '* Zone and badge references now follow a standard Markdown link format with a `badge://` or `map://` protocol.\n'
16
- + '* Badge partials are now known as badge requirements and support both AND and OR groups of requirements.\n'
16
+ + '* Badge partials are now known as badge requirements.\n'
17
17
  + '* Removed the `VidiotMap` API as it was never used or fleshed out properly.\n'
18
- + '* Added support for story arcs to badge requirements including a link to the contact.\n'
18
+ + '* Added formal support for Missions and Contacts in badge requirements.\n'
19
+ + '* Move exploration badge locations into badge requirement list.\n'
19
20
  + '* Standardized pluralization of some field names (name, icon).\n'
20
21
  + '* Combined `settitle` ids into a single tuple field.\n'
21
22
  + '* Change from GNU to The Unlicense.\n'
@@ -0,0 +1,41 @@
1
+ type KeysOfType<T, V> = { [P in keyof T]: T[P] extends V ? P : never }[keyof T]
2
+
3
+ export class AbstractIndex<T> {
4
+ readonly #keyField: KeysOfType<T, string>
5
+ protected _values: T[] = []
6
+ protected _hashTable: Record<string, T> = {}
7
+
8
+ constructor(keyField: KeysOfType<T, string>) {
9
+ this.#keyField = keyField
10
+ }
11
+
12
+ /**
13
+ * Return all indexed values
14
+ */
15
+ get values(): T[] {
16
+ return this._values
17
+ }
18
+
19
+ /**
20
+ * Load the given list of values into the index, replacing any existing data.
21
+ * @param values List of values.
22
+ */
23
+ load(values: T[] | undefined): void {
24
+ this._values = values ?? []
25
+ this._hashTable = {}
26
+ for (const value of this.values) {
27
+ const key = value[this.#keyField] as string
28
+ if (this._hashTable[key] !== undefined) throw new Error(`Duplicate key [${key}]`)
29
+ this._hashTable[key] = value
30
+ }
31
+ }
32
+
33
+ /**
34
+ * Get a value from the index
35
+ * @param key Key string
36
+ */
37
+ get(key: string | undefined): T | undefined {
38
+ if (!key) return undefined
39
+ return this._hashTable[key]
40
+ }
41
+ }
@@ -0,0 +1,54 @@
1
+ import { ALIGNMENT, Alignment, AlignmentExtended } from '../api/alignment'
2
+
3
+ export class AlignmentList {
4
+ readonly #items: Set<Alignment>
5
+
6
+ readonly hero: boolean
7
+ readonly villain: boolean
8
+ readonly praetorian: boolean
9
+
10
+ readonly primal: boolean
11
+ readonly all: boolean
12
+
13
+ constructor(items?: AlignmentExtended[]) {
14
+ const set = new Set(items ?? [...ALIGNMENT])
15
+ this.hero = set.has('hero') || set.has('primal') || set.has('all')
16
+ this.villain = set.has('villain') || set.has('primal') || set.has('all')
17
+ this.praetorian = set.has('praetorian') || set.has('all')
18
+
19
+ this.primal = this.hero && this.villain
20
+ this.all = this.hero && this.villain && this.praetorian
21
+
22
+ this.#items = new Set()
23
+ if (this.hero) this.#items.add('hero')
24
+ if (this.villain) this.#items.add('villain')
25
+ if (this.praetorian) this.#items.add('praetorian')
26
+ }
27
+
28
+ get items(): Alignment[] {
29
+ return [...this.#items]
30
+ }
31
+
32
+ has(alignment?: AlignmentExtended): boolean {
33
+ switch (alignment) {
34
+ case 'hero': {
35
+ return this.hero
36
+ }
37
+ case 'villain': {
38
+ return this.villain
39
+ }
40
+ case 'praetorian': {
41
+ return this.praetorian
42
+ }
43
+ case 'primal' : {
44
+ return this.primal
45
+ }
46
+ case 'all': {
47
+ return this.all
48
+ }
49
+ default: {
50
+ return false
51
+ }
52
+ }
53
+ }
54
+ }
@@ -1,16 +1,21 @@
1
1
  import { AlternateData } from '../api/alternate-data'
2
- import { Sex } from '../api/sex'
3
- import { Alignment } from '../api/alignment'
4
-
5
- const ALIGNMENT_SORT: Record<string, number> = { H: 2, V: 1, P: 0 }
6
- const SEX_SORT: Record<string, number> = { M: 1, F: 0 }
2
+ import { compareSex, Sex } from '../api/sex'
3
+ import { Alignment, compareAlignment } from '../api/alignment'
7
4
 
8
5
  export class Alternates<T> {
9
6
  readonly #sortedValues: AlternateData<T>[] = []
10
7
 
11
- constructor(values: AlternateData<T>[]) {
12
- this.#sortedValues = values.sort()
13
- this.#sortedValues.sort((a, b) => this.#compareAlternates(a, b))
8
+ /**
9
+ * Create an alternate set from either a list of categorized values, or a single value when there are no alternates.
10
+ * @param value List of alternates, or a single value.
11
+ */
12
+ constructor(value: AlternateData<T>[] | T) {
13
+ if (Array.isArray(value)) {
14
+ this.#sortedValues = value.sort()
15
+ this.#sortedValues.sort((a, b) => this.#compareAlternates(a, b))
16
+ } else {
17
+ this.#sortedValues = [{ value }]
18
+ }
14
19
  }
15
20
 
16
21
  getValue(alignment?: Alignment, sex?: Sex): T | undefined {
@@ -51,34 +56,12 @@ export class Alternates<T> {
51
56
  const bSpecificity = (b.alignment ? 2 : 0) + (b.sex ? 1 : 0)
52
57
  if (aSpecificity !== bSpecificity) return aSpecificity - bSpecificity // Order first by least-specific
53
58
 
54
- const alignmentComparison = this.#compareAlignment(a.alignment, b.alignment) // Next by alignment
59
+ const alignmentComparison = compareAlignment(a.alignment, b.alignment) // Next by alignment
55
60
  if (alignmentComparison !== 0) return alignmentComparison
56
61
 
57
- const sexComparison = this.#compareSex(a.sex, b.sex) // Last by sex
62
+ const sexComparison = compareSex(a.sex, b.sex) // Last by sex
58
63
  if (sexComparison !== 0) return sexComparison
59
64
 
60
65
  return String(a.value).localeCompare(String(b.value))
61
66
  }
62
-
63
- #compareAlignment(a?: Alignment, b?: Alignment): number {
64
- if (a === b) return 0
65
- if (a === undefined && b !== undefined) return -1
66
- if (b === undefined && a !== undefined) return 1
67
-
68
- const aSort = a === undefined ? -1 : ALIGNMENT_SORT[a] ?? -1 // Unknown values get -1 priority
69
- const bSort = b === undefined ? -1 : ALIGNMENT_SORT[b] ?? -1
70
-
71
- return bSort - aSort
72
- }
73
-
74
- #compareSex(a?: Sex, b?: Sex): number {
75
- if (a === b) return 0
76
- if (a === undefined && b !== undefined) return -1
77
- if (b === undefined && a !== undefined) return 1
78
-
79
- const aSort = SEX_SORT[a ?? -1] ?? -1 // Unknown values get -1 priority
80
- const bSort = SEX_SORT[b ?? -1] ?? -1
81
-
82
- return bSort - aSort
83
- }
84
67
  }
@@ -1,42 +1,17 @@
1
- import { Badge } from './badge'
1
+ import { Badge, compareByDefaultName, compareByZoneKey } from './badge'
2
2
  import { BadgeSearchOptions } from './badge-search-options'
3
- import { Zone } from './zone'
4
3
  import { Paged } from './paged'
4
+ import { AbstractIndex } from './abstract-index'
5
5
 
6
- export class BadgeIndex {
7
- readonly #badges: Badge[] = []
8
- readonly #badgeIndex: Record<string, Badge> = {}
9
-
10
- readonly #zoneOrder: Record<string, number> = {}
11
-
12
- constructor(badges: Badge[], zones?: Zone[]) {
13
- this.#zoneOrder = Object.fromEntries(
14
- zones
15
- ?.sort((a, b) => a.name.localeCompare(b.name))
16
- ?.map((x, index) => [x.key, index]) ?? [],
17
- )
18
-
19
- this.#badges = badges
20
- for (const badge of badges) {
21
- if (this.#badgeIndex[badge.key] !== undefined) throw new Error(`Duplicate badge key [${badge.key}]`)
22
- this.#badgeIndex[badge.key] = badge
23
- }
24
- }
25
-
26
- getBadge(key: string): Badge {
27
- const result = this.#badgeIndex[key]
28
- if (result === undefined) throw new Error(`Unknown badge key [${key}]`)
29
- return result
30
- }
31
-
32
- badgeExists(key: string): boolean {
33
- return !!this.#badgeIndex[key]
6
+ export class BadgeIndex extends AbstractIndex<Badge> {
7
+ constructor() {
8
+ super('key')
34
9
  }
35
10
 
36
- searchBadges(options?: BadgeSearchOptions): Paged<Badge> {
11
+ search(options?: BadgeSearchOptions): Paged<Badge> {
37
12
  const filtered = (options?.query || options?.filter)
38
- ? this.#badges.filter(badge => this.#satisfiesQueryPredicate(badge, options?.query) && this.#satisfiesFilterPredicate(badge, options?.filter))
39
- : this.#badges
13
+ ? this._values.filter(badge => this.#satisfiesQueryPredicate(badge, options?.query) && this.#satisfiesFilterPredicate(badge, options?.filter))
14
+ : this._values
40
15
 
41
16
  const totalPages = options?.pageSize ? Math.ceil(filtered.length / (options?.pageSize)) : 1
42
17
  const page = Math.max(1, Math.min(totalPages, options?.page ?? 1))
@@ -60,34 +35,23 @@ export class BadgeIndex {
60
35
  || (query?.on?.acquisition && badge.acquisition?.toLowerCase().includes(queryString))
61
36
  || (query?.on?.effect && badge.effect?.toLowerCase().includes(queryString))
62
37
  || (query?.on?.notes && badge.notes?.toLowerCase().includes(queryString))
63
- || (query?.on?.setTitle && (badge.setTitle?.id?.toString().includes(queryString) || badge.setTitle?.praetorianId?.toString().includes(queryString))))
38
+ || (query?.on?.setTitle && (badge.setTitleId?.some(x => x?.toString().includes(queryString)))))
64
39
  }
65
40
 
66
41
  #satisfiesFilterPredicate(badge: Badge, filter?: BadgeSearchOptions['filter']): boolean {
67
42
  return (!filter?.type || badge.type === filter.type)
68
43
  && (!filter?.zoneKey || badge.zoneKey === filter.zoneKey)
69
- && (!filter?.alignment || badge.alignment.items.includes(filter.alignment))
44
+ && (!filter?.morality || badge.morality.has(filter.morality))
70
45
  }
71
46
 
72
47
  #sort(badges: Badge[], sort?: BadgeSearchOptions['sort']): Badge[] {
73
48
  if (!sort) return badges
74
- const ascending = sort.dir !== 'DESC'
75
-
76
- if (!sort.by || sort.by === 'CANONICAL') return sort.dir === 'DESC' ? badges.reverse() : badges
77
-
78
- if (sort.by === 'BADGE_NAME') return ascending
79
- ? badges.sort((a, b) => a.name.default?.value.localeCompare(b.name.default?.value ?? '') ?? 0)
80
- : badges.sort((a, b) => b.name.default?.value.localeCompare(a.name.default?.value ?? '') ?? 0)
49
+ const ascending = sort.dir !== 'desc'
81
50
 
82
- return badges.sort((a, b) => {
83
- const aIndex = this.#zoneOrder[a.zoneKey ?? '']
84
- const bIndex = this.#zoneOrder[b.zoneKey ?? '']
51
+ if (sort.by === 'badge-name') return badges.sort((a, b) => ascending ? compareByDefaultName(a, b) : compareByDefaultName(b, a))
85
52
 
86
- if (aIndex === bIndex) return 0
87
- if (aIndex === undefined) return ascending ? 1 : -1
88
- if (bIndex === undefined) return ascending ? -1 : 1
53
+ if (sort.by === 'zone-key') return badges.sort((a, b) => ascending ? compareByZoneKey(a, b) : compareByZoneKey(b, a))
89
54
 
90
- return ascending ? aIndex - bIndex : bIndex - aIndex
91
- })
55
+ return sort.dir === 'desc' ? badges.reverse() : badges
92
56
  }
93
57
  }