Skip to content

Commit

Permalink
Deprecated old Async APIs
Browse files Browse the repository at this point in the history
  • Loading branch information
zziger committed May 7, 2022
1 parent 600ff58 commit d5437a3
Show file tree
Hide file tree
Showing 7 changed files with 264 additions and 3 deletions.
5 changes: 5 additions & 0 deletions api/AltV.Net.Async/AltAsync.BaseObject.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Threading.Tasks;
using AltV.Net.Elements.Args;
using AltV.Net.Elements.Entities;
Expand All @@ -7,19 +8,23 @@ namespace AltV.Net.Async
//TODO: allocate position, rotation, rgba structs in task thread an pass them to the main thread instead of creating them in the main thread
public partial class AltAsync
{
[Obsolete("Use async entities instead")]
public static Task<bool> ExistsAsync(this IBaseObject baseObject) =>
AltVAsync.Schedule(() => baseObject.Exists);

[Obsolete("Use async entities instead")]
public static Task<BaseObjectType> GetTypeAsync(this IBaseObject baseObject) =>
AltVAsync.Schedule(() => baseObject.Type);

[Obsolete("Use async entities instead")]
public static async Task SetMetaDataAsync(this IBaseObject baseObject, string key, object value)
{
Alt.Core.CreateMValue(out var mValue, value);
await AltVAsync.Schedule(() => baseObject.SetMetaData(key, in mValue));
mValue.Dispose();
}

[Obsolete("Use async entities instead")]
public static Task<T> GetMetaDataAsync<T>(this IBaseObject baseObject, string key) =>
AltVAsync.Schedule(() =>
{
Expand Down
10 changes: 10 additions & 0 deletions api/AltV.Net.Async/AltAsync.Blip.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Threading.Tasks;
using AltV.Net.Data;
using AltV.Net.Elements.Entities;
Expand Down Expand Up @@ -30,30 +31,39 @@ public static Task<IBlip> CreateBlip(BlipType type, Position pos) =>
public static Task<IBlip> CreateBlip(BlipType type, IEntity entityAttach) =>
AltVAsync.Schedule(() => Alt.CreateBlip(type, entityAttach));

[Obsolete("Use async entities instead")]
public static Task<bool> IsGlobalAsync(this IBlip blip) =>
AltVAsync.Schedule(() => blip.IsGlobal);

[Obsolete("Use async entities instead")]
public static Task<bool> IsAttachedAsync(this IBlip blip) =>
AltVAsync.Schedule(() => blip.IsAttached);

[Obsolete("Use async entities instead")]
public static Task<IEntity> AttachedToAsync(this IBlip blip) =>
AltVAsync.Schedule(() => blip.AttachedTo);

[Obsolete("Use async entities instead")]
public static Task<BlipType> GetBlipTypeAsync(this IBlip blip) =>
AltVAsync.Schedule(() => (BlipType) blip.BlipType);

[Obsolete("Use async entities instead")]
public static Task SetSpriteAsync(this IBlip blip, ushort sprite) =>
AltVAsync.Schedule(() => blip.Sprite = sprite);

[Obsolete("Use async entities instead")]
public static Task SetColorAsync(this IBlip blip, byte color) =>
AltVAsync.Schedule(() => blip.Color = color);

[Obsolete("Use async entities instead")]
public static Task SetRouteAsync(this IBlip blip, bool route) =>
AltVAsync.Schedule(() => blip.Route = route);

[Obsolete("Use async entities instead")]
public static Task SetRouteColorAsync(this IBlip blip, Rgba color) =>
AltVAsync.Schedule(() => blip.RouteColor = color);

[Obsolete("Use async entities instead")]
public static Task RemoveAsync(this IBlip blip) =>
AltVAsync.Schedule(blip.RemoveAsync);
}
Expand Down
10 changes: 8 additions & 2 deletions api/AltV.Net.Async/AltAsync.Checkpoint.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,30 +17,36 @@ public static Task<ICheckpoint> CreateCheckpoint(CheckpointType type, Position p
Rgba color) =>
AltVAsync.Schedule(() => Alt.CreateCheckpoint(type, pos, radius, height, color));

[Obsolete("Use async entities instead")]
public static Task<CheckpointType> GetCheckpointTypeAsync(this ICheckpoint checkpoint) =>
AltVAsync.Schedule(() => (CheckpointType) checkpoint.CheckpointType);

[Obsolete("Use async entities instead")]
public static Task<float> GetHeightAsync(this ICheckpoint checkpoint) =>
AltVAsync.Schedule(() => checkpoint.Height);

[Obsolete("Use async entities instead")]
public static Task<float> GetRadiusAsync(this ICheckpoint checkpoint) =>
AltVAsync.Schedule(() => checkpoint.Radius);

[Obsolete("Use async entities instead")]
public static Task<Rgba> GetColorAsync(this ICheckpoint checkpoint) =>
AltVAsync.Schedule(() => checkpoint.Color);


[Obsolete("Use Checkpoint.IsEntityInAsync instead")]
[Obsolete("Use Checkpoint.IsEntityIn on async entity instead")]
public static Task<bool> IsPlayerInAsync(this ICheckpoint checkpoint, IPlayer player) =>
AltVAsync.Schedule(() => checkpoint.IsPlayerIn(player));

[Obsolete("Use Checkpoint.IsEntityInAsync instead")]
[Obsolete("Use Checkpoint.IsEntityIn on async entity instead")]
public static Task<bool> IsVehicleInAsync(this ICheckpoint checkpoint, IVehicle vehicle) =>
AltVAsync.Schedule(() => checkpoint.IsVehicleIn(vehicle));

[Obsolete("Use async entities instead")]
public static Task<bool> IsEntityInAsync(this ICheckpoint checkpoint, IEntity entity) =>
AltVAsync.Schedule(() => checkpoint.IsEntityIn(entity));

[Obsolete("Use async entities instead")]
public static Task RemoveAsync(this ICheckpoint checkpoint) =>
AltVAsync.Schedule(checkpoint.Remove);
}
Expand Down
10 changes: 10 additions & 0 deletions api/AltV.Net.Async/AltAsync.Entity.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System;
using System.Threading.Tasks;
using AltV.Net.Data;
using AltV.Net.Elements.Args;
Expand All @@ -8,46 +9,55 @@ namespace AltV.Net.Async
//TODO: allocate position, rotation, rgba structs in task thread an pass them to the main thread instead of creating them in the main thread
public partial class AltAsync
{
[Obsolete("Use async entities instead")]
public static Task<uint> GetModelAsync(this IEntity entity) =>
AltVAsync.Schedule(() => entity.Model);

[Obsolete("Use async entities instead")]
public static Task SetRotationAsync(this IEntity entity, Rotation rotation) =>
AltVAsync.Schedule(() => entity.Rotation = rotation);

[Obsolete("Use async entities instead")]
public static Task<Rotation> GetRotationAsync(this IEntity entity) =>
AltVAsync.Schedule(() => entity.Rotation);

[Obsolete("Use async entities instead")]
public static async Task SetSyncedMetaDataAsync(this IEntity entity, string key, object value)
{
Alt.Core.CreateMValue(out var mValue, value);
await AltVAsync.Schedule(() => entity.SetSyncedMetaData(key, mValue));
mValue.Dispose();
}

[Obsolete("Use async entities instead")]
public static Task<T> GetSyncedMetaDataAsync<T>(this IEntity entity, string key) =>
AltVAsync.Schedule(() =>
{
entity.GetSyncedMetaData<T>(key, out var value);
return value;
});

[Obsolete("Use async entities instead")]
public static async Task SetStreamSyncedMetaDataAsync(this IEntity entity, string key, object value)
{
Alt.Core.CreateMValue(out var mValue, value);
await AltVAsync.Schedule(() => entity.SetStreamSyncedMetaData(key, mValue));
mValue.Dispose();
}

[Obsolete("Use async entities instead")]
public static Task<T> GetStreamSyncedMetaDataAsync<T>(this IEntity entity, string key) =>
AltVAsync.Schedule(() =>
{
entity.GetStreamSyncedMetaData<T>(key, out var value);
return value;
});

[Obsolete("Use async entities instead")]
public static Task DeleteSyncedMetaDataAsync(this IEntity entity, string key) =>
AltVAsync.Schedule(() => entity.DeleteSyncedMetaData(key));

[Obsolete("Use async entities instead")]
public static Task DeleteStreamSyncedMetaDataAsync(this IEntity entity, string key) =>
AltVAsync.Schedule(() => entity.DeleteStreamSyncedMetaData(key));
}
Expand Down
Loading

0 comments on commit d5437a3

Please sign in to comment.