Files
shd.build/src/lib/server/os-protocol-profiles.ts
T
jb 57068b61cd
Validate and deploy production / validate (push) Canceled after 0s
Validate and deploy production / deploy (push) Canceled after 0s
Validate and deploy staging / validate (push) Successful in 28s
Validate and deploy staging / deploy (push) Successful in 1m3s
feat: expand ISAC content modeling
2026-08-03 01:23:20 -04:00

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
>;
}