import { writeFileSync } from 'node:fs'; import { prepareHolodoriDbSource, readHolodoriDbText } from './holodoridb-source.mjs'; const source = prepareHolodoriDbSource('kor'); const missions = JSON.parse(readHolodoriDbText(source, 'Mission.json')).map((row) => row.data) .filter((mission) => mission.characterId && mission.categoryType === 'MissionCategoryType_MISSION_CATEGORY_TYPE_ACHIEVEMENT' && mission.type === 'MissionType_MISSION_TYPE_INCREMENT_WORK_FINISH_COUNT'); const progress = JSON.parse(readHolodoriDbText(source, 'MissionProgress.json')).map((row) => row.data); if (!missions.length) throw new Error('No member Holo-work achievements found.'); const thresholdsByMember = Object.fromEntries(missions.sort((a, b) => a.characterId.localeCompare(b.characterId)).map((mission) => { const thresholds = [...new Set(progress.filter((row) => row.missionId === mission.id).map((row) => Number(row.threshold)))].sort((a, b) => a - b); if (!thresholds.length || thresholds.some((value) => !Number.isSafeInteger(value) || value <= 0)) { throw new Error(`Invalid Holo-work thresholds: ${mission.id}`); } return [mission.characterId, thresholds]; })); writeFileSync(new URL('../src/lib/data/holo-work-achievements.json', import.meta.url), JSON.stringify({ source: { repository: source.repository, commit: source.commit, files: ['Mission.json', 'MissionProgress.json'] }, thresholdsByMember }, null, 2) + '\n'); console.log(`Collected Holo-work achievements for ${missions.length} members at ${source.commit}.`);