49 lines
1.5 KiB
TypeScript
49 lines
1.5 KiB
TypeScript
import type { Database } from '@tursodatabase/database';
|
|
|
|
export const OS_PROTOCOL_PROFILE_ATTRIBUTE_SPECS = {
|
|
Firepower: {
|
|
Core: { name: 'Firepower', unit: '' },
|
|
Damage: { name: 'Weapon Damage', unit: '' },
|
|
Health: { name: 'Health', unit: '' },
|
|
},
|
|
Toughness: {
|
|
Core: { name: 'Toughness', unit: '' },
|
|
Damage: { name: 'Weapon Damage', unit: '' },
|
|
Health: { name: 'Health', unit: '' },
|
|
},
|
|
Engineering: {
|
|
Core: { name: 'Engineering', unit: '' },
|
|
Damage: { name: 'Skill Damage', unit: '%' },
|
|
Health: { name: 'Health', unit: '' },
|
|
},
|
|
} as const;
|
|
|
|
export type OsProtocolAttributeType =
|
|
keyof typeof OS_PROTOCOL_PROFILE_ATTRIBUTE_SPECS;
|
|
export type OsProtocolSecondaryRole = 'Core' | 'Damage' | 'Health';
|
|
|
|
export async function getOsProtocolProfileAttributeIds(
|
|
database: Database,
|
|
attributeType: OsProtocolAttributeType,
|
|
) {
|
|
const specs = OS_PROTOCOL_PROFILE_ATTRIBUTE_SPECS[attributeType];
|
|
const entries = await Promise.all(
|
|
(
|
|
Object.entries(specs) as Array<
|
|
[OsProtocolSecondaryRole, { name: string; unit: string }]
|
|
>
|
|
).map(async ([role, spec]) => {
|
|
const row = await (
|
|
await database.prepare(
|
|
'SELECT id FROM stat_attributes WHERE active=1 AND name=? COLLATE NOCASE AND unit=?',
|
|
)
|
|
).get(spec.name, spec.unit);
|
|
return [role, row ? String(row.id) : null] as const;
|
|
}),
|
|
);
|
|
return Object.fromEntries(entries) as Record<
|
|
OsProtocolSecondaryRole,
|
|
string | null
|
|
>;
|
|
}
|