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.

48 lines (39 loc) 1.46 kB
import { z } from "zod"; const schema = z.tuple([z.union([z.array(z.union([z.number(), z.string()])), z.literal(0)])]); const chunkSchema = z.tuple([z.number(), z.number()]); /** * @member `x` represents the point's position on the x-axis. * @member `y` represents the point's position on the y-axis. */ export interface Point2D { readonly x: number; readonly y: number; } /** * @packet-id "mm" * @description **UpdateMiniMap** is a packet that holds information about the current status of mini map in the game. * @member `points` is a list of Point2D (each point is teammate position) * * @member `Point2D.x` represents the point's position on the x-axis. * @member `Point2D.y` represents the point's position on the y-axis. */ export default class UpdateMiniMap { public static readonly PACKET_ID = "mm"; public static readonly PACKET_NAME = "UpdateMiniMap"; public readonly PACKET_NAME = "UpdateMiniMap"; constructor(readonly points: Point2D[]) {} static parse(data: unknown): UpdateMiniMap { const result: Point2D[] = []; const info = schema.parse(data)[0]; if (info instanceof Array) for (let i = 0; i < info.length; i += 2) { const content = info.slice(i, i + 2); const chunk = chunkSchema.parse(content); result.push({ x: chunk[0], y: chunk[1], }); } return new UpdateMiniMap(result); } }