UNPKG

moomooio-client

Version:

MooMooIO-Client is a client-side wrapper API designed for the game MooMoo.io. This package aims to provide a simple yet powerful API for creating clones, mods, or plugins for MooMoo.io.

51 lines (42 loc) 1.62 kB
import { z } from "zod"; const schema = z.tuple([z.array(z.union([z.number(), z.string()]))]); const chunkSchema = z.tuple([z.number(), z.string(), z.number()]); /** * @member `score` indicates the player's gold score. * @member `name` indicates the player's name. * @member `id` a special code that uniquely identifies the player. */ export interface LeaderBoardMember { readonly score: number; readonly name: string; readonly id: number; } /** * @packet-id "5" * @description **UpdateLeaderBoard** is a packet that holds information about the current status of LeaderBoard in the game. * @member `members` is a list of LeaderBoardMember * * @member `LeaderBoardMember.score` indicates the player's gold score. * @member `LeaderBoardMember.name` indicates the player's name. * @member `LeaderBoardMember.id` a special code that uniquely identifies the player. */ export default class UpdateLeaderBoard { public static readonly PACKET_ID = "5"; public static readonly PACKET_NAME = "UpdateLeaderBoard"; public readonly PACKET_NAME = "UpdateLeaderBoard"; constructor(readonly members: LeaderBoardMember[]) {} static parse(data: unknown): UpdateLeaderBoard { const result: LeaderBoardMember[] = []; const info = schema.parse(data)[0]; for (let i = 0; i < info.length; i += 3) { const content = info.slice(i, i + 3); const chunk = chunkSchema.parse(content); result.push({ name: chunk[1], score: chunk[2], id: chunk[0], }); } return new UpdateLeaderBoard(result); } }