import { BaseComponent } from "@flamework/components"; import { OnStart } from "@flamework/core"; import { Signal } from "@rbxts/beacon"; import { Atom } from "@rbxts/charm"; import { SyncPatch } from "@rbxts/charm-sync"; import { SharedComponentInfo } from "../types"; import { ISharedNetwork } from "./network"; import { Pointer } from "./pointer"; export declare const InstancesWithId: Map; export declare const GetInstanceWithId: (id: string) => Instance | undefined; export declare const removeInstanceId: (id: string) => void; export declare abstract class SharedComponent extends BaseComponent implements OnStart { static readonly instances: Map; static readonly onAddedInstances: Signal<[SharedComponent, string]>; protected pointer?: Pointer; protected abstract state: S; /** @client */ protected isBlockingServerDispatches: boolean; /** @client */ protected isAutoConnect: boolean; protected readonly remotes: Record; protected atom: Atom; private isConnected; private isEnableDevTool; private info?; private attributeConnection?; private listeners; private connectedPlayers; private playerRemovingConnection?; private scheduledSyncConnection?; private uniqueId; private instanceServerId?; private sharedComponentCtor; private onDoneHydrating; private isDestroyed; private isDoneHydrating; constructor(); onStart(): void; GetID(): string; /** * @returns The current state of the component. */ GetState(): S; /** * Gets whether the component is currently connected to the server. * @returns Whether the component is currently connected to the server. * @client */ GetIsConnected(): boolean; /** * Subscribe to changes in the state of the component. * * If provided a single function argument, the function will be called whenever the state of the component changes. * * If provided two arguments, the first argument should be a selector function that takes the current state of the component and returns a new value, and the second argument should be a listener function that takes the new value and the previous value as arguments. * * @returns A function that can be called to unsubscribe from further updates. */ Subscribe(listener: (state: S, previousState: S) => void): () => void; Subscribe(selector: (state: S) => T, listener: (state: T, previousState: T) => void): () => void; /** * Sets the state of the shared component, and notifies all subscribers of the update. * * @param newState The new state of the shared component. */ Dispatch(newState: S): S | undefined; /** * Generates and returns the information about the shared component. * * @return {SharedComponentInfo} The information about the shared component. */ GenerateInfo(): SharedComponentInfo; /** * Disconnects a player. * * @param player - The player to disconnect. * @server */ DisconnectPlayer(player: Player): void; /** * Disconnects the local player. * @client */ Disconnect(): Promise; /** * Connects the local player. * @client */ Connect(): Promise; /** * Determines whether the given sync patch is allowed to be synced for the specified player. * WARNING: Argument data is read-only!!!. * * @param {Player} player - The player for whom the sync patch is being resolved. * @param {SyncPatch} data - The sync patch to be resolved. * @return {boolean} Returns `true` if the sync patch is allowed to be synced for the player, `false` otherwise. * @server */ ResolveIsSyncForPlayer(player: Player, data: SyncPatch): boolean; /** * Determines whether the specified player has access to the connection. * * @param {Player} player - The player for whom access is being resolved. * @return {boolean} Returns `true` if the player is allowed to the connection, `false` otherwise. * @server */ ResolveConnectionPermission(player: Player): boolean; /** * Resolves the sync data for a specific player. * * @param {Player} player - The player for whom the sync data is being resolved. * @param {SyncPatch} data - The sync data to be resolved. * @return {SyncPatch} - The resolved sync data. * @server */ ResolveSyncForPlayer(player: Player, data: SyncPatch): SyncPatch; /** * Called when a player connects to the component. * @param {Player} player The player that connected. * @server */ OnConnectedPlayer(player: Player): void; /** * Called when a player disconnects to the component. * @param {Player} player The player that disconnected. * @server */ OnDisconnectedPlayer(player: Player): void; /** * Called when a local player connects to the component. * @client */ OnConnected(): void; /** * Called when a local player disconnects to the component. * @client */ OnDisconnected(): void; /** * Retrieves the set of players currently connected to the component. * * @returns A set of connected players. * @server */ GetConnectedPlayers(): ReadonlySet; /** * Checks if a player is currently connected to the component. * * @param {Player} player - The player to check for connection status. * @return {boolean} Returns `true` if the player is connected, `false` otherwise. * @server **/ IsConnectedPlayer(player: Player): boolean; /** @client */ AttachDevTool(): void; /** @client */ DisableDevTool(): void; /** @hidden **/ private onSetup; private scheduleSync; private onSendPayload; private initSharedActions; private getServerId; private getConstructor; private initInstanceID; private _onStartServer; /** @client */ private sendConnectAction; /** @client */ private sendDisconnectAction; private _onStartClient; destroy(): void; }