Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix missing Skaven prayers (fixes #1595) #1596

Merged
merged 3 commits into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 26 additions & 2 deletions src/factions/factionClass.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { uniq } from 'lodash'
import { TGrandAlliances } from 'meta/alliances'
import { TSupportedFaction } from 'meta/factions'
import { TRuleSource } from 'meta/rule_sources'
import { TSubfactionArmy } from 'types/army'
import { TEffects } from 'types/data'
import { TItemDescriptions } from './factionTypes'
import { SELECTION_TYPES, TEffects } from 'types/data'
import { TSelectionTypes } from 'types/selections'
import { TItemDescriptions, TItemKey } from './factionTypes'
import { getAggregateArmy, temporaryAdapter } from './temporaryAdapter'

/**
Expand Down Expand Up @@ -54,6 +56,28 @@ export class Faction<
a[subFactionName] = temporaryAdapter(this.SubFactions[subFactionName], subFactionName, this.flavorLabel)
return a
}, {} as Record<K, TSubfactionArmy>)

this.checkForDataEntryErrors()
}

/** Throw an error if we've got bad data (this will discover bad data entry) */
private checkForDataEntryErrors = () => {
const validSelectionKeys: TItemKey[] = [...SELECTION_TYPES, 'allied_units']

this.subFactionKeys.forEach(k => {
const allKeys = uniq([
...Object.keys(this.SubFactions[k]?.available ?? {}),
...Object.keys(this.SubFactions[k]?.mandatory ?? {}),
]) as TSelectionTypes[]

allKeys.forEach(selection => {
if (!validSelectionKeys.includes(selection)) {
throw new Error(
`${this.factionName} subfaction ${k} has an invalid/unknown key: ${selection}. Please check your data in this faction's subfactions.ts file`
)
}
})
})
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/factions/skaven/subfactions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ const subFactions = {
endless_spells: [EndlessSpells],
flavors: [Flavors],
grand_strategies: [GrandStrategies],
Prayers: [Prayers],
prayers: [Prayers],
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

very naughty!

scenery: [Scenery],
spells: [Spells],
units: [Units],
Expand Down
7 changes: 7 additions & 0 deletions src/tests/getArmy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { GenericEndlessSpells, GenericTriumphs } from 'generic_rules'
import { sortBy } from 'lodash'
import { ORDER } from 'meta/alliances'
import { BEASTS_OF_CHAOS, SERAPHON, SYLVANETH } from 'meta/factions'
import { getFactionList } from 'meta/faction_list'
import { IArmy } from 'types/army'
import { getAllianceItems } from 'utils/getArmy/getAllianceItems'
import { getArmy } from 'utils/getArmy/getArmy'
Expand Down Expand Up @@ -49,3 +50,9 @@ describe('getArmy', () => {
expect(shouldNotHaveThisUnit).toBeUndefined()
})
})

describe('getFactionList', () => {
it('should not throw errors when using getFactionList', () => {
expect(getFactionList).not.toThrow()
})
})
19 changes: 19 additions & 0 deletions src/types/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,25 @@ export const ENTRY_PROPERTIES: TEntryProperties[] = [
'unit',
]

export const SELECTION_TYPES: TSelectionTypes[] = [
'artifacts',
'battalions',
'command_abilities',
'command_traits',
'core_rules',
'endless_spells',
'flavors',
'grand_strategies',
'incarnates',
'monstrous_rampages',
'mount_traits',
'prayers',
'scenery',
'spells',
'triumphs',
'units',
]

export const lowerToUpperLookup: Record<TSelectionTypes, keyof TCollection> = {
artifacts: 'Artifacts',
battalions: 'Battalions',
Expand Down