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
111 lines • 4.39 kB
TypeScript
import type { Agent, MultyxTeam } from "../agents";
import { RawObject, Value } from "../types";
import { MultyxItem, MultyxValue } from ".";
import { Build, Get, Self } from "../utils/native";
export default class MultyxList {
data: MultyxItem[];
propertyPath: string[];
agent: Agent;
disabled: boolean;
relayed: boolean;
allowItemChange: boolean;
allowItemAddition: boolean;
allowItemDeletion: boolean;
private publicTeams;
private writeCallbacks;
[key: string]: any;
get value(): any[];
get relayedValue(): any[];
get length(): number;
set length(length: number);
private sendShiftOperation;
/**
* Create a MultyxItem representation of an array
* @param list Array to turn into MultyxObject
* @param agent Client or MultyxTeam hosting this MultyxItem
* @param propertyPath Entire path from agent to this MultyxList
* @returns MultyxList
*/
constructor(list: (RawObject | Value | MultyxItem)[], 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;
has(index: number): boolean;
/**
* Get the value of a property
*/
get(property: number | string[]): MultyxItem | undefined;
/**
* Set the value of the MultyxValue object of a property
* @example
* ```js
* // Server
* multyx.on('reset', client => client.player.set('x', 5));
*
* // Client
* client.position[1] = 20 * Math.random();
* multyx.send('reset');
* console.log(client.position[1]); // 5
* ```
*/
set(index: string | number, value: any): this | false;
delete(index: string | number): this;
await(index: number): Promise<unknown>;
/**
* Create a callback that gets called whenever the object is edited
* @param index Index to listen for writes on
* @param callback Function to call whenever object is edited
* @returns Event object representing write callback
*/
onWrite(index: number, callback: (v: any) => void): import("../messages/event").Event;
/**
* Get all properties in list 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[];
[Self](newPath: string[]): void;
push(...items: any[]): number;
pop(): MultyxItem | undefined;
unshift(...items: any[]): number;
shift(): MultyxList | import("./object").default | MultyxValue | undefined;
splice(start: number, deleteCount?: number, ...items: any[]): this;
slice(start?: number, end?: number): this;
filter(predicate: (value: any, index: number, array: MultyxList) => boolean): this;
map(callbackfn: (value: any, index: number, array: MultyxList) => any): void;
flat(): void;
reduce(callbackfn: (accumulator: any, currentValue: any, index: number, array: MultyxList) => any, startingAccumulator: any): any;
reduceRight(callbackfn: (accumulator: any, currentValue: any, index: number, array: MultyxList) => any, startingAccumulator: any): any;
reverse(): this;
forEach(callbackfn: (value: any, index: number, array: MultyxList) => void): void;
every(predicate: (value: any, index: number, array: MultyxList) => boolean): boolean;
some(predicate: (value: any, index: number, array: MultyxList) => boolean): boolean;
find(predicate: (value: any, index: number, array: MultyxList) => boolean): MultyxList | import("./object").default | MultyxValue | undefined;
findIndex(predicate: (value: any, index: number, array: MultyxList) => boolean): number;
entries(): [any, any][];
keys(): any[];
values(): any[];
[Symbol.iterator](): Iterator<MultyxItem>;
toString: () => string;
valueOf: () => any[];
[Symbol.toPrimitive]: () => any[];
}
//# sourceMappingURL=list.d.ts.map