UNPKG

multyx

Version:

Framework designed to simplify the creation of multiplayer browser games by addressing the complexities of managing server-client communication, shared state, and input handling

113 lines 3.71 kB
import { MultyxItem } from "."; import { RawObject } from "../types"; import { Get, Build, Self } from '../utils/native'; import type { Agent, MultyxTeam } from "../agents"; export default class MultyxObject { data: { [key: string]: MultyxItem; }; propertyPath: string[]; agent: Agent; disabled: boolean; relayed: boolean; private publicTeams; [key: string]: any; /** * Turn MultyxObject back into regular object * @returns RawObject mirroring shape and values of MultyxObject */ get value(): RawObject; /** * Get the value of MultyxObject that is relayed to public agents * @returns RawObject mirroring shape and values of relayed MultyxObject */ get relayedValue(): RawObject; /** * Create a MultyxItem representation of an object * @param object Object to turn into MultyxItem * @param agent Client or MultyxTeam hosting this MultyxItem * @param propertyPath Entire path from agent to this MultyxObject * @returns MultyxObject */ constructor(object: RawObject | MultyxObject, agent: Agent, propertyPath?: string[]); disable(): this; enable(): this; relay(): this; unrelay(): this; /** * Publicize MultyxValue from specific MultyxTeam * @param team MultyxTeam to share MultyxValue to * @returns Same MultyxValue */ addPublic(team: MultyxTeam): this; /** * Privitize MultyxValue from specific MultyxTeam * @param team MultyxTeam to hide MultyxValue from * @returns Same MultyxValue */ removePublic(team: MultyxTeam): this; /** * Check if property is in object */ has(property: string): boolean; /** * Get the value of a property */ get(property: string | string[]): MultyxItem | undefined; /** * Set the explicit value of the property * @example * ```js * // Server * multyx.on('reset', client => client.player.set('x', 5)); * * // Client * client.player.x = 20 * Math.random(); * multyx.send('reset'); * console.log(client.player.x); // 5 * ``` */ set(property: string, value: any): MultyxObject | false; /** * Delete property from MultyxObject * @param property Name of property to delete * @returns False if deletion failed, same MultyxObject otherwise */ delete(property: string): this; /** * Wait for a property in object to be defined * @param property Name of property in object to wait for * @returns Promise that resolves once object[property] is defined */ await(property: string): Promise<unknown>; /** * Create a callback that gets called whenever the object is edited * @param property Property to listen for writes on * @param callback Function to call whenever object is edited * @returns Event object representing write callback */ onWrite(property: string, callback: (v: any) => void): import("../messages/event").Event; /** * Get all properties in object publicized to specific team * @param team MultyxTeam to get public data for * @returns Raw object */ [Get](team: MultyxTeam): RawObject; /** * Build a constraint table * @returns Constraint table */ [Build](): RawObject; /** * Edit the property path of MultyxObject and any children * @param newPath New property path to take */ [Self](newPath: string[]): void; entries(): [string, any][]; keys(): string[]; values(): any[]; toString: () => string; valueOf: () => RawObject; [Symbol.toPrimitive]: () => RawObject; } //# sourceMappingURL=object.d.ts.map