- Update Zod schemas to match raw API response formats - Create transformation layer (rounds, weapons, chat) to convert raw API to structured format - Add player name mapping in transformers for better UX - Fix Svelte 5 reactivity issues in chat page (replace $effect with $derived) - Fix Chart.js compatibility with Svelte 5 state proxies using JSON serialization - Add economy advantage chart with halftime perspective flip (WIP) - Remove stray comment from details page - Update layout to load match data first, then pass to API methods 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
47 lines
1.1 KiB
TypeScript
47 lines
1.1 KiB
TypeScript
import type { ChatAPIResponse } from '$lib/types/api/ChatAPIResponse';
|
|
import type { MatchChatResponse, Message, Match } from '$lib/types';
|
|
|
|
/**
|
|
* Transform raw chat API response into structured format
|
|
* @param rawData - Raw API response
|
|
* @param matchId - Match ID
|
|
* @param match - Match data with player information
|
|
* @returns Structured chat data
|
|
*/
|
|
export function transformChatResponse(
|
|
rawData: ChatAPIResponse,
|
|
matchId: string,
|
|
match?: Match
|
|
): MatchChatResponse {
|
|
const messages: Message[] = [];
|
|
|
|
// Create player ID to name mapping
|
|
const playerMap = new Map<string, string>();
|
|
if (match?.players) {
|
|
for (const player of match.players) {
|
|
playerMap.set(player.id, player.name);
|
|
}
|
|
}
|
|
|
|
// Flatten all player messages into a single array
|
|
for (const [playerId, playerMessages] of Object.entries(rawData)) {
|
|
const playerName = playerMap.get(playerId) || `Player ${playerId}`;
|
|
|
|
for (const message of playerMessages) {
|
|
messages.push({
|
|
...message,
|
|
player_id: Number(playerId),
|
|
player_name: playerName
|
|
});
|
|
}
|
|
}
|
|
|
|
// Sort by tick
|
|
messages.sort((a, b) => a.tick - b.tick);
|
|
|
|
return {
|
|
match_id: matchId,
|
|
messages
|
|
};
|
|
}
|