From ffe50da915501917fa830d127f9b810f6d424007 Mon Sep 17 00:00:00 2001 From: xshady <54737754+xxshady@users.noreply.github.com> Date: Mon, 16 Sep 2024 16:38:04 +0300 Subject: [PATCH] feat: add multiple metadata setters (#322) --- client/index.d.ts | 11 +++++++++++ server/index.d.ts | 30 ++++++++++++++++++++++++------ shared/index.d.ts | 35 +++++++++++++++++++++++++++++++++++ 3 files changed, 70 insertions(+), 6 deletions(-) diff --git a/client/index.d.ts b/client/index.d.ts index 5741ca69..9f877e55 100644 --- a/client/index.d.ts +++ b/client/index.d.ts @@ -594,6 +594,7 @@ declare module "alt-client" { public setMeta>(key: K, value: ICustomBaseObjectMeta[K]): void; /** @deprecated See {@link ICustomBaseObjectMeta} */ public setMeta(key: K, value: shared.InterfaceValueByKey): void; + public setMeta(values: shared.MetaValues): void; } /** [Documentation](https://docs.altv.mp/articles/virtualentity.html) */ @@ -739,6 +740,7 @@ declare module "alt-client" { public setMeta>(key: K, value: ICustomAudioMeta[K]): void; /** @deprecated See {@link ICustomAudioMeta} */ public setMeta(key: K, value: shared.InterfaceValueByKey): void; + public setMeta(values: shared.MetaValues): void; } export class AudioOutput extends BaseObject { @@ -847,6 +849,7 @@ declare module "alt-client" { public setMeta>(key: K, value: ICustomCheckpointMeta[K]): void; /** @deprecated See {@link ICustomCheckpointMeta} */ public setMeta(key: K, value: shared.InterfaceValueByKey): void; + public setMeta(values: shared.MetaValues): void; } export class Entity extends WorldObject { @@ -916,6 +919,7 @@ declare module "alt-client" { public setMeta>(key: K, value: ICustomEntityMeta[K]): void; /** @deprecated See {@link ICustomEntityMeta} */ public setMeta(key: K, value: shared.InterfaceValueByKey): void; + public setMeta(values: shared.MetaValues): void; public deleteMeta(key: string): void; public deleteMeta>(key: K): void; @@ -1202,6 +1206,7 @@ declare module "alt-client" { public setMeta>(key: K, value: ICustomPlayerMeta[K]): void; /** @deprecated See {@link ICustomPlayerMeta} */ public setMeta(key: K, value: shared.InterfaceValueByKey): void; + public setMeta(values: shared.MetaValues): void; public deleteMeta(key: string): void; public deleteMeta>(key: K): void; @@ -1282,6 +1287,7 @@ declare module "alt-client" { public setMeta>(key: K, value: ICustomLocalPlayerMeta[K]): void; /** @deprecated See {@link ICustomLocalPlayerMeta} */ public setMeta(key: K, value: shared.InterfaceValueByKey): void; + public setMeta(values: shared.MetaValues): void; } export class Vehicle extends Entity { @@ -1734,6 +1740,7 @@ declare module "alt-client" { public setMeta>(key: K, value: ICustomVehicleMeta[K]): void; /** @deprecated See {@link ICustomVehicleMeta} */ public setMeta(key: K, value: shared.InterfaceValueByKey): void; + public setMeta(values: shared.MetaValues): void; public deleteMeta(key: string): void; public deleteMeta>(key: K): void; @@ -1998,6 +2005,7 @@ declare module "alt-client" { public setMeta>(key: K, value: ICustomWebViewMeta[K]): void; /** @deprecated See {@link ICustomWebViewMeta} */ public setMeta(key: K, value: shared.InterfaceValueByKey): void; + public setMeta(values: shared.MetaValues): void; } /** @deprecated */ @@ -2249,6 +2257,7 @@ declare module "alt-client" { public setMeta>(key: K, value: ICustomBlipMeta[K]): void; /** @deprecated See {@link ICustomBlipMeta} */ public setMeta(key: K, value: shared.InterfaceValueByKey): void; + public setMeta(values: shared.MetaValues): void; } export class AreaBlip extends Blip { @@ -3987,6 +3996,7 @@ declare module "alt-client" { public setMeta(key: K, value: shared.InterfaceValueByKey): void; public setMeta>(key: K, value: ICustomPedMeta[K]): void; + public setMeta(values: shared.MetaValues): void; public deleteMeta(key: string): void; public deleteMeta>(key: K): void; @@ -4168,6 +4178,7 @@ declare module "alt-client" { public setMeta>(key: K, value: ICustomColshapeMeta[K]): void; /** @deprecated See {@link ICustomColshapeMeta} */ public setMeta(key: K, value: shared.InterfaceValueByKey): void; + public setMeta(values: shared.MetaValues): void; } export class ColshapeCylinder extends Colshape { diff --git a/server/index.d.ts b/server/index.d.ts index 960f6fe8..1662406d 100644 --- a/server/index.d.ts +++ b/server/index.d.ts @@ -686,6 +686,7 @@ declare module "alt-server" { public setMeta>(key: K, value: ICustomBaseObjectMeta[K]): void; /** @deprecated See {@link ICustomBaseObjectMeta} */ public setMeta(key: K, value: shared.InterfaceValueByKey): void; + public setMeta(values: shared.MetaValues): void; /** * Removes the specified key and the data connected to that specific key. @@ -707,6 +708,7 @@ declare module "alt-server" { public setSyncedMeta>(key: K, value: shared.ICustomBaseObjectSyncedMeta[K]): void; /** @deprecated See {@link "alt-shared".ICustomBaseObjectSyncedMeta} */ public setSyncedMeta(key: K, value: shared.InterfaceValueByKey): void; + public setSyncedMeta(values: shared.MetaValues): void; } export class WorldObject extends BaseObject { @@ -792,6 +794,7 @@ declare module "alt-server" { public setStreamSyncedMeta>(key: K, value: shared.ICustomVirtualEntityStreamSyncedMeta[K]): void; /** @deprecated See {@link "alt-shared".ICustomVirtualEntityStreamSyncedMeta} */ public setStreamSyncedMeta(key: K, value: shared.InterfaceValueByKey): void; + public setStreamSyncedMeta(values: shared.MetaValues): void; /** * Removes the specified key and the data connected to that specific key. @@ -857,6 +860,7 @@ declare module "alt-server" { public setMeta>(key: K, value: ICustomEntityMeta[K]): void; /** @deprecated See {@link ICustomEntityMeta} */ public setMeta(key: K, value: shared.InterfaceValueByKey): void; + public setMeta(values: shared.MetaValues): void; public deleteMeta(key: string): void; public deleteMeta>(key: K): void; @@ -911,6 +915,7 @@ declare module "alt-server" { public setSyncedMeta>(key: K, value: shared.ICustomEntitySyncedMeta[K]): void; /** @deprecated See {@link "alt-shared".ICustomEntitySyncedMeta} */ public setSyncedMeta(key: K, value: shared.InterfaceValueByKey): void; + public setSyncedMeta(values: shared.MetaValues): void; /** * Removes the specified key and the data connected to that specific key. @@ -954,6 +959,7 @@ declare module "alt-server" { public setStreamSyncedMeta>(key: K, value: shared.ICustomEntityStreamSyncedMeta[K]): void; /** @deprecated See {@link "alt-shared".ICustomEntityStreamSyncedMeta} */ public setStreamSyncedMeta(key: K, value: shared.InterfaceValueByKey): void; + public setStreamSyncedMeta(values: shared.MetaValues): void; /** * Changes network owner to the specified player. @@ -1485,6 +1491,7 @@ declare module "alt-server" { public setLocalMeta>(key: K, value: shared.ICustomPlayerLocalMeta[K]): void; /** @deprecated See {@link "alt-shared".ICustomPlayerLocalMeta} */ public setLocalMeta(key: K, value: shared.InterfaceValueByKey): void; + public setLocalMeta(values: shared.MetaValues): void; public deleteLocalMeta(key: string): void; public deleteLocalMeta>(key: K): void; @@ -1511,6 +1518,7 @@ declare module "alt-server" { public setMeta>(key: K, value: ICustomPlayerMeta[K]): void; /** @deprecated See {@link ICustomPlayerMeta} */ public setMeta(key: K, value: shared.InterfaceValueByKey): void; + public setMeta(values: shared.MetaValues): void; public deleteMeta(key: string): void; public deleteMeta>(key: K): void; @@ -1529,6 +1537,7 @@ declare module "alt-server" { public setSyncedMeta>(key: K, value: shared.ICustomPlayerSyncedMeta[K]): void; /** @deprecated See {@link "alt-shared".ICustomPlayerSyncedMeta} */ public setSyncedMeta(key: K, value: shared.InterfaceValueByKey): void; + public setSyncedMeta(values: shared.MetaValues): void; public deleteSyncedMeta(key: string): void; public deleteSyncedMeta>(key: K): void; @@ -1547,6 +1556,7 @@ declare module "alt-server" { public setStreamSyncedMeta>(key: K, value: shared.ICustomPlayerStreamSyncedMeta[K]): void; /** @deprecated See {@link "alt-shared".ICustomPlayerStreamSyncedMeta} */ public setStreamSyncedMeta(key: K, value: shared.InterfaceValueByKey): void; + public setStreamSyncedMeta(values: shared.MetaValues): void; public deleteStreamSyncedMeta(key: string): void; public deleteStreamSyncedMeta>(key: K): void; @@ -2491,6 +2501,7 @@ declare module "alt-server" { public setMeta>(key: K, value: ICustomVehicleMeta[K]): void; /** @deprecated See {@link ICustomVehicleMeta} */ public setMeta(key: K, value: shared.InterfaceValueByKey): void; + public setMeta(values: shared.MetaValues): void; public deleteMeta(key: string): void; public deleteMeta>(key: K): void; @@ -2509,6 +2520,7 @@ declare module "alt-server" { public setSyncedMeta>(key: K, value: shared.ICustomVehicleSyncedMeta[K]): void; /** @deprecated See {@link "alt-shared".ICustomVehicleSyncedMeta} */ public setSyncedMeta(key: K, value: shared.InterfaceValueByKey): void; + public setSyncedMeta(values: shared.MetaValues): void; public deleteSyncedMeta(key: string): void; public deleteSyncedMeta>(key: K): void; @@ -2527,6 +2539,7 @@ declare module "alt-server" { public setStreamSyncedMeta>(key: K, value: shared.ICustomVehicleStreamSyncedMeta[K]): void; /** @deprecated See {@link "alt-shared".ICustomVehicleStreamSyncedMeta} */ public setStreamSyncedMeta(key: K, value: shared.InterfaceValueByKey): void; + public setStreamSyncedMeta(values: shared.MetaValues): void; public deleteStreamSyncedMeta(key: string): void; public deleteStreamSyncedMeta>(key: K): void; @@ -2667,6 +2680,7 @@ declare module "alt-server" { public setMeta>(key: K, value: ICustomBlipMeta[K]): void; /** @deprecated See {@link ICustomBlipMeta} */ public setMeta(key: K, value: shared.InterfaceValueByKey): void; + public setMeta(values: shared.MetaValues): void; } export class AreaBlip extends Blip { @@ -2732,6 +2746,7 @@ declare module "alt-server" { public setMeta>(key: K, value: ICustomColshapeMeta[K]): void; /** @deprecated See {@link ICustomColshapeMeta} */ public setMeta(key: K, value: shared.InterfaceValueByKey): void; + public setMeta(values: shared.MetaValues): void; } export class ColshapeCylinder extends Colshape { @@ -2792,18 +2807,20 @@ declare module "alt-server" { public setMeta(key: K, value: shared.InterfaceValueByKey): void; public setMeta>(key: K, value: ICustomCheckpointMeta[K]): void; + public setMeta(values: shared.MetaValues): void; - public setStreamSyncedMeta(key: K, value: shared.InterfaceValueByKey): void; - public setStreamSyncedMeta>(key: K, value: shared.ICustomPlayerStreamSyncedMeta[K]): void; + public setStreamSyncedMeta(key: K, value: shared.InterfaceValueByKey): void; + public setStreamSyncedMeta>(key: K, value: shared.ICustomCheckpointStreamSyncedMeta[K]): void; + public setStreamSyncedMeta(values: shared.MetaValues): void; public deleteStreamSyncedMeta(key: string): void; - public deleteStreamSyncedMeta>(key: K): void; + public deleteStreamSyncedMeta>(key: K): void; - public getStreamSyncedMeta(key: Exclude): unknown; - public getStreamSyncedMeta>(key: K): shared.ICustomPlayerStreamSyncedMeta[K] | undefined; + public getStreamSyncedMeta(key: Exclude): unknown; + public getStreamSyncedMeta>(key: K): shared.ICustomCheckpointStreamSyncedMeta[K] | undefined; public hasStreamSyncedMeta(key: string): boolean; - public hasStreamSyncedMeta>(key: K): boolean; + public hasStreamSyncedMeta>(key: K): boolean; public getStreamSyncedMetaKeys(): readonly string[]; } @@ -2862,6 +2879,7 @@ declare module "alt-server" { public setMeta>(key: K, value: ICustomVoiceChannelMeta[K]): void; /** @deprecated See {@link ICustomVoiceChannelMeta} */ public setMeta(key: K, value: shared.InterfaceValueByKey): void; + public setMeta(values: shared.MetaValues): void; public readonly players: readonly Player[]; diff --git a/shared/index.d.ts b/shared/index.d.ts index 8703ed80..802ee71c 100644 --- a/shared/index.d.ts +++ b/shared/index.d.ts @@ -1745,6 +1745,33 @@ declare module "alt-shared" { > ); + /** + * This is an internal utility type and you probably don't need it + * + * Converts metadata interface for multi values setter. + * For example, `setStreamSyncedMeta(values: MetaValues): void` in `alt.Vehicle`: + * ``` + * declare module "alt-shared" { + * export interface ICustomVehicleStreamSyncedMeta { + * typed: boolean, + * } + * } + * + * // vehicle is alt.Vehicle + * vehicle.setStreamSyncedMeta({ + * // must be boolean + * typed: true, + * + * // unknown type + * a: 1, + * b: 2 + * }); + * ``` + * + * @hidden + */ + export type MetaValues = Partial & Record; + export interface IVector2 { readonly x: number; readonly y: number; @@ -1895,6 +1922,13 @@ declare module "alt-shared" { */ export interface ICustomPedStreamSyncedMeta extends ICustomEntityStreamSyncedMeta {} + /** + * Extend it by interface merging for use in checkpoint stream synced meta (class `Checkpoint` on client & server, e.g. `checkpoint.getStreamSyncedMeta`) + * + * @remarks See {@link ICustomGlobalMeta} for an example of use + */ + export interface ICustomCheckpointStreamSyncedMeta {} + /** * Extend `alt.emitServer` and `alt.onServer` auto-completion by merging interfaces. * @@ -2604,6 +2638,7 @@ declare module "alt-shared" { public setMeta>(key: K, value: ICustomBaseObjectMeta[K]): void; /** @deprecated See {@link ICustomBaseObjectMeta} */ public setMeta(key: K, value: InterfaceValueByKey): void; + public setMeta(values: MetaValues): void; /** * Gets a value using the specified key.