import { getDatabase } from '$lib/server/database'; import { gameDataIconUrl } from '$lib/server/game-data-icons'; import type { PageServerLoad } from './$types'; export const load: PageServerLoad = async () => { const database = await getDatabase(); const [ attributes, gear, gearBrands, gearTalents, gearAugments, gearAugmentCosts, brands, brandEffects, weapons, weaponRanges, weaponTalentOptions, weaponBonuses, talents, talentTiers, talentEffects, talentTemplates, chipSets, chipTwoPiece, chipPrimary, chipSecondary, chipTalents, chipTalentEffects, protocols, protocolPrimary, protocolProfiles, protocolSecondary, protocolTalents, protocolTalentEffects, coreRanges, icons ] = await Promise.all([ (await database.prepare('SELECT * FROM stat_attributes WHERE active=1 ORDER BY name COLLATE NOCASE')).all(), (await database.prepare('SELECT * FROM gear WHERE active=1 ORDER BY slot,name COLLATE NOCASE')).all(), (await database.prepare('SELECT * FROM gear_brand_sets')).all(), (await database.prepare('SELECT * FROM gear_talents')).all(), (await database.prepare('SELECT * FROM gear_tactical_augments ORDER BY gear_slot,augment_slot')).all(), (await database.prepare('SELECT * FROM gear_tactical_augment_costs ORDER BY gear_tier')).all(), (await database.prepare('SELECT * FROM brand_sets WHERE active=1 ORDER BY name COLLATE NOCASE')).all(), (await database.prepare('SELECT * FROM brand_set_effects ORDER BY pieces_required')).all(), (await database.prepare('SELECT * FROM weapons WHERE active=1 ORDER BY category,name COLLATE NOCASE')).all(), (await database.prepare('SELECT * FROM weapon_tier_ranges ORDER BY tier')).all(), (await database.prepare('SELECT * FROM weapon_talent_options ORDER BY talent_slot')).all(), (await database.prepare('SELECT * FROM weapon_base_attribute_bonuses ORDER BY sort_order')).all(), (await database.prepare('SELECT * FROM talents WHERE active=1 ORDER BY name COLLATE NOCASE')).all(), (await database.prepare('SELECT * FROM talent_tiers ORDER BY tier')).all(), (await database.prepare('SELECT * FROM talent_tier_effects')).all(), (await database.prepare('SELECT * FROM talent_description_templates')).all(), (await database.prepare('SELECT * FROM skill_chip_sets WHERE active=1 ORDER BY name COLLATE NOCASE')).all(), (await database.prepare('SELECT * FROM skill_chip_two_piece_bonuses')).all(), (await database.prepare('SELECT * FROM skill_chip_primary_options')).all(), (await database.prepare('SELECT * FROM skill_chip_secondary_options')).all(), (await database.prepare('SELECT * FROM skill_chip_talents')).all(), (await database.prepare('SELECT * FROM skill_chip_talent_effects ORDER BY sort_order')).all(), (await database.prepare('SELECT * FROM os_protocols WHERE active=1 ORDER BY name COLLATE NOCASE')).all(), (await database.prepare('SELECT * FROM os_protocol_primary_effects')).all(), (await database.prepare('SELECT * FROM os_protocol_secondary_profiles')).all(), (await database.prepare('SELECT * FROM os_protocol_secondary_effects ORDER BY effect_role')).all(), (await database.prepare('SELECT * FROM os_protocol_talents')).all(), (await database.prepare('SELECT * FROM os_protocol_talent_effects ORDER BY sort_order')).all(), (await database.prepare('SELECT * FROM core_attribute_tier_ranges ORDER BY tier')).all(), (await database.prepare("SELECT * FROM game_data_icons")).all() ]); const iconUrl = (type: 'talent' | 'brand_set' | 'os_protocol' | 'skill_chip', id: unknown) => { const icon = icons.find((item) => item.entity_type === type && item.entity_id === id); return icon ? gameDataIconUrl(type, String(id), icon.updated_at) : ''; }; const configuredTalents = talents.map((talent) => ({ ...talent, iconUrl: iconUrl('talent', talent.id), template: talentTemplates.find((item) => item.talent_id === talent.id)?.template ?? '', tiers: talentTiers.filter((tier) => tier.talent_id === talent.id).map((tier) => ({ ...tier, effects: talentEffects.filter((effect) => effect.talent_tier_id === tier.id) })) })); return { attributes, coreRanges, gear: gear.map((item) => ({ ...item, brandIds: gearBrands.filter((link) => link.gear_id === item.id).map((link) => String(link.brand_set_id)), talentIds: gearTalents.filter((link) => link.gear_id === item.id).map((link) => String(link.talent_id)) })), gearAugments: gearAugments.map((augment) => ({ ...augment, costs: gearAugmentCosts.filter((cost) => cost.augment_id === augment.id) })), brands: brands.map((brand) => ({ ...brand, iconUrl: iconUrl('brand_set', brand.id), effects: brandEffects.filter((effect) => effect.brand_set_id === brand.id) })), weapons: weapons.map((weapon) => ({ ...weapon, ranges: weaponRanges.filter((range) => range.weapon_id === weapon.id), talent1Ids: weaponTalentOptions.filter((link) => link.weapon_id === weapon.id && Number(link.talent_slot) === 1).map((link) => String(link.talent_id)), talent2Ids: weaponTalentOptions.filter((link) => link.weapon_id === weapon.id && Number(link.talent_slot) === 2).map((link) => String(link.talent_id)), baseBonuses: weaponBonuses.filter((bonus) => bonus.weapon_id === weapon.id) })), talents: configuredTalents, chipSets: chipSets.map((set) => { const talent = chipTalents.find((item) => item.skill_chip_set_id === set.id); return { ...set, iconUrl: iconUrl('skill_chip', set.id), twoPiece: chipTwoPiece.find((item) => item.skill_chip_set_id === set.id) ?? null, primaryStatIds: chipPrimary.filter((item) => item.skill_chip_set_id === set.id).map((item) => String(item.stat_attribute_id)), secondaryStatIds: chipSecondary.filter((item) => item.skill_chip_set_id === set.id).map((item) => String(item.stat_attribute_id)), talent: talent ? { ...talent, effects: chipTalentEffects.filter((effect) => effect.talent_id === talent.id) } : null }; }), protocols: protocols.map((protocol) => { const profile = protocolProfiles.find((item) => item.quality === protocol.quality && item.primary_attribute_type === protocol.primary_attribute_type); const talent = protocolTalents.find((item) => item.protocol_id === protocol.id); return { ...protocol, iconUrl: iconUrl('os_protocol', protocol.id), primaryEffect: protocolPrimary.find((item) => item.protocol_id === protocol.id) ?? null, secondaryEffects: profile ? protocolSecondary.filter((effect) => effect.profile_id === profile.id) : [], talent: talent ? { ...talent, effects: protocolTalentEffects.filter((effect) => effect.talent_id === talent.id) } : null }; }) }; };