mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-07-06 13:33:55 -07:00
refactor typescript wiring
This commit is contained in:
parent
cea9ae62d8
commit
c62c336a11
286 changed files with 2999 additions and 3053 deletions
|
|
@ -1,19 +1,15 @@
|
|||
import type { ServerInfo_Room } from 'generated/proto/serverinfo_room_pb';
|
||||
import type { ServerInfo_Game } from 'generated/proto/serverinfo_game_pb';
|
||||
import type { ServerInfo_GameType } from 'generated/proto/serverinfo_gametype_pb';
|
||||
import type { ServerInfo_ChatMessage } from 'generated/proto/serverinfo_chat_message_pb';
|
||||
import { Game, GametypeMap, LogGroups, Message, Room } from 'types';
|
||||
import { Data, Enriched } from '@app/types';
|
||||
|
||||
/** Flatten a gametype list into a lookup map of { gameTypeId → description }. */
|
||||
export function normalizeGametypeMap(gametypeList: ServerInfo_GameType[]): GametypeMap {
|
||||
return gametypeList.reduce<GametypeMap>((map, type) => {
|
||||
export function normalizeGametypeMap(gametypeList: Data.ServerInfo_GameType[]): Enriched.GametypeMap {
|
||||
return gametypeList.reduce<Enriched.GametypeMap>((map, type) => {
|
||||
map[type.gameTypeId] = type.description;
|
||||
return map;
|
||||
}, {});
|
||||
}
|
||||
|
||||
/** Flatten room gameTypes into a map object and normalize all games inside. */
|
||||
export function normalizeRoomInfo(roomInfo: ServerInfo_Room): Room {
|
||||
export function normalizeRoomInfo(roomInfo: Data.ServerInfo_Room): Enriched.Room {
|
||||
const gametypeMap = normalizeGametypeMap(roomInfo.gametypeList);
|
||||
|
||||
const gameList = roomInfo.gameList.map(
|
||||
|
|
@ -29,7 +25,7 @@ export function normalizeRoomInfo(roomInfo: ServerInfo_Room): Room {
|
|||
}
|
||||
|
||||
/** Flatten gameTypes[] into a gameType string; fill in default sortable values. */
|
||||
export function normalizeGameObject(game: ServerInfo_Game, gametypeMap: GametypeMap): Game {
|
||||
export function normalizeGameObject(game: Data.ServerInfo_Game, gametypeMap: Enriched.GametypeMap): Enriched.Game {
|
||||
const { gameTypes, description } = game;
|
||||
const hasType = gameTypes && gameTypes.length;
|
||||
|
||||
|
|
@ -41,13 +37,13 @@ export function normalizeGameObject(game: ServerInfo_Game, gametypeMap: Gametype
|
|||
}
|
||||
|
||||
/** Group a flat LogItem[] into { room, game, chat } buckets for the server store. */
|
||||
export function normalizeLogs(logs: ServerInfo_ChatMessage[]): LogGroups {
|
||||
export function normalizeLogs(logs: Data.ServerInfo_ChatMessage[]): Enriched.LogGroups {
|
||||
return logs.reduce((obj, log) => {
|
||||
const type = log.targetType as keyof LogGroups;
|
||||
const type = log.targetType as keyof Enriched.LogGroups;
|
||||
obj[type] = obj[type] || [];
|
||||
obj[type]!.push(log);
|
||||
return obj;
|
||||
}, {} as LogGroups);
|
||||
}, {} as Enriched.LogGroups);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
@ -56,7 +52,7 @@ export function normalizeLogs(logs: ServerInfo_ChatMessage[]): LogGroups {
|
|||
* so this is a no-op for those.
|
||||
* Returns a new Message — does not mutate the original.
|
||||
*/
|
||||
export function normalizeUserMessage(message: Message): Message {
|
||||
export function normalizeUserMessage(message: Enriched.Message): Enriched.Message {
|
||||
if (!message.name) {
|
||||
return message;
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue