|
1 | 1 | import { findInArray } from '../../lib/src/findInArray' |
2 | 2 | import { Town } from '../../lib/town/_common' |
3 | | -import { compileWeightToPercentile, getTownDeityWeightings } from './createTownReligion' |
| 3 | +import { compileWeightToPercentile, getFallbackPantheon, getTownDeityWeightings } from './createTownReligion' |
4 | 4 | import { Deity, Pantheon, religion } from './religion' |
5 | 5 |
|
6 | 6 | export const getDeity = (town: Town, deity: string, customPantheon?: Pantheon) => { |
| 7 | + console.log(`Getting ${deity}...`) |
7 | 8 | return findInArray( |
8 | 9 | getPantheonDeities(town, customPantheon), 'name', deity) |
9 | 10 | } |
10 | 11 |
|
11 | 12 | export const getPantheon = (town: Town, customPantheon?: Pantheon): Pantheon => { |
12 | | - if (isUsingCustomPantheon(town)) return getCustomPantheon(town, customPantheon) |
| 13 | + townHasPantheon(town) |
| 14 | + console.log(`Getting pantheon that matched ${town.religion.pantheon}`) |
| 15 | + if (isUsingCustomPantheon(town, customPantheon)) { |
| 16 | + console.log('Using a custom pantheon!') |
| 17 | + return getCustomPantheon(town, customPantheon) |
| 18 | + } |
13 | 19 | return religion.pantheon[town.religion.pantheon] |
14 | 20 | } |
15 | 21 |
|
16 | 22 | export const getPantheonDeities = (town: Town, customPantheon?: Pantheon): Deity[] => { |
| 23 | + console.log('Getting pantheon deities...') |
17 | 24 | return getPantheon(town, customPantheon).gods |
18 | 25 | } |
19 | 26 |
|
20 | 27 | export const getPantheonNames = (town: Town, customPantheon?: Pantheon) => { |
| 28 | + console.log('Getting pantheon names...') |
21 | 29 | return Object.keys(getAllPantheons(town, customPantheon)) |
22 | 30 | } |
23 | 31 |
|
24 | 32 | export const getAllPantheons = (town: Town, customPantheon?: Pantheon) => { |
| 33 | + console.log('Getting all pantheons...') |
25 | 34 | const pantheons: Record<string, Pantheon> = Object.assign({}, religion.pantheon) |
26 | 35 | if (seeIfCustomPantheonExists(town, customPantheon)) pantheons[getCustomPantheon(town, customPantheon).name] = getCustomPantheon(town, customPantheon) |
27 | 36 | return pantheons |
28 | 37 | } |
29 | 38 |
|
30 | 39 | /** If the pantheon being used doesn't exist in the data, it's obviously custom. */ |
31 | | -export const isUsingCustomPantheon = (town: Town) => { |
| 40 | +export const isUsingCustomPantheon = (town: Town, customPantheon = getFallbackPantheon(town)) => { |
| 41 | + console.log('Checking to see if you are using a custom pantheon...') |
| 42 | + // if (!town.religion.pantheon) return false |
| 43 | + if (!town.religion._customPantheon) return false |
32 | 44 | if (religion.pantheon[town.religion.pantheon]) return false |
| 45 | + if (customPantheon?.name === 'greek') return false |
| 46 | + console.log('Looks like you are using a custom pantheon!') |
| 47 | + if (town.religion.pantheon === customPantheon.name) return true |
33 | 48 | return true |
34 | 49 | } |
35 | 50 |
|
36 | 51 | export const seeIfCustomPantheonExists = (town: Town, customPantheon?: Pantheon): boolean => { |
| 52 | + console.log('Checking to see if a custom pantheon exists...') |
37 | 53 | if (customPantheon) return true |
38 | | - if (town.religion.customPantheon) return true |
| 54 | + if (town.religion._customPantheon) return true |
| 55 | + console.log('Looks like the custom pantheon does not exist!') |
39 | 56 | return false |
40 | 57 | } |
41 | 58 |
|
42 | 59 | export const getCustomPantheon = (town: Town, customPantheon?: Pantheon): Pantheon => { |
43 | | - if (town.religion.customPantheon) return town.religion.customPantheon |
| 60 | + console.log('Getting the custom pantheon...') |
44 | 61 | if (customPantheon) return customPantheon |
45 | | - throw new Error('Custom panthon not defined!') |
| 62 | + if (town.religion._customPantheon) return town.religion._customPantheon |
| 63 | + throw new Error('Custom pantheon not defined!') |
46 | 64 | } |
47 | 65 |
|
48 | 66 | /** For getting ALL deities, including 0% ones. */ |
@@ -74,3 +92,12 @@ export const getPantheonPercentages = (town: Town, customPantheon?: Pantheon) => |
74 | 92 | .reverse() |
75 | 93 | ) |
76 | 94 | } |
| 95 | + |
| 96 | +const townHasPantheon = (town: Town) => { |
| 97 | + switch (typeof town.religion.pantheon) { |
| 98 | + case 'undefined': |
| 99 | + town.religion.pantheon = 'greek' |
| 100 | + break |
| 101 | + case 'string': |
| 102 | + } |
| 103 | +} |
0 commit comments