Files
TheGame/packages/web/graphql/getPersonalityInfo.ts
dan13ram 8517a26048 Upgrade dependencies (#486)
* upgraded storybook dependencies

* upgraded web dependencies

* updated timezone selector

* upgrade chakra in metamaps

* upgraded react-dnd in metamaps

* upgraded framer-motion

* fixed types in metamaps

* upgraded eslint

* upgraded lerna, husky and graphql

* upgraded node version

* removed metamaps package

* fixed all eslint issues

* ran yarn format to prettier format all files

* updated lint-staged & husky scripts

* add executable perms to pre-push scripts

* updated yarn.lock

* fixed eslint and moved chakra icons to ds

* fixed emotion errors

* removed extra useContext

* update yarn.lock

* upgraded more packages

* removed unnecessary .huskyrc.json

* lint fix
2021-05-01 12:46:48 +05:30

70 lines
1.7 KiB
TypeScript

import AmbitionAltImg from 'assets/colors/Ambition.svg';
import BalanceAltImg from 'assets/colors/Balance.svg';
import ChaosAltImg from 'assets/colors/Chaos.svg';
import JusticeAltImg from 'assets/colors/Justice.svg';
import WisdomAltImg from 'assets/colors/Wisdom.svg';
import gql from 'fake-tag';
import { isPow2 } from 'utils/mathHelper';
import { ColorAspect } from './autogen/types';
import { client } from './client';
import { PersonalityOption } from './types';
const AspectsQuery = gql`
query GetAspects {
ColorAspect {
mask
name
description
}
}
`;
export const images: {
[x: number]: string;
} = {
0b10000: JusticeAltImg,
0b01000: WisdomAltImg,
0b00100: AmbitionAltImg,
0b00010: ChaosAltImg,
0b00001: BalanceAltImg,
};
export const colors: {
[x: number]: string;
} = {
0b10000: '#c4aab4',
0b01000: '#0273b2',
0b00100: '#141a36',
0b00010: '#b72d5b',
0b00001: '#36ae60',
};
export const getPersonalityInfo = async (): Promise<{
parts: Array<PersonalityOption>;
types: { [any: string]: PersonalityOption };
}> => {
const { data, error } = await client.query(AspectsQuery).toPromise();
if (error) throw error;
if (!data) throw new Error("data isn't set");
const parts: Array<PersonalityOption> = [];
const types: { [x: number]: PersonalityOption } = {};
data.ColorAspect.forEach((aspect: ColorAspect) => {
const option = {
name: aspect.name,
description: aspect.description,
mask: aspect.mask,
};
types[aspect.mask] = option;
// pure colors are powers of 2 (only 1 bit set)
if (isPow2(aspect.mask)) {
parts.push(option);
}
});
return { parts, types };
};